Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit e7ba7ca

Browse files
feat: upgrade core-utils (#22)
1 parent d516785 commit e7ba7ca

File tree

14 files changed

+124
-63
lines changed

14 files changed

+124
-63
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"prepack": "pnpm build && clean-pkg-json"
3434
},
3535
"dependencies": {
36-
"@esbuild-kit/core-utils": "^2.3.2",
36+
"@esbuild-kit/core-utils": "^3.0.0",
3737
"get-tsconfig": "^4.2.0"
3838
},
3939
"devDependencies": {

pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
installSourceMapSupport,
77
resolveTsPath,
88
transformDynamicImport,
9-
applySourceMap,
109
compareNodeVersion,
1110
} from '@esbuild-kit/core-utils';
1211
import {
@@ -32,7 +31,7 @@ const tsconfig = (
3231
const tsconfigRaw = tsconfig?.config;
3332
const tsconfigPathsMatcher = tsconfig && createPathsMatcher(tsconfig);
3433

35-
const sourcemaps = installSourceMapSupport();
34+
const applySourceMap = installSourceMapSupport();
3635

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

6463
if (filePath.endsWith('.cjs') && nodeSupportsImport) {
65-
const transformed = transformDynamicImport(code);
64+
const transformed = transformDynamicImport(filePath, code);
6665
if (transformed) {
67-
code = applySourceMap(transformed, filePath, sourcemaps);
66+
code = applySourceMap(transformed, filePath);
6867
}
6968
} else {
7069
const transformed = transformSync(
@@ -75,7 +74,7 @@ function transformer(
7574
},
7675
);
7776

78-
code = applySourceMap(transformed, filePath, sourcemaps);
77+
code = applySourceMap(transformed, filePath);
7978
}
8079

8180
module._compile(code, filePath);

tests/fixtures/lib/cjs-ext-cjs/index.cjs

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ test(
3535

3636
test(
3737
'sourcemaps',
38-
() => new Error().stack.includes(':38:'),
38+
() => {
39+
const { stack } = new Error();
40+
return (
41+
stack.includes(__filename + ':39:')
42+
// TODO: Investigate why converting slashes is only needed for .cjs
43+
|| stack.includes(__filename.toLowerCase().replace(/\\/g, '/') + ':39:')
44+
);
45+
},
3946
);
4047

4148
test(

tests/fixtures/lib/cjs-ext-js/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ test(
3535

3636
test(
3737
'sourcemaps',
38-
() => new Error().stack.includes(':38:'),
38+
() => {
39+
const { stack } = new Error();
40+
return (
41+
stack.includes(`${__filename}:39:`)
42+
|| stack.includes(`${__filename.toLowerCase()}:39:`)
43+
);
44+
},
3945
);
4046

4147
test(

tests/fixtures/lib/esm-ext-js/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ test(
3434

3535
test(
3636
'sourcemaps',
37-
() => new Error().stack.includes(':37:'),
37+
() => {
38+
const { stack } = new Error();
39+
return (
40+
stack.includes(`${__filename}:38:`)
41+
|| stack.includes(`${__filename.toLowerCase()}:38:`)
42+
);
43+
},
3844
);
3945

4046
test(

tests/fixtures/lib/esm-ext-mjs/index.mjs

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ test(
3434

3535
test(
3636
'sourcemaps',
37-
() => new Error().stack.includes(':37:'),
37+
() => {
38+
const { stack } = new Error();
39+
const filePath = (typeof __filename === 'string') ? __filename : import.meta.url;
40+
return (
41+
stack.includes(filePath + ':38:')
42+
|| stack.includes(filePath.toLowerCase() + ':38:')
43+
);
44+
},
3845
);
3946

4047
test(

tests/fixtures/lib/ts-ext-cts/index.cts

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ test(
3434

3535
test(
3636
'sourcemaps',
37-
() => new Error().stack!.includes(':37:'),
37+
() => {
38+
const { stack } = new Error();
39+
return (
40+
stack!.includes(`${__filename}:38:`)
41+
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
42+
);
43+
},
3844
);
3945

4046
test(

tests/fixtures/lib/ts-ext-jsx/index.jsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ test(
3434

3535
test(
3636
'sourcemaps',
37-
() => new Error().stack.includes(':37:'),
37+
() => {
38+
const { stack } = new Error();
39+
return (
40+
stack.includes(`${__filename}:38:`)
41+
|| stack.includes(`${__filename.toLowerCase()}:38:`)
42+
);
43+
},
3844
);
3945

4046
test(

tests/fixtures/lib/ts-ext-mts/index.mts

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ test(
3434

3535
test(
3636
'sourcemaps',
37-
() => new Error().stack!.includes(':37:'),
37+
() => {
38+
const { stack } = new Error();
39+
return (
40+
stack!.includes(`${__filename}:38:`)
41+
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
42+
);
43+
},
3844
);
3945

4046
test(

tests/fixtures/lib/ts-ext-ts/index.ts

+33-27
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,61 @@
11
async function test(description: string, testFunction: () => any | Promise<any>) {
22
try {
3-
const result = await testFunction();
4-
if (!result) { throw result; }
5-
console.log(`✔ ${description}`);
6-
} catch (error) {
7-
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`);
8-
}
3+
const result = await testFunction();
4+
if (!result) { throw result; }
5+
console.log(`✔ ${description}`);
6+
} catch (error) {
7+
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`);
8+
}
99
}
1010

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

1313
test(
14-
'has CJS context',
15-
() => typeof require !== 'undefined' || typeof module !== 'undefined',
14+
'has CJS context',
15+
() => typeof require !== 'undefined' || typeof module !== 'undefined',
1616
);
1717

1818
test(
19-
'import.meta.url',
20-
() => Boolean(import.meta.url),
19+
'import.meta.url',
20+
() => Boolean(import.meta.url),
2121
);
2222

2323
test(
24-
'name in error',
25-
() => {
26-
let nameInError;
27-
try {
28-
nameInError();
29-
} catch (error) {
30-
return error.message.includes('nameInError');
31-
}
32-
},
24+
'name in error',
25+
() => {
26+
let nameInError;
27+
try {
28+
nameInError();
29+
} catch (error) {
30+
return error.message.includes('nameInError');
31+
}
32+
},
3333
);
3434

3535
test(
36-
'sourcemaps',
37-
() => new Error().stack!.includes(':37:'),
36+
'sourcemaps',
37+
() => {
38+
const { stack } = new Error();
39+
return (
40+
stack!.includes(`${__filename}:38:`)
41+
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
42+
);
43+
},
3844
);
3945

4046
test(
41-
'has dynamic import',
42-
() => import('fs').then(Boolean),
47+
'has dynamic import',
48+
() => import('fs').then(Boolean),
4349
);
4450

4551
test(
46-
'resolves optional node prefix',
47-
() => import('node:fs').then(Boolean),
52+
'resolves optional node prefix',
53+
() => import('node:fs').then(Boolean),
4854
);
4955

5056
test(
51-
'resolves required node prefix',
52-
() => import('node:test').then(Boolean),
57+
'resolves required node prefix',
58+
() => import('node:test').then(Boolean),
5359
);
5460

5561
test(

tests/fixtures/lib/ts-ext-ts/index.tsx.ts

+23-17
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,59 @@ async function test(description: string, testFunction: () => any | Promise<any>)
33
const result = await testFunction();
44
if (!result) { throw result; }
55
console.log(`✔ ${description}`);
6-
} catch (error) {
6+
} catch (error) {
77
console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`);
8-
}
8+
}
99
}
1010

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

1313
test(
14-
'has CJS context',
15-
() => typeof require !== 'undefined' || typeof module !== 'undefined',
14+
'has CJS context',
15+
() => typeof require !== 'undefined' || typeof module !== 'undefined',
1616
);
1717

1818
test(
19-
'import.meta.url',
20-
() => Boolean(import.meta.url),
19+
'import.meta.url',
20+
() => Boolean(import.meta.url),
2121
);
2222

2323
test(
24-
'name in error',
25-
() => {
24+
'name in error',
25+
() => {
2626
let nameInError;
2727
try {
2828
nameInError();
2929
} catch (error) {
3030
return error.message.includes('nameInError');
3131
}
32-
},
32+
},
3333
);
3434

3535
test(
36-
'sourcemaps',
37-
() => new Error().stack!.includes(':37:'),
36+
'sourcemaps',
37+
() => {
38+
const { stack } = new Error();
39+
return (
40+
stack!.includes(`${__filename}:38:`)
41+
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
42+
);
43+
},
3844
);
3945

4046
test(
41-
'has dynamic import',
42-
() => import('fs').then(Boolean),
47+
'has dynamic import',
48+
() => import('fs').then(Boolean),
4349
);
4450

4551
test(
46-
'resolves optional node prefix',
47-
() => import('node:fs').then(Boolean),
52+
'resolves optional node prefix',
53+
() => import('node:fs').then(Boolean),
4854
);
4955

5056
test(
51-
'resolves required node prefix',
52-
() => import('node:test').then(Boolean),
57+
'resolves required node prefix',
58+
() => import('node:test').then(Boolean),
5359
);
5460

5561
test(

tests/fixtures/lib/ts-ext-tsx/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ test(
3434

3535
test(
3636
'sourcemaps',
37-
() => new Error().stack!.includes(':37:'),
37+
() => {
38+
const { stack } = new Error();
39+
return (
40+
stack!.includes(`${__filename}:38:`)
41+
|| stack!.includes(`${__filename.toLowerCase()}:38:`)
42+
);
43+
},
3844
);
3945

4046
test(

tests/fixtures/tsconfig/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log('Should not run');
1+
console.log('Should not run');

0 commit comments

Comments
 (0)