@umijs/mfsu 4.0.0-beta.8 → 4.0.0-canary-20240513.3

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 (100) hide show
  1. package/compiled/is-absolute-url/LICENSE +9 -0
  2. package/compiled/is-absolute-url/index.d.ts +20 -0
  3. package/compiled/is-absolute-url/index.js +1 -0
  4. package/compiled/is-absolute-url/package.json +1 -0
  5. package/compiled/mrmime/package.json +1 -1
  6. package/compiled/webpack-virtual-modules/index.js +1 -1
  7. package/compiled/webpack-virtual-modules/package.json +1 -1
  8. package/dist/babelPlugins/awaitImport/MFImport.d.ts +24 -0
  9. package/dist/babelPlugins/awaitImport/MFImport.js +66 -0
  10. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
  11. package/dist/babelPlugins/awaitImport/awaitImport.js +111 -112
  12. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +3 -1
  13. package/dist/babelPlugins/awaitImport/checkMatch.js +166 -109
  14. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +2 -2
  15. package/dist/babelPlugins/awaitImport/getAliasedPath.js +44 -33
  16. package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
  17. package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
  18. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +62 -47
  19. package/dist/constants.d.ts +1 -0
  20. package/dist/constants.js +50 -10
  21. package/dist/dep/dep.d.ts +11 -4
  22. package/dist/dep/dep.js +118 -80
  23. package/dist/dep/getCJSExports.js +83 -47
  24. package/dist/dep/getExposeFromContent.d.ts +0 -1
  25. package/dist/dep/getExposeFromContent.js +99 -74
  26. package/dist/dep/getModuleExports.js +58 -43
  27. package/dist/depBuilder/depBuilder.d.ts +6 -2
  28. package/dist/depBuilder/depBuilder.js +222 -158
  29. package/dist/depBuilder/getESBuildEntry.d.ts +1 -1
  30. package/dist/depBuilder/getESBuildEntry.js +50 -14
  31. package/dist/depInfo.d.ts +20 -6
  32. package/dist/depInfo.js +90 -39
  33. package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
  34. package/dist/esbuildHandlers/autoCssModules.js +48 -0
  35. package/dist/esbuildHandlers/awaitImport/index.d.ts +15 -0
  36. package/dist/esbuildHandlers/awaitImport/index.js +86 -0
  37. package/dist/index.d.ts +3 -2
  38. package/dist/index.js +35 -13
  39. package/dist/loader/esbuild.d.ts +5 -0
  40. package/dist/loader/esbuild.js +79 -0
  41. package/dist/mfsu/mfsu.d.ts +69 -0
  42. package/dist/mfsu/mfsu.js +319 -0
  43. package/dist/mfsu/strategyCompileTime.d.ts +20 -0
  44. package/dist/mfsu/strategyCompileTime.js +142 -0
  45. package/dist/mfsu/strategyStaticAnalyze.d.ts +24 -0
  46. package/dist/mfsu/strategyStaticAnalyze.js +196 -0
  47. package/dist/moduleGraph.d.ts +6 -9
  48. package/dist/moduleGraph.js +228 -178
  49. package/dist/staticDepInfo/importParser.d.ts +4 -0
  50. package/dist/staticDepInfo/importParser.js +28 -0
  51. package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +15 -0
  52. package/dist/staticDepInfo/simulations/babel-plugin-import.js +118 -0
  53. package/dist/staticDepInfo/staticDepInfo.d.ts +61 -0
  54. package/dist/staticDepInfo/staticDepInfo.js +274 -0
  55. package/dist/types.d.ts +12 -0
  56. package/dist/types.js +33 -8
  57. package/dist/utils/makeArray.js +29 -5
  58. package/dist/utils/resolveUtils.d.ts +1 -0
  59. package/dist/utils/resolveUtils.js +104 -0
  60. package/dist/utils/trimFileContent.js +29 -5
  61. package/dist/utils/webpackUtils.d.ts +3 -0
  62. package/dist/utils/webpackUtils.js +80 -0
  63. package/dist/webpackPlugins/buildDepPlugin.d.ts +4 -3
  64. package/dist/webpackPlugins/buildDepPlugin.js +61 -17
  65. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +1 -1
  66. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +47 -19
  67. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +55 -27
  68. package/dist/webpackPlugins/writeCachePlugin.js +45 -15
  69. package/package.json +32 -28
  70. package/vendors/importParser/_importParser.js +683 -0
  71. package/vendors/importParser/importParser.jison +105 -0
  72. package/dist/babelPlugins/autoExport.d.ts +0 -7
  73. package/dist/babelPlugins/autoExport.d.ts.map +0 -1
  74. package/dist/babelPlugins/autoExport.js +0 -61
  75. package/dist/babelPlugins/awaitImport/awaitImport.d.ts.map +0 -1
  76. package/dist/babelPlugins/awaitImport/checkMatch.d.ts.map +0 -1
  77. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts.map +0 -1
  78. package/dist/babelPlugins/awaitImport/getRealPath.d.ts.map +0 -1
  79. package/dist/babelPlugins/awaitImport/isExternals.d.ts.map +0 -1
  80. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts.map +0 -1
  81. package/dist/constants.d.ts.map +0 -1
  82. package/dist/dep/dep.d.ts.map +0 -1
  83. package/dist/dep/getCJSExports.d.ts.map +0 -1
  84. package/dist/dep/getExposeFromContent.d.ts.map +0 -1
  85. package/dist/dep/getModuleExports.d.ts.map +0 -1
  86. package/dist/depBuilder/depBuilder.d.ts.map +0 -1
  87. package/dist/depBuilder/getESBuildEntry.d.ts.map +0 -1
  88. package/dist/depInfo.d.ts.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/mfsu.d.ts +0 -55
  91. package/dist/mfsu.d.ts.map +0 -1
  92. package/dist/mfsu.js +0 -173
  93. package/dist/moduleGraph.d.ts.map +0 -1
  94. package/dist/types.d.ts.map +0 -1
  95. package/dist/utils/makeArray.d.ts.map +0 -1
  96. package/dist/utils/trimFileContent.d.ts.map +0 -1
  97. package/dist/webpackPlugins/buildDepPlugin.d.ts.map +0 -1
  98. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts.map +0 -1
  99. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts.map +0 -1
  100. package/dist/webpackPlugins/writeCachePlugin.d.ts.map +0 -1
@@ -0,0 +1,61 @@
1
+ import { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
2
+ import { checkMatch } from '../babelPlugins/awaitImport/checkMatch';
3
+ import { MFSU } from '../mfsu/mfsu';
4
+ declare type FileChangeEvent = {
5
+ event: 'unlink' | 'change' | 'add';
6
+ path: string;
7
+ };
8
+ declare type MergedCodeInfo = {
9
+ imports: readonly ImportSpecifier[];
10
+ code: string;
11
+ events: FileChangeEvent[];
12
+ };
13
+ declare type AutoUpdateSrcCodeCache = {
14
+ register(listener: (info: MergedCodeInfo) => void): void;
15
+ getMergedCode(): MergedCodeInfo;
16
+ handleFileChangeEvents(events: FileChangeEvent[]): void;
17
+ replayChangeEvents(): FileChangeEvent[];
18
+ getSrcPath(): string;
19
+ };
20
+ interface IOpts {
21
+ mfsu: MFSU;
22
+ srcCodeCache: AutoUpdateSrcCodeCache;
23
+ safeList?: string[];
24
+ }
25
+ export declare type Match = ReturnType<typeof checkMatch> & {
26
+ version: string;
27
+ };
28
+ export declare class StaticDepInfo {
29
+ opts: IOpts;
30
+ private readonly cacheFilePath;
31
+ private mfsu;
32
+ private readonly include;
33
+ private currentDep;
34
+ private builtWithDep;
35
+ private cacheDependency;
36
+ private produced;
37
+ private readonly cwd;
38
+ private readonly runtimeSimulations;
39
+ constructor(opts: IOpts);
40
+ getProducedEvent(): {
41
+ changes: unknown[];
42
+ }[];
43
+ consumeAllProducedEvents(): void;
44
+ shouldBuild(): false | "cacheDependency has changed" | "dependencies changed";
45
+ getDepModules(): Record<string, {
46
+ file: string;
47
+ version: string;
48
+ }>;
49
+ snapshot(): void;
50
+ loadCache(): void;
51
+ writeCache(): void;
52
+ getCacheFilePath(): string;
53
+ getDependencies(): Record<string, Match>;
54
+ init(): void;
55
+ private _getDependencies;
56
+ private simulateRuntimeTransform;
57
+ private appendIncludeList;
58
+ allRuntimeHelpers(): Promise<void>;
59
+ setBabelPluginImportConfig(config: Map<string, any>): void;
60
+ }
61
+ export {};
@@ -0,0 +1,274 @@
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 });
10
+ };
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(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/staticDepInfo/staticDepInfo.ts
30
+ var staticDepInfo_exports = {};
31
+ __export(staticDepInfo_exports, {
32
+ StaticDepInfo: () => StaticDepInfo
33
+ });
34
+ module.exports = __toCommonJS(staticDepInfo_exports);
35
+ var import_utils = require("@umijs/utils");
36
+ var import_fs = require("fs");
37
+ var import_why = __toESM(require("is-equal/why"));
38
+ var import_path = require("path");
39
+ var import_checkMatch = require("../babelPlugins/awaitImport/checkMatch");
40
+ var import_dep = require("../dep/dep");
41
+ var import_babel_plugin_import = __toESM(require("./simulations/babel-plugin-import"));
42
+ var StaticDepInfo = class {
43
+ constructor(opts) {
44
+ this.currentDep = {};
45
+ this.builtWithDep = {};
46
+ this.cacheDependency = {};
47
+ this.produced = [];
48
+ this.mfsu = opts.mfsu;
49
+ this.include = this.mfsu.opts.include || [];
50
+ this.opts = opts;
51
+ this.cacheFilePath = (0, import_path.join)(
52
+ this.opts.mfsu.opts.tmpBase,
53
+ "MFSU_CACHE_v4.json"
54
+ );
55
+ this.cwd = this.mfsu.opts.cwd;
56
+ opts.srcCodeCache.register((info) => {
57
+ this.currentDep = this._getDependencies(info.code, info.imports);
58
+ });
59
+ this.runtimeSimulations = [];
60
+ }
61
+ getProducedEvent() {
62
+ return this.produced;
63
+ }
64
+ consumeAllProducedEvents() {
65
+ this.produced = [];
66
+ }
67
+ shouldBuild() {
68
+ const currentCacheDep = this.opts.mfsu.opts.getCacheDependency();
69
+ if (!import_utils.lodash.isEqual(this.cacheDependency, currentCacheDep)) {
70
+ if (process.env.DEBUG_UMI) {
71
+ const reason = (0, import_why.default)(this.cacheDependency, currentCacheDep);
72
+ import_utils.logger.info(
73
+ "[MFSU][eager]: isEqual(cacheDependency,currentCacheDep) === false, because ",
74
+ reason
75
+ );
76
+ }
77
+ return "cacheDependency has changed";
78
+ }
79
+ if (import_utils.lodash.isEqual(this.builtWithDep, this.currentDep)) {
80
+ return false;
81
+ } else {
82
+ if (process.env.DEBUG_UMI) {
83
+ const reason = (0, import_why.default)(this.builtWithDep, this.currentDep);
84
+ import_utils.logger.info(
85
+ "[MFSU][eager]: isEqual(oldDep,newDep) === false, because ",
86
+ reason
87
+ );
88
+ }
89
+ return "dependencies changed";
90
+ }
91
+ }
92
+ getDepModules() {
93
+ const map = this.getDependencies();
94
+ const staticDeps = {};
95
+ const keys = Object.keys(map);
96
+ for (const k of keys) {
97
+ staticDeps[k] = {
98
+ file: k,
99
+ version: map[k].version
100
+ };
101
+ }
102
+ return staticDeps;
103
+ }
104
+ snapshot() {
105
+ this.builtWithDep = this.currentDep;
106
+ this.cacheDependency = this.mfsu.opts.getCacheDependency();
107
+ }
108
+ loadCache() {
109
+ if ((0, import_fs.existsSync)(this.cacheFilePath)) {
110
+ try {
111
+ const { dep = {}, cacheDependency = {} } = JSON.parse(
112
+ (0, import_fs.readFileSync)(this.cacheFilePath, "utf-8")
113
+ );
114
+ this.builtWithDep = dep;
115
+ this.cacheDependency = cacheDependency;
116
+ import_utils.logger.info("[MFSU][eager] restored cache");
117
+ } catch (e) {
118
+ import_utils.logger.warn(
119
+ "[MFSU][eager] restore cache failed, fallback to Empty dependency",
120
+ e
121
+ );
122
+ }
123
+ }
124
+ }
125
+ writeCache() {
126
+ import_utils.fsExtra.mkdirpSync((0, import_path.dirname)(this.cacheFilePath));
127
+ const newContent = JSON.stringify(
128
+ {
129
+ dep: this.builtWithDep,
130
+ cacheDependency: this.cacheDependency
131
+ },
132
+ null,
133
+ 2
134
+ );
135
+ if ((0, import_fs.existsSync)(this.cacheFilePath) && (0, import_fs.readFileSync)(this.cacheFilePath, "utf-8") === newContent) {
136
+ return;
137
+ }
138
+ import_utils.logger.info("[MFSU][eager] write cache");
139
+ (0, import_fs.writeFileSync)(this.cacheFilePath, newContent, "utf-8");
140
+ }
141
+ getCacheFilePath() {
142
+ return this.cacheFilePath;
143
+ }
144
+ getDependencies() {
145
+ return this.currentDep;
146
+ }
147
+ init() {
148
+ const merged = this.opts.srcCodeCache.getMergedCode();
149
+ this.currentDep = this._getDependencies(merged.code, merged.imports);
150
+ }
151
+ _getDependencies(bigCodeString, imports) {
152
+ const start = Date.now();
153
+ const cwd = this.mfsu.opts.cwd;
154
+ const mfsuOpts = this.mfsu.opts;
155
+ const userUnMatches = mfsuOpts.unMatchLibs || [];
156
+ const sharedUnMatches = Object.keys(mfsuOpts.shared || {});
157
+ const remoteAliasUnMatches = (mfsuOpts.remoteAliases || []).map(
158
+ (str) => new RegExp(`^${str}`)
159
+ );
160
+ const unMatches = [
161
+ ...userUnMatches,
162
+ ...sharedUnMatches,
163
+ ...remoteAliasUnMatches
164
+ ];
165
+ const opts = {
166
+ exportAllMembers: this.mfsu.opts.exportAllMembers,
167
+ unMatchLibs: unMatches,
168
+ remoteName: this.mfsu.opts.mfName,
169
+ alias: this.mfsu.alias,
170
+ externals: this.mfsu.externals
171
+ };
172
+ const matched = {};
173
+ const unMatched = /* @__PURE__ */ new Set();
174
+ const pkgNames = this.runtimeSimulations.map(
175
+ ({ packageName }) => packageName
176
+ );
177
+ const groupedMockImports = {};
178
+ for (const imp of imports) {
179
+ if (!imp.n) {
180
+ continue;
181
+ }
182
+ if (pkgNames.indexOf(imp.n) >= 0) {
183
+ const name = imp.n;
184
+ if (groupedMockImports[name]) {
185
+ groupedMockImports[name].push(imp);
186
+ } else {
187
+ groupedMockImports[name] = [imp];
188
+ }
189
+ continue;
190
+ }
191
+ if (unMatched.has(imp.n)) {
192
+ continue;
193
+ }
194
+ if (matched[imp.n]) {
195
+ continue;
196
+ }
197
+ const match = (0, import_checkMatch.checkMatch)({
198
+ value: imp.n,
199
+ depth: 1,
200
+ filename: "_.js",
201
+ opts
202
+ });
203
+ if (match.isMatch) {
204
+ matched[match.value] = {
205
+ ...match,
206
+ version: import_dep.Dep.getDepVersion({
207
+ dep: match.value,
208
+ cwd
209
+ })
210
+ };
211
+ } else {
212
+ unMatched.add(imp.n);
213
+ }
214
+ }
215
+ this.simulateRuntimeTransform(matched, groupedMockImports, bigCodeString);
216
+ this.appendIncludeList(matched, opts);
217
+ import_utils.logger.debug("[MFSU][eager] _getDependencies costs", Date.now() - start);
218
+ return matched;
219
+ }
220
+ simulateRuntimeTransform(matched, groupedImports, rawCode) {
221
+ for (const mock of this.runtimeSimulations) {
222
+ const name = mock.packageName;
223
+ const pathToVersion = (dep) => {
224
+ return import_dep.Dep.getDepVersion({
225
+ dep,
226
+ cwd: this.cwd
227
+ });
228
+ };
229
+ const ms = mock.handleImports({
230
+ imports: groupedImports[name],
231
+ rawCode,
232
+ alias: this.mfsu.alias,
233
+ mfName: this.mfsu.opts.mfName,
234
+ pathToVersion
235
+ });
236
+ for (const m of ms) {
237
+ matched[m.value] = m;
238
+ }
239
+ }
240
+ }
241
+ appendIncludeList(matched, opts) {
242
+ for (const p of this.include) {
243
+ const match = (0, import_checkMatch.checkMatch)({
244
+ value: p,
245
+ depth: 1,
246
+ filename: "_.js",
247
+ opts
248
+ });
249
+ if (match.isMatch) {
250
+ matched[match.value] = {
251
+ ...match,
252
+ version: import_dep.Dep.getDepVersion({
253
+ dep: match.value,
254
+ cwd: this.cwd
255
+ })
256
+ };
257
+ }
258
+ }
259
+ }
260
+ async allRuntimeHelpers() {
261
+ }
262
+ setBabelPluginImportConfig(config) {
263
+ for (const [key, c] of config.entries()) {
264
+ this.runtimeSimulations.push({
265
+ packageName: key,
266
+ handleImports: (0, import_babel_plugin_import.default)(c)
267
+ });
268
+ }
269
+ }
270
+ };
271
+ // Annotate the CommonJS export names for ESM import in node:
272
+ 0 && (module.exports = {
273
+ StaticDepInfo
274
+ });
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/dist/types.js CHANGED
@@ -1,8 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Mode = void 0;
4
- var Mode;
5
- (function (Mode) {
6
- Mode["development"] = "development";
7
- Mode["production"] = "production";
8
- })(Mode = exports.Mode || (exports.Mode = {}));
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/types.ts
20
+ var types_exports = {};
21
+ __export(types_exports, {
22
+ Mode: () => Mode
23
+ });
24
+ module.exports = __toCommonJS(types_exports);
25
+ var Mode = /* @__PURE__ */ ((Mode2) => {
26
+ Mode2["development"] = "development";
27
+ Mode2["production"] = "production";
28
+ return Mode2;
29
+ })(Mode || {});
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ Mode
33
+ });
@@ -1,7 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeArray = void 0;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/utils/makeArray.ts
20
+ var makeArray_exports = {};
21
+ __export(makeArray_exports, {
22
+ makeArray: () => makeArray
23
+ });
24
+ module.exports = __toCommonJS(makeArray_exports);
4
25
  function makeArray(item) {
5
- return Array.isArray(item) ? item : [item];
26
+ return Array.isArray(item) ? item : [item];
6
27
  }
7
- exports.makeArray = makeArray;
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ makeArray
31
+ });
@@ -0,0 +1 @@
1
+ export declare function resolveFromContexts(contexts: string[], path: string): Promise<string>;
@@ -0,0 +1,104 @@
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 });
10
+ };
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(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/utils/resolveUtils.ts
30
+ var resolveUtils_exports = {};
31
+ __export(resolveUtils_exports, {
32
+ resolveFromContexts: () => resolveFromContexts
33
+ });
34
+ module.exports = __toCommonJS(resolveUtils_exports);
35
+ var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
36
+ var ORDERED_MAIN_FIELDS = ["browser", "module", "main"];
37
+ var SUPPORTED_EXTS = [".wasm", ".mjs", ".js", ".jsx", ".ts", ".tsx", ".json"];
38
+ var EXPORTS_FIELDS = ["exports"];
39
+ var browserResolver = import_enhanced_resolve.default.create({
40
+ mainFields: ORDERED_MAIN_FIELDS,
41
+ extensions: SUPPORTED_EXTS,
42
+ exportsFields: EXPORTS_FIELDS,
43
+ conditionNames: ["browser", "import"],
44
+ symlinks: false
45
+ });
46
+ var esmResolver = import_enhanced_resolve.default.create({
47
+ mainFields: ORDERED_MAIN_FIELDS,
48
+ extensions: SUPPORTED_EXTS,
49
+ exportsFields: EXPORTS_FIELDS,
50
+ conditionNames: ["module"],
51
+ symlinks: false
52
+ });
53
+ var cjsResolver = import_enhanced_resolve.default.create({
54
+ mainFields: ORDERED_MAIN_FIELDS,
55
+ extensions: SUPPORTED_EXTS,
56
+ exportsFields: EXPORTS_FIELDS,
57
+ conditionNames: ["require", "node"],
58
+ symlinks: false
59
+ });
60
+ async function resolveWith(resolver, context, path) {
61
+ return new Promise((resolve2, reject) => {
62
+ resolver(
63
+ context,
64
+ path,
65
+ (err, result) => err ? reject(err) : resolve2(result)
66
+ );
67
+ });
68
+ }
69
+ async function tryResolvers(rs, context, path) {
70
+ let result = "";
71
+ let lastError = null;
72
+ for (const r of rs) {
73
+ try {
74
+ result = await resolveWith(r, context, path);
75
+ return result;
76
+ } catch (e) {
77
+ lastError = e;
78
+ }
79
+ }
80
+ if (!result) {
81
+ throw lastError || Error(`can't resolve ${path} from ${context}`);
82
+ }
83
+ return result;
84
+ }
85
+ async function resolve(context, path) {
86
+ return await tryResolvers(
87
+ [browserResolver, esmResolver, cjsResolver],
88
+ context,
89
+ path
90
+ );
91
+ }
92
+ async function resolveFromContexts(contexts, path) {
93
+ for (const context of contexts) {
94
+ try {
95
+ return await resolve(context, path);
96
+ } catch (e) {
97
+ }
98
+ }
99
+ throw new Error(`Can't resolve ${path} from ${contexts.join(", ")}`);
100
+ }
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ resolveFromContexts
104
+ });
@@ -1,7 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trimFileContent = void 0;
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/utils/trimFileContent.ts
20
+ var trimFileContent_exports = {};
21
+ __export(trimFileContent_exports, {
22
+ trimFileContent: () => trimFileContent
23
+ });
24
+ module.exports = __toCommonJS(trimFileContent_exports);
4
25
  function trimFileContent(content) {
5
- return content.trim() + '\n';
26
+ return content.trim() + "\n";
6
27
  }
7
- exports.trimFileContent = trimFileContent;
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ trimFileContent
31
+ });
@@ -0,0 +1,3 @@
1
+ import { Configuration } from 'webpack';
2
+ export declare function extractBabelPluginImportOptions(webpackConfig: Configuration): Map<string, any>;
3
+ export declare function getResolver(opts: Configuration): (path: string) => string | false;
@@ -0,0 +1,80 @@
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 });
10
+ };
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(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/utils/webpackUtils.ts
30
+ var webpackUtils_exports = {};
31
+ __export(webpackUtils_exports, {
32
+ extractBabelPluginImportOptions: () => extractBabelPluginImportOptions,
33
+ getResolver: () => getResolver
34
+ });
35
+ module.exports = __toCommonJS(webpackUtils_exports);
36
+ var import_webpack = require("webpack");
37
+ var import_utils = require("@umijs/utils");
38
+ var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
39
+ var { property, compact, flatMap } = import_utils.lodash;
40
+ function extractBabelPluginImportOptions(webpackConfig) {
41
+ var _a;
42
+ const rules = ((_a = webpackConfig.module) == null ? void 0 : _a.rules) || [];
43
+ const uses = compact(flatMap(rules, property(["use"]))).filter(
44
+ (u) => {
45
+ var _a2;
46
+ return ((_a2 = u == null ? void 0 : u.loader) == null ? void 0 : _a2.indexOf("babel-loader")) >= 0;
47
+ }
48
+ );
49
+ const pluginConfigs = compact(
50
+ flatMap(uses, property(["options", "plugins"]))
51
+ ).filter(
52
+ (p) => {
53
+ var _a2, _b;
54
+ return Array.isArray(p) && ((_b = (_a2 = p[0]) == null ? void 0 : _a2.indexOf) == null ? void 0 : _b.call(_a2, "babel-plugin-import")) >= 0;
55
+ }
56
+ );
57
+ const configs = /* @__PURE__ */ new Map();
58
+ for (const c of pluginConfigs) {
59
+ !configs.has(c[1].libraryName) && configs.set(c[1].libraryName, c[1]);
60
+ }
61
+ return configs;
62
+ }
63
+ function getResolver(opts) {
64
+ const context = opts.context ?? process.cwd();
65
+ const resolveDefaults = {
66
+ extensions: [".tsx", ".ts", ".jsx", ".js"],
67
+ // keep same with previous mfsu version
68
+ roots: [context]
69
+ };
70
+ const mergedResolve = import_webpack.util.cleverMerge(resolveDefaults, opts.resolve);
71
+ const resolver = import_enhanced_resolve.default.create.sync(mergedResolve);
72
+ return (path) => {
73
+ return resolver(context, path);
74
+ };
75
+ }
76
+ // Annotate the CommonJS export names for ESM import in node:
77
+ 0 && (module.exports = {
78
+ extractBabelPluginImportOptions,
79
+ getResolver
80
+ });
@@ -1,10 +1,11 @@
1
1
  import type { Compiler } from 'webpack';
2
- interface IOpts {
2
+ export interface IBuildDepPluginOpts {
3
3
  onCompileDone: Function;
4
+ onFileChange?: (c: Compiler) => Promise<any>;
5
+ beforeCompile?: () => Promise<any>;
4
6
  }
5
7
  export declare class BuildDepPlugin {
6
8
  private opts;
7
- constructor(opts: IOpts);
9
+ constructor(opts: IBuildDepPluginOpts);
8
10
  apply(compiler: Compiler): void;
9
11
  }
10
- export {};