Skip to content

Commit 80fe39d

Browse files
committed
build(linter/plugins): build either release or debug version, not both (#15949)
#15921 added a debug build for Oxlint, and various PRs since have tweaked it. However, I now realize there's little point in generating *both* a release build and debug build. Just create one build, and use env var `DEBUG` to control whether it has debug assertions included in it or not. `pnpm run build` produces release build with no debug assertions, `pnpm run build-test` includes the asserts. I've verified that both do what they're meant to.
1 parent 48d18e0 commit 80fe39d

File tree

8 files changed

+23
-28
lines changed

8 files changed

+23
-28
lines changed

apps/oxlint/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/node_modules/
22
/dist/
3-
/debug/
43
*.node

apps/oxlint/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"license": "MIT",
99
"scripts": {
1010
"build": "pnpm run build-napi-release && pnpm run build-js",
11-
"build-dev": "pnpm run build-napi && pnpm run build-js",
12-
"build-test": "pnpm run build-napi-test && pnpm run build-js",
11+
"build-dev": "pnpm run build-napi && cross-env DEBUG=true pnpm run build-js",
12+
"build-test": "pnpm run build-napi-test && cross-env DEBUG=true pnpm run build-js",
1313
"build-napi": "napi build --esm --platform --js ./bindings.js --dts ./bindings.d.ts --output-dir src-js --no-dts-cache",
1414
"build-napi-test": "pnpm run build-napi --features force_test_reporter",
1515
"build-napi-release": "pnpm run build-napi --release --features allocator",
@@ -24,6 +24,7 @@
2424
"@types/estree": "^1.0.8",
2525
"@typescript-eslint/scope-manager": "8.46.2",
2626
"@typescript-eslint/typescript-estree": "^8.47.0",
27+
"cross-env": "catalog:",
2728
"eslint": "^9.36.0",
2829
"esquery": "^1.6.0",
2930
"execa": "^9.6.0",
@@ -49,6 +50,6 @@
4950
]
5051
},
5152
"imports": {
52-
"#oxlint": "./debug/index.js"
53+
"#oxlint": "./dist/index.js"
5354
}
5455
}

apps/oxlint/scripts/build.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { join } from 'node:path';
44

55
const oxlintDirPath = join(import.meta.dirname, '..'),
66
srcDirPath = join(oxlintDirPath, 'src-js'),
7-
distDirPath = join(oxlintDirPath, 'dist'),
8-
debugDirPath = join(oxlintDirPath, 'debug');
7+
distDirPath = join(oxlintDirPath, 'dist');
98

109
// Modify `bindings.js` to use correct package names
1110
console.log('Modifying bindings.js...');
@@ -24,15 +23,13 @@ execSync('pnpm tsdown', { stdio: 'inherit', cwd: oxlintDirPath });
2423
// Delete `cli.d.ts`
2524
console.log('Deleting cli.d.ts...');
2625
rmSync(join(distDirPath, 'cli.d.ts'));
27-
rmSync(join(debugDirPath, 'cli.d.ts'));
2826

2927
// Copy native `.node` files from `src-js`
3028
console.log('Copying `.node` files...');
3129
for (const filename of readdirSync(srcDirPath)) {
3230
if (!filename.endsWith('.node')) continue;
3331
const srcPath = join(srcDirPath, filename);
3432
copyFileSync(srcPath, join(distDirPath, filename));
35-
copyFileSync(srcPath, join(debugDirPath, filename));
3633
}
3734

3835
console.log('Build complete!');

apps/oxlint/test/e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PACKAGE_ROOT_PATH, getFixtures, testFixtureWithCommand } from './utils.
44

55
import type { Fixture } from './utils.ts';
66

7-
const CLI_PATH = pathJoin(PACKAGE_ROOT_PATH, 'debug/cli.js');
7+
const CLI_PATH = pathJoin(PACKAGE_ROOT_PATH, 'dist/cli.js');
88

99
// Use current NodeJS executable, rather than `node`, to avoid problems with a Node version manager
1010
// installed on system resulting in using wrong NodeJS version

apps/oxlint/tsdown.config.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import { defineConfig } from 'tsdown';
33

44
import type { Plugin } from 'rolldown';
55

6-
const ASSERTS_PATH = join(import.meta.dirname, 'src-js/utils/asserts.ts');
6+
// When run with `DEBUG=true pnpm run build-js`, generate a debug build with extra assertions.
7+
// This is the build used in tests.
8+
const DEBUG = process.env.DEBUG === 'true' || process.env.DEBUG === '1';
79

8-
const replaceAssertsPlugin = createReplaceAssertsPlugin();
9-
const plugins = [replaceAssertsPlugin];
10-
11-
const config = defineConfig({
10+
export default defineConfig({
1211
entry: ['src-js/cli.ts', 'src-js/index.ts'],
1312
format: 'esm',
1413
platform: 'node',
@@ -34,24 +33,14 @@ const config = defineConfig({
3433
},
3534
dts: { resolve: true },
3635
attw: true,
37-
define: { DEBUG: 'false' },
38-
plugins,
36+
define: { DEBUG: DEBUG ? 'true' : 'false' },
37+
plugins: DEBUG ? [] : [createReplaceAssertsPlugin()],
3938
inputOptions: {
4039
// For `replaceAssertsPlugin`
4140
experimental: { nativeMagicString: true },
4241
},
4342
});
4443

45-
// Create separate debug build with debug assertions enabled
46-
const debugConfig = defineConfig({
47-
...config,
48-
outDir: 'debug',
49-
define: { DEBUG: 'true' },
50-
plugins: plugins.filter((plugin) => plugin !== replaceAssertsPlugin),
51-
});
52-
53-
export default [config, debugConfig];
54-
5544
/**
5645
* Create a plugin to remove imports of `assert*` functions from `src-js/utils/asserts.ts`,
5746
* and replace those imports with empty function declarations.
@@ -77,6 +66,8 @@ export default [config, debugConfig];
7766
* @returns Plugin
7867
*/
7968
function createReplaceAssertsPlugin(): Plugin {
69+
const ASSERTS_PATH = join(import.meta.dirname, 'src-js/utils/asserts.ts');
70+
8071
return {
8172
name: 'replace-asserts',
8273
transform: {

editors/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
"@vscode/test-cli": "^0.0.12",
260260
"@vscode/test-electron": "^2.4.1",
261261
"@vscode/vsce": "^3.0.0",
262-
"cross-env": "^10.0.0",
262+
"cross-env": "catalog:",
263263
"ovsx": "^0.10.0",
264264
"rolldown": "1.0.0-beta.51",
265265
"tinyglobby": "^0.2.15",

pnpm-lock.yaml

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ catalog:
1212
'@napi-rs/cli': 3.4.1
1313
'@napi-rs/wasm-runtime': 1.0.7
1414
'@types/node': ^24.0.0
15+
cross-env: ^10.1.0
1516
publint: 0.3.15
1617
rolldown: 1.0.0-beta.51
1718
tsdown: 0.16.6

0 commit comments

Comments
 (0)