Skip to content

Commit

Permalink
feat: use isWatch from onBeforeBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 committed Jul 31, 2024
1 parent bc82d40 commit eb9d6da
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 49 deletions.
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"@playwright/test": "1.43.1",
"@rsbuild/core": "1.0.1-beta.6",
"@rsbuild/core": "1.0.1-beta.8",
"@rslib/core": "workspace:*",
"@rslib/tsconfig": "workspace:*",
"@types/fs-extra": "^11.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"prebundle": "prebundle"
},
"dependencies": {
"@rsbuild/core": "1.0.1-beta.6",
"@rsbuild/core": "1.0.1-beta.8",
"rsbuild-plugin-dts": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { initRsbuild } from './config';
import type { RslibConfig } from './types/config';

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

await rsbuildInstance.build({
mode: 'production',
Expand Down
22 changes: 3 additions & 19 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'node:fs';
import path, { dirname, isAbsolute, join } from 'node:path';
import {
type BuildOptions,
type RsbuildConfig,
createRsbuild,
defineConfig as defineRsbuildConfig,
Expand Down Expand Up @@ -298,7 +297,6 @@ const getBundleConfig = (bundle = true): RsbuildConfig => {
const getDefaultDtsConfig = (
libConfig: LibConfig,
entryConfig: RsbuildConfig,
isWatch = false,
): RsbuildConfig => {
const { dts, bundle, output } = libConfig;

Expand All @@ -312,7 +310,6 @@ const getDefaultDtsConfig = (
tsconfigPath: dts?.tsconfigPath ?? 'tsconfig.json',
// TODO: temporarily use main as dts entry
entryPath: entryConfig.source?.entry?.main as string,
isWatch,
}),
],
};
Expand Down Expand Up @@ -345,7 +342,6 @@ async function postUpdateRsbuildConfig(
libConfig: LibConfig,
rsbuildConfig: RsbuildConfig,
configPath: string,
options?: BuildOptions,
) {
const defaultTargetConfig = getDefaultTargetConfig(
rsbuildConfig.output?.target ?? 'web',
Expand All @@ -357,11 +353,7 @@ async function postUpdateRsbuildConfig(
dirname(configPath),
);

const defaultDtsConfig = getDefaultDtsConfig(
libConfig,
defaultEntryConfig,
options?.watch,
);
const defaultDtsConfig = getDefaultDtsConfig(libConfig, defaultEntryConfig);

return mergeRsbuildConfig(
defaultTargetConfig,
Expand Down Expand Up @@ -393,7 +385,6 @@ const getDefaultTargetConfig = (target: string): RsbuildConfig => {

export async function composeCreateRsbuildConfig(
rslibConfig: RslibConfig,
options?: BuildOptions,
): Promise<Partial<Record<Format, RsbuildConfig>>> {
const internalRsbuildConfig = await createInternalRsbuildConfig();
const configPath = rslibConfig._privateMeta?.configFilePath ?? process.cwd();
Expand Down Expand Up @@ -427,7 +418,6 @@ export async function composeCreateRsbuildConfig(
libConfig,
mergedRsbuildConfig,
configPath,
options,
);

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

export async function initRsbuild(
rslibConfig: RslibConfig,
options?: BuildOptions,
) {
const rsbuildConfigObject = await composeCreateRsbuildConfig(
rslibConfig,
options,
);
export async function initRsbuild(rslibConfig: RslibConfig) {
const rsbuildConfigObject = await composeCreateRsbuildConfig(rslibConfig);

return createRsbuild({
rsbuildConfig: {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-dts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@microsoft/api-extractor": "^7.47.4",
"@rsbuild/core": "1.0.1-beta.6",
"@rsbuild/core": "1.0.1-beta.8",
"@rslib/tsconfig": "workspace:*",
"typescript": "^5.5.3"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-dts/src/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ensureTempDeclarationDir, loadTsconfig } from './utils';

export async function generateDts(data: sendData) {
logger.info('Generating DTS...');
const { options: pluginOptions } = data;
const { tsconfigPath, distPath, bundle, entryPath, isWatch } = pluginOptions;
const { options: pluginOptions, isWatch } = data;
const { tsconfigPath, distPath, bundle, entryPath } = pluginOptions;
const cwd = process.cwd();
const configPath = tsconfigPath
? join(cwd, tsconfigPath)
Expand Down Expand Up @@ -79,7 +79,7 @@ process.on('message', async (data: sendData) => {

await generateDts(data);

if (!data.options.isWatch) {
if (!data.isWatch) {
process.exit();
}
});
21 changes: 12 additions & 9 deletions packages/plugin-dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export type pluginDtsOptions = {
distPath?: string;
tsconfigPath?: string;
entryPath?: string;
isWatch?: boolean;
};

export type sendData = {
options: pluginDtsOptions;
isWatch: boolean;
};

export const PLUGIN_DTS_NAME = 'rsbuild:dts';
Expand All @@ -26,15 +26,18 @@ export const pluginDts = (
): RsbuildPlugin => ({
name: PLUGIN_DTS_NAME,

setup() {
const childProcess = fork(join(__dirname, './dts.js'), [], {
stdio: 'inherit',
});
setup(api) {
api.onBeforeBuild(({ isWatch }) => {
const childProcess = fork(join(__dirname, './dts.js'), [], {
stdio: 'inherit',
});

const sendData = {
options,
};
const sendData = {
options,
isWatch,
};

childProcess.send(sendData);
childProcess.send(sendData);
});
},
});
27 changes: 13 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eb9d6da

Please sign in to comment.