Skip to content

Commit 2e258b0

Browse files
committed
use import.meta.dirname
1 parent b089269 commit 2e258b0

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

0 commit comments

Comments
 (0)