Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
abae165
feat: upgrade core-utils
privatenumber Sep 30, 2022
d8db40b
Merge branch 'develop' of github.com:esbuild-kit/cjs-loader into upgr…
privatenumber Sep 30, 2022
681569e
chore: use new applySourceMap
privatenumber Oct 4, 2022
cd892d1
chore: test core-utils
privatenumber Oct 5, 2022
c4f0163
chore: test core-utils
privatenumber Oct 5, 2022
e72e891
Merge branch 'develop' of github.com:esbuild-kit/cjs-loader into upgr…
privatenumber Oct 5, 2022
bfeeadb
test: check soure map file path
privatenumber Oct 6, 2022
213a390
wip
privatenumber Oct 6, 2022
9d224dd
wip
privatenumber Oct 6, 2022
4631c72
wip
privatenumber Oct 6, 2022
aa55414
wip
privatenumber Oct 6, 2022
1190ebc
wip
privatenumber Oct 6, 2022
6a740e7
wip
privatenumber Oct 6, 2022
410eb60
wip
privatenumber Oct 6, 2022
12f306e
wip
privatenumber Oct 6, 2022
ebcab0b
wip
privatenumber Oct 6, 2022
a1182a5
wip
privatenumber Oct 6, 2022
d98ba81
wip
privatenumber Oct 6, 2022
90db020
wip
privatenumber Oct 6, 2022
5a6b148
wip
privatenumber Oct 6, 2022
0fbb874
wip
privatenumber Oct 6, 2022
bdd60b5
wip
privatenumber Oct 6, 2022
a8fb916
wip
privatenumber Oct 6, 2022
9e875a5
wip
privatenumber Oct 6, 2022
966e78d
wip
privatenumber Oct 6, 2022
9c9861d
wip
privatenumber Oct 6, 2022
83aad40
wip
privatenumber Oct 6, 2022
d9baada
wip
privatenumber Oct 6, 2022
82ecc10
wip
privatenumber Oct 6, 2022
a5a7e71
wip
privatenumber Oct 6, 2022
b2d1ee8
wip
privatenumber Oct 6, 2022
b19cab0
wip
privatenumber Oct 6, 2022
53888f0
wip
privatenumber Oct 6, 2022
304bb08
wip
privatenumber Oct 7, 2022
87d1084
wip
privatenumber Oct 7, 2022
3d215a6
chore: upgrade to core-utils stable
privatenumber Oct 7, 2022
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"prepack": "pnpm build && clean-pkg-json"
},
"dependencies": {
"@esbuild-kit/core-utils": "^2.3.2",
"@esbuild-kit/core-utils": "^3.0.0",
"get-tsconfig": "^4.2.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
installSourceMapSupport,
resolveTsPath,
transformDynamicImport,
applySourceMap,
compareNodeVersion,
} from '@esbuild-kit/core-utils';
import {
Expand All @@ -32,7 +31,7 @@ const tsconfig = (
const tsconfigRaw = tsconfig?.config;
const tsconfigPathsMatcher = tsconfig && createPathsMatcher(tsconfig);

const sourcemaps = installSourceMapSupport();
const applySourceMap = installSourceMapSupport();

const nodeSupportsImport = (
// v13.2.0 and higher
Expand Down Expand Up @@ -62,9 +61,9 @@ function transformer(
let code = fs.readFileSync(filePath, 'utf8');

if (filePath.endsWith('.cjs') && nodeSupportsImport) {
const transformed = transformDynamicImport(code);
const transformed = transformDynamicImport(filePath, code);
if (transformed) {
code = applySourceMap(transformed, filePath, sourcemaps);
code = applySourceMap(transformed, filePath);
}
} else {
const transformed = transformSync(
Expand All @@ -75,7 +74,7 @@ function transformer(
},
);

code = applySourceMap(transformed, filePath, sourcemaps);
code = applySourceMap(transformed, filePath);
}

module._compile(code, filePath);
Expand Down
9 changes: 8 additions & 1 deletion tests/fixtures/lib/cjs-ext-cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ test(

test(
'sourcemaps',
() => new Error().stack.includes(':38:'),
() => {
const { stack } = new Error();
return (
stack.includes(__filename + ':39:')
// TODO: Investigate why converting slashes is only needed for .cjs
|| stack.includes(__filename.toLowerCase().replace(/\\/g, '/') + ':39:')
);
},
);

test(
Expand Down
8 changes: 7 additions & 1 deletion tests/fixtures/lib/cjs-ext-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ test(

test(
'sourcemaps',
() => new Error().stack.includes(':38:'),
() => {
const { stack } = new Error();
return (
stack.includes(`${__filename}:39:`)
|| stack.includes(`${__filename.toLowerCase()}:39:`)
);
},
);

test(
Expand Down
8 changes: 7 additions & 1 deletion tests/fixtures/lib/esm-ext-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ test(

test(
'sourcemaps',
() => new Error().stack.includes(':37:'),
() => {
const { stack } = new Error();
return (
stack.includes(`${__filename}:38:`)
|| stack.includes(`${__filename.toLowerCase()}:38:`)
);
},
);

test(
Expand Down
9 changes: 8 additions & 1 deletion tests/fixtures/lib/esm-ext-mjs/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ test(

test(
'sourcemaps',
() => new Error().stack.includes(':37:'),
() => {
const { stack } = new Error();
const filePath = (typeof __filename === 'string') ? __filename : import.meta.url;
return (
stack.includes(filePath + ':38:')
|| stack.includes(filePath.toLowerCase() + ':38:')
);
},
);

test(
Expand Down
8 changes: 7 additions & 1 deletion tests/fixtures/lib/ts-ext-cts/index.cts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ test(

test(
'sourcemaps',
() => new Error().stack!.includes(':37:'),
() => {
const { stack } = new Error();
return (
stack!.includes(`${__filename}:38:`)
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
);
},
);

test(
Expand Down
8 changes: 7 additions & 1 deletion tests/fixtures/lib/ts-ext-jsx/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ test(

test(
'sourcemaps',
() => new Error().stack.includes(':37:'),
() => {
const { stack } = new Error();
return (
stack.includes(`${__filename}:38:`)
|| stack.includes(`${__filename.toLowerCase()}:38:`)
);
},
);

test(
Expand Down
8 changes: 7 additions & 1 deletion tests/fixtures/lib/ts-ext-mts/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ test(

test(
'sourcemaps',
() => new Error().stack!.includes(':37:'),
() => {
const { stack } = new Error();
return (
stack!.includes(`${__filename}:38:`)
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
);
},
);

test(
Expand Down
60 changes: 33 additions & 27 deletions tests/fixtures/lib/ts-ext-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
async function test(description: string, testFunction: () => any | Promise<any>) {
try {
const result = await testFunction();
if (!result) { throw result; }
console.log(`✔ ${description}`);
} catch (error) {
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`);
}
const result = await testFunction();
if (!result) { throw result; }
console.log(`✔ ${description}`);
} catch (error) {
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`);
}
}

console.log('loaded ts-ext-ts/index.ts');

test(
'has CJS context',
() => typeof require !== 'undefined' || typeof module !== 'undefined',
'has CJS context',
() => typeof require !== 'undefined' || typeof module !== 'undefined',
);

test(
'import.meta.url',
() => Boolean(import.meta.url),
'import.meta.url',
() => Boolean(import.meta.url),
);

test(
'name in error',
() => {
let nameInError;
try {
nameInError();
} catch (error) {
return error.message.includes('nameInError');
}
},
'name in error',
() => {
let nameInError;
try {
nameInError();
} catch (error) {
return error.message.includes('nameInError');
}
},
);

test(
'sourcemaps',
() => new Error().stack!.includes(':37:'),
'sourcemaps',
() => {
const { stack } = new Error();
return (
stack!.includes(`${__filename}:38:`)
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
);
},
);

test(
'has dynamic import',
() => import('fs').then(Boolean),
'has dynamic import',
() => import('fs').then(Boolean),
);

test(
'resolves optional node prefix',
() => import('node:fs').then(Boolean),
'resolves optional node prefix',
() => import('node:fs').then(Boolean),
);

test(
'resolves required node prefix',
() => import('node:test').then(Boolean),
'resolves required node prefix',
() => import('node:test').then(Boolean),
);

test(
Expand Down
40 changes: 23 additions & 17 deletions tests/fixtures/lib/ts-ext-ts/index.tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,59 @@ async function test(description: string, testFunction: () => any | Promise<any>)
const result = await testFunction();
if (!result) { throw result; }
console.log(`✔ ${description}`);
} catch (error) {
} catch (error) {
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`);
}
}
}

console.log('loaded ts-ext-ts/index.tsx.ts');

test(
'has CJS context',
() => typeof require !== 'undefined' || typeof module !== 'undefined',
'has CJS context',
() => typeof require !== 'undefined' || typeof module !== 'undefined',
);

test(
'import.meta.url',
() => Boolean(import.meta.url),
'import.meta.url',
() => Boolean(import.meta.url),
);

test(
'name in error',
() => {
'name in error',
() => {
let nameInError;
try {
nameInError();
} catch (error) {
return error.message.includes('nameInError');
}
},
},
);

test(
'sourcemaps',
() => new Error().stack!.includes(':37:'),
'sourcemaps',
() => {
const { stack } = new Error();
return (
stack!.includes(`${__filename}:38:`)
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
);
},
);

test(
'has dynamic import',
() => import('fs').then(Boolean),
'has dynamic import',
() => import('fs').then(Boolean),
);

test(
'resolves optional node prefix',
() => import('node:fs').then(Boolean),
'resolves optional node prefix',
() => import('node:fs').then(Boolean),
);

test(
'resolves required node prefix',
() => import('node:test').then(Boolean),
'resolves required node prefix',
() => import('node:test').then(Boolean),
);

test(
Expand Down
8 changes: 7 additions & 1 deletion tests/fixtures/lib/ts-ext-tsx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ test(

test(
'sourcemaps',
() => new Error().stack!.includes(':37:'),
() => {
const { stack } = new Error();
return (
stack!.includes(`${__filename}:38:`)
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
);
},
);

test(
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/tsconfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log('Should not run');
console.log('Should not run');