Skip to content

Commit 9faab6d

Browse files
committed
up
1 parent e010d26 commit 9faab6d

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

tests/integration/externals/index.test.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'node:path';
22
import stripAnsi from 'strip-ansi';
3-
import { buildAndGetResults, proxyConsole } from 'test-helper';
3+
import { buildAndGetResults, proxyConsole, queryContent } from 'test-helper';
44
import { expect, test } from 'vitest';
55
import { composeModuleImportWarn } from '../../../packages/core/src/config';
66

@@ -77,17 +77,31 @@ test('require ESM from CJS', async () => {
7777

7878
test('user externals', async () => {
7979
// Ensure the priority of user externals higher than others.
80-
// - memfs: userExternalsConfig > targetExternalsConfig
81-
// - lodash-es/zip: userExternalsConfig > autoExternalConfig
80+
// - "memfs": userExternalsConfig > targetExternalsConfig
81+
// - "lodash-es/zip": userExternalsConfig > autoExternalConfig
82+
// - "./foo2": userExternalsConfig > bundlelessExternalConfig
83+
8284
const fixturePath = join(__dirname, 'user-externals');
83-
const { entries } = await buildAndGetResults({ fixturePath });
84-
expect(entries.esm).toMatchInlineSnapshot(
85+
const { entries, contents } = await buildAndGetResults({ fixturePath });
86+
expect(entries.esm0).toMatchInlineSnapshot(
8587
`
86-
"import * as __WEBPACK_EXTERNAL_MODULE_memfs__ from "memfs";
88+
"import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
8789
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
88-
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_zip_b8981481__ from "lodash-es/zip";
89-
console.log(__WEBPACK_EXTERNAL_MODULE_memfs__["default"], __WEBPACK_EXTERNAL_MODULE_lodash__["default"].add, __WEBPACK_EXTERNAL_MODULE_lodash_es_zip_b8981481__["default"]);
90+
import * as __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__ from "lodash/zip";
91+
const foo = 'foo';
92+
console.log(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], __WEBPACK_EXTERNAL_MODULE_lodash__["default"].add, __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__["default"], foo);
9093
"
9194
`,
9295
);
96+
97+
expect(
98+
queryContent(contents.esm1!, 'index.js', { basename: true }).content,
99+
).toMatchInlineSnapshot(`
100+
"import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
101+
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
102+
import * as __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__ from "lodash/zip";
103+
import * as __WEBPACK_EXTERNAL_MODULE__foo2_1d132755__ from "./foo2";
104+
console.log(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], __WEBPACK_EXTERNAL_MODULE_lodash__["default"].add, __WEBPACK_EXTERNAL_MODULE_lodash_zip_41bf8b9e__["default"], __WEBPACK_EXTERNAL_MODULE__foo2_1d132755__.foo);
105+
"
106+
`);
93107
});
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import { defineConfig } from '@rslib/core';
22
import { generateBundleEsmConfig } from 'test-helper';
33

4+
const baseExternals = {
5+
externals: { 'lodash/zip': 'lodash-es/zip', 'node:fs': 'memfs' },
6+
};
7+
48
export default defineConfig({
5-
lib: [generateBundleEsmConfig()],
6-
output: {
7-
externals: { 'lodash/zip': 'lodash-es/zip', 'node:fs': 'memfs' },
8-
},
9+
lib: [
10+
generateBundleEsmConfig({
11+
output: {
12+
externals: baseExternals,
13+
distPath: {
14+
root: 'dist/bundle',
15+
},
16+
},
17+
}),
18+
generateBundleEsmConfig({
19+
bundle: false,
20+
output: {
21+
externals: { ...baseExternals, './foo': './foo2' },
22+
distPath: {
23+
root: 'dist/bundle-false',
24+
},
25+
},
26+
}),
27+
],
928
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs';
22
import lodash from 'lodash';
33
import zip from 'lodash/zip';
4+
import { foo } from './foo';
45

5-
console.log(fs, lodash.add, zip);
6+
console.log(fs, lodash.add, zip, foo);

0 commit comments

Comments
 (0)