@rsbuild/plugin-source-build 0.7.10 → 1.0.0-alpha.0
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/common/getBaseData.d.ts +9 -0
- package/dist/common/getProjects.d.ts +4 -0
- package/dist/common/index.d.ts +6 -0
- package/dist/common/isMonorepo.d.ts +8 -0
- package/dist/common/pnpm.d.ts +2 -0
- package/dist/common/rush.d.ts +2 -0
- package/dist/constants.d.ts +3 -0
- package/dist/index.cjs +74 -64
- package/dist/index.d.ts +4 -207
- package/dist/index.js +74 -65
- package/dist/plugin.d.ts +23 -0
- package/dist/project-utils/filter.d.ts +4 -0
- package/dist/project-utils/getDependentProjects.d.ts +12 -0
- package/dist/project-utils/index.d.ts +2 -0
- package/dist/project.d.ts +18 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/packageJson.d.ts +152 -0
- package/dist/types/rushJson.d.ts +7 -0
- package/dist/utils.d.ts +4 -0
- package/package.json +7 -7
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MonorepoAnalyzer } from '../types';
|
|
2
|
+
import type { GetProjectsFunc } from './getProjects';
|
|
3
|
+
export interface IMonorepoBaseData {
|
|
4
|
+
isMonorepo: boolean;
|
|
5
|
+
type: string;
|
|
6
|
+
rootPath: string;
|
|
7
|
+
getProjects?: GetProjectsFunc;
|
|
8
|
+
}
|
|
9
|
+
export declare const getMonorepoBaseData: (starFindPath: string, otherMonorepoAnalyzer?: Record<string, MonorepoAnalyzer>) => Promise<IMonorepoBaseData>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Project } from '../project';
|
|
2
|
+
import type { IMonorepoBaseData } from './getBaseData';
|
|
3
|
+
export type GetProjectsFunc = (rootPath: string) => Promise<Project[]> | Project[];
|
|
4
|
+
export declare const getMonorepoSubProjects: (monorepoBaseData: IMonorepoBaseData) => Promise<Project[]>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './getBaseData';
|
|
2
|
+
export * from './isMonorepo';
|
|
3
|
+
export { getMonorepoSubProjects } from './getProjects';
|
|
4
|
+
export { getProjects as getPnpmMonorepoSubProjects } from './pnpm';
|
|
5
|
+
export { getProjects as getRushMonorepoSubProjects } from './rush';
|
|
6
|
+
export type { GetProjectsFunc } from './getProjects';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type IsMonorepoFn = (monorepoRootPath: string) => Promise<boolean> | boolean;
|
|
2
|
+
export type IsMonorepoResult = {
|
|
3
|
+
isMonorepo: boolean;
|
|
4
|
+
type: 'rush' | 'pnpm' | string;
|
|
5
|
+
};
|
|
6
|
+
export declare const isPnpmMonorepo: IsMonorepoFn;
|
|
7
|
+
export declare const isRushMonorepo: IsMonorepoFn;
|
|
8
|
+
export declare const isMonorepo: (monorepoRootPath: string, otherMonorepoChecks?: Record<string, IsMonorepoFn>) => Promise<IsMonorepoResult>;
|
package/dist/index.cjs
CHANGED
|
@@ -63,12 +63,15 @@ var init_constants = __esm({
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
// src/utils.ts
|
|
66
|
-
|
|
66
|
+
async function pathExists2(path9) {
|
|
67
|
+
return import_node_fs2.default.promises.access(path9).then(() => true).catch(() => false);
|
|
68
|
+
}
|
|
69
|
+
var import_node_fs2, import_node_path3, import_json5, readPackageJson, readRushJson, readJson;
|
|
67
70
|
var init_utils = __esm({
|
|
68
71
|
"src/utils.ts"() {
|
|
69
72
|
"use strict";
|
|
73
|
+
import_node_fs2 = __toESM(require("fs"));
|
|
70
74
|
import_node_path3 = __toESM(require("path"));
|
|
71
|
-
import_shared2 = require("@rsbuild/shared");
|
|
72
75
|
import_json5 = __toESM(require("json5"));
|
|
73
76
|
init_constants();
|
|
74
77
|
readPackageJson = async (pkgJsonFilePath) => {
|
|
@@ -81,22 +84,22 @@ var init_utils = __esm({
|
|
|
81
84
|
return rushJson;
|
|
82
85
|
};
|
|
83
86
|
readJson = async (jsonFileAbsPath) => {
|
|
84
|
-
if (!await
|
|
87
|
+
if (!await pathExists2(jsonFileAbsPath)) {
|
|
85
88
|
return {};
|
|
86
89
|
}
|
|
87
|
-
const content = await
|
|
90
|
+
const content = await import_node_fs2.default.promises.readFile(jsonFileAbsPath, "utf-8");
|
|
88
91
|
const json = import_json5.default.parse(content);
|
|
89
92
|
return json;
|
|
90
93
|
};
|
|
91
94
|
}
|
|
92
95
|
});
|
|
93
96
|
|
|
94
|
-
// src/project
|
|
95
|
-
var
|
|
97
|
+
// src/project.ts
|
|
98
|
+
var import_node_fs3, import_node_path4, _getExportsSourceDirs, getExportsSourceDirs_fn, _getCommonRootPaths, getCommonRootPaths_fn, _getRootPath, getRootPath_fn, Project;
|
|
96
99
|
var init_project = __esm({
|
|
97
|
-
"src/project
|
|
100
|
+
"src/project.ts"() {
|
|
98
101
|
"use strict";
|
|
99
|
-
|
|
102
|
+
import_node_fs3 = __toESM(require("fs"));
|
|
100
103
|
import_node_path4 = __toESM(require("path"));
|
|
101
104
|
init_constants();
|
|
102
105
|
init_utils();
|
|
@@ -191,6 +194,11 @@ var init_project = __esm({
|
|
|
191
194
|
_getExportsSourceDirs = new WeakSet();
|
|
192
195
|
getExportsSourceDirs_fn = function(exportsConfig, sourceField) {
|
|
193
196
|
const exportsSourceDirs = [];
|
|
197
|
+
if (typeof exportsConfig[sourceField] === "string") {
|
|
198
|
+
exportsSourceDirs.push(
|
|
199
|
+
import_node_path4.default.normalize(exportsConfig[sourceField])
|
|
200
|
+
);
|
|
201
|
+
}
|
|
194
202
|
for (const moduleRules of Object.values(exportsConfig)) {
|
|
195
203
|
if (typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string") {
|
|
196
204
|
exportsSourceDirs.push(
|
|
@@ -206,7 +214,7 @@ var init_project = __esm({
|
|
|
206
214
|
for (const p of paths) {
|
|
207
215
|
let dir;
|
|
208
216
|
try {
|
|
209
|
-
dir =
|
|
217
|
+
dir = import_node_fs3.default.statSync(p).isDirectory() ? p : import_node_path4.default.dirname(p);
|
|
210
218
|
} catch {
|
|
211
219
|
dir = import_node_path4.default.dirname(p);
|
|
212
220
|
}
|
|
@@ -6957,14 +6965,14 @@ var require_parser = __commonJS({
|
|
|
6957
6965
|
case "scalar":
|
|
6958
6966
|
case "single-quoted-scalar":
|
|
6959
6967
|
case "double-quoted-scalar": {
|
|
6960
|
-
const
|
|
6968
|
+
const fs7 = this.flowScalar(this.type);
|
|
6961
6969
|
if (atNextItem || it.value) {
|
|
6962
|
-
map.items.push({ start, key:
|
|
6970
|
+
map.items.push({ start, key: fs7, sep: [] });
|
|
6963
6971
|
this.onKeyLine = true;
|
|
6964
6972
|
} else if (it.sep) {
|
|
6965
|
-
this.stack.push(
|
|
6973
|
+
this.stack.push(fs7);
|
|
6966
6974
|
} else {
|
|
6967
|
-
Object.assign(it, { key:
|
|
6975
|
+
Object.assign(it, { key: fs7, sep: [] });
|
|
6968
6976
|
this.onKeyLine = true;
|
|
6969
6977
|
}
|
|
6970
6978
|
return;
|
|
@@ -7082,13 +7090,13 @@ var require_parser = __commonJS({
|
|
|
7082
7090
|
case "scalar":
|
|
7083
7091
|
case "single-quoted-scalar":
|
|
7084
7092
|
case "double-quoted-scalar": {
|
|
7085
|
-
const
|
|
7093
|
+
const fs7 = this.flowScalar(this.type);
|
|
7086
7094
|
if (!it || it.value)
|
|
7087
|
-
fc.items.push({ start: [], key:
|
|
7095
|
+
fc.items.push({ start: [], key: fs7, sep: [] });
|
|
7088
7096
|
else if (it.sep)
|
|
7089
|
-
this.stack.push(
|
|
7097
|
+
this.stack.push(fs7);
|
|
7090
7098
|
else
|
|
7091
|
-
Object.assign(it, { key:
|
|
7099
|
+
Object.assign(it, { key: fs7, sep: [] });
|
|
7092
7100
|
return;
|
|
7093
7101
|
}
|
|
7094
7102
|
case "flow-map-end":
|
|
@@ -7395,18 +7403,14 @@ var require_dist = __commonJS({
|
|
|
7395
7403
|
// src/common/pnpm.ts
|
|
7396
7404
|
var pnpm_exports = {};
|
|
7397
7405
|
__export(pnpm_exports, {
|
|
7398
|
-
|
|
7399
|
-
getProjects: () => getProjects,
|
|
7400
|
-
makeFileFinder: () => makeFileFinder,
|
|
7401
|
-
normalize: () => normalize,
|
|
7402
|
-
readPnpmProjects: () => readPnpmProjects
|
|
7406
|
+
getProjects: () => getProjects
|
|
7403
7407
|
});
|
|
7404
|
-
var
|
|
7408
|
+
var import_node_fs4, import_node_path5, import_fast_glob, getPatternsFromYaml, normalize, getGlobOpts, makeFileFinder, readPnpmProjects, getProjects;
|
|
7405
7409
|
var init_pnpm = __esm({
|
|
7406
7410
|
"src/common/pnpm.ts"() {
|
|
7407
7411
|
"use strict";
|
|
7412
|
+
import_node_fs4 = __toESM(require("fs"));
|
|
7408
7413
|
import_node_path5 = __toESM(require("path"));
|
|
7409
|
-
import_shared3 = require("@rsbuild/shared");
|
|
7410
7414
|
import_fast_glob = __toESM(require("fast-glob"));
|
|
7411
7415
|
init_constants();
|
|
7412
7416
|
init_project();
|
|
@@ -7414,7 +7418,7 @@ var init_pnpm = __esm({
|
|
|
7414
7418
|
getPatternsFromYaml = async (monorepoRoot) => {
|
|
7415
7419
|
const { parse } = await Promise.resolve().then(() => __toESM(require_dist()));
|
|
7416
7420
|
const workspaceYamlFilePath = import_node_path5.default.join(monorepoRoot, PNPM_WORKSPACE_FILE);
|
|
7417
|
-
const yamlContent = await
|
|
7421
|
+
const yamlContent = await import_node_fs4.default.promises.readFile(workspaceYamlFilePath, "utf8");
|
|
7418
7422
|
const pnpmWorkspace = parse(yamlContent);
|
|
7419
7423
|
return pnpmWorkspace.packages || [];
|
|
7420
7424
|
};
|
|
@@ -7517,28 +7521,31 @@ __export(src_exports, {
|
|
|
7517
7521
|
module.exports = __toCommonJS(src_exports);
|
|
7518
7522
|
|
|
7519
7523
|
// src/plugin.ts
|
|
7520
|
-
var
|
|
7524
|
+
var import_node_fs6 = __toESM(require("fs"));
|
|
7521
7525
|
var import_node_path8 = __toESM(require("path"));
|
|
7522
7526
|
|
|
7523
7527
|
// src/project-utils/getDependentProjects.ts
|
|
7528
|
+
var import_node_fs5 = __toESM(require("fs"));
|
|
7524
7529
|
var import_node_path7 = __toESM(require("path"));
|
|
7525
|
-
var import_shared4 = require("@rsbuild/shared");
|
|
7526
7530
|
|
|
7527
7531
|
// src/common/getBaseData.ts
|
|
7528
7532
|
var import_node_path2 = __toESM(require("path"));
|
|
7529
7533
|
|
|
7530
7534
|
// src/common/isMonorepo.ts
|
|
7535
|
+
var import_node_fs = __toESM(require("fs"));
|
|
7531
7536
|
var import_node_path = __toESM(require("path"));
|
|
7532
|
-
var import_shared = require("@rsbuild/shared");
|
|
7533
7537
|
init_constants();
|
|
7538
|
+
async function pathExists(path9) {
|
|
7539
|
+
return import_node_fs.default.promises.access(path9).then(() => true).catch(() => false);
|
|
7540
|
+
}
|
|
7534
7541
|
var isPnpmMonorepo = async (monorepoRootPath) => {
|
|
7535
|
-
const existPnpmWorkspaceFile = await
|
|
7542
|
+
const existPnpmWorkspaceFile = await pathExists(
|
|
7536
7543
|
import_node_path.default.join(monorepoRootPath, PNPM_WORKSPACE_FILE)
|
|
7537
7544
|
);
|
|
7538
7545
|
return existPnpmWorkspaceFile;
|
|
7539
7546
|
};
|
|
7540
7547
|
var isRushMonorepo = async (monorepoRootPath) => {
|
|
7541
|
-
const existRushJsonFile = await
|
|
7548
|
+
const existRushJsonFile = await pathExists(
|
|
7542
7549
|
import_node_path.default.join(monorepoRootPath, RUSH_JSON_FILE)
|
|
7543
7550
|
);
|
|
7544
7551
|
return existRushJsonFile;
|
|
@@ -7629,27 +7636,9 @@ init_rush();
|
|
|
7629
7636
|
|
|
7630
7637
|
// src/project-utils/getDependentProjects.ts
|
|
7631
7638
|
init_utils();
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
function hasExportsSourceField(exportsConfig, sourceField) {
|
|
7635
|
-
return Object.values(exportsConfig).some(
|
|
7636
|
-
(moduleRules) => typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string"
|
|
7637
|
-
);
|
|
7639
|
+
async function pathExists3(path9) {
|
|
7640
|
+
return import_node_fs5.default.promises.access(path9).then(() => true).catch(() => false);
|
|
7638
7641
|
}
|
|
7639
|
-
var defaultFilter = (projects) => projects;
|
|
7640
|
-
var filterByField = (fieldName, checkExports) => (projects) => {
|
|
7641
|
-
return projects.filter((p) => {
|
|
7642
|
-
return fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName);
|
|
7643
|
-
});
|
|
7644
|
-
};
|
|
7645
|
-
|
|
7646
|
-
// src/project-utils/getDependentProjects.ts
|
|
7647
|
-
var filterProjects = async (projects, filter) => {
|
|
7648
|
-
if (!filter) {
|
|
7649
|
-
return defaultFilter(projects);
|
|
7650
|
-
}
|
|
7651
|
-
return filter(projects);
|
|
7652
|
-
};
|
|
7653
7642
|
var getDependentProjects = async (projectNameOrRootPath, options) => {
|
|
7654
7643
|
const {
|
|
7655
7644
|
cwd = process.cwd(),
|
|
@@ -7662,7 +7651,7 @@ var getDependentProjects = async (projectNameOrRootPath, options) => {
|
|
|
7662
7651
|
"package.json"
|
|
7663
7652
|
);
|
|
7664
7653
|
let projectName;
|
|
7665
|
-
if (await
|
|
7654
|
+
if (await pathExists3(currentProjectPkgJsonPath)) {
|
|
7666
7655
|
({ name: projectName } = await readPackageJson(currentProjectPkgJsonPath));
|
|
7667
7656
|
} else {
|
|
7668
7657
|
projectName = projectNameOrRootPath;
|
|
@@ -7681,10 +7670,24 @@ var getDependentProjects = async (projectNameOrRootPath, options) => {
|
|
|
7681
7670
|
let dependentProjects = currentProject.getDependentProjects(projects, {
|
|
7682
7671
|
recursive
|
|
7683
7672
|
});
|
|
7684
|
-
|
|
7673
|
+
if (filter) {
|
|
7674
|
+
dependentProjects = await filter(dependentProjects);
|
|
7675
|
+
}
|
|
7685
7676
|
return dependentProjects;
|
|
7686
7677
|
};
|
|
7687
7678
|
|
|
7679
|
+
// src/project-utils/filter.ts
|
|
7680
|
+
function hasExportsSourceField(exportsConfig, sourceField) {
|
|
7681
|
+
return typeof exportsConfig[sourceField] === "string" || Object.values(exportsConfig).some(
|
|
7682
|
+
(moduleRules) => typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string"
|
|
7683
|
+
);
|
|
7684
|
+
}
|
|
7685
|
+
var filterByField = (fieldName, checkExports) => (projects) => {
|
|
7686
|
+
return projects.filter((p) => {
|
|
7687
|
+
return fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName);
|
|
7688
|
+
});
|
|
7689
|
+
};
|
|
7690
|
+
|
|
7688
7691
|
// src/plugin.ts
|
|
7689
7692
|
var PLUGIN_SOURCE_BUILD_NAME = "rsbuild:source-build";
|
|
7690
7693
|
var getSourceInclude = async (options) => {
|
|
@@ -7734,36 +7737,43 @@ function pluginSourceBuild(options) {
|
|
|
7734
7737
|
}
|
|
7735
7738
|
}
|
|
7736
7739
|
});
|
|
7737
|
-
const getReferences = async () => {
|
|
7738
|
-
const refers = projects.map((project) => import_node_path8.default.join(project.dir, "tsconfig.json")).filter((filePath) =>
|
|
7739
|
-
if (
|
|
7740
|
+
const getReferences = async (tsconfigPath) => {
|
|
7741
|
+
const refers = projects.map((project) => import_node_path8.default.join(project.dir, "tsconfig.json")).filter((filePath) => import_node_fs6.default.existsSync(filePath));
|
|
7742
|
+
if (tsconfigPath) {
|
|
7740
7743
|
const { default: json52 } = await import("json5");
|
|
7741
7744
|
const { references } = json52.parse(
|
|
7742
|
-
|
|
7745
|
+
import_node_fs6.default.readFileSync(tsconfigPath, "utf-8")
|
|
7743
7746
|
);
|
|
7744
7747
|
return Array.isArray(references) ? references.map((r) => r.path).filter(Boolean).concat(refers) : refers;
|
|
7745
7748
|
}
|
|
7746
7749
|
return refers;
|
|
7747
7750
|
};
|
|
7748
7751
|
if (api.context.bundlerType === "rspack") {
|
|
7749
|
-
api.modifyRspackConfig(async (config) => {
|
|
7750
|
-
|
|
7752
|
+
api.modifyRspackConfig(async (config, { environment }) => {
|
|
7753
|
+
const { tsconfigPath } = environment;
|
|
7754
|
+
if (!tsconfigPath) {
|
|
7751
7755
|
return;
|
|
7752
7756
|
}
|
|
7753
7757
|
config.resolve ||= {};
|
|
7758
|
+
const { tsConfig = { configFile: tsconfigPath } } = config.resolve;
|
|
7759
|
+
const configObject = typeof tsConfig === "string" ? { configFile: tsConfig } : tsConfig;
|
|
7760
|
+
const references = [
|
|
7761
|
+
...await getReferences(tsconfigPath),
|
|
7762
|
+
...Array.isArray(configObject.references) ? configObject.references : []
|
|
7763
|
+
];
|
|
7754
7764
|
config.resolve.tsConfig = {
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
references: await getReferences()
|
|
7765
|
+
configFile: configObject?.configFile || tsconfigPath,
|
|
7766
|
+
references
|
|
7758
7767
|
};
|
|
7759
7768
|
});
|
|
7760
7769
|
} else {
|
|
7761
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
7770
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => {
|
|
7762
7771
|
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
7763
7772
|
if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
|
|
7764
7773
|
return;
|
|
7765
7774
|
}
|
|
7766
|
-
const
|
|
7775
|
+
const { tsconfigPath } = environment;
|
|
7776
|
+
const references = await getReferences(tsconfigPath);
|
|
7767
7777
|
chain.resolve.plugin(TS_CONFIG_PATHS).tap(
|
|
7768
7778
|
(options2) => options2.map((option) => ({
|
|
7769
7779
|
...option,
|
|
@@ -7776,7 +7786,7 @@ function pluginSourceBuild(options) {
|
|
|
7776
7786
|
};
|
|
7777
7787
|
}
|
|
7778
7788
|
|
|
7779
|
-
// src/
|
|
7789
|
+
// src/index.ts
|
|
7780
7790
|
init_project();
|
|
7781
7791
|
// Annotate the CommonJS export names for ESM import in node:
|
|
7782
7792
|
0 && (module.exports = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,207 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* https://github.com/microsoft/rushstack/blob/main/libraries/node-core-library/src/IPackageJson.ts
|
|
6
|
-
*
|
|
7
|
-
* MIT Licensed
|
|
8
|
-
* Copyright (c) Microsoft Corporation
|
|
9
|
-
* https://github.com/microsoft/rushstack/blob/main/LICENSE
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* This interface is part of the {@link IPackageJson} file format. It is used for the
|
|
13
|
-
* "dependencies", "optionalDependencies", and "devDependencies" fields.
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
interface IPackageJsonDependencyTable {
|
|
17
|
-
/**
|
|
18
|
-
* The key is the name of a dependency. The value is a Semantic Versioning (SemVer)
|
|
19
|
-
* range specifier.
|
|
20
|
-
*/
|
|
21
|
-
[dependencyName: string]: string;
|
|
22
|
-
}
|
|
23
|
-
interface IPackageJsonRepository {
|
|
24
|
-
/**
|
|
25
|
-
* The source control type for the repository that hosts the project. This is typically "git".
|
|
26
|
-
*/
|
|
27
|
-
type: string;
|
|
28
|
-
/**
|
|
29
|
-
* The URL of the repository that hosts the project.
|
|
30
|
-
*/
|
|
31
|
-
url: string;
|
|
32
|
-
/**
|
|
33
|
-
* If the project does not exist at the root of the repository, its path is specified here.
|
|
34
|
-
*/
|
|
35
|
-
directory?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* This interface is part of the {@link IPackageJson} file format. It is used for the
|
|
39
|
-
* "scripts" field.
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
interface IPackageJsonScriptTable {
|
|
43
|
-
/**
|
|
44
|
-
* The key is the name of the script hook. The value is the script body which may
|
|
45
|
-
* be a file path or shell script command.
|
|
46
|
-
*/
|
|
47
|
-
[scriptName: string]: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* This interface is part of the {@link IPackageJson} file format. It is used for the
|
|
51
|
-
* "peerDependenciesMeta" field.
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
interface IPeerDependenciesMetaTable {
|
|
55
|
-
[dependencyName: string]: {
|
|
56
|
-
optional?: boolean;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
type ExportsModuleRules = string | Record<string, string> | Record<string, string | Record<string, string>>;
|
|
60
|
-
interface ExportsConfig {
|
|
61
|
-
[modulePath: string]: ExportsModuleRules;
|
|
62
|
-
}
|
|
63
|
-
interface INodePackageJson {
|
|
64
|
-
/**
|
|
65
|
-
* The name of the package.
|
|
66
|
-
*/
|
|
67
|
-
name: string;
|
|
68
|
-
/**
|
|
69
|
-
* A version number conforming to the Semantic Versioning (SemVer) standard.
|
|
70
|
-
*/
|
|
71
|
-
version?: string;
|
|
72
|
-
/**
|
|
73
|
-
* Indicates whether this package is allowed to be published or not.
|
|
74
|
-
*/
|
|
75
|
-
private?: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* A brief description of the package.
|
|
78
|
-
*/
|
|
79
|
-
description?: string;
|
|
80
|
-
/**
|
|
81
|
-
* The URL of the project's repository.
|
|
82
|
-
*/
|
|
83
|
-
repository?: string | IPackageJsonRepository;
|
|
84
|
-
/**
|
|
85
|
-
* The URL to the project's web page.
|
|
86
|
-
*/
|
|
87
|
-
homepage?: string;
|
|
88
|
-
/**
|
|
89
|
-
* The name of the license.
|
|
90
|
-
*/
|
|
91
|
-
license?: string;
|
|
92
|
-
/**
|
|
93
|
-
* The path to the module file that will act as the main entry point.
|
|
94
|
-
*/
|
|
95
|
-
main?: string;
|
|
96
|
-
exports?: ExportsConfig;
|
|
97
|
-
/**
|
|
98
|
-
* The path to the TypeScript *.d.ts file describing the module file
|
|
99
|
-
* that will act as the main entry point.
|
|
100
|
-
*/
|
|
101
|
-
types?: string;
|
|
102
|
-
/**
|
|
103
|
-
* Alias for `types`
|
|
104
|
-
*/
|
|
105
|
-
typings?: string;
|
|
106
|
-
/**
|
|
107
|
-
* The path to the TSDoc metadata file.
|
|
108
|
-
* This is still being standardized: https://github.com/microsoft/tsdoc/issues/7#issuecomment-442271815
|
|
109
|
-
* @beta
|
|
110
|
-
*/
|
|
111
|
-
tsdocMetadata?: string;
|
|
112
|
-
/**
|
|
113
|
-
* The main entry point for the package.
|
|
114
|
-
*/
|
|
115
|
-
bin?: string;
|
|
116
|
-
/**
|
|
117
|
-
* An array of dependencies that must always be installed for this package.
|
|
118
|
-
*/
|
|
119
|
-
dependencies?: IPackageJsonDependencyTable;
|
|
120
|
-
/**
|
|
121
|
-
* An array of optional dependencies that may be installed for this package.
|
|
122
|
-
*/
|
|
123
|
-
optionalDependencies?: IPackageJsonDependencyTable;
|
|
124
|
-
/**
|
|
125
|
-
* An array of dependencies that must only be installed for developers who will
|
|
126
|
-
* build this package.
|
|
127
|
-
*/
|
|
128
|
-
devDependencies?: IPackageJsonDependencyTable;
|
|
129
|
-
/**
|
|
130
|
-
* An array of dependencies that must be installed by a consumer of this package,
|
|
131
|
-
* but which will not be automatically installed by this package.
|
|
132
|
-
*/
|
|
133
|
-
peerDependencies?: IPackageJsonDependencyTable;
|
|
134
|
-
/**
|
|
135
|
-
* An array of metadata about peer dependencies.
|
|
136
|
-
*/
|
|
137
|
-
peerDependenciesMeta?: IPeerDependenciesMetaTable;
|
|
138
|
-
/**
|
|
139
|
-
* A table of script hooks that a package manager or build tool may invoke.
|
|
140
|
-
*/
|
|
141
|
-
scripts?: IPackageJsonScriptTable;
|
|
142
|
-
/**
|
|
143
|
-
* A table of package version resolutions. This feature is only implemented by the Yarn package manager.
|
|
144
|
-
*
|
|
145
|
-
* @remarks
|
|
146
|
-
* See the {@link https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md
|
|
147
|
-
* | 0000-selective-versions-resolutions.md RFC} for details.
|
|
148
|
-
*/
|
|
149
|
-
resolutions?: Record<string, string>;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
declare class Project {
|
|
153
|
-
#private;
|
|
154
|
-
name: string;
|
|
155
|
-
dir: string;
|
|
156
|
-
metaData: INodePackageJson;
|
|
157
|
-
constructor(name: string, dir: string);
|
|
158
|
-
init(): Promise<void>;
|
|
159
|
-
getMetaData(): INodePackageJson;
|
|
160
|
-
getDependentProjects(monorepoProjects: Project[], options?: {
|
|
161
|
-
recursive?: boolean;
|
|
162
|
-
}): Project[];
|
|
163
|
-
getDirectDependentProjects(allProjectMap: Map<string, Project>): Project[];
|
|
164
|
-
getSourceEntryPaths(options?: {
|
|
165
|
-
field?: string;
|
|
166
|
-
exports?: boolean;
|
|
167
|
-
}): string[];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
interface IMonorepoBaseData {
|
|
171
|
-
isMonorepo: boolean;
|
|
172
|
-
type: string;
|
|
173
|
-
rootPath: string;
|
|
174
|
-
getProjects?: GetProjectsFunc;
|
|
175
|
-
}
|
|
176
|
-
declare const getMonorepoBaseData: (starFindPath: string, otherMonorepoAnalyzer?: Record<string, MonorepoAnalyzer>) => Promise<IMonorepoBaseData>;
|
|
177
|
-
|
|
178
|
-
type GetProjectsFunc = (rootPath: string) => Promise<Project[]> | Project[];
|
|
179
|
-
declare const getMonorepoSubProjects: (monorepoBaseData: IMonorepoBaseData) => Promise<Project[]>;
|
|
180
|
-
|
|
181
|
-
type IsMonorepoFn = (monorepoRootPath: string) => Promise<boolean> | boolean;
|
|
182
|
-
|
|
183
|
-
interface MonorepoAnalyzer {
|
|
184
|
-
check: IsMonorepoFn;
|
|
185
|
-
getProjects: GetProjectsFunc;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
type ExtraMonorepoStrategies = Record<string, MonorepoAnalyzer>;
|
|
189
|
-
|
|
190
|
-
declare const PLUGIN_SOURCE_BUILD_NAME = "rsbuild:source-build";
|
|
191
|
-
interface PluginSourceBuildOptions {
|
|
192
|
-
/**
|
|
193
|
-
* Used to configure the resolve field of the source code files.
|
|
194
|
-
* @default 'source''
|
|
195
|
-
*/
|
|
196
|
-
sourceField?: string;
|
|
197
|
-
/**
|
|
198
|
-
* Whether to read source code or output code first.
|
|
199
|
-
* @default 'source'
|
|
200
|
-
*/
|
|
201
|
-
resolvePriority?: 'source' | 'output';
|
|
202
|
-
projectName?: string;
|
|
203
|
-
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
204
|
-
}
|
|
205
|
-
declare function pluginSourceBuild(options?: PluginSourceBuildOptions): RsbuildPlugin;
|
|
206
|
-
|
|
207
|
-
export { type MonorepoAnalyzer, PLUGIN_SOURCE_BUILD_NAME, type PluginSourceBuildOptions, Project, getMonorepoBaseData, getMonorepoSubProjects, pluginSourceBuild };
|
|
1
|
+
export { PLUGIN_SOURCE_BUILD_NAME, pluginSourceBuild, type PluginSourceBuildOptions, } from './plugin';
|
|
2
|
+
export { Project } from './project';
|
|
3
|
+
export { getMonorepoBaseData, getMonorepoSubProjects } from './common';
|
|
4
|
+
export type { MonorepoAnalyzer } from './types';
|
package/dist/index.js
CHANGED
|
@@ -52,11 +52,11 @@ var __privateMethod = (obj, member, method) => {
|
|
|
52
52
|
return method;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
55
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
56
56
|
import { fileURLToPath } from "url";
|
|
57
57
|
import path from "path";
|
|
58
58
|
var init_esm = __esm({
|
|
59
|
-
"../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
59
|
+
"../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js"() {
|
|
60
60
|
"use strict";
|
|
61
61
|
}
|
|
62
62
|
});
|
|
@@ -74,9 +74,12 @@ var init_constants = __esm({
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
// src/utils.ts
|
|
77
|
+
import fs2 from "fs";
|
|
77
78
|
import path4 from "path";
|
|
78
|
-
import { fse as fse2 } from "@rsbuild/shared";
|
|
79
79
|
import json5 from "json5";
|
|
80
|
+
async function pathExists2(path10) {
|
|
81
|
+
return fs2.promises.access(path10).then(() => true).catch(() => false);
|
|
82
|
+
}
|
|
80
83
|
var readPackageJson, readRushJson, readJson;
|
|
81
84
|
var init_utils = __esm({
|
|
82
85
|
"src/utils.ts"() {
|
|
@@ -93,22 +96,22 @@ var init_utils = __esm({
|
|
|
93
96
|
return rushJson;
|
|
94
97
|
};
|
|
95
98
|
readJson = async (jsonFileAbsPath) => {
|
|
96
|
-
if (!await
|
|
99
|
+
if (!await pathExists2(jsonFileAbsPath)) {
|
|
97
100
|
return {};
|
|
98
101
|
}
|
|
99
|
-
const content = await
|
|
102
|
+
const content = await fs2.promises.readFile(jsonFileAbsPath, "utf-8");
|
|
100
103
|
const json = json5.parse(content);
|
|
101
104
|
return json;
|
|
102
105
|
};
|
|
103
106
|
}
|
|
104
107
|
});
|
|
105
108
|
|
|
106
|
-
// src/project
|
|
107
|
-
import
|
|
109
|
+
// src/project.ts
|
|
110
|
+
import fs3 from "fs";
|
|
108
111
|
import path5 from "path";
|
|
109
112
|
var _getExportsSourceDirs, getExportsSourceDirs_fn, _getCommonRootPaths, getCommonRootPaths_fn, _getRootPath, getRootPath_fn, Project;
|
|
110
113
|
var init_project = __esm({
|
|
111
|
-
"src/project
|
|
114
|
+
"src/project.ts"() {
|
|
112
115
|
"use strict";
|
|
113
116
|
init_esm();
|
|
114
117
|
init_constants();
|
|
@@ -204,6 +207,11 @@ var init_project = __esm({
|
|
|
204
207
|
_getExportsSourceDirs = new WeakSet();
|
|
205
208
|
getExportsSourceDirs_fn = function(exportsConfig, sourceField) {
|
|
206
209
|
const exportsSourceDirs = [];
|
|
210
|
+
if (typeof exportsConfig[sourceField] === "string") {
|
|
211
|
+
exportsSourceDirs.push(
|
|
212
|
+
path5.normalize(exportsConfig[sourceField])
|
|
213
|
+
);
|
|
214
|
+
}
|
|
207
215
|
for (const moduleRules of Object.values(exportsConfig)) {
|
|
208
216
|
if (typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string") {
|
|
209
217
|
exportsSourceDirs.push(
|
|
@@ -219,7 +227,7 @@ var init_project = __esm({
|
|
|
219
227
|
for (const p of paths) {
|
|
220
228
|
let dir;
|
|
221
229
|
try {
|
|
222
|
-
dir =
|
|
230
|
+
dir = fs3.statSync(p).isDirectory() ? p : path5.dirname(p);
|
|
223
231
|
} catch {
|
|
224
232
|
dir = path5.dirname(p);
|
|
225
233
|
}
|
|
@@ -7039,14 +7047,14 @@ var require_parser = __commonJS({
|
|
|
7039
7047
|
case "scalar":
|
|
7040
7048
|
case "single-quoted-scalar":
|
|
7041
7049
|
case "double-quoted-scalar": {
|
|
7042
|
-
const
|
|
7050
|
+
const fs7 = this.flowScalar(this.type);
|
|
7043
7051
|
if (atNextItem || it.value) {
|
|
7044
|
-
map.items.push({ start, key:
|
|
7052
|
+
map.items.push({ start, key: fs7, sep: [] });
|
|
7045
7053
|
this.onKeyLine = true;
|
|
7046
7054
|
} else if (it.sep) {
|
|
7047
|
-
this.stack.push(
|
|
7055
|
+
this.stack.push(fs7);
|
|
7048
7056
|
} else {
|
|
7049
|
-
Object.assign(it, { key:
|
|
7057
|
+
Object.assign(it, { key: fs7, sep: [] });
|
|
7050
7058
|
this.onKeyLine = true;
|
|
7051
7059
|
}
|
|
7052
7060
|
return;
|
|
@@ -7164,13 +7172,13 @@ var require_parser = __commonJS({
|
|
|
7164
7172
|
case "scalar":
|
|
7165
7173
|
case "single-quoted-scalar":
|
|
7166
7174
|
case "double-quoted-scalar": {
|
|
7167
|
-
const
|
|
7175
|
+
const fs7 = this.flowScalar(this.type);
|
|
7168
7176
|
if (!it || it.value)
|
|
7169
|
-
fc.items.push({ start: [], key:
|
|
7177
|
+
fc.items.push({ start: [], key: fs7, sep: [] });
|
|
7170
7178
|
else if (it.sep)
|
|
7171
|
-
this.stack.push(
|
|
7179
|
+
this.stack.push(fs7);
|
|
7172
7180
|
else
|
|
7173
|
-
Object.assign(it, { key:
|
|
7181
|
+
Object.assign(it, { key: fs7, sep: [] });
|
|
7174
7182
|
return;
|
|
7175
7183
|
}
|
|
7176
7184
|
case "flow-map-end":
|
|
@@ -7479,14 +7487,10 @@ var require_dist = __commonJS({
|
|
|
7479
7487
|
// src/common/pnpm.ts
|
|
7480
7488
|
var pnpm_exports = {};
|
|
7481
7489
|
__export(pnpm_exports, {
|
|
7482
|
-
|
|
7483
|
-
getProjects: () => getProjects,
|
|
7484
|
-
makeFileFinder: () => makeFileFinder,
|
|
7485
|
-
normalize: () => normalize,
|
|
7486
|
-
readPnpmProjects: () => readPnpmProjects
|
|
7490
|
+
getProjects: () => getProjects
|
|
7487
7491
|
});
|
|
7492
|
+
import fs4 from "fs";
|
|
7488
7493
|
import path6 from "path";
|
|
7489
|
-
import { fse as fse3 } from "@rsbuild/shared";
|
|
7490
7494
|
import glob from "fast-glob";
|
|
7491
7495
|
var getPatternsFromYaml, normalize, getGlobOpts, makeFileFinder, readPnpmProjects, getProjects;
|
|
7492
7496
|
var init_pnpm = __esm({
|
|
@@ -7499,7 +7503,7 @@ var init_pnpm = __esm({
|
|
|
7499
7503
|
getPatternsFromYaml = async (monorepoRoot) => {
|
|
7500
7504
|
const { parse } = await Promise.resolve().then(() => __toESM(require_dist()));
|
|
7501
7505
|
const workspaceYamlFilePath = path6.join(monorepoRoot, PNPM_WORKSPACE_FILE);
|
|
7502
|
-
const yamlContent = await
|
|
7506
|
+
const yamlContent = await fs4.promises.readFile(workspaceYamlFilePath, "utf8");
|
|
7503
7507
|
const pnpmWorkspace = parse(yamlContent);
|
|
7504
7508
|
return pnpmWorkspace.packages || [];
|
|
7505
7509
|
};
|
|
@@ -7596,7 +7600,7 @@ init_esm();
|
|
|
7596
7600
|
|
|
7597
7601
|
// src/plugin.ts
|
|
7598
7602
|
init_esm();
|
|
7599
|
-
import
|
|
7603
|
+
import fs6 from "fs";
|
|
7600
7604
|
import path9 from "path";
|
|
7601
7605
|
|
|
7602
7606
|
// src/project-utils/index.ts
|
|
@@ -7604,8 +7608,8 @@ init_esm();
|
|
|
7604
7608
|
|
|
7605
7609
|
// src/project-utils/getDependentProjects.ts
|
|
7606
7610
|
init_esm();
|
|
7611
|
+
import fs5 from "fs";
|
|
7607
7612
|
import path8 from "path";
|
|
7608
|
-
import { fse as fse4 } from "@rsbuild/shared";
|
|
7609
7613
|
|
|
7610
7614
|
// src/common/index.ts
|
|
7611
7615
|
init_esm();
|
|
@@ -7617,16 +7621,19 @@ import path3 from "path";
|
|
|
7617
7621
|
// src/common/isMonorepo.ts
|
|
7618
7622
|
init_esm();
|
|
7619
7623
|
init_constants();
|
|
7624
|
+
import fs from "fs";
|
|
7620
7625
|
import path2 from "path";
|
|
7621
|
-
|
|
7626
|
+
async function pathExists(path10) {
|
|
7627
|
+
return fs.promises.access(path10).then(() => true).catch(() => false);
|
|
7628
|
+
}
|
|
7622
7629
|
var isPnpmMonorepo = async (monorepoRootPath) => {
|
|
7623
|
-
const existPnpmWorkspaceFile = await
|
|
7630
|
+
const existPnpmWorkspaceFile = await pathExists(
|
|
7624
7631
|
path2.join(monorepoRootPath, PNPM_WORKSPACE_FILE)
|
|
7625
7632
|
);
|
|
7626
7633
|
return existPnpmWorkspaceFile;
|
|
7627
7634
|
};
|
|
7628
7635
|
var isRushMonorepo = async (monorepoRootPath) => {
|
|
7629
|
-
const existRushJsonFile = await
|
|
7636
|
+
const existRushJsonFile = await pathExists(
|
|
7630
7637
|
path2.join(monorepoRootPath, RUSH_JSON_FILE)
|
|
7631
7638
|
);
|
|
7632
7639
|
return existRushJsonFile;
|
|
@@ -7718,28 +7725,9 @@ init_rush();
|
|
|
7718
7725
|
|
|
7719
7726
|
// src/project-utils/getDependentProjects.ts
|
|
7720
7727
|
init_utils();
|
|
7721
|
-
|
|
7722
|
-
|
|
7723
|
-
init_esm();
|
|
7724
|
-
function hasExportsSourceField(exportsConfig, sourceField) {
|
|
7725
|
-
return Object.values(exportsConfig).some(
|
|
7726
|
-
(moduleRules) => typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string"
|
|
7727
|
-
);
|
|
7728
|
+
async function pathExists3(path10) {
|
|
7729
|
+
return fs5.promises.access(path10).then(() => true).catch(() => false);
|
|
7728
7730
|
}
|
|
7729
|
-
var defaultFilter = (projects) => projects;
|
|
7730
|
-
var filterByField = (fieldName, checkExports) => (projects) => {
|
|
7731
|
-
return projects.filter((p) => {
|
|
7732
|
-
return fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName);
|
|
7733
|
-
});
|
|
7734
|
-
};
|
|
7735
|
-
|
|
7736
|
-
// src/project-utils/getDependentProjects.ts
|
|
7737
|
-
var filterProjects = async (projects, filter) => {
|
|
7738
|
-
if (!filter) {
|
|
7739
|
-
return defaultFilter(projects);
|
|
7740
|
-
}
|
|
7741
|
-
return filter(projects);
|
|
7742
|
-
};
|
|
7743
7731
|
var getDependentProjects = async (projectNameOrRootPath, options) => {
|
|
7744
7732
|
const {
|
|
7745
7733
|
cwd = process.cwd(),
|
|
@@ -7752,7 +7740,7 @@ var getDependentProjects = async (projectNameOrRootPath, options) => {
|
|
|
7752
7740
|
"package.json"
|
|
7753
7741
|
);
|
|
7754
7742
|
let projectName;
|
|
7755
|
-
if (await
|
|
7743
|
+
if (await pathExists3(currentProjectPkgJsonPath)) {
|
|
7756
7744
|
({ name: projectName } = await readPackageJson(currentProjectPkgJsonPath));
|
|
7757
7745
|
} else {
|
|
7758
7746
|
projectName = projectNameOrRootPath;
|
|
@@ -7771,10 +7759,25 @@ var getDependentProjects = async (projectNameOrRootPath, options) => {
|
|
|
7771
7759
|
let dependentProjects = currentProject.getDependentProjects(projects, {
|
|
7772
7760
|
recursive
|
|
7773
7761
|
});
|
|
7774
|
-
|
|
7762
|
+
if (filter) {
|
|
7763
|
+
dependentProjects = await filter(dependentProjects);
|
|
7764
|
+
}
|
|
7775
7765
|
return dependentProjects;
|
|
7776
7766
|
};
|
|
7777
7767
|
|
|
7768
|
+
// src/project-utils/filter.ts
|
|
7769
|
+
init_esm();
|
|
7770
|
+
function hasExportsSourceField(exportsConfig, sourceField) {
|
|
7771
|
+
return typeof exportsConfig[sourceField] === "string" || Object.values(exportsConfig).some(
|
|
7772
|
+
(moduleRules) => typeof moduleRules === "object" && typeof moduleRules[sourceField] === "string"
|
|
7773
|
+
);
|
|
7774
|
+
}
|
|
7775
|
+
var filterByField = (fieldName, checkExports) => (projects) => {
|
|
7776
|
+
return projects.filter((p) => {
|
|
7777
|
+
return fieldName in p.metaData || checkExports && hasExportsSourceField(p.metaData.exports || {}, fieldName);
|
|
7778
|
+
});
|
|
7779
|
+
};
|
|
7780
|
+
|
|
7778
7781
|
// src/plugin.ts
|
|
7779
7782
|
var PLUGIN_SOURCE_BUILD_NAME = "rsbuild:source-build";
|
|
7780
7783
|
var getSourceInclude = async (options) => {
|
|
@@ -7824,36 +7827,43 @@ function pluginSourceBuild(options) {
|
|
|
7824
7827
|
}
|
|
7825
7828
|
}
|
|
7826
7829
|
});
|
|
7827
|
-
const getReferences = async () => {
|
|
7828
|
-
const refers = projects.map((project) => path9.join(project.dir, "tsconfig.json")).filter((filePath) =>
|
|
7829
|
-
if (
|
|
7830
|
+
const getReferences = async (tsconfigPath) => {
|
|
7831
|
+
const refers = projects.map((project) => path9.join(project.dir, "tsconfig.json")).filter((filePath) => fs6.existsSync(filePath));
|
|
7832
|
+
if (tsconfigPath) {
|
|
7830
7833
|
const { default: json52 } = await import("json5");
|
|
7831
7834
|
const { references } = json52.parse(
|
|
7832
|
-
|
|
7835
|
+
fs6.readFileSync(tsconfigPath, "utf-8")
|
|
7833
7836
|
);
|
|
7834
7837
|
return Array.isArray(references) ? references.map((r) => r.path).filter(Boolean).concat(refers) : refers;
|
|
7835
7838
|
}
|
|
7836
7839
|
return refers;
|
|
7837
7840
|
};
|
|
7838
7841
|
if (api.context.bundlerType === "rspack") {
|
|
7839
|
-
api.modifyRspackConfig(async (config) => {
|
|
7840
|
-
|
|
7842
|
+
api.modifyRspackConfig(async (config, { environment }) => {
|
|
7843
|
+
const { tsconfigPath } = environment;
|
|
7844
|
+
if (!tsconfigPath) {
|
|
7841
7845
|
return;
|
|
7842
7846
|
}
|
|
7843
7847
|
config.resolve ||= {};
|
|
7848
|
+
const { tsConfig = { configFile: tsconfigPath } } = config.resolve;
|
|
7849
|
+
const configObject = typeof tsConfig === "string" ? { configFile: tsConfig } : tsConfig;
|
|
7850
|
+
const references = [
|
|
7851
|
+
...await getReferences(tsconfigPath),
|
|
7852
|
+
...Array.isArray(configObject.references) ? configObject.references : []
|
|
7853
|
+
];
|
|
7844
7854
|
config.resolve.tsConfig = {
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
references: await getReferences()
|
|
7855
|
+
configFile: configObject?.configFile || tsconfigPath,
|
|
7856
|
+
references
|
|
7848
7857
|
};
|
|
7849
7858
|
});
|
|
7850
7859
|
} else {
|
|
7851
|
-
api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
|
|
7860
|
+
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => {
|
|
7852
7861
|
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
7853
7862
|
if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
|
|
7854
7863
|
return;
|
|
7855
7864
|
}
|
|
7856
|
-
const
|
|
7865
|
+
const { tsconfigPath } = environment;
|
|
7866
|
+
const references = await getReferences(tsconfigPath);
|
|
7857
7867
|
chain.resolve.plugin(TS_CONFIG_PATHS).tap(
|
|
7858
7868
|
(options2) => options2.map((option) => ({
|
|
7859
7869
|
...option,
|
|
@@ -7866,8 +7876,7 @@ function pluginSourceBuild(options) {
|
|
|
7866
7876
|
};
|
|
7867
7877
|
}
|
|
7868
7878
|
|
|
7869
|
-
// src/
|
|
7870
|
-
init_esm();
|
|
7879
|
+
// src/index.ts
|
|
7871
7880
|
init_project();
|
|
7872
7881
|
export {
|
|
7873
7882
|
PLUGIN_SOURCE_BUILD_NAME,
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import type { Project } from './project';
|
|
3
|
+
import { type ExtraMonorepoStrategies } from './project-utils';
|
|
4
|
+
export declare const PLUGIN_SOURCE_BUILD_NAME = "rsbuild:source-build";
|
|
5
|
+
export declare const getSourceInclude: (options: {
|
|
6
|
+
projects: Project[];
|
|
7
|
+
sourceField: string;
|
|
8
|
+
}) => Promise<string[]>;
|
|
9
|
+
export interface PluginSourceBuildOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Used to configure the resolve field of the source code files.
|
|
12
|
+
* @default 'source''
|
|
13
|
+
*/
|
|
14
|
+
sourceField?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to read source code or output code first.
|
|
17
|
+
* @default 'source'
|
|
18
|
+
*/
|
|
19
|
+
resolvePriority?: 'source' | 'output';
|
|
20
|
+
projectName?: string;
|
|
21
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
22
|
+
}
|
|
23
|
+
export declare function pluginSourceBuild(options?: PluginSourceBuildOptions): RsbuildPlugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Project } from '../project';
|
|
2
|
+
import type { MonorepoAnalyzer } from '../types';
|
|
3
|
+
import type { Filter } from './filter';
|
|
4
|
+
export type ExtraMonorepoStrategies = Record<string, MonorepoAnalyzer>;
|
|
5
|
+
export interface GetDependentProjectsOptions {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
recursive?: boolean;
|
|
8
|
+
filter?: Filter;
|
|
9
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
10
|
+
}
|
|
11
|
+
declare const getDependentProjects: (projectNameOrRootPath: string, options: GetDependentProjectsOptions) => Promise<Project[]>;
|
|
12
|
+
export { getDependentProjects };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { INodePackageJson } from './types/packageJson';
|
|
2
|
+
export declare class Project {
|
|
3
|
+
#private;
|
|
4
|
+
name: string;
|
|
5
|
+
dir: string;
|
|
6
|
+
metaData: INodePackageJson;
|
|
7
|
+
constructor(name: string, dir: string);
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
getMetaData(): INodePackageJson;
|
|
10
|
+
getDependentProjects(monorepoProjects: Project[], options?: {
|
|
11
|
+
recursive?: boolean;
|
|
12
|
+
}): Project[];
|
|
13
|
+
getDirectDependentProjects(allProjectMap: Map<string, Project>): Project[];
|
|
14
|
+
getSourceEntryPaths(options?: {
|
|
15
|
+
field?: string;
|
|
16
|
+
exports?: boolean;
|
|
17
|
+
}): string[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GetProjectsFunc } from '../common/getProjects';
|
|
2
|
+
import type { IsMonorepoFn } from '../common/isMonorepo';
|
|
3
|
+
export * from './packageJson';
|
|
4
|
+
export * from './rushJson';
|
|
5
|
+
export interface MonorepoAnalyzer {
|
|
6
|
+
check: IsMonorepoFn;
|
|
7
|
+
getProjects: GetProjectsFunc;
|
|
8
|
+
}
|
|
9
|
+
export interface IPnpmWorkSpace {
|
|
10
|
+
packages: string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The following code is modified based on
|
|
3
|
+
* https://github.com/microsoft/rushstack/blob/main/libraries/node-core-library/src/IPackageJson.ts
|
|
4
|
+
*
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
* Copyright (c) Microsoft Corporation
|
|
7
|
+
* https://github.com/microsoft/rushstack/blob/main/LICENSE
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* This interface is part of the {@link IPackageJson} file format. It is used for the
|
|
11
|
+
* "dependencies", "optionalDependencies", and "devDependencies" fields.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface IPackageJsonDependencyTable {
|
|
15
|
+
/**
|
|
16
|
+
* The key is the name of a dependency. The value is a Semantic Versioning (SemVer)
|
|
17
|
+
* range specifier.
|
|
18
|
+
*/
|
|
19
|
+
[dependencyName: string]: string;
|
|
20
|
+
}
|
|
21
|
+
export interface IPackageJsonRepository {
|
|
22
|
+
/**
|
|
23
|
+
* The source control type for the repository that hosts the project. This is typically "git".
|
|
24
|
+
*/
|
|
25
|
+
type: string;
|
|
26
|
+
/**
|
|
27
|
+
* The URL of the repository that hosts the project.
|
|
28
|
+
*/
|
|
29
|
+
url: string;
|
|
30
|
+
/**
|
|
31
|
+
* If the project does not exist at the root of the repository, its path is specified here.
|
|
32
|
+
*/
|
|
33
|
+
directory?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This interface is part of the {@link IPackageJson} file format. It is used for the
|
|
37
|
+
* "scripts" field.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export interface IPackageJsonScriptTable {
|
|
41
|
+
/**
|
|
42
|
+
* The key is the name of the script hook. The value is the script body which may
|
|
43
|
+
* be a file path or shell script command.
|
|
44
|
+
*/
|
|
45
|
+
[scriptName: string]: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* This interface is part of the {@link IPackageJson} file format. It is used for the
|
|
49
|
+
* "peerDependenciesMeta" field.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export interface IPeerDependenciesMetaTable {
|
|
53
|
+
[dependencyName: string]: {
|
|
54
|
+
optional?: boolean;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export type ExportsModuleRules = string | Record<string, string> | Record<string, string | Record<string, string>>;
|
|
58
|
+
export interface ExportsConfig {
|
|
59
|
+
[modulePath: string]: ExportsModuleRules;
|
|
60
|
+
}
|
|
61
|
+
export interface INodePackageJson {
|
|
62
|
+
/**
|
|
63
|
+
* The name of the package.
|
|
64
|
+
*/
|
|
65
|
+
name: string;
|
|
66
|
+
/**
|
|
67
|
+
* A version number conforming to the Semantic Versioning (SemVer) standard.
|
|
68
|
+
*/
|
|
69
|
+
version?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Indicates whether this package is allowed to be published or not.
|
|
72
|
+
*/
|
|
73
|
+
private?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* A brief description of the package.
|
|
76
|
+
*/
|
|
77
|
+
description?: string;
|
|
78
|
+
/**
|
|
79
|
+
* The URL of the project's repository.
|
|
80
|
+
*/
|
|
81
|
+
repository?: string | IPackageJsonRepository;
|
|
82
|
+
/**
|
|
83
|
+
* The URL to the project's web page.
|
|
84
|
+
*/
|
|
85
|
+
homepage?: string;
|
|
86
|
+
/**
|
|
87
|
+
* The name of the license.
|
|
88
|
+
*/
|
|
89
|
+
license?: string;
|
|
90
|
+
/**
|
|
91
|
+
* The path to the module file that will act as the main entry point.
|
|
92
|
+
*/
|
|
93
|
+
main?: string;
|
|
94
|
+
exports?: ExportsConfig;
|
|
95
|
+
/**
|
|
96
|
+
* The path to the TypeScript *.d.ts file describing the module file
|
|
97
|
+
* that will act as the main entry point.
|
|
98
|
+
*/
|
|
99
|
+
types?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Alias for `types`
|
|
102
|
+
*/
|
|
103
|
+
typings?: string;
|
|
104
|
+
/**
|
|
105
|
+
* The path to the TSDoc metadata file.
|
|
106
|
+
* This is still being standardized: https://github.com/microsoft/tsdoc/issues/7#issuecomment-442271815
|
|
107
|
+
* @beta
|
|
108
|
+
*/
|
|
109
|
+
tsdocMetadata?: string;
|
|
110
|
+
/**
|
|
111
|
+
* The main entry point for the package.
|
|
112
|
+
*/
|
|
113
|
+
bin?: string;
|
|
114
|
+
/**
|
|
115
|
+
* An array of dependencies that must always be installed for this package.
|
|
116
|
+
*/
|
|
117
|
+
dependencies?: IPackageJsonDependencyTable;
|
|
118
|
+
/**
|
|
119
|
+
* An array of optional dependencies that may be installed for this package.
|
|
120
|
+
*/
|
|
121
|
+
optionalDependencies?: IPackageJsonDependencyTable;
|
|
122
|
+
/**
|
|
123
|
+
* An array of dependencies that must only be installed for developers who will
|
|
124
|
+
* build this package.
|
|
125
|
+
*/
|
|
126
|
+
devDependencies?: IPackageJsonDependencyTable;
|
|
127
|
+
/**
|
|
128
|
+
* An array of dependencies that must be installed by a consumer of this package,
|
|
129
|
+
* but which will not be automatically installed by this package.
|
|
130
|
+
*/
|
|
131
|
+
peerDependencies?: IPackageJsonDependencyTable;
|
|
132
|
+
/**
|
|
133
|
+
* An array of metadata about peer dependencies.
|
|
134
|
+
*/
|
|
135
|
+
peerDependenciesMeta?: IPeerDependenciesMetaTable;
|
|
136
|
+
/**
|
|
137
|
+
* A table of script hooks that a package manager or build tool may invoke.
|
|
138
|
+
*/
|
|
139
|
+
scripts?: IPackageJsonScriptTable;
|
|
140
|
+
/**
|
|
141
|
+
* A table of package version resolutions. This feature is only implemented by the Yarn package manager.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* See the {@link https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md
|
|
145
|
+
* | 0000-selective-versions-resolutions.md RFC} for details.
|
|
146
|
+
*/
|
|
147
|
+
resolutions?: Record<string, string>;
|
|
148
|
+
}
|
|
149
|
+
export interface IPackageJson extends INodePackageJson {
|
|
150
|
+
/** {@inheritDoc INodePackageJson.version} */
|
|
151
|
+
version: string;
|
|
152
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { INodePackageJson, IRushConfig } from './types';
|
|
2
|
+
export declare const readPackageJson: (pkgJsonFilePath: string) => Promise<INodePackageJson>;
|
|
3
|
+
export declare const readRushJson: (rushJsonFilePath: string) => Promise<IRushConfig>;
|
|
4
|
+
export declare const readJson: <T>(jsonFileAbsPath: string) => Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-source-build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
4
|
"description": "Source build plugin of Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"fast-glob": "^3.3.2",
|
|
27
27
|
"json5": "^2.2.3",
|
|
28
|
-
"@rsbuild/shared": "0.
|
|
28
|
+
"@rsbuild/shared": "1.0.0-alpha.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"typescript": "^5.
|
|
31
|
+
"typescript": "^5.5.2",
|
|
32
32
|
"yaml": "^2.4.5",
|
|
33
|
-
"@rsbuild/core": "0.
|
|
34
|
-
"@rsbuild/plugin-babel": "0.
|
|
35
|
-
"@scripts/test-helper": "0.
|
|
33
|
+
"@rsbuild/core": "1.0.0-alpha.0",
|
|
34
|
+
"@rsbuild/plugin-babel": "1.0.0-alpha.0",
|
|
35
|
+
"@scripts/test-helper": "1.0.0-alpha.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@rsbuild/core": "^0.
|
|
38
|
+
"@rsbuild/core": "^1.0.0-alpha.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public",
|