@rsbuild/plugin-source-build 1.0.1 → 1.0.2

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 CHANGED
@@ -1,567 +1,487 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
2
+ var __webpack_modules__ = {
3
+ yaml: function(module) {
4
+ module.exports = import("yaml");
5
+ }
19
6
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- PLUGIN_SOURCE_BUILD_NAME: () => PLUGIN_SOURCE_BUILD_NAME,
34
- Project: () => Project,
35
- getMonorepoBaseData: () => getMonorepoBaseData,
36
- getMonorepoSubProjects: () => getMonorepoSubProjects,
37
- pluginSourceBuild: () => pluginSourceBuild
7
+ /************************************************************************/ // The module cache
8
+ var __webpack_module_cache__ = {};
9
+ // The require function
10
+ function __webpack_require__(moduleId) {
11
+ // Check if module is in cache
12
+ var cachedModule = __webpack_module_cache__[moduleId];
13
+ if (void 0 !== cachedModule) return cachedModule.exports;
14
+ // Create a new module (and put it into the cache)
15
+ var module = __webpack_module_cache__[moduleId] = {
16
+ exports: {}
17
+ };
18
+ // Execute the module function
19
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
20
+ // Return the exports of the module
21
+ return module.exports;
22
+ }
23
+ /************************************************************************/ // webpack/runtime/compat_get_default_export
24
+ (()=>{
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
+ };
32
+ __webpack_require__.d(getter, {
33
+ a: getter
34
+ });
35
+ return getter;
36
+ };
37
+ })();
38
+ // webpack/runtime/define_property_getters
39
+ (()=>{
40
+ __webpack_require__.d = function(exports1, definition) {
41
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
42
+ enumerable: true,
43
+ get: definition[key]
44
+ });
45
+ };
46
+ })();
47
+ // webpack/runtime/has_own_property
48
+ (()=>{
49
+ __webpack_require__.o = function(obj, prop) {
50
+ return Object.prototype.hasOwnProperty.call(obj, prop);
51
+ };
52
+ })();
53
+ // webpack/runtime/make_namespace_object
54
+ (()=>{
55
+ // define __esModule on exports
56
+ __webpack_require__.r = function(exports1) {
57
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
58
+ value: 'Module'
59
+ });
60
+ Object.defineProperty(exports1, '__esModule', {
61
+ value: true
62
+ });
63
+ };
64
+ })();
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
38
75
  });
39
- module.exports = __toCommonJS(src_exports);
40
-
41
- // src/plugin.ts
42
- var import_node_fs6 = __toESM(require("fs"), 1);
43
- var import_node_path8 = __toESM(require("path"), 1);
44
- var import_json52 = __toESM(require("json5"), 1);
45
-
46
- // src/project-utils/getDependentProjects.ts
47
- var import_node_fs5 = __toESM(require("fs"), 1);
48
- var import_node_path7 = __toESM(require("path"), 1);
49
-
50
- // src/common/getBaseData.ts
51
- var import_node_path2 = __toESM(require("path"), 1);
52
-
53
- // src/common/isMonorepo.ts
54
- var import_node_fs = __toESM(require("fs"), 1);
55
- var import_node_path = __toESM(require("path"), 1);
56
-
57
- // src/constants.ts
58
- var PNPM_WORKSPACE_FILE = "pnpm-workspace.yaml";
59
- var RUSH_JSON_FILE = "rush.json";
60
- var PACKAGE_JSON = "package.json";
61
-
62
- // src/common/isMonorepo.ts
63
- async function pathExists(path9) {
64
- return import_node_fs.default.promises.access(path9).then(() => true).catch(() => false);
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);
65
87
  }
66
- var isPnpmMonorepo = async (monorepoRootPath) => {
67
- const existPnpmWorkspaceFile = await pathExists(
68
- import_node_path.default.join(monorepoRootPath, PNPM_WORKSPACE_FILE)
69
- );
70
- return existPnpmWorkspaceFile;
88
+ const isPnpmMonorepo = async (monorepoRootPath)=>{
89
+ const existPnpmWorkspaceFile = await pathExists(external_node_path_default().join(monorepoRootPath, PNPM_WORKSPACE_FILE));
90
+ return existPnpmWorkspaceFile;
71
91
  };
72
- var isRushMonorepo = async (monorepoRootPath) => {
73
- const existRushJsonFile = await pathExists(
74
- import_node_path.default.join(monorepoRootPath, RUSH_JSON_FILE)
75
- );
76
- return existRushJsonFile;
92
+ const isRushMonorepo = async (monorepoRootPath)=>{
93
+ const existRushJsonFile = await pathExists(external_node_path_default().join(monorepoRootPath, RUSH_JSON_FILE));
94
+ return existRushJsonFile;
77
95
  };
78
- var isMonorepo = async (monorepoRootPath, otherMonorepoChecks) => {
79
- if (typeof otherMonorepoChecks === "object") {
80
- for (const [monorepoType, monorepoCheck] of Object.entries(
81
- otherMonorepoChecks
82
- )) {
83
- if (typeof monorepoCheck === "function" && await monorepoCheck(monorepoRootPath)) {
84
- return {
85
- isMonorepo: true,
86
- type: monorepoType
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
87
101
  };
88
- }
89
102
  }
90
- }
91
- if (await isPnpmMonorepo(monorepoRootPath)) {
92
- return {
93
- isMonorepo: true,
94
- type: "pnpm"
103
+ if (await isPnpmMonorepo(monorepoRootPath)) return {
104
+ isMonorepo: true,
105
+ type: 'pnpm'
106
+ };
107
+ if (await isRushMonorepo(monorepoRootPath)) return {
108
+ isMonorepo: true,
109
+ type: 'rush'
95
110
  };
96
- }
97
- if (await isRushMonorepo(monorepoRootPath)) {
98
111
  return {
99
- isMonorepo: true,
100
- type: "rush"
112
+ isMonorepo: false,
113
+ type: ''
101
114
  };
102
- }
103
- return {
104
- isMonorepo: false,
105
- type: ""
106
- };
107
115
  };
108
-
109
- // src/common/getBaseData.ts
110
- var getMonorepoBaseData = async (starFindPath, otherMonorepoAnalyzer) => {
111
- let repoIsMonorepo = false;
112
- let findPath = starFindPath;
113
- let type = "";
114
- let otherMonorepoChecks;
115
- if (otherMonorepoAnalyzer) {
116
- otherMonorepoChecks = otherMonorepoChecks ?? {};
117
- for (const [monoType, analyzer] of Object.entries(otherMonorepoAnalyzer)) {
118
- otherMonorepoChecks[monoType] = analyzer.check;
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;
119
125
  }
120
- }
121
- while (true) {
122
- const result = await isMonorepo(findPath, otherMonorepoChecks);
123
- if (result.isMonorepo) {
124
- repoIsMonorepo = true;
125
- ({ type } = result);
126
- break;
127
- }
128
- if (findPath === import_node_path2.default.dirname(findPath)) {
129
- break;
126
+ while(true){
127
+ const result = await isMonorepo(findPath, otherMonorepoChecks);
128
+ if (result.isMonorepo) {
129
+ repoIsMonorepo = true;
130
+ ({ type } = result);
131
+ break;
132
+ }
133
+ // find system root path
134
+ if (findPath === external_node_path_default().dirname(findPath)) break;
135
+ findPath = external_node_path_default().dirname(findPath);
130
136
  }
131
- findPath = import_node_path2.default.dirname(findPath);
132
- }
133
- return {
134
- isMonorepo: repoIsMonorepo,
135
- rootPath: repoIsMonorepo ? findPath : "",
136
- type,
137
- getProjects: otherMonorepoAnalyzer?.[type]?.getProjects
138
- };
139
- };
140
-
141
- // src/common/pnpm.ts
142
- var import_node_fs4 = __toESM(require("fs"), 1);
143
- var import_node_path5 = __toESM(require("path"), 1);
144
- var import_fast_glob = __toESM(require("fast-glob"), 1);
145
-
146
- // src/project.ts
147
- var import_node_fs3 = __toESM(require("fs"), 1);
148
- var import_node_path4 = __toESM(require("path"), 1);
149
-
150
- // src/utils.ts
151
- var import_node_fs2 = __toESM(require("fs"), 1);
152
- var import_node_path3 = __toESM(require("path"), 1);
153
- var import_json5 = __toESM(require("json5"), 1);
154
- var readPackageJson = async (pkgJsonFilePath) => {
155
- return readJson(pkgJsonFilePath);
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
142
+ };
156
143
  };
157
- var readRushJson = async (rushJsonFilePath) => {
158
- const rushJson = readJson(
159
- rushJsonFilePath.includes(RUSH_JSON_FILE) ? rushJsonFilePath : import_node_path3.default.join(rushJsonFilePath, RUSH_JSON_FILE)
160
- );
161
- return rushJson;
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;
162
150
  };
163
- async function pathExists2(path9) {
164
- return import_node_fs2.default.promises.access(path9).then(() => true).catch(() => false);
151
+ async function utils_pathExists(path) {
152
+ return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
165
153
  }
166
- var readJson = async (jsonFileAbsPath) => {
167
- if (!await pathExists2(jsonFileAbsPath)) {
168
- return {};
169
- }
170
- const content = await import_node_fs2.default.promises.readFile(jsonFileAbsPath, "utf-8");
171
- const json = import_json5.default.parse(content);
172
- return json;
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;
173
159
  };
174
-
175
- // src/project.ts
176
- var Project = class {
177
- constructor(name, dir) {
178
- this.name = name;
179
- this.dir = dir;
180
- }
181
- async init() {
182
- this.metaData = await readPackageJson(import_node_path4.default.join(this.dir, PACKAGE_JSON));
183
- }
184
- getMetaData() {
185
- if (this.metaData === null) {
186
- throw new Error(
187
- "The Project object needs to be initialized by executing the `init` function"
188
- );
189
- }
190
- return this.metaData;
191
- }
192
- getDependentProjects(monorepoProjects, options) {
193
- const { recursive } = options ?? { recursive: false };
194
- const allProjectMap = /* @__PURE__ */ new Map();
195
- for (const project of monorepoProjects) {
196
- allProjectMap.set(project.name, project);
197
- }
198
- if (!recursive) {
199
- return this.getDirectDependentProjects(allProjectMap);
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));
200
189
  }
201
- const computedSet = /* @__PURE__ */ new Set();
202
- computedSet.add(this.name);
203
- const queue = this.getDirectDependentProjects(allProjectMap).filter(
204
- (p) => !computedSet.has(p.name)
205
- );
206
- const result = [];
207
- while (queue.length > 0) {
208
- const item = queue.shift();
209
- if (computedSet.has(item.name)) {
210
- continue;
211
- }
212
- result.push(item);
213
- computedSet.add(item.name);
214
- const newDeps = item.getDirectDependentProjects(allProjectMap);
215
- if (newDeps.length > 0) {
216
- queue.push(...newDeps);
217
- }
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;
218
193
  }
219
- return result;
220
- }
221
- getDirectDependentProjects(allProjectMap) {
222
- const pkgJson = this.getMetaData();
223
- const { dependencies = {}, devDependencies = {} } = pkgJson;
224
- const projects = [];
225
- for (const d of Object.keys(dependencies)) {
226
- if (allProjectMap.has(d)) {
227
- projects.push(allProjectMap.get(d));
228
- }
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;
229
214
  }
230
- for (const d of Object.keys(devDependencies)) {
231
- if (allProjectMap.has(d)) {
232
- projects.push(allProjectMap.get(d));
233
- }
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;
234
222
  }
235
- return projects;
236
- }
237
- getSourceEntryPaths(options) {
238
- const { exports: checkExports = false, field: sourceField = "source" } = options ?? {};
239
- const pkgJson = this.getMetaData();
240
- const sourceDirs = pkgJson[sourceField] ? [import_node_path4.default.normalize(pkgJson[sourceField])] : [];
241
- if (checkExports) {
242
- const exportsSourceDirs = this.#getExportsSourceDirs(
243
- pkgJson.exports ?? {},
244
- sourceField
245
- );
246
- sourceDirs.push(...exportsSourceDirs);
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);
240
+ }
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);
247
243
  }
248
- if (!sourceDirs.length) {
249
- throw new Error(
250
- `"${sourceField}" field is not found in ${this.name} package.json`
251
- );
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;
252
253
  }
253
- return this.#getCommonRootPaths(sourceDirs);
254
- }
255
- #getExportsSourceDirs(exportsConfig, sourceField) {
254
+ }
255
+ function getExportsSourceDirs(exportsConfig, sourceField) {
256
256
  const exportsSourceDirs = [];
257
- if (typeof exportsConfig[sourceField] === "string") {
258
- exportsSourceDirs.push(
259
- import_node_path4.default.normalize(exportsConfig[sourceField])
260
- );
261
- }
262
- for (const moduleRules of Object.values(exportsConfig)) {
263
- if (typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string") {
264
- exportsSourceDirs.push(
265
- import_node_path4.default.normalize(moduleRules[sourceField])
266
- );
267
- }
268
- }
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
269
260
  return exportsSourceDirs;
270
- }
271
- /**
272
- *
273
- * @param paths normalize paths
274
- * @returns common root paths
275
- */
276
- #getCommonRootPaths(paths) {
277
- const commonRootPathsSet = /* @__PURE__ */ new Set();
278
- for (const p of paths) {
279
- let dir;
280
- try {
281
- dir = import_node_fs3.default.statSync(p).isDirectory() ? p : import_node_path4.default.dirname(p);
282
- } catch {
283
- dir = import_node_path4.default.dirname(p);
284
- }
285
- const rootPath = this.#getRootPath(dir);
286
- if (!commonRootPathsSet.has(rootPath)) {
287
- commonRootPathsSet.add(rootPath);
288
- }
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);
270
+ }
271
+ const rootPath = _class_private_method_get(this, _getRootPath, getRootPath).call(this, dir);
272
+ if (!commonRootPathsSet.has(rootPath)) commonRootPathsSet.add(rootPath);
289
273
  }
290
- return Array.from(commonRootPathsSet).map((p) => import_node_path4.default.join(this.dir, p));
291
- }
292
- #getRootPath(p) {
293
- return p.split(import_node_path4.default.sep)[0];
294
- }
295
- };
296
-
297
- // src/common/pnpm.ts
298
- var getPatternsFromYaml = async (monorepoRoot) => {
299
- const { parse } = await import("yaml");
300
- const workspaceYamlFilePath = import_node_path5.default.join(monorepoRoot, PNPM_WORKSPACE_FILE);
301
- const yamlContent = await import_node_fs4.default.promises.readFile(workspaceYamlFilePath, "utf8");
302
- const pnpmWorkspace = parse(yamlContent);
303
- return pnpmWorkspace.packages || [];
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 || [];
304
285
  };
305
- var normalize = (results) => results.map((fp) => import_node_path5.default.normalize(fp));
306
- var getGlobOpts = (rootPath, patterns) => {
307
- const globOpts = {
308
- cwd: rootPath,
309
- absolute: true,
310
- followSymbolicLinks: false
311
- };
312
- if (patterns.some((cfg) => cfg.includes("**") || cfg.includes("*"))) {
313
- globOpts.ignore = [
314
- // allow globs like "packages/**" or "packages/*",
315
- // but avoid picking up node_modules/**/package.json and dist/**/package.json
316
- "**/dist/**",
317
- "**/node_modules/**"
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
292
+ };
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/**'
318
298
  ];
319
- }
320
- return globOpts;
299
+ return globOpts;
321
300
  };
322
- var makeFileFinder = (rootPath, patterns) => {
323
- const globOpts = getGlobOpts(rootPath, patterns);
324
- return async (fileName, fileMapper) => {
325
- let result = await (0, import_fast_glob.default)(
326
- patterns.map((globPath) => import_node_path5.default.posix.join(globPath, fileName)),
327
- globOpts
328
- );
329
- result = result.sort();
330
- result = normalize(result);
331
- return fileMapper(result);
332
- };
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);
310
+ };
333
311
  };
334
- var readPnpmProjects = async (monorepoRoot, patterns) => {
335
- const finder = makeFileFinder(monorepoRoot, patterns);
336
- const mapper = async (pkgJsonFilePath) => {
337
- const pkgJson = await readPackageJson(pkgJsonFilePath);
338
- return {
339
- dir: import_node_path5.default.dirname(pkgJsonFilePath),
340
- manifest: pkgJson
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
319
+ };
341
320
  };
342
- };
343
- const projects = await finder(
344
- PACKAGE_JSON,
345
- (filePaths) => Promise.all(filePaths.map(mapper))
346
- );
347
- return projects;
321
+ const projects = await finder(PACKAGE_JSON, (filePaths)=>Promise.all(filePaths.map(mapper)));
322
+ return projects;
348
323
  };
349
- var getProjects = async (monorepoRoot) => {
350
- const patterns = await getPatternsFromYaml(monorepoRoot);
351
- const pnpmProjects = await readPnpmProjects(monorepoRoot, patterns);
352
- return Promise.all(
353
- pnpmProjects.filter((p) => p.manifest.name).map(async (p) => {
354
- const project = new Project(p.manifest.name, p.dir);
355
- await project.init();
356
- return project;
357
- })
358
- );
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
+ }));
359
332
  };
360
-
361
- // src/common/rush.ts
362
- var import_node_path6 = __toESM(require("path"), 1);
363
- var getProjects2 = async (monorepoRoot) => {
364
- const rushConfiguration = await readRushJson(monorepoRoot);
365
- const { projects = [] } = rushConfiguration;
366
- return Promise.all(
367
- projects.map(async (p) => {
368
- const project = new Project(
369
- p.packageName,
370
- import_node_path6.default.join(monorepoRoot, p.projectFolder)
371
- );
372
- await project.init();
373
- return project;
374
- })
375
- );
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
+ }));
376
341
  };
377
-
378
- // src/common/getProjects.ts
379
- var getMonorepoSubProjects = async (monorepoBaseData) => {
380
- const { type, rootPath, getProjects: getProjects3 } = monorepoBaseData;
381
- if (type === "pnpm") {
382
- return getProjects(rootPath);
383
- }
384
- if (type === "rush") {
385
- return getProjects2(rootPath);
386
- }
387
- if (getProjects3) {
388
- return getProjects3(rootPath);
389
- }
390
- return [];
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 [];
391
348
  };
392
-
393
- // src/project-utils/getDependentProjects.ts
394
- async function pathExists3(path9) {
395
- return import_node_fs5.default.promises.access(path9).then(() => true).catch(() => false);
349
+ async function getDependentProjects_pathExists(path) {
350
+ return external_node_fs_default().promises.access(path).then(()=>true).catch(()=>false);
396
351
  }
397
- var getDependentProjects = async (projectNameOrRootPath, options) => {
398
- const {
399
- cwd = process.cwd(),
400
- recursive,
401
- filter,
402
- extraMonorepoStrategies
403
- } = options;
404
- const currentProjectPkgJsonPath = import_node_path7.default.join(
405
- projectNameOrRootPath,
406
- "package.json"
407
- );
408
- let projectName;
409
- if (await pathExists3(currentProjectPkgJsonPath)) {
410
- ({ name: projectName } = await readPackageJson(currentProjectPkgJsonPath));
411
- } else {
412
- projectName = projectNameOrRootPath;
413
- }
414
- const monoBaseData = await getMonorepoBaseData(cwd, extraMonorepoStrategies);
415
- if (!monoBaseData.isMonorepo) {
416
- return [];
417
- }
418
- const projects = await getMonorepoSubProjects(monoBaseData);
419
- const currentProject = projects.find(
420
- (project) => project.name === projectName
421
- );
422
- if (!currentProject) {
423
- return [];
424
- }
425
- let dependentProjects = currentProject.getDependentProjects(projects, {
426
- recursive
427
- });
428
- if (filter) {
429
- dependentProjects = await filter(dependentProjects);
430
- }
431
- return dependentProjects;
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;
432
369
  };
433
-
434
- // src/project-utils/filter.ts
435
370
  function hasExportsSourceField(exportsConfig, sourceField) {
436
- return typeof exportsConfig[sourceField] === "string" || Object.values(exportsConfig).some(
437
- (moduleRules) => typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string"
438
- );
371
+ return 'string' == typeof exportsConfig[sourceField] || Object.values(exportsConfig).some((moduleRules)=>'object' == typeof moduleRules && 'string' == typeof moduleRules[sourceField]);
439
372
  }
440
- var filterByField = (fieldName, checkExports) => (projects) => {
441
- return projects.filter((p) => {
442
- return fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName);
443
- });
444
- };
445
-
446
- // src/plugin.ts
447
- var PLUGIN_SOURCE_BUILD_NAME = "rsbuild:source-build";
448
- var getSourceInclude = async (options) => {
449
- const { projects, sourceField } = options;
450
- const includes = [];
451
- for (const project of projects) {
452
- includes.push(
453
- ...project.getSourceEntryPaths({ field: sourceField, exports: true })
454
- );
455
- }
456
- return includes;
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;
457
383
  };
458
384
  function pluginSourceBuild(options) {
459
- const {
460
- projectName,
461
- sourceField = "source",
462
- resolvePriority = "source",
463
- extraMonorepoStrategies
464
- } = options ?? {};
465
- return {
466
- name: PLUGIN_SOURCE_BUILD_NAME,
467
- setup(api) {
468
- const projectRootPath = api.context.rootPath;
469
- let projects;
470
- api.modifyEnvironmentConfig(async (config) => {
471
- projects = projects || await getDependentProjects(projectName || projectRootPath, {
472
- cwd: projectRootPath,
473
- recursive: true,
474
- filter: filterByField(sourceField, true),
475
- extraMonorepoStrategies
476
- });
477
- const includes = await getSourceInclude({
478
- projects,
479
- sourceField
480
- });
481
- config.source = config.source ?? {};
482
- config.source.include = [...config.source.include ?? [], ...includes];
483
- });
484
- api.modifyBundlerChain((chain, { CHAIN_ID }) => {
485
- for (const ruleId of [CHAIN_ID.RULE.TS, CHAIN_ID.RULE.JS]) {
486
- if (chain.module.rules.get(ruleId)) {
487
- const rule = chain.module.rule(ruleId);
488
- rule.resolve.mainFields.merge(
489
- resolvePriority === "source" ? [sourceField, "..."] : ["...", sourceField]
490
- );
491
- rule.resolve.conditionNames.add("...").add(sourceField);
492
- }
493
- }
494
- });
495
- const getReferences = async (tsconfigPath, rspackReferences) => {
496
- const references = /* @__PURE__ */ new Set();
497
- for (const project of projects || []) {
498
- const filePath = import_node_path8.default.join(project.dir, "tsconfig.json");
499
- if (import_node_fs6.default.existsSync(filePath)) {
500
- references.add(filePath);
501
- }
502
- }
503
- const tsconfig = import_json52.default.parse(
504
- import_node_fs6.default.readFileSync(tsconfigPath, "utf-8")
505
- );
506
- const userReferences = [
507
- ...Array.isArray(rspackReferences) ? rspackReferences : [],
508
- ...tsconfig.references ? tsconfig.references.map((item) => item.path).filter(Boolean) : []
509
- ];
510
- if (userReferences.length) {
511
- const baseDir = import_node_path8.default.dirname(tsconfigPath);
512
- for (const item of userReferences) {
513
- if (!item) {
514
- continue;
515
- }
516
- const absolutePath = import_node_path8.default.isAbsolute(item) ? item : import_node_path8.default.join(baseDir, item);
517
- references.add(absolutePath);
518
- }
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
397
+ });
398
+ const includes = await getSourceInclude({
399
+ projects,
400
+ sourceField
401
+ });
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);
446
+ }
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
466
+ };
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
+ });
519
480
  }
520
- references.delete(tsconfigPath);
521
- return Array.from(references);
522
- };
523
- if (api.context.bundlerType === "rspack") {
524
- api.modifyRspackConfig(async (config, { environment }) => {
525
- const { tsconfigPath } = environment;
526
- if (!tsconfigPath) {
527
- return;
528
- }
529
- config.resolve ||= {};
530
- const { tsConfig = { configFile: tsconfigPath } } = config.resolve;
531
- const configObject = typeof tsConfig === "string" ? { configFile: tsConfig } : tsConfig;
532
- const references = await getReferences(
533
- tsconfigPath,
534
- configObject.references
535
- );
536
- config.resolve.tsConfig = {
537
- configFile: configObject?.configFile || tsconfigPath,
538
- references
539
- };
540
- });
541
- } else {
542
- api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => {
543
- const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
544
- const { tsconfigPath } = environment;
545
- if (!chain.resolve.plugins.has(TS_CONFIG_PATHS) || !tsconfigPath) {
546
- return;
547
- }
548
- const references = await getReferences(tsconfigPath);
549
- chain.resolve.plugin(TS_CONFIG_PATHS).tap(
550
- (options2) => options2.map((option) => ({
551
- ...option,
552
- references
553
- }))
554
- );
555
- });
556
- }
557
- }
558
- };
481
+ };
559
482
  }
560
- // Annotate the CommonJS export names for ESM import in node:
561
- 0 && (module.exports = {
562
- PLUGIN_SOURCE_BUILD_NAME,
563
- Project,
564
- getMonorepoBaseData,
565
- getMonorepoSubProjects,
566
- pluginSourceBuild
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', {
486
+ value: true
567
487
  });