@umijs/mfsu 4.0.0-canary.20220318.1 → 4.0.0-canary.20220412.1
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/dep/dep.js +2 -3
- package/dist/depBuilder/depBuilder.js +20 -10
- package/dist/depInfo.d.ts +1 -1
- package/dist/depInfo.js +10 -5
- package/dist/mfsu.d.ts +6 -3
- package/dist/mfsu.js +42 -15
- package/package.json +5 -5
- package/dist/babelPlugins/autoExport.d.ts +0 -7
- package/dist/babelPlugins/autoExport.js +0 -65
- package/dist/esbuildHandlers/autoExport.d.ts +0 -6
- package/dist/esbuildHandlers/autoExport.js +0 -9
package/dist/dep/dep.js
CHANGED
|
@@ -24,9 +24,8 @@ const getExposeFromContent_1 = require("./getExposeFromContent");
|
|
|
24
24
|
const resolver = enhanced_resolve_1.default.create({
|
|
25
25
|
mainFields: ['module', 'browser', 'main'],
|
|
26
26
|
extensions: ['.js', '.json', '.mjs'],
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
exportsFields: [],
|
|
27
|
+
exportsFields: ['exports'],
|
|
28
|
+
conditionNames: ['import', 'module', 'require', 'node'],
|
|
30
29
|
});
|
|
31
30
|
function resolve(context, path) {
|
|
32
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -73,17 +73,24 @@ class DepBuilder {
|
|
|
73
73
|
build(opts) {
|
|
74
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
75
|
this.isBuilding = true;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
const onBuildComplete = () => {
|
|
77
|
+
this.isBuilding = false;
|
|
78
|
+
this.completeFns.forEach((fn) => fn());
|
|
79
|
+
this.completeFns = [];
|
|
80
|
+
};
|
|
81
|
+
try {
|
|
82
|
+
yield this.writeMFFiles({ deps: opts.deps });
|
|
83
|
+
const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete });
|
|
84
|
+
if (this.opts.mfsu.opts.buildDepWithESBuild) {
|
|
85
|
+
yield this.buildWithESBuild(newOpts);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
yield this.buildWithWebpack(newOpts);
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
catch (e) {
|
|
92
|
+
onBuildComplete();
|
|
93
|
+
throw e;
|
|
87
94
|
}
|
|
88
95
|
});
|
|
89
96
|
}
|
|
@@ -144,6 +151,9 @@ class DepBuilder {
|
|
|
144
151
|
depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
|
|
145
152
|
webpack: this.opts.mfsu.opts.implementor,
|
|
146
153
|
}));
|
|
154
|
+
depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
|
|
155
|
+
this.opts.mfsu.onProgress({ percent, status: msg });
|
|
156
|
+
}));
|
|
147
157
|
const exposes = opts.deps.reduce((memo, dep) => {
|
|
148
158
|
memo[`./${dep.file}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
|
|
149
159
|
return memo;
|
package/dist/depInfo.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class DepInfo {
|
|
|
9
9
|
moduleGraph: ModuleGraph;
|
|
10
10
|
cacheDependency: object;
|
|
11
11
|
constructor(opts: IOpts);
|
|
12
|
-
shouldBuild():
|
|
12
|
+
shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
|
|
13
13
|
snapshot(): void;
|
|
14
14
|
loadCache(): void;
|
|
15
15
|
writeCache(): void;
|
package/dist/depInfo.js
CHANGED
|
@@ -14,10 +14,10 @@ class DepInfo {
|
|
|
14
14
|
}
|
|
15
15
|
shouldBuild() {
|
|
16
16
|
if (!utils_1.lodash.isEqual(this.cacheDependency, this.opts.mfsu.opts.getCacheDependency())) {
|
|
17
|
-
return
|
|
17
|
+
return 'cacheDependency has changed';
|
|
18
18
|
}
|
|
19
19
|
if (this.moduleGraph.hasDepChanged()) {
|
|
20
|
-
return
|
|
20
|
+
return 'moduleGraph has changed';
|
|
21
21
|
}
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
@@ -35,11 +35,16 @@ class DepInfo {
|
|
|
35
35
|
}
|
|
36
36
|
writeCache() {
|
|
37
37
|
utils_1.fsExtra.mkdirpSync((0, path_1.dirname)(this.cacheFilePath));
|
|
38
|
-
|
|
39
|
-
(0, fs_1.writeFileSync)(this.cacheFilePath, JSON.stringify({
|
|
38
|
+
const newContent = JSON.stringify({
|
|
40
39
|
cacheDependency: this.cacheDependency,
|
|
41
40
|
moduleGraph: this.moduleGraph.toJSON(),
|
|
42
|
-
}, null, 2)
|
|
41
|
+
}, null, 2);
|
|
42
|
+
if ((0, fs_1.existsSync)(this.cacheFilePath) &&
|
|
43
|
+
(0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8') === newContent) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
utils_1.logger.info('MFSU write cache');
|
|
47
|
+
(0, fs_1.writeFileSync)(this.cacheFilePath, newContent, 'utf-8');
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
exports.DepInfo = DepInfo;
|
package/dist/mfsu.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from '@umijs/bundler-utils/compiled/express';
|
|
2
2
|
import webpack, { Configuration } from 'webpack';
|
|
3
|
-
import autoExport from './babelPlugins/autoExport';
|
|
4
3
|
import awaitImport from './babelPlugins/awaitImport/awaitImport';
|
|
5
4
|
import { DepBuilder } from './depBuilder/depBuilder';
|
|
6
5
|
import { DepInfo } from './depInfo';
|
|
@@ -10,6 +9,7 @@ interface IOpts {
|
|
|
10
9
|
excludeNodeNatives?: boolean;
|
|
11
10
|
exportAllMembers?: Record<string, string[]>;
|
|
12
11
|
getCacheDependency?: Function;
|
|
12
|
+
onMFSUProgress?: Function;
|
|
13
13
|
mfName?: string;
|
|
14
14
|
mode?: Mode;
|
|
15
15
|
tmpBase?: string;
|
|
@@ -26,6 +26,9 @@ export declare class MFSU {
|
|
|
26
26
|
depInfo: DepInfo;
|
|
27
27
|
depBuilder: DepBuilder;
|
|
28
28
|
depConfig: Configuration | null;
|
|
29
|
+
buildDepsAgain: boolean;
|
|
30
|
+
progress: any;
|
|
31
|
+
onProgress: Function;
|
|
29
32
|
constructor(opts: IOpts);
|
|
30
33
|
asyncImport(content: string): string;
|
|
31
34
|
setWebpackConfig(opts: {
|
|
@@ -35,7 +38,7 @@ export declare class MFSU {
|
|
|
35
38
|
buildDeps(): Promise<void>;
|
|
36
39
|
getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
|
|
37
40
|
private getAwaitImportCollectOpts;
|
|
38
|
-
getBabelPlugins(): (
|
|
41
|
+
getBabelPlugins(): ({
|
|
39
42
|
onTransformDeps: () => void;
|
|
40
43
|
onCollect: ({ file, data, }: {
|
|
41
44
|
file: string;
|
|
@@ -53,7 +56,7 @@ export declare class MFSU {
|
|
|
53
56
|
remoteName: string | undefined;
|
|
54
57
|
alias: Record<string, string>;
|
|
55
58
|
externals: (Function | Record<string, string>)[];
|
|
56
|
-
} | typeof awaitImport)[]
|
|
59
|
+
} | typeof awaitImport)[][];
|
|
57
60
|
getEsbuildLoaderHandler(): any[];
|
|
58
61
|
}
|
|
59
62
|
export {};
|
package/dist/mfsu.js
CHANGED
|
@@ -21,30 +21,34 @@ const path_1 = require("path");
|
|
|
21
21
|
const mrmime_1 = require("../compiled/mrmime");
|
|
22
22
|
// @ts-ignore
|
|
23
23
|
const webpack_virtual_modules_1 = __importDefault(require("../compiled/webpack-virtual-modules"));
|
|
24
|
-
const autoExport_1 = __importDefault(require("./babelPlugins/autoExport"));
|
|
25
24
|
const awaitImport_1 = __importDefault(require("./babelPlugins/awaitImport/awaitImport"));
|
|
26
25
|
const getRealPath_1 = require("./babelPlugins/awaitImport/getRealPath");
|
|
27
26
|
const constants_1 = require("./constants");
|
|
28
27
|
const dep_1 = require("./dep/dep");
|
|
29
28
|
const depBuilder_1 = require("./depBuilder/depBuilder");
|
|
30
29
|
const depInfo_1 = require("./depInfo");
|
|
31
|
-
const autoExport_2 = __importDefault(require("./esbuildHandlers/autoExport"));
|
|
32
30
|
const awaitImport_2 = __importDefault(require("./esbuildHandlers/awaitImport"));
|
|
33
31
|
const types_1 = require("./types");
|
|
34
32
|
const makeArray_1 = require("./utils/makeArray");
|
|
35
33
|
const buildDepPlugin_1 = require("./webpackPlugins/buildDepPlugin");
|
|
36
|
-
const writeCachePlugin_1 = require("./webpackPlugins/writeCachePlugin");
|
|
37
34
|
class MFSU {
|
|
38
35
|
constructor(opts) {
|
|
39
36
|
this.alias = {};
|
|
40
37
|
this.externals = [];
|
|
41
38
|
this.depConfig = null;
|
|
39
|
+
this.buildDepsAgain = false;
|
|
40
|
+
this.progress = { done: false };
|
|
42
41
|
this.opts = opts;
|
|
43
42
|
this.opts.mfName = this.opts.mfName || constants_1.DEFAULT_MF_NAME;
|
|
44
43
|
this.opts.tmpBase =
|
|
45
44
|
this.opts.tmpBase || (0, path_1.join)(process.cwd(), constants_1.DEFAULT_TMP_DIR_NAME);
|
|
46
45
|
this.opts.mode = this.opts.mode || types_1.Mode.development;
|
|
47
46
|
this.opts.getCacheDependency = this.opts.getCacheDependency || (() => ({}));
|
|
47
|
+
this.onProgress = (progress) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
this.progress = Object.assign(Object.assign({}, this.progress), progress);
|
|
50
|
+
(_b = (_a = this.opts).onMFSUProgress) === null || _b === void 0 ? void 0 : _b.call(_a, this.progress);
|
|
51
|
+
};
|
|
48
52
|
this.opts.cwd = this.opts.cwd || process.cwd();
|
|
49
53
|
this.depInfo = new depInfo_1.DepInfo({ mfsu: this });
|
|
50
54
|
this.depBuilder = new depBuilder_1.DepBuilder({ mfsu: this });
|
|
@@ -162,16 +166,30 @@ promise new Promise(resolve => {
|
|
|
162
166
|
}),
|
|
163
167
|
new buildDepPlugin_1.BuildDepPlugin({
|
|
164
168
|
onCompileDone: () => {
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
}
|
|
169
|
+
if (this.depBuilder.isBuilding) {
|
|
170
|
+
this.buildDepsAgain = true;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
this.buildDeps()
|
|
174
|
+
.then(() => {
|
|
175
|
+
this.onProgress({
|
|
176
|
+
done: true,
|
|
177
|
+
});
|
|
178
|
+
})
|
|
179
|
+
.catch((e) => {
|
|
180
|
+
utils_1.logger.error(e);
|
|
181
|
+
this.onProgress({
|
|
182
|
+
done: true,
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
168
186
|
},
|
|
169
187
|
}),
|
|
170
|
-
new
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}),
|
|
188
|
+
// new WriteCachePlugin({
|
|
189
|
+
// onWriteCache: lodash.debounce(() => {
|
|
190
|
+
// this.depInfo.writeCache();
|
|
191
|
+
// }, 300),
|
|
192
|
+
// }),
|
|
175
193
|
]);
|
|
176
194
|
// ensure topLevelAwait enabled
|
|
177
195
|
utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
|
|
@@ -183,7 +201,8 @@ promise new Promise(resolve => {
|
|
|
183
201
|
}
|
|
184
202
|
buildDeps() {
|
|
185
203
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
|
|
204
|
+
const shouldBuild = this.depInfo.shouldBuild();
|
|
205
|
+
if (!shouldBuild) {
|
|
187
206
|
utils_1.logger.info('MFSU skip buildDeps');
|
|
188
207
|
return;
|
|
189
208
|
}
|
|
@@ -193,11 +212,20 @@ promise new Promise(resolve => {
|
|
|
193
212
|
cwd: this.opts.cwd,
|
|
194
213
|
mfsu: this,
|
|
195
214
|
});
|
|
196
|
-
utils_1.logger.info(
|
|
215
|
+
utils_1.logger.info(`MFSU buildDeps since ${shouldBuild}`);
|
|
197
216
|
utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
|
|
198
217
|
yield this.depBuilder.build({
|
|
199
218
|
deps,
|
|
200
219
|
});
|
|
220
|
+
// Write cache
|
|
221
|
+
this.depInfo.writeCache();
|
|
222
|
+
if (this.buildDepsAgain) {
|
|
223
|
+
utils_1.logger.info('MFSU buildDepsAgain');
|
|
224
|
+
this.buildDepsAgain = false;
|
|
225
|
+
this.buildDeps().catch((e) => {
|
|
226
|
+
utils_1.logger.error(e);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
201
229
|
});
|
|
202
230
|
}
|
|
203
231
|
getMiddlewares() {
|
|
@@ -258,13 +286,12 @@ promise new Promise(resolve => {
|
|
|
258
286
|
};
|
|
259
287
|
}
|
|
260
288
|
getBabelPlugins() {
|
|
261
|
-
return [
|
|
289
|
+
return [[awaitImport_1.default, this.getAwaitImportCollectOpts()]];
|
|
262
290
|
}
|
|
263
291
|
getEsbuildLoaderHandler() {
|
|
264
292
|
const cache = new Map();
|
|
265
293
|
const checkOpts = this.getAwaitImportCollectOpts();
|
|
266
294
|
return [
|
|
267
|
-
autoExport_2.default,
|
|
268
295
|
(0, awaitImport_2.default)({
|
|
269
296
|
cache,
|
|
270
297
|
opts: checkOpts,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/mfsu",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220412.1",
|
|
4
4
|
"description": "@umijs/mfsu",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"test": "jest -c ../../jest.turbo.config.ts"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@umijs/bundler-esbuild": "4.0.0-canary.
|
|
26
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
27
|
-
"@umijs/utils": "4.0.0-canary.
|
|
25
|
+
"@umijs/bundler-esbuild": "4.0.0-canary.20220412.1",
|
|
26
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220412.1",
|
|
27
|
+
"@umijs/utils": "4.0.0-canary.20220412.1",
|
|
28
28
|
"enhanced-resolve": "5.9.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"mrmime": "1.0.0",
|
|
32
|
-
"webpack": "5.
|
|
32
|
+
"webpack": "5.72.0",
|
|
33
33
|
"webpack-virtual-modules": "0.4.3"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
27
|
-
function default_1() {
|
|
28
|
-
return {
|
|
29
|
-
visitor: {
|
|
30
|
-
Program(path) {
|
|
31
|
-
let hasExport = false;
|
|
32
|
-
path.node.body.forEach((node) => {
|
|
33
|
-
if (
|
|
34
|
-
// esm
|
|
35
|
-
t.isExportNamedDeclaration(node) ||
|
|
36
|
-
t.isExportDefaultDeclaration(node) ||
|
|
37
|
-
t.isExportAllDeclaration(node) ||
|
|
38
|
-
// cjs
|
|
39
|
-
(t.isExpressionStatement(node) &&
|
|
40
|
-
t.isAssignmentExpression(node.expression) &&
|
|
41
|
-
t.isMemberExpression(node.expression.left) &&
|
|
42
|
-
// exports.xxx =
|
|
43
|
-
(t.isIdentifier(node.expression.left.object, {
|
|
44
|
-
name: 'exports',
|
|
45
|
-
}) ||
|
|
46
|
-
// module.exports =
|
|
47
|
-
(t.isIdentifier(node.expression.left.object, {
|
|
48
|
-
name: 'module',
|
|
49
|
-
}) &&
|
|
50
|
-
t.isIdentifier(node.expression.left.property, {
|
|
51
|
-
name: 'exports',
|
|
52
|
-
}))))) {
|
|
53
|
-
hasExport = true;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
if (!hasExport) {
|
|
57
|
-
path.node.body.push(t.exportNamedDeclaration(t.variableDeclaration('const', [
|
|
58
|
-
t.variableDeclarator(t.identifier('__mfsu'), t.numericLiteral(1)),
|
|
59
|
-
])));
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exports.default = default_1;
|