Skip to content

Commit 5eaaa21

Browse files
committed
fix(esm): disable module.parser.javascript.url
1 parent cff510b commit 5eaaa21

File tree

8 files changed

+67
-0
lines changed

8 files changed

+67
-0
lines changed

packages/core/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ const composeFormatConfig = ({
496496
esm: {
497497
importMeta: false,
498498
importDynamic: false,
499+
url: false,
499500
},
500501
} as const;
501502

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
177177
"requireAsExpression": false,
178178
"requireDynamic": false,
179179
"requireResolve": false,
180+
"url": false,
180181
},
181182
},
182183
},
@@ -415,6 +416,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
415416
"requireAsExpression": false,
416417
"requireDynamic": false,
417418
"requireResolve": false,
419+
"url": false,
418420
},
419421
},
420422
},

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { buildAndGetResults } from 'test-helper';
2+
import { expect, test } from 'vitest';
3+
4+
test('esm', async () => {
5+
const fixturePath = __dirname;
6+
const { files, entries, entryFiles } = await buildAndGetResults({
7+
fixturePath,
8+
});
9+
expect(files).toMatchInlineSnapshot(`
10+
{
11+
"esm": [
12+
"<ROOT>/tests/integration/format/dist/esm/index.js",
13+
],
14+
}
15+
`);
16+
expect(entries.esm).toMatchInlineSnapshot(`
17+
"import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
18+
const packageDirectory = __WEBPACK_EXTERNAL_MODULE_node_url__["default"].fileURLToPath(new URL('.', import.meta.url));
19+
const foo = 'foo';
20+
export { foo, packageDirectory };
21+
"
22+
`);
23+
24+
const result = await import(entryFiles.esm);
25+
expect(result).toMatchInlineSnapshot(`
26+
{
27+
"foo": "foo",
28+
"packageDirectory": "<ROOT>/tests/integration/format/dist/esm/",
29+
}
30+
`);
31+
});

tests/integration/format/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "format-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig({
7+
output: {
8+
distPath: {
9+
root: './dist/esm',
10+
},
11+
},
12+
}),
13+
],
14+
source: {
15+
entry: {
16+
index: './src/index.js',
17+
},
18+
},
19+
});

tests/integration/format/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { packageDirectory, foo } from './value.js';

tests/integration/format/src/value.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import url from 'node:url';
2+
export const packageDirectory = url.fileURLToPath(
3+
new URL('.', import.meta.url),
4+
);
5+
export const foo = 'foo';

0 commit comments

Comments
 (0)