rsbuild-plugin-workspace-dev 0.0.1-beta.1 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -7
- package/README.zh-CN.md +49 -12
- package/dist/index.cjs +8 -8
- package/dist/index.js +8 -8
- package/dist/workspace-dev.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,12 +11,14 @@ Start monorepo sub-projects in topological order.
|
|
|
11
11
|
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
+
English | [简体中文](./README.zh-CN.md)
|
|
15
|
+
|
|
14
16
|
## Usage
|
|
15
17
|
|
|
16
18
|
Install:
|
|
17
19
|
|
|
18
20
|
```bash
|
|
19
|
-
|
|
21
|
+
pnpm add rsbuild-plugin-workspace-dev -D
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
Register the plugin in `rsbuild.config.ts`:
|
|
@@ -56,7 +58,7 @@ Here, app is built with Rsbuild, and lib is built with Rslib. The app depends on
|
|
|
56
58
|
}
|
|
57
59
|
```
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
lib2 depends on lib3:
|
|
60
62
|
|
|
61
63
|
```json
|
|
62
64
|
{
|
|
@@ -81,12 +83,17 @@ Whether a sub-project has finished starting is determined by matching sub-projec
|
|
|
81
83
|
|
|
82
84
|
## Options
|
|
83
85
|
|
|
84
|
-
###
|
|
86
|
+
### projects
|
|
85
87
|
Configure how sub-projects are started and define custom log matching logic.
|
|
86
88
|
|
|
87
89
|
- Type:
|
|
88
90
|
```
|
|
89
|
-
|
|
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 {
|
|
90
97
|
/**
|
|
91
98
|
* Custom sub-project start command. Default is `dev` (runs `npm run dev`).
|
|
92
99
|
*/
|
|
@@ -102,14 +109,25 @@ interface ProjectConfig {
|
|
|
102
109
|
*/
|
|
103
110
|
skip?: boolean;
|
|
104
111
|
}
|
|
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
|
+
})
|
|
105
123
|
```
|
|
106
124
|
|
|
107
|
-
###
|
|
125
|
+
### startCurrent
|
|
108
126
|
|
|
109
127
|
- Type: `boolean`
|
|
110
|
-
- Default: `
|
|
128
|
+
- Default: `false`
|
|
111
129
|
|
|
112
|
-
Whether to
|
|
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.
|
|
113
131
|
|
|
114
132
|
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.
|
|
115
133
|
|
|
@@ -144,6 +162,36 @@ Set the current working directory. The default is the current project directory;
|
|
|
144
162
|
|
|
145
163
|
Set the directory where the workspace file resides. The default is the current project directory; usually no configuration is needed.
|
|
146
164
|
|
|
165
|
+
## Frequently Asked Questions
|
|
166
|
+
|
|
167
|
+
### Project startup stuck
|
|
168
|
+
Stuck may be due to slow sub-project builds, etc. The lack of log output is because, by default, sub-project logs are output all at once after startup (to avoid interleaving sub-project logs). You can enable debug mode by adding an environment variable, which will allow sub-project logs to be output in real time.
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
DEBUG=rsbuild pnpm dev
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Some projects don't need to start
|
|
175
|
+
|
|
176
|
+
If some sub-projects don't need to start, simply configure `skip: true` for the specified project in `rsbuild.config.ts`.
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
// rsbuild.config.ts
|
|
180
|
+
import { pluginWorkspaceDev } from "rsbuild-plugin-workspace-dev";
|
|
181
|
+
|
|
182
|
+
export default {
|
|
183
|
+
plugins: [
|
|
184
|
+
pluginWorkspaceDev({
|
|
185
|
+
projects: {
|
|
186
|
+
lib1: {
|
|
187
|
+
skip: true,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
147
195
|
## License
|
|
148
196
|
|
|
149
197
|
[MIT](./LICENSE).
|
package/README.zh-CN.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
安装:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
|
|
19
|
+
pnpm add rsbuild-plugin-workspace-dev -D
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
在 `rsbuild.config.ts` 里注册插件:
|
|
@@ -78,12 +78,17 @@ lib2 依赖了 lib3:
|
|
|
78
78
|
|
|
79
79
|
## 选项
|
|
80
80
|
|
|
81
|
-
###
|
|
81
|
+
### projects
|
|
82
82
|
用于子项目的启动项配置和自定义日志匹配逻辑。
|
|
83
83
|
|
|
84
|
-
-
|
|
84
|
+
- **类型:**
|
|
85
85
|
```
|
|
86
|
-
|
|
86
|
+
type projects = {
|
|
87
|
+
// key 为子项目 package.json name
|
|
88
|
+
[key: string]: Projects;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface Projects {
|
|
87
92
|
/**
|
|
88
93
|
* 自定义子项目启动命令,默认值为 `dev`, 即执行 `npm run dev`。
|
|
89
94
|
*/
|
|
@@ -97,14 +102,26 @@ interface ProjectConfig {
|
|
|
97
102
|
*/
|
|
98
103
|
skip?: boolean;
|
|
99
104
|
}
|
|
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
|
+
})
|
|
100
115
|
```
|
|
101
116
|
|
|
102
|
-
|
|
117
|
+
|
|
118
|
+
### startCurrent
|
|
103
119
|
|
|
104
120
|
- **类型:** `boolean`
|
|
105
|
-
- **默认值:** `
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
- **默认值:** `false`
|
|
122
|
+
|
|
123
|
+
插件是否同时启动当前项目,默认值为 `false`。通常无需手动配置,当前项目通常由用户手动执行 dev 启动,无需插件干预。
|
|
124
|
+
|
|
108
125
|
考虑如下场景,docs 和 lib 是在同一个项目中,而 docs 需要调试 lib 的产物,此时需要启动 `pnpm doc` 命令,而 lib 则需要启动 `pnpm dev` 命令,配置该选项到 rspress 配置中后,启动 `pnpm doc` 时会自动执行 `pnpm dev` 命令,用于启动 lib 子项目。
|
|
109
126
|
```
|
|
110
127
|
├── docs
|
|
@@ -127,24 +144,44 @@ interface ProjectConfig {
|
|
|
127
144
|
- **类型:** `string`
|
|
128
145
|
- **默认值:** `process.cwd()`
|
|
129
146
|
|
|
130
|
-
|
|
147
|
+
用于配置当前工作目录,默认值为当前项目目录,通常无需配置。
|
|
131
148
|
|
|
132
149
|
### workspaceFileDir
|
|
133
150
|
|
|
134
151
|
- **类型:** `string`
|
|
135
152
|
- **默认值:** `process.cwd()`
|
|
136
153
|
|
|
137
|
-
用于配置 workspace
|
|
154
|
+
用于配置 workspace 文件目录,默认值为当前项目目录,通常无需配置。
|
|
138
155
|
|
|
139
156
|
|
|
140
157
|
## 常见问题
|
|
141
158
|
|
|
142
|
-
###
|
|
143
|
-
|
|
159
|
+
### 启动项目时卡住
|
|
160
|
+
卡住可能是因为子项目构建过慢等原因,没有日志输出是因为默认情况下子项目日志是启动完成后一次性输出的(为了避免子项目日志混和在一起交错输出),可以通过添加环境变量来开启调试模式,这会让子项目的日志实时输出。
|
|
144
161
|
```
|
|
145
162
|
DEBUG=rsbuild pnpm dev
|
|
146
163
|
```
|
|
147
164
|
|
|
165
|
+
### 某些项目无需启动
|
|
166
|
+
如果某些子项目不需要启动,只需要在 `rsbuild.config.ts` 中给指定项目配置 `skip: true` 即可。
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
// rsbuild.config.ts
|
|
170
|
+
import { pluginWorkspaceDev } from "rsbuild-plugin-workspace-dev";
|
|
171
|
+
|
|
172
|
+
export default {
|
|
173
|
+
plugins: [
|
|
174
|
+
pluginWorkspaceDev({
|
|
175
|
+
projects: {
|
|
176
|
+
lib1: {
|
|
177
|
+
skip: true,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
```
|
|
184
|
+
|
|
148
185
|
|
|
149
186
|
## License
|
|
150
187
|
|
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
38
38
|
});
|
|
39
39
|
const external_chalk_namespaceObject = require("chalk");
|
|
40
40
|
var external_chalk_default = /*#__PURE__*/ __webpack_require__.n(external_chalk_namespaceObject);
|
|
41
|
+
const PACKAGE_JSON = 'package.json';
|
|
42
|
+
const DEBUG_LOG_TITLE = '[Rsbuild Workspace Dev Plugin]: ';
|
|
43
|
+
const RSLIB_READY_MESSAGE = 'build complete, watching for changes';
|
|
44
|
+
const MODERN_MODULE_READY_MESSAGE = 'Watching for file changes';
|
|
45
|
+
const TSUP_READY_MESSAGE = 'Watching for changes in';
|
|
41
46
|
const external_fs_namespaceObject = require("fs");
|
|
42
47
|
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
|
|
43
48
|
const external_json5_namespaceObject = require("json5");
|
|
@@ -53,11 +58,6 @@ const readJson = async (jsonFileAbsPath)=>{
|
|
|
53
58
|
};
|
|
54
59
|
const readPackageJson = async (pkgJsonFilePath)=>readJson(pkgJsonFilePath);
|
|
55
60
|
const isDebug = 'rsbuild' === process.env.DEBUG || '*' === process.env.DEBUG;
|
|
56
|
-
const PACKAGE_JSON = 'package.json';
|
|
57
|
-
const DEBUG_LOG_TITLE = '[Rsbuild Workspace Dev Plugin]: ';
|
|
58
|
-
const RSLIB_READY_MESSAGE = 'build complete, watching for changes';
|
|
59
|
-
const MODERN_MODULE_READY_MESSAGE = 'Watching for file changes';
|
|
60
|
-
const TSUP_READY_MESSAGE = 'Watching for changes in';
|
|
61
61
|
function _define_property(obj, key, value) {
|
|
62
62
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
63
63
|
value: value,
|
|
@@ -179,7 +179,7 @@ class WorkspaceDevRunner {
|
|
|
179
179
|
const promises = [];
|
|
180
180
|
const allNodes = this.getNodes();
|
|
181
181
|
const filterSelfNodes = allNodes.filter((node)=>node !== this.metaData.name);
|
|
182
|
-
const nodes = this.options.
|
|
182
|
+
const nodes = this.options.startCurrent ? allNodes : filterSelfNodes;
|
|
183
183
|
for (const node of nodes){
|
|
184
184
|
const dependencies = this.getDependencies(node) || [];
|
|
185
185
|
const canStart = dependencies.every((dep)=>{
|
|
@@ -202,7 +202,7 @@ class WorkspaceDevRunner {
|
|
|
202
202
|
const logger = new Logger({
|
|
203
203
|
name
|
|
204
204
|
});
|
|
205
|
-
const config = this.options?.
|
|
205
|
+
const config = this.options?.projects?.[name];
|
|
206
206
|
if (config?.skip) {
|
|
207
207
|
this.visited[node] = true;
|
|
208
208
|
this.visiting[node] = false;
|
|
@@ -275,7 +275,7 @@ class WorkspaceDevRunner {
|
|
|
275
275
|
workspace_dev_define_property(this, "matched", void 0);
|
|
276
276
|
workspace_dev_define_property(this, "metaData", void 0);
|
|
277
277
|
this.options = {
|
|
278
|
-
|
|
278
|
+
startCurrent: false,
|
|
279
279
|
...options
|
|
280
280
|
};
|
|
281
281
|
this.cwd = options.cwd || process.cwd();
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,11 @@ import { getPackagesSync } from "@manypkg/get-packages";
|
|
|
5
5
|
import { spawn } from "child_process";
|
|
6
6
|
import graphlib, { Graph } from "graphlib";
|
|
7
7
|
import path_0 from "path";
|
|
8
|
+
const PACKAGE_JSON = 'package.json';
|
|
9
|
+
const DEBUG_LOG_TITLE = '[Rsbuild Workspace Dev Plugin]: ';
|
|
10
|
+
const RSLIB_READY_MESSAGE = 'build complete, watching for changes';
|
|
11
|
+
const MODERN_MODULE_READY_MESSAGE = 'Watching for file changes';
|
|
12
|
+
const TSUP_READY_MESSAGE = 'Watching for changes in';
|
|
8
13
|
async function pathExists(path) {
|
|
9
14
|
return fs.promises.access(path).then(()=>true).catch(()=>false);
|
|
10
15
|
}
|
|
@@ -16,11 +21,6 @@ const readJson = async (jsonFileAbsPath)=>{
|
|
|
16
21
|
};
|
|
17
22
|
const readPackageJson = async (pkgJsonFilePath)=>readJson(pkgJsonFilePath);
|
|
18
23
|
const isDebug = 'rsbuild' === process.env.DEBUG || '*' === process.env.DEBUG;
|
|
19
|
-
const PACKAGE_JSON = 'package.json';
|
|
20
|
-
const DEBUG_LOG_TITLE = '[Rsbuild Workspace Dev Plugin]: ';
|
|
21
|
-
const RSLIB_READY_MESSAGE = 'build complete, watching for changes';
|
|
22
|
-
const MODERN_MODULE_READY_MESSAGE = 'Watching for file changes';
|
|
23
|
-
const TSUP_READY_MESSAGE = 'Watching for changes in';
|
|
24
24
|
function _define_property(obj, key, value) {
|
|
25
25
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
26
26
|
value: value,
|
|
@@ -136,7 +136,7 @@ class WorkspaceDevRunner {
|
|
|
136
136
|
const promises = [];
|
|
137
137
|
const allNodes = this.getNodes();
|
|
138
138
|
const filterSelfNodes = allNodes.filter((node)=>node !== this.metaData.name);
|
|
139
|
-
const nodes = this.options.
|
|
139
|
+
const nodes = this.options.startCurrent ? allNodes : filterSelfNodes;
|
|
140
140
|
for (const node of nodes){
|
|
141
141
|
const dependencies = this.getDependencies(node) || [];
|
|
142
142
|
const canStart = dependencies.every((dep)=>{
|
|
@@ -159,7 +159,7 @@ class WorkspaceDevRunner {
|
|
|
159
159
|
const logger = new Logger({
|
|
160
160
|
name
|
|
161
161
|
});
|
|
162
|
-
const config = this.options?.
|
|
162
|
+
const config = this.options?.projects?.[name];
|
|
163
163
|
if (config?.skip) {
|
|
164
164
|
this.visited[node] = true;
|
|
165
165
|
this.visiting[node] = false;
|
|
@@ -232,7 +232,7 @@ class WorkspaceDevRunner {
|
|
|
232
232
|
workspace_dev_define_property(this, "matched", void 0);
|
|
233
233
|
workspace_dev_define_property(this, "metaData", void 0);
|
|
234
234
|
this.options = {
|
|
235
|
-
|
|
235
|
+
startCurrent: false,
|
|
236
236
|
...options
|
|
237
237
|
};
|
|
238
238
|
this.cwd = options.cwd || process.cwd();
|
package/dist/workspace-dev.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import graphlib from 'graphlib';
|
|
|
2
2
|
export interface WorkspaceDevRunnerOptions {
|
|
3
3
|
cwd?: string;
|
|
4
4
|
workspaceFileDir?: string;
|
|
5
|
-
|
|
5
|
+
projects?: Record<string, {
|
|
6
6
|
match?: (stdout: string) => boolean;
|
|
7
7
|
command?: string;
|
|
8
8
|
skip?: boolean;
|
|
9
9
|
}>;
|
|
10
|
-
|
|
10
|
+
startCurrent?: boolean;
|
|
11
11
|
}
|
|
12
12
|
export declare class WorkspaceDevRunner {
|
|
13
13
|
private options;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rsbuild-plugin-workspace-dev",
|
|
3
|
-
"version": "0.0.1
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"description": "An Rsbuild plugin to provides workspace recursive dev functionality for Monorepo topologies.",
|
|
5
5
|
"repository": "https://github.com/rspack-contrib/rsbuild-plugin-workspace-dev",
|
|
6
6
|
"license": "MIT",
|