@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.
Files changed (104) hide show
  1. package/compiled/is-absolute-url/LICENSE +9 -0
  2. package/compiled/is-absolute-url/index.d.ts +22 -0
  3. package/compiled/is-absolute-url/index.js +1 -0
  4. package/compiled/is-absolute-url/package.json +1 -0
  5. package/dist/babelPlugins/awaitImport/MFImport.d.ts +0 -1
  6. package/dist/babelPlugins/awaitImport/MFImport.js +59 -66
  7. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +0 -1
  8. package/dist/babelPlugins/awaitImport/awaitImport.js +103 -117
  9. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +0 -1
  10. package/dist/babelPlugins/awaitImport/checkMatch.js +129 -132
  11. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +0 -1
  12. package/dist/babelPlugins/awaitImport/getAliasedPath.js +54 -35
  13. package/dist/babelPlugins/awaitImport/getRealPath.d.ts +0 -1
  14. package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
  15. package/dist/babelPlugins/awaitImport/isExternals.d.ts +0 -1
  16. package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
  17. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +0 -1
  18. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +51 -52
  19. package/dist/constants.d.ts +0 -1
  20. package/dist/constants.js +47 -10
  21. package/dist/dep/dep.d.ts +0 -1
  22. package/dist/dep/dep.js +112 -83
  23. package/dist/dep/getCJSExports.d.ts +0 -1
  24. package/dist/dep/getCJSExports.js +60 -53
  25. package/dist/dep/getExposeFromContent.d.ts +0 -1
  26. package/dist/dep/getExposeFromContent.js +71 -61
  27. package/dist/dep/getModuleExports.d.ts +0 -1
  28. package/dist/dep/getModuleExports.js +58 -32
  29. package/dist/depBuilder/depBuilder.d.ts +0 -1
  30. package/dist/depBuilder/depBuilder.js +192 -158
  31. package/dist/depBuilder/getESBuildEntry.d.ts +0 -1
  32. package/dist/depBuilder/getESBuildEntry.js +35 -12
  33. package/dist/depInfo.d.ts +0 -1
  34. package/dist/depInfo.js +75 -53
  35. package/dist/esbuildHandlers/autoCssModules.d.ts +0 -1
  36. package/dist/esbuildHandlers/autoCssModules.js +43 -22
  37. package/dist/esbuildHandlers/awaitImport/index.d.ts +0 -1
  38. package/dist/esbuildHandlers/awaitImport/index.js +82 -70
  39. package/dist/index.d.ts +0 -1
  40. package/dist/index.js +32 -22
  41. package/dist/loader/esbuild.d.ts +0 -1
  42. package/dist/loader/esbuild.js +87 -35
  43. package/dist/mfsu/mfsu.d.ts +4 -1
  44. package/dist/mfsu/mfsu.js +236 -257
  45. package/dist/mfsu/strategyCompileTime.d.ts +0 -1
  46. package/dist/mfsu/strategyCompileTime.js +131 -99
  47. package/dist/mfsu/strategyStaticAnalyze.d.ts +0 -1
  48. package/dist/mfsu/strategyStaticAnalyze.js +151 -115
  49. package/dist/moduleGraph.d.ts +0 -1
  50. package/dist/moduleGraph.js +227 -186
  51. package/dist/staticDepInfo/importParser.d.ts +0 -1
  52. package/dist/staticDepInfo/importParser.js +28 -6
  53. package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +0 -1
  54. package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -91
  55. package/dist/staticDepInfo/staticDepInfo.d.ts +0 -1
  56. package/dist/staticDepInfo/staticDepInfo.js +239 -197
  57. package/dist/types.d.ts +0 -1
  58. package/dist/types.js +33 -8
  59. package/dist/utils/makeArray.d.ts +0 -1
  60. package/dist/utils/makeArray.js +29 -5
  61. package/dist/utils/trimFileContent.d.ts +0 -1
  62. package/dist/utils/trimFileContent.js +29 -5
  63. package/dist/webpackPlugins/buildDepPlugin.d.ts +0 -1
  64. package/dist/webpackPlugins/buildDepPlugin.js +49 -25
  65. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +0 -1
  66. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +44 -19
  67. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +0 -1
  68. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +46 -27
  69. package/dist/webpackPlugins/writeCachePlugin.d.ts +0 -1
  70. package/dist/webpackPlugins/writeCachePlugin.js +39 -15
  71. package/package.json +8 -6
  72. package/dist/babelPlugins/awaitImport/MFImport.d.ts.map +0 -1
  73. package/dist/babelPlugins/awaitImport/awaitImport.d.ts.map +0 -1
  74. package/dist/babelPlugins/awaitImport/checkMatch.d.ts.map +0 -1
  75. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts.map +0 -1
  76. package/dist/babelPlugins/awaitImport/getRealPath.d.ts.map +0 -1
  77. package/dist/babelPlugins/awaitImport/isExternals.d.ts.map +0 -1
  78. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts.map +0 -1
  79. package/dist/constants.d.ts.map +0 -1
  80. package/dist/dep/dep.d.ts.map +0 -1
  81. package/dist/dep/getCJSExports.d.ts.map +0 -1
  82. package/dist/dep/getExposeFromContent.d.ts.map +0 -1
  83. package/dist/dep/getModuleExports.d.ts.map +0 -1
  84. package/dist/depBuilder/depBuilder.d.ts.map +0 -1
  85. package/dist/depBuilder/getESBuildEntry.d.ts.map +0 -1
  86. package/dist/depInfo.d.ts.map +0 -1
  87. package/dist/esbuildHandlers/autoCssModules.d.ts.map +0 -1
  88. package/dist/esbuildHandlers/awaitImport/index.d.ts.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/loader/esbuild.d.ts.map +0 -1
  91. package/dist/mfsu/mfsu.d.ts.map +0 -1
  92. package/dist/mfsu/strategyCompileTime.d.ts.map +0 -1
  93. package/dist/mfsu/strategyStaticAnalyze.d.ts.map +0 -1
  94. package/dist/moduleGraph.d.ts.map +0 -1
  95. package/dist/staticDepInfo/importParser.d.ts.map +0 -1
  96. package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts.map +0 -1
  97. package/dist/staticDepInfo/staticDepInfo.d.ts.map +0 -1
  98. package/dist/types.d.ts.map +0 -1
  99. package/dist/utils/makeArray.d.ts.map +0 -1
  100. package/dist/utils/trimFileContent.d.ts.map +0 -1
  101. package/dist/webpackPlugins/buildDepPlugin.d.ts.map +0 -1
  102. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts.map +0 -1
  103. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts.map +0 -1
  104. package/dist/webpackPlugins/writeCachePlugin.d.ts.map +0 -1
@@ -1,99 +1,107 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const utils_1 = require("@umijs/utils");
7
- const path_1 = require("path");
8
- const getAliasedPath_1 = require("../../babelPlugins/awaitImport/getAliasedPath");
9
- const importParser_1 = __importDefault(require("../importParser"));
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
- var _a;
12
- const { libraryName, libraryDirectory } = importOptions;
13
- const useUnderline = importOptions.camel2UnderlineComponentName;
14
- const useDash = (_a = importOptions.camel2DashComponentName) !== null && _a !== void 0 ? _a : true;
15
- const transformName = useUnderline
16
- ? (n) => transCamel(n, '_')
17
- : useDash
18
- ? (n) => transCamel(n, '-')
19
- : (n) => n;
20
- /*
21
- todo support other config values
22
- [x] boolean true
23
- [x] string css
24
- [ ] function
25
- */
26
- const stylePathFromCompPath = importOptions.style === 'css'
27
- ? (compFsPath) => (0, utils_1.winPath)((0, path_1.join)(compFsPath, 'style/css'))
28
- : (compFsPath) => (0, utils_1.winPath)((0, path_1.join)(compFsPath, 'style'));
29
- return function handleImports(opts) {
30
- const { imports, rawCode } = opts;
31
- if ((imports === null || imports === void 0 ? void 0 : imports.length) > 0) {
32
- const version = opts.pathToVersion(libraryName);
33
- function addToMatches(moduleFsPath) {
34
- const unAliasedModulePath = (0, getAliasedPath_1.getAliasedPathWithLoopDetect)({
35
- value: (0, utils_1.winPath)(moduleFsPath),
36
- alias: opts.alias,
37
- });
38
- retMatched.push({
39
- isMatch: true,
40
- value: unAliasedModulePath,
41
- replaceValue: `${mfName}/${unAliasedModulePath}`,
42
- version,
43
- });
44
- const unAliasedStylePath = (0, getAliasedPath_1.getAliasedPathWithLoopDetect)({
45
- value: stylePathFromCompPath(moduleFsPath),
46
- alias: opts.alias,
47
- });
48
- retMatched.push({
49
- isMatch: true,
50
- value: unAliasedStylePath,
51
- replaceValue: `${mfName}/${unAliasedStylePath}`,
52
- version,
53
- });
54
- }
55
- const importSnippets = imports
56
- .map(({ ss, se }) => {
57
- return rawCode.slice(ss, se + 1);
58
- })
59
- .join('\n');
60
- const retMatched = [];
61
- const parsedImports = (0, importParser_1.default)(importSnippets);
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
- return [];
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
- const str = _str[0].toLowerCase() + _str.substr(1);
90
- return str.replace(/([A-Z])/g, ($1) => `${symbol}${$1.toLowerCase()}`);
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
- utils_1.logger.error(`"import * as ant from 'antd'" or "export * from '${libraryName}'" are not allowed in mfsu#version=v4`);
94
- utils_1.logger.error(`solutions:`);
95
- utils_1.logger.error(` change to "import { Xxx } from '${libraryName}'" or`);
96
- utils_1.logger.error(` "export { Xxx } from '${libraryName}'" syntax`);
97
- utils_1.logger.error(` or use mfsu#version=v3 configuration`);
98
- throw Error(`"import * as ant from 'antd'" not allowed in mfsu#version=4`);
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 = {});
@@ -54,4 +54,3 @@ export declare class StaticDepInfo {
54
54
  allRuntimeHelpers(): Promise<void>;
55
55
  }
56
56
  export {};
57
- //# sourceMappingURL=staticDepInfo.d.ts.map
@@ -1,206 +1,248 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.StaticDepInfo = void 0;
7
- const utils_1 = require("@umijs/utils");
8
- const fs_1 = require("fs");
9
- // @ts-ignore
10
- const why_1 = __importDefault(require("is-equal/why"));
11
- const path_1 = require("path");
12
- const checkMatch_1 = require("../babelPlugins/awaitImport/checkMatch");
13
- const dep_1 = require("../dep/dep");
14
- const babel_plugin_import_1 = __importDefault(require("./simulations/babel-plugin-import"));
15
- class StaticDepInfo {
16
- constructor(opts) {
17
- this.currentDep = {};
18
- this.builtWithDep = {};
19
- this.produced = [];
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
- writeCache() {
88
- utils_1.fsExtra.mkdirpSync((0, path_1.dirname)(this.cacheFilePath));
89
- const newContent = JSON.stringify(this.builtWithDep, null, 2);
90
- if ((0, fs_1.existsSync)(this.cacheFilePath) &&
91
- (0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8') === newContent) {
92
- return;
93
- }
94
- utils_1.logger.info('[MFSU][eager] write cache');
95
- (0, fs_1.writeFileSync)(this.cacheFilePath, newContent, 'utf-8');
96
- }
97
- getCacheFilePath() {
98
- return this.cacheFilePath;
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
- getDependencies() {
101
- return this.currentDep;
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
- init() {
104
- const merged = this.opts.srcCodeCache.getMergedCode();
105
- this.currentDep = this._getDependencies(merged.code, merged.imports);
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
- _getDependencies(bigCodeString, imports) {
108
- const start = Date.now();
109
- const cwd = this.mfsu.opts.cwd;
110
- const opts = {
111
- exportAllMembers: this.mfsu.opts.exportAllMembers,
112
- unMatchLibs: this.mfsu.opts.unMatchLibs,
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
- simulateRuntimeTransform(matched, groupedImports, rawCode) {
163
- for (const mock of this.runtimeSimulations) {
164
- const name = mock.packageName;
165
- const pathToVersion = (dep) => {
166
- return dep_1.Dep.getDepVersion({
167
- dep,
168
- cwd: this.cwd,
169
- });
170
- };
171
- const ms = mock.handleImports({
172
- imports: groupedImports[name],
173
- rawCode,
174
- alias: this.mfsu.alias,
175
- mfName: this.mfsu.opts.mfName,
176
- pathToVersion,
177
- });
178
- for (const m of ms) {
179
- matched[m.value] = m;
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
- appendIncludeList(matched, opts) {
184
- for (const p of this.include) {
185
- const match = (0, checkMatch_1.checkMatch)({
186
- value: p,
187
- depth: 1,
188
- filename: '_.js',
189
- opts,
190
- });
191
- if (match.isMatch) {
192
- matched[match.value] = {
193
- ...match,
194
- version: dep_1.Dep.getDepVersion({
195
- dep: match.value,
196
- cwd: this.cwd,
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
- async allRuntimeHelpers() {
203
- // todo mfsu4
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
- exports.StaticDepInfo = StaticDepInfo;
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
@@ -14,4 +14,3 @@ export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
14
14
  handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
15
15
  implementation?: typeof import('@umijs/bundler-utils/compiled/esbuild');
16
16
  }
17
- //# sourceMappingURL=types.d.ts.map