Skip to content

Commit f313e1f

Browse files
committed
fix: preserve import.meta.url despite target
fixes #115
1 parent c6e4cda commit f313e1f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/rollup/plugins/esbuild.ts

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ export const esbuildTransform = (
1919
const result = await transform(code, {
2020
...options,
2121

22+
supported: {
23+
/**
24+
* esbuild is used for TS, syntax lowering, & define, but
25+
* we'll ignore import.meta as it injects a polyfill that
26+
* may break if the output is ESM
27+
*
28+
* https://esbuild.github.io/try/#dAAwLjI1LjAAe3RhcmdldDogWydlczIwMTcnXX0AY29uc29sZS5sb2coaW1wb3J0Lm1ldGEudXJsKQ
29+
*/
30+
'import-meta': true,
31+
},
32+
2233
loader: 'default',
2334

2435
// https://github.com/evanw/esbuild/issues/1932#issuecomment-1013380565

tests/specs/builds/output-module.ts

+19
Original file line numberDiff line numberDiff line change
@@ -364,5 +364,24 @@ export default testSuite(({ describe }, nodePath: string) => {
364364
const content = await fixture.readFile('dist/dynamic-imports.mjs', 'utf8');
365365
expect(content).toMatch('import(');
366366
});
367+
368+
// https://github.com/privatenumber/pkgroll/issues/115
369+
test('import.meta.url should be preserved', async () => {
370+
await using fixture = await createFixture({
371+
'src/index.js': 'console.log(import.meta.url)',
372+
'package.json': createPackageJson({
373+
exports: './dist/index.mjs',
374+
}),
375+
});
376+
377+
const pkgrollProcess = await pkgroll(['--target=es2017'], {
378+
cwd: fixture.path,
379+
nodePath,
380+
});
381+
expect(pkgrollProcess.exitCode).toBe(0);
382+
383+
const content = await fixture.readFile('dist/index.mjs', 'utf8');
384+
expect(content).toMatch('import.meta.url');
385+
});
367386
});
368387
});

0 commit comments

Comments
 (0)