@rsbuild/plugin-source-build 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +29 -22
- package/dist/index.mjs +28 -20
- package/package.json +5 -6
package/dist/index.js
CHANGED
|
@@ -53,14 +53,13 @@ function pluginSourceBuild(options) {
|
|
|
53
53
|
projectName,
|
|
54
54
|
sourceField = "source",
|
|
55
55
|
extraMonorepoStrategies
|
|
56
|
-
} = options
|
|
56
|
+
} = options ?? {};
|
|
57
57
|
return {
|
|
58
58
|
name: pluginName,
|
|
59
59
|
setup(api) {
|
|
60
60
|
const projectRootPath = api.context.rootPath;
|
|
61
61
|
let projects = [];
|
|
62
62
|
api.modifyRsbuildConfig(async (config) => {
|
|
63
|
-
var _a, _b;
|
|
64
63
|
projects = await (0, import_monorepo_utils.getDependentProjects)(projectName || projectRootPath, {
|
|
65
64
|
cwd: projectRootPath,
|
|
66
65
|
recursive: true,
|
|
@@ -71,30 +70,38 @@ function pluginSourceBuild(options) {
|
|
|
71
70
|
projects,
|
|
72
71
|
sourceField
|
|
73
72
|
});
|
|
74
|
-
config.source =
|
|
75
|
-
config.source.include = [...
|
|
73
|
+
config.source = config.source ?? {};
|
|
74
|
+
config.source.include = [...config.source.include ?? [], ...includes];
|
|
76
75
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.merge({
|
|
85
|
-
conditionNames: ["...", sourceField]
|
|
86
|
-
});
|
|
87
|
-
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
88
|
-
if (chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
|
|
89
|
-
chain.resolve.plugin(TS_CONFIG_PATHS).tap((options2) => {
|
|
90
|
-
const references = projects.map((project) => import_path.default.join(project.dir, import_shared.TS_CONFIG_FILE)).filter((filePath) => import_fs.default.existsSync(filePath));
|
|
91
|
-
return options2.map((option) => ({
|
|
92
|
-
...option,
|
|
93
|
-
references
|
|
94
|
-
}));
|
|
76
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
77
|
+
[CHAIN_ID.RULE.TS, CHAIN_ID.RULE.JS].forEach((ruleId) => {
|
|
78
|
+
if (chain.module.rules.get(ruleId)) {
|
|
79
|
+
const rule = chain.module.rule(ruleId);
|
|
80
|
+
rule.resolve.mainFields.merge([sourceField, "..."]);
|
|
81
|
+
rule.resolve.merge({
|
|
82
|
+
conditionNames: ["...", sourceField]
|
|
95
83
|
});
|
|
96
84
|
}
|
|
97
85
|
});
|
|
86
|
+
});
|
|
87
|
+
const getReferences = () => projects.map((project) => import_path.default.join(project.dir, import_shared.TS_CONFIG_FILE)).filter((filePath) => import_fs.default.existsSync(filePath));
|
|
88
|
+
if (api.context.bundlerType === "rspack") {
|
|
89
|
+
api.modifyRspackConfig((config) => {
|
|
90
|
+
(0, import_shared.setConfig)(config, "resolve.tsConfig.references", getReferences());
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
94
|
+
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
95
|
+
if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
chain.resolve.plugin(TS_CONFIG_PATHS).tap(
|
|
99
|
+
(options2) => options2.map((option) => ({
|
|
100
|
+
...option,
|
|
101
|
+
references: getReferences()
|
|
102
|
+
}))
|
|
103
|
+
);
|
|
104
|
+
});
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
107
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
|
-
// ../../scripts/
|
|
5
|
+
// ../../scripts/requireShims.js
|
|
6
6
|
import { createRequire } from "module";
|
|
7
7
|
global.require = createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import fs from "fs";
|
|
11
11
|
import path2 from "path";
|
|
12
|
-
import { TS_CONFIG_FILE } from "@rsbuild/shared";
|
|
12
|
+
import { setConfig, TS_CONFIG_FILE } from "@rsbuild/shared";
|
|
13
13
|
import {
|
|
14
14
|
filterByField,
|
|
15
15
|
getDependentProjects
|
|
@@ -48,27 +48,35 @@ function pluginSourceBuild(options) {
|
|
|
48
48
|
config.source = config.source ?? {};
|
|
49
49
|
config.source.include = [...config.source.include ?? [], ...includes];
|
|
50
50
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.merge({
|
|
59
|
-
conditionNames: ["...", sourceField]
|
|
60
|
-
});
|
|
61
|
-
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
62
|
-
if (chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
|
|
63
|
-
chain.resolve.plugin(TS_CONFIG_PATHS).tap((options2) => {
|
|
64
|
-
const references = projects.map((project) => path2.join(project.dir, TS_CONFIG_FILE)).filter((filePath) => fs.existsSync(filePath));
|
|
65
|
-
return options2.map((option) => ({
|
|
66
|
-
...option,
|
|
67
|
-
references
|
|
68
|
-
}));
|
|
51
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
52
|
+
[CHAIN_ID.RULE.TS, CHAIN_ID.RULE.JS].forEach((ruleId) => {
|
|
53
|
+
if (chain.module.rules.get(ruleId)) {
|
|
54
|
+
const rule = chain.module.rule(ruleId);
|
|
55
|
+
rule.resolve.mainFields.merge([sourceField, "..."]);
|
|
56
|
+
rule.resolve.merge({
|
|
57
|
+
conditionNames: ["...", sourceField]
|
|
69
58
|
});
|
|
70
59
|
}
|
|
71
60
|
});
|
|
61
|
+
});
|
|
62
|
+
const getReferences = () => projects.map((project) => path2.join(project.dir, TS_CONFIG_FILE)).filter((filePath) => fs.existsSync(filePath));
|
|
63
|
+
if (api.context.bundlerType === "rspack") {
|
|
64
|
+
api.modifyRspackConfig((config) => {
|
|
65
|
+
setConfig(config, "resolve.tsConfig.references", getReferences());
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
69
|
+
const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
|
|
70
|
+
if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
chain.resolve.plugin(TS_CONFIG_PATHS).tap(
|
|
74
|
+
(options2) => options2.map((option) => ({
|
|
75
|
+
...option,
|
|
76
|
+
references: getReferences()
|
|
77
|
+
}))
|
|
78
|
+
);
|
|
79
|
+
});
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
82
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-source-build",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Source build plugin of Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -22,15 +22,14 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@rsbuild/monorepo-utils": "0.1.
|
|
26
|
-
"@rsbuild/shared": "0.1.
|
|
25
|
+
"@rsbuild/monorepo-utils": "0.1.3",
|
|
26
|
+
"@rsbuild/shared": "0.1.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/core": "^7.23.2",
|
|
30
30
|
"typescript": "^5.3.0",
|
|
31
|
-
"@rsbuild/
|
|
32
|
-
"@rsbuild/
|
|
33
|
-
"@rsbuild/webpack": "0.1.1"
|
|
31
|
+
"@rsbuild/test-helper": "0.1.3",
|
|
32
|
+
"@rsbuild/core": "0.1.3"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"@rsbuild/core": "0.x"
|