From 8fb746eccd6d11ae01e422460b64c9f6bf0b1812 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Dec 2024 20:32:08 +0100 Subject: [PATCH 1/7] ci: update node to v22 (v1) --- .github/workflows/ci.yml | 8 ++++---- .nvmrc | 1 + test/__snapshots__/fixtures.test.ts.snap | 24 ++++++++++++++++++------ test/fixtures.test.ts | 2 ++ 4 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 .nvmrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4eba0eaf..717fe1d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - node: [18, 20] + node: [22] fail-fast: false steps: @@ -28,15 +28,15 @@ jobs: node-version: ${{ matrix.node }} cache: "pnpm" - uses: oven-sh/setup-bun@v2 - if: ${{ matrix.os != 'windows-latest' && matrix.node == 20 }} + if: ${{ matrix.os != 'windows-latest' && matrix.node == 22 }} with: bun-version: latest - run: pnpm install - run: pnpm lint - if: ${{ matrix.os != 'windows-latest' && matrix.node == 20 }} + if: ${{ matrix.os != 'windows-latest' && matrix.node == 22 }} - run: pnpm build - run: pnpm vitest run --coverage - run: pnpm test:bun --coverage - if: ${{ matrix.os != 'windows-latest' && matrix.node == 20 }} + if: ${{ matrix.os != 'windows-latest' && matrix.node == 22 }} # - name: Coverage # uses: codecov/codecov-action@v1 diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..2bd5a0a9 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index 30815bcf..da68954d 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -22,9 +22,11 @@ Error: ParseError: \`import\` can only be used in \`import /index.ts at Object. (/bin/jiti) at Module._compile (internal/modules/cjs/loader) - at Module._extensions..js (internal/modules/cjs/loader) + at Object..js (internal/modules/cjs/loader) at Module.load (internal/modules/cjs/loader) - at Module._load (internal/modules/cjs/loader) + at Function._load (internal/modules/cjs/loader) + at TracingChannel.traceSync (node:diagnostics_channel) + at wrapModuleLoad (internal/modules/cjs/loader) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main) at internal/main/run_main_module @@ -47,9 +49,11 @@ TypeError: The "listener" argument must be of type function. Received undefined at jiti (/dist/jiti) at Object. (/bin/jiti) at Module._compile (internal/modules/cjs/loader) - at Module._extensions..js (internal/modules/cjs/loader) + at Object..js (internal/modules/cjs/loader) at Module.load (internal/modules/cjs/loader) - at Module._load (internal/modules/cjs/loader) + at Function._load (internal/modules/cjs/loader) + at TracingChannel.traceSync (node:diagnostics_channel) + at wrapModuleLoad (internal/modules/cjs/loader) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main) at internal/main/run_main_module { code: 'ERR_INVALID_ARG_TYPE' @@ -74,9 +78,11 @@ exports[`fixtures > esm > stdout 1`] = ` 'at jiti (/dist/jiti)', 'at Object. (/bin/jiti)', 'at Module._compile (internal/modules/cjs/loader)', - 'at Module._extensions..js (internal/modules/cjs/loader)', + 'at Object..js (internal/modules/cjs/loader)', 'at Module.load (internal/modules/cjs/loader)', - 'at Module._load (internal/modules/cjs/loader)', + 'at Function._load (internal/modules/cjs/loader)', + 'at TracingChannel.traceSync (node:diagnostics_channel)', + 'at wrapModuleLoad (internal/modules/cjs/loader)', 'at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main)', 'at internal/main/run_main_module' ] @@ -99,6 +105,12 @@ Required : { test: 123 } .default: { test: 123 } Dynamic Imported : { test: 123 } .default: { test: 123 }" `; +exports[`fixtures > mixed > mixed-stderr 1`] = ` +"(node:47936) ExperimentalWarning: CommonJS module /index.js is loading ES Module /esm.js using require(). +Support for loading ES Module in require() is an experimental feature and might change at any time +(Use \`node --trace-warnings ...\` to show where the warning was created)" +`; + exports[`fixtures > mixed > stdout 1`] = `"Mixed works for: "`; exports[`fixtures > native > stdout 1`] = `"[Module: null prototype] { default: { hasRequire: false } }"`; diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 822f155f..66c251a2 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -47,6 +47,8 @@ describe("fixtures", async () => { if (name.includes("error")) { expect(cleanUpSnap(stderr)).toMatchSnapshot("stderr"); + } else if (name === "mixed") { + expect(cleanUpSnap(stderr)).toMatchSnapshot("mixed-stderr"); } else { // expect no error expect(stderr).toBe(""); From e56b92609e252710d99b8dba81b2207c94c905c1 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Dec 2024 20:40:00 +0100 Subject: [PATCH 2/7] update snapshot test --- .github/workflows/ci.yml | 2 +- test/__snapshots__/fixtures.test.ts.snap | 24 ++++++------------------ test/fixtures.test.ts | 4 +++- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 717fe1d3..9ac525c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - node: [22] + node: [18, 20, 22] fail-fast: false steps: diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index da68954d..30815bcf 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -22,11 +22,9 @@ Error: ParseError: \`import\` can only be used in \`import /index.ts at Object. (/bin/jiti) at Module._compile (internal/modules/cjs/loader) - at Object..js (internal/modules/cjs/loader) + at Module._extensions..js (internal/modules/cjs/loader) at Module.load (internal/modules/cjs/loader) - at Function._load (internal/modules/cjs/loader) - at TracingChannel.traceSync (node:diagnostics_channel) - at wrapModuleLoad (internal/modules/cjs/loader) + at Module._load (internal/modules/cjs/loader) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main) at internal/main/run_main_module @@ -49,11 +47,9 @@ TypeError: The "listener" argument must be of type function. Received undefined at jiti (/dist/jiti) at Object. (/bin/jiti) at Module._compile (internal/modules/cjs/loader) - at Object..js (internal/modules/cjs/loader) + at Module._extensions..js (internal/modules/cjs/loader) at Module.load (internal/modules/cjs/loader) - at Function._load (internal/modules/cjs/loader) - at TracingChannel.traceSync (node:diagnostics_channel) - at wrapModuleLoad (internal/modules/cjs/loader) + at Module._load (internal/modules/cjs/loader) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main) at internal/main/run_main_module { code: 'ERR_INVALID_ARG_TYPE' @@ -78,11 +74,9 @@ exports[`fixtures > esm > stdout 1`] = ` 'at jiti (/dist/jiti)', 'at Object. (/bin/jiti)', 'at Module._compile (internal/modules/cjs/loader)', - 'at Object..js (internal/modules/cjs/loader)', + 'at Module._extensions..js (internal/modules/cjs/loader)', 'at Module.load (internal/modules/cjs/loader)', - 'at Function._load (internal/modules/cjs/loader)', - 'at TracingChannel.traceSync (node:diagnostics_channel)', - 'at wrapModuleLoad (internal/modules/cjs/loader)', + 'at Module._load (internal/modules/cjs/loader)', 'at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main)', 'at internal/main/run_main_module' ] @@ -105,12 +99,6 @@ Required : { test: 123 } .default: { test: 123 } Dynamic Imported : { test: 123 } .default: { test: 123 }" `; -exports[`fixtures > mixed > mixed-stderr 1`] = ` -"(node:47936) ExperimentalWarning: CommonJS module /index.js is loading ES Module /esm.js using require(). -Support for loading ES Module in require() is an experimental feature and might change at any time -(Use \`node --trace-warnings ...\` to show where the warning was created)" -`; - exports[`fixtures > mixed > stdout 1`] = `"Mixed works for: "`; exports[`fixtures > native > stdout 1`] = `"[Module: null prototype] { default: { hasRequire: false } }"`; diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 66c251a2..1cd71977 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -3,6 +3,8 @@ import { execa } from "execa"; import { describe, it, expect } from "vitest"; import fg from "fast-glob"; +const nodeMajor = parseInt(process.version.slice(1), 10); + describe("fixtures", async () => { const jitiPath = resolve(__dirname, "../bin/jiti.js"); @@ -47,7 +49,7 @@ describe("fixtures", async () => { if (name.includes("error")) { expect(cleanUpSnap(stderr)).toMatchSnapshot("stderr"); - } else if (name === "mixed") { + } else if (name === "mixed" && nodeMajor >= 22) { expect(cleanUpSnap(stderr)).toMatchSnapshot("mixed-stderr"); } else { // expect no error From 87b2ac48c2d0e2890f498838d9a96952d4b8dec9 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 19:40:40 +0000 Subject: [PATCH 3/7] chore: apply automated lint fixes --- test/fixtures.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 1cd71977..26f74c22 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -3,7 +3,7 @@ import { execa } from "execa"; import { describe, it, expect } from "vitest"; import fg from "fast-glob"; -const nodeMajor = parseInt(process.version.slice(1), 10); +const nodeMajor = Number.parseInt(process.version.slice(1), 10); describe("fixtures", async () => { const jitiPath = resolve(__dirname, "../bin/jiti.js"); From a980ddcab60953b301647c5d065a96dfa3ac1fbf Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Dec 2024 20:57:35 +0100 Subject: [PATCH 4/7] update fixture test --- test/__snapshots__/fixtures.test.ts.snap | 47 ++++-------------------- test/fixtures.test.ts | 14 +++++-- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index 30815bcf..477d3edd 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -13,49 +13,18 @@ import.meta.env.TEST true import.meta.env?.TEST true" `; -exports[`fixtures > error-parse > stderr 1`] = ` -"/lib/index.js:2 - throw err; /* ↓ Check stack trace ↓ */ - ^ - -Error: ParseError: \`import\` can only be used in \`import - /index.ts - at Object. (/bin/jiti) - at Module._compile (internal/modules/cjs/loader) - at Module._extensions..js (internal/modules/cjs/loader) - at Module.load (internal/modules/cjs/loader) - at Module._load (internal/modules/cjs/loader) - at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main) - at internal/main/run_main_module - -Node.js v" +exports[`fixtures > error-parse > errors 1`] = ` +[ + "Error: ParseError: \`import\` can only be used in \`import ", +] `; exports[`fixtures > error-parse > stdout 1`] = `""`; -exports[`fixtures > error-runtime > stderr 1`] = ` -"/lib/index.js:2 - throw err; /* ↓ Check stack trace ↓ */ - ^ - -TypeError: The "listener" argument must be of type function. Received undefined - at checkListener (events) - at _addListener (events) - at process.addListener (events) - at /index.ts - at evalModule (/dist/jiti) - at jiti (/dist/jiti) - at Object. (/bin/jiti) - at Module._compile (internal/modules/cjs/loader) - at Module._extensions..js (internal/modules/cjs/loader) - at Module.load (internal/modules/cjs/loader) - at Module._load (internal/modules/cjs/loader) - at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main) - at internal/main/run_main_module { - code: 'ERR_INVALID_ARG_TYPE' -} - -Node.js v" +exports[`fixtures > error-runtime > errors 1`] = ` +[ + "TypeError: The "listener" argument must be of type function. Received undefined", +] `; exports[`fixtures > error-runtime > stdout 1`] = `""`; diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 26f74c22..9fa5348c 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -37,6 +37,14 @@ describe("fixtures", async () => { .trim(); } + function extractErrors(message: string) { + const errors = [] as string[]; + for (const m of message.matchAll(/\w*Error.*:.*$/gm)) { + errors.push(m[0]); + } + return errors; + } + const { stdout, stderr } = await execa("node", [jitiPath, fixtureEntry], { cwd, stdio: "pipe", @@ -48,11 +56,11 @@ describe("fixtures", async () => { }); if (name.includes("error")) { - expect(cleanUpSnap(stderr)).toMatchSnapshot("stderr"); + expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("errors"); } else if (name === "mixed" && nodeMajor >= 22) { - expect(cleanUpSnap(stderr)).toMatchSnapshot("mixed-stderr"); + expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("errors"); } else { - // expect no error + // Expect no error by default expect(stderr).toBe(""); } From 73cdd070f30c14c73b91d72086c8dffaeca1786a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Dec 2024 21:07:38 +0100 Subject: [PATCH 5/7] update --- test/__snapshots__/fixtures.test.ts.snap | 20 +++----------------- test/fixtures.test.ts | 4 ++-- test/fixtures/esm/test.js | 4 ---- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index 477d3edd..ca7c3a5d 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -13,7 +13,7 @@ import.meta.env.TEST true import.meta.env?.TEST true" `; -exports[`fixtures > error-parse > errors 1`] = ` +exports[`fixtures > error-parse > stderr 1`] = ` [ "Error: ParseError: \`import\` can only be used in \`import ", ] @@ -21,7 +21,7 @@ exports[`fixtures > error-parse > errors 1`] = ` exports[`fixtures > error-parse > stdout 1`] = `""`; -exports[`fixtures > error-runtime > errors 1`] = ` +exports[`fixtures > error-runtime > stderr 1`] = ` [ "TypeError: The "listener" argument must be of type function. Received undefined", ] @@ -34,21 +34,7 @@ exports[`fixtures > esm > stdout 1`] = ` { file: '/test.js', dir: '', - 'import.meta.url': 'file:///test.js', - stack: [ - 'at getStack (/test)', - 'at test (/test)', - 'at /index.js', - 'at evalModule (/dist/jiti)', - 'at jiti (/dist/jiti)', - 'at Object. (/bin/jiti)', - 'at Module._compile (internal/modules/cjs/loader)', - 'at Module._extensions..js (internal/modules/cjs/loader)', - 'at Module.load (internal/modules/cjs/loader)', - 'at Module._load (internal/modules/cjs/loader)', - 'at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main)', - 'at internal/main/run_main_module' - ] + 'import.meta.url': 'file:///test.js' }" `; diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 9fa5348c..71f342c0 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -56,9 +56,9 @@ describe("fixtures", async () => { }); if (name.includes("error")) { - expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("errors"); + expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("stderr"); } else if (name === "mixed" && nodeMajor >= 22) { - expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("errors"); + expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("stderr"); } else { // Expect no error by default expect(stderr).toBe(""); diff --git a/test/fixtures/esm/test.js b/test/fixtures/esm/test.js index c8eaf962..806819df 100644 --- a/test/fixtures/esm/test.js +++ b/test/fixtures/esm/test.js @@ -5,9 +5,5 @@ export default function test() { file: __filename, dir: __dirname, "import.meta.url": import.meta.url, - stack: getStack() - .split("\n") - .splice(1) - .map((s) => s.trim()), }; } From 5fdfaf7c3ae3e036b4794b511fe007a2bb63975f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Dec 2024 21:09:38 +0100 Subject: [PATCH 6/7] update snapshot --- test/__snapshots__/fixtures.test.ts.snap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index ca7c3a5d..0eecf988 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -54,6 +54,8 @@ Required : { test: 123 } .default: { test: 123 } Dynamic Imported : { test: 123 } .default: { test: 123 }" `; +exports[`fixtures > mixed > stderr 1`] = `[]`; + exports[`fixtures > mixed > stdout 1`] = `"Mixed works for: "`; exports[`fixtures > native > stdout 1`] = `"[Module: null prototype] { default: { hasRequire: false } }"`; From ad5ccabdc71d14fe1b4655e535f1608f17ba9640 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Dec 2024 21:11:34 +0100 Subject: [PATCH 7/7] update snapshot --- test/__snapshots__/fixtures.test.ts.snap | 6 +++++- test/fixtures.test.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/__snapshots__/fixtures.test.ts.snap b/test/__snapshots__/fixtures.test.ts.snap index 0eecf988..51ce7af6 100644 --- a/test/__snapshots__/fixtures.test.ts.snap +++ b/test/__snapshots__/fixtures.test.ts.snap @@ -54,7 +54,11 @@ Required : { test: 123 } .default: { test: 123 } Dynamic Imported : { test: 123 } .default: { test: 123 }" `; -exports[`fixtures > mixed > stderr 1`] = `[]`; +exports[`fixtures > mixed > stderr 1`] = ` +[ + "ExperimentalWarning: CommonJS module /index.js is loading ES Module /esm.js using require().", +] +`; exports[`fixtures > mixed > stdout 1`] = `"Mixed works for: "`; diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts index 71f342c0..f08a22ff 100644 --- a/test/fixtures.test.ts +++ b/test/fixtures.test.ts @@ -39,7 +39,7 @@ describe("fixtures", async () => { function extractErrors(message: string) { const errors = [] as string[]; - for (const m of message.matchAll(/\w*Error.*:.*$/gm)) { + for (const m of message.matchAll(/\w*(Error|Warning).*:.*$/gm)) { errors.push(m[0]); } return errors; @@ -58,6 +58,7 @@ describe("fixtures", async () => { if (name.includes("error")) { expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("stderr"); } else if (name === "mixed" && nodeMajor >= 22) { + console.log(stderr); expect(extractErrors(cleanUpSnap(stderr))).toMatchSnapshot("stderr"); } else { // Expect no error by default