Skip to content

Commit e907a2b

Browse files
committed
chore: prune tree as default skip api
1 parent 2134993 commit e907a2b

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ interface projects {
105105
match?: (stdout: string) => boolean;
106106
/**
107107
* Whether to skip starting the current sub-project. The default value is `false`, typically used to skip sub-projects that don't need to be started.
108-
* When the value is `prune`, the specified project will be pruned, meaning that the project and all its direct and indirect dependencies will not be started by the plugin.
109-
* When the value is `true`, the specified project will be skipped from starting, but no pruning will be performed, meaning that the project's direct and indirect dependencies will still be started by the plugin.
110-
*/
111-
skip?: boolean;
108+
* When the value is `true`, pruning will be performed on the specified project, meaning that this project and all its direct and indirect dependencies will not be started by the plugin.
109+
* When the value is `only`, starting the specified project will be skipped, but no pruning will be performed, meaning that the project's direct and indirect dependencies will still be started by the plugin.
110+
*/
111+
skip?: boolean | 'only';
112112
}
113113
114114

README.zh-CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ interface Projects {
9999
match?: (stdout: string) => boolean;
100100
/**
101101
* 是否跳过当前子项目的启动,默认值为 `false`,通常用于跳过一些不需要启动的子项目。
102-
* 当值为 `prune` 时,会从指定项目进行剪枝,这意味着该项目以及他的所有直接和间接依赖都不会被插件启动。
103-
* 当值为 `true` 时,会跳过指定项目的启动,但不会进行剪枝,这意味着该项目的直接和间接依赖仍然会被插件启动。
102+
* 当值为 `true` 时,会从指定项目进行剪枝,这意味着该项目以及他的所有直接和间接依赖都不会被插件启动。
103+
* 当值为 `only` 时,会跳过指定项目的启动,但不会进行剪枝,这意味着该项目的直接和间接依赖仍然会被插件启动。
104104
*/
105-
skip?: 'prune' | boolean;
105+
skip?: boolean | 'only';
106106
}
107107
108108
// 例如,配置 lib1 子项目,用 build:watch 命令启动,匹配 watch success 日志

src/plugin.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,25 @@ export function pluginWorkspaceDev(
1212
name: 'rsbuild-plugin-workspace-dev',
1313
async setup(api) {
1414
const rootPath = api.context.rootPath;
15-
api.modifyRsbuildConfig(async () => {
15+
api.onBeforeStartDevServer(async () => {
1616
const runner = new WorkspaceDevRunner({
1717
cwd: rootPath,
1818
...options,
1919
});
20+
await runner.init();
21+
await runner.start();
22+
Logger.setEndBanner();
23+
});
24+
25+
api.onBeforeBuild(async ({ isWatch, isFirstCompile }) => {
26+
if (!isWatch || !isFirstCompile) {
27+
return;
28+
}
2029

30+
const runner = new WorkspaceDevRunner({
31+
cwd: rootPath,
32+
...options,
33+
});
2134
await runner.init();
2235
await runner.start();
2336
Logger.setEndBanner();

src/workspace-dev.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface WorkspaceDevRunnerOptions {
2727
{
2828
match?: (stdout: string) => boolean;
2929
command?: string;
30-
skip?: boolean | 'prune';
30+
skip?: boolean | 'only';
3131
}
3232
>;
3333
startCurrent?: boolean;
@@ -86,14 +86,14 @@ export class WorkspaceDevRunner {
8686
packageJson,
8787
path: dir,
8888
};
89-
if (this.options.projects?.[name]?.skip === 'prune') {
89+
const skip = this.options.projects?.[name]?.skip;
90+
if (skip && skip !== 'only') {
9091
console.log(
91-
`${PLUGIN_LOG_TITLE} Prune project ${name} and its dependencies because it is marked as skip: prune`,
92+
`${PLUGIN_LOG_TITLE} Prune project ${name} and its dependencies because it is marked as skip: true`,
9293
);
9394
return;
9495
}
9596
this.graph.setNode(name, node);
96-
// this.visited[name] = this.options.projects?.[name]?.skip ? true : false;
9797
this.visited[name] = false;
9898
this.visiting[name] = false;
9999
this.matched[name] = false;
@@ -110,10 +110,8 @@ export class WorkspaceDevRunner {
110110
(p) => p.packageJson.name === depName,
111111
);
112112

113-
if (
114-
isInternalDep &&
115-
this.options.projects?.[depName]?.skip !== 'prune'
116-
) {
113+
const skip = this.options.projects?.[depName]?.skip;
114+
if (isInternalDep && skip !== true) {
117115
this.graph.setEdge(packageName, depName);
118116
this.checkGraph();
119117
const depPackage = packages.find(

0 commit comments

Comments
 (0)