@rsbuild/plugin-source-build 1.0.2 → 1.0.3
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/dist/index.cjs +388 -421
- package/dist/index.js +37 -64
- package/package.json +17 -17
package/dist/index.cjs
CHANGED
|
@@ -1,59 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
3
|
yaml: function(module) {
|
|
4
|
-
module.exports = import("yaml")
|
|
4
|
+
module.exports = import("yaml").then(function(module) {
|
|
5
|
+
return module;
|
|
6
|
+
});
|
|
5
7
|
}
|
|
6
8
|
};
|
|
7
|
-
/************************************************************************/ // The module cache
|
|
8
9
|
var __webpack_module_cache__ = {};
|
|
9
|
-
// The require function
|
|
10
10
|
function __webpack_require__(moduleId) {
|
|
11
|
-
// Check if module is in cache
|
|
12
11
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
12
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
-
// Create a new module (and put it into the cache)
|
|
15
13
|
var module = __webpack_module_cache__[moduleId] = {
|
|
16
14
|
exports: {}
|
|
17
15
|
};
|
|
18
|
-
// Execute the module function
|
|
19
16
|
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
20
|
-
// Return the exports of the module
|
|
21
17
|
return module.exports;
|
|
22
18
|
}
|
|
23
|
-
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
|
24
19
|
(()=>{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var getter = module && module.__esModule ? function() {
|
|
28
|
-
return module['default'];
|
|
29
|
-
} : function() {
|
|
30
|
-
return module;
|
|
31
|
-
};
|
|
20
|
+
__webpack_require__.n = (module)=>{
|
|
21
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
32
22
|
__webpack_require__.d(getter, {
|
|
33
23
|
a: getter
|
|
34
24
|
});
|
|
35
25
|
return getter;
|
|
36
26
|
};
|
|
37
27
|
})();
|
|
38
|
-
// webpack/runtime/define_property_getters
|
|
39
28
|
(()=>{
|
|
40
|
-
__webpack_require__.d =
|
|
29
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
41
30
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
42
31
|
enumerable: true,
|
|
43
32
|
get: definition[key]
|
|
44
33
|
});
|
|
45
34
|
};
|
|
46
35
|
})();
|
|
47
|
-
// webpack/runtime/has_own_property
|
|
48
36
|
(()=>{
|
|
49
|
-
__webpack_require__.o =
|
|
50
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
51
|
-
};
|
|
37
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
52
38
|
})();
|
|
53
|
-
// webpack/runtime/make_namespace_object
|
|
54
39
|
(()=>{
|
|
55
|
-
|
|
56
|
-
__webpack_require__.r = function(exports1) {
|
|
40
|
+
__webpack_require__.r = (exports1)=>{
|
|
57
41
|
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
58
42
|
value: 'Module'
|
|
59
43
|
});
|
|
@@ -62,426 +46,409 @@ function __webpack_require__(moduleId) {
|
|
|
62
46
|
});
|
|
63
47
|
};
|
|
64
48
|
})();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
__webpack_require__.r(__webpack_exports__);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
87
|
-
}
|
|
88
|
-
const isPnpmMonorepo = async (monorepoRootPath)=>{
|
|
89
|
-
const existPnpmWorkspaceFile = await pathExists(external_node_path_default().join(monorepoRootPath, PNPM_WORKSPACE_FILE));
|
|
90
|
-
return existPnpmWorkspaceFile;
|
|
91
|
-
};
|
|
92
|
-
const isRushMonorepo = async (monorepoRootPath)=>{
|
|
93
|
-
const existRushJsonFile = await pathExists(external_node_path_default().join(monorepoRootPath, RUSH_JSON_FILE));
|
|
94
|
-
return existRushJsonFile;
|
|
95
|
-
};
|
|
96
|
-
const isMonorepo = async (monorepoRootPath, otherMonorepoChecks)=>{
|
|
97
|
-
if ('object' == typeof otherMonorepoChecks) {
|
|
98
|
-
for (const [monorepoType, monorepoCheck] of Object.entries(otherMonorepoChecks))if ('function' == typeof monorepoCheck && await monorepoCheck(monorepoRootPath)) return {
|
|
99
|
-
isMonorepo: true,
|
|
100
|
-
type: monorepoType
|
|
101
|
-
};
|
|
49
|
+
var __webpack_exports__ = {};
|
|
50
|
+
(()=>{
|
|
51
|
+
__webpack_require__.r(__webpack_exports__);
|
|
52
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
53
|
+
Project: ()=>Project,
|
|
54
|
+
pluginSourceBuild: ()=>pluginSourceBuild,
|
|
55
|
+
getMonorepoSubProjects: ()=>getMonorepoSubProjects,
|
|
56
|
+
PLUGIN_SOURCE_BUILD_NAME: ()=>PLUGIN_SOURCE_BUILD_NAME,
|
|
57
|
+
getMonorepoBaseData: ()=>getMonorepoBaseData
|
|
58
|
+
});
|
|
59
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
60
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
61
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
62
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
63
|
+
const external_json5_namespaceObject = require("json5");
|
|
64
|
+
var external_json5_default = /*#__PURE__*/ __webpack_require__.n(external_json5_namespaceObject);
|
|
65
|
+
const PNPM_WORKSPACE_FILE = 'pnpm-workspace.yaml';
|
|
66
|
+
const RUSH_JSON_FILE = 'rush.json';
|
|
67
|
+
const PACKAGE_JSON = 'package.json';
|
|
68
|
+
async function pathExists(path) {
|
|
69
|
+
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
102
70
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
71
|
+
const isPnpmMonorepo = async (monorepoRootPath)=>{
|
|
72
|
+
const existPnpmWorkspaceFile = await pathExists(external_node_path_default().join(monorepoRootPath, PNPM_WORKSPACE_FILE));
|
|
73
|
+
return existPnpmWorkspaceFile;
|
|
106
74
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
75
|
+
const isRushMonorepo = async (monorepoRootPath)=>{
|
|
76
|
+
const existRushJsonFile = await pathExists(external_node_path_default().join(monorepoRootPath, RUSH_JSON_FILE));
|
|
77
|
+
return existRushJsonFile;
|
|
110
78
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
79
|
+
const isMonorepo = async (monorepoRootPath, otherMonorepoChecks)=>{
|
|
80
|
+
if ('object' == typeof otherMonorepoChecks) {
|
|
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 {
|
|
91
|
+
isMonorepo: true,
|
|
92
|
+
type: 'rush'
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
isMonorepo: false,
|
|
96
|
+
type: ''
|
|
97
|
+
};
|
|
114
98
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
99
|
+
const getMonorepoBaseData = async (starFindPath, otherMonorepoAnalyzer)=>{
|
|
100
|
+
var _otherMonorepoAnalyzer_type;
|
|
101
|
+
let repoIsMonorepo = false;
|
|
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);
|
|
132
118
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
+
};
|
|
125
|
+
};
|
|
126
|
+
const external_fast_glob_namespaceObject = require("fast-glob");
|
|
127
|
+
var external_fast_glob_default = /*#__PURE__*/ __webpack_require__.n(external_fast_glob_namespaceObject);
|
|
128
|
+
const readPackageJson = async (pkgJsonFilePath)=>readJson(pkgJsonFilePath);
|
|
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;
|
|
132
|
+
};
|
|
133
|
+
async function utils_pathExists(path) {
|
|
134
|
+
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
136
135
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
const readJson = async (jsonFileAbsPath)=>{
|
|
137
|
+
if (!await utils_pathExists(jsonFileAbsPath)) return {};
|
|
138
|
+
const content = await external_node_fs_default().promises.readFile(jsonFileAbsPath, 'utf-8');
|
|
139
|
+
const json = external_json5_default().parse(content);
|
|
140
|
+
return json;
|
|
142
141
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var external_fast_glob_default = /*#__PURE__*/ __webpack_require__.n(external_fast_glob_namespaceObject);
|
|
146
|
-
const readPackageJson = async (pkgJsonFilePath)=>readJson(pkgJsonFilePath);
|
|
147
|
-
const readRushJson = async (rushJsonFilePath)=>{
|
|
148
|
-
const rushJson = readJson(rushJsonFilePath.includes(RUSH_JSON_FILE) ? rushJsonFilePath : external_node_path_default().join(rushJsonFilePath, RUSH_JSON_FILE));
|
|
149
|
-
return rushJson;
|
|
150
|
-
};
|
|
151
|
-
async function utils_pathExists(path) {
|
|
152
|
-
return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
|
|
153
|
-
}
|
|
154
|
-
const readJson = async (jsonFileAbsPath)=>{
|
|
155
|
-
if (!await utils_pathExists(jsonFileAbsPath)) return {};
|
|
156
|
-
const content = await external_node_fs_default().promises.readFile(jsonFileAbsPath, 'utf-8');
|
|
157
|
-
const json = external_json5_default().parse(content);
|
|
158
|
-
return json;
|
|
159
|
-
};
|
|
160
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
161
|
-
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
162
|
-
}
|
|
163
|
-
function _class_private_method_get(receiver, privateSet, fn) {
|
|
164
|
-
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
|
|
165
|
-
return fn;
|
|
166
|
-
}
|
|
167
|
-
function _class_private_method_init(obj, privateSet) {
|
|
168
|
-
_check_private_redeclaration(obj, privateSet);
|
|
169
|
-
privateSet.add(obj);
|
|
170
|
-
}
|
|
171
|
-
function _define_property(obj, key, value) {
|
|
172
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
173
|
-
value: value,
|
|
174
|
-
enumerable: true,
|
|
175
|
-
configurable: true,
|
|
176
|
-
writable: true
|
|
177
|
-
});
|
|
178
|
-
else obj[key] = value;
|
|
179
|
-
return obj;
|
|
180
|
-
}
|
|
181
|
-
var _getExportsSourceDirs = /*#__PURE__*/ new WeakSet(), /**
|
|
182
|
-
*
|
|
183
|
-
* @param paths normalize paths
|
|
184
|
-
* @returns common root paths
|
|
185
|
-
*/ _getCommonRootPaths = /*#__PURE__*/ new WeakSet(), _getRootPath = /*#__PURE__*/ new WeakSet();
|
|
186
|
-
class Project {
|
|
187
|
-
async init() {
|
|
188
|
-
this.metaData = await readPackageJson(external_node_path_default().join(this.dir, PACKAGE_JSON));
|
|
142
|
+
function _check_private_redeclaration(obj, privateCollection) {
|
|
143
|
+
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
189
144
|
}
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
return
|
|
145
|
+
function _class_private_method_get(receiver, privateSet, fn) {
|
|
146
|
+
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
|
|
147
|
+
return fn;
|
|
193
148
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
};
|
|
198
|
-
const allProjectMap = new Map();
|
|
199
|
-
for (const project of monorepoProjects)allProjectMap.set(project.name, project);
|
|
200
|
-
if (!recursive) return this.getDirectDependentProjects(allProjectMap);
|
|
201
|
-
const computedSet = new Set();
|
|
202
|
-
computedSet.add(this.name);
|
|
203
|
-
const queue = this.getDirectDependentProjects(allProjectMap).filter((p)=>!computedSet.has(p.name));
|
|
204
|
-
const result = [];
|
|
205
|
-
while(queue.length > 0){
|
|
206
|
-
const item = queue.shift();
|
|
207
|
-
if (computedSet.has(item.name)) continue;
|
|
208
|
-
result.push(item);
|
|
209
|
-
computedSet.add(item.name);
|
|
210
|
-
const newDeps = item.getDirectDependentProjects(allProjectMap);
|
|
211
|
-
if (newDeps.length > 0) queue.push(...newDeps);
|
|
212
|
-
}
|
|
213
|
-
return result;
|
|
149
|
+
function _class_private_method_init(obj, privateSet) {
|
|
150
|
+
_check_private_redeclaration(obj, privateSet);
|
|
151
|
+
privateSet.add(obj);
|
|
214
152
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
153
|
+
function _define_property(obj, key, value) {
|
|
154
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
155
|
+
value: value,
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
writable: true
|
|
159
|
+
});
|
|
160
|
+
else obj[key] = value;
|
|
161
|
+
return obj;
|
|
222
162
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
163
|
+
var _getExportsSourceDirs = /*#__PURE__*/ new WeakSet(), _getCommonRootPaths = /*#__PURE__*/ new WeakSet(), _getRootPath = /*#__PURE__*/ new WeakSet();
|
|
164
|
+
class Project {
|
|
165
|
+
async init() {
|
|
166
|
+
this.metaData = await readPackageJson(external_node_path_default().join(this.dir, PACKAGE_JSON));
|
|
167
|
+
}
|
|
168
|
+
getMetaData() {
|
|
169
|
+
if (null === this.metaData) throw new Error('The Project object needs to be initialized by executing the `init` function');
|
|
170
|
+
return this.metaData;
|
|
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;
|
|
240
223
|
}
|
|
241
|
-
if (!sourceDirs.length) throw new Error(`"${sourceField}" field is not found in ${this.name} package.json`);
|
|
242
|
-
return _class_private_method_get(this, _getCommonRootPaths, getCommonRootPaths).call(this, sourceDirs);
|
|
243
224
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
_define_property(this, "dir", void 0);
|
|
250
|
-
_define_property(this, "metaData", void 0);
|
|
251
|
-
this.name = name;
|
|
252
|
-
this.dir = dir;
|
|
225
|
+
function getExportsSourceDirs(exportsConfig, sourceField) {
|
|
226
|
+
const exportsSourceDirs = [];
|
|
227
|
+
if ('string' == typeof exportsConfig[sourceField]) exportsSourceDirs.push(external_node_path_default().normalize(exportsConfig[sourceField]));
|
|
228
|
+
for (const moduleRules of Object.values(exportsConfig))if ('object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]) exportsSourceDirs.push(external_node_path_default().normalize(moduleRules[sourceField]));
|
|
229
|
+
return exportsSourceDirs;
|
|
253
230
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
let dir;
|
|
266
|
-
try {
|
|
267
|
-
dir = external_node_fs_default().statSync(p).isDirectory() ? p : external_node_path_default().dirname(p);
|
|
268
|
-
} catch {
|
|
269
|
-
dir = external_node_path_default().dirname(p);
|
|
231
|
+
function getCommonRootPaths(paths) {
|
|
232
|
+
const commonRootPathsSet = new Set();
|
|
233
|
+
for (const p of paths){
|
|
234
|
+
let dir;
|
|
235
|
+
try {
|
|
236
|
+
dir = external_node_fs_default().statSync(p).isDirectory() ? p : external_node_path_default().dirname(p);
|
|
237
|
+
} catch {
|
|
238
|
+
dir = external_node_path_default().dirname(p);
|
|
239
|
+
}
|
|
240
|
+
const rootPath = _class_private_method_get(this, _getRootPath, getRootPath).call(this, dir);
|
|
241
|
+
if (!commonRootPathsSet.has(rootPath)) commonRootPathsSet.add(rootPath);
|
|
270
242
|
}
|
|
271
|
-
|
|
272
|
-
if (!commonRootPathsSet.has(rootPath)) commonRootPathsSet.add(rootPath);
|
|
243
|
+
return Array.from(commonRootPathsSet).map((p)=>external_node_path_default().join(this.dir, p));
|
|
273
244
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const pnpmWorkspace = parse(yamlContent);
|
|
284
|
-
return pnpmWorkspace.packages || [];
|
|
285
|
-
};
|
|
286
|
-
const normalize = (results)=>results.map((fp)=>external_node_path_default().normalize(fp));
|
|
287
|
-
const getGlobOpts = (rootPath, patterns)=>{
|
|
288
|
-
const globOpts = {
|
|
289
|
-
cwd: rootPath,
|
|
290
|
-
absolute: true,
|
|
291
|
-
followSymbolicLinks: false
|
|
245
|
+
function getRootPath(p) {
|
|
246
|
+
return p.split(external_node_path_default().sep)[0];
|
|
247
|
+
}
|
|
248
|
+
const getPatternsFromYaml = async (monorepoRoot)=>{
|
|
249
|
+
const { parse } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "yaml"));
|
|
250
|
+
const workspaceYamlFilePath = external_node_path_default().join(monorepoRoot, PNPM_WORKSPACE_FILE);
|
|
251
|
+
const yamlContent = await external_node_fs_default().promises.readFile(workspaceYamlFilePath, 'utf8');
|
|
252
|
+
const pnpmWorkspace = parse(yamlContent);
|
|
253
|
+
return pnpmWorkspace.packages || [];
|
|
292
254
|
};
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// fast-glob does not respect pattern order, so we re-sort by absolute path
|
|
306
|
-
result = result.sort();
|
|
307
|
-
// POSIX results always need to be normalized
|
|
308
|
-
result = normalize(result);
|
|
309
|
-
return fileMapper(result);
|
|
255
|
+
const normalize = (results)=>results.map((fp)=>external_node_path_default().normalize(fp));
|
|
256
|
+
const getGlobOpts = (rootPath, patterns)=>{
|
|
257
|
+
const globOpts = {
|
|
258
|
+
cwd: rootPath,
|
|
259
|
+
absolute: true,
|
|
260
|
+
followSymbolicLinks: false
|
|
261
|
+
};
|
|
262
|
+
if (patterns.some((cfg)=>cfg.includes('**') || cfg.includes('*'))) globOpts.ignore = [
|
|
263
|
+
'**/dist/**',
|
|
264
|
+
'**/node_modules/**'
|
|
265
|
+
];
|
|
266
|
+
return globOpts;
|
|
310
267
|
};
|
|
311
|
-
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
manifest: pkgJson
|
|
268
|
+
const makeFileFinder = (rootPath, patterns)=>{
|
|
269
|
+
const globOpts = getGlobOpts(rootPath, patterns);
|
|
270
|
+
return async (fileName, fileMapper)=>{
|
|
271
|
+
let result = await external_fast_glob_default()(patterns.map((globPath)=>external_node_path_default().posix.join(globPath, fileName)), globOpts);
|
|
272
|
+
result = result.sort();
|
|
273
|
+
result = normalize(result);
|
|
274
|
+
return fileMapper(result);
|
|
319
275
|
};
|
|
320
276
|
};
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
};
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
};
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}));
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
277
|
+
const readPnpmProjects = async (monorepoRoot, patterns)=>{
|
|
278
|
+
const finder = makeFileFinder(monorepoRoot, patterns);
|
|
279
|
+
const mapper = async (pkgJsonFilePath)=>{
|
|
280
|
+
const pkgJson = await readPackageJson(pkgJsonFilePath);
|
|
281
|
+
return {
|
|
282
|
+
dir: external_node_path_default().dirname(pkgJsonFilePath),
|
|
283
|
+
manifest: pkgJson
|
|
284
|
+
};
|
|
285
|
+
};
|
|
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
|
+
};
|
|
348
|
+
function pluginSourceBuild(options) {
|
|
349
|
+
const { projectName, sourceField = 'source', resolvePriority = 'source', extraMonorepoStrategies } = options ?? {};
|
|
350
|
+
return {
|
|
351
|
+
name: PLUGIN_SOURCE_BUILD_NAME,
|
|
352
|
+
setup (api) {
|
|
353
|
+
const projectRootPath = api.context.rootPath;
|
|
354
|
+
let projects;
|
|
355
|
+
api.modifyEnvironmentConfig(async (config)=>{
|
|
356
|
+
projects = projects || await getDependentProjects(projectName || projectRootPath, {
|
|
357
|
+
cwd: projectRootPath,
|
|
358
|
+
recursive: true,
|
|
359
|
+
filter: filterByField(sourceField, true),
|
|
360
|
+
extraMonorepoStrategies
|
|
361
|
+
});
|
|
362
|
+
const includes = await getSourceInclude({
|
|
363
|
+
projects,
|
|
364
|
+
sourceField
|
|
365
|
+
});
|
|
366
|
+
config.source = config.source ?? {};
|
|
367
|
+
config.source.include = [
|
|
368
|
+
...config.source.include ?? [],
|
|
369
|
+
...includes
|
|
370
|
+
];
|
|
397
371
|
});
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
372
|
+
api.modifyBundlerChain((chain, { CHAIN_ID })=>{
|
|
373
|
+
for (const ruleId of [
|
|
374
|
+
CHAIN_ID.RULE.TS,
|
|
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
|
+
}
|
|
401
387
|
});
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
});
|
|
408
|
-
api.modifyBundlerChain((chain, { CHAIN_ID })=>{
|
|
409
|
-
for (const ruleId of [
|
|
410
|
-
CHAIN_ID.RULE.TS,
|
|
411
|
-
CHAIN_ID.RULE.JS
|
|
412
|
-
])if (chain.module.rules.get(ruleId)) {
|
|
413
|
-
const rule = chain.module.rule(ruleId);
|
|
414
|
-
// https://rspack.dev/config/resolve
|
|
415
|
-
// when source is not exist, other mainFields will effect. // source > Rspack default mainFields.
|
|
416
|
-
rule.resolve.mainFields.merge('source' === resolvePriority ? [
|
|
417
|
-
sourceField,
|
|
418
|
-
'...'
|
|
419
|
-
] : [
|
|
420
|
-
'...',
|
|
421
|
-
sourceField
|
|
422
|
-
]);
|
|
423
|
-
// `conditionNames` is not affected by `resolvePriority`.
|
|
424
|
-
// The priority is controlled by the order of fields declared in `exports`.
|
|
425
|
-
rule.resolve.conditionNames.add('...').add(sourceField);
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
const getReferences = async (tsconfigPath, rspackReferences)=>{
|
|
429
|
-
const references = new Set();
|
|
430
|
-
for (const project of projects || []){
|
|
431
|
-
const filePath = external_node_path_default().join(project.dir, 'tsconfig.json');
|
|
432
|
-
if (external_node_fs_default().existsSync(filePath)) references.add(filePath);
|
|
433
|
-
}
|
|
434
|
-
// Add references in the current project's tsconfig.json
|
|
435
|
-
const tsconfig = external_json5_default().parse(external_node_fs_default().readFileSync(tsconfigPath, 'utf-8'));
|
|
436
|
-
const userReferences = [
|
|
437
|
-
...Array.isArray(rspackReferences) ? rspackReferences : [],
|
|
438
|
-
...tsconfig.references ? tsconfig.references.map((item)=>item.path).filter(Boolean) : []
|
|
439
|
-
];
|
|
440
|
-
if (userReferences.length) {
|
|
441
|
-
const baseDir = external_node_path_default().dirname(tsconfigPath);
|
|
442
|
-
for (const item of userReferences){
|
|
443
|
-
if (!item) continue;
|
|
444
|
-
const absolutePath = external_node_path_default().isAbsolute(item) ? item : external_node_path_default().join(baseDir, item);
|
|
445
|
-
references.add(absolutePath);
|
|
388
|
+
const getReferences = async (tsconfigPath, rspackReferences)=>{
|
|
389
|
+
const references = new Set();
|
|
390
|
+
for (const project of projects || []){
|
|
391
|
+
const filePath = external_node_path_default().join(project.dir, 'tsconfig.json');
|
|
392
|
+
if (external_node_fs_default().existsSync(filePath)) references.add(filePath);
|
|
446
393
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const references = await getReferences(tsconfigPath, configObject.references);
|
|
463
|
-
config.resolve.tsConfig = {
|
|
464
|
-
configFile: (null == configObject ? void 0 : configObject.configFile) || tsconfigPath,
|
|
465
|
-
references: references
|
|
394
|
+
const tsconfig = external_json5_default().parse(external_node_fs_default().readFileSync(tsconfigPath, 'utf-8'));
|
|
395
|
+
const userReferences = [
|
|
396
|
+
...Array.isArray(rspackReferences) ? rspackReferences : [],
|
|
397
|
+
...tsconfig.references ? tsconfig.references.map((item)=>item.path).filter(Boolean) : []
|
|
398
|
+
];
|
|
399
|
+
if (userReferences.length) {
|
|
400
|
+
const baseDir = external_node_path_default().dirname(tsconfigPath);
|
|
401
|
+
for (const item of userReferences){
|
|
402
|
+
if (!item) continue;
|
|
403
|
+
const absolutePath = external_node_path_default().isAbsolute(item) ? item : external_node_path_default().join(baseDir, item);
|
|
404
|
+
references.add(absolutePath);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
references.delete(tsconfigPath);
|
|
408
|
+
return Array.from(references);
|
|
466
409
|
};
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
410
|
+
if ('rspack' === api.context.bundlerType) api.modifyRspackConfig(async (config, { environment })=>{
|
|
411
|
+
const { tsconfigPath } = environment;
|
|
412
|
+
if (!tsconfigPath) return;
|
|
413
|
+
config.resolve ||= {};
|
|
414
|
+
const { tsConfig = {
|
|
415
|
+
configFile: tsconfigPath
|
|
416
|
+
} } = config.resolve;
|
|
417
|
+
const configObject = 'string' == typeof tsConfig ? {
|
|
418
|
+
configFile: tsConfig
|
|
419
|
+
} : tsConfig;
|
|
420
|
+
const references = await getReferences(tsconfigPath, configObject.references);
|
|
421
|
+
config.resolve.tsConfig = {
|
|
422
|
+
configFile: (null == configObject ? void 0 : configObject.configFile) || tsconfigPath,
|
|
423
|
+
references: references
|
|
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
|
+
})();
|
|
440
|
+
exports.PLUGIN_SOURCE_BUILD_NAME = __webpack_exports__.PLUGIN_SOURCE_BUILD_NAME;
|
|
441
|
+
exports.Project = __webpack_exports__.Project;
|
|
442
|
+
exports.getMonorepoBaseData = __webpack_exports__.getMonorepoBaseData;
|
|
443
|
+
exports.getMonorepoSubProjects = __webpack_exports__.getMonorepoSubProjects;
|
|
444
|
+
exports.pluginSourceBuild = __webpack_exports__.pluginSourceBuild;
|
|
445
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
446
|
+
"PLUGIN_SOURCE_BUILD_NAME",
|
|
447
|
+
"Project",
|
|
448
|
+
"getMonorepoBaseData",
|
|
449
|
+
"getMonorepoSubProjects",
|
|
450
|
+
"pluginSourceBuild"
|
|
451
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
452
|
+
Object.defineProperty(exports, '__esModule', {
|
|
486
453
|
value: true
|
|
487
454
|
});
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import json5 from "json5";
|
|
4
|
+
import fast_glob from "fast-glob";
|
|
5
5
|
const PNPM_WORKSPACE_FILE = 'pnpm-workspace.yaml';
|
|
6
6
|
const RUSH_JSON_FILE = 'rush.json';
|
|
7
7
|
const PACKAGE_JSON = 'package.json';
|
|
8
8
|
async function pathExists(path) {
|
|
9
|
-
return
|
|
9
|
+
return node_fs.promises.access(path).then(()=>true).catch(()=>false);
|
|
10
10
|
}
|
|
11
11
|
const isPnpmMonorepo = async (monorepoRootPath)=>{
|
|
12
|
-
const existPnpmWorkspaceFile = await pathExists(
|
|
12
|
+
const existPnpmWorkspaceFile = await pathExists(node_path.join(monorepoRootPath, PNPM_WORKSPACE_FILE));
|
|
13
13
|
return existPnpmWorkspaceFile;
|
|
14
14
|
};
|
|
15
15
|
const isRushMonorepo = async (monorepoRootPath)=>{
|
|
16
|
-
const existRushJsonFile = await pathExists(
|
|
16
|
+
const existRushJsonFile = await pathExists(node_path.join(monorepoRootPath, RUSH_JSON_FILE));
|
|
17
17
|
return existRushJsonFile;
|
|
18
18
|
};
|
|
19
19
|
const isMonorepo = async (monorepoRootPath, otherMonorepoChecks)=>{
|
|
@@ -53,29 +53,28 @@ const getMonorepoBaseData = async (starFindPath, otherMonorepoAnalyzer)=>{
|
|
|
53
53
|
({ type } = result);
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
findPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(findPath);
|
|
56
|
+
if (findPath === node_path.dirname(findPath)) break;
|
|
57
|
+
findPath = node_path.dirname(findPath);
|
|
59
58
|
}
|
|
60
59
|
return {
|
|
61
60
|
isMonorepo: repoIsMonorepo,
|
|
62
61
|
rootPath: repoIsMonorepo ? findPath : '',
|
|
63
62
|
type,
|
|
64
|
-
getProjects: null == otherMonorepoAnalyzer ? void 0 : null
|
|
63
|
+
getProjects: null == otherMonorepoAnalyzer ? void 0 : null == (_otherMonorepoAnalyzer_type = otherMonorepoAnalyzer[type]) ? void 0 : _otherMonorepoAnalyzer_type.getProjects
|
|
65
64
|
};
|
|
66
65
|
};
|
|
67
66
|
const readPackageJson = async (pkgJsonFilePath)=>readJson(pkgJsonFilePath);
|
|
68
67
|
const readRushJson = async (rushJsonFilePath)=>{
|
|
69
|
-
const rushJson = readJson(rushJsonFilePath.includes(RUSH_JSON_FILE) ? rushJsonFilePath :
|
|
68
|
+
const rushJson = readJson(rushJsonFilePath.includes(RUSH_JSON_FILE) ? rushJsonFilePath : node_path.join(rushJsonFilePath, RUSH_JSON_FILE));
|
|
70
69
|
return rushJson;
|
|
71
70
|
};
|
|
72
71
|
async function utils_pathExists(path) {
|
|
73
|
-
return
|
|
72
|
+
return node_fs.promises.access(path).then(()=>true).catch(()=>false);
|
|
74
73
|
}
|
|
75
74
|
const readJson = async (jsonFileAbsPath)=>{
|
|
76
75
|
if (!await utils_pathExists(jsonFileAbsPath)) return {};
|
|
77
|
-
const content = await
|
|
78
|
-
const json =
|
|
76
|
+
const content = await node_fs.promises.readFile(jsonFileAbsPath, 'utf-8');
|
|
77
|
+
const json = json5.parse(content);
|
|
79
78
|
return json;
|
|
80
79
|
};
|
|
81
80
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
@@ -99,14 +98,10 @@ function _define_property(obj, key, value) {
|
|
|
99
98
|
else obj[key] = value;
|
|
100
99
|
return obj;
|
|
101
100
|
}
|
|
102
|
-
var _getExportsSourceDirs = /*#__PURE__*/ new WeakSet(),
|
|
103
|
-
*
|
|
104
|
-
* @param paths normalize paths
|
|
105
|
-
* @returns common root paths
|
|
106
|
-
*/ _getCommonRootPaths = /*#__PURE__*/ new WeakSet(), _getRootPath = /*#__PURE__*/ new WeakSet();
|
|
101
|
+
var _getExportsSourceDirs = /*#__PURE__*/ new WeakSet(), _getCommonRootPaths = /*#__PURE__*/ new WeakSet(), _getRootPath = /*#__PURE__*/ new WeakSet();
|
|
107
102
|
class Project {
|
|
108
103
|
async init() {
|
|
109
|
-
this.metaData = await readPackageJson(
|
|
104
|
+
this.metaData = await readPackageJson(node_path.join(this.dir, PACKAGE_JSON));
|
|
110
105
|
}
|
|
111
106
|
getMetaData() {
|
|
112
107
|
if (null === this.metaData) throw new Error('The Project object needs to be initialized by executing the `init` function');
|
|
@@ -144,19 +139,11 @@ class Project {
|
|
|
144
139
|
getSourceEntryPaths(options) {
|
|
145
140
|
const { exports: checkExports = false, field: sourceField = 'source' } = options ?? {};
|
|
146
141
|
const pkgJson = this.getMetaData();
|
|
147
|
-
// normalize strings
|
|
148
142
|
const sourceDirs = pkgJson[sourceField] ? [
|
|
149
|
-
|
|
143
|
+
node_path.normalize(pkgJson[sourceField])
|
|
150
144
|
] : [];
|
|
151
145
|
if (checkExports) {
|
|
152
|
-
|
|
153
|
-
* analyze exports:
|
|
154
|
-
* "exports": {
|
|
155
|
-
* ".": {
|
|
156
|
-
* "source": "./src/index.ts"
|
|
157
|
-
* }
|
|
158
|
-
* },
|
|
159
|
-
*/ const exportsSourceDirs = _class_private_method_get(this, _getExportsSourceDirs, getExportsSourceDirs).call(this, pkgJson.exports ?? {}, sourceField);
|
|
146
|
+
const exportsSourceDirs = _class_private_method_get(this, _getExportsSourceDirs, getExportsSourceDirs).call(this, pkgJson.exports ?? {}, sourceField);
|
|
160
147
|
sourceDirs.push(...exportsSourceDirs);
|
|
161
148
|
}
|
|
162
149
|
if (!sourceDirs.length) throw new Error(`"${sourceField}" field is not found in ${this.name} package.json`);
|
|
@@ -175,9 +162,8 @@ class Project {
|
|
|
175
162
|
}
|
|
176
163
|
function getExportsSourceDirs(exportsConfig, sourceField) {
|
|
177
164
|
const exportsSourceDirs = [];
|
|
178
|
-
if ('string' == typeof exportsConfig[sourceField]) exportsSourceDirs.push(
|
|
179
|
-
for (const moduleRules of Object.values(exportsConfig))if ('object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]) exportsSourceDirs.push(
|
|
180
|
-
// normalize strings
|
|
165
|
+
if ('string' == typeof exportsConfig[sourceField]) exportsSourceDirs.push(node_path.normalize(exportsConfig[sourceField]));
|
|
166
|
+
for (const moduleRules of Object.values(exportsConfig))if ('object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]) exportsSourceDirs.push(node_path.normalize(moduleRules[sourceField]));
|
|
181
167
|
return exportsSourceDirs;
|
|
182
168
|
}
|
|
183
169
|
function getCommonRootPaths(paths) {
|
|
@@ -185,26 +171,26 @@ function getCommonRootPaths(paths) {
|
|
|
185
171
|
for (const p of paths){
|
|
186
172
|
let dir;
|
|
187
173
|
try {
|
|
188
|
-
dir =
|
|
174
|
+
dir = node_fs.statSync(p).isDirectory() ? p : node_path.dirname(p);
|
|
189
175
|
} catch {
|
|
190
|
-
dir =
|
|
176
|
+
dir = node_path.dirname(p);
|
|
191
177
|
}
|
|
192
178
|
const rootPath = _class_private_method_get(this, _getRootPath, getRootPath).call(this, dir);
|
|
193
179
|
if (!commonRootPathsSet.has(rootPath)) commonRootPathsSet.add(rootPath);
|
|
194
180
|
}
|
|
195
|
-
return Array.from(commonRootPathsSet).map((p)=>
|
|
181
|
+
return Array.from(commonRootPathsSet).map((p)=>node_path.join(this.dir, p));
|
|
196
182
|
}
|
|
197
183
|
function getRootPath(p) {
|
|
198
|
-
return p.split(
|
|
184
|
+
return p.split(node_path.sep)[0];
|
|
199
185
|
}
|
|
200
186
|
const getPatternsFromYaml = async (monorepoRoot)=>{
|
|
201
187
|
const { parse } = await import("yaml");
|
|
202
|
-
const workspaceYamlFilePath =
|
|
203
|
-
const yamlContent = await
|
|
188
|
+
const workspaceYamlFilePath = node_path.join(monorepoRoot, PNPM_WORKSPACE_FILE);
|
|
189
|
+
const yamlContent = await node_fs.promises.readFile(workspaceYamlFilePath, 'utf8');
|
|
204
190
|
const pnpmWorkspace = parse(yamlContent);
|
|
205
191
|
return pnpmWorkspace.packages || [];
|
|
206
192
|
};
|
|
207
|
-
const normalize = (results)=>results.map((fp)=>
|
|
193
|
+
const normalize = (results)=>results.map((fp)=>node_path.normalize(fp));
|
|
208
194
|
const getGlobOpts = (rootPath, patterns)=>{
|
|
209
195
|
const globOpts = {
|
|
210
196
|
cwd: rootPath,
|
|
@@ -212,8 +198,6 @@ const getGlobOpts = (rootPath, patterns)=>{
|
|
|
212
198
|
followSymbolicLinks: false
|
|
213
199
|
};
|
|
214
200
|
if (patterns.some((cfg)=>cfg.includes('**') || cfg.includes('*'))) globOpts.ignore = [
|
|
215
|
-
// allow globs like "packages/**" or "packages/*",
|
|
216
|
-
// but avoid picking up node_modules/**/package.json and dist/**/package.json
|
|
217
201
|
'**/dist/**',
|
|
218
202
|
'**/node_modules/**'
|
|
219
203
|
];
|
|
@@ -222,10 +206,8 @@ const getGlobOpts = (rootPath, patterns)=>{
|
|
|
222
206
|
const makeFileFinder = (rootPath, patterns)=>{
|
|
223
207
|
const globOpts = getGlobOpts(rootPath, patterns);
|
|
224
208
|
return async (fileName, fileMapper)=>{
|
|
225
|
-
let result = await (
|
|
226
|
-
// fast-glob does not respect pattern order, so we re-sort by absolute path
|
|
209
|
+
let result = await fast_glob(patterns.map((globPath)=>node_path.posix.join(globPath, fileName)), globOpts);
|
|
227
210
|
result = result.sort();
|
|
228
|
-
// POSIX results always need to be normalized
|
|
229
211
|
result = normalize(result);
|
|
230
212
|
return fileMapper(result);
|
|
231
213
|
};
|
|
@@ -235,7 +217,7 @@ const readPnpmProjects = async (monorepoRoot, patterns)=>{
|
|
|
235
217
|
const mapper = async (pkgJsonFilePath)=>{
|
|
236
218
|
const pkgJson = await readPackageJson(pkgJsonFilePath);
|
|
237
219
|
return {
|
|
238
|
-
dir:
|
|
220
|
+
dir: node_path.dirname(pkgJsonFilePath),
|
|
239
221
|
manifest: pkgJson
|
|
240
222
|
};
|
|
241
223
|
};
|
|
@@ -255,7 +237,7 @@ const rush_getProjects = async (monorepoRoot)=>{
|
|
|
255
237
|
const rushConfiguration = await readRushJson(monorepoRoot);
|
|
256
238
|
const { projects = [] } = rushConfiguration;
|
|
257
239
|
return Promise.all(projects.map(async (p)=>{
|
|
258
|
-
const project = new Project(p.packageName,
|
|
240
|
+
const project = new Project(p.packageName, node_path.join(monorepoRoot, p.projectFolder));
|
|
259
241
|
await project.init();
|
|
260
242
|
return project;
|
|
261
243
|
}));
|
|
@@ -268,12 +250,11 @@ const getMonorepoSubProjects = async (monorepoBaseData)=>{
|
|
|
268
250
|
return [];
|
|
269
251
|
};
|
|
270
252
|
async function getDependentProjects_pathExists(path) {
|
|
271
|
-
return
|
|
253
|
+
return node_fs.promises.access(path).then(()=>true).catch(()=>false);
|
|
272
254
|
}
|
|
273
255
|
const getDependentProjects = async (projectNameOrRootPath, options)=>{
|
|
274
256
|
const { cwd = process.cwd(), recursive, filter, extraMonorepoStrategies } = options;
|
|
275
|
-
|
|
276
|
-
const currentProjectPkgJsonPath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(projectNameOrRootPath, 'package.json');
|
|
257
|
+
const currentProjectPkgJsonPath = node_path.join(projectNameOrRootPath, 'package.json');
|
|
277
258
|
let projectName;
|
|
278
259
|
if (await getDependentProjects_pathExists(currentProjectPkgJsonPath)) ({ name: projectName } = await readPackageJson(currentProjectPkgJsonPath));
|
|
279
260
|
else projectName = projectNameOrRootPath;
|
|
@@ -332,8 +313,6 @@ function pluginSourceBuild(options) {
|
|
|
332
313
|
CHAIN_ID.RULE.JS
|
|
333
314
|
])if (chain.module.rules.get(ruleId)) {
|
|
334
315
|
const rule = chain.module.rule(ruleId);
|
|
335
|
-
// https://rspack.dev/config/resolve
|
|
336
|
-
// when source is not exist, other mainFields will effect. // source > Rspack default mainFields.
|
|
337
316
|
rule.resolve.mainFields.merge('source' === resolvePriority ? [
|
|
338
317
|
sourceField,
|
|
339
318
|
'...'
|
|
@@ -341,32 +320,28 @@ function pluginSourceBuild(options) {
|
|
|
341
320
|
'...',
|
|
342
321
|
sourceField
|
|
343
322
|
]);
|
|
344
|
-
// `conditionNames` is not affected by `resolvePriority`.
|
|
345
|
-
// The priority is controlled by the order of fields declared in `exports`.
|
|
346
323
|
rule.resolve.conditionNames.add('...').add(sourceField);
|
|
347
324
|
}
|
|
348
325
|
});
|
|
349
326
|
const getReferences = async (tsconfigPath, rspackReferences)=>{
|
|
350
327
|
const references = new Set();
|
|
351
328
|
for (const project of projects || []){
|
|
352
|
-
const filePath =
|
|
353
|
-
if (
|
|
329
|
+
const filePath = node_path.join(project.dir, 'tsconfig.json');
|
|
330
|
+
if (node_fs.existsSync(filePath)) references.add(filePath);
|
|
354
331
|
}
|
|
355
|
-
|
|
356
|
-
const tsconfig = __WEBPACK_EXTERNAL_MODULE_json5__["default"].parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(tsconfigPath, 'utf-8'));
|
|
332
|
+
const tsconfig = json5.parse(node_fs.readFileSync(tsconfigPath, 'utf-8'));
|
|
357
333
|
const userReferences = [
|
|
358
334
|
...Array.isArray(rspackReferences) ? rspackReferences : [],
|
|
359
335
|
...tsconfig.references ? tsconfig.references.map((item)=>item.path).filter(Boolean) : []
|
|
360
336
|
];
|
|
361
337
|
if (userReferences.length) {
|
|
362
|
-
const baseDir =
|
|
338
|
+
const baseDir = node_path.dirname(tsconfigPath);
|
|
363
339
|
for (const item of userReferences){
|
|
364
340
|
if (!item) continue;
|
|
365
|
-
const absolutePath =
|
|
341
|
+
const absolutePath = node_path.isAbsolute(item) ? item : node_path.join(baseDir, item);
|
|
366
342
|
references.add(absolutePath);
|
|
367
343
|
}
|
|
368
344
|
}
|
|
369
|
-
// avoid self reference, it will break the resolver
|
|
370
345
|
references.delete(tsconfigPath);
|
|
371
346
|
return Array.from(references);
|
|
372
347
|
};
|
|
@@ -391,8 +366,6 @@ function pluginSourceBuild(options) {
|
|
|
391
366
|
const { tsconfigPath } = environment;
|
|
392
367
|
if (!chain.resolve.plugins.has(TS_CONFIG_PATHS) || !tsconfigPath) return;
|
|
393
368
|
const references = await getReferences(tsconfigPath);
|
|
394
|
-
// set references config
|
|
395
|
-
// https://github.com/dividab/tsconfig-paths-webpack-plugin#options
|
|
396
369
|
chain.resolve.plugin(TS_CONFIG_PATHS).tap((options)=>options.map((option)=>({
|
|
397
370
|
...option,
|
|
398
371
|
references
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-source-build",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "An Rsbuild plugin to provide support for monorepo source code referencing.",
|
|
5
5
|
"repository": "https://github.com/rspack-contrib/rsbuild-plugin-source-build",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,26 +34,26 @@
|
|
|
34
34
|
]
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"fast-glob": "^3.3.
|
|
37
|
+
"fast-glob": "^3.3.3",
|
|
38
38
|
"json5": "^2.2.3",
|
|
39
|
-
"yaml": "^2.
|
|
39
|
+
"yaml": "^2.8.0"
|
|
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": "^
|
|
50
|
-
"@types/react-dom": "^
|
|
43
|
+
"@playwright/test": "^1.54.1",
|
|
44
|
+
"@rsbuild/core": "^1.4.12",
|
|
45
|
+
"@rsbuild/plugin-react": "^1.3.4",
|
|
46
|
+
"@rsbuild/plugin-type-check": "^1.2.3",
|
|
47
|
+
"@rslib/core": "^0.11.0",
|
|
48
|
+
"@types/node": "^22.17.0",
|
|
49
|
+
"@types/react": "^19.1.9",
|
|
50
|
+
"@types/react-dom": "^19.1.7",
|
|
51
51
|
"nano-staged": "^0.8.0",
|
|
52
|
-
"playwright": "^1.
|
|
53
|
-
"react": "^
|
|
54
|
-
"react-dom": "^
|
|
55
|
-
"simple-git-hooks": "^2.
|
|
56
|
-
"typescript": "^5.
|
|
52
|
+
"playwright": "^1.54.1",
|
|
53
|
+
"react": "^19.1.1",
|
|
54
|
+
"react-dom": "^19.1.1",
|
|
55
|
+
"simple-git-hooks": "^2.13.1",
|
|
56
|
+
"typescript": "^5.9.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@rsbuild/core": "1.x"
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"optional": true
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"packageManager": "pnpm@
|
|
66
|
+
"packageManager": "pnpm@10.14.0",
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public",
|
|
69
69
|
"registry": "https://registry.npmjs.org/"
|