@umijs/mfsu 4.0.0-rc.2 → 4.0.0-rc.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,54 +1,38 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.esbuildLoader = void 0;
24
4
  const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
25
5
  const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
26
6
  const path_1 = require("path");
27
- function esbuildTranspiler(source) {
7
+ async function esbuildTranspiler(source) {
28
8
  var _a;
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const done = this.async();
31
- const options = this.getOptions();
32
- const { handler = [], implementation } = options, otherOptions = __rest(options, ["handler", "implementation"]);
33
- const transform = (implementation === null || implementation === void 0 ? void 0 : implementation.transform) || esbuild_1.transform;
34
- const filePath = this.resourcePath;
35
- const ext = (0, path_1.extname)(filePath).slice(1);
36
- const transformOptions = Object.assign(Object.assign({}, otherOptions), { target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015', loader: ext !== null && ext !== void 0 ? ext : 'js', sourcemap: this.sourceMap, sourcefile: filePath });
37
- try {
38
- let { code, map } = yield transform(source, transformOptions);
39
- if (handler.length) {
40
- yield es_module_lexer_1.init;
41
- handler.forEach((handle) => {
42
- const [imports, exports] = (0, es_module_lexer_1.parse)(code);
43
- code = handle({ code, imports, exports, filePath });
44
- });
45
- }
46
- done(null, code, map && JSON.parse(map));
47
- }
48
- catch (error) {
49
- done(error);
9
+ const done = this.async();
10
+ const options = this.getOptions();
11
+ const { handler = [], implementation, ...otherOptions } = options;
12
+ const transform = (implementation === null || implementation === void 0 ? void 0 : implementation.transform) || esbuild_1.transform;
13
+ const filePath = this.resourcePath;
14
+ const ext = (0, path_1.extname)(filePath).slice(1);
15
+ const transformOptions = {
16
+ ...otherOptions,
17
+ target: (_a = options.target) !== null && _a !== void 0 ? _a : 'es2015',
18
+ loader: ext !== null && ext !== void 0 ? ext : 'js',
19
+ sourcemap: this.sourceMap,
20
+ sourcefile: filePath,
21
+ };
22
+ try {
23
+ let { code, map } = await transform(source, transformOptions);
24
+ if (handler.length) {
25
+ await es_module_lexer_1.init;
26
+ handler.forEach((handle) => {
27
+ const [imports, exports] = (0, es_module_lexer_1.parse)(code);
28
+ code = handle({ code, imports, exports, filePath });
29
+ });
50
30
  }
51
- });
31
+ done(null, code, map && JSON.parse(map));
32
+ }
33
+ catch (error) {
34
+ done(error);
35
+ }
52
36
  }
53
37
  exports.default = esbuildTranspiler;
54
38
  exports.esbuildLoader = __filename;
package/dist/mfsu.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import type { NextFunction, Request, Response } from 'express';
1
+ import type { NextFunction, Request, Response } from '@umijs/bundler-utils/compiled/express';
2
2
  import webpack, { Configuration } from 'webpack';
3
- import autoExport from './babelPlugins/autoExport';
4
3
  import awaitImport from './babelPlugins/awaitImport/awaitImport';
5
4
  import { DepBuilder } from './depBuilder/depBuilder';
6
5
  import { DepInfo } from './depInfo';
@@ -10,6 +9,7 @@ interface IOpts {
10
9
  excludeNodeNatives?: boolean;
11
10
  exportAllMembers?: Record<string, string[]>;
12
11
  getCacheDependency?: Function;
12
+ onMFSUProgress?: Function;
13
13
  mfName?: string;
14
14
  mode?: Mode;
15
15
  tmpBase?: string;
@@ -26,6 +26,10 @@ export declare class MFSU {
26
26
  depInfo: DepInfo;
27
27
  depBuilder: DepBuilder;
28
28
  depConfig: Configuration | null;
29
+ buildDepsAgain: boolean;
30
+ progress: any;
31
+ onProgress: Function;
32
+ publicPath: string;
29
33
  constructor(opts: IOpts);
30
34
  asyncImport(content: string): string;
31
35
  setWebpackConfig(opts: {
@@ -35,7 +39,7 @@ export declare class MFSU {
35
39
  buildDeps(): Promise<void>;
36
40
  getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
37
41
  private getAwaitImportCollectOpts;
38
- getBabelPlugins(): (typeof autoExport | ({
42
+ getBabelPlugins(): ({
39
43
  onTransformDeps: () => void;
40
44
  onCollect: ({ file, data, }: {
41
45
  file: string;
@@ -53,7 +57,7 @@ export declare class MFSU {
53
57
  remoteName: string | undefined;
54
58
  alias: Record<string, string>;
55
59
  externals: (Function | Record<string, string>)[];
56
- } | typeof awaitImport)[])[];
60
+ } | typeof awaitImport)[][];
57
61
  getEsbuildLoaderHandler(): any[];
58
62
  }
59
63
  export {};
package/dist/mfsu.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -21,30 +12,38 @@ const path_1 = require("path");
21
12
  const mrmime_1 = require("../compiled/mrmime");
22
13
  // @ts-ignore
23
14
  const webpack_virtual_modules_1 = __importDefault(require("../compiled/webpack-virtual-modules"));
24
- const autoExport_1 = __importDefault(require("./babelPlugins/autoExport"));
25
15
  const awaitImport_1 = __importDefault(require("./babelPlugins/awaitImport/awaitImport"));
26
16
  const getRealPath_1 = require("./babelPlugins/awaitImport/getRealPath");
27
17
  const constants_1 = require("./constants");
28
18
  const dep_1 = require("./dep/dep");
29
19
  const depBuilder_1 = require("./depBuilder/depBuilder");
30
20
  const depInfo_1 = require("./depInfo");
31
- const autoExport_2 = __importDefault(require("./esbuildHandlers/autoExport"));
32
21
  const awaitImport_2 = __importDefault(require("./esbuildHandlers/awaitImport"));
33
22
  const types_1 = require("./types");
34
23
  const makeArray_1 = require("./utils/makeArray");
35
24
  const buildDepPlugin_1 = require("./webpackPlugins/buildDepPlugin");
36
- const writeCachePlugin_1 = require("./webpackPlugins/writeCachePlugin");
37
25
  class MFSU {
38
26
  constructor(opts) {
39
27
  this.alias = {};
40
28
  this.externals = [];
41
29
  this.depConfig = null;
30
+ this.buildDepsAgain = false;
31
+ this.progress = { done: false };
32
+ this.publicPath = '/';
42
33
  this.opts = opts;
43
34
  this.opts.mfName = this.opts.mfName || constants_1.DEFAULT_MF_NAME;
44
35
  this.opts.tmpBase =
45
36
  this.opts.tmpBase || (0, path_1.join)(process.cwd(), constants_1.DEFAULT_TMP_DIR_NAME);
46
37
  this.opts.mode = this.opts.mode || types_1.Mode.development;
47
38
  this.opts.getCacheDependency = this.opts.getCacheDependency || (() => ({}));
39
+ this.onProgress = (progress) => {
40
+ var _a, _b;
41
+ this.progress = {
42
+ ...this.progress,
43
+ ...progress,
44
+ };
45
+ (_b = (_a = this.opts).onMFSUProgress) === null || _b === void 0 ? void 0 : _b.call(_a, this.progress);
46
+ };
48
47
  this.opts.cwd = this.opts.cwd || process.cwd();
49
48
  this.depInfo = new depInfo_1.DepInfo({ mfsu: this });
50
49
  this.depBuilder = new depBuilder_1.DepBuilder({ mfsu: this });
@@ -56,86 +55,86 @@ class MFSU {
56
55
  return `await import('${(0, utils_1.winPath)(content)}');`;
57
56
  // return `(async () => await import('${content}'))();`;
58
57
  }
59
- setWebpackConfig(opts) {
58
+ async setWebpackConfig(opts) {
60
59
  var _a;
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const { mfName } = this.opts;
63
- /**
64
- * config
65
- */
66
- // set alias and externals with reference for babel plugin
67
- Object.assign(this.alias, ((_a = opts.config.resolve) === null || _a === void 0 ? void 0 : _a.alias) || {});
68
- this.externals.push(...(0, makeArray_1.makeArray)(opts.config.externals || []));
69
- // entry
70
- const entry = {};
71
- const virtualModules = {};
72
- // ensure entry object type
73
- const entryObject = utils_1.lodash.isString(opts.config.entry)
74
- ? { default: [opts.config.entry] }
75
- : opts.config.entry;
76
- (0, assert_1.default)(utils_1.lodash.isPlainObject(entryObject), `webpack config 'entry' value must be a string or an object.`);
77
- for (const key of Object.keys(entryObject)) {
78
- const virtualPath = `./mfsu-virtual-entry/${key}.js`;
79
- const virtualContent = [];
80
- let index = 1;
81
- let hasDefaultExport = false;
82
- const entryFiles = utils_1.lodash.isArray(entryObject[key])
83
- ? entryObject[key]
84
- : [entryObject[key]];
85
- for (let entry of entryFiles) {
86
- // ensure entry is a file
87
- if ((0, fs_1.statSync)(entry).isDirectory()) {
88
- const realEntry = (0, utils_1.tryPaths)([
89
- (0, path_1.join)(entry, 'index.tsx'),
90
- (0, path_1.join)(entry, 'index.ts'),
91
- ]);
92
- (0, assert_1.default)(realEntry, `entry file not found, please configure the specific entry path. (e.g. 'src/index.tsx')`);
93
- entry = realEntry;
94
- }
95
- const content = (0, fs_1.readFileSync)(entry, 'utf-8');
96
- const [_imports, exports] = yield (0, bundler_utils_1.parseModule)({ content, path: entry });
97
- if (exports.length) {
98
- virtualContent.push(`const k${index} = ${this.asyncImport(entry)}`);
99
- for (const exportName of exports) {
100
- if (exportName === 'default') {
101
- hasDefaultExport = true;
102
- virtualContent.push(`export default k${index}.${exportName}`);
103
- }
104
- else {
105
- virtualContent.push(`export const ${exportName} = k${index}.${exportName}`);
106
- }
60
+ const { mfName } = this.opts;
61
+ /**
62
+ * config
63
+ */
64
+ // set alias and externals with reference for babel plugin
65
+ Object.assign(this.alias, ((_a = opts.config.resolve) === null || _a === void 0 ? void 0 : _a.alias) || {});
66
+ this.externals.push(...(0, makeArray_1.makeArray)(opts.config.externals || []));
67
+ // entry
68
+ const entry = {};
69
+ const virtualModules = {};
70
+ // ensure entry object type
71
+ const entryObject = utils_1.lodash.isString(opts.config.entry)
72
+ ? { default: [opts.config.entry] }
73
+ : opts.config.entry;
74
+ (0, assert_1.default)(utils_1.lodash.isPlainObject(entryObject), `webpack config 'entry' value must be a string or an object.`);
75
+ for (const key of Object.keys(entryObject)) {
76
+ const virtualPath = `./mfsu-virtual-entry/${key}.js`;
77
+ const virtualContent = [];
78
+ let index = 1;
79
+ let hasDefaultExport = false;
80
+ const entryFiles = utils_1.lodash.isArray(entryObject[key])
81
+ ? entryObject[key]
82
+ : [entryObject[key]];
83
+ for (let entry of entryFiles) {
84
+ // ensure entry is a file
85
+ if ((0, fs_1.statSync)(entry).isDirectory()) {
86
+ const realEntry = (0, utils_1.tryPaths)([
87
+ (0, path_1.join)(entry, 'index.tsx'),
88
+ (0, path_1.join)(entry, 'index.ts'),
89
+ ]);
90
+ (0, assert_1.default)(realEntry, `entry file not found, please configure the specific entry path. (e.g. 'src/index.tsx')`);
91
+ entry = realEntry;
92
+ }
93
+ const content = (0, fs_1.readFileSync)(entry, 'utf-8');
94
+ const [_imports, exports] = await (0, bundler_utils_1.parseModule)({ content, path: entry });
95
+ if (exports.length) {
96
+ virtualContent.push(`const k${index} = ${this.asyncImport(entry)}`);
97
+ for (const exportName of exports) {
98
+ if (exportName === 'default') {
99
+ hasDefaultExport = true;
100
+ virtualContent.push(`export default k${index}.${exportName}`);
101
+ }
102
+ else {
103
+ virtualContent.push(`export const ${exportName} = k${index}.${exportName}`);
107
104
  }
108
105
  }
109
- else {
110
- virtualContent.push(this.asyncImport(entry));
111
- }
112
- index += 1;
113
106
  }
114
- if (!hasDefaultExport) {
115
- virtualContent.push(`export default 1;`);
107
+ else {
108
+ virtualContent.push(this.asyncImport(entry));
116
109
  }
117
- virtualModules[virtualPath] = virtualContent.join('\n');
118
- entry[key] = virtualPath;
110
+ index += 1;
119
111
  }
120
- opts.config.entry = entry;
121
- // plugins
122
- opts.config.plugins = opts.config.plugins || [];
123
- // support publicPath auto
124
- let publicPath = opts.config.output.publicPath;
125
- if (publicPath === 'auto') {
126
- publicPath = '/';
112
+ if (!hasDefaultExport) {
113
+ virtualContent.push(`export default 1;`);
127
114
  }
128
- opts.config.plugins.push(...[
129
- new webpack_virtual_modules_1.default(virtualModules),
130
- new this.opts.implementor.container.ModuleFederationPlugin({
131
- name: '__',
132
- remotes: {
133
- [mfName]: this.opts.runtimePublicPath
134
- ? // ref:
135
- // https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes
136
- `
115
+ virtualModules[virtualPath] = virtualContent.join('\n');
116
+ entry[key] = virtualPath;
117
+ }
118
+ opts.config.entry = entry;
119
+ // plugins
120
+ opts.config.plugins = opts.config.plugins || [];
121
+ // support publicPath auto
122
+ let publicPath = opts.config.output.publicPath;
123
+ if (publicPath === 'auto') {
124
+ publicPath = '/';
125
+ }
126
+ this.publicPath = publicPath;
127
+ opts.config.plugins.push(...[
128
+ new webpack_virtual_modules_1.default(virtualModules),
129
+ new this.opts.implementor.container.ModuleFederationPlugin({
130
+ name: '__',
131
+ remotes: {
132
+ [mfName]: this.opts.runtimePublicPath
133
+ ? // ref:
134
+ // https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes
135
+ `
137
136
  promise new Promise(resolve => {
138
- const remoteUrlWithVersion = window.publicPath + '${constants_1.REMOTE_FILE_FULL}';
137
+ const remoteUrlWithVersion = (window.publicPath || '/') + '${constants_1.REMOTE_FILE_FULL}';
139
138
  const script = document.createElement('script');
140
139
  script.src = remoteUrlWithVersion;
141
140
  script.onload = () => {
@@ -157,53 +156,74 @@ promise new Promise(resolve => {
157
156
  document.head.appendChild(script);
158
157
  })
159
158
  `.trimLeft()
160
- : `${mfName}@${publicPath}${constants_1.REMOTE_FILE_FULL}`,
161
- },
162
- }),
163
- new buildDepPlugin_1.BuildDepPlugin({
164
- onCompileDone: () => {
165
- this.buildDeps().catch((e) => {
159
+ : `${mfName}@${publicPath}${constants_1.REMOTE_FILE_FULL}`,
160
+ },
161
+ }),
162
+ new buildDepPlugin_1.BuildDepPlugin({
163
+ onCompileDone: () => {
164
+ if (this.depBuilder.isBuilding) {
165
+ this.buildDepsAgain = true;
166
+ }
167
+ else {
168
+ this.buildDeps()
169
+ .then(() => {
170
+ this.onProgress({
171
+ done: true,
172
+ });
173
+ })
174
+ .catch((e) => {
166
175
  utils_1.logger.error(e);
176
+ this.onProgress({
177
+ done: true,
178
+ });
167
179
  });
168
- },
169
- }),
170
- new writeCachePlugin_1.WriteCachePlugin({
171
- onWriteCache: utils_1.lodash.debounce(() => {
172
- this.depInfo.writeCache();
173
- }, 300),
174
- }),
175
- ]);
176
- // ensure topLevelAwait enabled
177
- utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
178
- /**
179
- * depConfig
180
- */
181
- this.depConfig = opts.depConfig;
182
- });
180
+ }
181
+ },
182
+ }),
183
+ // new WriteCachePlugin({
184
+ // onWriteCache: lodash.debounce(() => {
185
+ // this.depInfo.writeCache();
186
+ // }, 300),
187
+ // }),
188
+ ]);
189
+ // ensure topLevelAwait enabled
190
+ utils_1.lodash.set(opts.config, 'experiments.topLevelAwait', true);
191
+ /**
192
+ * depConfig
193
+ */
194
+ this.depConfig = opts.depConfig;
183
195
  }
184
- buildDeps() {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- if (!this.depInfo.shouldBuild()) {
187
- utils_1.logger.info('MFSU skip buildDeps');
188
- return;
189
- }
190
- this.depInfo.snapshot();
191
- const deps = dep_1.Dep.buildDeps({
192
- deps: this.depInfo.moduleGraph.depSnapshotModules,
193
- cwd: this.opts.cwd,
194
- mfsu: this,
195
- });
196
- utils_1.logger.info('MFSU buildDeps');
197
- utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
198
- yield this.depBuilder.build({
199
- deps,
200
- });
196
+ async buildDeps() {
197
+ const shouldBuild = this.depInfo.shouldBuild();
198
+ if (!shouldBuild) {
199
+ utils_1.logger.info('MFSU skip buildDeps');
200
+ return;
201
+ }
202
+ this.depInfo.snapshot();
203
+ const deps = dep_1.Dep.buildDeps({
204
+ deps: this.depInfo.moduleGraph.depSnapshotModules,
205
+ cwd: this.opts.cwd,
206
+ mfsu: this,
207
+ });
208
+ utils_1.logger.info(`MFSU buildDeps since ${shouldBuild}`);
209
+ utils_1.logger.debug(deps.map((dep) => dep.file).join(', '));
210
+ await this.depBuilder.build({
211
+ deps,
201
212
  });
213
+ // Write cache
214
+ this.depInfo.writeCache();
215
+ if (this.buildDepsAgain) {
216
+ utils_1.logger.info('MFSU buildDepsAgain');
217
+ this.buildDepsAgain = false;
218
+ this.buildDeps().catch((e) => {
219
+ utils_1.logger.error(e);
220
+ });
221
+ }
202
222
  }
203
223
  getMiddlewares() {
204
224
  return [
205
225
  (req, res, next) => {
206
- const publicPath = '/';
226
+ const publicPath = this.publicPath;
207
227
  const isMF = req.path.startsWith(`${publicPath}${constants_1.MF_VA_PREFIX}`) ||
208
228
  req.path.startsWith(`${publicPath}${constants_1.MF_DEP_PREFIX}`) ||
209
229
  req.path.startsWith(`${publicPath}${constants_1.MF_STATIC_PREFIX}`);
@@ -258,13 +278,12 @@ promise new Promise(resolve => {
258
278
  };
259
279
  }
260
280
  getBabelPlugins() {
261
- return [autoExport_1.default, [awaitImport_1.default, this.getAwaitImportCollectOpts()]];
281
+ return [[awaitImport_1.default, this.getAwaitImportCollectOpts()]];
262
282
  }
263
283
  getEsbuildLoaderHandler() {
264
284
  const cache = new Map();
265
285
  const checkOpts = this.getAwaitImportCollectOpts();
266
286
  return [
267
- autoExport_2.default,
268
287
  (0, awaitImport_2.default)({
269
288
  cache,
270
289
  opts: checkOpts,
@@ -151,7 +151,7 @@ class ModuleGraph {
151
151
  this.deleteNode({ mod: importedModulesMap[key], importer: opts.mod });
152
152
  });
153
153
  newDeps.forEach((dep) => {
154
- this.addNode(Object.assign(Object.assign({}, dep), { importer: opts.mod }));
154
+ this.addNode({ ...dep, importer: opts.mod });
155
155
  });
156
156
  }
157
157
  addNode(opts) {
package/dist/types.d.ts CHANGED
@@ -12,5 +12,5 @@ export interface IEsbuildLoaderHandlerParams {
12
12
  }
13
13
  export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
14
14
  handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
15
- implementation?: typeof import('esbuild');
15
+ implementation?: typeof import('@umijs/bundler-utils/compiled/esbuild');
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-rc.2",
3
+ "version": "4.0.0-rc.20",
4
4
  "description": "@umijs/mfsu",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -17,19 +17,19 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "pnpm tsc",
20
- "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
21
- "dev": "pnpm build -- --watch"
20
+ "build:deps": "umi-scripts bundleDeps",
21
+ "dev": "pnpm build -- --watch",
22
+ "test": "umi-scripts jest-turbo"
22
23
  },
23
24
  "dependencies": {
24
- "@umijs/bundler-esbuild": "4.0.0-rc.2",
25
- "@umijs/bundler-utils": "4.0.0-rc.2",
26
- "@umijs/utils": "4.0.0-rc.2",
27
- "enhanced-resolve": "5.9.0"
25
+ "@umijs/bundler-esbuild": "4.0.0-rc.20",
26
+ "@umijs/bundler-utils": "4.0.0-rc.20",
27
+ "@umijs/utils": "4.0.0-rc.20",
28
+ "enhanced-resolve": "5.9.3"
28
29
  },
29
30
  "devDependencies": {
30
- "@types/express": "4.17.13",
31
31
  "mrmime": "1.0.0",
32
- "webpack": "5.69.1",
32
+ "webpack": "5.72.0",
33
33
  "webpack-virtual-modules": "0.4.3"
34
34
  },
35
35
  "publishConfig": {
@@ -1,7 +0,0 @@
1
- import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
- import * as t from '@umijs/bundler-utils/compiled/babel/types';
3
- export default function (): {
4
- visitor: {
5
- Program(path: Babel.NodePath<t.Program>): void;
6
- };
7
- };
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
23
- function default_1() {
24
- return {
25
- visitor: {
26
- Program(path) {
27
- let hasExport = false;
28
- path.node.body.forEach((node) => {
29
- if (
30
- // esm
31
- t.isExportNamedDeclaration(node) ||
32
- t.isExportDefaultDeclaration(node) ||
33
- t.isExportAllDeclaration(node) ||
34
- // cjs
35
- (t.isExpressionStatement(node) &&
36
- t.isAssignmentExpression(node.expression) &&
37
- t.isMemberExpression(node.expression.left) &&
38
- // exports.xxx =
39
- (t.isIdentifier(node.expression.left.object, {
40
- name: 'exports',
41
- }) ||
42
- // module.exports =
43
- (t.isIdentifier(node.expression.left.object, {
44
- name: 'module',
45
- }) &&
46
- t.isIdentifier(node.expression.left.property, {
47
- name: 'exports',
48
- }))))) {
49
- hasExport = true;
50
- }
51
- });
52
- if (!hasExport) {
53
- path.node.body.push(t.exportNamedDeclaration(t.variableDeclaration('const', [
54
- t.variableDeclarator(t.identifier('__mfsu'), t.numericLiteral(1)),
55
- ])));
56
- }
57
- },
58
- },
59
- };
60
- }
61
- exports.default = default_1;
@@ -1,6 +0,0 @@
1
- interface IOpts {
2
- exports: string[];
3
- code: string;
4
- }
5
- export default function autoExportHandler(opts: IOpts): string;
6
- export {};
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function autoExportHandler(opts) {
4
- if (!opts.exports.length) {
5
- return `${opts.code}\nexport const __mfsu = 1;`;
6
- }
7
- return opts.code;
8
- }
9
- exports.default = autoExportHandler;