Skip to content

Commit cc0019f

Browse files
committed
refactor(napi): move scripts into scripts directory (#14048)
Move all build scripts in `napi` packages into a `scripts` dir. These packages don't have root directories with tons of files like `napi/parser` and `apps/oxlint` do, but IMO it's preferable to have a consistent directory structure in all NAPI packages. Also, rename these scripts from `.mjs` to `.js`, since these packages are ESM.
1 parent 2f9e16d commit cc0019f

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

napi/minify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build-dev": "napi build --esm --platform",
99
"build-test": "pnpm run build-dev",
1010
"build": "pnpm run build-dev --features allocator --release",
11-
"postbuild-dev": "node patch.mjs",
11+
"postbuild-dev": "node scripts/patch.js",
1212
"test": "tsc && vitest run --dir ./test"
1313
},
1414
"engines": {

napi/minify/patch.mjs renamed to napi/minify/scripts/patch.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import fs from 'node:fs';
2+
import { join as pathJoin } from 'node:path';
23

3-
const filename = './index.js';
4-
let data = fs.readFileSync(filename, 'utf-8');
4+
const path = pathJoin(import.meta.dirname, '../index.js');
5+
6+
let data = fs.readFileSync(path, 'utf-8');
57
data = data.replace(
68
'\nif (!nativeBinding) {',
79
(s) =>
@@ -15,4 +17,4 @@ if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
1517
}
1618
` + s,
1719
);
18-
fs.writeFileSync(filename, data);
20+
fs.writeFileSync(path, data);

napi/parser/src-js/wrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function wrap(result) {
2020
};
2121
}
2222

23-
// Used by `napi/playground/patch.mjs`.
23+
// Used by `napi/playground/scripts/patch.js`.
2424
//
2525
// Set `value` field of `Literal`s which are `BigInt`s or `RegExp`s.
2626
//

napi/playground/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
},
1515
"scripts": {
1616
"build-test": "echo 'Skipped because there are no tests.'",
17-
"build-dev": "pnpm run build:napi && node patch.mjs",
18-
"build": "pnpm run build:napi --release && node patch.mjs",
17+
"build-dev": "pnpm run build:napi && node scripts/patch.js",
18+
"build": "pnpm run build:napi --release && node scripts/patch.js",
1919
"build:napi": "napi build --platform --esm --target wasm32-wasip1-threads"
2020
},
2121
"dependencies": {

napi/playground/patch.mjs renamed to napi/playground/scripts/patch.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import fs from 'node:fs';
2+
import { join as pathJoin } from 'node:path';
23

3-
const filename = './playground.wasi-browser.js';
4-
let data = fs.readFileSync(filename, 'utf-8');
4+
const path = pathJoin(import.meta.dirname, '../playground.wasi-browser.js');
5+
6+
let data = fs.readFileSync(path, 'utf-8');
57
data = data.replace(
68
`export const Oxc = __napiModule.exports.Oxc`,
79
`
@@ -24,4 +26,4 @@ export function Oxc() {
2426
}
2527
`,
2628
);
27-
fs.writeFileSync(filename, data);
29+
fs.writeFileSync(path, data);

napi/transform/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build-dev": "napi build --esm --platform",
99
"build-test": "pnpm run build-dev",
1010
"build": "pnpm run build-dev --features allocator --release",
11-
"postbuild-dev": "node patch.mjs",
11+
"postbuild-dev": "node scripts/patch.js",
1212
"test": "tsc && vitest run --dir ./test"
1313
},
1414
"engines": {

napi/transform/patch.mjs renamed to napi/transform/scripts/patch.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import fs from 'node:fs';
2+
import { join as pathJoin } from 'node:path';
23

3-
const filename = './index.js';
4-
let data = fs.readFileSync(filename, 'utf-8');
4+
const path = pathJoin(import.meta.dirname, '../index.js');
5+
6+
let data = fs.readFileSync(path, 'utf-8');
57
data = data.replace(
68
'\nif (!nativeBinding) {',
79
(s) =>
@@ -15,4 +17,4 @@ if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
1517
}
1618
` + s,
1719
);
18-
fs.writeFileSync(filename, data);
20+
fs.writeFileSync(path, data);

0 commit comments

Comments
 (0)