Skip to content

Commit 77572e0

Browse files
committed
use import.meta.dirname
1 parent 8f71a3c commit 77572e0

File tree

43 files changed

+92
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+92
-129
lines changed

cli/_paths.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// @ts-check
22

33
import * as path from "node:path";
4-
import { fileURLToPath } from "node:url";
54

6-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7-
8-
export const cliPath = path.join(__dirname, "rescript.js");
5+
export const cliPath = path.join(import.meta.dirname, "rescript.js");
96

107
/**
118
* For compatibility reasons, if the architecture is x64, omit it from the bin directory name.
@@ -19,7 +16,11 @@ export const platformName =
1916
? process.platform
2017
: process.platform + process.arch;
2118

22-
export const platformDir = path.resolve(__dirname, "..", platformName);
19+
export const platformDir = path.resolve(
20+
import.meta.dirname,
21+
"..",
22+
platformName,
23+
);
2324

2425
export const bsc_exe = path.join(platformDir, "bsc.exe");
2526

lib_dev/paths.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
// @ts-check
22

33
import * as path from "node:path";
4-
import { fileURLToPath } from "node:url";
5-
6-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
74

85
/**
96
* The project root path
107
*/
11-
export const projectDir = path.resolve(__dirname, "..");
8+
export const projectDir = path.resolve(import.meta.dirname, "..");
129

1310
/**
1411
* path: `<projectDir>/compiler/`

lib_dev/process.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import * as child_process from "node:child_process";
2-
import * as path from "node:path";
3-
import { fileURLToPath } from "node:url";
42
import { bsc_exe, cliPath, rescript_exe } from "#cli/paths";
53

64
/**
@@ -21,18 +19,10 @@ const signals = {
2119
export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } =
2220
setup();
2321

24-
/**
25-
* @param {string} url
26-
*/
27-
export function setupWithUrl(url) {
28-
return setup(path.dirname(fileURLToPath(url)));
29-
}
30-
3122
/**
3223
* @param {string} [cwd]
3324
*/
3425
export function setup(cwd = process.cwd()) {
35-
3626
/**
3727
* @param {string} command
3828
* @param {string[]} [args]

lib_dev/utils.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
/**
2-
* `import.meta.dirname` alternative. It is available since Node.js v20.11.0
3-
*
4-
* @param {string} url `import.meta.url`
5-
* @return {string}
6-
*/
7-
export function getDirname(url) {
8-
return path.dirname(fileURLToPath(url));
9-
}
10-
111
/**
122
* @param {string} s
133
*/

packages/playground-bundling/rollup.config.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import * as path from "node:path";
2-
import { fileURLToPath } from "node:url";
32
import nodeResolve from "@rollup/plugin-node-resolve";
43
import { glob } from "glob";
54

6-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7-
8-
const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", "..");
5+
const RESCRIPT_COMPILER_ROOT_DIR = path.join(import.meta.dirname, "..", "..");
96
const LIB_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "lib");
107
const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground");
118
// Final target output directory where all the cmijs will be stored

packages/playground-bundling/scripts/generate_cmijs.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
import * as child_process from "node:child_process";
1919
import * as fs from "node:fs";
2020
import * as path from "node:path";
21-
import { fileURLToPath } from "node:url";
2221

2322
import resConfig from "../rescript.json" with { type: "json" };
2423

25-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
26-
27-
const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", "..", "..");
24+
const RESCRIPT_COMPILER_ROOT_DIR = path.join(
25+
import.meta.dirname,
26+
"..",
27+
"..",
28+
"..",
29+
);
2830
const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground");
2931

3032
// The playground-bundling root dir
31-
const PROJECT_ROOT_DIR = path.join(__dirname, "..");
33+
const PROJECT_ROOT_DIR = path.join(import.meta.dirname, "..");
3234

3335
// Final target output directory where all the cmijs will be stored
3436
const PACKAGES_DIR = path.join(PLAYGROUND_DIR, "packages");

tests/build_tests/build_warn_as_error/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from "node:assert";
2-
import { setupWithUrl } from "#dev/process";
2+
import { setup } from "#dev/process";
33

4-
const { execBuild, execClean } = setupWithUrl(import.meta.url);
4+
const { execBuild, execClean } = setup(import.meta.dirname);
55

66
const o1 = await execBuild();
77

tests/build_tests/case/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as assert from "node:assert";
2-
import { setupWithUrl } from "#dev/process";
2+
import { setup } from "#dev/process";
33
import { normalizeNewlines } from "#dev/utils";
44

5-
const { execBuild } = setupWithUrl(import.meta.url);
5+
const { execBuild } = setup(import.meta.dirname);
66

77
const { stderr } = await execBuild();
88

tests/build_tests/case2/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @ts-check
22

33
import * as assert from "node:assert";
4-
import { setupWithUrl } from "#dev/process";
4+
import { setup } from "#dev/process";
55
import { normalizeNewlines } from "#dev/utils";
66

7-
const { execBuild } = setupWithUrl(import.meta.url);
7+
const { execBuild } = setup(import.meta.dirname);
88

99
const { stderr } = await execBuild();
1010

tests/build_tests/case3/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import assert from "node:assert";
44
import fs from "node:fs/promises";
55
import path from "node:path";
6-
import { setupWithUrl } from "#dev/process";
6+
import { setup } from "#dev/process";
77

8-
const { execBuild } = setupWithUrl(import.meta.url);
8+
const { execBuild } = setup(import.meta.dirname);
99

1010
await execBuild();
1111

tests/build_tests/cli_compile_status/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @ts-check
22

33
import * as assert from "node:assert";
4-
import { setupWithUrl } from "#dev/process";
4+
import { setup } from "#dev/process";
55
import { normalizeNewlines } from "#dev/utils";
66

7-
const { rescript } = setupWithUrl(import.meta.url);
7+
const { rescript } = setup(import.meta.dirname);
88

99
// Shows compile time for `rescript build` command
1010
let out = await rescript("build");

tests/build_tests/cli_help/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @ts-check
22

33
import * as assert from "node:assert";
4-
import { setupWithUrl } from "#dev/process";
4+
import { setup } from "#dev/process";
55
import { normalizeNewlines } from "#dev/utils";
66

7-
const { rescript } = setupWithUrl(import.meta.url);
7+
const { rescript } = setup(import.meta.dirname);
88

99
const cliHelp =
1010
"Usage: rescript <options> <subcommand>\n" +

tests/build_tests/custom_namespace/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from "node:assert";
2-
import { setupWithUrl } from "#dev/process";
2+
import { setup } from "#dev/process";
33

4-
const { execClean, execBuild } = setupWithUrl(import.meta.url);
4+
const { execClean, execBuild } = setup(import.meta.dirname);
55

66
await execClean();
77
await execBuild();

tests/build_tests/cycle/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import * as assert from "node:assert";
44
import * as fs from "node:fs/promises";
55
import * as path from "node:path";
6-
import { setupWithUrl } from "#dev/process";
6+
import { setup } from "#dev/process";
77

8-
const { execBuild } = setupWithUrl(import.meta.url);
8+
const { execBuild } = setup(import.meta.dirname);
99

1010
const output = await execBuild();
1111

tests/build_tests/cycle1/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import * as assert from "node:assert";
44
import * as fs from "node:fs/promises";
55
import * as path from "node:path";
6-
import { setupWithUrl } from "#dev/process";
6+
import { setup } from "#dev/process";
77

8-
const { execBuild, execClean } = setupWithUrl(import.meta.url);
8+
const { execBuild, execClean } = setup(import.meta.dirname);
99

1010
await execClean();
1111
const output = await execBuild();

tests/build_tests/deprecated-package-specs/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @ts-check
22

33
import assert from "node:assert";
4-
import { setupWithUrl } from "#dev/process";
4+
import { setup } from "#dev/process";
55

6-
const { execBuild } = setupWithUrl(import.meta.url);
6+
const { execBuild } = setup(import.meta.dirname);
77

88
const out = await execBuild();
99
assert.match(

tests/build_tests/devonly/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

3-
import { setupWithUrl } from "#dev/process";
3+
import { setup } from "#dev/process";
44

5-
const { execBuild } = setupWithUrl(import.meta.url);
5+
const { execBuild } = setup(import.meta.dirname);
66

77
await execBuild();

tests/build_tests/duplicated_symlinked_packages/input.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// @ts-check
22

33
import * as fs from "node:fs/promises";
4-
import * as path from "node:path";
5-
import { fileURLToPath } from "node:url";
6-
import { setupWithUrl } from "#dev/process";
4+
import { setup } from "#dev/process";
75

8-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
9-
const { execBuild, execClean } = setupWithUrl(import.meta.url);
6+
const { execBuild, execClean } = setup(import.meta.dirname);
107

118
const expectedFilePath = "./out.expected";
129

@@ -17,7 +14,7 @@ const updateTests = process.argv[2] === "update";
1714
* @return {string}
1815
*/
1916
function postProcessErrorOutput(output) {
20-
return output.trimEnd().replace(new RegExp(__dirname, "gi"), ".");
17+
return output.trimEnd().replace(new RegExp(import.meta.dirname, "gi"), ".");
2118
}
2219

2320
if (process.platform === "win32") {

tests/build_tests/exports/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

3-
import { setupWithUrl } from "#dev/process";
3+
import { setup } from "#dev/process";
44

5-
const { execBuild } = setupWithUrl(import.meta.url);
5+
const { execBuild } = setup(import.meta.dirname);
66

77
await execBuild();

tests/build_tests/gpr_978/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import * as assert from "node:assert";
44
import * as fs from "node:fs/promises";
55
import * as path from "node:path";
6-
import { setupWithUrl } from "#dev/process";
6+
import { setup } from "#dev/process";
77

8-
const { execBuild } = setupWithUrl(import.meta.url);
8+
const { execBuild } = setup(import.meta.dirname);
99

1010
const output = await execBuild();
1111
assert.match(output.stdout, /M is exported twice/);

tests/build_tests/hyphen2/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

3-
import { setupWithUrl } from "#dev/process";
3+
import { setup } from "#dev/process";
44

5-
const { execBuild } = setupWithUrl(import.meta.url);
5+
const { execBuild } = setup(import.meta.dirname);
66

77
await execBuild();

tests/build_tests/in_source/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @ts-check
22

33
import * as assert from "node:assert";
4-
import { setupWithUrl } from "#dev/process";
4+
import { setup } from "#dev/process";
55

6-
const { execBuild } = setupWithUrl(import.meta.url);
6+
const { execBuild } = setup(import.meta.dirname);
77

88
const output = await execBuild(["-regen"]);
99
assert.match(output.stderr, /detected two module formats/);

tests/build_tests/install/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import * as assert from "node:assert";
44
import { existsSync } from "node:fs";
55
import * as path from "node:path";
6-
import { setupWithUrl } from "#dev/process";
6+
import { setup } from "#dev/process";
77

8-
const { execBuild, execClean } = setupWithUrl(import.meta.url);
8+
const { execBuild, execClean } = setup(import.meta.dirname);
99

1010
await execClean();
1111
await execBuild(["-install"]);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

3-
import { setupWithUrl } from "#dev/process";
3+
import { setup } from "#dev/process";
44

5-
const { execBuild } = setupWithUrl(import.meta.url);
5+
const { execBuild } = setup(import.meta.dirname);
66

77
await execBuild();

tests/build_tests/nested/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import * as assert from "node:assert";
44
import * as fs from "node:fs/promises";
55
import * as path from "node:path";
6-
import { setupWithUrl } from "#dev/process";
6+
import { setup } from "#dev/process";
77

8-
const { execBuild } = setupWithUrl(import.meta.url);
8+
const { execBuild } = setup(import.meta.dirname);
99

1010
await execBuild();
1111

tests/build_tests/nnest/input.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import * as assert from "node:assert";
44
import * as fs from "node:fs/promises";
55
import * as path from "node:path";
6-
import { setupWithUrl } from "#dev/process";
6+
import { setup } from "#dev/process";
77

8-
const { execBuild } = setupWithUrl(import.meta.url);
8+
const { execBuild } = setup(import.meta.dirname);
99

1010
await execBuild();
1111

@@ -20,12 +20,3 @@ assert.equal(content.match(/b0_main/g)?.length, 1);
2020

2121
const mod = await import("./src/demo.js");
2222
assert.equal(mod.v, 4, "nested");
23-
24-
// var testWarnError = /warnings\s*=\s*[^\r\n]*-warn-error/;
25-
26-
// function hasWarnError(file) {
27-
// var content = fs.readFileSync(file, "utf8");
28-
// return testWarnError.test(content);
29-
// }
30-
31-
// assert.ok(hasWarnError(path.join(__dirname,'lib','bs','build.ninja')))

tests/build_tests/ns/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

3-
import { setupWithUrl } from "#dev/process";
3+
import { setup } from "#dev/process";
44

5-
const { execBuild } = setupWithUrl(import.meta.url);
5+
const { execBuild } = setup(import.meta.dirname);
66

77
await execBuild();

tests/build_tests/post-build/input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @ts-check
22

33
import * as assert from "node:assert";
4-
import { setupWithUrl } from "#dev/process";
4+
import { setup } from "#dev/process";
55

6-
const { execBuild } = setupWithUrl(import.meta.url);
6+
const { execBuild } = setup(import.meta.dirname);
77

88
if (process.platform === "win32") {
99
console.log("Skipping test on Windows");

0 commit comments

Comments
 (0)