diff --git a/package.json b/package.json index b8bdea3..dd33bba 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "test": "node --loader @esbuild-kit/esm-loader tests" }, "dependencies": { - "@esbuild-kit/core-utils": "^1.3.1", + "@esbuild-kit/core-utils": "^1.3.3", "get-tsconfig": "^4.0.0" }, "devDependencies": { @@ -44,6 +44,7 @@ "manten": "^0.1.0", "pkgroll": "^1.3.0", "semver": "^7.3.7", + "source-map-support": "^0.5.21", "type-fest": "^2.12.2", "typescript": "^4.6.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 237cfa0..c53746d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,7 +1,7 @@ lockfileVersion: 5.4 specifiers: - '@esbuild-kit/core-utils': ^1.3.1 + '@esbuild-kit/core-utils': ^1.3.3 '@pvtnbr/eslint-config': ^0.22.0 '@types/node': ^17.0.33 '@types/semver': ^7.3.9 @@ -12,11 +12,12 @@ specifiers: manten: ^0.1.0 pkgroll: ^1.3.0 semver: ^7.3.7 + source-map-support: ^0.5.21 type-fest: ^2.12.2 typescript: ^4.6.4 dependencies: - '@esbuild-kit/core-utils': 1.3.1 + '@esbuild-kit/core-utils': 1.3.3 get-tsconfig: 4.0.0 devDependencies: @@ -29,6 +30,7 @@ devDependencies: manten: 0.1.0 pkgroll: 1.3.0_typescript@4.6.4 semver: 7.3.7 + source-map-support: 0.5.21 type-fest: 2.12.2 typescript: 4.6.4 @@ -55,8 +57,8 @@ packages: js-tokens: 4.0.0 dev: true - /@esbuild-kit/core-utils/1.3.1: - resolution: {integrity: sha512-QXWJKf3mEIs+jgUCrY2YWJ2cr9e9asRYRwDhxit+wkCaQbSfV6fCCgs8KjRsrkIdMBcWsjbWnFKfwZ9kjILPrw==} + /@esbuild-kit/core-utils/1.3.3: + resolution: {integrity: sha512-LBpZunrStkP3N1qA+cTx+M4K1lpmJw9f0kqS1mauItjFqUbajCDON1ZXKm/kFYxR1/whsNvtU9Ohv8qhtrFR9w==} dependencies: esbuild: 0.14.38 source-map-support: 0.5.21 @@ -623,7 +625,6 @@ packages: /buffer-from/1.1.2: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} - dev: false /buffer/5.7.1: resolution: {integrity: sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==} @@ -3317,12 +3318,10 @@ packages: dependencies: buffer-from: 1.1.2 source-map: 0.6.1 - dev: false /source-map/0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} - dev: false /sourcemap-codec/1.4.8: resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==} diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 188c476..184fe20 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -1,6 +1,9 @@ import { testSuite, expect } from 'manten'; +import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader'; +const nodeSupportsSourceMap = '^14.18.0 || >=16.6.0'; + export default testSuite(async ({ describe }, node: NodeApis) => { describe('.ts extension', ({ describe }) => { const output = 'loaded ts-ext-ts/index.ts {"nodePrefix":true,"hasDynamicImport":true,"nameInError":true,"sourceMap":true}'; @@ -13,6 +16,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toBe(output); }); + if (semver.satisfies(node.version, nodeSupportsSourceMap)) { + test('Disables native source map if Error.prepareStackTrace is customized', async () => { + const nodeProcess = await node.load(importPath, { + nodeOptions: ['-r', 'source-map-support/register'], + }); + expect(nodeProcess.stdout).toBe(output); + }); + } + test('Import', async () => { const nodeProcess = await node.import(importPath); expect(nodeProcess.stdout).toBe(`${output}\n{"default":1234}`); diff --git a/tests/utils/node-with-loader.ts b/tests/utils/node-with-loader.ts index d4cd60d..49ae43d 100644 --- a/tests/utils/node-with-loader.ts +++ b/tests/utils/node-with-loader.ts @@ -7,6 +7,7 @@ type Options = { args: string[]; nodePath: string; cwd?: string; + nodeOptions?: string[]; }; const __dirname = fileURLToPath(import.meta.url); @@ -21,6 +22,8 @@ export const nodeWithLoader = ( ESBK_DISABLE_CACHE: '1', }, nodeOptions: [ + ...(options.nodeOptions ?? []), + '--loader', pathToFileURL( path.resolve(__dirname, '../../../dist/index.js'), @@ -44,6 +47,7 @@ export async function createNode( filePath: string, options?: { cwd?: string; + nodeOptions?: string[]; }, ) { return nodeWithLoader( @@ -51,6 +55,7 @@ export async function createNode( args: [filePath], nodePath: node.path, cwd: path.join(fixturePath, options?.cwd ?? ''), + nodeOptions: options?.nodeOptions, }, ); },