Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"chokidar": "^4.0.3",
"fs-extra": "^11.3.1",
"memfs": "^4.38.1",
"path-serializer": "0.5.1",
"picocolors": "1.1.1",
"prebundle": "1.4.1",
"rsbuild-plugin-publint": "^0.3.3",
Expand Down
1 change: 1 addition & 0 deletions packages/core/rstest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import { shared } from '../../rstest.workspace';
export default defineConfig({
...shared,
name: 'unit',
setupFiles: ['./setupRstestTests.ts'],
});
40 changes: 40 additions & 0 deletions packages/core/setupRstestTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import path from 'node:path';
import process from 'node:process';
import { beforeEach, expect } from '@rstest/core';
import { createSnapshotSerializer } from 'path-serializer';

beforeEach(() => {
// since our NODE_ENV injection logic is via cli, we need to
// delete "test" NODE_ENV to avoid affecting the default build config
delete process.env.NODE_ENV;
});

function removeTrailingSlash(inputPath: string): string {
return path.normalize(inputPath).replace(/[\\/]+$/, '');
}
expect.addSnapshotSerializer(
createSnapshotSerializer({
root: removeTrailingSlash(path.join(__dirname, '../../')),
workspace: __dirname,
features: {
replaceHomeDir: false,
replaceWorkspace: true,
replaceRoot: true,
escapeDoubleQuotes: false,
transformCLR: false,
},
}),
);

if (process.env.ECO_CI) {
expect.extend({
toMatchSnapshot: () => ({
pass: true,
message: () => 'Snapshot always passes',
}),
toMatchInlineSnapshot: () => ({
pass: true,
message: () => 'Snapshot always passes',
}),
});
}
15 changes: 15 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,16 @@ const disableUrlParseRsbuildPlugin = (): RsbuildPlugin => ({
},
});

// Port https://github.com/web-infra-dev/rsbuild/pull/5955 before it merged into Rsbuild.
const fixJsModuleTypePlugin = (): RsbuildPlugin => ({
name: 'rsbuild:fix-js-module-type',
setup(api) {
api.modifyBundlerChain((config, { CHAIN_ID }) => {
config.module.rule(CHAIN_ID.RULE.JS).delete('type');
});
},
});

const composeShimsConfig = (
format: Format,
shims?: Shims,
Expand Down Expand Up @@ -866,6 +876,7 @@ const composeShimsConfig = (
plugins: [
resolvedShims.esm.require && pluginEsmRequireShim(),
disableUrlParseRsbuildPlugin(),
fixJsModuleTypePlugin(),
].filter(Boolean),
};
break;
Expand All @@ -875,12 +886,16 @@ const composeShimsConfig = (
plugins: [
resolvedShims.cjs['import.meta.url'] && pluginCjsImportMetaUrlShim(),
disableUrlParseRsbuildPlugin(),
fixJsModuleTypePlugin(),
].filter(Boolean),
};
break;
case 'umd':
case 'iife':
case 'mf':
rsbuildConfig = {
plugins: [fixJsModuleTypePlugin()],
};
break;
default:
throw new Error(`Unsupported format: ${format}`);
Expand Down
Loading
Loading