Skip to content

Commit eb9d6da

Browse files
committed
feat: use isWatch from onBeforeBuild
1 parent bc82d40 commit eb9d6da

File tree

8 files changed

+35
-49
lines changed

8 files changed

+35
-49
lines changed

e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"devDependencies": {
1616
"@playwright/test": "1.43.1",
17-
"@rsbuild/core": "1.0.1-beta.6",
17+
"@rsbuild/core": "1.0.1-beta.8",
1818
"@rslib/core": "workspace:*",
1919
"@rslib/tsconfig": "workspace:*",
2020
"@types/fs-extra": "^11.0.4",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"prebundle": "prebundle"
3939
},
4040
"dependencies": {
41-
"@rsbuild/core": "1.0.1-beta.6",
41+
"@rsbuild/core": "1.0.1-beta.8",
4242
"rsbuild-plugin-dts": "workspace:*"
4343
},
4444
"devDependencies": {

packages/core/src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { initRsbuild } from './config';
33
import type { RslibConfig } from './types/config';
44

55
export async function build(config: RslibConfig, options?: BuildOptions) {
6-
const rsbuildInstance = await initRsbuild(config, options);
6+
const rsbuildInstance = await initRsbuild(config);
77

88
await rsbuildInstance.build({
99
mode: 'production',

packages/core/src/config.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from 'node:fs';
22
import path, { dirname, isAbsolute, join } from 'node:path';
33
import {
4-
type BuildOptions,
54
type RsbuildConfig,
65
createRsbuild,
76
defineConfig as defineRsbuildConfig,
@@ -298,7 +297,6 @@ const getBundleConfig = (bundle = true): RsbuildConfig => {
298297
const getDefaultDtsConfig = (
299298
libConfig: LibConfig,
300299
entryConfig: RsbuildConfig,
301-
isWatch = false,
302300
): RsbuildConfig => {
303301
const { dts, bundle, output } = libConfig;
304302

@@ -312,7 +310,6 @@ const getDefaultDtsConfig = (
312310
tsconfigPath: dts?.tsconfigPath ?? 'tsconfig.json',
313311
// TODO: temporarily use main as dts entry
314312
entryPath: entryConfig.source?.entry?.main as string,
315-
isWatch,
316313
}),
317314
],
318315
};
@@ -345,7 +342,6 @@ async function postUpdateRsbuildConfig(
345342
libConfig: LibConfig,
346343
rsbuildConfig: RsbuildConfig,
347344
configPath: string,
348-
options?: BuildOptions,
349345
) {
350346
const defaultTargetConfig = getDefaultTargetConfig(
351347
rsbuildConfig.output?.target ?? 'web',
@@ -357,11 +353,7 @@ async function postUpdateRsbuildConfig(
357353
dirname(configPath),
358354
);
359355

360-
const defaultDtsConfig = getDefaultDtsConfig(
361-
libConfig,
362-
defaultEntryConfig,
363-
options?.watch,
364-
);
356+
const defaultDtsConfig = getDefaultDtsConfig(libConfig, defaultEntryConfig);
365357

366358
return mergeRsbuildConfig(
367359
defaultTargetConfig,
@@ -393,7 +385,6 @@ const getDefaultTargetConfig = (target: string): RsbuildConfig => {
393385

394386
export async function composeCreateRsbuildConfig(
395387
rslibConfig: RslibConfig,
396-
options?: BuildOptions,
397388
): Promise<Partial<Record<Format, RsbuildConfig>>> {
398389
const internalRsbuildConfig = await createInternalRsbuildConfig();
399390
const configPath = rslibConfig._privateMeta?.configFilePath ?? process.cwd();
@@ -427,7 +418,6 @@ export async function composeCreateRsbuildConfig(
427418
libConfig,
428419
mergedRsbuildConfig,
429420
configPath,
430-
options,
431421
);
432422

433423
// Reset some fields as they will be totally overridden by the following merge
@@ -447,14 +437,8 @@ export async function composeCreateRsbuildConfig(
447437
return composedRsbuildConfig;
448438
}
449439

450-
export async function initRsbuild(
451-
rslibConfig: RslibConfig,
452-
options?: BuildOptions,
453-
) {
454-
const rsbuildConfigObject = await composeCreateRsbuildConfig(
455-
rslibConfig,
456-
options,
457-
);
440+
export async function initRsbuild(rslibConfig: RslibConfig) {
441+
const rsbuildConfigObject = await composeCreateRsbuildConfig(rslibConfig);
458442

459443
return createRsbuild({
460444
rsbuildConfig: {

packages/plugin-dts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"devDependencies": {
3333
"@microsoft/api-extractor": "^7.47.4",
34-
"@rsbuild/core": "1.0.1-beta.6",
34+
"@rsbuild/core": "1.0.1-beta.8",
3535
"@rslib/tsconfig": "workspace:*",
3636
"typescript": "^5.5.3"
3737
},

packages/plugin-dts/src/dts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { ensureTempDeclarationDir, loadTsconfig } from './utils';
66

77
export async function generateDts(data: sendData) {
88
logger.info('Generating DTS...');
9-
const { options: pluginOptions } = data;
10-
const { tsconfigPath, distPath, bundle, entryPath, isWatch } = pluginOptions;
9+
const { options: pluginOptions, isWatch } = data;
10+
const { tsconfigPath, distPath, bundle, entryPath } = pluginOptions;
1111
const cwd = process.cwd();
1212
const configPath = tsconfigPath
1313
? join(cwd, tsconfigPath)
@@ -79,7 +79,7 @@ process.on('message', async (data: sendData) => {
7979

8080
await generateDts(data);
8181

82-
if (!data.options.isWatch) {
82+
if (!data.isWatch) {
8383
process.exit();
8484
}
8585
});

packages/plugin-dts/src/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export type pluginDtsOptions = {
77
distPath?: string;
88
tsconfigPath?: string;
99
entryPath?: string;
10-
isWatch?: boolean;
1110
};
1211

1312
export type sendData = {
1413
options: pluginDtsOptions;
14+
isWatch: boolean;
1515
};
1616

1717
export const PLUGIN_DTS_NAME = 'rsbuild:dts';
@@ -26,15 +26,18 @@ export const pluginDts = (
2626
): RsbuildPlugin => ({
2727
name: PLUGIN_DTS_NAME,
2828

29-
setup() {
30-
const childProcess = fork(join(__dirname, './dts.js'), [], {
31-
stdio: 'inherit',
32-
});
29+
setup(api) {
30+
api.onBeforeBuild(({ isWatch }) => {
31+
const childProcess = fork(join(__dirname, './dts.js'), [], {
32+
stdio: 'inherit',
33+
});
3334

34-
const sendData = {
35-
options,
36-
};
35+
const sendData = {
36+
options,
37+
isWatch,
38+
};
3739

38-
childProcess.send(sendData);
40+
childProcess.send(sendData);
41+
});
3942
},
4043
});

pnpm-lock.yaml

Lines changed: 13 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)