@modern-js/builder 2.25.1 → 2.26.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/CHANGELOG.md +34 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/sourceBuild.d.ts +23 -0
- package/dist/plugins/sourceBuild.js +121 -0
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @modern-js/builder
|
|
2
2
|
|
|
3
|
+
## 2.26.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e26b05e: feat(builder): rename source field and add rule.resolve.mainFields and rule.resolve.conditionNames configuration
|
|
8
|
+
feat(builder): 重命名 source 字段,增加 rule.resolve.mainFields 和 rule.resolve.conditionName 配置
|
|
9
|
+
- 786c195: feat(builder): New builder plug-in to support source code building
|
|
10
|
+
feat(builder): 新增支持源码构建的 builder 插件
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- b36ece4: fix: rename source field name
|
|
15
|
+
fix: 重新命名源码字段
|
|
16
|
+
- Updated dependencies [150ddb1]
|
|
17
|
+
- Updated dependencies [786c195]
|
|
18
|
+
- Updated dependencies [b36ece4]
|
|
19
|
+
- Updated dependencies [15ad760]
|
|
20
|
+
- Updated dependencies [786c195]
|
|
21
|
+
- @modern-js/builder-shared@2.26.0
|
|
22
|
+
- @modern-js/monorepo-utils@2.26.0
|
|
23
|
+
- @modern-js/utils@2.26.0
|
|
24
|
+
|
|
25
|
+
## 2.25.2
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [63d8247]
|
|
30
|
+
- Updated dependencies [6651684]
|
|
31
|
+
- Updated dependencies [15a8276]
|
|
32
|
+
- Updated dependencies [272646c]
|
|
33
|
+
- Updated dependencies [358ed24]
|
|
34
|
+
- @modern-js/utils@2.25.2
|
|
35
|
+
- @modern-js/builder-shared@2.25.2
|
|
36
|
+
|
|
3
37
|
## 2.25.1
|
|
4
38
|
|
|
5
39
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { createBuilder } from './createBuilder';
|
|
2
2
|
export { mergeBuilderConfig } from '@modern-js/builder-shared';
|
|
3
|
+
export { builderPluginSourceBuild } from './plugins/sourceBuild';
|
|
3
4
|
export type { BuilderMode, BuilderEntry, BuilderTarget, BuilderPlugin, BuilderContext, BuilderInstance, CreateBuilderOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, ModifyBuilderConfigFn, } from '@modern-js/builder-shared';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeBuilderConfig = exports.createBuilder = void 0;
|
|
3
|
+
exports.builderPluginSourceBuild = exports.mergeBuilderConfig = exports.createBuilder = void 0;
|
|
4
4
|
var createBuilder_1 = require("./createBuilder");
|
|
5
5
|
Object.defineProperty(exports, "createBuilder", { enumerable: true, get: function () { return createBuilder_1.createBuilder; } });
|
|
6
6
|
var builder_shared_1 = require("@modern-js/builder-shared");
|
|
7
7
|
Object.defineProperty(exports, "mergeBuilderConfig", { enumerable: true, get: function () { return builder_shared_1.mergeBuilderConfig; } });
|
|
8
|
+
var sourceBuild_1 = require("./plugins/sourceBuild");
|
|
9
|
+
Object.defineProperty(exports, "builderPluginSourceBuild", { enumerable: true, get: function () { return sourceBuild_1.builderPluginSourceBuild; } });
|
package/dist/plugins/index.js
CHANGED
|
@@ -52,4 +52,5 @@ exports.plugins = {
|
|
|
52
52
|
wasm: () => Promise.resolve().then(() => __importStar(require('./wasm'))).then(m => m.builderPluginWasm()),
|
|
53
53
|
moment: () => Promise.resolve().then(() => __importStar(require('./moment'))).then(m => m.builderPluginMoment()),
|
|
54
54
|
externals: () => Promise.resolve().then(() => __importStar(require('./externals'))).then(m => m.builderPluginExternals()),
|
|
55
|
+
sourceBuild: () => Promise.resolve().then(() => __importStar(require('./sourceBuild'))).then(m => m.builderPluginSourceBuild({ sourceField: 'source' })),
|
|
55
56
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BuilderPlugin } from '@modern-js/builder-shared';
|
|
2
|
+
import type { BuilderPluginAPI as WebpackBuilderPluginAPI } from '@modern-js/builder-webpack-provider';
|
|
3
|
+
import type { BuilderPluginAPI as RspackBuilderPluginAPI } from '@modern-js/builder-rspack-provider';
|
|
4
|
+
import { type ExtraMonorepoStrategies } from '@modern-js/monorepo-utils';
|
|
5
|
+
export declare const pluginName = "builder-plugin-source-build";
|
|
6
|
+
export declare const getSourceInclude: (options: {
|
|
7
|
+
projectNameOrRootPath: string;
|
|
8
|
+
findMonorepoStartPath: string;
|
|
9
|
+
sourceField: string;
|
|
10
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
11
|
+
}) => Promise<string[]>;
|
|
12
|
+
export declare const sourceBuildInWebpack: (api: WebpackBuilderPluginAPI, options: {
|
|
13
|
+
sourceField: string;
|
|
14
|
+
projectRootPath: string;
|
|
15
|
+
projectName?: string;
|
|
16
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
17
|
+
}) => void;
|
|
18
|
+
export interface PluginSourceBuildOptions {
|
|
19
|
+
projectName?: string;
|
|
20
|
+
sourceField?: string;
|
|
21
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
22
|
+
}
|
|
23
|
+
export declare function builderPluginSourceBuild(options?: PluginSourceBuildOptions): BuilderPlugin<WebpackBuilderPluginAPI | RspackBuilderPluginAPI>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.builderPluginSourceBuild = exports.sourceBuildInWebpack = exports.getSourceInclude = exports.pluginName = void 0;
|
|
4
|
+
const monorepo_utils_1 = require("@modern-js/monorepo-utils");
|
|
5
|
+
exports.pluginName = 'builder-plugin-source-build';
|
|
6
|
+
const getSourceInclude = async (options) => {
|
|
7
|
+
const { projectNameOrRootPath, sourceField, extraMonorepoStrategies, findMonorepoStartPath, } = options;
|
|
8
|
+
const projects = await (0, monorepo_utils_1.getDependentProjects)(projectNameOrRootPath, {
|
|
9
|
+
cwd: findMonorepoStartPath,
|
|
10
|
+
recursive: true,
|
|
11
|
+
filter: (0, monorepo_utils_1.filterByField)(sourceField),
|
|
12
|
+
extraMonorepoStrategies,
|
|
13
|
+
});
|
|
14
|
+
const includes = [];
|
|
15
|
+
for (const project of projects) {
|
|
16
|
+
includes.push(...project.getSourceEntryPaths({ field: sourceField }));
|
|
17
|
+
}
|
|
18
|
+
return includes;
|
|
19
|
+
};
|
|
20
|
+
exports.getSourceInclude = getSourceInclude;
|
|
21
|
+
const sourceBuildInWebpack = (api, options) => {
|
|
22
|
+
const { sourceField, projectRootPath, projectName, extraMonorepoStrategies } = options;
|
|
23
|
+
api.modifyBuilderConfig(async (config) => {
|
|
24
|
+
var _a, _b, _c;
|
|
25
|
+
const { sourceBuild = true } = (_a = config.experiments) !== null && _a !== void 0 ? _a : {};
|
|
26
|
+
if (!sourceBuild) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const includes = await (0, exports.getSourceInclude)({
|
|
30
|
+
projectNameOrRootPath: projectName || projectRootPath,
|
|
31
|
+
sourceField,
|
|
32
|
+
findMonorepoStartPath: projectRootPath,
|
|
33
|
+
extraMonorepoStrategies,
|
|
34
|
+
});
|
|
35
|
+
config.source = (_b = config.source) !== null && _b !== void 0 ? _b : {};
|
|
36
|
+
config.source.include = [...((_c = config.source.include) !== null && _c !== void 0 ? _c : []), ...includes];
|
|
37
|
+
});
|
|
38
|
+
api.modifyBundlerChain(chain => {
|
|
39
|
+
const { experiments: { sourceBuild }, } = api.getNormalizedConfig();
|
|
40
|
+
if (!sourceBuild) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Now not support chain.resolve.conditionNames API
|
|
44
|
+
// chain.resolve.conditionNames.prepend(sourcePkgField);
|
|
45
|
+
// when user not config source.resolveMainFields, mainFields is empty array
|
|
46
|
+
if (chain.resolve.mainFields.values().length === 0) {
|
|
47
|
+
// "..." is special syntax,it will retain the original value
|
|
48
|
+
chain.resolve.mainFields.prepend('...');
|
|
49
|
+
chain.resolve.mainFields.prepend(sourceField);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
api.modifyWebpackConfig(async (config) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const { experiments: { sourceBuild }, } = api.getNormalizedConfig();
|
|
55
|
+
if (!sourceBuild) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
config.resolve = (_a = config.resolve) !== null && _a !== void 0 ? _a : {};
|
|
59
|
+
config.resolve.conditionNames = [
|
|
60
|
+
'...',
|
|
61
|
+
sourceField,
|
|
62
|
+
...((_b = config.resolve.conditionNames) !== null && _b !== void 0 ? _b : []),
|
|
63
|
+
];
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
exports.sourceBuildInWebpack = sourceBuildInWebpack;
|
|
67
|
+
function builderPluginSourceBuild(options) {
|
|
68
|
+
const { projectName, sourceField = 'source', extraMonorepoStrategies, } = options !== null && options !== void 0 ? options : {};
|
|
69
|
+
return {
|
|
70
|
+
name: exports.pluginName,
|
|
71
|
+
async setup(api) {
|
|
72
|
+
const projectRootPath = api.context.rootPath;
|
|
73
|
+
// TODO: when rspack support tsconfig paths functionality, this comment will remove
|
|
74
|
+
// if (api.context.bundlerType === 'rspack') {
|
|
75
|
+
// (api as RspackBuilderPluginAPI).modifyRspackConfig(async config => {
|
|
76
|
+
// // when support chain.resolve.conditionNames API, remove this logic
|
|
77
|
+
// setConfig(config, 'resolve.conditionNames', [
|
|
78
|
+
// '...', // Special syntax: retain the original value
|
|
79
|
+
// sourceField,
|
|
80
|
+
// ...(config.resolve?.conditionNames ?? []),
|
|
81
|
+
// ]);
|
|
82
|
+
// });
|
|
83
|
+
// }
|
|
84
|
+
if (api.context.bundlerType === 'webpack') {
|
|
85
|
+
api.modifyBuilderConfig(async (config) => {
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
const { sourceBuild = true } = (_a = config.experiments) !== null && _a !== void 0 ? _a : {};
|
|
88
|
+
if (!sourceBuild) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const includes = await (0, exports.getSourceInclude)({
|
|
92
|
+
projectNameOrRootPath: projectName || projectRootPath,
|
|
93
|
+
sourceField,
|
|
94
|
+
findMonorepoStartPath: projectRootPath,
|
|
95
|
+
extraMonorepoStrategies,
|
|
96
|
+
});
|
|
97
|
+
config.source = (_b = config.source) !== null && _b !== void 0 ? _b : {};
|
|
98
|
+
config.source.include = [
|
|
99
|
+
...((_c = config.source.include) !== null && _c !== void 0 ? _c : []),
|
|
100
|
+
...includes,
|
|
101
|
+
];
|
|
102
|
+
});
|
|
103
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
104
|
+
const { experiments: { sourceBuild }, } = api.getNormalizedConfig();
|
|
105
|
+
if (!sourceBuild) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// webpack.js.org/configuration/module/#ruleresolve
|
|
109
|
+
chain.module
|
|
110
|
+
.rule(CHAIN_ID.RULE.JS)
|
|
111
|
+
.resolve.mainFields.merge(['...', sourceField]);
|
|
112
|
+
// webpack chain not support resolve.conditionNames
|
|
113
|
+
chain.module.rule(CHAIN_ID.RULE.JS).resolve.merge({
|
|
114
|
+
conditionNames: ['...', sourceField],
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.builderPluginSourceBuild = builderPluginSourceBuild;
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=14.0.0"
|
|
20
20
|
},
|
|
21
|
-
"version": "2.
|
|
21
|
+
"version": "2.26.0",
|
|
22
22
|
"jsnext:source": "./src/index.ts",
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"main": "./dist/index.js",
|
|
@@ -31,14 +31,17 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@svgr/webpack": "8.0.1",
|
|
34
|
-
"@modern-js/builder-shared": "2.
|
|
35
|
-
"@modern-js/utils": "2.
|
|
34
|
+
"@modern-js/builder-shared": "2.26.0",
|
|
35
|
+
"@modern-js/monorepo-utils": "2.26.0",
|
|
36
|
+
"@modern-js/utils": "2.26.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/babel__core": "^7.20.0",
|
|
39
40
|
"@types/node": "^14",
|
|
40
41
|
"typescript": "^5",
|
|
41
|
-
"@
|
|
42
|
+
"@modern-js/builder-webpack-provider": "2.26.0",
|
|
43
|
+
"@modern-js/builder-rspack-provider": "2.26.0",
|
|
44
|
+
"@scripts/vitest-config": "2.26.0"
|
|
42
45
|
},
|
|
43
46
|
"publishConfig": {
|
|
44
47
|
"registry": "https://registry.npmjs.org/",
|