@umijs/preset-umi 4.0.14 → 4.0.17

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.
@@ -0,0 +1,107 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
16
+
17
+ // src/commands/dev/depBuildWorker/depBuildWorker.ts
18
+ var import_bundler_webpack = require("@umijs/bundler-webpack");
19
+ var import_constants = require("@umijs/bundler-webpack/dist/constants");
20
+ var import_types = require("@umijs/bundler-webpack/dist/types");
21
+ var import_mfsu = require("@umijs/mfsu");
22
+ var import_utils = require("@umijs/utils");
23
+ var import_path = require("path");
24
+ var import_worker_threads = require("worker_threads");
25
+ var import_depBuilder = require("./depBuilder");
26
+ var import_getConfig = require("./getConfig");
27
+ if (import_worker_threads.isMainThread) {
28
+ throw Error("MFSU-eager builder can only be called in a worker thread");
29
+ }
30
+ var bundlerWebpackPath = (0, import_path.dirname)(require.resolve("@umijs/bundler-webpack"));
31
+ var bufferedRequest = [];
32
+ async function start() {
33
+ var _a, _b, _c, _d, _e, _f, _g;
34
+ let builder = null;
35
+ function build(deps) {
36
+ import_utils.logger.info("[MFSU][eager] build worker start to build");
37
+ return builder.build({ deps }).catch((e) => {
38
+ import_utils.logger.error("[MFSU][eager] build worker failed", e);
39
+ import_worker_threads.parentPort.postMessage({ error: e });
40
+ });
41
+ }
42
+ function scheduleBuild() {
43
+ if (builder && !builder.isBuilding) {
44
+ const buildReq = bufferedRequest.shift();
45
+ if (buildReq) {
46
+ build(buildReq).finally(() => {
47
+ scheduleBuild();
48
+ });
49
+ }
50
+ }
51
+ }
52
+ import_worker_threads.parentPort.on("message", (buildReq) => {
53
+ bufferedRequest.push(buildReq);
54
+ scheduleBuild();
55
+ });
56
+ const start2 = Date.now();
57
+ const opts = await (0, import_getConfig.getDevConfig)();
58
+ const cacheDirectoryPath = (0, import_path.resolve)(opts.rootDir || opts.cwd, opts.config.cacheDirectoryPath || "node_modules/.cache");
59
+ const depConfig = await (0, import_bundler_webpack.getConfig)({
60
+ cwd: opts.cwd,
61
+ rootDir: opts.rootDir,
62
+ env: import_types.Env.development,
63
+ entry: opts.entry,
64
+ userConfig: opts.config,
65
+ hash: true,
66
+ staticPathPrefix: import_mfsu.MF_DEP_PREFIX,
67
+ name: import_constants.MFSU_NAME,
68
+ chainWebpack: (_a = opts.config.mfsu) == null ? void 0 : _a.chainWebpack,
69
+ extraBabelIncludes: opts.config.extraBabelIncludes,
70
+ cache: {
71
+ buildDependencies: (_b = opts.cache) == null ? void 0 : _b.buildDependencies,
72
+ cacheDirectory: (0, import_path.join)(cacheDirectoryPath, "mfsu-deps")
73
+ },
74
+ pkg: opts.pkg
75
+ });
76
+ (_c = depConfig.resolve).alias || (_c.alias = {});
77
+ ["@umijs/utils/compiled/strip-ansi", "react-error-overlay"].forEach((dep) => {
78
+ depConfig.resolve.alias[dep] = require.resolve(dep, {
79
+ paths: [bundlerWebpackPath]
80
+ });
81
+ });
82
+ const depEsBuildConfig = {
83
+ extraPostCSSPlugins: ((_d = opts.config) == null ? void 0 : _d.extraPostCSSPlugins) || []
84
+ };
85
+ const tmpBase = ((_e = opts.config.mfsu) == null ? void 0 : _e.cacheDirectory) || (0, import_path.join)(cacheDirectoryPath, "mfsu");
86
+ const externals = makeArray(opts.config.externals || []);
87
+ builder = new import_depBuilder.DepBuilderInWorker({
88
+ depConfig,
89
+ cwd: opts.cwd,
90
+ tmpBase,
91
+ mfName: ((_f = opts.config.mfsu) == null ? void 0 : _f.mfName) || import_mfsu.DEFAULT_MF_NAME,
92
+ shared: ((_g = opts.config.mfsu) == null ? void 0 : _g.shared) || {},
93
+ buildDepWithESBuild: false,
94
+ depEsBuildConfig,
95
+ externals
96
+ });
97
+ import_utils.logger.info("[MFSU][eager] worker init, takes", Date.now() - start2);
98
+ scheduleBuild();
99
+ }
100
+ start().catch((e) => {
101
+ import_utils.logger.error("[MFSU][eager] build worker start failed", e);
102
+ });
103
+ function makeArray(a) {
104
+ if (Array.isArray(a))
105
+ return a;
106
+ return [a];
107
+ }
@@ -0,0 +1,37 @@
1
+ import webpack from '@umijs/bundler-webpack/compiled/webpack';
2
+ import { Dep } from '@umijs/mfsu/dist/dep/dep';
3
+ declare type IOpts = {
4
+ depConfig: webpack.Configuration;
5
+ cwd: string;
6
+ tmpBase: string;
7
+ mfName: string;
8
+ shared: any;
9
+ buildDepWithESBuild: boolean;
10
+ depEsBuildConfig: any;
11
+ externals: any[];
12
+ };
13
+ export declare class DepBuilderInWorker {
14
+ completeFns: Function[];
15
+ isBuilding: boolean;
16
+ opts: IOpts;
17
+ constructor(opts: IOpts);
18
+ buildWithWebpack(opts: {
19
+ onBuildComplete: Function;
20
+ deps: Dep[];
21
+ }): Promise<unknown>;
22
+ buildWithESBuild(opts: {
23
+ onBuildComplete: Function;
24
+ deps: Dep[];
25
+ }): Promise<void>;
26
+ build(opts: {
27
+ deps: Dep[];
28
+ }): Promise<void>;
29
+ onBuildComplete(fn: Function): void;
30
+ writeMFFiles(opts: {
31
+ deps: Dep[];
32
+ }): Promise<void>;
33
+ getWebpackConfig(opts: {
34
+ deps: Dep[];
35
+ }): webpack.Configuration;
36
+ }
37
+ export {};
@@ -0,0 +1,210 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // src/commands/dev/depBuildWorker/depBuilder.ts
40
+ var depBuilder_exports = {};
41
+ __export(depBuilder_exports, {
42
+ DepBuilderInWorker: () => DepBuilderInWorker
43
+ });
44
+ module.exports = __toCommonJS(depBuilder_exports);
45
+ var import_bundler_esbuild = require("@umijs/bundler-esbuild");
46
+ var import_webpack = __toESM(require("@umijs/bundler-webpack/compiled/webpack"));
47
+ var import_mfsu = require("@umijs/mfsu");
48
+ var import_dep = require("@umijs/mfsu/dist/dep/dep");
49
+ var import_getESBuildEntry = require("@umijs/mfsu/dist/depBuilder/getESBuildEntry");
50
+ var import_depChunkIdPrefixPlugin = require("@umijs/mfsu/dist/webpackPlugins/depChunkIdPrefixPlugin");
51
+ var import_stripSourceMapUrlPlugin = require("@umijs/mfsu/dist/webpackPlugins/stripSourceMapUrlPlugin");
52
+ var import_utils = require("@umijs/utils");
53
+ var import_fs = require("fs");
54
+ var import_path = require("path");
55
+ var import_worker_threads = require("worker_threads");
56
+ var DepBuilderInWorker = class {
57
+ constructor(opts) {
58
+ this.completeFns = [];
59
+ this.isBuilding = false;
60
+ this.opts = opts;
61
+ }
62
+ async buildWithWebpack(opts) {
63
+ const config = this.getWebpackConfig({ deps: opts.deps });
64
+ return new Promise((resolve, reject) => {
65
+ const compiler = (0, import_webpack.default)(config);
66
+ compiler.run((err, stats) => {
67
+ opts.onBuildComplete();
68
+ if (err || (stats == null ? void 0 : stats.hasErrors())) {
69
+ if (err) {
70
+ reject(err);
71
+ }
72
+ if (stats) {
73
+ const errorMsg = stats.toString("errors-only");
74
+ reject(new Error(errorMsg));
75
+ }
76
+ } else {
77
+ resolve(stats);
78
+ }
79
+ compiler.close(() => {
80
+ });
81
+ });
82
+ });
83
+ }
84
+ async buildWithESBuild(opts) {
85
+ var _a;
86
+ const alias = __spreadValues({}, (_a = this.opts.depConfig.resolve) == null ? void 0 : _a.alias);
87
+ const externals = this.opts.depConfig.externals;
88
+ const entryContent = (0, import_getESBuildEntry.getESBuildEntry)({ deps: opts.deps });
89
+ const ENTRY_FILE = "esbuild-entry.js";
90
+ const tmpDir = this.opts.tmpBase;
91
+ const entryPath = (0, import_path.join)(tmpDir, ENTRY_FILE);
92
+ (0, import_fs.writeFileSync)(entryPath, entryContent, "utf-8");
93
+ const date = new Date().getTime();
94
+ await (0, import_bundler_esbuild.build)({
95
+ cwd: this.opts.cwd,
96
+ entry: {
97
+ [`${import_mfsu.MF_VA_PREFIX}remoteEntry`]: entryPath
98
+ },
99
+ config: __spreadProps(__spreadValues({}, this.opts.depEsBuildConfig), {
100
+ outputPath: tmpDir,
101
+ alias,
102
+ externals
103
+ }),
104
+ inlineStyle: true
105
+ });
106
+ import_utils.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
107
+ opts.onBuildComplete();
108
+ }
109
+ async build(opts) {
110
+ this.isBuilding = true;
111
+ const onBuildComplete = () => {
112
+ this.isBuilding = false;
113
+ import_worker_threads.parentPort.postMessage({
114
+ done: true
115
+ });
116
+ };
117
+ try {
118
+ await this.writeMFFiles({ deps: opts.deps.map((d) => new import_dep.Dep(d)) });
119
+ const newOpts = __spreadProps(__spreadValues({}, opts), {
120
+ onBuildComplete
121
+ });
122
+ if (this.opts.buildDepWithESBuild) {
123
+ await this.buildWithESBuild(newOpts);
124
+ } else {
125
+ await this.buildWithWebpack(newOpts);
126
+ }
127
+ } catch (e) {
128
+ onBuildComplete();
129
+ import_worker_threads.parentPort.postMessage({
130
+ error: e
131
+ });
132
+ throw e;
133
+ }
134
+ }
135
+ onBuildComplete(fn) {
136
+ if (this.isBuilding) {
137
+ this.completeFns.push(fn);
138
+ } else {
139
+ fn();
140
+ }
141
+ }
142
+ async writeMFFiles(opts) {
143
+ const tmpBase = this.opts.tmpBase;
144
+ import_utils.fsExtra.mkdirpSync(tmpBase);
145
+ for (const dep of opts.deps) {
146
+ const content = await dep.buildExposeContent();
147
+ (0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, dep.filePath), content, "utf-8");
148
+ }
149
+ (0, import_fs.writeFileSync)((0, import_path.join)(tmpBase, "index.js"), '"\u{1F61B}"', "utf-8");
150
+ }
151
+ getWebpackConfig(opts) {
152
+ var _a, _b;
153
+ const mfName = this.opts.mfName;
154
+ const depConfig = import_utils.lodash.cloneDeep(this.opts.depConfig);
155
+ depConfig.entry = (0, import_path.join)(this.opts.tmpBase, "index.js");
156
+ depConfig.output.path = this.opts.tmpBase;
157
+ depConfig.output.publicPath = "auto";
158
+ depConfig.devtool = false;
159
+ if ((_a = depConfig.output) == null ? void 0 : _a.library)
160
+ delete depConfig.output.library;
161
+ if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget)
162
+ delete depConfig.output.libraryTarget;
163
+ depConfig.optimization || (depConfig.optimization = {});
164
+ depConfig.optimization.splitChunks = {
165
+ chunks: (chunk) => {
166
+ const hasShared = chunk.getModules().some((m) => {
167
+ return m.type === "consume-shared-module" || m.type === "provide-module" || m.type === "provide-shared-module";
168
+ });
169
+ return !hasShared;
170
+ },
171
+ maxInitialRequests: Infinity,
172
+ minSize: 0,
173
+ cacheGroups: {
174
+ vendor: {
175
+ test: /.+/,
176
+ name(_module, _chunks, cacheGroupKey) {
177
+ return `${import_mfsu.MF_DEP_PREFIX}___${cacheGroupKey}`;
178
+ }
179
+ }
180
+ }
181
+ };
182
+ depConfig.plugins = depConfig.plugins || [];
183
+ depConfig.plugins.push(new import_depChunkIdPrefixPlugin.DepChunkIdPrefixPlugin());
184
+ depConfig.plugins.push(new import_stripSourceMapUrlPlugin.StripSourceMapUrlPlugin({
185
+ webpack: import_webpack.default
186
+ }));
187
+ depConfig.plugins.push(new import_webpack.default.ProgressPlugin((percent, msg) => {
188
+ import_worker_threads.parentPort.postMessage({ progress: { percent, status: msg } });
189
+ }));
190
+ const exposes = opts.deps.reduce((memo, dep) => {
191
+ memo[`./${dep.file}`] = (0, import_path.join)(this.opts.tmpBase, dep.filePath);
192
+ return memo;
193
+ }, {});
194
+ depConfig.plugins.push(new import_webpack.default.container.ModuleFederationPlugin({
195
+ library: {
196
+ type: "global",
197
+ name: mfName
198
+ },
199
+ name: mfName,
200
+ filename: import_mfsu.REMOTE_FILE_FULL,
201
+ exposes,
202
+ shared: this.opts.shared || {}
203
+ }));
204
+ return depConfig;
205
+ }
206
+ };
207
+ // Annotate the CommonJS export names for ESM import in node:
208
+ 0 && (module.exports = {
209
+ DepBuilderInWorker
210
+ });
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,124 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // src/commands/dev/depBuildWorker/dev-config.ts
37
+ var dev_config_exports = {};
38
+ __export(dev_config_exports, {
39
+ default: () => dev_config_default
40
+ });
41
+ module.exports = __toCommonJS(dev_config_exports);
42
+ var import_utils = require("@umijs/utils");
43
+ var import_path = require("path");
44
+ var import_getBabelOpts = require("../getBabelOpts");
45
+ var MFSU_EAGER_DEFAULT_INCLUDE = [
46
+ "react",
47
+ "react-error-overlay",
48
+ "react/jsx-dev-runtime",
49
+ "@umijs/utils/compiled/strip-ansi"
50
+ ];
51
+ var dev_config_default = (api) => {
52
+ api.describe({
53
+ enableBy() {
54
+ return api.name === "dev-config";
55
+ },
56
+ key: "dev-config"
57
+ });
58
+ api.registerCommand({
59
+ name: "dev-config",
60
+ description: "dev server for development",
61
+ details: ``,
62
+ async fn() {
63
+ var _a, _b, _c;
64
+ const {
65
+ babelPreset,
66
+ beforeBabelPlugins,
67
+ beforeBabelPresets,
68
+ extraBabelPlugins,
69
+ extraBabelPresets
70
+ } = await (0, import_getBabelOpts.getBabelOpts)({ api });
71
+ const chainWebpack = async (memo, args) => {
72
+ await api.applyPlugins({
73
+ key: "chainWebpack",
74
+ type: api.ApplyPluginsType.modify,
75
+ initialValue: memo,
76
+ args
77
+ });
78
+ };
79
+ const modifyWebpackConfig = async (memo, args) => {
80
+ return await api.applyPlugins({
81
+ key: "modifyWebpackConfig",
82
+ initialValue: memo,
83
+ args
84
+ });
85
+ };
86
+ const entry = await api.applyPlugins({
87
+ key: "modifyEntry",
88
+ initialValue: {
89
+ umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
90
+ }
91
+ });
92
+ const opts = __spreadProps(__spreadValues({
93
+ config: api.config,
94
+ pkg: api.pkg,
95
+ cwd: api.cwd,
96
+ rootDir: process.cwd(),
97
+ entry,
98
+ port: api.appData.port,
99
+ host: api.appData.host,
100
+ ip: api.appData.ip
101
+ }, { babelPreset, chainWebpack, modifyWebpackConfig }), {
102
+ beforeBabelPlugins,
103
+ beforeBabelPresets,
104
+ extraBabelPlugins,
105
+ extraBabelPresets,
106
+ mfsuWithESBuild: (_a = api.config.mfsu) == null ? void 0 : _a.esbuild,
107
+ mfsuStrategy: (_b = api.config.mfsu) == null ? void 0 : _b.strategy,
108
+ cache: {
109
+ buildDependencies: [
110
+ api.pkgPath,
111
+ api.service.configManager.mainConfigFile || ""
112
+ ].filter(Boolean)
113
+ },
114
+ mfsuInclude: import_utils.lodash.union([
115
+ ...MFSU_EAGER_DEFAULT_INCLUDE,
116
+ ...((_c = api.config.mfsu) == null ? void 0 : _c.include) || []
117
+ ])
118
+ });
119
+ return opts;
120
+ }
121
+ });
122
+ };
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {});
@@ -0,0 +1 @@
1
+ export declare function getDevConfig(): Promise<any>;
@@ -0,0 +1,42 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/commands/dev/depBuildWorker/getConfig.ts
23
+ var getConfig_exports = {};
24
+ __export(getConfig_exports, {
25
+ getDevConfig: () => getDevConfig
26
+ });
27
+ module.exports = __toCommonJS(getConfig_exports);
28
+ var import_service = require("umi/dist/service/service");
29
+ async function getDevConfig() {
30
+ const service = new import_service.Service({
31
+ presets: [require.resolve("./workerPreset")]
32
+ });
33
+ const opts = await service.run({
34
+ name: "dev-config",
35
+ args: []
36
+ });
37
+ return opts;
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ getDevConfig
42
+ });
@@ -0,0 +1,4 @@
1
+ declare const _default: () => {
2
+ plugins: string[];
3
+ };
4
+ export default _default;
@@ -0,0 +1,34 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/commands/dev/depBuildWorker/workerPreset.ts
23
+ var workerPreset_exports = {};
24
+ __export(workerPreset_exports, {
25
+ default: () => workerPreset_default
26
+ });
27
+ module.exports = __toCommonJS(workerPreset_exports);
28
+ var workerPreset_default = () => {
29
+ return {
30
+ plugins: [require.resolve("./dev-config")]
31
+ };
32
+ };
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {});
@@ -45,6 +45,7 @@ module.exports = __toCommonJS(dev_exports);
45
45
  var import_utils = require("@umijs/utils");
46
46
  var import_fs = require("fs");
47
47
  var import_path = require("path");
48
+ var import_worker_threads = require("worker_threads");
48
49
  var import_constants = require("../../constants");
49
50
  var import_AutoUpdateSourceCodeCache = require("../../libs/folderCache/AutoUpdateSourceCodeCache");
50
51
  var import_lazyImportFromCurrentPkg = require("../../utils/lazyImportFromCurrentPkg");
@@ -236,6 +237,8 @@ PORT=8888 umi dev
236
237
  };
237
238
  const debouncedPrintMemoryUsage = import_utils.lodash.debounce(import_printMemoryUsage.printMemoryUsage, 5e3);
238
239
  let srcCodeCache;
240
+ let startBuildWorker = () => {
241
+ };
239
242
  if (((_b = api.config.mfsu) == null ? void 0 : _b.strategy) === "eager") {
240
243
  srcCodeCache = new import_AutoUpdateSourceCodeCache.AutoUpdateSrcCodeCache({
241
244
  cwd: api.paths.absSrcPath,
@@ -245,6 +248,18 @@ PORT=8888 umi dev
245
248
  (0, import_watch.addUnWatch)(() => {
246
249
  srcCodeCache.unwatch();
247
250
  });
251
+ let currentWorker = null;
252
+ const initWorker = () => {
253
+ currentWorker = new import_worker_threads.Worker((0, import_path.join)(__dirname, "depBuildWorker/depBuildWorker.js"));
254
+ currentWorker.on("exit", () => {
255
+ initWorker();
256
+ });
257
+ return currentWorker;
258
+ };
259
+ currentWorker = initWorker();
260
+ startBuildWorker = () => {
261
+ return currentWorker;
262
+ };
248
263
  }
249
264
  const entry = await api.applyPlugins({
250
265
  key: "modifyEntry",
@@ -299,7 +314,8 @@ PORT=8888 umi dev
299
314
  mfsuInclude: import_utils.lodash.union([
300
315
  ...MFSU_EAGER_DEFAULT_INCLUDE,
301
316
  ...((_e = api.config.mfsu) == null ? void 0 : _e.include) || []
302
- ])
317
+ ]),
318
+ startBuildWorker
303
319
  });
304
320
  if (api.config.mf) {
305
321
  opts.mfsuServerBase = `${api.config.https ? "https" : "http"}://${api.appData.ip}:${api.appData.port}`;
@@ -66,6 +66,7 @@ var jest_default = (api) => {
66
66
  initial: true
67
67
  });
68
68
  const hasSrc = api.paths.absSrcPath.endsWith("src");
69
+ const importSource = api.appData.umi.importSource;
69
70
  const basicDeps = {
70
71
  jest: "^27",
71
72
  "@types/jest": "^27",
@@ -79,12 +80,12 @@ var jest_default = (api) => {
79
80
  }) : basicDeps;
80
81
  h.addDevDeps(packageToInstall);
81
82
  h.addScript("test", "jest");
82
- if (res.willUseTLR) {
83
- (0, import_fs.writeFileSync)((0, import_path.join)(api.cwd, "jest-setup.ts"), `import '@testing-library/jest-dom';
84
- `.trimLeft());
85
- import_utils.logger.info("Write jest-setup.ts");
86
- }
87
- const importSource = api.appData.umi.importSource;
83
+ const setupImports = res.willUseTLR ? [
84
+ `import '@testing-library/jest-dom';`,
85
+ `import '${api.appData.umi.importSource}/test-setup'`
86
+ ] : [`import '${api.appData.umi.importSource}/test-setup'`];
87
+ (0, import_fs.writeFileSync)((0, import_path.join)(api.cwd, "jest-setup.ts"), setupImports.join("\n"));
88
+ import_utils.logger.info("Write jest-setup.ts");
88
89
  const collectCoverageFrom = hasSrc ? [
89
90
  "src/**/*.{ts,js,tsx,jsx}",
90
91
  "!src/.umi/**",
@@ -115,7 +116,9 @@ export default async () => {
115
116
  jsTransformerOpts: { jsx: 'automatic' },
116
117
  }),
117
118
  ${res.willUseTLR ? `setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],` : ""}
118
- collectCoverageFrom: [${collectCoverageFrom.map((v) => `'${v}'`).join(", ")}],
119
+ collectCoverageFrom: [
120
+ ${collectCoverageFrom.map((v) => ` '${v}'`).join(",\n")}
121
+ ],
119
122
  // if you require some es-module npm package, please uncomment below line and insert your package name
120
123
  // transformIgnorePatterns: ['node_modules/(?!.*(lodash-es|your-es-pkg-name)/)']
121
124
  })) as Config.InitialOptions;
@@ -0,0 +1,5 @@
1
+ import { IApi, IRoute } from '../../types';
2
+ declare type Routes = Record<string, IRoute>;
3
+ export declare function patchRoutes(routes: Routes): Routes;
4
+ declare const _default: (api: IApi) => void;
5
+ export default _default;
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/features/404/404.ts
20
+ var __exports = {};
21
+ __export(__exports, {
22
+ default: () => __default,
23
+ patchRoutes: () => patchRoutes
24
+ });
25
+ module.exports = __toCommonJS(__exports);
26
+ function patchRoutes(routes) {
27
+ Object.keys(routes).forEach((key) => {
28
+ if (routes[key].path === "404") {
29
+ routes[key].path = "*";
30
+ }
31
+ });
32
+ return routes;
33
+ }
34
+ var __default = (api) => {
35
+ api.describe({
36
+ key: "404"
37
+ });
38
+ api.modifyRoutes(async (routes) => {
39
+ if (api.config.routes) {
40
+ return routes;
41
+ }
42
+ return patchRoutes(routes);
43
+ });
44
+ };
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ patchRoutes
48
+ });
@@ -45,7 +45,8 @@ var appData_default = (api) => {
45
45
  memo.umi = {
46
46
  version: require("../../../package.json").version,
47
47
  name: "Umi",
48
- importSource: "umi"
48
+ importSource: "umi",
49
+ cliName: "umi"
49
50
  };
50
51
  memo.bundleStatus = {
51
52
  done: false
@@ -50,7 +50,8 @@ var legacy_default = (api) => {
50
50
  config: {
51
51
  schema(Joi) {
52
52
  return Joi.object({
53
- buildOnly: Joi.boolean()
53
+ buildOnly: Joi.boolean(),
54
+ nodeModulesTransform: Joi.boolean()
54
55
  });
55
56
  }
56
57
  },
@@ -60,7 +61,7 @@ var legacy_default = (api) => {
60
61
  stage: Number.MAX_SAFE_INTEGER,
61
62
  fn: (memo) => {
62
63
  const { userConfig } = api;
63
- const { buildOnly = true } = api.config.legacy || userConfig.legacy || {};
64
+ const { buildOnly = true, nodeModulesTransform = true } = api.config.legacy || userConfig.legacy || {};
64
65
  if (api.env === import_types.Env.development) {
65
66
  if (buildOnly) {
66
67
  return memo;
@@ -82,10 +83,6 @@ var legacy_default = (api) => {
82
83
  memo.targets = __spreadProps(__spreadValues({}, userConfig.targets), {
83
84
  ie: 11
84
85
  });
85
- memo.extraBabelIncludes = [
86
- ...memo.extraBabelIncludes || [],
87
- /node_modules/
88
- ];
89
86
  import_utils.logger.ready(`${import_utils.chalk.cyan("legacy")} mode is enabled, we automatically modify the ${[
90
87
  "srcTranspiler",
91
88
  "jsMinifier",
@@ -96,6 +93,10 @@ var legacy_default = (api) => {
96
93
  if (originChainWebpack) {
97
94
  originChainWebpack(memo2, ...args);
98
95
  }
96
+ if (nodeModulesTransform) {
97
+ memo2.module.rule("extra-src").include.add(/node_modules/).end();
98
+ }
99
+ memo2.module.rule("extra-src").exclude.add(/core-js/).add(/node_modules\/(css-loader)/).end();
99
100
  useBabelTransformSvgr(memo2, api);
100
101
  if (!import_utils.lodash.isEmpty(userConfig.externals)) {
101
102
  const externalsAsString = JSON.stringify(userConfig.externals);
@@ -53,7 +53,10 @@ var mpa_default = (api) => {
53
53
  key: "mpa",
54
54
  config: {
55
55
  schema(Joi) {
56
- return Joi.object({});
56
+ return Joi.object({
57
+ template: Joi.string(),
58
+ getConfigFromEntryFile: Joi.boolean()
59
+ });
57
60
  }
58
61
  },
59
62
  enableBy: api.EnableBy.config
@@ -63,13 +66,13 @@ var mpa_default = (api) => {
63
66
  });
64
67
  api.modifyAppData(async (memo) => {
65
68
  memo.mpa = {
66
- entry: await collectEntryWithTimeCount(api.paths.absPagesPath)
69
+ entry: await collectEntryWithTimeCount(api.paths.absPagesPath, api.config.mpa)
67
70
  };
68
71
  return memo;
69
72
  });
70
73
  api.onGenerateFiles(async ({ isFirstTime }) => {
71
74
  if (!isFirstTime) {
72
- api.appData.mpa.entry = await collectEntryWithTimeCount(api.paths.absPagesPath);
75
+ api.appData.mpa.entry = await collectEntryWithTimeCount(api.paths.absPagesPath, api.config.mpa);
73
76
  }
74
77
  const isReact18 = api.appData.react.version.startsWith("18.");
75
78
  api.appData.mpa.entry.forEach((entry) => {
@@ -118,7 +121,7 @@ ${renderer}
118
121
  {
119
122
  filename: `${entry.name}.html`,
120
123
  minify: false,
121
- template: entry.template ? (0, import_path.resolve)(api.cwd, entry.template) : (0, import_path.join)(api.paths.absTmpPath, "mpa/template.html"),
124
+ template: entry.template ? (0, import_path.resolve)(api.cwd, entry.template) : api.config.mpa.template ? (0, import_path.resolve)(api.cwd, api.config.mpa.template) : (0, import_path.join)(api.paths.absTmpPath, "mpa/template.html"),
122
125
  templateParameters: entry,
123
126
  chunks: [entry.name]
124
127
  }
@@ -127,20 +130,20 @@ ${renderer}
127
130
  return memo;
128
131
  });
129
132
  };
130
- async function collectEntryWithTimeCount(root) {
133
+ async function collectEntryWithTimeCount(root, opts) {
131
134
  const d = new Date();
132
- const entries = await collectEntry(root);
135
+ const entries = await collectEntry(root, opts);
133
136
  import_utils.logger.info(`[MPA] Collect Entries in ${new Date().getTime() - d.getTime()}ms`);
134
137
  return entries;
135
138
  }
136
- async function collectEntry(root) {
139
+ async function collectEntry(root, opts) {
137
140
  return await (0, import_fs.readdirSync)(root).reduce(async (memoP, dir) => {
138
141
  const memo = await memoP;
139
142
  const absDir = (0, import_path.join)(root, dir);
140
143
  if ((0, import_fs.existsSync)(absDir) && (0, import_fs.statSync)(absDir).isDirectory()) {
141
144
  const indexFile = getIndexFile(absDir);
142
145
  if (indexFile) {
143
- const config = await getConfig(indexFile);
146
+ const config = opts.getConfigFromEntryFile ? await getConfigFromEntryFile(indexFile) : await getConfig(indexFile);
144
147
  memo.push(__spreadProps(__spreadValues({
145
148
  name: dir,
146
149
  file: indexFile,
@@ -166,6 +169,16 @@ function getIndexFile(dir) {
166
169
  return null;
167
170
  }
168
171
  async function getConfig(indexFile) {
172
+ const dir = (0, import_path.dirname)(indexFile);
173
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "config.json"))) {
174
+ const config = JSON.parse((0, import_fs.readFileSync)((0, import_path.join)(dir, "config.json"), "utf-8"));
175
+ checkConfig(config);
176
+ return config;
177
+ } else {
178
+ return {};
179
+ }
180
+ }
181
+ async function getConfigFromEntryFile(indexFile) {
169
182
  const config = await (0, import_extractExports.extractExports)({
170
183
  entry: indexFile,
171
184
  exportName: "config"
package/dist/index.js CHANGED
@@ -29,6 +29,8 @@ var src_default = () => {
29
29
  return {
30
30
  plugins: [
31
31
  require.resolve("./registerMethods"),
32
+ require.resolve("@umijs/did-you-know/dist/plugin"),
33
+ require.resolve("./features/404/404"),
32
34
  require.resolve("./features/appData/appData"),
33
35
  require.resolve("./features/check/check"),
34
36
  require.resolve("./features/clientLoader/clientLoader"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.14",
3
+ "version": "4.0.17",
4
4
  "description": "@umijs/preset-umi",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/preset-umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -26,16 +26,18 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@types/multer": "1.4.7",
29
- "@umijs/ast": "4.0.14",
30
- "@umijs/babel-preset-umi": "4.0.14",
31
- "@umijs/bundler-utils": "4.0.14",
32
- "@umijs/bundler-vite": "4.0.14",
33
- "@umijs/bundler-webpack": "4.0.14",
34
- "@umijs/core": "4.0.14",
35
- "@umijs/plugin-run": "4.0.14",
36
- "@umijs/renderer-react": "4.0.14",
37
- "@umijs/server": "4.0.14",
38
- "@umijs/utils": "4.0.14",
29
+ "@umijs/ast": "4.0.17",
30
+ "@umijs/babel-preset-umi": "4.0.17",
31
+ "@umijs/bundler-utils": "4.0.17",
32
+ "@umijs/bundler-vite": "4.0.17",
33
+ "@umijs/bundler-webpack": "4.0.17",
34
+ "@umijs/core": "4.0.17",
35
+ "@umijs/did-you-know": "^1.0.0",
36
+ "@umijs/mfsu": "4.0.17",
37
+ "@umijs/plugin-run": "4.0.17",
38
+ "@umijs/renderer-react": "4.0.17",
39
+ "@umijs/server": "4.0.17",
40
+ "@umijs/utils": "4.0.17",
39
41
  "click-to-react-component": "^1.0.8",
40
42
  "core-js": "3.22.4",
41
43
  "current-script-polyfill": "1.0.0",