Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/oxlint/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules/
/dist/
/debug/
*.node
2 changes: 1 addition & 1 deletion apps/oxlint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
]
},
"imports": {
"#oxlint": "./dist/index.js"
"#oxlint": "./debug/index.js"
}
}
4 changes: 3 additions & 1 deletion apps/oxlint/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { copyFileSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path';

const oxlintDirPath = join(import.meta.dirname, '..'),
distDirPath = join(oxlintDirPath, 'dist');
distDirPath = join(oxlintDirPath, 'dist'),
debugDirPath = join(oxlintDirPath, 'debug');

// Modify `bindings.js` to use correct package names
console.log('Modifying bindings.js...');
Expand All @@ -26,6 +27,7 @@ const srcDirPath = join(oxlintDirPath, 'src-js');
for (const filename of readdirSync(srcDirPath)) {
if (!filename.endsWith('.node')) continue;
copyFileSync(join(srcDirPath, filename), join(distDirPath, filename));
copyFileSync(join(srcDirPath, filename), join(debugDirPath, filename));
}

console.log('Build complete!');
2 changes: 2 additions & 0 deletions apps/oxlint/src-js/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Global constant defined at build time by TSDown
declare const DEBUG: boolean;
13 changes: 10 additions & 3 deletions apps/oxlint/src-js/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ export function assertIs<T>(value: unknown): asserts value is T {}
/**
* Assert a value is not `null` or `undefined`.
*
* Has no runtime effect - only for guiding the type-checker.
* Minification removes this function and all calls to it, so it has zero runtime cost.
* In release builds, is a no-op. Only does runtime checks in debug builds.
* Minification removes this function and all calls to it in release builds, so it has zero runtime cost.
*
* @param value - Value
*/
// oxlint-disable-next-line no-unused-vars
export function assertIsNonNull<T>(value: T | null | undefined): asserts value is T {}
export function assertIsNonNull<T>(value: T | null | undefined): asserts value is T {
if (!DEBUG) return;

if (value === null || value === undefined) {
// oxlint-disable-next-line typescript/restrict-template-expressions
throw new Error(`Expected non-null value, got ${value}`);
}
}

/**
* Utility type to make specified properties of a type nullable.
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PACKAGE_ROOT_PATH, getFixtures, testFixtureWithCommand } from './utils.

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

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

// Use current NodeJS executable, rather than `node`, to avoid problems with a Node version manager
// installed on system resulting in using wrong NodeJS version
Expand Down
13 changes: 12 additions & 1 deletion apps/oxlint/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const commonConfig: UserConfig = {
mangle: false,
codegen: { removeWhitespace: false },
},
define: { DEBUG: 'false' },
};

// Only generate `.d.ts` file for main export, not for CLI
export default defineConfig([
const configs = defineConfig([
{
entry: 'src-js/cli.ts',
...commonConfig,
Expand All @@ -37,3 +38,13 @@ export default defineConfig([
attw: true,
},
]);

// Create separate debug build with debug assertions enabled
const debugConfigs = configs.map((config) => ({
...config,
outDir: 'debug',
define: { DEBUG: 'true' },
}));
configs.push(...debugConfigs);

export default configs;
3 changes: 3 additions & 0 deletions apps/oxlint/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export default defineConfig({
test: {
exclude: [...configDefaults.exclude, 'fixtures/**'],
},
define: {
DEBUG: 'true',
},
});
Loading