@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.
Files changed (3) hide show
  1. package/dist/index.cjs +388 -421
  2. package/dist/index.js +37 -64
  3. 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
- // getDefaultExport function for compatibility with non-ESM modules
26
- __webpack_require__.n = function(module) {
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 = function(exports1, definition) {
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 = function(obj, prop) {
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
- // define __esModule on exports
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
- /************************************************************************/ var __webpack_exports__ = {};
66
- // ESM COMPAT FLAG
67
- __webpack_require__.r(__webpack_exports__);
68
- // EXPORTS
69
- __webpack_require__.d(__webpack_exports__, {
70
- getMonorepoBaseData: ()=>/* reexport */ getMonorepoBaseData,
71
- PLUGIN_SOURCE_BUILD_NAME: ()=>/* reexport */ PLUGIN_SOURCE_BUILD_NAME,
72
- pluginSourceBuild: ()=>/* reexport */ pluginSourceBuild,
73
- getMonorepoSubProjects: ()=>/* reexport */ getMonorepoSubProjects,
74
- Project: ()=>/* reexport */ Project
75
- });
76
- const external_node_fs_namespaceObject = require("node:fs");
77
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
78
- const external_node_path_namespaceObject = require("node:path");
79
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
80
- const external_json5_namespaceObject = require("json5");
81
- var external_json5_default = /*#__PURE__*/ __webpack_require__.n(external_json5_namespaceObject);
82
- const PNPM_WORKSPACE_FILE = 'pnpm-workspace.yaml';
83
- const RUSH_JSON_FILE = 'rush.json';
84
- const PACKAGE_JSON = 'package.json';
85
- async function pathExists(path) {
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
- if (await isPnpmMonorepo(monorepoRootPath)) return {
104
- isMonorepo: true,
105
- type: 'pnpm'
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
- if (await isRushMonorepo(monorepoRootPath)) return {
108
- isMonorepo: true,
109
- type: 'rush'
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
- return {
112
- isMonorepo: false,
113
- type: ''
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
- const getMonorepoBaseData = async (starFindPath, otherMonorepoAnalyzer)=>{
117
- var _otherMonorepoAnalyzer_type;
118
- let repoIsMonorepo = false;
119
- let findPath = starFindPath;
120
- let type = '';
121
- let otherMonorepoChecks;
122
- if (otherMonorepoAnalyzer) {
123
- otherMonorepoChecks = otherMonorepoChecks ?? {};
124
- for (const [monoType, analyzer] of Object.entries(otherMonorepoAnalyzer))otherMonorepoChecks[monoType] = analyzer.check;
125
- }
126
- while(true){
127
- const result = await isMonorepo(findPath, otherMonorepoChecks);
128
- if (result.isMonorepo) {
129
- repoIsMonorepo = true;
130
- ({ type } = result);
131
- break;
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
- // find system root path
134
- if (findPath === external_node_path_default().dirname(findPath)) break;
135
- findPath = external_node_path_default().dirname(findPath);
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
- return {
138
- isMonorepo: repoIsMonorepo,
139
- rootPath: repoIsMonorepo ? findPath : '',
140
- type,
141
- getProjects: null == otherMonorepoAnalyzer ? void 0 : null === (_otherMonorepoAnalyzer_type = otherMonorepoAnalyzer[type]) || void 0 === _otherMonorepoAnalyzer_type ? void 0 : _otherMonorepoAnalyzer_type.getProjects
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
- const external_fast_glob_namespaceObject = require("fast-glob");
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
- getMetaData() {
191
- if (null === this.metaData) throw new Error('The Project object needs to be initialized by executing the `init` function');
192
- return this.metaData;
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
- getDependentProjects(monorepoProjects, options) {
195
- const { recursive } = options ?? {
196
- recursive: false
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
- getDirectDependentProjects(allProjectMap) {
216
- const pkgJson = this.getMetaData();
217
- const { dependencies = {}, devDependencies = {} } = pkgJson;
218
- const projects = [];
219
- for (const d of Object.keys(dependencies))if (allProjectMap.has(d)) projects.push(allProjectMap.get(d));
220
- for (const d of Object.keys(devDependencies))if (allProjectMap.has(d)) projects.push(allProjectMap.get(d));
221
- return projects;
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
- getSourceEntryPaths(options) {
224
- const { exports: checkExports = false, field: sourceField = 'source' } = options ?? {};
225
- const pkgJson = this.getMetaData();
226
- // normalize strings
227
- const sourceDirs = pkgJson[sourceField] ? [
228
- external_node_path_default().normalize(pkgJson[sourceField])
229
- ] : [];
230
- if (checkExports) {
231
- /**
232
- * analyze exports:
233
- * "exports": {
234
- * ".": {
235
- * "source": "./src/index.ts"
236
- * }
237
- * },
238
- */ const exportsSourceDirs = _class_private_method_get(this, _getExportsSourceDirs, getExportsSourceDirs).call(this, pkgJson.exports ?? {}, sourceField);
239
- sourceDirs.push(...exportsSourceDirs);
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
- constructor(name, dir){
245
- _class_private_method_init(this, _getExportsSourceDirs);
246
- _class_private_method_init(this, _getCommonRootPaths);
247
- _class_private_method_init(this, _getRootPath);
248
- _define_property(this, "name", void 0);
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
- function getExportsSourceDirs(exportsConfig, sourceField) {
256
- const exportsSourceDirs = [];
257
- if ('string' == typeof exportsConfig[sourceField]) exportsSourceDirs.push(external_node_path_default().normalize(exportsConfig[sourceField]));
258
- for (const moduleRules of Object.values(exportsConfig))if ('object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]) exportsSourceDirs.push(external_node_path_default().normalize(moduleRules[sourceField]));
259
- // normalize strings
260
- return exportsSourceDirs;
261
- }
262
- function getCommonRootPaths(paths) {
263
- const commonRootPathsSet = new Set();
264
- for (const p of paths){
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
- const rootPath = _class_private_method_get(this, _getRootPath, getRootPath).call(this, dir);
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
- return Array.from(commonRootPathsSet).map((p)=>external_node_path_default().join(this.dir, p));
275
- }
276
- function getRootPath(p) {
277
- return p.split(external_node_path_default().sep)[0];
278
- }
279
- const getPatternsFromYaml = async (monorepoRoot)=>{
280
- const { parse } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "yaml"));
281
- const workspaceYamlFilePath = external_node_path_default().join(monorepoRoot, PNPM_WORKSPACE_FILE);
282
- const yamlContent = await external_node_fs_default().promises.readFile(workspaceYamlFilePath, 'utf8');
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
- if (patterns.some((cfg)=>cfg.includes('**') || cfg.includes('*'))) globOpts.ignore = [
294
- // allow globs like "packages/**" or "packages/*",
295
- // but avoid picking up node_modules/**/package.json and dist/**/package.json
296
- '**/dist/**',
297
- '**/node_modules/**'
298
- ];
299
- return globOpts;
300
- };
301
- const makeFileFinder = (rootPath, patterns)=>{
302
- const globOpts = getGlobOpts(rootPath, patterns);
303
- return async (fileName, fileMapper)=>{
304
- let result = await external_fast_glob_default()(patterns.map((globPath)=>external_node_path_default().posix.join(globPath, fileName)), globOpts);
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 readPnpmProjects = async (monorepoRoot, patterns)=>{
313
- const finder = makeFileFinder(monorepoRoot, patterns);
314
- const mapper = async (pkgJsonFilePath)=>{
315
- const pkgJson = await readPackageJson(pkgJsonFilePath);
316
- return {
317
- dir: external_node_path_default().dirname(pkgJsonFilePath),
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 projects = await finder(PACKAGE_JSON, (filePaths)=>Promise.all(filePaths.map(mapper)));
322
- return projects;
323
- };
324
- const pnpm_getProjects = async (monorepoRoot)=>{
325
- const patterns = await getPatternsFromYaml(monorepoRoot);
326
- const pnpmProjects = await readPnpmProjects(monorepoRoot, patterns);
327
- return Promise.all(pnpmProjects.filter((p)=>p.manifest.name).map(async (p)=>{
328
- const project = new Project(p.manifest.name, p.dir);
329
- await project.init();
330
- return project;
331
- }));
332
- };
333
- const rush_getProjects = async (monorepoRoot)=>{
334
- const rushConfiguration = await readRushJson(monorepoRoot);
335
- const { projects = [] } = rushConfiguration;
336
- return Promise.all(projects.map(async (p)=>{
337
- const project = new Project(p.packageName, external_node_path_default().join(monorepoRoot, p.projectFolder));
338
- await project.init();
339
- return project;
340
- }));
341
- };
342
- const getMonorepoSubProjects = async (monorepoBaseData)=>{
343
- const { type, rootPath, getProjects } = monorepoBaseData;
344
- if ('pnpm' === type) return pnpm_getProjects(rootPath);
345
- if ('rush' === type) return rush_getProjects(rootPath);
346
- if (getProjects) return getProjects(rootPath);
347
- return [];
348
- };
349
- async function getDependentProjects_pathExists(path) {
350
- return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
351
- }
352
- const getDependentProjects = async (projectNameOrRootPath, options)=>{
353
- const { cwd = process.cwd(), recursive, filter, extraMonorepoStrategies } = options;
354
- // check if first argument is projectRootPath.
355
- const currentProjectPkgJsonPath = external_node_path_default().join(projectNameOrRootPath, 'package.json');
356
- let projectName;
357
- if (await getDependentProjects_pathExists(currentProjectPkgJsonPath)) ({ name: projectName } = await readPackageJson(currentProjectPkgJsonPath));
358
- else projectName = projectNameOrRootPath;
359
- const monoBaseData = await getMonorepoBaseData(cwd, extraMonorepoStrategies);
360
- if (!monoBaseData.isMonorepo) return [];
361
- const projects = await getMonorepoSubProjects(monoBaseData);
362
- const currentProject = projects.find((project)=>project.name === projectName);
363
- if (!currentProject) return [];
364
- let dependentProjects = currentProject.getDependentProjects(projects, {
365
- recursive
366
- });
367
- if (filter) dependentProjects = await filter(dependentProjects);
368
- return dependentProjects;
369
- };
370
- function hasExportsSourceField(exportsConfig, sourceField) {
371
- return 'string' == typeof exportsConfig[sourceField] || Object.values(exportsConfig).some((moduleRules)=>'object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]);
372
- }
373
- const filterByField = (fieldName, checkExports)=>(projects)=>projects.filter((p)=>fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName));
374
- const PLUGIN_SOURCE_BUILD_NAME = 'rsbuild:source-build';
375
- const getSourceInclude = async (options)=>{
376
- const { projects, sourceField } = options;
377
- const includes = [];
378
- for (const project of projects)includes.push(...project.getSourceEntryPaths({
379
- field: sourceField,
380
- exports: true
381
- }));
382
- return includes;
383
- };
384
- function pluginSourceBuild(options) {
385
- const { projectName, sourceField = 'source', resolvePriority = 'source', extraMonorepoStrategies } = options ?? {};
386
- return {
387
- name: PLUGIN_SOURCE_BUILD_NAME,
388
- setup (api) {
389
- const projectRootPath = api.context.rootPath;
390
- let projects;
391
- api.modifyEnvironmentConfig(async (config)=>{
392
- projects = projects || await getDependentProjects(projectName || projectRootPath, {
393
- cwd: projectRootPath,
394
- recursive: true,
395
- filter: filterByField(sourceField, true),
396
- extraMonorepoStrategies
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
- const includes = await getSourceInclude({
399
- projects,
400
- sourceField
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
- config.source = config.source ?? {};
403
- config.source.include = [
404
- ...config.source.include ?? [],
405
- ...includes
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
- // avoid self reference, it will break the resolver
449
- references.delete(tsconfigPath);
450
- return Array.from(references);
451
- };
452
- if ('rspack' === api.context.bundlerType) api.modifyRspackConfig(async (config, { environment })=>{
453
- const { tsconfigPath } = environment;
454
- if (!tsconfigPath) return;
455
- config.resolve ||= {};
456
- const { tsConfig = {
457
- configFile: tsconfigPath
458
- } } = config.resolve;
459
- const configObject = 'string' == typeof tsConfig ? {
460
- configFile: tsConfig
461
- } : tsConfig;
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
- else api.modifyBundlerChain(async (chain, { CHAIN_ID, environment })=>{
469
- const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
470
- const { tsconfigPath } = environment;
471
- if (!chain.resolve.plugins.has(TS_CONFIG_PATHS) || !tsconfigPath) return;
472
- const references = await getReferences(tsconfigPath);
473
- // set references config
474
- // https://github.com/dividab/tsconfig-paths-webpack-plugin#options
475
- chain.resolve.plugin(TS_CONFIG_PATHS).tap((options)=>options.map((option)=>({
476
- ...option,
477
- references
478
- })));
479
- });
480
- }
481
- };
482
- }
483
- var __webpack_export_target__ = exports;
484
- for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
485
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
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 * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
2
- import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
3
- import * as __WEBPACK_EXTERNAL_MODULE_json5__ from "json5";
4
- import * as __WEBPACK_EXTERNAL_MODULE_fast_glob__ from "fast-glob";
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 __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.access(path).then(()=>true).catch(()=>false);
9
+ return node_fs.promises.access(path).then(()=>true).catch(()=>false);
10
10
  }
11
11
  const isPnpmMonorepo = async (monorepoRootPath)=>{
12
- const existPnpmWorkspaceFile = await pathExists(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(monorepoRootPath, PNPM_WORKSPACE_FILE));
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(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(monorepoRootPath, RUSH_JSON_FILE));
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
- // find system root path
57
- if (findPath === __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(findPath)) break;
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 === (_otherMonorepoAnalyzer_type = otherMonorepoAnalyzer[type]) || void 0 === _otherMonorepoAnalyzer_type ? void 0 : _otherMonorepoAnalyzer_type.getProjects
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 : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(rushJsonFilePath, RUSH_JSON_FILE));
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 __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.access(path).then(()=>true).catch(()=>false);
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 __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.readFile(jsonFileAbsPath, 'utf-8');
78
- const json = __WEBPACK_EXTERNAL_MODULE_json5__["default"].parse(content);
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(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(this.dir, PACKAGE_JSON));
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
- __WEBPACK_EXTERNAL_MODULE_node_path__["default"].normalize(pkgJson[sourceField])
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(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].normalize(exportsConfig[sourceField]));
179
- for (const moduleRules of Object.values(exportsConfig))if ('object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]) exportsSourceDirs.push(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].normalize(moduleRules[sourceField]));
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 = __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].statSync(p).isDirectory() ? p : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(p);
174
+ dir = node_fs.statSync(p).isDirectory() ? p : node_path.dirname(p);
189
175
  } catch {
190
- dir = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(p);
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)=>__WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(this.dir, 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(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].sep)[0];
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 = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(monorepoRoot, PNPM_WORKSPACE_FILE);
203
- const yamlContent = await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.readFile(workspaceYamlFilePath, 'utf8');
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)=>__WEBPACK_EXTERNAL_MODULE_node_path__["default"].normalize(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 (0, __WEBPACK_EXTERNAL_MODULE_fast_glob__["default"])(patterns.map((globPath)=>__WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.join(globPath, fileName)), globOpts);
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: __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(pkgJsonFilePath),
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, __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(monorepoRoot, p.projectFolder));
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 __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.access(path).then(()=>true).catch(()=>false);
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
- // check if first argument is projectRootPath.
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 = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(project.dir, 'tsconfig.json');
353
- if (__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(filePath)) references.add(filePath);
329
+ const filePath = node_path.join(project.dir, 'tsconfig.json');
330
+ if (node_fs.existsSync(filePath)) references.add(filePath);
354
331
  }
355
- // Add references in the current project's tsconfig.json
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 = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname(tsconfigPath);
338
+ const baseDir = node_path.dirname(tsconfigPath);
363
339
  for (const item of userReferences){
364
340
  if (!item) continue;
365
- const absolutePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].isAbsolute(item) ? item : __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(baseDir, item);
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.2",
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.2",
37
+ "fast-glob": "^3.3.3",
38
38
  "json5": "^2.2.3",
39
- "yaml": "^2.6.1"
39
+ "yaml": "^2.8.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@biomejs/biome": "^1.9.4",
43
- "@playwright/test": "^1.49.0",
44
- "@rsbuild/core": "^1.1.6",
45
- "@rsbuild/plugin-react": "^1.0.7",
46
- "@rsbuild/plugin-type-check": "^1.1.0",
47
- "@rslib/core": "^0.1.1",
48
- "@types/node": "^22.10.1",
49
- "@types/react": "^18.3.12",
50
- "@types/react-dom": "^18.3.1",
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.49.0",
53
- "react": "^18.3.1",
54
- "react-dom": "^18.3.1",
55
- "simple-git-hooks": "^2.11.1",
56
- "typescript": "^5.7.2"
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@9.14.4",
66
+ "packageManager": "pnpm@10.14.0",
67
67
  "publishConfig": {
68
68
  "access": "public",
69
69
  "registry": "https://registry.npmjs.org/"