Skip to content

Commit cccf5e2

Browse files
authored
chore: rename config && use advanced esm (#7)
1 parent abb5f2b commit cccf5e2

File tree

6 files changed

+61
-24
lines changed

6 files changed

+61
-24
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,17 @@ Whether a sub-project has finished starting is determined by matching sub-projec
8383

8484
## Options
8585

86-
### projectConfig
86+
### projects
8787
Configure how sub-projects are started and define custom log matching logic.
8888

8989
- Type:
9090
```
91-
interface ProjectConfig {
91+
type projects = {
92+
// The key is the name of the sub-project's package.json file.
93+
[key: string]: Projects;
94+
}
95+
96+
interface projects {
9297
/**
9398
* Custom sub-project start command. Default is `dev` (runs `npm run dev`).
9499
*/
@@ -104,14 +109,25 @@ interface ProjectConfig {
104109
*/
105110
skip?: boolean;
106111
}
112+
113+
114+
// For example, to configure lib1 sub-project to use build:watch command and match watch success log
115+
pluginWorkspaceDev({
116+
projects: {
117+
lib1: {
118+
command: 'build:watch',
119+
match: (stdout) => stdout.includes('watch success'),
120+
},
121+
},
122+
})
107123
```
108124

109-
### ignoreSelf
125+
### startCurrent
110126

111127
- Type: `boolean`
112-
- Default: `true`
128+
- Default: `false`
113129

114-
Whether to ignore starting the current project. The default is `true`. In most cases, you start the current project manually, so the plugin does not interfere.
130+
Whether to also start the current project. The default is `false`. In most cases, you start the current project manually, so the plugin does not interfere.
115131

116132
Consider a scenario where docs and lib are in the same project, and docs needs to debug the output of lib. In this case, you want to run `pnpm doc` for the docs, while lib should run `pnpm dev`. After configuring this option in your Rspress config, starting `pnpm doc` will automatically run `pnpm dev` to start the lib sub-project.
117133

@@ -166,7 +182,7 @@ import { pluginWorkspaceDev } from "rsbuild-plugin-workspace-dev";
166182
export default {
167183
plugins: [
168184
pluginWorkspaceDev({
169-
projectConfig: {
185+
projects: {
170186
lib1: {
171187
skip: true,
172188
},

README.zh-CN.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ lib2 依赖了 lib3:
7878

7979
## 选项
8080

81-
### projectConfig
81+
### projects
8282
用于子项目的启动项配置和自定义日志匹配逻辑。
8383

84-
- **类型:**:
84+
- **类型:**
8585
```
86-
interface ProjectConfig {
86+
type projects = {
87+
// key 为子项目 package.json name
88+
[key: string]: Projects;
89+
}
90+
91+
interface Projects {
8792
/**
8893
* 自定义子项目启动命令,默认值为 `dev`, 即执行 `npm run dev`。
8994
*/
@@ -97,14 +102,25 @@ interface ProjectConfig {
97102
*/
98103
skip?: boolean;
99104
}
105+
106+
// 例如,配置 lib1 子项目,用 build:watch 命令启动,匹配 watch success 日志
107+
pluginWorkspaceDev({
108+
projects: {
109+
lib1: {
110+
command: 'build:watch',
111+
match: (stdout) => stdout.includes('watch success'),
112+
},
113+
},
114+
})
100115
```
101116

102-
### ignoreSelf
117+
118+
### startCurrent
103119

104120
- **类型:** `boolean`
105-
- **默认值:** `true`
106-
-
107-
是否忽略当前项目的启动,默认值为 `true`。一般无需手动配置,当前项目通常由用户手动执行 dev 启动,无需插件干预。
121+
- **默认值:** `false`
122+
123+
插件是否同时启动当前项目,默认值为 `false`。通常无需手动配置,当前项目通常由用户手动执行 dev 启动,无需插件干预。
108124

109125
考虑如下场景,docs 和 lib 是在同一个项目中,而 docs 需要调试 lib 的产物,此时需要启动 `pnpm doc` 命令,而 lib 则需要启动 `pnpm dev` 命令,配置该选项到 rspress 配置中后,启动 `pnpm doc` 时会自动执行 `pnpm dev` 命令,用于启动 lib 子项目。
110126
```
@@ -128,14 +144,14 @@ interface ProjectConfig {
128144
- **类型:** `string`
129145
- **默认值:** `process.cwd()`
130146

131-
用于配置当前工作目录,默认值为当前项目目录,一般无需配置
147+
用于配置当前工作目录,默认值为当前项目目录,通常无需配置
132148

133149
### workspaceFileDir
134150

135151
- **类型:** `string`
136152
- **默认值:** `process.cwd()`
137153

138-
用于配置 workspace 文件目录,默认值为当前项目目录,一般无需配置
154+
用于配置 workspace 文件目录,默认值为当前项目目录,通常无需配置
139155

140156

141157
## 常见问题
@@ -156,7 +172,7 @@ import { pluginWorkspaceDev } from "rsbuild-plugin-workspace-dev";
156172
export default {
157173
plugins: [
158174
pluginWorkspaceDev({
159-
projectConfig: {
175+
projects: {
160176
lib1: {
161177
skip: true,
162178
},

rslib.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { defineConfig } from '@rslib/core';
22

33
export default defineConfig({
44
lib: [
5-
{ format: 'esm', syntax: 'es2021', dts: true },
5+
{
6+
format: 'esm',
7+
syntax: 'es2021',
8+
dts: true,
9+
experiments: { advancedEsm: true },
10+
},
611
{ format: 'cjs', syntax: 'es2021' },
712
],
813
});

src/workspace-dev.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ interface GraphNode {
2222
export interface WorkspaceDevRunnerOptions {
2323
cwd?: string;
2424
workspaceFileDir?: string;
25-
projectConfig?: Record<
25+
projects?: Record<
2626
string,
2727
{
2828
match?: (stdout: string) => boolean;
2929
command?: string;
3030
skip?: boolean;
3131
}
3232
>;
33-
ignoreSelf?: boolean;
33+
startCurrent?: boolean;
3434
}
3535

3636
export class WorkspaceDevRunner {
@@ -46,7 +46,7 @@ export class WorkspaceDevRunner {
4646

4747
constructor(options: WorkspaceDevRunnerOptions) {
4848
this.options = {
49-
ignoreSelf: true,
49+
startCurrent: false,
5050
...options,
5151
};
5252
this.cwd = options.cwd || process.cwd();
@@ -136,7 +136,7 @@ export class WorkspaceDevRunner {
136136
const filterSelfNodes = allNodes.filter(
137137
(node) => node !== this.metaData.name,
138138
);
139-
const nodes = this.options.ignoreSelf ? filterSelfNodes : allNodes;
139+
const nodes = this.options.startCurrent ? allNodes : filterSelfNodes;
140140

141141
for (const node of nodes) {
142142
const dependencies = this.getDependencies(node) || [];
@@ -162,7 +162,7 @@ export class WorkspaceDevRunner {
162162
const logger = new Logger({
163163
name,
164164
});
165-
const config = this.options?.projectConfig?.[name];
165+
const config = this.options?.projects?.[name];
166166
if (config?.skip) {
167167
this.visited[node] = true;
168168
this.visiting[node] = false;

test/doc/rspress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default defineConfig({
3030
builderConfig: {
3131
plugins: [
3232
pluginWorkspaceDev({
33-
ignoreSelf: false,
33+
startCurrent: true,
3434
}),
3535
],
3636
},

test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ it('test', async () => {
127127
return matched;
128128
};
129129
const runner = new WorkspaceDevRunner({
130-
projectConfig: {
130+
projects: {
131131
a: {
132132
match: (stdout) => matchFn(stdout, 'a'),
133133
},

0 commit comments

Comments
 (0)