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
31 changes: 31 additions & 0 deletions packages/core/src/core/rsbuild.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'node:fs';
import {
type ManifestData,
type RsbuildInstance,
logger as RsbuildLogger,
type RsbuildPlugin,
Expand Down Expand Up @@ -108,6 +109,8 @@ export const prepareRsbuild = async (
},
},
output: {
// Pass resources to the worker on demand according to entry
manifest: true,
sourceMap: {
js: 'source-map',
},
Expand Down Expand Up @@ -141,6 +144,11 @@ export const prepareRsbuild = async (
...(config.optimization || {}),
moduleIds: 'named',
chunkIds: 'named',
splitChunks: {
chunks: 'all',
minSize: 0,
maxInitialRequests: Number.POSITIVE_INFINITY,
},
};
},
},
Expand Down Expand Up @@ -213,15 +221,21 @@ export const createRsbuildServer = async ({
const getRsbuildStats = async () => {
const stats = await devServer.environments[name]!.getStats();

const manifest = devServer.environments[name]!.context
.manifest as ManifestData;

const {
entrypoints,
outputPath,
assets,
time: buildTime,
} = stats.toJson({
all: false,
entrypoints: true,
outputPath: true,
assets: true,
relatedAssets: true,
cachedAssets: true,
// get the compilation time
timings: true,
});
Expand All @@ -237,6 +251,21 @@ export const createRsbuildServer = async ({
});
};

const getEntryFiles = async () => {
const entryFiles: Record<string, string[]> = {};

const entries = Object.keys(manifest!.entries!);

for (const entry of entries) {
const data = manifest!.entries[entry];
entryFiles[entry] = (
(data?.initial?.js || []).concat(data?.async?.js || []) || []
).map((file: string) => path.join(outputPath!, file));
}
return entryFiles;
};

const entryFiles = await getEntryFiles();
const entries: EntryInfo[] = [];
const setupEntries: EntryInfo[] = [];
const sourceEntries = await globTestSourceEntries();
Expand All @@ -253,11 +282,13 @@ export const createRsbuildServer = async ({
setupEntries.push({
distPath,
testPath: setupFiles[entry],
files: entryFiles[entry],
});
} else if (sourceEntries[entry]) {
entries.push({
distPath,
testPath: sourceEntries[entry],
files: entryFiles[entry],
});
}
}
Expand Down
41 changes: 33 additions & 8 deletions packages/core/src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,34 @@ export const createPool = async ({
},
};

const setupAssets = setupEntries.flatMap((entry) => entry.files);

const filterAssetsByEntry = (entryInfo: EntryInfo) => {
const neededFiles = entryInfo.files
? Object.fromEntries(
Object.entries(assetFiles).filter(
([key]) =>
entryInfo.files!.includes(key) || setupAssets.includes(key),
),
)
: assetFiles;

const neededSourceMaps =
Object.keys(entries).length > 1
? Object.fromEntries(
Object.entries(sourceMaps).filter(([key]) => neededFiles[key]),
)
: sourceMaps;

return { assetFiles: neededFiles, sourceMaps: neededSourceMaps };
};
return {
runTests: async () => {
const results = await Promise.all(
entries.map((entryInfo) =>
pool.runTest({
entries.map((entryInfo) => {
const { assetFiles, sourceMaps } = filterAssetsByEntry(entryInfo);

return pool.runTest({
options: {
entryInfo,
assetFiles,
Expand All @@ -182,8 +205,8 @@ export const createPool = async ({
updateSnapshot,
},
rpcMethods,
}),
),
});
}),
);

for (const result of results) {
Expand All @@ -198,8 +221,10 @@ export const createPool = async ({
},
collectTests: async () => {
return Promise.all(
entries.map((entryInfo) =>
pool.collectTests({
entries.map((entryInfo) => {
const { assetFiles, sourceMaps } = filterAssetsByEntry(entryInfo);

return pool.collectTests({
options: {
entryInfo,
assetFiles,
Expand All @@ -213,8 +238,8 @@ export const createPool = async ({
updateSnapshot,
},
rpcMethods,
}),
),
});
}),
);
},
close: () => pool.close(),
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { DistPath, TestPath } from './utils';
export type EntryInfo = {
distPath: DistPath;
testPath: TestPath;
files?: string[];
};

/** Server to Runtime */
Expand Down
25 changes: 24 additions & 1 deletion packages/core/tests/core/__snapshots__/rsbuild.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ exports[`prepareRsbuild > should generate rspack config correctly 1`] = `
"emitOnErrors": true,
"minimize": false,
"moduleIds": "named",
"splitChunks": false,
"splitChunks": {
"chunks": "all",
"maxInitialRequests": Infinity,
"minSize": 0,
},
},
"output": {
"assetModuleFilename": "static/assets/[name].[contenthash:8][ext]",
Expand Down Expand Up @@ -374,6 +378,25 @@ exports[`prepareRsbuild > should generate rspack config correctly 1`] = `
"affectedHooks": "compilation",
"name": "DefinePlugin",
},
WebpackManifestPlugin {
"options": {
"assetHookStage": Infinity,
"basePath": "",
"fileName": "manifest.json",
"filter": [Function],
"generate": [Function],
"map": null,
"publicPath": null,
"removeKeyHash": /\\(\\[a-f0-9\\]\\{16,32\\}\\\\\\.\\?\\)/gi,
"seed": undefined,
"serialize": [Function],
"sort": null,
"transformExtensions": /\\^\\(gz\\|map\\)\\$/i,
"useEntryKeys": false,
"useLegacyEmit": false,
"writeToFileEmit": false,
},
},
IgnoreModuleNotFoundErrorPlugin {},
],
"resolve": {
Expand Down
Loading