@umijs/mfsu 4.0.0 → 4.0.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.
- package/dist/babelPlugins/awaitImport/MFImport.d.ts +24 -0
- package/dist/babelPlugins/awaitImport/MFImport.js +68 -0
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +1 -0
- package/dist/babelPlugins/awaitImport/checkMatch.js +1 -0
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +5 -2
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +16 -2
- package/dist/dep/dep.d.ts +1 -1
- package/dist/dep/dep.js +1 -1
- package/dist/depBuilder/depBuilder.d.ts +1 -1
- package/dist/depInfo.d.ts +18 -4
- package/dist/depInfo.js +7 -0
- package/dist/esbuildHandlers/awaitImport/index.d.ts +3 -0
- package/dist/esbuildHandlers/awaitImport/index.js +30 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{mfsu.d.ts → mfsu/mfsu.d.ts} +22 -25
- package/dist/{mfsu.js → mfsu/mfsu.js} +69 -75
- package/dist/mfsu/strategyCompileTime.d.ts +20 -0
- package/dist/mfsu/strategyCompileTime.js +100 -0
- package/dist/mfsu/strategyStaticAnalyze.d.ts +24 -0
- package/dist/mfsu/strategyStaticAnalyze.js +122 -0
- package/dist/moduleGraph.d.ts +3 -8
- package/dist/staticDepInfo/importParser.d.ts +4 -0
- package/dist/staticDepInfo/importParser.js +8 -0
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +15 -0
- package/dist/staticDepInfo/simulations/babel-plugin-import.js +99 -0
- package/dist/staticDepInfo/staticDepInfo.d.ts +43 -0
- package/dist/staticDepInfo/staticDepInfo.js +198 -0
- package/dist/webpackPlugins/buildDepPlugin.d.ts +4 -3
- package/dist/webpackPlugins/buildDepPlugin.js +10 -4
- package/package.json +12 -10
- package/vendors/importParser/_importParser.js +683 -0
- package/vendors/importParser/importParser.jison +105 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
|
|
2
|
+
import * as t from '@umijs/bundler-utils/compiled/babel/types';
|
|
3
|
+
export interface IOpts {
|
|
4
|
+
resolveImportSource: (importSource: string) => string;
|
|
5
|
+
exportAllMembers?: Record<string, string[]>;
|
|
6
|
+
unMatchLibs?: string[];
|
|
7
|
+
remoteName?: string;
|
|
8
|
+
alias?: Record<string, string>;
|
|
9
|
+
externals?: any;
|
|
10
|
+
}
|
|
11
|
+
export default function (): {
|
|
12
|
+
visitor: {
|
|
13
|
+
Program: {
|
|
14
|
+
exit(path: Babel.NodePath<t.Program>, { opts }: {
|
|
15
|
+
opts: IOpts;
|
|
16
|
+
}): void;
|
|
17
|
+
};
|
|
18
|
+
CallExpression: {
|
|
19
|
+
exit(path: Babel.NodePath<t.CallExpression>, { opts }: {
|
|
20
|
+
opts: IOpts;
|
|
21
|
+
}): void;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
27
|
+
function default_1() {
|
|
28
|
+
return {
|
|
29
|
+
visitor: {
|
|
30
|
+
Program: {
|
|
31
|
+
exit(path, { opts }) {
|
|
32
|
+
let index = path.node.body.length - 1;
|
|
33
|
+
while (index >= 0) {
|
|
34
|
+
const node = path.node.body[index];
|
|
35
|
+
// import x from 'x';
|
|
36
|
+
// import * as x from 'x';
|
|
37
|
+
// import x, * as xx from 'x';
|
|
38
|
+
// import { x } from 'x';
|
|
39
|
+
if (t.isImportDeclaration(node)) {
|
|
40
|
+
node.source.value = opts.resolveImportSource(node.source.value);
|
|
41
|
+
}
|
|
42
|
+
// export * from 'x';
|
|
43
|
+
else if (t.isExportAllDeclaration(node)) {
|
|
44
|
+
node.source.value = opts.resolveImportSource(node.source.value);
|
|
45
|
+
}
|
|
46
|
+
// export { x } from 'x';
|
|
47
|
+
else if (t.isExportNamedDeclaration(node) && node.source) {
|
|
48
|
+
node.source.value = opts.resolveImportSource(node.source.value);
|
|
49
|
+
}
|
|
50
|
+
index -= 1;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
CallExpression: {
|
|
55
|
+
exit(path, { opts }) {
|
|
56
|
+
const { node } = path;
|
|
57
|
+
if (t.isImport(node.callee) &&
|
|
58
|
+
node.arguments.length === 1 &&
|
|
59
|
+
node.arguments[0].type === 'StringLiteral') {
|
|
60
|
+
const newValue = opts.resolveImportSource(node.arguments[0].value);
|
|
61
|
+
node.arguments[0] = t.stringLiteral(newValue);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.default = default_1;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
declare type Opts = {
|
|
2
2
|
value: string;
|
|
3
3
|
alias: Record<string, string>;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
|
+
export declare function getAliasedPath({ value, alias }: Opts): string | undefined;
|
|
6
|
+
export declare function getAliasedPathWithLoopDetect({ value, alias }: Opts): string;
|
|
7
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAliasedPath = void 0;
|
|
4
|
-
function getAliasedPath({ value, alias
|
|
3
|
+
exports.getAliasedPathWithLoopDetect = exports.getAliasedPath = void 0;
|
|
4
|
+
function getAliasedPath({ value, alias }) {
|
|
5
5
|
const importValue = value;
|
|
6
6
|
// equal alias
|
|
7
7
|
if (alias[value]) {
|
|
@@ -28,3 +28,17 @@ exports.getAliasedPath = getAliasedPath;
|
|
|
28
28
|
function addLastSlash(path) {
|
|
29
29
|
return path.endsWith('/') ? path : `${path}/`;
|
|
30
30
|
}
|
|
31
|
+
function getAliasedPathWithLoopDetect({ value, alias }) {
|
|
32
|
+
let needUnAlias = value;
|
|
33
|
+
for (let i = 0; i < 10; i++) {
|
|
34
|
+
let unAliased = getAliasedPath({ value: needUnAlias, alias });
|
|
35
|
+
if (unAliased) {
|
|
36
|
+
needUnAlias = unAliased;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return needUnAlias;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw Error(`endless loop detected in resolve alias for '${value}', please check your alias config.`);
|
|
43
|
+
}
|
|
44
|
+
exports.getAliasedPathWithLoopDetect = getAliasedPathWithLoopDetect;
|
package/dist/dep/dep.d.ts
CHANGED
package/dist/dep/dep.js
CHANGED
package/dist/depInfo.d.ts
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
|
-
import { MFSU } from './mfsu';
|
|
1
|
+
import { MFSU } from './mfsu/mfsu';
|
|
2
2
|
import { ModuleGraph } from './moduleGraph';
|
|
3
3
|
interface IOpts {
|
|
4
4
|
mfsu: MFSU;
|
|
5
5
|
}
|
|
6
|
-
export declare
|
|
6
|
+
export declare type DepModule = {
|
|
7
|
+
file: string;
|
|
8
|
+
version: string;
|
|
9
|
+
};
|
|
10
|
+
export interface IDepInfo {
|
|
11
|
+
shouldBuild(): string | boolean;
|
|
12
|
+
snapshot(): void;
|
|
13
|
+
loadCache(): void;
|
|
14
|
+
writeCache(): void;
|
|
15
|
+
getCacheFilePath(): string;
|
|
16
|
+
getDepModules(): Record<string, DepModule>;
|
|
17
|
+
}
|
|
18
|
+
export declare class DepInfo implements IDepInfo {
|
|
7
19
|
private opts;
|
|
8
|
-
cacheFilePath
|
|
20
|
+
private readonly cacheFilePath;
|
|
9
21
|
moduleGraph: ModuleGraph;
|
|
10
|
-
cacheDependency
|
|
22
|
+
private cacheDependency;
|
|
11
23
|
constructor(opts: IOpts);
|
|
12
24
|
shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
|
|
13
25
|
snapshot(): void;
|
|
14
26
|
loadCache(): void;
|
|
15
27
|
writeCache(): void;
|
|
28
|
+
getDepModules(): Record<string, DepModule>;
|
|
29
|
+
getCacheFilePath(): string;
|
|
16
30
|
}
|
|
17
31
|
export {};
|
package/dist/depInfo.js
CHANGED
|
@@ -19,6 +19,7 @@ class DepInfo {
|
|
|
19
19
|
if (this.moduleGraph.hasDepChanged()) {
|
|
20
20
|
return 'moduleGraph has changed';
|
|
21
21
|
}
|
|
22
|
+
// fixme always rebuild in dev
|
|
22
23
|
return false;
|
|
23
24
|
}
|
|
24
25
|
snapshot() {
|
|
@@ -46,5 +47,11 @@ class DepInfo {
|
|
|
46
47
|
utils_1.logger.info('[MFSU] write cache');
|
|
47
48
|
(0, fs_1.writeFileSync)(this.cacheFilePath, newContent, 'utf-8');
|
|
48
49
|
}
|
|
50
|
+
getDepModules() {
|
|
51
|
+
return this.moduleGraph.depSnapshotModules;
|
|
52
|
+
}
|
|
53
|
+
getCacheFilePath() {
|
|
54
|
+
return this.cacheFilePath;
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
exports.DepInfo = DepInfo;
|
|
@@ -8,5 +8,8 @@ interface IOpts {
|
|
|
8
8
|
imports: ImportSpecifier[];
|
|
9
9
|
filePath: string;
|
|
10
10
|
}
|
|
11
|
+
export declare function getImportHandlerV4(params: {
|
|
12
|
+
resolveImportSource: (source: string) => string;
|
|
13
|
+
}): (opts: IOpts) => string;
|
|
11
14
|
export default function getAwaitImportHandler(params: IParams): (opts: IOpts) => string;
|
|
12
15
|
export {};
|
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getImportHandlerV4 = void 0;
|
|
3
4
|
const checkMatch_1 = require("../../babelPlugins/awaitImport/checkMatch");
|
|
5
|
+
function getImportHandlerV4(params) {
|
|
6
|
+
return function awaitImportHandler(opts) {
|
|
7
|
+
let offset = 0;
|
|
8
|
+
let { code } = opts;
|
|
9
|
+
const { 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 replaceValue = params.resolveImportSource(from);
|
|
16
|
+
if (replaceValue !== from) {
|
|
17
|
+
// case: import x from './index.ts';
|
|
18
|
+
// import('./index.ts');
|
|
19
|
+
// import x from '
|
|
20
|
+
// import(
|
|
21
|
+
const preSeg = code.substring(0, i.s + offset);
|
|
22
|
+
// ';
|
|
23
|
+
// );
|
|
24
|
+
const tailSeg = code.substring(i.e + offset);
|
|
25
|
+
const quote = isLazyImport ? '"' : '';
|
|
26
|
+
code = `${preSeg}${quote}${replaceValue}${quote}${tailSeg}`;
|
|
27
|
+
offset += replaceValue.length - from.length;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return code;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.getImportHandlerV4 = getImportHandlerV4;
|
|
4
34
|
function getAwaitImportHandler(params) {
|
|
5
35
|
return function awaitImportHandler(opts) {
|
|
6
36
|
var _a, _b;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,4 +20,4 @@ __exportStar(require("./esbuildHandlers/autoCssModules"), exports);
|
|
|
20
20
|
// for independent use `esbuild-loader`
|
|
21
21
|
var esbuild_1 = require("./loader/esbuild");
|
|
22
22
|
Object.defineProperty(exports, "esbuildLoader", { enumerable: true, get: function () { return esbuild_1.esbuildLoader; } });
|
|
23
|
-
__exportStar(require("./mfsu"), exports);
|
|
23
|
+
__exportStar(require("./mfsu/mfsu"), exports);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from '@umijs/bundler-utils/compiled/express';
|
|
2
|
+
import type { AutoUpdateSrcCodeCache } from '@umijs/utils';
|
|
2
3
|
import webpack, { Configuration } from 'webpack';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { DepBuilder } from '../depBuilder/depBuilder';
|
|
5
|
+
import { DepModule } from '../depInfo';
|
|
6
|
+
import { Mode } from '../types';
|
|
7
|
+
import { IBuildDepPluginOpts } from '../webpackPlugins/buildDepPlugin';
|
|
7
8
|
interface IOpts {
|
|
8
9
|
cwd?: string;
|
|
9
10
|
excludeNodeNatives?: boolean;
|
|
@@ -18,18 +19,21 @@ interface IOpts {
|
|
|
18
19
|
implementor: typeof webpack;
|
|
19
20
|
buildDepWithESBuild?: boolean;
|
|
20
21
|
depBuildConfig: any;
|
|
22
|
+
strategy?: 'eager' | 'normal';
|
|
23
|
+
include?: string[];
|
|
24
|
+
srcCodeCache?: AutoUpdateSrcCodeCache;
|
|
21
25
|
}
|
|
22
26
|
export declare class MFSU {
|
|
23
27
|
opts: IOpts;
|
|
24
28
|
alias: Record<string, string>;
|
|
25
29
|
externals: (Record<string, string> | Function)[];
|
|
26
|
-
depInfo: DepInfo;
|
|
27
30
|
depBuilder: DepBuilder;
|
|
28
31
|
depConfig: Configuration | null;
|
|
29
32
|
buildDepsAgain: boolean;
|
|
30
33
|
progress: any;
|
|
31
34
|
onProgress: Function;
|
|
32
35
|
publicPath: string;
|
|
36
|
+
private strategy;
|
|
33
37
|
constructor(opts: IOpts);
|
|
34
38
|
asyncImport(content: string): string;
|
|
35
39
|
setWebpackConfig(opts: {
|
|
@@ -38,26 +42,19 @@ export declare class MFSU {
|
|
|
38
42
|
}): Promise<void>;
|
|
39
43
|
buildDeps(): Promise<void>;
|
|
40
44
|
getMiddlewares(): ((req: Request, res: Response, next: NextFunction) => void)[];
|
|
41
|
-
|
|
42
|
-
getBabelPlugins(): ({
|
|
43
|
-
onTransformDeps: () => void;
|
|
44
|
-
onCollect: ({ file, data, }: {
|
|
45
|
-
file: string;
|
|
46
|
-
data: {
|
|
47
|
-
unMatched: Set<{
|
|
48
|
-
sourceValue: string;
|
|
49
|
-
}>;
|
|
50
|
-
matched: Set<{
|
|
51
|
-
sourceValue: string;
|
|
52
|
-
}>;
|
|
53
|
-
};
|
|
54
|
-
}) => void;
|
|
55
|
-
exportAllMembers: Record<string, string[]> | undefined;
|
|
56
|
-
unMatchLibs: string[] | undefined;
|
|
57
|
-
remoteName: string | undefined;
|
|
58
|
-
alias: Record<string, string>;
|
|
59
|
-
externals: (Function | Record<string, string>)[];
|
|
60
|
-
} | typeof awaitImport)[][];
|
|
45
|
+
getBabelPlugins(): any[][];
|
|
61
46
|
getEsbuildLoaderHandler(): any[];
|
|
47
|
+
getCacheFilePath(): string;
|
|
48
|
+
}
|
|
49
|
+
export interface IMFSUStrategy {
|
|
50
|
+
init(): void;
|
|
51
|
+
shouldBuild(): string | boolean;
|
|
52
|
+
getBabelPlugin(): any[];
|
|
53
|
+
getBuildDepPlugConfig(): IBuildDepPluginOpts;
|
|
54
|
+
loadCache(): void;
|
|
55
|
+
getCacheFilePath(): string;
|
|
56
|
+
getDepModules(): Record<string, DepModule>;
|
|
57
|
+
refresh(): void;
|
|
58
|
+
writeCache(): void;
|
|
62
59
|
}
|
|
63
60
|
export {};
|
|
@@ -1,4 +1,27 @@
|
|
|
1
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;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -9,19 +32,18 @@ const utils_1 = require("@umijs/utils");
|
|
|
9
32
|
const assert_1 = __importDefault(require("assert"));
|
|
10
33
|
const fs_1 = require("fs");
|
|
11
34
|
const path_1 = require("path");
|
|
12
|
-
const mrmime_1 = require("
|
|
35
|
+
const mrmime_1 = require("../../compiled/mrmime");
|
|
13
36
|
// @ts-ignore
|
|
14
|
-
const webpack_virtual_modules_1 = __importDefault(require("
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const buildDepPlugin_1 = require("./webpackPlugins/buildDepPlugin");
|
|
37
|
+
const webpack_virtual_modules_1 = __importDefault(require("../../compiled/webpack-virtual-modules"));
|
|
38
|
+
const constants_1 = require("../constants");
|
|
39
|
+
const dep_1 = require("../dep/dep");
|
|
40
|
+
const depBuilder_1 = require("../depBuilder/depBuilder");
|
|
41
|
+
const awaitImport_1 = __importStar(require("../esbuildHandlers/awaitImport"));
|
|
42
|
+
const types_1 = require("../types");
|
|
43
|
+
const makeArray_1 = require("../utils/makeArray");
|
|
44
|
+
const buildDepPlugin_1 = require("../webpackPlugins/buildDepPlugin");
|
|
45
|
+
const strategyCompileTime_1 = require("./strategyCompileTime");
|
|
46
|
+
const strategyStaticAnalyze_1 = require("./strategyStaticAnalyze");
|
|
25
47
|
class MFSU {
|
|
26
48
|
constructor(opts) {
|
|
27
49
|
this.alias = {};
|
|
@@ -45,9 +67,24 @@ class MFSU {
|
|
|
45
67
|
(_b = (_a = this.opts).onMFSUProgress) === null || _b === void 0 ? void 0 : _b.call(_a, this.progress);
|
|
46
68
|
};
|
|
47
69
|
this.opts.cwd = this.opts.cwd || process.cwd();
|
|
48
|
-
this.
|
|
70
|
+
if (this.opts.strategy === 'eager') {
|
|
71
|
+
if (opts.srcCodeCache) {
|
|
72
|
+
utils_1.logger.info('MFSU eager strategy enabled');
|
|
73
|
+
this.strategy = new strategyStaticAnalyze_1.StaticAnalyzeStrategy({
|
|
74
|
+
mfsu: this,
|
|
75
|
+
srcCodeCache: opts.srcCodeCache,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
utils_1.logger.warn('fallback to MFSU normal strategy, due to srcCache is not provided');
|
|
80
|
+
this.strategy = new strategyCompileTime_1.StrategyCompileTime({ mfsu: this });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.strategy = new strategyCompileTime_1.StrategyCompileTime({ mfsu: this });
|
|
85
|
+
}
|
|
86
|
+
this.strategy.loadCache();
|
|
49
87
|
this.depBuilder = new depBuilder_1.DepBuilder({ mfsu: this });
|
|
50
|
-
this.depInfo.loadCache();
|
|
51
88
|
}
|
|
52
89
|
// swc don't support top-level await
|
|
53
90
|
// ref: https://github.com/vercel/next.js/issues/31054
|
|
@@ -161,27 +198,7 @@ promise new Promise(resolve => {
|
|
|
161
198
|
: `${mfName}@${publicPath}${constants_1.REMOTE_FILE_FULL}`,
|
|
162
199
|
},
|
|
163
200
|
}),
|
|
164
|
-
new buildDepPlugin_1.BuildDepPlugin(
|
|
165
|
-
onCompileDone: () => {
|
|
166
|
-
if (this.depBuilder.isBuilding) {
|
|
167
|
-
this.buildDepsAgain = true;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
this.buildDeps()
|
|
171
|
-
.then(() => {
|
|
172
|
-
this.onProgress({
|
|
173
|
-
done: true,
|
|
174
|
-
});
|
|
175
|
-
})
|
|
176
|
-
.catch((e) => {
|
|
177
|
-
utils_1.logger.error(e);
|
|
178
|
-
this.onProgress({
|
|
179
|
-
done: true,
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
}),
|
|
201
|
+
new buildDepPlugin_1.BuildDepPlugin(this.strategy.getBuildDepPlugConfig()),
|
|
185
202
|
// new WriteCachePlugin({
|
|
186
203
|
// onWriteCache: lodash.debounce(() => {
|
|
187
204
|
// this.depInfo.writeCache();
|
|
@@ -194,16 +211,19 @@ promise new Promise(resolve => {
|
|
|
194
211
|
* depConfig
|
|
195
212
|
*/
|
|
196
213
|
this.depConfig = opts.depConfig;
|
|
214
|
+
this.strategy.init();
|
|
197
215
|
}
|
|
198
216
|
async buildDeps() {
|
|
199
|
-
const shouldBuild = this.
|
|
217
|
+
const shouldBuild = this.strategy.shouldBuild();
|
|
200
218
|
if (!shouldBuild) {
|
|
201
219
|
utils_1.logger.info('[MFSU] skip buildDeps');
|
|
202
220
|
return;
|
|
203
221
|
}
|
|
204
|
-
|
|
222
|
+
// Snapshot after compiled success
|
|
223
|
+
this.strategy.refresh();
|
|
224
|
+
const staticDeps = this.strategy.getDepModules();
|
|
205
225
|
const deps = dep_1.Dep.buildDeps({
|
|
206
|
-
deps:
|
|
226
|
+
deps: staticDeps,
|
|
207
227
|
cwd: this.opts.cwd,
|
|
208
228
|
mfsu: this,
|
|
209
229
|
});
|
|
@@ -213,7 +233,7 @@ promise new Promise(resolve => {
|
|
|
213
233
|
deps,
|
|
214
234
|
});
|
|
215
235
|
// Write cache
|
|
216
|
-
this.
|
|
236
|
+
this.strategy.writeCache();
|
|
217
237
|
if (this.buildDepsAgain) {
|
|
218
238
|
utils_1.logger.info('[MFSU] buildDepsAgain');
|
|
219
239
|
this.buildDepsAgain = false;
|
|
@@ -246,51 +266,25 @@ promise new Promise(resolve => {
|
|
|
246
266
|
},
|
|
247
267
|
];
|
|
248
268
|
}
|
|
249
|
-
getAwaitImportCollectOpts() {
|
|
250
|
-
return {
|
|
251
|
-
onTransformDeps: () => { },
|
|
252
|
-
onCollect: ({ file, data, }) => {
|
|
253
|
-
this.depInfo.moduleGraph.onFileChange({
|
|
254
|
-
file,
|
|
255
|
-
// @ts-ignore
|
|
256
|
-
deps: [
|
|
257
|
-
...Array.from(data.matched).map((item) => ({
|
|
258
|
-
file: item.sourceValue,
|
|
259
|
-
isDependency: true,
|
|
260
|
-
version: dep_1.Dep.getDepVersion({
|
|
261
|
-
dep: item.sourceValue,
|
|
262
|
-
cwd: this.opts.cwd,
|
|
263
|
-
}),
|
|
264
|
-
})),
|
|
265
|
-
...Array.from(data.unMatched).map((item) => ({
|
|
266
|
-
file: (0, getRealPath_1.getRealPath)({
|
|
267
|
-
file,
|
|
268
|
-
dep: item.sourceValue,
|
|
269
|
-
}),
|
|
270
|
-
isDependency: false,
|
|
271
|
-
})),
|
|
272
|
-
],
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
exportAllMembers: this.opts.exportAllMembers,
|
|
276
|
-
unMatchLibs: this.opts.unMatchLibs,
|
|
277
|
-
remoteName: this.opts.mfName,
|
|
278
|
-
alias: this.alias,
|
|
279
|
-
externals: this.externals,
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
269
|
getBabelPlugins() {
|
|
283
|
-
return [
|
|
270
|
+
return [this.strategy.getBabelPlugin()];
|
|
284
271
|
}
|
|
285
272
|
getEsbuildLoaderHandler() {
|
|
273
|
+
if (this.opts.strategy === 'eager') {
|
|
274
|
+
const opts = this.strategy.getBabelPlugin()[1];
|
|
275
|
+
return [(0, awaitImport_1.getImportHandlerV4)(opts)];
|
|
276
|
+
}
|
|
286
277
|
const cache = new Map();
|
|
287
|
-
const checkOpts = this.
|
|
278
|
+
const checkOpts = this.strategy.getBabelPlugin()[1];
|
|
288
279
|
return [
|
|
289
|
-
(0,
|
|
280
|
+
(0, awaitImport_1.default)({
|
|
290
281
|
cache,
|
|
291
282
|
opts: checkOpts,
|
|
292
283
|
}),
|
|
293
284
|
];
|
|
294
285
|
}
|
|
286
|
+
getCacheFilePath() {
|
|
287
|
+
return this.strategy.getCacheFilePath();
|
|
288
|
+
}
|
|
295
289
|
}
|
|
296
290
|
exports.MFSU = MFSU;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DepModule } from '../depInfo';
|
|
2
|
+
import { IBuildDepPluginOpts } from '../webpackPlugins/buildDepPlugin';
|
|
3
|
+
import type { IMFSUStrategy, MFSU } from './mfsu';
|
|
4
|
+
export declare class StrategyCompileTime implements IMFSUStrategy {
|
|
5
|
+
private readonly mfsu;
|
|
6
|
+
private depInfo;
|
|
7
|
+
constructor({ mfsu }: {
|
|
8
|
+
mfsu: MFSU;
|
|
9
|
+
});
|
|
10
|
+
getDepModules(): Record<string, DepModule>;
|
|
11
|
+
getCacheFilePath(): string;
|
|
12
|
+
init(): void;
|
|
13
|
+
shouldBuild(): false | "cacheDependency has changed" | "moduleGraph has changed";
|
|
14
|
+
loadCache(): void;
|
|
15
|
+
writeCache(): void;
|
|
16
|
+
refresh(): void;
|
|
17
|
+
getBabelPlugin(): any[];
|
|
18
|
+
getBuildDepPlugConfig(): IBuildDepPluginOpts;
|
|
19
|
+
private getAwaitImportCollectOpts;
|
|
20
|
+
}
|