@umijs/mfsu 4.0.0-rc.1 → 4.0.0-rc.10
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/babelPlugins/awaitImport/awaitImport.js +5 -1
- package/dist/babelPlugins/awaitImport/checkMatch.js +4 -2
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +5 -10
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +5 -1
- package/dist/dep/dep.js +2 -2
- package/dist/depBuilder/depBuilder.js +17 -10
- package/dist/depBuilder/getESBuildEntry.js +18 -5
- package/dist/depInfo.d.ts +1 -1
- package/dist/depInfo.js +10 -5
- package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
- package/dist/esbuildHandlers/autoCssModules.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10 -1
- package/dist/loader/esbuild.d.ts +5 -0
- package/dist/loader/esbuild.js +54 -0
- package/dist/mfsu.d.ts +4 -4
- package/dist/mfsu.js +28 -16
- package/dist/types.d.ts +12 -0
- package/package.json +8 -8
- package/dist/babelPlugins/autoExport.d.ts +0 -7
- package/dist/babelPlugins/autoExport.js +0 -61
- package/dist/esbuildHandlers/autoExport.d.ts +0 -6
- package/dist/esbuildHandlers/autoExport.js +0 -9
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -13,7 +13,7 @@ const isExternals_1 = require("./isExternals");
|
|
|
13
13
|
const RE_NODE_MODULES = /node_modules/;
|
|
14
14
|
const RE_UMI_LOCAL_DEV = /umi(-next)?\/packages\//;
|
|
15
15
|
function isUmiLocalDev(path) {
|
|
16
|
-
return RE_UMI_LOCAL_DEV.test(path);
|
|
16
|
+
return RE_UMI_LOCAL_DEV.test((0, utils_1.winPath)(path));
|
|
17
17
|
}
|
|
18
18
|
function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }) {
|
|
19
19
|
var _a, _b;
|
|
@@ -28,6 +28,8 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, })
|
|
|
28
28
|
if (
|
|
29
29
|
// unMatch specified libs
|
|
30
30
|
((_a = opts.unMatchLibs) === null || _a === void 0 ? void 0 : _a.includes(value)) ||
|
|
31
|
+
// do not match bundler-webpack/client/client/client.js
|
|
32
|
+
value.includes('client/client/client.js') ||
|
|
31
33
|
// already handled
|
|
32
34
|
value.startsWith(`${remoteName}/`) ||
|
|
33
35
|
// don't match dynamic path
|
|
@@ -69,7 +71,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, })
|
|
|
69
71
|
isMatch = !!(opts.exportAllMembers && value in opts.exportAllMembers);
|
|
70
72
|
}
|
|
71
73
|
if (isMatch) {
|
|
72
|
-
replaceValue = `${remoteName}/${value}`;
|
|
74
|
+
replaceValue = `${remoteName}/${(0, utils_1.winPath)(value)}`;
|
|
73
75
|
}
|
|
74
76
|
// @ts-ignore
|
|
75
77
|
const file = (path === null || path === void 0 ? void 0 : path.hub.file.opts.filename) || filename;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAliasedPath = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
4
|
function getAliasedPath({ value, alias, }) {
|
|
6
5
|
const importValue = value;
|
|
6
|
+
// equal alias
|
|
7
|
+
if (alias[value]) {
|
|
8
|
+
return alias[value];
|
|
9
|
+
}
|
|
7
10
|
for (const key of Object.keys(alias)) {
|
|
8
11
|
const aliasValue = alias[key];
|
|
9
12
|
// exact alias
|
|
@@ -15,21 +18,13 @@ function getAliasedPath({ value, alias, }) {
|
|
|
15
18
|
else
|
|
16
19
|
continue;
|
|
17
20
|
}
|
|
18
|
-
// e.g. foo: path/to/foo
|
|
19
|
-
if (importValue === key) {
|
|
20
|
-
return aliasValue;
|
|
21
|
-
}
|
|
22
21
|
// e.g. foo: path/to/foo.js
|
|
23
|
-
|
|
24
|
-
if (importValue.startsWith(slashedKey)) {
|
|
22
|
+
if (importValue.startsWith(addLastSlash(key))) {
|
|
25
23
|
return importValue.replace(key, aliasValue);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
exports.getAliasedPath = getAliasedPath;
|
|
30
|
-
function isJSFile(path) {
|
|
31
|
-
return ['.js', '.jsx', '.ts', '.tsx'].includes((0, path_1.extname)(path));
|
|
32
|
-
}
|
|
33
28
|
function addLastSlash(path) {
|
|
34
29
|
return path.endsWith('/') ? path : `${path}/`;
|
|
35
30
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/dep/dep.js
CHANGED
|
@@ -37,7 +37,7 @@ function resolve(context, path) {
|
|
|
37
37
|
}
|
|
38
38
|
class Dep {
|
|
39
39
|
constructor(opts) {
|
|
40
|
-
this.file = opts.file;
|
|
40
|
+
this.file = (0, utils_1.winPath)(opts.file);
|
|
41
41
|
this.version = opts.version;
|
|
42
42
|
this.cwd = opts.cwd;
|
|
43
43
|
this.shortFile = this.file;
|
|
@@ -98,7 +98,7 @@ export * from '${this.file}';
|
|
|
98
98
|
const dep = (0, path_1.isAbsolute)(opts.dep)
|
|
99
99
|
? opts.dep
|
|
100
100
|
: (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
|
|
101
|
-
const pkg = utils_1.pkgUp.
|
|
101
|
+
const pkg = utils_1.pkgUp.pkgUpSync({
|
|
102
102
|
cwd: dep,
|
|
103
103
|
});
|
|
104
104
|
(0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
|
|
@@ -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
|
}
|
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getESBuildEntry = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
|
+
// from typescript `esModuleInterop`
|
|
6
|
+
const ES_INTEROP_FUNC = `__exportStar`;
|
|
7
|
+
const ES_INTEROP_HELPER = `
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var ${ES_INTEROP_FUNC} = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
`;
|
|
5
19
|
function getESBuildEntry(opts) {
|
|
6
20
|
return `
|
|
7
21
|
(function() {
|
|
@@ -266,6 +280,7 @@ function getESBuildEntry(opts) {
|
|
|
266
280
|
var __webpack_exports__ = {};
|
|
267
281
|
(function() {
|
|
268
282
|
var exports = __webpack_exports__;
|
|
283
|
+
${ES_INTEROP_HELPER}
|
|
269
284
|
var moduleMap = {
|
|
270
285
|
${opts.deps.map(getDepModuleStr).join(',\n')}
|
|
271
286
|
};
|
|
@@ -299,15 +314,13 @@ ${opts.deps.map(getDepModuleStr).join(',\n')}
|
|
|
299
314
|
`;
|
|
300
315
|
}
|
|
301
316
|
exports.getESBuildEntry = getESBuildEntry;
|
|
302
|
-
function normalizeFile(file) {
|
|
303
|
-
return file.replace(/\//g, '_');
|
|
304
|
-
}
|
|
305
317
|
function getDepModuleStr(dep) {
|
|
306
318
|
return `
|
|
307
319
|
"./${dep.file}": function() {
|
|
308
320
|
return new Promise(resolve => {
|
|
309
|
-
import('./${constants_1.MF_VA_PREFIX}${
|
|
310
|
-
|
|
321
|
+
import('./${constants_1.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
|
|
322
|
+
module.default && ${ES_INTEROP_FUNC}(module, module.default);
|
|
323
|
+
resolve(() => module.default || module);
|
|
311
324
|
});
|
|
312
325
|
})
|
|
313
326
|
}
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.autoCssModulesHandler = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const CSS_MODULES_QUERY = '?modules';
|
|
6
|
+
const QUERY_LENGTH = CSS_MODULES_QUERY.length;
|
|
7
|
+
function autoCssModulesHandler(opts) {
|
|
8
|
+
let { code } = opts;
|
|
9
|
+
let offset = 0;
|
|
10
|
+
opts.imports.forEach((i) => {
|
|
11
|
+
if (i.d < 0 && (0, utils_1.isStyleFile)({ filename: i.n })) {
|
|
12
|
+
// import x from './index.less'
|
|
13
|
+
// => import x from '
|
|
14
|
+
const importSegment = code.substring(i.ss + offset, i.s + offset);
|
|
15
|
+
// is css module
|
|
16
|
+
if (~importSegment.indexOf(' from')) {
|
|
17
|
+
code = `${code.substring(0, i.e + offset)}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
|
|
18
|
+
offset += QUERY_LENGTH;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return code;
|
|
23
|
+
}
|
|
24
|
+
exports.autoCssModulesHandler = autoCssModulesHandler;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -10,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.esbuildLoader = void 0;
|
|
13
18
|
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./esbuildHandlers/autoCssModules"), exports);
|
|
20
|
+
// for independent use `esbuild-loader`
|
|
21
|
+
var esbuild_1 = require("./loader/esbuild");
|
|
22
|
+
Object.defineProperty(exports, "esbuildLoader", { enumerable: true, get: function () { return esbuild_1.esbuildLoader; } });
|
|
14
23
|
__exportStar(require("./mfsu"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LoaderContext } from 'webpack';
|
|
2
|
+
import type { IEsbuildLoaderOpts } from '../types';
|
|
3
|
+
declare function esbuildTranspiler(this: LoaderContext<IEsbuildLoaderOpts>, source: string): Promise<void>;
|
|
4
|
+
export default esbuildTranspiler;
|
|
5
|
+
export declare const esbuildLoader: string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.esbuildLoader = void 0;
|
|
24
|
+
const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
|
|
25
|
+
const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
|
|
26
|
+
const path_1 = require("path");
|
|
27
|
+
function esbuildTranspiler(source) {
|
|
28
|
+
var _a;
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const done = this.async();
|
|
31
|
+
const options = this.getOptions();
|
|
32
|
+
const { handler = [], implementation } = options, otherOptions = __rest(options, ["handler", "implementation"]);
|
|
33
|
+
const transform = (implementation === null || implementation === void 0 ? void 0 : implementation.transform) || esbuild_1.transform;
|
|
34
|
+
const filePath = this.resourcePath;
|
|
35
|
+
const ext = (0, path_1.extname)(filePath).slice(1);
|
|
36
|
+
const transformOptions = Object.assign(Object.assign({}, otherOptions), { target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015', loader: ext !== null && ext !== void 0 ? ext : 'js', sourcemap: this.sourceMap, sourcefile: filePath });
|
|
37
|
+
try {
|
|
38
|
+
let { code, map } = yield transform(source, transformOptions);
|
|
39
|
+
if (handler.length) {
|
|
40
|
+
yield es_module_lexer_1.init;
|
|
41
|
+
handler.forEach((handle) => {
|
|
42
|
+
const [imports, exports] = (0, es_module_lexer_1.parse)(code);
|
|
43
|
+
code = handle({ code, imports, exports, filePath });
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
done(null, code, map && JSON.parse(map));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
done(error);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.default = esbuildTranspiler;
|
|
54
|
+
exports.esbuildLoader = __filename;
|
package/dist/mfsu.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { NextFunction, Request, Response } from 'express';
|
|
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';
|
|
@@ -26,6 +25,7 @@ export declare class MFSU {
|
|
|
26
25
|
depInfo: DepInfo;
|
|
27
26
|
depBuilder: DepBuilder;
|
|
28
27
|
depConfig: Configuration | null;
|
|
28
|
+
buildDepsAgain: boolean;
|
|
29
29
|
constructor(opts: IOpts);
|
|
30
30
|
asyncImport(content: string): string;
|
|
31
31
|
setWebpackConfig(opts: {
|
|
@@ -35,7 +35,7 @@ export declare class MFSU {
|
|
|
35
35
|
buildDeps(): Promise<void>;
|
|
36
36
|
getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
|
|
37
37
|
private getAwaitImportCollectOpts;
|
|
38
|
-
getBabelPlugins(): (
|
|
38
|
+
getBabelPlugins(): ({
|
|
39
39
|
onTransformDeps: () => void;
|
|
40
40
|
onCollect: ({ file, data, }: {
|
|
41
41
|
file: string;
|
|
@@ -53,7 +53,7 @@ export declare class MFSU {
|
|
|
53
53
|
remoteName: string | undefined;
|
|
54
54
|
alias: Record<string, string>;
|
|
55
55
|
externals: (Function | Record<string, string>)[];
|
|
56
|
-
} | typeof awaitImport)[]
|
|
56
|
+
} | typeof awaitImport)[][];
|
|
57
57
|
getEsbuildLoaderHandler(): any[];
|
|
58
58
|
}
|
|
59
59
|
export {};
|
package/dist/mfsu.js
CHANGED
|
@@ -21,24 +21,22 @@ 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;
|
|
42
40
|
this.opts = opts;
|
|
43
41
|
this.opts.mfName = this.opts.mfName || constants_1.DEFAULT_MF_NAME;
|
|
44
42
|
this.opts.tmpBase =
|
|
@@ -53,7 +51,7 @@ class MFSU {
|
|
|
53
51
|
// swc don't support top-level await
|
|
54
52
|
// ref: https://github.com/vercel/next.js/issues/31054
|
|
55
53
|
asyncImport(content) {
|
|
56
|
-
return `await import('${content}');`;
|
|
54
|
+
return `await import('${(0, utils_1.winPath)(content)}');`;
|
|
57
55
|
// return `(async () => await import('${content}'))();`;
|
|
58
56
|
}
|
|
59
57
|
setWebpackConfig(opts) {
|
|
@@ -162,16 +160,21 @@ promise new Promise(resolve => {
|
|
|
162
160
|
}),
|
|
163
161
|
new buildDepPlugin_1.BuildDepPlugin({
|
|
164
162
|
onCompileDone: () => {
|
|
165
|
-
this.
|
|
166
|
-
|
|
167
|
-
}
|
|
163
|
+
if (this.depBuilder.isBuilding) {
|
|
164
|
+
this.buildDepsAgain = true;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.buildDeps().catch((e) => {
|
|
168
|
+
utils_1.logger.error(e);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
168
171
|
},
|
|
169
172
|
}),
|
|
170
|
-
new
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}),
|
|
173
|
+
// new WriteCachePlugin({
|
|
174
|
+
// onWriteCache: lodash.debounce(() => {
|
|
175
|
+
// this.depInfo.writeCache();
|
|
176
|
+
// }, 300),
|
|
177
|
+
// }),
|
|
175
178
|
]);
|
|
176
179
|
// ensure topLevelAwait enabled
|
|
177
180
|
utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
|
|
@@ -183,7 +186,8 @@ promise new Promise(resolve => {
|
|
|
183
186
|
}
|
|
184
187
|
buildDeps() {
|
|
185
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
|
|
189
|
+
const shouldBuild = this.depInfo.shouldBuild();
|
|
190
|
+
if (!shouldBuild) {
|
|
187
191
|
utils_1.logger.info('MFSU skip buildDeps');
|
|
188
192
|
return;
|
|
189
193
|
}
|
|
@@ -193,11 +197,20 @@ promise new Promise(resolve => {
|
|
|
193
197
|
cwd: this.opts.cwd,
|
|
194
198
|
mfsu: this,
|
|
195
199
|
});
|
|
196
|
-
utils_1.logger.info(
|
|
200
|
+
utils_1.logger.info(`MFSU buildDeps since ${shouldBuild}`);
|
|
197
201
|
utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
|
|
198
202
|
yield this.depBuilder.build({
|
|
199
203
|
deps,
|
|
200
204
|
});
|
|
205
|
+
// Write cache
|
|
206
|
+
this.depInfo.writeCache();
|
|
207
|
+
if (this.buildDepsAgain) {
|
|
208
|
+
utils_1.logger.info('MFSU buildDepsAgain');
|
|
209
|
+
this.buildDepsAgain = false;
|
|
210
|
+
this.buildDeps().catch((e) => {
|
|
211
|
+
utils_1.logger.error(e);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
201
214
|
});
|
|
202
215
|
}
|
|
203
216
|
getMiddlewares() {
|
|
@@ -258,13 +271,12 @@ promise new Promise(resolve => {
|
|
|
258
271
|
};
|
|
259
272
|
}
|
|
260
273
|
getBabelPlugins() {
|
|
261
|
-
return [
|
|
274
|
+
return [[awaitImport_1.default, this.getAwaitImportCollectOpts()]];
|
|
262
275
|
}
|
|
263
276
|
getEsbuildLoaderHandler() {
|
|
264
277
|
const cache = new Map();
|
|
265
278
|
const checkOpts = this.getAwaitImportCollectOpts();
|
|
266
279
|
return [
|
|
267
|
-
autoExport_2.default,
|
|
268
280
|
(0, awaitImport_2.default)({
|
|
269
281
|
cache,
|
|
270
282
|
opts: checkOpts,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
|
|
2
|
+
import type { TransformOptions } from '@umijs/bundler-utils/compiled/esbuild';
|
|
1
3
|
export declare enum Mode {
|
|
2
4
|
development = "development",
|
|
3
5
|
production = "production"
|
|
4
6
|
}
|
|
7
|
+
export interface IEsbuildLoaderHandlerParams {
|
|
8
|
+
code: string;
|
|
9
|
+
filePath: string;
|
|
10
|
+
imports: readonly ImportSpecifier[];
|
|
11
|
+
exports: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
|
|
14
|
+
handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
|
|
15
|
+
implementation?: typeof import('@umijs/bundler-utils/compiled/esbuild');
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/mfsu",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.10",
|
|
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",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "pnpm tsc",
|
|
20
20
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
21
|
-
"dev": "pnpm build -- --watch"
|
|
21
|
+
"dev": "pnpm build -- --watch",
|
|
22
|
+
"test": "jest -c ../../jest.turbo.config.ts"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@umijs/bundler-esbuild": "4.0.0-rc.
|
|
25
|
-
"@umijs/bundler-utils": "4.0.0-rc.
|
|
26
|
-
"@umijs/utils": "4.0.0-rc.
|
|
25
|
+
"@umijs/bundler-esbuild": "4.0.0-rc.10",
|
|
26
|
+
"@umijs/bundler-utils": "4.0.0-rc.10",
|
|
27
|
+
"@umijs/utils": "4.0.0-rc.10",
|
|
28
|
+
"enhanced-resolve": "5.9.2"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
|
-
"@types/express": "4.17.13",
|
|
30
|
-
"enhanced-resolve": "5.8.3",
|
|
31
31
|
"mrmime": "1.0.0",
|
|
32
|
-
"webpack": "5.
|
|
32
|
+
"webpack": "5.70.0",
|
|
33
33
|
"webpack-virtual-modules": "0.4.3"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
@@ -1,61 +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
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
23
|
-
function default_1() {
|
|
24
|
-
return {
|
|
25
|
-
visitor: {
|
|
26
|
-
Program(path) {
|
|
27
|
-
let hasExport = false;
|
|
28
|
-
path.node.body.forEach((node) => {
|
|
29
|
-
if (
|
|
30
|
-
// esm
|
|
31
|
-
t.isExportNamedDeclaration(node) ||
|
|
32
|
-
t.isExportDefaultDeclaration(node) ||
|
|
33
|
-
t.isExportAllDeclaration(node) ||
|
|
34
|
-
// cjs
|
|
35
|
-
(t.isExpressionStatement(node) &&
|
|
36
|
-
t.isAssignmentExpression(node.expression) &&
|
|
37
|
-
t.isMemberExpression(node.expression.left) &&
|
|
38
|
-
// exports.xxx =
|
|
39
|
-
(t.isIdentifier(node.expression.left.object, {
|
|
40
|
-
name: 'exports',
|
|
41
|
-
}) ||
|
|
42
|
-
// module.exports =
|
|
43
|
-
(t.isIdentifier(node.expression.left.object, {
|
|
44
|
-
name: 'module',
|
|
45
|
-
}) &&
|
|
46
|
-
t.isIdentifier(node.expression.left.property, {
|
|
47
|
-
name: 'exports',
|
|
48
|
-
}))))) {
|
|
49
|
-
hasExport = true;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
if (!hasExport) {
|
|
53
|
-
path.node.body.push(t.exportNamedDeclaration(t.variableDeclaration('const', [
|
|
54
|
-
t.variableDeclarator(t.identifier('__mfsu'), t.numericLiteral(1)),
|
|
55
|
-
])));
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
exports.default = default_1;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function autoExportHandler(opts) {
|
|
4
|
-
if (!opts.exports.length) {
|
|
5
|
-
return `${opts.code};\nexport const __mfsu = 1;`;
|
|
6
|
-
}
|
|
7
|
-
return opts.code;
|
|
8
|
-
}
|
|
9
|
-
exports.default = autoExportHandler;
|