@umijs/mfsu 4.0.6 → 4.0.9

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 (40) 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.js +59 -66
  6. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
  7. package/dist/babelPlugins/awaitImport/awaitImport.js +103 -117
  8. package/dist/babelPlugins/awaitImport/checkMatch.js +131 -119
  9. package/dist/babelPlugins/awaitImport/getAliasedPath.js +54 -35
  10. package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
  11. package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
  12. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +51 -52
  13. package/dist/constants.js +47 -10
  14. package/dist/dep/dep.js +112 -83
  15. package/dist/dep/getCJSExports.js +60 -53
  16. package/dist/dep/getExposeFromContent.js +71 -59
  17. package/dist/dep/getModuleExports.js +58 -32
  18. package/dist/depBuilder/depBuilder.js +184 -158
  19. package/dist/depBuilder/getESBuildEntry.js +35 -12
  20. package/dist/depInfo.js +75 -53
  21. package/dist/esbuildHandlers/autoCssModules.js +43 -22
  22. package/dist/esbuildHandlers/awaitImport/index.js +82 -70
  23. package/dist/index.js +32 -22
  24. package/dist/loader/esbuild.js +87 -35
  25. package/dist/mfsu/mfsu.d.ts +1 -1
  26. package/dist/mfsu/mfsu.js +231 -257
  27. package/dist/mfsu/strategyCompileTime.js +123 -99
  28. package/dist/mfsu/strategyStaticAnalyze.js +135 -117
  29. package/dist/moduleGraph.js +227 -186
  30. package/dist/staticDepInfo/importParser.js +28 -6
  31. package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -91
  32. package/dist/staticDepInfo/staticDepInfo.js +230 -197
  33. package/dist/types.js +33 -8
  34. package/dist/utils/makeArray.js +29 -5
  35. package/dist/utils/trimFileContent.js +29 -5
  36. package/dist/webpackPlugins/buildDepPlugin.js +49 -25
  37. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +44 -19
  38. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +46 -27
  39. package/dist/webpackPlugins/writeCachePlugin.js +39 -15
  40. package/package.json +8 -6
@@ -1,100 +1,124 @@
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
- exports.StrategyCompileTime = void 0;
7
- const utils_1 = require("@umijs/utils");
8
- const awaitImport_1 = __importDefault(require("../babelPlugins/awaitImport/awaitImport"));
9
- const getRealPath_1 = require("../babelPlugins/awaitImport/getRealPath");
10
- const dep_1 = require("../dep/dep");
11
- const depInfo_1 = require("../depInfo");
12
- class StrategyCompileTime {
13
- constructor({ mfsu }) {
14
- this.mfsu = mfsu;
15
- this.depInfo = new depInfo_1.DepInfo({ mfsu });
16
- }
17
- getDepModules() {
18
- return this.depInfo.getDepModules();
19
- }
20
- getCacheFilePath() {
21
- return this.depInfo.getCacheFilePath();
22
- }
23
- init() { }
24
- shouldBuild() {
25
- return this.depInfo.shouldBuild();
26
- }
27
- loadCache() {
28
- this.depInfo.loadCache();
29
- }
30
- writeCache() {
31
- this.depInfo.writeCache();
32
- }
33
- refresh() {
34
- this.depInfo.snapshot();
35
- }
36
- getBabelPlugin() {
37
- return [awaitImport_1.default, this.getAwaitImportCollectOpts()];
38
- }
39
- getBuildDepPlugConfig() {
40
- const mfsu = this.mfsu;
41
- return {
42
- onCompileDone: () => {
43
- if (mfsu.depBuilder.isBuilding) {
44
- mfsu.buildDepsAgain = true;
45
- }
46
- else {
47
- mfsu
48
- .buildDeps()
49
- .then(() => {
50
- mfsu.onProgress({
51
- done: true,
52
- });
53
- })
54
- .catch((e) => {
55
- utils_1.logger.error(e);
56
- mfsu.onProgress({
57
- done: true,
58
- });
59
- });
60
- }
61
- },
62
- };
63
- }
64
- getAwaitImportCollectOpts() {
65
- const mfsuOpts = this.mfsu.opts;
66
- const mfsu = this.mfsu;
67
- return {
68
- onTransformDeps: () => { },
69
- onCollect: ({ file, data, }) => {
70
- this.depInfo.moduleGraph.onFileChange({
71
- file,
72
- // @ts-ignore
73
- deps: [
74
- ...Array.from(data.matched).map((item) => ({
75
- file: item.sourceValue,
76
- isDependency: true,
77
- version: dep_1.Dep.getDepVersion({
78
- dep: item.sourceValue,
79
- cwd: mfsuOpts.cwd,
80
- }),
81
- })),
82
- ...Array.from(data.unMatched).map((item) => ({
83
- file: (0, getRealPath_1.getRealPath)({
84
- file,
85
- dep: item.sourceValue,
86
- }),
87
- isDependency: false,
88
- })),
89
- ],
90
- });
91
- },
92
- exportAllMembers: mfsuOpts.exportAllMembers,
93
- unMatchLibs: mfsuOpts.unMatchLibs,
94
- remoteName: mfsuOpts.mfName,
95
- alias: mfsu.alias,
96
- externals: mfsu.externals,
97
- };
98
- }
99
- }
100
- exports.StrategyCompileTime = StrategyCompileTime;
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
+ // strategyCompileTime.ts
23
+ var strategyCompileTime_exports = {};
24
+ __export(strategyCompileTime_exports, {
25
+ StrategyCompileTime: () => StrategyCompileTime
26
+ });
27
+ module.exports = __toCommonJS(strategyCompileTime_exports);
28
+ var import_utils = require("@umijs/utils");
29
+ var import_awaitImport = __toESM(require("../babelPlugins/awaitImport/awaitImport"));
30
+ var import_getRealPath = require("../babelPlugins/awaitImport/getRealPath");
31
+ var import_dep = require("../dep/dep");
32
+ var import_depInfo = require("../depInfo");
33
+ var StrategyCompileTime = class {
34
+ constructor({ mfsu }) {
35
+ this.mfsu = mfsu;
36
+ this.depInfo = new import_depInfo.DepInfo({ mfsu });
37
+ }
38
+ getDepModules() {
39
+ return this.depInfo.getDepModules();
40
+ }
41
+ getCacheFilePath() {
42
+ return this.depInfo.getCacheFilePath();
43
+ }
44
+ init() {
45
+ }
46
+ shouldBuild() {
47
+ return this.depInfo.shouldBuild();
48
+ }
49
+ loadCache() {
50
+ this.depInfo.loadCache();
51
+ }
52
+ writeCache() {
53
+ this.depInfo.writeCache();
54
+ }
55
+ refresh() {
56
+ this.depInfo.snapshot();
57
+ }
58
+ getBabelPlugin() {
59
+ return [import_awaitImport.default, this.getAwaitImportCollectOpts()];
60
+ }
61
+ getBuildDepPlugConfig() {
62
+ const mfsu = this.mfsu;
63
+ return {
64
+ onCompileDone: () => {
65
+ if (mfsu.depBuilder.isBuilding) {
66
+ mfsu.buildDepsAgain = true;
67
+ } else {
68
+ mfsu.buildDeps().then(() => {
69
+ mfsu.onProgress({
70
+ done: true
71
+ });
72
+ }).catch((e) => {
73
+ import_utils.printHelp.runtime(e);
74
+ mfsu.onProgress({
75
+ done: true
76
+ });
77
+ });
78
+ }
79
+ }
80
+ };
81
+ }
82
+ getAwaitImportCollectOpts() {
83
+ const mfsuOpts = this.mfsu.opts;
84
+ const mfsu = this.mfsu;
85
+ return {
86
+ onTransformDeps: () => {
87
+ },
88
+ onCollect: ({
89
+ file,
90
+ data
91
+ }) => {
92
+ this.depInfo.moduleGraph.onFileChange({
93
+ file,
94
+ deps: [
95
+ ...Array.from(data.matched).map((item) => ({
96
+ file: item.sourceValue,
97
+ isDependency: true,
98
+ version: import_dep.Dep.getDepVersion({
99
+ dep: item.sourceValue,
100
+ cwd: mfsuOpts.cwd
101
+ })
102
+ })),
103
+ ...Array.from(data.unMatched).map((item) => ({
104
+ file: (0, import_getRealPath.getRealPath)({
105
+ file,
106
+ dep: item.sourceValue
107
+ }),
108
+ isDependency: false
109
+ }))
110
+ ]
111
+ });
112
+ },
113
+ exportAllMembers: mfsuOpts.exportAllMembers,
114
+ unMatchLibs: mfsuOpts.unMatchLibs,
115
+ remoteName: mfsuOpts.mfName,
116
+ alias: mfsu.alias,
117
+ externals: mfsu.externals
118
+ };
119
+ }
120
+ };
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ StrategyCompileTime
124
+ });
@@ -1,121 +1,139 @@
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
- exports.StaticAnalyzeStrategy = void 0;
7
- const utils_1 = require("@umijs/utils");
8
- const getAliasedPath_1 = require("../babelPlugins/awaitImport/getAliasedPath");
9
- const MFImport_1 = __importDefault(require("../babelPlugins/awaitImport/MFImport"));
10
- const staticDepInfo_1 = require("../staticDepInfo/staticDepInfo");
11
- class StaticAnalyzeStrategy {
12
- constructor({ mfsu, srcCodeCache }) {
13
- this.mfsu = mfsu;
14
- this.staticDepInfo = new staticDepInfo_1.StaticDepInfo({
15
- mfsu,
16
- srcCodeCache,
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
+ // strategyStaticAnalyze.ts
23
+ var strategyStaticAnalyze_exports = {};
24
+ __export(strategyStaticAnalyze_exports, {
25
+ StaticAnalyzeStrategy: () => StaticAnalyzeStrategy
26
+ });
27
+ module.exports = __toCommonJS(strategyStaticAnalyze_exports);
28
+ var import_utils = require("@umijs/utils");
29
+ var import_getAliasedPath = require("../babelPlugins/awaitImport/getAliasedPath");
30
+ var import_MFImport = __toESM(require("../babelPlugins/awaitImport/MFImport"));
31
+ var import_staticDepInfo = require("../staticDepInfo/staticDepInfo");
32
+ var StaticAnalyzeStrategy = class {
33
+ constructor({ mfsu, srcCodeCache }) {
34
+ this.mfsu = mfsu;
35
+ this.staticDepInfo = new import_staticDepInfo.StaticDepInfo({
36
+ mfsu,
37
+ srcCodeCache
38
+ });
39
+ }
40
+ init() {
41
+ this.staticDepInfo.init();
42
+ }
43
+ getDepModules() {
44
+ return this.staticDepInfo.getDepModules();
45
+ }
46
+ getCacheFilePath() {
47
+ return this.staticDepInfo.getCacheFilePath();
48
+ }
49
+ shouldBuild() {
50
+ return this.staticDepInfo.shouldBuild();
51
+ }
52
+ writeCache() {
53
+ this.staticDepInfo.writeCache();
54
+ }
55
+ getBabelPlugin() {
56
+ return [import_MFImport.default, this.getMfImportOpts()];
57
+ }
58
+ getMfImportOpts() {
59
+ const mfsu = this.mfsu;
60
+ const mfsuOpts = this.mfsu.opts;
61
+ return {
62
+ resolveImportSource: (source) => {
63
+ const depMat = this.staticDepInfo.getDependencies();
64
+ const r = (0, import_getAliasedPath.getAliasedPathWithLoopDetect)({
65
+ value: source,
66
+ alias: mfsu.alias
17
67
  });
18
- }
19
- init() {
20
- this.staticDepInfo.init();
21
- }
22
- getDepModules() {
23
- return this.staticDepInfo.getDepModules();
24
- }
25
- getCacheFilePath() {
26
- return this.staticDepInfo.getCacheFilePath();
27
- }
28
- shouldBuild() {
29
- return this.staticDepInfo.shouldBuild();
30
- }
31
- writeCache() {
32
- this.staticDepInfo.writeCache();
33
- }
34
- getBabelPlugin() {
35
- return [MFImport_1.default, this.getMfImportOpts()];
36
- }
37
- getMfImportOpts() {
38
- const mfsu = this.mfsu;
39
- const mfsuOpts = this.mfsu.opts;
40
- return {
41
- resolveImportSource: (source) => {
42
- const depMat = this.staticDepInfo.getDependencies();
43
- const r = (0, getAliasedPath_1.getAliasedPathWithLoopDetect)({
44
- value: source,
45
- alias: mfsu.alias,
46
- });
47
- const m = depMat[r];
48
- if (m) {
49
- return m.replaceValue;
50
- }
51
- return r;
52
- },
53
- exportAllMembers: mfsuOpts.exportAllMembers,
54
- unMatchLibs: mfsuOpts.unMatchLibs,
55
- remoteName: mfsuOpts.mfName,
56
- alias: mfsu.alias,
57
- externals: mfsu.externals,
58
- };
59
- }
60
- getBuildDepPlugConfig() {
61
- const mfsu = this.mfsu;
62
- return {
63
- beforeCompile: async () => {
64
- utils_1.logger.event(`[MFSU][eager] start build deps`);
65
- if (mfsu.depBuilder.isBuilding) {
66
- mfsu.buildDepsAgain = true;
67
- }
68
- else {
69
- this.staticDepInfo.consumeAllProducedEvents();
70
- mfsu
71
- .buildDeps()
72
- .then(() => {
73
- mfsu.onProgress({
74
- done: true,
75
- });
76
- })
77
- .catch((e) => {
78
- utils_1.logger.error(e);
79
- mfsu.onProgress({
80
- done: true,
81
- });
82
- });
83
- }
84
- },
85
- onFileChange: async (c) => {
86
- utils_1.logger.debug('webpack found changes modified:', c.modifiedFiles, 'removed:', c.removedFiles);
87
- // webpack init run
88
- if (!c.modifiedFiles || c.modifiedFiles.size === 0) {
89
- return;
90
- }
91
- const start = Date.now();
92
- let event = this.staticDepInfo.getProducedEvent();
93
- while (event.length === 0) {
94
- await sleep(200);
95
- event = this.staticDepInfo.getProducedEvent();
96
- if (Date.now() - start > 5000) {
97
- utils_1.logger.warn('webpack wait mfsu deps too long');
98
- break;
99
- }
100
- }
101
- },
102
- onCompileDone: () => {
103
- // fixme if mf module finished earlier than src compile
104
- },
105
- };
106
- }
107
- loadCache() {
108
- this.staticDepInfo.loadCache();
109
- }
110
- refresh() {
111
- this.staticDepInfo.snapshot();
112
- }
113
- }
114
- exports.StaticAnalyzeStrategy = StaticAnalyzeStrategy;
68
+ const m = depMat[r];
69
+ if (m) {
70
+ return m.replaceValue;
71
+ }
72
+ return r;
73
+ },
74
+ exportAllMembers: mfsuOpts.exportAllMembers,
75
+ unMatchLibs: mfsuOpts.unMatchLibs,
76
+ remoteName: mfsuOpts.mfName,
77
+ alias: mfsu.alias,
78
+ externals: mfsu.externals
79
+ };
80
+ }
81
+ getBuildDepPlugConfig() {
82
+ const mfsu = this.mfsu;
83
+ return {
84
+ beforeCompile: async () => {
85
+ import_utils.logger.event(`[MFSU][eager] start build deps`);
86
+ if (mfsu.depBuilder.isBuilding) {
87
+ mfsu.buildDepsAgain = true;
88
+ } else {
89
+ this.staticDepInfo.consumeAllProducedEvents();
90
+ mfsu.buildDeps().then(() => {
91
+ mfsu.onProgress({
92
+ done: true
93
+ });
94
+ }).catch((e) => {
95
+ import_utils.printHelp.runtime(e);
96
+ mfsu.onProgress({
97
+ done: true
98
+ });
99
+ });
100
+ }
101
+ },
102
+ onFileChange: async (c) => {
103
+ import_utils.logger.debug("webpack found changes modified:", c.modifiedFiles, "removed:", c.removedFiles);
104
+ if (!c.modifiedFiles || c.modifiedFiles.size === 0) {
105
+ return;
106
+ }
107
+ const start = Date.now();
108
+ let event = this.staticDepInfo.getProducedEvent();
109
+ while (event.length === 0) {
110
+ await sleep(200);
111
+ event = this.staticDepInfo.getProducedEvent();
112
+ if (Date.now() - start > 5e3) {
113
+ import_utils.logger.warn("webpack wait mfsu deps too long");
114
+ break;
115
+ }
116
+ }
117
+ },
118
+ onCompileDone: () => {
119
+ }
120
+ };
121
+ }
122
+ loadCache() {
123
+ this.staticDepInfo.loadCache();
124
+ }
125
+ refresh() {
126
+ this.staticDepInfo.snapshot();
127
+ }
128
+ };
115
129
  function sleep(ms) {
116
- return new Promise((resolve) => {
117
- setTimeout(() => {
118
- resolve();
119
- }, ms);
120
- });
130
+ return new Promise((resolve) => {
131
+ setTimeout(() => {
132
+ resolve();
133
+ }, ms);
134
+ });
121
135
  }
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ StaticAnalyzeStrategy
139
+ });