Skip to content

Commit c13bada

Browse files
committed
up
1 parent 76eb4f0 commit c13bada

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

packages/core/src/config.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import type {
3535
LibConfig,
3636
PkgJson,
3737
Redirect,
38-
ResolvedShims,
3938
RsbuildConfigOutputTarget,
4039
RslibConfig,
4140
RslibConfigAsyncFn,
@@ -542,8 +541,8 @@ const composeFormatConfig = (format: Format): RsbuildConfig => {
542541
}
543542
};
544543

545-
const resolveShims = (shims?: Shims): ResolvedShims => {
546-
return {
544+
const composeShimsConfig = (format: Format, shims: Shims): RsbuildConfig => {
545+
const resolvedShims = {
547546
cjs: {
548547
'import.meta.url': shims?.cjs?.['import.meta.url'] ?? true,
549548
},
@@ -553,12 +552,7 @@ const resolveShims = (shims?: Shims): ResolvedShims => {
553552
require: shims?.esm?.require ?? false,
554553
},
555554
};
556-
};
557555

558-
const composeShimsConfig = (
559-
format: Format,
560-
resolvedShims: ResolvedShims,
561-
): RsbuildConfig => {
562556
switch (format) {
563557
case 'esm':
564558
return {
@@ -962,15 +956,15 @@ async function composeLibRsbuildConfig(config: LibConfig, configPath: string) {
962956

963957
const {
964958
format,
959+
shims,
965960
banner = {},
966961
footer = {},
967962
autoExtension = true,
968963
autoExternal = true,
969964
externalHelpers = false,
970965
redirect = {},
971966
} = config;
972-
const resolvedShims = resolveShims(config.shims);
973-
const shimsConfig = composeShimsConfig(format!, resolvedShims);
967+
const shimsConfig = composeShimsConfig(format!, shims);
974968
const formatConfig = composeFormatConfig(format!);
975969
const externalHelpersConfig = composeExternalHelpersConfig(
976970
externalHelpers,

packages/core/src/plugins/shims.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const importMetaUrlShim = `/*#__PURE__*/ (function () {
1212
// - Inject `importMetaUrl` to the end of the module (can't inject at the beginning because of `"use strict";`).
1313
// This is a short-term solution, and we hope to provide built-in polyfills like `node.__filename` on Rspack side.
1414
export const pluginCjsImportMetaUrlShim = (): RsbuildPlugin => ({
15-
name: 'rsbuild-plugin-cjs-import-meta-url-shim',
15+
name: 'rsbuild:cjs-import-meta-url-shim',
1616
setup(api) {
1717
api.modifyEnvironmentConfig((config) => {
1818
config.source.define = {
@@ -29,7 +29,7 @@ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.ur
2929
`;
3030

3131
export const pluginEsmRequireShim = (): RsbuildPlugin => ({
32-
name: 'rsbuild-plugin-esm-require-shim',
32+
name: 'rsbuild:esm-require-shim',
3333
setup(api) {
3434
api.modifyRspackConfig((config) => {
3535
config.plugins ??= [];

packages/core/src/types/config/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ export type Shims = {
5959
};
6060
};
6161

62-
export type ResolvedShims = {
63-
cjs: Required<NonNullable<Exclude<Shims['cjs'], boolean>>>;
64-
esm: Required<NonNullable<Exclude<Shims['esm'], boolean>>>;
65-
};
66-
6762
export type Redirect = {
6863
// TODO: support other redirects
6964
// alias?: boolean;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1
201201
},
202202
"plugins": [
203203
{
204-
"name": "rsbuild-plugin-cjs-import-meta-url-shim",
204+
"name": "rsbuild:cjs-import-meta-url-shim",
205205
"setup": [Function],
206206
},
207207
],

0 commit comments

Comments
 (0)