@umijs/mfsu 4.0.0-canary.20220718.2 → 4.0.0-canary.20220729.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/compiled/is-absolute-url/LICENSE +9 -0
- package/compiled/is-absolute-url/index.d.ts +22 -0
- package/compiled/is-absolute-url/index.js +1 -0
- package/compiled/is-absolute-url/package.json +1 -0
- package/dist/babelPlugins/awaitImport/MFImport.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/MFImport.js +59 -66
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/awaitImport.js +103 -117
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/checkMatch.js +129 -132
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +54 -35
- package/dist/babelPlugins/awaitImport/getRealPath.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
- package/dist/babelPlugins/awaitImport/isExternals.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
- package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +0 -1
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +51 -52
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +47 -10
- package/dist/dep/dep.d.ts +0 -1
- package/dist/dep/dep.js +112 -83
- package/dist/dep/getCJSExports.d.ts +0 -1
- package/dist/dep/getCJSExports.js +60 -53
- package/dist/dep/getExposeFromContent.d.ts +0 -1
- package/dist/dep/getExposeFromContent.js +71 -61
- package/dist/dep/getModuleExports.d.ts +0 -1
- package/dist/dep/getModuleExports.js +58 -32
- package/dist/depBuilder/depBuilder.d.ts +0 -1
- package/dist/depBuilder/depBuilder.js +192 -158
- package/dist/depBuilder/getESBuildEntry.d.ts +0 -1
- package/dist/depBuilder/getESBuildEntry.js +35 -12
- package/dist/depInfo.d.ts +0 -1
- package/dist/depInfo.js +75 -53
- package/dist/esbuildHandlers/autoCssModules.d.ts +0 -1
- package/dist/esbuildHandlers/autoCssModules.js +43 -22
- package/dist/esbuildHandlers/awaitImport/index.d.ts +0 -1
- package/dist/esbuildHandlers/awaitImport/index.js +82 -70
- package/dist/index.d.ts +0 -1
- package/dist/index.js +32 -22
- package/dist/loader/esbuild.d.ts +0 -1
- package/dist/loader/esbuild.js +87 -35
- package/dist/mfsu/mfsu.d.ts +4 -1
- package/dist/mfsu/mfsu.js +236 -257
- package/dist/mfsu/strategyCompileTime.d.ts +0 -1
- package/dist/mfsu/strategyCompileTime.js +131 -99
- package/dist/mfsu/strategyStaticAnalyze.d.ts +0 -1
- package/dist/mfsu/strategyStaticAnalyze.js +151 -115
- package/dist/moduleGraph.d.ts +0 -1
- package/dist/moduleGraph.js +227 -186
- package/dist/staticDepInfo/importParser.d.ts +0 -1
- package/dist/staticDepInfo/importParser.js +28 -6
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +0 -1
- package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -91
- package/dist/staticDepInfo/staticDepInfo.d.ts +0 -1
- package/dist/staticDepInfo/staticDepInfo.js +239 -197
- package/dist/types.d.ts +0 -1
- package/dist/types.js +33 -8
- package/dist/utils/makeArray.d.ts +0 -1
- package/dist/utils/makeArray.js +29 -5
- package/dist/utils/trimFileContent.d.ts +0 -1
- package/dist/utils/trimFileContent.js +29 -5
- package/dist/webpackPlugins/buildDepPlugin.d.ts +0 -1
- package/dist/webpackPlugins/buildDepPlugin.js +49 -25
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +0 -1
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +44 -19
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +0 -1
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +46 -27
- package/dist/webpackPlugins/writeCachePlugin.d.ts +0 -1
- package/dist/webpackPlugins/writeCachePlugin.js +39 -15
- package/package.json +8 -6
- package/dist/babelPlugins/awaitImport/MFImport.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/getRealPath.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/isExternals.d.ts.map +0 -1
- package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/dep/dep.d.ts.map +0 -1
- package/dist/dep/getCJSExports.d.ts.map +0 -1
- package/dist/dep/getExposeFromContent.d.ts.map +0 -1
- package/dist/dep/getModuleExports.d.ts.map +0 -1
- package/dist/depBuilder/depBuilder.d.ts.map +0 -1
- package/dist/depBuilder/getESBuildEntry.d.ts.map +0 -1
- package/dist/depInfo.d.ts.map +0 -1
- package/dist/esbuildHandlers/autoCssModules.d.ts.map +0 -1
- package/dist/esbuildHandlers/awaitImport/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/loader/esbuild.d.ts.map +0 -1
- package/dist/mfsu/mfsu.d.ts.map +0 -1
- package/dist/mfsu/strategyCompileTime.d.ts.map +0 -1
- package/dist/mfsu/strategyStaticAnalyze.d.ts.map +0 -1
- package/dist/moduleGraph.d.ts.map +0 -1
- package/dist/staticDepInfo/importParser.d.ts.map +0 -1
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts.map +0 -1
- package/dist/staticDepInfo/staticDepInfo.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/makeArray.d.ts.map +0 -1
- package/dist/utils/trimFileContent.d.ts.map +0 -1
- package/dist/webpackPlugins/buildDepPlugin.d.ts.map +0 -1
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts.map +0 -1
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts.map +0 -1
- package/dist/webpackPlugins/writeCachePlugin.d.ts.map +0 -1
|
@@ -1,99 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
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 });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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/staticDepInfo/simulations/babel-plugin-import.ts
|
|
23
|
+
var babel_plugin_import_exports = {};
|
|
24
|
+
__export(babel_plugin_import_exports, {
|
|
25
|
+
default: () => createHandle
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(babel_plugin_import_exports);
|
|
28
|
+
var import_utils = require("@umijs/utils");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
var import_getAliasedPath = require("../../babelPlugins/awaitImport/getAliasedPath");
|
|
31
|
+
var import_importParser = __toESM(require("../importParser"));
|
|
10
32
|
function createHandle(importOptions) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const importedVariable = new Set();
|
|
63
|
-
for (const i of parsedImports) {
|
|
64
|
-
i.imports.forEach((v) => {
|
|
65
|
-
if (v === '*') {
|
|
66
|
-
errorLogForSpaceImport(libraryName);
|
|
67
|
-
}
|
|
68
|
-
importedVariable.add(v);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
const mfName = opts.mfName;
|
|
72
|
-
for (const v of importedVariable.entries()) {
|
|
73
|
-
const importVariableName = v[0];
|
|
74
|
-
if (importVariableName === 'default') {
|
|
75
|
-
addToMatches((0, path_1.join)(libraryName, libraryDirectory));
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const transformedName = transformName(importVariableName);
|
|
79
|
-
const importFsPath = (0, path_1.join)(libraryName, libraryDirectory, transformedName);
|
|
80
|
-
addToMatches(importFsPath);
|
|
81
|
-
}
|
|
82
|
-
return retMatched;
|
|
33
|
+
const { libraryName, libraryDirectory } = importOptions;
|
|
34
|
+
const useUnderline = importOptions.camel2UnderlineComponentName;
|
|
35
|
+
const useDash = importOptions.camel2DashComponentName ?? true;
|
|
36
|
+
const transformName = useUnderline ? (n) => transCamel(n, "_") : useDash ? (n) => transCamel(n, "-") : (n) => n;
|
|
37
|
+
const stylePathFromCompPath = importOptions.style === "css" ? (compFsPath) => (0, import_utils.winPath)((0, import_path.join)(compFsPath, "style/css")) : (compFsPath) => (0, import_utils.winPath)((0, import_path.join)(compFsPath, "style"));
|
|
38
|
+
return function handleImports(opts) {
|
|
39
|
+
const { imports, rawCode } = opts;
|
|
40
|
+
if ((imports == null ? void 0 : imports.length) > 0) {
|
|
41
|
+
let addToMatches = function(moduleFsPath) {
|
|
42
|
+
const unAliasedModulePath = (0, import_getAliasedPath.getAliasedPathWithLoopDetect)({
|
|
43
|
+
value: (0, import_utils.winPath)(moduleFsPath),
|
|
44
|
+
alias: opts.alias
|
|
45
|
+
});
|
|
46
|
+
retMatched.push({
|
|
47
|
+
isMatch: true,
|
|
48
|
+
value: unAliasedModulePath,
|
|
49
|
+
replaceValue: `${mfName}/${unAliasedModulePath}`,
|
|
50
|
+
version
|
|
51
|
+
});
|
|
52
|
+
const unAliasedStylePath = (0, import_getAliasedPath.getAliasedPathWithLoopDetect)({
|
|
53
|
+
value: stylePathFromCompPath(moduleFsPath),
|
|
54
|
+
alias: opts.alias
|
|
55
|
+
});
|
|
56
|
+
retMatched.push({
|
|
57
|
+
isMatch: true,
|
|
58
|
+
value: unAliasedStylePath,
|
|
59
|
+
replaceValue: `${mfName}/${unAliasedStylePath}`,
|
|
60
|
+
version
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const version = opts.pathToVersion(libraryName);
|
|
64
|
+
const importSnippets = imports.map(({ ss, se }) => {
|
|
65
|
+
return rawCode.slice(ss, se + 1);
|
|
66
|
+
}).join("\n");
|
|
67
|
+
const retMatched = [];
|
|
68
|
+
const parsedImports = (0, import_importParser.default)(importSnippets);
|
|
69
|
+
const importedVariable = /* @__PURE__ */ new Set();
|
|
70
|
+
for (const i of parsedImports) {
|
|
71
|
+
i.imports.forEach((v) => {
|
|
72
|
+
if (v === "*") {
|
|
73
|
+
errorLogForSpaceImport(libraryName);
|
|
74
|
+
}
|
|
75
|
+
importedVariable.add(v);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const mfName = opts.mfName;
|
|
79
|
+
for (const v of importedVariable.entries()) {
|
|
80
|
+
const importVariableName = v[0];
|
|
81
|
+
if (importVariableName === "default") {
|
|
82
|
+
addToMatches((0, import_path.join)(libraryName, libraryDirectory));
|
|
83
|
+
continue;
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
const transformedName = transformName(importVariableName);
|
|
86
|
+
const importFsPath = (0, import_path.join)(libraryName, libraryDirectory, transformedName);
|
|
87
|
+
addToMatches(importFsPath);
|
|
88
|
+
}
|
|
89
|
+
return retMatched;
|
|
90
|
+
}
|
|
91
|
+
return [];
|
|
92
|
+
};
|
|
86
93
|
}
|
|
87
|
-
exports.default = createHandle;
|
|
88
94
|
function transCamel(_str, symbol) {
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
const str = _str[0].toLowerCase() + _str.substr(1);
|
|
96
|
+
return str.replace(/([A-Z])/g, ($1) => `${symbol}${$1.toLowerCase()}`);
|
|
91
97
|
}
|
|
92
98
|
function errorLogForSpaceImport(libraryName) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
import_utils.logger.error(`"import * as ant from 'antd'" or "export * from '${libraryName}'" are not allowed in mfsu#strategy='eager'`);
|
|
100
|
+
import_utils.logger.error(`solutions:`);
|
|
101
|
+
import_utils.logger.error(` change to "import { Xxx } from '${libraryName}'" or`);
|
|
102
|
+
import_utils.logger.error(` "export { Xxx } from '${libraryName}'" syntax`);
|
|
103
|
+
import_utils.logger.error(` or use mfsu#strategy='normal' configuration`);
|
|
104
|
+
throw Error(`"import * as ant from 'antd'" not allowed in mfsu#version=4`);
|
|
99
105
|
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {});
|
|
@@ -1,206 +1,248 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.mfsu = opts.mfsu;
|
|
21
|
-
this.include = this.mfsu.opts.include || [];
|
|
22
|
-
this.opts = opts;
|
|
23
|
-
this.cacheFilePath = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, 'MFSU_CACHE_v4.json');
|
|
24
|
-
this.cwd = this.mfsu.opts.cwd;
|
|
25
|
-
opts.srcCodeCache.register((info) => {
|
|
26
|
-
this.produced.push({ changes: info.events });
|
|
27
|
-
this.currentDep = this._getDependencies(info.code, info.imports);
|
|
28
|
-
});
|
|
29
|
-
this.runtimeSimulations = [
|
|
30
|
-
{
|
|
31
|
-
packageName: 'antd',
|
|
32
|
-
handleImports: (0, babel_plugin_import_1.default)({
|
|
33
|
-
libraryName: 'antd',
|
|
34
|
-
style: true,
|
|
35
|
-
libraryDirectory: 'es',
|
|
36
|
-
}),
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
packageName: '@alipay/bigfish/antd',
|
|
40
|
-
handleImports: (0, babel_plugin_import_1.default)({
|
|
41
|
-
libraryName: '@alipay/bigfish/antd',
|
|
42
|
-
style: true,
|
|
43
|
-
libraryDirectory: 'es',
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
getProducedEvent() {
|
|
49
|
-
return this.produced;
|
|
50
|
-
}
|
|
51
|
-
consumeAllProducedEvents() {
|
|
52
|
-
this.produced = [];
|
|
53
|
-
}
|
|
54
|
-
shouldBuild() {
|
|
55
|
-
if (utils_1.lodash.isEqual(this.builtWithDep, this.currentDep)) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
if (process.env.DEBUG_UMI) {
|
|
60
|
-
const reason = (0, why_1.default)(this.builtWithDep, this.currentDep);
|
|
61
|
-
utils_1.logger.info('[MFSU][eager]: isEqual(oldDep,newDep) === false, because ', reason);
|
|
62
|
-
}
|
|
63
|
-
return 'dependencies changed';
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
getDepModules() {
|
|
67
|
-
const map = this.getDependencies();
|
|
68
|
-
const staticDeps = {};
|
|
69
|
-
const keys = Object.keys(map);
|
|
70
|
-
for (const k of keys) {
|
|
71
|
-
staticDeps[k] = {
|
|
72
|
-
file: k,
|
|
73
|
-
version: map[k].version,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return staticDeps;
|
|
77
|
-
}
|
|
78
|
-
snapshot() {
|
|
79
|
-
this.builtWithDep = this.currentDep;
|
|
80
|
-
}
|
|
81
|
-
loadCache() {
|
|
82
|
-
if ((0, fs_1.existsSync)(this.cacheFilePath)) {
|
|
83
|
-
this.builtWithDep = JSON.parse((0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8'));
|
|
84
|
-
utils_1.logger.info('[MFSU][eager] restored cache');
|
|
85
|
-
}
|
|
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]);
|
|
86
20
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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/staticDepInfo/staticDepInfo.ts
|
|
40
|
+
var staticDepInfo_exports = {};
|
|
41
|
+
__export(staticDepInfo_exports, {
|
|
42
|
+
StaticDepInfo: () => StaticDepInfo
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(staticDepInfo_exports);
|
|
45
|
+
var import_utils = require("@umijs/utils");
|
|
46
|
+
var import_fs = require("fs");
|
|
47
|
+
var import_why = __toESM(require("is-equal/why"));
|
|
48
|
+
var import_path = require("path");
|
|
49
|
+
var import_checkMatch = require("../babelPlugins/awaitImport/checkMatch");
|
|
50
|
+
var import_dep = require("../dep/dep");
|
|
51
|
+
var import_babel_plugin_import = __toESM(require("./simulations/babel-plugin-import"));
|
|
52
|
+
var StaticDepInfo = class {
|
|
53
|
+
constructor(opts) {
|
|
54
|
+
this.currentDep = {};
|
|
55
|
+
this.builtWithDep = {};
|
|
56
|
+
this.produced = [];
|
|
57
|
+
this.mfsu = opts.mfsu;
|
|
58
|
+
this.include = this.mfsu.opts.include || [];
|
|
59
|
+
this.opts = opts;
|
|
60
|
+
this.cacheFilePath = (0, import_path.join)(this.opts.mfsu.opts.tmpBase, "MFSU_CACHE_v4.json");
|
|
61
|
+
this.cwd = this.mfsu.opts.cwd;
|
|
62
|
+
opts.srcCodeCache.register((info) => {
|
|
63
|
+
this.produced.push({ changes: info.events });
|
|
64
|
+
this.currentDep = this._getDependencies(info.code, info.imports);
|
|
65
|
+
});
|
|
66
|
+
this.runtimeSimulations = [
|
|
67
|
+
{
|
|
68
|
+
packageName: "antd",
|
|
69
|
+
handleImports: (0, import_babel_plugin_import.default)({
|
|
70
|
+
libraryName: "antd",
|
|
71
|
+
style: true,
|
|
72
|
+
libraryDirectory: "es"
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
packageName: "@alipay/bigfish/antd",
|
|
77
|
+
handleImports: (0, import_babel_plugin_import.default)({
|
|
78
|
+
libraryName: "@alipay/bigfish/antd",
|
|
79
|
+
style: true,
|
|
80
|
+
libraryDirectory: "es"
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
getProducedEvent() {
|
|
86
|
+
return this.produced;
|
|
87
|
+
}
|
|
88
|
+
consumeAllProducedEvents() {
|
|
89
|
+
this.produced = [];
|
|
90
|
+
}
|
|
91
|
+
shouldBuild() {
|
|
92
|
+
if (import_utils.lodash.isEqual(this.builtWithDep, this.currentDep)) {
|
|
93
|
+
return false;
|
|
94
|
+
} else {
|
|
95
|
+
if (process.env.DEBUG_UMI) {
|
|
96
|
+
const reason = (0, import_why.default)(this.builtWithDep, this.currentDep);
|
|
97
|
+
import_utils.logger.info("[MFSU][eager]: isEqual(oldDep,newDep) === false, because ", reason);
|
|
98
|
+
}
|
|
99
|
+
return "dependencies changed";
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
}
|
|
102
|
+
getDepModules() {
|
|
103
|
+
const map = this.getDependencies();
|
|
104
|
+
const staticDeps = {};
|
|
105
|
+
const keys = Object.keys(map);
|
|
106
|
+
for (const k of keys) {
|
|
107
|
+
staticDeps[k] = {
|
|
108
|
+
file: k,
|
|
109
|
+
version: map[k].version
|
|
110
|
+
};
|
|
102
111
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
return staticDeps;
|
|
113
|
+
}
|
|
114
|
+
snapshot() {
|
|
115
|
+
this.builtWithDep = this.currentDep;
|
|
116
|
+
}
|
|
117
|
+
loadCache() {
|
|
118
|
+
if ((0, import_fs.existsSync)(this.cacheFilePath)) {
|
|
119
|
+
this.builtWithDep = JSON.parse((0, import_fs.readFileSync)(this.cacheFilePath, "utf-8"));
|
|
120
|
+
import_utils.logger.info("[MFSU][eager] restored cache");
|
|
106
121
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
remoteName: this.mfsu.opts.mfName,
|
|
114
|
-
alias: this.mfsu.alias,
|
|
115
|
-
externals: this.mfsu.externals,
|
|
116
|
-
};
|
|
117
|
-
const matched = {};
|
|
118
|
-
const unMatched = new Set();
|
|
119
|
-
const pkgNames = this.runtimeSimulations.map(({ packageName }) => packageName);
|
|
120
|
-
const groupedMockImports = {};
|
|
121
|
-
for (const imp of imports) {
|
|
122
|
-
if (pkgNames.indexOf(imp.n) >= 0) {
|
|
123
|
-
const name = imp.n;
|
|
124
|
-
if (groupedMockImports[name]) {
|
|
125
|
-
groupedMockImports[name].push(imp);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
groupedMockImports[name] = [imp];
|
|
129
|
-
}
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (unMatched.has(imp.n)) {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (matched[imp.n]) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
const match = (0, checkMatch_1.checkMatch)({
|
|
139
|
-
value: imp.n,
|
|
140
|
-
depth: 1,
|
|
141
|
-
filename: '_.js',
|
|
142
|
-
opts,
|
|
143
|
-
});
|
|
144
|
-
if (match.isMatch) {
|
|
145
|
-
matched[match.value] = {
|
|
146
|
-
...match,
|
|
147
|
-
version: dep_1.Dep.getDepVersion({
|
|
148
|
-
dep: match.value,
|
|
149
|
-
cwd,
|
|
150
|
-
}),
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
unMatched.add(imp.n);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
this.simulateRuntimeTransform(matched, groupedMockImports, bigCodeString);
|
|
158
|
-
this.appendIncludeList(matched, opts);
|
|
159
|
-
utils_1.logger.debug('[MFSU][eager] _getDependencies costs', Date.now() - start);
|
|
160
|
-
return matched;
|
|
122
|
+
}
|
|
123
|
+
writeCache() {
|
|
124
|
+
import_utils.fsExtra.mkdirpSync((0, import_path.dirname)(this.cacheFilePath));
|
|
125
|
+
const newContent = JSON.stringify(this.builtWithDep, null, 2);
|
|
126
|
+
if ((0, import_fs.existsSync)(this.cacheFilePath) && (0, import_fs.readFileSync)(this.cacheFilePath, "utf-8") === newContent) {
|
|
127
|
+
return;
|
|
161
128
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
129
|
+
import_utils.logger.info("[MFSU][eager] write cache");
|
|
130
|
+
(0, import_fs.writeFileSync)(this.cacheFilePath, newContent, "utf-8");
|
|
131
|
+
}
|
|
132
|
+
getCacheFilePath() {
|
|
133
|
+
return this.cacheFilePath;
|
|
134
|
+
}
|
|
135
|
+
getDependencies() {
|
|
136
|
+
return this.currentDep;
|
|
137
|
+
}
|
|
138
|
+
init() {
|
|
139
|
+
const merged = this.opts.srcCodeCache.getMergedCode();
|
|
140
|
+
this.currentDep = this._getDependencies(merged.code, merged.imports);
|
|
141
|
+
}
|
|
142
|
+
_getDependencies(bigCodeString, imports) {
|
|
143
|
+
const start = Date.now();
|
|
144
|
+
const cwd = this.mfsu.opts.cwd;
|
|
145
|
+
const mfsuOpts = this.mfsu.opts;
|
|
146
|
+
const userUnMatches = mfsuOpts.unMatchLibs || [];
|
|
147
|
+
const sharedUnMatches = Object.keys(mfsuOpts.shared || {});
|
|
148
|
+
const remoteAliasUnMatches = (mfsuOpts.remoteAliases || []).map((str) => new RegExp(`^${str}`));
|
|
149
|
+
const unMatches = [
|
|
150
|
+
...userUnMatches,
|
|
151
|
+
...sharedUnMatches,
|
|
152
|
+
...remoteAliasUnMatches
|
|
153
|
+
];
|
|
154
|
+
const opts = {
|
|
155
|
+
exportAllMembers: this.mfsu.opts.exportAllMembers,
|
|
156
|
+
unMatchLibs: unMatches,
|
|
157
|
+
remoteName: this.mfsu.opts.mfName,
|
|
158
|
+
alias: this.mfsu.alias,
|
|
159
|
+
externals: this.mfsu.externals
|
|
160
|
+
};
|
|
161
|
+
const matched = {};
|
|
162
|
+
const unMatched = /* @__PURE__ */ new Set();
|
|
163
|
+
const pkgNames = this.runtimeSimulations.map(({ packageName }) => packageName);
|
|
164
|
+
const groupedMockImports = {};
|
|
165
|
+
for (const imp of imports) {
|
|
166
|
+
if (pkgNames.indexOf(imp.n) >= 0) {
|
|
167
|
+
const name = imp.n;
|
|
168
|
+
if (groupedMockImports[name]) {
|
|
169
|
+
groupedMockImports[name].push(imp);
|
|
170
|
+
} else {
|
|
171
|
+
groupedMockImports[name] = [imp];
|
|
181
172
|
}
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (unMatched.has(imp.n)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (matched[imp.n]) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const match = (0, import_checkMatch.checkMatch)({
|
|
182
|
+
value: imp.n,
|
|
183
|
+
depth: 1,
|
|
184
|
+
filename: "_.js",
|
|
185
|
+
opts
|
|
186
|
+
});
|
|
187
|
+
if (match.isMatch) {
|
|
188
|
+
matched[match.value] = __spreadProps(__spreadValues({}, match), {
|
|
189
|
+
version: import_dep.Dep.getDepVersion({
|
|
190
|
+
dep: match.value,
|
|
191
|
+
cwd
|
|
192
|
+
})
|
|
193
|
+
});
|
|
194
|
+
} else {
|
|
195
|
+
unMatched.add(imp.n);
|
|
196
|
+
}
|
|
182
197
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
this.simulateRuntimeTransform(matched, groupedMockImports, bigCodeString);
|
|
199
|
+
this.appendIncludeList(matched, opts);
|
|
200
|
+
import_utils.logger.debug("[MFSU][eager] _getDependencies costs", Date.now() - start);
|
|
201
|
+
return matched;
|
|
202
|
+
}
|
|
203
|
+
simulateRuntimeTransform(matched, groupedImports, rawCode) {
|
|
204
|
+
for (const mock of this.runtimeSimulations) {
|
|
205
|
+
const name = mock.packageName;
|
|
206
|
+
const pathToVersion = (dep) => {
|
|
207
|
+
return import_dep.Dep.getDepVersion({
|
|
208
|
+
dep,
|
|
209
|
+
cwd: this.cwd
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
const ms = mock.handleImports({
|
|
213
|
+
imports: groupedImports[name],
|
|
214
|
+
rawCode,
|
|
215
|
+
alias: this.mfsu.alias,
|
|
216
|
+
mfName: this.mfsu.opts.mfName,
|
|
217
|
+
pathToVersion
|
|
218
|
+
});
|
|
219
|
+
for (const m of ms) {
|
|
220
|
+
matched[m.value] = m;
|
|
221
|
+
}
|
|
201
222
|
}
|
|
202
|
-
|
|
203
|
-
|
|
223
|
+
}
|
|
224
|
+
appendIncludeList(matched, opts) {
|
|
225
|
+
for (const p of this.include) {
|
|
226
|
+
const match = (0, import_checkMatch.checkMatch)({
|
|
227
|
+
value: p,
|
|
228
|
+
depth: 1,
|
|
229
|
+
filename: "_.js",
|
|
230
|
+
opts
|
|
231
|
+
});
|
|
232
|
+
if (match.isMatch) {
|
|
233
|
+
matched[match.value] = __spreadProps(__spreadValues({}, match), {
|
|
234
|
+
version: import_dep.Dep.getDepVersion({
|
|
235
|
+
dep: match.value,
|
|
236
|
+
cwd: this.cwd
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
}
|
|
204
240
|
}
|
|
205
|
-
}
|
|
206
|
-
|
|
241
|
+
}
|
|
242
|
+
async allRuntimeHelpers() {
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
246
|
+
0 && (module.exports = {
|
|
247
|
+
StaticDepInfo
|
|
248
|
+
});
|
package/dist/types.d.ts
CHANGED