@umijs/mfsu 4.0.0-beta.9 → 4.0.0-canary.202200505.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babelPlugins/awaitImport/awaitImport.js +5 -1
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +2 -1
- package/dist/babelPlugins/awaitImport/checkMatch.js +12 -4
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +5 -10
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +5 -1
- package/dist/dep/dep.js +39 -51
- package/dist/dep/getExposeFromContent.js +44 -55
- package/dist/dep/getModuleExports.js +24 -35
- package/dist/depBuilder/depBuilder.js +73 -75
- package/dist/depBuilder/getESBuildEntry.js +18 -5
- package/dist/depInfo.d.ts +1 -1
- package/dist/depInfo.js +11 -4
- package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
- package/dist/esbuildHandlers/autoCssModules.js +24 -0
- package/dist/esbuildHandlers/awaitImport/index.d.ts +12 -0
- package/dist/esbuildHandlers/awaitImport/index.js +44 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10 -1
- package/dist/loader/esbuild.d.ts +5 -0
- package/dist/loader/esbuild.js +38 -0
- package/dist/mfsu.d.ts +14 -5
- package/dist/mfsu.js +194 -79
- package/dist/moduleGraph.d.ts +1 -0
- package/dist/moduleGraph.js +10 -2
- package/dist/types.d.ts +12 -0
- package/package.json +9 -9
- package/dist/babelPlugins/autoExport.d.ts +0 -7
- package/dist/babelPlugins/autoExport.js +0 -61
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getESBuildEntry = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
|
+
// from typescript `esModuleInterop`
|
|
6
|
+
const ES_INTEROP_FUNC = `__exportStar`;
|
|
7
|
+
const ES_INTEROP_HELPER = `
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var ${ES_INTEROP_FUNC} = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
`;
|
|
5
19
|
function getESBuildEntry(opts) {
|
|
6
20
|
return `
|
|
7
21
|
(function() {
|
|
@@ -266,6 +280,7 @@ function getESBuildEntry(opts) {
|
|
|
266
280
|
var __webpack_exports__ = {};
|
|
267
281
|
(function() {
|
|
268
282
|
var exports = __webpack_exports__;
|
|
283
|
+
${ES_INTEROP_HELPER}
|
|
269
284
|
var moduleMap = {
|
|
270
285
|
${opts.deps.map(getDepModuleStr).join(',\n')}
|
|
271
286
|
};
|
|
@@ -299,15 +314,13 @@ ${opts.deps.map(getDepModuleStr).join(',\n')}
|
|
|
299
314
|
`;
|
|
300
315
|
}
|
|
301
316
|
exports.getESBuildEntry = getESBuildEntry;
|
|
302
|
-
function normalizeFile(file) {
|
|
303
|
-
return file.replace(/\//g, '_');
|
|
304
|
-
}
|
|
305
317
|
function getDepModuleStr(dep) {
|
|
306
318
|
return `
|
|
307
319
|
"./${dep.file}": function() {
|
|
308
320
|
return new Promise(resolve => {
|
|
309
|
-
import('./${constants_1.MF_VA_PREFIX}${
|
|
310
|
-
|
|
321
|
+
import('./${constants_1.MF_VA_PREFIX}${dep.normalizedFile}.js').then(module => {
|
|
322
|
+
module.default && ${ES_INTEROP_FUNC}(module, module.default);
|
|
323
|
+
resolve(() => module.default || module);
|
|
311
324
|
});
|
|
312
325
|
})
|
|
313
326
|
}
|
package/dist/depInfo.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class DepInfo {
|
|
|
9
9
|
moduleGraph: ModuleGraph;
|
|
10
10
|
cacheDependency: object;
|
|
11
11
|
constructor(opts: IOpts);
|
|
12
|
-
shouldBuild():
|
|
12
|
+
shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
|
|
13
13
|
snapshot(): void;
|
|
14
14
|
loadCache(): void;
|
|
15
15
|
writeCache(): void;
|
package/dist/depInfo.js
CHANGED
|
@@ -14,10 +14,10 @@ class DepInfo {
|
|
|
14
14
|
}
|
|
15
15
|
shouldBuild() {
|
|
16
16
|
if (!utils_1.lodash.isEqual(this.cacheDependency, this.opts.mfsu.opts.getCacheDependency())) {
|
|
17
|
-
return
|
|
17
|
+
return 'cacheDependency has changed';
|
|
18
18
|
}
|
|
19
19
|
if (this.moduleGraph.hasDepChanged()) {
|
|
20
|
-
return
|
|
20
|
+
return 'moduleGraph has changed';
|
|
21
21
|
}
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
@@ -27,6 +27,7 @@ class DepInfo {
|
|
|
27
27
|
}
|
|
28
28
|
loadCache() {
|
|
29
29
|
if ((0, fs_1.existsSync)(this.cacheFilePath)) {
|
|
30
|
+
utils_1.logger.info('MFSU restore cache');
|
|
30
31
|
const { cacheDependency, moduleGraph } = JSON.parse((0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8'));
|
|
31
32
|
this.cacheDependency = cacheDependency;
|
|
32
33
|
this.moduleGraph.restore(moduleGraph);
|
|
@@ -34,10 +35,16 @@ class DepInfo {
|
|
|
34
35
|
}
|
|
35
36
|
writeCache() {
|
|
36
37
|
utils_1.fsExtra.mkdirpSync((0, path_1.dirname)(this.cacheFilePath));
|
|
37
|
-
|
|
38
|
+
const newContent = JSON.stringify({
|
|
38
39
|
cacheDependency: this.cacheDependency,
|
|
39
40
|
moduleGraph: this.moduleGraph.toJSON(),
|
|
40
|
-
}, null, 2)
|
|
41
|
+
}, null, 2);
|
|
42
|
+
if ((0, fs_1.existsSync)(this.cacheFilePath) &&
|
|
43
|
+
(0, fs_1.readFileSync)(this.cacheFilePath, 'utf-8') === newContent) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
utils_1.logger.info('MFSU write cache');
|
|
47
|
+
(0, fs_1.writeFileSync)(this.cacheFilePath, newContent, 'utf-8');
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
exports.DepInfo = DepInfo;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.autoCssModulesHandler = void 0;
|
|
4
|
+
const utils_1 = require("@umijs/utils");
|
|
5
|
+
const CSS_MODULES_QUERY = '?modules';
|
|
6
|
+
const QUERY_LENGTH = CSS_MODULES_QUERY.length;
|
|
7
|
+
function autoCssModulesHandler(opts) {
|
|
8
|
+
let { code } = opts;
|
|
9
|
+
let offset = 0;
|
|
10
|
+
opts.imports.forEach((i) => {
|
|
11
|
+
if (i.d < 0 && (0, utils_1.isStyleFile)({ filename: i.n })) {
|
|
12
|
+
// import x from './index.less'
|
|
13
|
+
// => import x from '
|
|
14
|
+
const importSegment = code.substring(i.ss + offset, i.s + offset);
|
|
15
|
+
// is css module
|
|
16
|
+
if (~importSegment.indexOf(' from')) {
|
|
17
|
+
code = `${code.substring(0, i.e + offset)}${CSS_MODULES_QUERY}${code.substring(i.e + offset)}`;
|
|
18
|
+
offset += QUERY_LENGTH;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return code;
|
|
23
|
+
}
|
|
24
|
+
exports.autoCssModulesHandler = autoCssModulesHandler;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
|
|
2
|
+
interface IParams {
|
|
3
|
+
cache: Map<string, any>;
|
|
4
|
+
opts: any;
|
|
5
|
+
}
|
|
6
|
+
interface IOpts {
|
|
7
|
+
code: string;
|
|
8
|
+
imports: ImportSpecifier[];
|
|
9
|
+
filePath: string;
|
|
10
|
+
}
|
|
11
|
+
export default function getAwaitImportHandler(params: IParams): (opts: IOpts) => string;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const checkMatch_1 = require("../../babelPlugins/awaitImport/checkMatch");
|
|
4
|
+
function getAwaitImportHandler(params) {
|
|
5
|
+
return function awaitImportHandler(opts) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
let offset = 0;
|
|
8
|
+
let { code } = opts;
|
|
9
|
+
const { filePath, imports } = opts;
|
|
10
|
+
imports.forEach((i) => {
|
|
11
|
+
if (!i.n)
|
|
12
|
+
return;
|
|
13
|
+
const isLazyImport = i.d > 0;
|
|
14
|
+
const from = i.n;
|
|
15
|
+
const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
|
|
16
|
+
cache: params.cache,
|
|
17
|
+
value: from,
|
|
18
|
+
opts: params.opts,
|
|
19
|
+
filename: filePath,
|
|
20
|
+
});
|
|
21
|
+
if (isMatch) {
|
|
22
|
+
// case: import x from './index.ts';
|
|
23
|
+
// import('./index.ts');
|
|
24
|
+
// import x from '
|
|
25
|
+
// import(
|
|
26
|
+
const preSeg = code.substring(0, i.s + offset);
|
|
27
|
+
// ';
|
|
28
|
+
// );
|
|
29
|
+
const tailSeg = code.substring(i.e + offset);
|
|
30
|
+
const quote = isLazyImport ? '"' : '';
|
|
31
|
+
code = `${preSeg}${quote}${replaceValue}${quote}${tailSeg}`;
|
|
32
|
+
offset += replaceValue.length - from.length;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (params.cache.has(filePath)) {
|
|
36
|
+
(_b = (_a = params.opts).onCollect) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
37
|
+
file: filePath,
|
|
38
|
+
data: params.cache.get(filePath),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return code;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.default = getAwaitImportHandler;
|
package/dist/index.d.ts
CHANGED
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.
|
|
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];
|
|
@@ -10,5 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.esbuildLoader = void 0;
|
|
13
18
|
__exportStar(require("./constants"), exports);
|
|
19
|
+
__exportStar(require("./esbuildHandlers/autoCssModules"), exports);
|
|
20
|
+
// for independent use `esbuild-loader`
|
|
21
|
+
var esbuild_1 = require("./loader/esbuild");
|
|
22
|
+
Object.defineProperty(exports, "esbuildLoader", { enumerable: true, get: function () { return esbuild_1.esbuildLoader; } });
|
|
14
23
|
__exportStar(require("./mfsu"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LoaderContext } from 'webpack';
|
|
2
|
+
import type { IEsbuildLoaderOpts } from '../types';
|
|
3
|
+
declare function esbuildTranspiler(this: LoaderContext<IEsbuildLoaderOpts>, source: string): Promise<void>;
|
|
4
|
+
export default esbuildTranspiler;
|
|
5
|
+
export declare const esbuildLoader: string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.esbuildLoader = void 0;
|
|
4
|
+
const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
|
|
5
|
+
const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
async function esbuildTranspiler(source) {
|
|
8
|
+
var _a;
|
|
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
|
+
});
|
|
30
|
+
}
|
|
31
|
+
done(null, code, map && JSON.parse(map));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
done(error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.default = esbuildTranspiler;
|
|
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,12 +9,15 @@ 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;
|
|
16
16
|
unMatchLibs?: string[];
|
|
17
|
+
runtimePublicPath?: boolean | string;
|
|
17
18
|
implementor: typeof webpack;
|
|
18
19
|
buildDepWithESBuild?: boolean;
|
|
20
|
+
depBuildConfig: any;
|
|
19
21
|
}
|
|
20
22
|
export declare class MFSU {
|
|
21
23
|
opts: IOpts;
|
|
@@ -24,14 +26,20 @@ export declare class MFSU {
|
|
|
24
26
|
depInfo: DepInfo;
|
|
25
27
|
depBuilder: DepBuilder;
|
|
26
28
|
depConfig: Configuration | null;
|
|
29
|
+
buildDepsAgain: boolean;
|
|
30
|
+
progress: any;
|
|
31
|
+
onProgress: Function;
|
|
32
|
+
publicPath: string;
|
|
27
33
|
constructor(opts: IOpts);
|
|
34
|
+
asyncImport(content: string): string;
|
|
28
35
|
setWebpackConfig(opts: {
|
|
29
36
|
config: Configuration;
|
|
30
37
|
depConfig: Configuration;
|
|
31
|
-
}): void
|
|
38
|
+
}): Promise<void>;
|
|
32
39
|
buildDeps(): Promise<void>;
|
|
33
40
|
getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
|
|
34
|
-
|
|
41
|
+
private getAwaitImportCollectOpts;
|
|
42
|
+
getBabelPlugins(): ({
|
|
35
43
|
onTransformDeps: () => void;
|
|
36
44
|
onCollect: ({ file, data, }: {
|
|
37
45
|
file: string;
|
|
@@ -49,6 +57,7 @@ export declare class MFSU {
|
|
|
49
57
|
remoteName: string | undefined;
|
|
50
58
|
alias: Record<string, string>;
|
|
51
59
|
externals: (Function | Record<string, string>)[];
|
|
52
|
-
})[]
|
|
60
|
+
} | typeof awaitImport)[][];
|
|
61
|
+
getEsbuildLoaderHandler(): any[];
|
|
53
62
|
}
|
|
54
63
|
export {};
|