@rsbuild/plugin-source-build 1.0.3 → 1.0.4
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 +18 -6
- package/README.zh-CN.md +18 -6
- package/dist/index.cjs +364 -383
- package/dist/index.js +2 -3
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -122,6 +122,18 @@ If the sub-project uses [exports](https://nodejs.org/api/packages.html#package-e
|
|
|
122
122
|
}
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
### Customizing Source Field
|
|
126
|
+
|
|
127
|
+
Although the plugin uses the `source` field by default to specify the source file, we recommend configuring a custom field through the [sourceField](#sourceField) option (for example, `@custom/source`, where `custom` can be replaced with any scope name).
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
pluginSourceBuild({
|
|
131
|
+
sourceField: "@custom/source",
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This is because some packages (such as Mobx) also define a `source` field in their `package.json`. If not distinguished, Rsbuild may mistakenly resolve the source files of those dependencies, leading to unexpected build results or type issues. By using a custom field, you can avoid such conflicts and ensure that Rsbuild behaves predictably when resolving dependencies.
|
|
136
|
+
|
|
125
137
|
## Configure Project Reference
|
|
126
138
|
|
|
127
139
|
In a TypeScript project, you need to use the capability provided by TypeScript called [Project Reference](https://typescriptlang.org/docs/handbook/project-references). It helps you develop source code more effectively.
|
|
@@ -154,7 +166,7 @@ At the same time, we need to set `composite` to `true` in the lib project's `tsc
|
|
|
154
166
|
{
|
|
155
167
|
"compilerOptions": {
|
|
156
168
|
"composite": true
|
|
157
|
-
}
|
|
169
|
+
}
|
|
158
170
|
}
|
|
159
171
|
```
|
|
160
172
|
|
|
@@ -173,24 +185,24 @@ Note that the above example is a simplified one. In real monorepo projects, ther
|
|
|
173
185
|
|
|
174
186
|
Used to configure the resolve field of the source code files.
|
|
175
187
|
|
|
176
|
-
For example, when configured as
|
|
188
|
+
For example, when configured as `@custom/source`:
|
|
177
189
|
|
|
178
190
|
```ts
|
|
179
191
|
pluginSourceBuild({
|
|
180
|
-
sourceField: "
|
|
192
|
+
sourceField: "@custom/source",
|
|
181
193
|
});
|
|
182
194
|
```
|
|
183
195
|
|
|
184
|
-
In `package.json`, the source code file path can be specified using
|
|
196
|
+
In `package.json`, the source code file path can be specified using `@custom/source`:
|
|
185
197
|
|
|
186
198
|
```json title="package.json"
|
|
187
199
|
{
|
|
188
200
|
"name": "lib",
|
|
189
201
|
"main": "./dist/index.js",
|
|
190
|
-
"
|
|
202
|
+
"@custom/source": "./src/index.ts",
|
|
191
203
|
"exports": {
|
|
192
204
|
".": {
|
|
193
|
-
"
|
|
205
|
+
"@custom/source": "./src/index.ts",
|
|
194
206
|
"default": "./dist/index.js"
|
|
195
207
|
}
|
|
196
208
|
}
|
package/README.zh-CN.md
CHANGED
|
@@ -120,6 +120,18 @@ monorepo
|
|
|
120
120
|
}
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
### 自定义 source 字段
|
|
124
|
+
|
|
125
|
+
虽然插件默认使用 `source` 字段来指定源代码文件,但我们更推荐通过 [sourceField](#sourceField) 选项配置一个自定义字段(例如 `@custom/source`,其中 `custom` 可以替换为任意 scope 名称)。
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
pluginSourceBuild({
|
|
129
|
+
sourceField: "@custom/source",
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
这是因为某些三方库(例如 Mobx)的 `package.json` 中也包含 `source` 字段,如果不进行区分,Rsbuild 可能会错误地解析这些库的源文件路径,从而导致意料之外的构建结果或类型问题。使用自定义字段可以避免此类冲突,确保 Rsbuild 在解析依赖关系时保持可控的行为。
|
|
134
|
+
|
|
123
135
|
## 配置 Project Reference
|
|
124
136
|
|
|
125
137
|
在 TypeScript 项目中,你需要使用 TypeScript 提供的 [Project Reference](https://typescriptlang.org/docs/handbook/project-references) 能力,它可以帮助你更好地使用源码开发。
|
|
@@ -152,7 +164,7 @@ Project reference 提供了以下能力:
|
|
|
152
164
|
{
|
|
153
165
|
"compilerOptions": {
|
|
154
166
|
"composite": true
|
|
155
|
-
}
|
|
167
|
+
}
|
|
156
168
|
}
|
|
157
169
|
```
|
|
158
170
|
|
|
@@ -171,24 +183,24 @@ Project reference 提供了以下能力:
|
|
|
171
183
|
|
|
172
184
|
用于配置源代码文件对应的解析字段。
|
|
173
185
|
|
|
174
|
-
比如配置为
|
|
186
|
+
比如配置为 `@custom/source`:
|
|
175
187
|
|
|
176
188
|
```ts
|
|
177
189
|
pluginSourceBuild({
|
|
178
|
-
sourceField: "
|
|
190
|
+
sourceField: "@custom/source",
|
|
179
191
|
});
|
|
180
192
|
```
|
|
181
193
|
|
|
182
|
-
在 `package.json` 中,即可通过
|
|
194
|
+
在 `package.json` 中,即可通过 `@custom/source` 指定源代码文件的路径:
|
|
183
195
|
|
|
184
196
|
```json title="package.json"
|
|
185
197
|
{
|
|
186
198
|
"name": "lib",
|
|
187
199
|
"main": "./dist/index.js",
|
|
188
|
-
"
|
|
200
|
+
"@custom/source": "./src/index.ts",
|
|
189
201
|
"exports": {
|
|
190
202
|
".": {
|
|
191
|
-
"
|
|
203
|
+
"@custom/source": "./src/index.ts",
|
|
192
204
|
"default": "./dist/index.js"
|
|
193
205
|
}
|
|
194
206
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
yaml: function(module) {
|
|
4
|
-
module.exports = import("yaml").then(function(module) {
|
|
5
|
-
return module;
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
var __webpack_module_cache__ = {};
|
|
10
|
-
function __webpack_require__(moduleId) {
|
|
11
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
12
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
13
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
14
|
-
exports: {}
|
|
15
|
-
};
|
|
16
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
17
|
-
return module.exports;
|
|
18
|
-
}
|
|
2
|
+
var __webpack_require__ = {};
|
|
19
3
|
(()=>{
|
|
20
4
|
__webpack_require__.n = (module)=>{
|
|
21
5
|
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
@@ -47,396 +31,393 @@ function __webpack_require__(moduleId) {
|
|
|
47
31
|
};
|
|
48
32
|
})();
|
|
49
33
|
var __webpack_exports__ = {};
|
|
50
|
-
(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if ('
|
|
81
|
-
for (const [monorepoType, monorepoCheck] of Object.entries(otherMonorepoChecks))if ('function' == typeof monorepoCheck && await monorepoCheck(monorepoRootPath)) return {
|
|
82
|
-
isMonorepo: true,
|
|
83
|
-
type: monorepoType
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (await isPnpmMonorepo(monorepoRootPath)) return {
|
|
87
|
-
isMonorepo: true,
|
|
88
|
-
type: 'pnpm'
|
|
89
|
-
};
|
|
90
|
-
if (await isRushMonorepo(monorepoRootPath)) return {
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
Project: ()=>Project,
|
|
37
|
+
PLUGIN_SOURCE_BUILD_NAME: ()=>PLUGIN_SOURCE_BUILD_NAME,
|
|
38
|
+
getMonorepoSubProjects: ()=>getMonorepoSubProjects,
|
|
39
|
+
pluginSourceBuild: ()=>pluginSourceBuild,
|
|
40
|
+
getMonorepoBaseData: ()=>getMonorepoBaseData
|
|
41
|
+
});
|
|
42
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
43
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
44
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
45
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
46
|
+
const external_json5_namespaceObject = require("json5");
|
|
47
|
+
var external_json5_default = /*#__PURE__*/ __webpack_require__.n(external_json5_namespaceObject);
|
|
48
|
+
const PNPM_WORKSPACE_FILE = 'pnpm-workspace.yaml';
|
|
49
|
+
const RUSH_JSON_FILE = 'rush.json';
|
|
50
|
+
const PACKAGE_JSON = 'package.json';
|
|
51
|
+
async function pathExists(path) {
|
|
52
|
+
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
53
|
+
}
|
|
54
|
+
const isPnpmMonorepo = async (monorepoRootPath)=>{
|
|
55
|
+
const existPnpmWorkspaceFile = await pathExists(external_node_path_default().join(monorepoRootPath, PNPM_WORKSPACE_FILE));
|
|
56
|
+
return existPnpmWorkspaceFile;
|
|
57
|
+
};
|
|
58
|
+
const isRushMonorepo = async (monorepoRootPath)=>{
|
|
59
|
+
const existRushJsonFile = await pathExists(external_node_path_default().join(monorepoRootPath, RUSH_JSON_FILE));
|
|
60
|
+
return existRushJsonFile;
|
|
61
|
+
};
|
|
62
|
+
const isMonorepo = async (monorepoRootPath, otherMonorepoChecks)=>{
|
|
63
|
+
if ('object' == typeof otherMonorepoChecks) {
|
|
64
|
+
for (const [monorepoType, monorepoCheck] of Object.entries(otherMonorepoChecks))if ('function' == typeof monorepoCheck && await monorepoCheck(monorepoRootPath)) return {
|
|
91
65
|
isMonorepo: true,
|
|
92
|
-
type:
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
isMonorepo: false,
|
|
96
|
-
type: ''
|
|
66
|
+
type: monorepoType
|
|
97
67
|
};
|
|
68
|
+
}
|
|
69
|
+
if (await isPnpmMonorepo(monorepoRootPath)) return {
|
|
70
|
+
isMonorepo: true,
|
|
71
|
+
type: 'pnpm'
|
|
98
72
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let findPath = starFindPath;
|
|
103
|
-
let type = '';
|
|
104
|
-
let otherMonorepoChecks;
|
|
105
|
-
if (otherMonorepoAnalyzer) {
|
|
106
|
-
otherMonorepoChecks = otherMonorepoChecks ?? {};
|
|
107
|
-
for (const [monoType, analyzer] of Object.entries(otherMonorepoAnalyzer))otherMonorepoChecks[monoType] = analyzer.check;
|
|
108
|
-
}
|
|
109
|
-
while(true){
|
|
110
|
-
const result = await isMonorepo(findPath, otherMonorepoChecks);
|
|
111
|
-
if (result.isMonorepo) {
|
|
112
|
-
repoIsMonorepo = true;
|
|
113
|
-
({ type } = result);
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
if (findPath === external_node_path_default().dirname(findPath)) break;
|
|
117
|
-
findPath = external_node_path_default().dirname(findPath);
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
isMonorepo: repoIsMonorepo,
|
|
121
|
-
rootPath: repoIsMonorepo ? findPath : '',
|
|
122
|
-
type,
|
|
123
|
-
getProjects: null == otherMonorepoAnalyzer ? void 0 : null == (_otherMonorepoAnalyzer_type = otherMonorepoAnalyzer[type]) ? void 0 : _otherMonorepoAnalyzer_type.getProjects
|
|
124
|
-
};
|
|
73
|
+
if (await isRushMonorepo(monorepoRootPath)) return {
|
|
74
|
+
isMonorepo: true,
|
|
75
|
+
type: 'rush'
|
|
125
76
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const readRushJson = async (rushJsonFilePath)=>{
|
|
130
|
-
const rushJson = readJson(rushJsonFilePath.includes(RUSH_JSON_FILE) ? rushJsonFilePath : external_node_path_default().join(rushJsonFilePath, RUSH_JSON_FILE));
|
|
131
|
-
return rushJson;
|
|
77
|
+
return {
|
|
78
|
+
isMonorepo: false,
|
|
79
|
+
type: ''
|
|
132
80
|
};
|
|
133
|
-
|
|
134
|
-
|
|
81
|
+
};
|
|
82
|
+
const getMonorepoBaseData = async (starFindPath, otherMonorepoAnalyzer)=>{
|
|
83
|
+
let repoIsMonorepo = false;
|
|
84
|
+
let findPath = starFindPath;
|
|
85
|
+
let type = '';
|
|
86
|
+
let otherMonorepoChecks;
|
|
87
|
+
if (otherMonorepoAnalyzer) {
|
|
88
|
+
otherMonorepoChecks = otherMonorepoChecks ?? {};
|
|
89
|
+
for (const [monoType, analyzer] of Object.entries(otherMonorepoAnalyzer))otherMonorepoChecks[monoType] = analyzer.check;
|
|
90
|
+
}
|
|
91
|
+
while(true){
|
|
92
|
+
const result = await isMonorepo(findPath, otherMonorepoChecks);
|
|
93
|
+
if (result.isMonorepo) {
|
|
94
|
+
repoIsMonorepo = true;
|
|
95
|
+
({ type } = result);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (findPath === external_node_path_default().dirname(findPath)) break;
|
|
99
|
+
findPath = external_node_path_default().dirname(findPath);
|
|
135
100
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
101
|
+
return {
|
|
102
|
+
isMonorepo: repoIsMonorepo,
|
|
103
|
+
rootPath: repoIsMonorepo ? findPath : '',
|
|
104
|
+
type,
|
|
105
|
+
getProjects: otherMonorepoAnalyzer?.[type]?.getProjects
|
|
141
106
|
};
|
|
142
|
-
|
|
143
|
-
|
|
107
|
+
};
|
|
108
|
+
const external_fast_glob_namespaceObject = require("fast-glob");
|
|
109
|
+
var external_fast_glob_default = /*#__PURE__*/ __webpack_require__.n(external_fast_glob_namespaceObject);
|
|
110
|
+
const readPackageJson = async (pkgJsonFilePath)=>readJson(pkgJsonFilePath);
|
|
111
|
+
const readRushJson = async (rushJsonFilePath)=>{
|
|
112
|
+
const rushJson = readJson(rushJsonFilePath.includes(RUSH_JSON_FILE) ? rushJsonFilePath : external_node_path_default().join(rushJsonFilePath, RUSH_JSON_FILE));
|
|
113
|
+
return rushJson;
|
|
114
|
+
};
|
|
115
|
+
async function utils_pathExists(path) {
|
|
116
|
+
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
117
|
+
}
|
|
118
|
+
const readJson = async (jsonFileAbsPath)=>{
|
|
119
|
+
if (!await utils_pathExists(jsonFileAbsPath)) return {};
|
|
120
|
+
const content = await external_node_fs_default().promises.readFile(jsonFileAbsPath, 'utf-8');
|
|
121
|
+
const json = external_json5_default().parse(content);
|
|
122
|
+
return json;
|
|
123
|
+
};
|
|
124
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
125
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
126
|
+
}
|
|
127
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
128
|
+
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
|
|
129
|
+
return fn;
|
|
130
|
+
}
|
|
131
|
+
function _class_private_method_init(obj, privateSet) {
|
|
132
|
+
_check_private_redeclaration(obj, privateSet);
|
|
133
|
+
privateSet.add(obj);
|
|
134
|
+
}
|
|
135
|
+
function _define_property(obj, key, value) {
|
|
136
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
137
|
+
value: value,
|
|
138
|
+
enumerable: true,
|
|
139
|
+
configurable: true,
|
|
140
|
+
writable: true
|
|
141
|
+
});
|
|
142
|
+
else obj[key] = value;
|
|
143
|
+
return obj;
|
|
144
|
+
}
|
|
145
|
+
var _getExportsSourceDirs = /*#__PURE__*/ new WeakSet(), _getCommonRootPaths = /*#__PURE__*/ new WeakSet(), _getRootPath = /*#__PURE__*/ new WeakSet();
|
|
146
|
+
class Project {
|
|
147
|
+
async init() {
|
|
148
|
+
this.metaData = await readPackageJson(external_node_path_default().join(this.dir, PACKAGE_JSON));
|
|
144
149
|
}
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
150
|
+
getMetaData() {
|
|
151
|
+
if (null === this.metaData) throw new Error('The Project object needs to be initialized by executing the `init` function');
|
|
152
|
+
return this.metaData;
|
|
148
153
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
getDependentProjects(monorepoProjects, options) {
|
|
155
|
+
const { recursive } = options ?? {
|
|
156
|
+
recursive: false
|
|
157
|
+
};
|
|
158
|
+
const allProjectMap = new Map();
|
|
159
|
+
for (const project of monorepoProjects)allProjectMap.set(project.name, project);
|
|
160
|
+
if (!recursive) return this.getDirectDependentProjects(allProjectMap);
|
|
161
|
+
const computedSet = new Set();
|
|
162
|
+
computedSet.add(this.name);
|
|
163
|
+
const queue = this.getDirectDependentProjects(allProjectMap).filter((p)=>!computedSet.has(p.name));
|
|
164
|
+
const result = [];
|
|
165
|
+
while(queue.length > 0){
|
|
166
|
+
const item = queue.shift();
|
|
167
|
+
if (computedSet.has(item.name)) continue;
|
|
168
|
+
result.push(item);
|
|
169
|
+
computedSet.add(item.name);
|
|
170
|
+
const newDeps = item.getDirectDependentProjects(allProjectMap);
|
|
171
|
+
if (newDeps.length > 0) queue.push(...newDeps);
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
152
174
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
else obj[key] = value;
|
|
161
|
-
return obj;
|
|
175
|
+
getDirectDependentProjects(allProjectMap) {
|
|
176
|
+
const pkgJson = this.getMetaData();
|
|
177
|
+
const { dependencies = {}, devDependencies = {} } = pkgJson;
|
|
178
|
+
const projects = [];
|
|
179
|
+
for (const d of Object.keys(dependencies))if (allProjectMap.has(d)) projects.push(allProjectMap.get(d));
|
|
180
|
+
for (const d of Object.keys(devDependencies))if (allProjectMap.has(d)) projects.push(allProjectMap.get(d));
|
|
181
|
+
return projects;
|
|
162
182
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
getDependentProjects(monorepoProjects, options) {
|
|
173
|
-
const { recursive } = options ?? {
|
|
174
|
-
recursive: false
|
|
175
|
-
};
|
|
176
|
-
const allProjectMap = new Map();
|
|
177
|
-
for (const project of monorepoProjects)allProjectMap.set(project.name, project);
|
|
178
|
-
if (!recursive) return this.getDirectDependentProjects(allProjectMap);
|
|
179
|
-
const computedSet = new Set();
|
|
180
|
-
computedSet.add(this.name);
|
|
181
|
-
const queue = this.getDirectDependentProjects(allProjectMap).filter((p)=>!computedSet.has(p.name));
|
|
182
|
-
const result = [];
|
|
183
|
-
while(queue.length > 0){
|
|
184
|
-
const item = queue.shift();
|
|
185
|
-
if (computedSet.has(item.name)) continue;
|
|
186
|
-
result.push(item);
|
|
187
|
-
computedSet.add(item.name);
|
|
188
|
-
const newDeps = item.getDirectDependentProjects(allProjectMap);
|
|
189
|
-
if (newDeps.length > 0) queue.push(...newDeps);
|
|
190
|
-
}
|
|
191
|
-
return result;
|
|
192
|
-
}
|
|
193
|
-
getDirectDependentProjects(allProjectMap) {
|
|
194
|
-
const pkgJson = this.getMetaData();
|
|
195
|
-
const { dependencies = {}, devDependencies = {} } = pkgJson;
|
|
196
|
-
const projects = [];
|
|
197
|
-
for (const d of Object.keys(dependencies))if (allProjectMap.has(d)) projects.push(allProjectMap.get(d));
|
|
198
|
-
for (const d of Object.keys(devDependencies))if (allProjectMap.has(d)) projects.push(allProjectMap.get(d));
|
|
199
|
-
return projects;
|
|
200
|
-
}
|
|
201
|
-
getSourceEntryPaths(options) {
|
|
202
|
-
const { exports: checkExports = false, field: sourceField = 'source' } = options ?? {};
|
|
203
|
-
const pkgJson = this.getMetaData();
|
|
204
|
-
const sourceDirs = pkgJson[sourceField] ? [
|
|
205
|
-
external_node_path_default().normalize(pkgJson[sourceField])
|
|
206
|
-
] : [];
|
|
207
|
-
if (checkExports) {
|
|
208
|
-
const exportsSourceDirs = _class_private_method_get(this, _getExportsSourceDirs, getExportsSourceDirs).call(this, pkgJson.exports ?? {}, sourceField);
|
|
209
|
-
sourceDirs.push(...exportsSourceDirs);
|
|
210
|
-
}
|
|
211
|
-
if (!sourceDirs.length) throw new Error(`"${sourceField}" field is not found in ${this.name} package.json`);
|
|
212
|
-
return _class_private_method_get(this, _getCommonRootPaths, getCommonRootPaths).call(this, sourceDirs);
|
|
213
|
-
}
|
|
214
|
-
constructor(name, dir){
|
|
215
|
-
_class_private_method_init(this, _getExportsSourceDirs);
|
|
216
|
-
_class_private_method_init(this, _getCommonRootPaths);
|
|
217
|
-
_class_private_method_init(this, _getRootPath);
|
|
218
|
-
_define_property(this, "name", void 0);
|
|
219
|
-
_define_property(this, "dir", void 0);
|
|
220
|
-
_define_property(this, "metaData", void 0);
|
|
221
|
-
this.name = name;
|
|
222
|
-
this.dir = dir;
|
|
183
|
+
getSourceEntryPaths(options) {
|
|
184
|
+
const { exports: checkExports = false, field: sourceField = 'source' } = options ?? {};
|
|
185
|
+
const pkgJson = this.getMetaData();
|
|
186
|
+
const sourceDirs = pkgJson[sourceField] ? [
|
|
187
|
+
external_node_path_default().normalize(pkgJson[sourceField])
|
|
188
|
+
] : [];
|
|
189
|
+
if (checkExports) {
|
|
190
|
+
const exportsSourceDirs = _class_private_method_get(this, _getExportsSourceDirs, getExportsSourceDirs).call(this, pkgJson.exports ?? {}, sourceField);
|
|
191
|
+
sourceDirs.push(...exportsSourceDirs);
|
|
223
192
|
}
|
|
193
|
+
if (!sourceDirs.length) throw new Error(`"${sourceField}" field is not found in ${this.name} package.json`);
|
|
194
|
+
return _class_private_method_get(this, _getCommonRootPaths, getCommonRootPaths).call(this, sourceDirs);
|
|
224
195
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
196
|
+
constructor(name, dir){
|
|
197
|
+
_class_private_method_init(this, _getExportsSourceDirs);
|
|
198
|
+
_class_private_method_init(this, _getCommonRootPaths);
|
|
199
|
+
_class_private_method_init(this, _getRootPath);
|
|
200
|
+
_define_property(this, "name", void 0);
|
|
201
|
+
_define_property(this, "dir", void 0);
|
|
202
|
+
_define_property(this, "metaData", void 0);
|
|
203
|
+
this.name = name;
|
|
204
|
+
this.dir = dir;
|
|
230
205
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
206
|
+
}
|
|
207
|
+
function getExportsSourceDirs(exportsConfig, sourceField) {
|
|
208
|
+
const exportsSourceDirs = [];
|
|
209
|
+
if ('string' == typeof exportsConfig[sourceField]) exportsSourceDirs.push(external_node_path_default().normalize(exportsConfig[sourceField]));
|
|
210
|
+
for (const moduleRules of Object.values(exportsConfig))if ('object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]) exportsSourceDirs.push(external_node_path_default().normalize(moduleRules[sourceField]));
|
|
211
|
+
return exportsSourceDirs;
|
|
212
|
+
}
|
|
213
|
+
function getCommonRootPaths(paths) {
|
|
214
|
+
const commonRootPathsSet = new Set();
|
|
215
|
+
for (const p of paths){
|
|
216
|
+
let dir;
|
|
217
|
+
try {
|
|
218
|
+
dir = external_node_fs_default().statSync(p).isDirectory() ? p : external_node_path_default().dirname(p);
|
|
219
|
+
} catch {
|
|
220
|
+
dir = external_node_path_default().dirname(p);
|
|
242
221
|
}
|
|
243
|
-
|
|
222
|
+
const rootPath = _class_private_method_get(this, _getRootPath, getRootPath).call(this, dir);
|
|
223
|
+
if (!commonRootPathsSet.has(rootPath)) commonRootPathsSet.add(rootPath);
|
|
244
224
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
'**/dist/**',
|
|
264
|
-
'**/node_modules/**'
|
|
265
|
-
];
|
|
266
|
-
return globOpts;
|
|
225
|
+
return Array.from(commonRootPathsSet).map((p)=>external_node_path_default().join(this.dir, p));
|
|
226
|
+
}
|
|
227
|
+
function getRootPath(p) {
|
|
228
|
+
return p.split(external_node_path_default().sep)[0];
|
|
229
|
+
}
|
|
230
|
+
const getPatternsFromYaml = async (monorepoRoot)=>{
|
|
231
|
+
const { parse } = await import("yaml");
|
|
232
|
+
const workspaceYamlFilePath = external_node_path_default().join(monorepoRoot, PNPM_WORKSPACE_FILE);
|
|
233
|
+
const yamlContent = await external_node_fs_default().promises.readFile(workspaceYamlFilePath, 'utf8');
|
|
234
|
+
const pnpmWorkspace = parse(yamlContent);
|
|
235
|
+
return pnpmWorkspace.packages || [];
|
|
236
|
+
};
|
|
237
|
+
const normalize = (results)=>results.map((fp)=>external_node_path_default().normalize(fp));
|
|
238
|
+
const getGlobOpts = (rootPath, patterns)=>{
|
|
239
|
+
const globOpts = {
|
|
240
|
+
cwd: rootPath,
|
|
241
|
+
absolute: true,
|
|
242
|
+
followSymbolicLinks: false
|
|
267
243
|
};
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
244
|
+
if (patterns.some((cfg)=>cfg.includes('**') || cfg.includes('*'))) globOpts.ignore = [
|
|
245
|
+
'**/dist/**',
|
|
246
|
+
'**/node_modules/**'
|
|
247
|
+
];
|
|
248
|
+
return globOpts;
|
|
249
|
+
};
|
|
250
|
+
const makeFileFinder = (rootPath, patterns)=>{
|
|
251
|
+
const globOpts = getGlobOpts(rootPath, patterns);
|
|
252
|
+
return async (fileName, fileMapper)=>{
|
|
253
|
+
let result = await external_fast_glob_default()(patterns.map((globPath)=>external_node_path_default().posix.join(globPath, fileName)), globOpts);
|
|
254
|
+
result = result.sort();
|
|
255
|
+
result = normalize(result);
|
|
256
|
+
return fileMapper(result);
|
|
276
257
|
};
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
258
|
+
};
|
|
259
|
+
const readPnpmProjects = async (monorepoRoot, patterns)=>{
|
|
260
|
+
const finder = makeFileFinder(monorepoRoot, patterns);
|
|
261
|
+
const mapper = async (pkgJsonFilePath)=>{
|
|
262
|
+
const pkgJson = await readPackageJson(pkgJsonFilePath);
|
|
263
|
+
return {
|
|
264
|
+
dir: external_node_path_default().dirname(pkgJsonFilePath),
|
|
265
|
+
manifest: pkgJson
|
|
285
266
|
};
|
|
286
|
-
const projects = await finder(PACKAGE_JSON, (filePaths)=>Promise.all(filePaths.map(mapper)));
|
|
287
|
-
return projects;
|
|
288
|
-
};
|
|
289
|
-
const pnpm_getProjects = async (monorepoRoot)=>{
|
|
290
|
-
const patterns = await getPatternsFromYaml(monorepoRoot);
|
|
291
|
-
const pnpmProjects = await readPnpmProjects(monorepoRoot, patterns);
|
|
292
|
-
return Promise.all(pnpmProjects.filter((p)=>p.manifest.name).map(async (p)=>{
|
|
293
|
-
const project = new Project(p.manifest.name, p.dir);
|
|
294
|
-
await project.init();
|
|
295
|
-
return project;
|
|
296
|
-
}));
|
|
297
|
-
};
|
|
298
|
-
const rush_getProjects = async (monorepoRoot)=>{
|
|
299
|
-
const rushConfiguration = await readRushJson(monorepoRoot);
|
|
300
|
-
const { projects = [] } = rushConfiguration;
|
|
301
|
-
return Promise.all(projects.map(async (p)=>{
|
|
302
|
-
const project = new Project(p.packageName, external_node_path_default().join(monorepoRoot, p.projectFolder));
|
|
303
|
-
await project.init();
|
|
304
|
-
return project;
|
|
305
|
-
}));
|
|
306
|
-
};
|
|
307
|
-
const getMonorepoSubProjects = async (monorepoBaseData)=>{
|
|
308
|
-
const { type, rootPath, getProjects } = monorepoBaseData;
|
|
309
|
-
if ('pnpm' === type) return pnpm_getProjects(rootPath);
|
|
310
|
-
if ('rush' === type) return rush_getProjects(rootPath);
|
|
311
|
-
if (getProjects) return getProjects(rootPath);
|
|
312
|
-
return [];
|
|
313
|
-
};
|
|
314
|
-
async function getDependentProjects_pathExists(path) {
|
|
315
|
-
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
316
|
-
}
|
|
317
|
-
const getDependentProjects = async (projectNameOrRootPath, options)=>{
|
|
318
|
-
const { cwd = process.cwd(), recursive, filter, extraMonorepoStrategies } = options;
|
|
319
|
-
const currentProjectPkgJsonPath = external_node_path_default().join(projectNameOrRootPath, 'package.json');
|
|
320
|
-
let projectName;
|
|
321
|
-
if (await getDependentProjects_pathExists(currentProjectPkgJsonPath)) ({ name: projectName } = await readPackageJson(currentProjectPkgJsonPath));
|
|
322
|
-
else projectName = projectNameOrRootPath;
|
|
323
|
-
const monoBaseData = await getMonorepoBaseData(cwd, extraMonorepoStrategies);
|
|
324
|
-
if (!monoBaseData.isMonorepo) return [];
|
|
325
|
-
const projects = await getMonorepoSubProjects(monoBaseData);
|
|
326
|
-
const currentProject = projects.find((project)=>project.name === projectName);
|
|
327
|
-
if (!currentProject) return [];
|
|
328
|
-
let dependentProjects = currentProject.getDependentProjects(projects, {
|
|
329
|
-
recursive
|
|
330
|
-
});
|
|
331
|
-
if (filter) dependentProjects = await filter(dependentProjects);
|
|
332
|
-
return dependentProjects;
|
|
333
|
-
};
|
|
334
|
-
function hasExportsSourceField(exportsConfig, sourceField) {
|
|
335
|
-
return 'string' == typeof exportsConfig[sourceField] || Object.values(exportsConfig).some((moduleRules)=>'object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]);
|
|
336
|
-
}
|
|
337
|
-
const filterByField = (fieldName, checkExports)=>(projects)=>projects.filter((p)=>fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName));
|
|
338
|
-
const PLUGIN_SOURCE_BUILD_NAME = 'rsbuild:source-build';
|
|
339
|
-
const getSourceInclude = async (options)=>{
|
|
340
|
-
const { projects, sourceField } = options;
|
|
341
|
-
const includes = [];
|
|
342
|
-
for (const project of projects)includes.push(...project.getSourceEntryPaths({
|
|
343
|
-
field: sourceField,
|
|
344
|
-
exports: true
|
|
345
|
-
}));
|
|
346
|
-
return includes;
|
|
347
267
|
};
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
268
|
+
const projects = await finder(PACKAGE_JSON, (filePaths)=>Promise.all(filePaths.map(mapper)));
|
|
269
|
+
return projects;
|
|
270
|
+
};
|
|
271
|
+
const pnpm_getProjects = async (monorepoRoot)=>{
|
|
272
|
+
const patterns = await getPatternsFromYaml(monorepoRoot);
|
|
273
|
+
const pnpmProjects = await readPnpmProjects(monorepoRoot, patterns);
|
|
274
|
+
return Promise.all(pnpmProjects.filter((p)=>p.manifest.name).map(async (p)=>{
|
|
275
|
+
const project = new Project(p.manifest.name, p.dir);
|
|
276
|
+
await project.init();
|
|
277
|
+
return project;
|
|
278
|
+
}));
|
|
279
|
+
};
|
|
280
|
+
const rush_getProjects = async (monorepoRoot)=>{
|
|
281
|
+
const rushConfiguration = await readRushJson(monorepoRoot);
|
|
282
|
+
const { projects = [] } = rushConfiguration;
|
|
283
|
+
return Promise.all(projects.map(async (p)=>{
|
|
284
|
+
const project = new Project(p.packageName, external_node_path_default().join(monorepoRoot, p.projectFolder));
|
|
285
|
+
await project.init();
|
|
286
|
+
return project;
|
|
287
|
+
}));
|
|
288
|
+
};
|
|
289
|
+
const getMonorepoSubProjects = async (monorepoBaseData)=>{
|
|
290
|
+
const { type, rootPath, getProjects } = monorepoBaseData;
|
|
291
|
+
if ('pnpm' === type) return pnpm_getProjects(rootPath);
|
|
292
|
+
if ('rush' === type) return rush_getProjects(rootPath);
|
|
293
|
+
if (getProjects) return getProjects(rootPath);
|
|
294
|
+
return [];
|
|
295
|
+
};
|
|
296
|
+
async function getDependentProjects_pathExists(path) {
|
|
297
|
+
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
298
|
+
}
|
|
299
|
+
const getDependentProjects = async (projectNameOrRootPath, options)=>{
|
|
300
|
+
const { cwd = process.cwd(), recursive, filter, extraMonorepoStrategies } = options;
|
|
301
|
+
const currentProjectPkgJsonPath = external_node_path_default().join(projectNameOrRootPath, 'package.json');
|
|
302
|
+
let projectName;
|
|
303
|
+
if (await getDependentProjects_pathExists(currentProjectPkgJsonPath)) ({ name: projectName } = await readPackageJson(currentProjectPkgJsonPath));
|
|
304
|
+
else projectName = projectNameOrRootPath;
|
|
305
|
+
const monoBaseData = await getMonorepoBaseData(cwd, extraMonorepoStrategies);
|
|
306
|
+
if (!monoBaseData.isMonorepo) return [];
|
|
307
|
+
const projects = await getMonorepoSubProjects(monoBaseData);
|
|
308
|
+
const currentProject = projects.find((project)=>project.name === projectName);
|
|
309
|
+
if (!currentProject) return [];
|
|
310
|
+
let dependentProjects = currentProject.getDependentProjects(projects, {
|
|
311
|
+
recursive
|
|
312
|
+
});
|
|
313
|
+
if (filter) dependentProjects = await filter(dependentProjects);
|
|
314
|
+
return dependentProjects;
|
|
315
|
+
};
|
|
316
|
+
function hasExportsSourceField(exportsConfig, sourceField) {
|
|
317
|
+
return 'string' == typeof exportsConfig[sourceField] || Object.values(exportsConfig).some((moduleRules)=>'object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]);
|
|
318
|
+
}
|
|
319
|
+
const filterByField = (fieldName, checkExports)=>(projects)=>projects.filter((p)=>fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName));
|
|
320
|
+
const PLUGIN_SOURCE_BUILD_NAME = 'rsbuild:source-build';
|
|
321
|
+
const getSourceInclude = async (options)=>{
|
|
322
|
+
const { projects, sourceField } = options;
|
|
323
|
+
const includes = [];
|
|
324
|
+
for (const project of projects)includes.push(...project.getSourceEntryPaths({
|
|
325
|
+
field: sourceField,
|
|
326
|
+
exports: true
|
|
327
|
+
}));
|
|
328
|
+
return includes;
|
|
329
|
+
};
|
|
330
|
+
function pluginSourceBuild(options) {
|
|
331
|
+
const { projectName, sourceField = 'source', resolvePriority = 'source', extraMonorepoStrategies } = options ?? {};
|
|
332
|
+
return {
|
|
333
|
+
name: PLUGIN_SOURCE_BUILD_NAME,
|
|
334
|
+
setup (api) {
|
|
335
|
+
const projectRootPath = api.context.rootPath;
|
|
336
|
+
let projects;
|
|
337
|
+
api.modifyEnvironmentConfig(async (config)=>{
|
|
338
|
+
projects = projects || await getDependentProjects(projectName || projectRootPath, {
|
|
339
|
+
cwd: projectRootPath,
|
|
340
|
+
recursive: true,
|
|
341
|
+
filter: filterByField(sourceField, true),
|
|
342
|
+
extraMonorepoStrategies
|
|
371
343
|
});
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
CHAIN_ID.RULE.JS
|
|
376
|
-
])if (chain.module.rules.get(ruleId)) {
|
|
377
|
-
const rule = chain.module.rule(ruleId);
|
|
378
|
-
rule.resolve.mainFields.merge('source' === resolvePriority ? [
|
|
379
|
-
sourceField,
|
|
380
|
-
'...'
|
|
381
|
-
] : [
|
|
382
|
-
'...',
|
|
383
|
-
sourceField
|
|
384
|
-
]);
|
|
385
|
-
rule.resolve.conditionNames.add('...').add(sourceField);
|
|
386
|
-
}
|
|
344
|
+
const includes = await getSourceInclude({
|
|
345
|
+
projects,
|
|
346
|
+
sourceField
|
|
387
347
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
348
|
+
config.source = config.source ?? {};
|
|
349
|
+
config.source.include = [
|
|
350
|
+
...config.source.include ?? [],
|
|
351
|
+
...includes
|
|
352
|
+
];
|
|
353
|
+
});
|
|
354
|
+
api.modifyBundlerChain((chain, { CHAIN_ID })=>{
|
|
355
|
+
for (const ruleId of [
|
|
356
|
+
CHAIN_ID.RULE.TS,
|
|
357
|
+
CHAIN_ID.RULE.JS
|
|
358
|
+
])if (chain.module.rules.get(ruleId)) {
|
|
359
|
+
const rule = chain.module.rule(ruleId);
|
|
360
|
+
rule.resolve.mainFields.merge('source' === resolvePriority ? [
|
|
361
|
+
sourceField,
|
|
362
|
+
'...'
|
|
363
|
+
] : [
|
|
364
|
+
'...',
|
|
365
|
+
sourceField
|
|
366
|
+
]);
|
|
367
|
+
rule.resolve.conditionNames.add('...').add(sourceField);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
const getReferences = async (tsconfigPath, rspackReferences)=>{
|
|
371
|
+
const references = new Set();
|
|
372
|
+
for (const project of projects || []){
|
|
373
|
+
const filePath = external_node_path_default().join(project.dir, 'tsconfig.json');
|
|
374
|
+
if (external_node_fs_default().existsSync(filePath)) references.add(filePath);
|
|
375
|
+
}
|
|
376
|
+
const tsconfig = external_json5_default().parse(external_node_fs_default().readFileSync(tsconfigPath, 'utf-8'));
|
|
377
|
+
const userReferences = [
|
|
378
|
+
...Array.isArray(rspackReferences) ? rspackReferences : [],
|
|
379
|
+
...tsconfig.references ? tsconfig.references.map((item)=>item.path).filter(Boolean) : []
|
|
380
|
+
];
|
|
381
|
+
if (userReferences.length) {
|
|
382
|
+
const baseDir = external_node_path_default().dirname(tsconfigPath);
|
|
383
|
+
for (const item of userReferences){
|
|
384
|
+
if (!item) continue;
|
|
385
|
+
const absolutePath = external_node_path_default().isAbsolute(item) ? item : external_node_path_default().join(baseDir, item);
|
|
386
|
+
references.add(absolutePath);
|
|
406
387
|
}
|
|
407
|
-
|
|
408
|
-
|
|
388
|
+
}
|
|
389
|
+
references.delete(tsconfigPath);
|
|
390
|
+
return Array.from(references);
|
|
391
|
+
};
|
|
392
|
+
if ('rspack' === api.context.bundlerType) api.modifyRspackConfig(async (config, { environment })=>{
|
|
393
|
+
const { tsconfigPath } = environment;
|
|
394
|
+
if (!tsconfigPath) return;
|
|
395
|
+
config.resolve ||= {};
|
|
396
|
+
const { tsConfig = {
|
|
397
|
+
configFile: tsconfigPath
|
|
398
|
+
} } = config.resolve;
|
|
399
|
+
const configObject = 'string' == typeof tsConfig ? {
|
|
400
|
+
configFile: tsConfig
|
|
401
|
+
} : tsConfig;
|
|
402
|
+
const references = await getReferences(tsconfigPath, configObject.references);
|
|
403
|
+
config.resolve.tsConfig = {
|
|
404
|
+
configFile: configObject?.configFile || tsconfigPath,
|
|
405
|
+
references: references
|
|
409
406
|
};
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
};
|
|
425
|
-
});
|
|
426
|
-
else api.modifyBundlerChain(async (chain, { CHAIN_ID, environment })=>{
|
|
427
|
-
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
428
|
-
const { tsconfigPath } = environment;
|
|
429
|
-
if (!chain.resolve.plugins.has(TS_CONFIG_PATHS) || !tsconfigPath) return;
|
|
430
|
-
const references = await getReferences(tsconfigPath);
|
|
431
|
-
chain.resolve.plugin(TS_CONFIG_PATHS).tap((options)=>options.map((option)=>({
|
|
432
|
-
...option,
|
|
433
|
-
references
|
|
434
|
-
})));
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
})();
|
|
407
|
+
});
|
|
408
|
+
else api.modifyBundlerChain(async (chain, { CHAIN_ID, environment })=>{
|
|
409
|
+
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
410
|
+
const { tsconfigPath } = environment;
|
|
411
|
+
if (!chain.resolve.plugins.has(TS_CONFIG_PATHS) || !tsconfigPath) return;
|
|
412
|
+
const references = await getReferences(tsconfigPath);
|
|
413
|
+
chain.resolve.plugin(TS_CONFIG_PATHS).tap((options)=>options.map((option)=>({
|
|
414
|
+
...option,
|
|
415
|
+
references
|
|
416
|
+
})));
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|
|
440
421
|
exports.PLUGIN_SOURCE_BUILD_NAME = __webpack_exports__.PLUGIN_SOURCE_BUILD_NAME;
|
|
441
422
|
exports.Project = __webpack_exports__.Project;
|
|
442
423
|
exports.getMonorepoBaseData = __webpack_exports__.getMonorepoBaseData;
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,6 @@ const isMonorepo = async (monorepoRootPath, otherMonorepoChecks)=>{
|
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
39
|
const getMonorepoBaseData = async (starFindPath, otherMonorepoAnalyzer)=>{
|
|
40
|
-
var _otherMonorepoAnalyzer_type;
|
|
41
40
|
let repoIsMonorepo = false;
|
|
42
41
|
let findPath = starFindPath;
|
|
43
42
|
let type = '';
|
|
@@ -60,7 +59,7 @@ const getMonorepoBaseData = async (starFindPath, otherMonorepoAnalyzer)=>{
|
|
|
60
59
|
isMonorepo: repoIsMonorepo,
|
|
61
60
|
rootPath: repoIsMonorepo ? findPath : '',
|
|
62
61
|
type,
|
|
63
|
-
getProjects:
|
|
62
|
+
getProjects: otherMonorepoAnalyzer?.[type]?.getProjects
|
|
64
63
|
};
|
|
65
64
|
};
|
|
66
65
|
const readPackageJson = async (pkgJsonFilePath)=>readJson(pkgJsonFilePath);
|
|
@@ -357,7 +356,7 @@ function pluginSourceBuild(options) {
|
|
|
357
356
|
} : tsConfig;
|
|
358
357
|
const references = await getReferences(tsconfigPath, configObject.references);
|
|
359
358
|
config.resolve.tsConfig = {
|
|
360
|
-
configFile:
|
|
359
|
+
configFile: configObject?.configFile || tsconfigPath,
|
|
361
360
|
references: references
|
|
362
361
|
};
|
|
363
362
|
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-source-build",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "An Rsbuild plugin to provide support for monorepo source code referencing.",
|
|
5
|
-
"repository": "https://github.com/
|
|
5
|
+
"repository": "https://github.com/rstackjs/rsbuild-plugin-source-build",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
@@ -36,34 +36,34 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"fast-glob": "^3.3.3",
|
|
38
38
|
"json5": "^2.2.3",
|
|
39
|
-
"yaml": "^2.8.
|
|
39
|
+
"yaml": "^2.8.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@biomejs/biome": "^1.9.4",
|
|
43
|
-
"@playwright/test": "^1.
|
|
44
|
-
"@rsbuild/core": "^1.
|
|
45
|
-
"@rsbuild/plugin-react": "^1.
|
|
46
|
-
"@rsbuild/plugin-type-check": "^1.
|
|
47
|
-
"@rslib/core": "^0.
|
|
48
|
-
"@types/node": "^22.
|
|
49
|
-
"@types/react": "^19.
|
|
50
|
-
"@types/react-dom": "^19.
|
|
51
|
-
"nano-staged": "^0.
|
|
52
|
-
"playwright": "^1.
|
|
53
|
-
"react": "^19.
|
|
54
|
-
"react-dom": "^19.
|
|
43
|
+
"@playwright/test": "^1.57.0",
|
|
44
|
+
"@rsbuild/core": "^1.6.10",
|
|
45
|
+
"@rsbuild/plugin-react": "^1.4.2",
|
|
46
|
+
"@rsbuild/plugin-type-check": "^1.3.1",
|
|
47
|
+
"@rslib/core": "^0.18.2",
|
|
48
|
+
"@types/node": "^22.19.1",
|
|
49
|
+
"@types/react": "^19.2.7",
|
|
50
|
+
"@types/react-dom": "^19.2.3",
|
|
51
|
+
"nano-staged": "^0.9.0",
|
|
52
|
+
"playwright": "^1.57.0",
|
|
53
|
+
"react": "^19.2.0",
|
|
54
|
+
"react-dom": "^19.2.0",
|
|
55
55
|
"simple-git-hooks": "^2.13.1",
|
|
56
|
-
"typescript": "^5.9.
|
|
56
|
+
"typescript": "^5.9.3"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@rsbuild/core": "1.
|
|
59
|
+
"@rsbuild/core": "^1.0.0 || ^2.0.0-0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
62
62
|
"@rsbuild/core": {
|
|
63
63
|
"optional": true
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"packageManager": "pnpm@10.
|
|
66
|
+
"packageManager": "pnpm@10.24.0",
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public",
|
|
69
69
|
"registry": "https://registry.npmjs.org/"
|