@umijs/plugins 4.0.7 → 4.0.8

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.
@@ -1,251 +1,230 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
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 });
24
10
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
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;
27
18
  };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.ModelUtils = exports.Model = exports.getNamespace = void 0;
30
- const parser = __importStar(require("@umijs/bundler-utils/compiled/babel/parser"));
31
- const traverse_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/traverse"));
32
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
33
- const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
34
- const fs_1 = require("fs");
35
- const path_1 = require("path");
36
- const plugin_utils_1 = require("umi/plugin-utils");
37
- const astUtils_1 = require("./astUtils");
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
+ // modelUtils.ts
23
+ var modelUtils_exports = {};
24
+ __export(modelUtils_exports, {
25
+ Model: () => Model,
26
+ ModelUtils: () => ModelUtils,
27
+ getNamespace: () => getNamespace
28
+ });
29
+ module.exports = __toCommonJS(modelUtils_exports);
30
+ var parser = __toESM(require("@umijs/bundler-utils/compiled/babel/parser"));
31
+ var import_traverse = __toESM(require("@umijs/bundler-utils/compiled/babel/traverse"));
32
+ var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
33
+ var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
34
+ var import_fs = require("fs");
35
+ var import_path = require("path");
36
+ var import_plugin_utils = require("umi/plugin-utils");
37
+ var import_astUtils = require("./astUtils");
38
38
  function getNamespace(absFilePath, absSrcPath) {
39
- const relPath = (0, plugin_utils_1.winPath)((0, path_1.relative)((0, plugin_utils_1.winPath)(absSrcPath), (0, plugin_utils_1.winPath)(absFilePath)));
40
- const parts = relPath.split('/');
41
- const dirs = parts.slice(0, -1);
42
- const file = parts[parts.length - 1];
43
- // src/pages/foo/models/bar > foo/bar
44
- const validDirs = dirs.filter((dir) => !['src', 'pages', 'models'].includes(dir));
45
- let normalizedFile = file;
46
- normalizedFile = (0, path_1.basename)(file, (0, path_1.extname)(file));
47
- // foo.model > foo
48
- if (normalizedFile.endsWith('.model')) {
49
- normalizedFile = normalizedFile.split('.').slice(0, -1).join('.');
50
- }
51
- return [...validDirs, normalizedFile].join('.');
39
+ const relPath = (0, import_plugin_utils.winPath)((0, import_path.relative)((0, import_plugin_utils.winPath)(absSrcPath), (0, import_plugin_utils.winPath)(absFilePath)));
40
+ const parts = relPath.split("/");
41
+ const dirs = parts.slice(0, -1);
42
+ const file = parts[parts.length - 1];
43
+ const validDirs = dirs.filter((dir) => !["src", "pages", "models"].includes(dir));
44
+ let normalizedFile = file;
45
+ normalizedFile = (0, import_path.basename)(file, (0, import_path.extname)(file));
46
+ if (normalizedFile.endsWith(".model")) {
47
+ normalizedFile = normalizedFile.split(".").slice(0, -1).join(".");
48
+ }
49
+ return [...validDirs, normalizedFile].join(".");
52
50
  }
53
- exports.getNamespace = getNamespace;
54
- class Model {
55
- constructor(file, absSrcPath, sort, id) {
56
- let namespace;
57
- let exportName;
58
- const [_file, meta] = file.split('#');
59
- if (meta) {
60
- const metaObj = JSON.parse(meta);
61
- namespace = metaObj.namespace;
62
- exportName = metaObj.exportName;
63
- }
64
- this.file = _file;
65
- this.id = `model_${id}`;
66
- this.namespace = namespace || getNamespace(_file, absSrcPath);
67
- this.exportName = exportName || 'default';
68
- this.deps = sort ? this.findDeps(sort) : [];
51
+ var Model = class {
52
+ constructor(file, absSrcPath, sort, id) {
53
+ let namespace;
54
+ let exportName;
55
+ const [_file, meta] = file.split("#");
56
+ if (meta) {
57
+ const metaObj = JSON.parse(meta);
58
+ namespace = metaObj.namespace;
59
+ exportName = metaObj.exportName;
69
60
  }
70
- findDeps(sort) {
71
- const content = (0, fs_1.readFileSync)(this.file, 'utf-8');
72
- // transform with esbuild first
73
- // to reduce unexpected ast problem
74
- const loader = (0, path_1.extname)(this.file).slice(1);
75
- const result = (0, esbuild_1.transformSync)(content, {
76
- loader,
77
- sourcemap: false,
78
- minify: false,
79
- });
80
- // transform with babel
81
- const deps = new Set();
82
- const ast = parser.parse(result.code, {
83
- sourceType: 'module',
84
- sourceFilename: this.file,
85
- plugins: [],
86
- });
87
- // TODO: use sort
88
- sort;
89
- (0, traverse_1.default)(ast, {
90
- CallExpression: (path) => {
91
- if (t.isIdentifier(path.node.callee, { name: 'useModel' }) &&
92
- t.isStringLiteral(path.node.arguments[0])) {
93
- deps.add(path.node.arguments[0].value);
94
- }
95
- },
96
- });
97
- return [...deps];
61
+ this.file = _file;
62
+ this.id = `model_${id}`;
63
+ this.namespace = namespace || getNamespace(_file, absSrcPath);
64
+ this.exportName = exportName || "default";
65
+ this.deps = sort ? this.findDeps(sort) : [];
66
+ }
67
+ findDeps(sort) {
68
+ const content = (0, import_fs.readFileSync)(this.file, "utf-8");
69
+ const loader = (0, import_path.extname)(this.file).slice(1);
70
+ const result = (0, import_esbuild.transformSync)(content, {
71
+ loader,
72
+ sourcemap: false,
73
+ minify: false
74
+ });
75
+ const deps = /* @__PURE__ */ new Set();
76
+ const ast = parser.parse(result.code, {
77
+ sourceType: "module",
78
+ sourceFilename: this.file,
79
+ plugins: []
80
+ });
81
+ sort;
82
+ (0, import_traverse.default)(ast, {
83
+ CallExpression: (path) => {
84
+ if (t.isIdentifier(path.node.callee, { name: "useModel" }) && t.isStringLiteral(path.node.arguments[0])) {
85
+ deps.add(path.node.arguments[0].value);
86
+ }
87
+ }
88
+ });
89
+ return [...deps];
90
+ }
91
+ };
92
+ var ModelUtils = class {
93
+ constructor(api, opts) {
94
+ this.opts = {};
95
+ this.count = 1;
96
+ this.api = api;
97
+ this.opts = opts;
98
+ }
99
+ getAllModels(opts) {
100
+ this.count = 1;
101
+ const models = [
102
+ ...this.getModels({
103
+ base: (0, import_path.join)(this.api.paths.absSrcPath, "models"),
104
+ pattern: "**/*.{ts,tsx,js,jsx}"
105
+ }),
106
+ ...this.getModels({
107
+ base: (0, import_path.join)(this.api.paths.absPagesPath),
108
+ pattern: "**/models/**/*.{ts,tsx,js,jsx}"
109
+ }),
110
+ ...this.getModels({
111
+ base: (0, import_path.join)(this.api.paths.absPagesPath),
112
+ pattern: "**/model.{ts,tsx,js,jsx}"
113
+ }),
114
+ ...opts.extraModels
115
+ ].map((file) => {
116
+ return new Model(file, this.api.paths.absSrcPath, opts.sort, this.count++);
117
+ });
118
+ const namespaces = models.map((model) => model.namespace);
119
+ if (new Set(namespaces).size !== namespaces.length) {
120
+ throw new Error(`Duplicate namespace in models: ${namespaces.sort().join(", ")}`);
98
121
  }
99
- }
100
- exports.Model = Model;
101
- class ModelUtils {
102
- constructor(api, opts) {
103
- this.opts = {};
104
- this.count = 1;
105
- this.api = api;
106
- this.opts = opts;
122
+ if (opts.sort) {
123
+ const namespaces2 = this.getSortedNamespaces(models);
124
+ models.sort((a, b) => namespaces2.indexOf(a.namespace) - namespaces2.indexOf(b.namespace));
107
125
  }
108
- getAllModels(opts) {
109
- // reset count
110
- this.count = 1;
111
- const models = [
112
- ...this.getModels({
113
- base: (0, path_1.join)(this.api.paths.absSrcPath, 'models'),
114
- pattern: '**/*.{ts,tsx,js,jsx}',
115
- }),
116
- ...this.getModels({
117
- base: (0, path_1.join)(this.api.paths.absPagesPath),
118
- pattern: '**/models/**/*.{ts,tsx,js,jsx}',
119
- }),
120
- ...this.getModels({
121
- base: (0, path_1.join)(this.api.paths.absPagesPath),
122
- pattern: '**/model.{ts,tsx,js,jsx}',
123
- }),
124
- ...opts.extraModels,
125
- ].map((file) => {
126
- return new Model(file, this.api.paths.absSrcPath, opts.sort, this.count++);
127
- });
128
- // check duplicate
129
- const namespaces = models.map((model) => model.namespace);
130
- if (new Set(namespaces).size !== namespaces.length) {
131
- throw new Error(`Duplicate namespace in models: ${namespaces.sort().join(', ')}`);
126
+ return models;
127
+ }
128
+ getSortedNamespaces(models) {
129
+ let final = [];
130
+ models.forEach((model, index) => {
131
+ const { deps, namespace } = model;
132
+ if (deps && deps.length) {
133
+ const itemGroup = [...deps, namespace];
134
+ const cannotUse = [namespace];
135
+ for (let i = 0; i <= index; i += 1) {
136
+ if (models[i].deps.filter((v) => cannotUse.includes(v)).length) {
137
+ if (!cannotUse.includes(models[i].namespace)) {
138
+ cannotUse.push(models[i].namespace);
139
+ i = -1;
140
+ }
141
+ }
132
142
  }
133
- // sort models by deps
134
- if (opts.sort) {
135
- const namespaces = this.getSortedNamespaces(models);
136
- models.sort((a, b) => namespaces.indexOf(a.namespace) - namespaces.indexOf(b.namespace));
143
+ const errorList = deps.filter((v) => cannotUse.includes(v));
144
+ if (errorList.length) {
145
+ throw Error(`Circular dependencies: ${namespace} can't use ${errorList.join(", ")}`);
137
146
  }
138
- return models;
139
- }
140
- getSortedNamespaces(models) {
141
- let final = [];
142
- models.forEach((model, index) => {
143
- const { deps, namespace } = model;
144
- if (deps && deps.length) {
145
- const itemGroup = [...deps, namespace];
146
- const cannotUse = [namespace];
147
- for (let i = 0; i <= index; i += 1) {
148
- if (models[i].deps.filter((v) => cannotUse.includes(v)).length) {
149
- if (!cannotUse.includes(models[i].namespace)) {
150
- cannotUse.push(models[i].namespace);
151
- i = -1;
152
- }
153
- }
154
- }
155
- const errorList = deps.filter((v) => cannotUse.includes(v));
156
- if (errorList.length) {
157
- throw Error(`Circular dependencies: ${namespace} can't use ${errorList.join(', ')}`);
158
- }
159
- const intersection = final.filter((v) => itemGroup.includes(v));
160
- if (intersection.length) {
161
- // first intersection
162
- const finalIndex = final.indexOf(intersection[0]);
163
- // replace with groupItem
164
- final = final
165
- .slice(0, finalIndex)
166
- .concat(itemGroup)
167
- .concat(final.slice(finalIndex + 1));
168
- }
169
- else {
170
- final.push(...itemGroup);
171
- }
172
- }
173
- if (!final.includes(namespace)) {
174
- // first occurrence append to the end
175
- final.push(namespace);
176
- }
177
- });
178
- return [...new Set(final)];
179
- }
180
- getModels(opts) {
181
- return plugin_utils_1.glob
182
- .sync(opts.pattern || '**/*.{ts,js}', {
183
- cwd: opts.base,
184
- absolute: true,
185
- })
186
- .map(plugin_utils_1.winPath)
187
- .filter((file) => {
188
- if (/\.d.ts$/.test(file))
189
- return false;
190
- if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
191
- return false;
192
- const content = (0, fs_1.readFileSync)(file, 'utf-8');
193
- return this.isModelValid({ content, file });
194
- });
195
- }
196
- isModelValid(opts) {
197
- const { file, content } = opts;
198
- if (this.opts.contentTest && this.opts.contentTest(content)) {
199
- return true;
147
+ const intersection = final.filter((v) => itemGroup.includes(v));
148
+ if (intersection.length) {
149
+ const finalIndex = final.indexOf(intersection[0]);
150
+ final = final.slice(0, finalIndex).concat(itemGroup).concat(final.slice(finalIndex + 1));
151
+ } else {
152
+ final.push(...itemGroup);
200
153
  }
201
- // transform with esbuild first
202
- // to reduce unexpected ast problem
203
- const loader = (0, path_1.extname)(file).slice(1);
204
- const result = (0, esbuild_1.transformSync)(content, {
205
- loader,
206
- sourcemap: false,
207
- minify: false,
208
- });
209
- // transform with babel
210
- let ret = false;
211
- const ast = parser.parse(result.code, {
212
- sourceType: 'module',
213
- sourceFilename: file,
214
- plugins: [],
215
- });
216
- (0, traverse_1.default)(ast, {
217
- ExportDefaultDeclaration: (path) => {
218
- let node = path.node.declaration;
219
- node = (0, astUtils_1.getIdentifierDeclaration)(node, path);
220
- if (this.opts.astTest && this.opts.astTest({ node, content })) {
221
- ret = true;
222
- }
223
- },
224
- });
225
- return ret;
154
+ }
155
+ if (!final.includes(namespace)) {
156
+ final.push(namespace);
157
+ }
158
+ });
159
+ return [...new Set(final)];
160
+ }
161
+ getModels(opts) {
162
+ return import_plugin_utils.glob.sync(opts.pattern || "**/*.{ts,js}", {
163
+ cwd: opts.base,
164
+ absolute: true
165
+ }).map(import_plugin_utils.winPath).filter((file) => {
166
+ if (/\.d.ts$/.test(file))
167
+ return false;
168
+ if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
169
+ return false;
170
+ const content = (0, import_fs.readFileSync)(file, "utf-8");
171
+ return this.isModelValid({ content, file });
172
+ });
173
+ }
174
+ isModelValid(opts) {
175
+ const { file, content } = opts;
176
+ if (this.opts.contentTest && this.opts.contentTest(content)) {
177
+ return true;
226
178
  }
227
- static getModelsContent(models) {
228
- const imports = [];
229
- const modelProps = [];
230
- models.forEach((model) => {
231
- const fileWithoutExt = (0, plugin_utils_1.winPath)((0, path_1.format)({
232
- dir: (0, path_1.dirname)(model.file),
233
- base: (0, path_1.basename)(model.file, (0, path_1.extname)(model.file)),
234
- }));
235
- if (model.exportName !== 'default') {
236
- imports.push(`import { ${model.exportName} as ${model.id} } from '${fileWithoutExt}';`);
237
- }
238
- else {
239
- imports.push(`import ${model.id} from '${fileWithoutExt}';`);
240
- }
241
- modelProps.push(`${model.id}: { namespace: '${model.namespace}', model: ${model.id} },`);
242
- });
243
- return `
244
- ${imports.join('\n')}
179
+ const loader = (0, import_path.extname)(file).slice(1);
180
+ const result = (0, import_esbuild.transformSync)(content, {
181
+ loader,
182
+ sourcemap: false,
183
+ minify: false
184
+ });
185
+ let ret = false;
186
+ const ast = parser.parse(result.code, {
187
+ sourceType: "module",
188
+ sourceFilename: file,
189
+ plugins: []
190
+ });
191
+ (0, import_traverse.default)(ast, {
192
+ ExportDefaultDeclaration: (path) => {
193
+ let node = path.node.declaration;
194
+ node = (0, import_astUtils.getIdentifierDeclaration)(node, path);
195
+ if (this.opts.astTest && this.opts.astTest({ node, content })) {
196
+ ret = true;
197
+ }
198
+ }
199
+ });
200
+ return ret;
201
+ }
202
+ static getModelsContent(models) {
203
+ const imports = [];
204
+ const modelProps = [];
205
+ models.forEach((model) => {
206
+ const fileWithoutExt = (0, import_plugin_utils.winPath)((0, import_path.format)({
207
+ dir: (0, import_path.dirname)(model.file),
208
+ base: (0, import_path.basename)(model.file, (0, import_path.extname)(model.file))
209
+ }));
210
+ if (model.exportName !== "default") {
211
+ imports.push(`import { ${model.exportName} as ${model.id} } from '${fileWithoutExt}';`);
212
+ } else {
213
+ imports.push(`import ${model.id} from '${fileWithoutExt}';`);
214
+ }
215
+ modelProps.push(`${model.id}: { namespace: '${model.namespace}', model: ${model.id} },`);
216
+ });
217
+ return `
218
+ ${imports.join("\n")}
245
219
 
246
220
  export const models = {
247
- ${modelProps.join('\n')}
221
+ ${modelProps.join("\n")}
248
222
  } as const`;
249
- }
250
- }
251
- exports.ModelUtils = ModelUtils;
223
+ }
224
+ };
225
+ // Annotate the CommonJS export names for ESM import in node:
226
+ 0 && (module.exports = {
227
+ Model,
228
+ ModelUtils,
229
+ getNamespace
230
+ });
@@ -1,15 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveProjectDep = void 0;
4
- const path_1 = require("path");
5
- const plugin_utils_1 = require("umi/plugin-utils");
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
+ // resolveProjectDep.ts
20
+ var resolveProjectDep_exports = {};
21
+ __export(resolveProjectDep_exports, {
22
+ resolveProjectDep: () => resolveProjectDep
23
+ });
24
+ module.exports = __toCommonJS(resolveProjectDep_exports);
25
+ var import_path = require("path");
26
+ var import_plugin_utils = require("umi/plugin-utils");
6
27
  function resolveProjectDep(opts) {
7
- var _a, _b;
8
- if (((_a = opts.pkg.dependencies) === null || _a === void 0 ? void 0 : _a[opts.dep]) ||
9
- ((_b = opts.pkg.devDependencies) === null || _b === void 0 ? void 0 : _b[opts.dep])) {
10
- return (0, path_1.dirname)(plugin_utils_1.resolve.sync(`${opts.dep}/package.json`, {
11
- basedir: opts.cwd,
12
- }));
13
- }
28
+ var _a, _b;
29
+ if (((_a = opts.pkg.dependencies) == null ? void 0 : _a[opts.dep]) || ((_b = opts.pkg.devDependencies) == null ? void 0 : _b[opts.dep])) {
30
+ return (0, import_path.dirname)(import_plugin_utils.resolve.sync(`${opts.dep}/package.json`, {
31
+ basedir: opts.cwd
32
+ }));
33
+ }
14
34
  }
15
- exports.resolveProjectDep = resolveProjectDep;
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ resolveProjectDep
38
+ });
@@ -1,11 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withTmpPath = void 0;
4
- const path_1 = require("path");
5
- const plugin_utils_1 = require("umi/plugin-utils");
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
+ // withTmpPath.ts
20
+ var withTmpPath_exports = {};
21
+ __export(withTmpPath_exports, {
22
+ withTmpPath: () => withTmpPath
23
+ });
24
+ module.exports = __toCommonJS(withTmpPath_exports);
25
+ var import_path = require("path");
26
+ var import_plugin_utils = require("umi/plugin-utils");
6
27
  function withTmpPath(opts) {
7
- return (0, plugin_utils_1.winPath)((0, path_1.join)(opts.api.paths.absTmpPath, opts.api.plugin.key && !opts.noPluginDir
8
- ? `plugin-${opts.api.plugin.key}`
9
- : '', opts.path));
28
+ return (0, import_plugin_utils.winPath)((0, import_path.join)(opts.api.paths.absTmpPath, opts.api.plugin.key && !opts.noPluginDir ? `plugin-${opts.api.plugin.key}` : "", opts.path));
10
29
  }
11
- exports.withTmpPath = withTmpPath;
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ withTmpPath
33
+ });
@@ -90,7 +90,8 @@ export const MicroApp = forwardRef(
90
90
 
91
91
  // 优先使用 alias 名匹配,fallback 到 name 匹配
92
92
  const name = componentProps[appNameKeyAlias] || componentProps.name;
93
- const isCurrentApp = (app: any) => app[appNameKeyAlias] === name || app.name === name;
93
+ const isCurrentApp = (app: any) =>
94
+ app[appNameKeyAlias] === name || app.name === name;
94
95
 
95
96
  const [loading, setLoading] = useState(true);
96
97
  const [error, setError] = useState<any>(null);
@@ -143,13 +144,6 @@ export const MicroApp = forwardRef(
143
144
  setComponentError(null);
144
145
  setLoading(true);
145
146
  const configuration = {
146
- fetch(url) {
147
- return window.fetch(url, {
148
- headers: {
149
- accept: 'text/html',
150
- },
151
- });
152
- },
153
147
  globalContext: window,
154
148
  ...globalSettings,
155
149
  ...settingsFromProps,
@@ -178,11 +172,16 @@ export const MicroApp = forwardRef(
178
172
  if (noneMounted) {
179
173
  if (Array.isArray(prefetch)) {
180
174
  const specialPrefetchApps = apps.filter(
181
- (app) => !isCurrentApp(app) && (prefetch.indexOf(app[appNameKeyAlias]) !== -1 || prefetch.indexOf(app.name) !== -1)
175
+ (app) =>
176
+ !isCurrentApp(app) &&
177
+ (prefetch.indexOf(app[appNameKeyAlias]) !== -1 ||
178
+ prefetch.indexOf(app.name) !== -1),
182
179
  );
183
180
  prefetchApps(specialPrefetchApps, configuration);
184
181
  } else {
185
- const otherNotMountedApps = apps.filter((app) => !isCurrentApp(app));
182
+ const otherNotMountedApps = apps.filter(
183
+ (app) => !isCurrentApp(app),
184
+ );
186
185
  prefetchApps(otherNotMountedApps, configuration);
187
186
  }
188
187
  noneMounted = false;
@@ -73,7 +73,7 @@ export function genMount(mountElementId: string) {
73
73
  await slaveRuntime.mount(props);
74
74
  }
75
75
 
76
- const { type, ...historyOpts } = props?.history;
76
+ const { type, ...historyOpts } = props?.history || {};
77
77
 
78
78
  // 更新 clientRender 配置
79
79
  const clientRenderOpts = {