@umijs/mfsu 4.0.0-canary.20220428.1 β†’ 4.0.0-canary.20220429.2

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 (55) hide show
  1. package/package.json +4 -4
  2. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +0 -27
  3. package/dist/babelPlugins/awaitImport/awaitImport.js +0 -120
  4. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +0 -18
  5. package/dist/babelPlugins/awaitImport/checkMatch.js +0 -127
  6. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +0 -4
  7. package/dist/babelPlugins/awaitImport/getAliasedPath.js +0 -30
  8. package/dist/babelPlugins/awaitImport/getRealPath.d.ts +0 -4
  9. package/dist/babelPlugins/awaitImport/getRealPath.js +0 -24
  10. package/dist/babelPlugins/awaitImport/isExternals.d.ts +0 -11
  11. package/dist/babelPlugins/awaitImport/isExternals.js +0 -29
  12. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +0 -1
  13. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +0 -55
  14. package/dist/constants.d.ts +0 -7
  15. package/dist/constants.js +0 -10
  16. package/dist/dep/dep.d.ts +0 -30
  17. package/dist/dep/dep.js +0 -107
  18. package/dist/dep/getCJSExports.d.ts +0 -3
  19. package/dist/dep/getCJSExports.js +0 -58
  20. package/dist/dep/getExposeFromContent.d.ts +0 -6
  21. package/dist/dep/getExposeFromContent.js +0 -80
  22. package/dist/dep/getModuleExports.d.ts +0 -7
  23. package/dist/dep/getModuleExports.js +0 -45
  24. package/dist/depBuilder/depBuilder.d.ts +0 -30
  25. package/dist/depBuilder/depBuilder.js +0 -173
  26. package/dist/depBuilder/getESBuildEntry.d.ts +0 -4
  27. package/dist/depBuilder/getESBuildEntry.js +0 -328
  28. package/dist/depInfo.d.ts +0 -17
  29. package/dist/depInfo.js +0 -50
  30. package/dist/esbuildHandlers/autoCssModules.d.ts +0 -2
  31. package/dist/esbuildHandlers/autoCssModules.js +0 -24
  32. package/dist/esbuildHandlers/awaitImport/index.d.ts +0 -12
  33. package/dist/esbuildHandlers/awaitImport/index.js +0 -44
  34. package/dist/index.d.ts +0 -4
  35. package/dist/index.js +0 -23
  36. package/dist/loader/esbuild.d.ts +0 -5
  37. package/dist/loader/esbuild.js +0 -54
  38. package/dist/mfsu.d.ts +0 -63
  39. package/dist/mfsu.js +0 -304
  40. package/dist/moduleGraph.d.ts +0 -73
  41. package/dist/moduleGraph.js +0 -197
  42. package/dist/types.d.ts +0 -16
  43. package/dist/types.js +0 -8
  44. package/dist/utils/makeArray.d.ts +0 -1
  45. package/dist/utils/makeArray.js +0 -7
  46. package/dist/utils/trimFileContent.d.ts +0 -1
  47. package/dist/utils/trimFileContent.js +0 -7
  48. package/dist/webpackPlugins/buildDepPlugin.d.ts +0 -10
  49. package/dist/webpackPlugins/buildDepPlugin.js +0 -17
  50. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +0 -5
  51. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +0 -19
  52. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +0 -10
  53. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +0 -28
  54. package/dist/webpackPlugins/writeCachePlugin.d.ts +0 -10
  55. package/dist/webpackPlugins/writeCachePlugin.js +0 -15
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCJSExports = void 0;
4
- function getCJSExports({ content }) {
5
- return matchAll(/Object\.defineProperty\(\s*exports\s*\,\s*[\"|\'](\w+)[\"|\']/g, content)
6
- .concat(
7
- // Support export['default']
8
- // ref: https://unpkg.alibaba-inc.com/browse/echarts-for-react@2.0.16/lib/core.js
9
- matchAll(/exports(?:\.|\[(?:\'|\"))(\w+)(?:\s*|(?:\'|\")\])\s*\=/g, content))
10
- .concat(
11
- // Support __webpack_exports__["default"]
12
- // ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8429
13
- matchAll(/__webpack_exports__\[(?:\"|\')(\w+)(?:\"|\')\]\s*\=/g, content))
14
- .concat(
15
- // Support __webpack_require__.d(__webpack_exports, "EditorState")
16
- // ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8347
17
- matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(?:\"|\')(\w+)(?:\"|\')\s*,/g, content))
18
- .concat(
19
- // Support __webpack_require__.d(__webpack_exports__, {"default": function() { return /* binding */ clipboard; }});
20
- // ref: https://unpkg.alibaba-inc.com/browse/clipboard@2.0.8/dist/clipboard.js L26
21
- ...matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(\{)/g, content).map((matchResult) => {
22
- const { index } = matchResult;
23
- let idx = index;
24
- let deep = 0;
25
- let isMeetSymbol = false;
26
- let symbolBeginIndex = index;
27
- while (idx < content.length) {
28
- if (!deep && isMeetSymbol) {
29
- break;
30
- }
31
- if (content[idx] === '{') {
32
- if (!isMeetSymbol) {
33
- isMeetSymbol = true;
34
- symbolBeginIndex = idx;
35
- }
36
- deep++;
37
- }
38
- if (content[idx] === '}') {
39
- deep--;
40
- }
41
- idx++;
42
- }
43
- let result = content.slice(symbolBeginIndex, idx);
44
- return [
45
- ...matchAll(/(?:\"|\')(\w+)(?:\"|\')\s*\:\s*(?:function|\()/g, result),
46
- ];
47
- }))
48
- .map((result) => result[1]);
49
- }
50
- exports.getCJSExports = getCJSExports;
51
- function matchAll(regexp, str) {
52
- const result = [];
53
- let match;
54
- while ((match = regexp.exec(str)) !== null) {
55
- result.push(match);
56
- }
57
- return result;
58
- }
@@ -1,6 +0,0 @@
1
- import { Dep } from './dep';
2
- export declare function getExposeFromContent(opts: {
3
- dep: Dep;
4
- filePath: string;
5
- content: string;
6
- }): Promise<string>;
@@ -1,80 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getExposeFromContent = void 0;
16
- const assert_1 = __importDefault(require("assert"));
17
- const path_1 = require("path");
18
- const getModuleExports_1 = require("./getModuleExports");
19
- function getExposeFromContent(opts) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- // Support CSS
22
- if (opts.filePath &&
23
- /\.(css|less|scss|sass|stylus|styl)$/.test(opts.filePath)) {
24
- return `import '${opts.dep.file}';`;
25
- }
26
- // Support Assets Files
27
- if (opts.filePath &&
28
- /\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(opts.filePath)) {
29
- return `
30
- import _ from '${opts.dep.file}';
31
- export default _;`.trim();
32
- }
33
- (0, assert_1.default)(/(js|jsx|mjs|ts|tsx)$/.test(opts.filePath), `file type not supported for ${(0, path_1.basename)(opts.filePath)}.`);
34
- const { exports, isCJS } = yield (0, getModuleExports_1.getModuleExports)({
35
- content: opts.content,
36
- filePath: opts.filePath,
37
- });
38
- // cjs
39
- if (isCJS) {
40
- return [
41
- `import _ from '${opts.dep.file}';`,
42
- `export default _;`,
43
- `export * from '${opts.dep.file}';`,
44
- ].join('\n');
45
- }
46
- // esm
47
- else {
48
- const ret = [];
49
- let hasExports = false;
50
- if (exports.includes('default')) {
51
- ret.push(`import _ from '${opts.dep.file}';`);
52
- ret.push(`export default _;`);
53
- hasExports = true;
54
- }
55
- if (hasNonDefaultExports(exports) ||
56
- // export * from δΈδΌšζœ‰ exports,εͺδΌšζœ‰ imports
57
- /export\s+\*\s+from/.test(opts.content)) {
58
- ret.push(`export * from '${opts.dep.file}';`);
59
- hasExports = true;
60
- }
61
- if (!hasExports) {
62
- // εͺζœ‰ __esModule ηš„ε…¨ι‡ε―Όε‡Ί
63
- if (exports.includes('__esModule')) {
64
- ret.push(`import _ from '${opts.dep.file}';`);
65
- ret.push(`export default _;`);
66
- ret.push(`export * from '${opts.dep.file}';`);
67
- }
68
- else {
69
- ret.push(`import '${opts.dep.file}';`);
70
- }
71
- }
72
- return ret.join('\n');
73
- }
74
- });
75
- }
76
- exports.getExposeFromContent = getExposeFromContent;
77
- function hasNonDefaultExports(exports) {
78
- return (exports.filter((exp) => !['__esModule', 'default'].includes(exp))
79
- .length > 0);
80
- }
@@ -1,7 +0,0 @@
1
- export declare function getModuleExports({ content, filePath, }: {
2
- filePath: string;
3
- content: string;
4
- }): Promise<{
5
- exports: readonly string[];
6
- isCJS: boolean;
7
- }>;
@@ -1,45 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getModuleExports = void 0;
13
- const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer");
14
- const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
15
- const path_1 = require("path");
16
- const getCJSExports_1 = require("./getCJSExports");
17
- function getModuleExports({ content, filePath, }) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- // Support tsx and jsx
20
- if (filePath && /\.(tsx|jsx)$/.test(filePath)) {
21
- content = (yield (0, esbuild_1.transform)(content, {
22
- sourcemap: false,
23
- sourcefile: filePath,
24
- format: 'esm',
25
- target: 'es6',
26
- loader: (0, path_1.extname)(filePath).slice(1),
27
- })).code;
28
- }
29
- yield es_module_lexer_1.init;
30
- const [imports, exports] = (0, es_module_lexer_1.parse)(content);
31
- let isCJS = !imports.length && !exports.length;
32
- let cjsEsmExports = null;
33
- if (isCJS) {
34
- cjsEsmExports = (0, getCJSExports_1.getCJSExports)({ content });
35
- if (cjsEsmExports.includes('__esModule')) {
36
- isCJS = false;
37
- }
38
- }
39
- return {
40
- exports: cjsEsmExports || exports,
41
- isCJS,
42
- };
43
- });
44
- }
45
- exports.getModuleExports = getModuleExports;
@@ -1,30 +0,0 @@
1
- import { Dep } from '../dep/dep';
2
- import { MFSU } from '../mfsu';
3
- interface IOpts {
4
- mfsu: MFSU;
5
- }
6
- export declare class DepBuilder {
7
- opts: IOpts;
8
- completeFns: Function[];
9
- isBuilding: boolean;
10
- constructor(opts: IOpts);
11
- buildWithWebpack(opts: {
12
- onBuildComplete: Function;
13
- deps: Dep[];
14
- }): Promise<unknown>;
15
- buildWithESBuild(opts: {
16
- onBuildComplete: Function;
17
- deps: Dep[];
18
- }): Promise<void>;
19
- build(opts: {
20
- deps: Dep[];
21
- }): Promise<void>;
22
- onBuildComplete(fn: Function): void;
23
- writeMFFiles(opts: {
24
- deps: Dep[];
25
- }): Promise<void>;
26
- getWebpackConfig(opts: {
27
- deps: Dep[];
28
- }): import("webpack").Configuration;
29
- }
30
- export {};
@@ -1,173 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DepBuilder = void 0;
13
- const bundler_esbuild_1 = require("@umijs/bundler-esbuild");
14
- const utils_1 = require("@umijs/utils");
15
- const fs_1 = require("fs");
16
- const path_1 = require("path");
17
- const constants_1 = require("../constants");
18
- const depChunkIdPrefixPlugin_1 = require("../webpackPlugins/depChunkIdPrefixPlugin");
19
- const stripSourceMapUrlPlugin_1 = require("../webpackPlugins/stripSourceMapUrlPlugin");
20
- const getESBuildEntry_1 = require("./getESBuildEntry");
21
- class DepBuilder {
22
- constructor(opts) {
23
- this.completeFns = [];
24
- this.isBuilding = false;
25
- this.opts = opts;
26
- }
27
- buildWithWebpack(opts) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const config = this.getWebpackConfig({ deps: opts.deps });
30
- return new Promise((resolve, reject) => {
31
- const compiler = this.opts.mfsu.opts.implementor(config);
32
- compiler.run((err, stats) => {
33
- opts.onBuildComplete();
34
- if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
35
- if (err) {
36
- reject(err);
37
- }
38
- if (stats) {
39
- const errorMsg = stats.toString('errors-only');
40
- // console.error(errorMsg);
41
- reject(new Error(errorMsg));
42
- }
43
- }
44
- else {
45
- resolve(stats);
46
- }
47
- compiler.close(() => { });
48
- });
49
- });
50
- });
51
- }
52
- // TODO: support watch and rebuild
53
- buildWithESBuild(opts) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const entryContent = (0, getESBuildEntry_1.getESBuildEntry)({ deps: opts.deps });
56
- const ENTRY_FILE = 'esbuild-entry.js';
57
- const tmpDir = this.opts.mfsu.opts.tmpBase;
58
- const entryPath = (0, path_1.join)(tmpDir, ENTRY_FILE);
59
- (0, fs_1.writeFileSync)(entryPath, entryContent, 'utf-8');
60
- const date = new Date().getTime();
61
- yield (0, bundler_esbuild_1.build)({
62
- cwd: this.opts.mfsu.opts.cwd,
63
- entry: {
64
- [`${constants_1.MF_VA_PREFIX}remoteEntry`]: entryPath,
65
- },
66
- config: Object.assign(Object.assign({}, this.opts.mfsu.opts.depBuildConfig), { outputPath: tmpDir, alias: this.opts.mfsu.alias, externals: this.opts.mfsu.externals }),
67
- inlineStyle: true,
68
- });
69
- utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
70
- opts.onBuildComplete();
71
- });
72
- }
73
- build(opts) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- this.isBuilding = true;
76
- const onBuildComplete = () => {
77
- this.isBuilding = false;
78
- this.completeFns.forEach((fn) => fn());
79
- this.completeFns = [];
80
- };
81
- try {
82
- yield this.writeMFFiles({ deps: opts.deps });
83
- const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete });
84
- if (this.opts.mfsu.opts.buildDepWithESBuild) {
85
- yield this.buildWithESBuild(newOpts);
86
- }
87
- else {
88
- yield this.buildWithWebpack(newOpts);
89
- }
90
- }
91
- catch (e) {
92
- onBuildComplete();
93
- throw e;
94
- }
95
- });
96
- }
97
- onBuildComplete(fn) {
98
- if (this.isBuilding) {
99
- this.completeFns.push(fn);
100
- }
101
- else {
102
- fn();
103
- }
104
- }
105
- writeMFFiles(opts) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const tmpBase = this.opts.mfsu.opts.tmpBase;
108
- utils_1.fsExtra.mkdirpSync(tmpBase);
109
- // expose files
110
- for (const dep of opts.deps) {
111
- const content = yield dep.buildExposeContent();
112
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, dep.filePath), content, 'utf-8');
113
- }
114
- // index file
115
- (0, fs_1.writeFileSync)((0, path_1.join)(tmpBase, 'index.js'), '"πŸ˜›"', 'utf-8');
116
- });
117
- }
118
- getWebpackConfig(opts) {
119
- var _a, _b;
120
- const mfName = this.opts.mfsu.opts.mfName;
121
- const depConfig = utils_1.lodash.cloneDeep(this.opts.mfsu.depConfig);
122
- // depConfig.stats = 'none';
123
- depConfig.entry = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, 'index.js');
124
- depConfig.output.path = this.opts.mfsu.opts.tmpBase;
125
- // disable devtool
126
- depConfig.devtool = false;
127
- // disable library
128
- // library δΌšε½±ε“ external ηš„θ―­ζ³•οΌŒε―Όθ‡΄ζŠ₯ι”™
129
- // ref: https://github.com/umijs/plugins/blob/6d3fc2d/packages/plugin-qiankun/src/slave/index.ts#L83
130
- if ((_a = depConfig.output) === null || _a === void 0 ? void 0 : _a.library)
131
- delete depConfig.output.library;
132
- if ((_b = depConfig.output) === null || _b === void 0 ? void 0 : _b.libraryTarget)
133
- delete depConfig.output.libraryTarget;
134
- // merge all deps to vendor
135
- depConfig.optimization || (depConfig.optimization = {});
136
- depConfig.optimization.splitChunks = {
137
- chunks: 'all',
138
- maxInitialRequests: Infinity,
139
- minSize: 0,
140
- cacheGroups: {
141
- vendor: {
142
- test: /.+/,
143
- name(_module, _chunks, cacheGroupKey) {
144
- return `${constants_1.MF_DEP_PREFIX}___${cacheGroupKey}`;
145
- },
146
- },
147
- },
148
- };
149
- depConfig.plugins = depConfig.plugins || [];
150
- depConfig.plugins.push(new depChunkIdPrefixPlugin_1.DepChunkIdPrefixPlugin());
151
- depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
152
- webpack: this.opts.mfsu.opts.implementor,
153
- }));
154
- depConfig.plugins.push(new this.opts.mfsu.opts.implementor.ProgressPlugin((percent, msg) => {
155
- this.opts.mfsu.onProgress({ percent, status: msg });
156
- }));
157
- const exposes = opts.deps.reduce((memo, dep) => {
158
- memo[`./${dep.file}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
159
- return memo;
160
- }, {});
161
- depConfig.plugins.push(new this.opts.mfsu.opts.implementor.container.ModuleFederationPlugin({
162
- library: {
163
- type: 'global',
164
- name: mfName,
165
- },
166
- name: mfName,
167
- filename: constants_1.REMOTE_FILE_FULL,
168
- exposes,
169
- }));
170
- return depConfig;
171
- }
172
- }
173
- exports.DepBuilder = DepBuilder;
@@ -1,4 +0,0 @@
1
- import { Dep } from '../dep/dep';
2
- export declare function getESBuildEntry(opts: {
3
- deps: Dep[];
4
- }): string;