From 08928b413ae20a8288f0cbc6dded7419b46dd9be Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 31 Mar 2025 21:27:59 +0200 Subject: [PATCH 1/5] tools: enable linter in `test/fixtures/source-map/output` --- eslint.config.mjs | 3 +++ .../source_map_enabled_by_api_node_modules.js | 2 +- .../output/source_map_prepare_stack_trace.js | 2 +- .../output/source_map_throw_async_stack_trace.mjs | 13 ++++++++----- .../output/source_map_throw_async_stack_trace.mts | 5 ++++- .../output/source_map_throw_construct.mjs | 12 +++++++----- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 45ee3455226cab..e0dd35d616d9a8 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -53,6 +53,9 @@ export default [ // We want to lint only a few specific fixtures folders 'test/fixtures/*', '!test/fixtures/console', + '!test/fixtures/source-map', + 'test/fixtures/source-map/*', + '!test/fixtures/source-map/output', '!test/fixtures/v8', '!test/fixtures/vm', ]), diff --git a/test/fixtures/source-map/output/source_map_enabled_by_api_node_modules.js b/test/fixtures/source-map/output/source_map_enabled_by_api_node_modules.js index 5de2f3b0d7eb85..78633bef83e3b6 100644 --- a/test/fixtures/source-map/output/source_map_enabled_by_api_node_modules.js +++ b/test/fixtures/source-map/output/source_map_enabled_by_api_node_modules.js @@ -45,4 +45,4 @@ try { require('../node_modules/error-stack/enclosing-call-site-min.js').simpleErrorStack(); } catch (e) { console.log(e); -} \ No newline at end of file +} diff --git a/test/fixtures/source-map/output/source_map_prepare_stack_trace.js b/test/fixtures/source-map/output/source_map_prepare_stack_trace.js index 894aea60a96f18..9f3e0f45bf847c 100644 --- a/test/fixtures/source-map/output/source_map_prepare_stack_trace.js +++ b/test/fixtures/source-map/output/source_map_prepare_stack_trace.js @@ -9,7 +9,7 @@ Error.stackTraceLimit = 5; assert.strictEqual(typeof Error.prepareStackTrace, 'function'); const defaultPrepareStackTrace = Error.prepareStackTrace; Error.prepareStackTrace = (error, trace) => { - trace = trace.filter(it => { + trace = trace.filter((it) => { return it.getFunctionName() !== 'functionC'; }); return defaultPrepareStackTrace(error, trace); diff --git a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs index 8e3fefbebe4d5d..7f2b78e6b6e174 100644 --- a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs +++ b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs @@ -1,13 +1,16 @@ // Flags: --enable-source-maps import '../../../common/index.mjs'; async function Throw() { - await 0; - throw new Error('message'); + await 0; + throw new Error('message'); } +// eslint-disable-next-line node-core/async-iife-no-unused-result (async function main() { - await Promise.all([0, 1, 2, Throw()]); + await Promise.all([0, 1, 2, Throw()]); })(); // To recreate: // -// npx --package typescript tsc --module nodenext --target esnext --outDir test/fixtures/source-map/output --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts -//# sourceMappingURL=source_map_throw_async_stack_trace.mjs.map \ No newline at end of file +// npx --package typescript tsc --module nodenext --target esnext \ +// --outDir test/fixtures/source-map/output \ +// --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts +// # sourceMappingURL=source_map_throw_async_stack_trace.mjs.map diff --git a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts index 718f617928d5ce..260475ae4fe237 100644 --- a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts +++ b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts @@ -13,10 +13,13 @@ async function Throw() { throw new Error('message') } +// eslint-disable-next-line node-core/async-iife-no-unused-result (async function main() { await Promise.all([0, 1, 2, Throw()]); })() // To recreate: // -// npx --package typescript tsc --module nodenext --target esnext --outDir test/fixtures/source-map/output --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts +// npx --package typescript tsc --module nodenext --target esnext +// --outDir test/fixtures/source-map/output +// --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts diff --git a/test/fixtures/source-map/output/source_map_throw_construct.mjs b/test/fixtures/source-map/output/source_map_throw_construct.mjs index 24361da883da7c..68ac7c9930ba5e 100644 --- a/test/fixtures/source-map/output/source_map_throw_construct.mjs +++ b/test/fixtures/source-map/output/source_map_throw_construct.mjs @@ -1,12 +1,14 @@ // Flags: --enable-source-maps import '../../../common/index.mjs'; class Foo { - constructor() { - throw new Error('message'); - } + constructor() { + throw new Error('message'); + } } new Foo(); // To recreate: // -// npx --package typescript tsc --module nodenext --target esnext --outDir test/fixtures/source-map/output --sourceMap test/fixtures/source-map/output/source_map_throw_construct.mts -//# sourceMappingURL=source_map_throw_construct.mjs.map \ No newline at end of file +// npx --package typescript tsc --module nodenext --target esnext +// --outDir test/fixtures/source-map/output +// --sourceMap test/fixtures/source-map/output/source_map_throw_construct.mts +// # sourceMappingURL=source_map_throw_construct.mjs.map From 2d224f4e5cc6a0c87cd386d1c522f0c91a53f3ee Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 1 Apr 2025 13:53:35 +0200 Subject: [PATCH 2/5] fixup! tools: enable linter in `test/fixtures/source-map/output` --- eslint.config.mjs | 5 +++++ .../output/source_map_throw_async_stack_trace.mjs | 13 +++++-------- .../output/source_map_throw_async_stack_trace.mts | 5 +---- .../output/source_map_throw_construct.mjs | 12 +++++------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index e0dd35d616d9a8..6e451c948132c7 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,3 +1,4 @@ +import { readdirSync } from 'node:fs'; import Module from 'node:module'; import { fileURLToPath, URL } from 'node:url'; @@ -56,6 +57,10 @@ export default [ '!test/fixtures/source-map', 'test/fixtures/source-map/*', '!test/fixtures/source-map/output', + ...readdirSync('test/fixtures/source-map/output') + // We don't want to lint tsc output files + .filter((f, _, files) => f.endsWith('js') && files.includes(f.replace(/(\.[cm]?)js$/, '$1ts'))) + .map((f) => `test/fixtures/source-map/output/${f}`), '!test/fixtures/v8', '!test/fixtures/vm', ]), diff --git a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs index 7f2b78e6b6e174..8e3fefbebe4d5d 100644 --- a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs +++ b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mjs @@ -1,16 +1,13 @@ // Flags: --enable-source-maps import '../../../common/index.mjs'; async function Throw() { - await 0; - throw new Error('message'); + await 0; + throw new Error('message'); } -// eslint-disable-next-line node-core/async-iife-no-unused-result (async function main() { - await Promise.all([0, 1, 2, Throw()]); + await Promise.all([0, 1, 2, Throw()]); })(); // To recreate: // -// npx --package typescript tsc --module nodenext --target esnext \ -// --outDir test/fixtures/source-map/output \ -// --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts -// # sourceMappingURL=source_map_throw_async_stack_trace.mjs.map +// npx --package typescript tsc --module nodenext --target esnext --outDir test/fixtures/source-map/output --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts +//# sourceMappingURL=source_map_throw_async_stack_trace.mjs.map \ No newline at end of file diff --git a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts index 260475ae4fe237..718f617928d5ce 100644 --- a/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts +++ b/test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts @@ -13,13 +13,10 @@ async function Throw() { throw new Error('message') } -// eslint-disable-next-line node-core/async-iife-no-unused-result (async function main() { await Promise.all([0, 1, 2, Throw()]); })() // To recreate: // -// npx --package typescript tsc --module nodenext --target esnext -// --outDir test/fixtures/source-map/output -// --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts +// npx --package typescript tsc --module nodenext --target esnext --outDir test/fixtures/source-map/output --sourceMap test/fixtures/source-map/output/source_map_throw_async_stack_trace.mts diff --git a/test/fixtures/source-map/output/source_map_throw_construct.mjs b/test/fixtures/source-map/output/source_map_throw_construct.mjs index 68ac7c9930ba5e..24361da883da7c 100644 --- a/test/fixtures/source-map/output/source_map_throw_construct.mjs +++ b/test/fixtures/source-map/output/source_map_throw_construct.mjs @@ -1,14 +1,12 @@ // Flags: --enable-source-maps import '../../../common/index.mjs'; class Foo { - constructor() { - throw new Error('message'); - } + constructor() { + throw new Error('message'); + } } new Foo(); // To recreate: // -// npx --package typescript tsc --module nodenext --target esnext -// --outDir test/fixtures/source-map/output -// --sourceMap test/fixtures/source-map/output/source_map_throw_construct.mts -// # sourceMappingURL=source_map_throw_construct.mjs.map +// npx --package typescript tsc --module nodenext --target esnext --outDir test/fixtures/source-map/output --sourceMap test/fixtures/source-map/output/source_map_throw_construct.mts +//# sourceMappingURL=source_map_throw_construct.mjs.map \ No newline at end of file From fca609dcf70e5345544f9c1a432a0f21c9d803da Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 1 Apr 2025 13:57:13 +0200 Subject: [PATCH 3/5] fixup! fixup! tools: enable linter in `test/fixtures/source-map/output` --- eslint.config.mjs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 6e451c948132c7..4d3c2b93654940 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -26,6 +26,12 @@ const { default: stylisticJs } = await importEslintTool('@stylistic/eslint-plugi nodeCore.RULES_DIR = fileURLToPath(new URL('./tools/eslint-rules', import.meta.url)); +function filterFilesInDir(dirpath, filterFn) { + return readdirSync(dirpath) + .filter(filterFn) + .map((f) => `${dirpath}/${f}`) +} + // The Module._resolveFilename() monkeypatching is to make it so that ESLint is able to // dynamically load extra modules that we install with it. const ModuleResolveFilename = Module._resolveFilename; @@ -57,10 +63,11 @@ export default [ '!test/fixtures/source-map', 'test/fixtures/source-map/*', '!test/fixtures/source-map/output', - ...readdirSync('test/fixtures/source-map/output') - // We don't want to lint tsc output files - .filter((f, _, files) => f.endsWith('js') && files.includes(f.replace(/(\.[cm]?)js$/, '$1ts'))) - .map((f) => `test/fixtures/source-map/output/${f}`), + ...filterFilesInDir( + 'test/fixtures/source-map/output', + // Filtering tsc output files (i.e. if there a foo.ts, we ignore foo.js): + (f, _, files) => f.endsWith('js') && files.includes(f.replace(/(\.[cm]?)js$/, '$1ts')) + ), '!test/fixtures/v8', '!test/fixtures/vm', ]), From d7618deba1b442e0a9af104c453214b7911a64c5 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 1 Apr 2025 14:22:23 +0200 Subject: [PATCH 4/5] fixup! fixup! fixup! tools: enable linter in `test/fixtures/source-map/output` --- eslint.config.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 4d3c2b93654940..9f9aea2461317c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -29,7 +29,7 @@ nodeCore.RULES_DIR = fileURLToPath(new URL('./tools/eslint-rules', import.meta.u function filterFilesInDir(dirpath, filterFn) { return readdirSync(dirpath) .filter(filterFn) - .map((f) => `${dirpath}/${f}`) + .map((f) => `${dirpath}/${f}`); } // The Module._resolveFilename() monkeypatching is to make it so that ESLint is able to @@ -66,7 +66,7 @@ export default [ ...filterFilesInDir( 'test/fixtures/source-map/output', // Filtering tsc output files (i.e. if there a foo.ts, we ignore foo.js): - (f, _, files) => f.endsWith('js') && files.includes(f.replace(/(\.[cm]?)js$/, '$1ts')) + (f, _, files) => f.endsWith('js') && files.includes(f.replace(/(\.[cm]?)js$/, '$1ts')), ), '!test/fixtures/v8', '!test/fixtures/vm', From eb3dbad1e2a01d4685ffd225398a91c4ebe4c6f1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 4 Apr 2025 15:47:01 +0200 Subject: [PATCH 5/5] Update eslint.config.mjs --- eslint.config.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/eslint.config.mjs b/eslint.config.mjs index 24086a55872606..60a12481822c6a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -68,6 +68,7 @@ export default [ 'test/fixtures/source-map/output', // Filtering tsc output files (i.e. if there a foo.ts, we ignore foo.js): (f, _, files) => f.endsWith('js') && files.includes(f.replace(/(\.[cm]?)js$/, '$1ts')), + ), '!test/fixtures/test-runner', 'test/fixtures/test-runner/*', '!test/fixtures/test-runner/output',