@umijs/mfsu 4.0.0-beta.5 → 4.0.0-beta.9
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/compiled/webpack-virtual-modules/LICENSE +21 -0
- package/compiled/webpack-virtual-modules/index.js +1 -0
- package/compiled/webpack-virtual-modules/package.json +1 -0
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +5 -3
- package/dist/babelPlugins/awaitImport/awaitImport.js +21 -89
- package/dist/dep/dep.d.ts +5 -1
- package/dist/dep/dep.js +41 -39
- package/dist/depBuilder/depBuilder.d.ts +9 -1
- package/dist/depBuilder/depBuilder.js +50 -6
- package/dist/depBuilder/getESBuildEntry.d.ts +4 -0
- package/dist/depBuilder/getESBuildEntry.js +315 -0
- package/dist/mfsu.d.ts +1 -1
- package/dist/mfsu.js +23 -20
- package/dist/moduleGraph.d.ts +1 -1
- package/dist/moduleGraph.js +1 -1
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +10 -0
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +28 -0
- package/package.json +26 -19
- package/dist/dep/getFilePath.d.ts +0 -3
- package/dist/dep/getFilePath.js +0 -73
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 SysGears
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";var e={636:function(e,t,r){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};const a=i(r(622));const s=r(570);let n=45e6;function checkActivation(e){if(!e._compiler){throw new Error("You must use this plugin only after creating webpack instance!")}}function getModulePath(e,t){return a.default.isAbsolute(e)?e:a.default.join(t.context,e)}function createWebpackData(e){return t=>{if(t._data){const r=t._currentLevel;const i=t._levels[r];return{result:e,level:i}}return[null,e]}}function getData(e,t){if(e._data instanceof Map){return e._data.get(t)}else if(e._data){return e.data[t]}else if(e.data instanceof Map){return e.data.get(t)}else{return e.data[t]}}function setData(e,t,r){const i=r(e);if(e._data instanceof Map){e._data.set(t,i)}else if(e._data){e.data[t]=i}else if(e.data instanceof Map){e.data.set(t,i)}else{e.data[t]=i}}function getStatStorage(e){if(e._statStorage){return e._statStorage}else if(e._statBackend){return e._statBackend}else{throw new Error("Couldn't find a stat storage")}}function getFileStorage(e){if(e._readFileStorage){return e._readFileStorage}else if(e._readFileBackend){return e._readFileBackend}else{throw new Error("Couldn't find a readFileStorage")}}function getReadDirBackend(e){if(e._readdirBackend){return e._readdirBackend}else if(e._readdirStorage){return e._readdirStorage}else{throw new Error("Couldn't find a readDirStorage from Webpack Internals")}}class VirtualModulesPlugin{constructor(e){this._compiler=null;this._watcher=null;this._staticModules=e||null}writeModule(e,t){if(!this._compiler){throw new Error(`Plugin has not been initialized`)}checkActivation(this);const r=t?t.length:0;const i=Date.now();const a=new Date(i);const o=new s.VirtualStats({dev:8675309,nlink:0,uid:1e3,gid:1e3,rdev:0,blksize:4096,ino:n++,mode:33188,size:r,blocks:Math.floor(r/4096),atime:a,mtime:a,ctime:a,birthtime:a});const l=getModulePath(e,this._compiler);if(process.env.WVM_DEBUG)console.log(this._compiler.name,"Write virtual module:",l,t);let c=this._watcher&&this._watcher.watchFileSystem;while(c&&c.wfs){c=c.wfs}let u=this._compiler.inputFileSystem;while(u&&u._inputFileSystem){u=u._inputFileSystem}u._writeVirtualFile(l,o,t);if(c&&(c.watcher.fileWatchers.size||c.watcher.fileWatchers.length)){const t=c.watcher.fileWatchers instanceof Map?Array.from(c.watcher.fileWatchers.values()):c.watcher.fileWatchers;for(const r of t){if(r.path===l){if(process.env.DEBUG)console.log(this._compiler.name,"Emit file change:",l,i);delete r.directoryWatcher._cachedTimeInfoEntries;r.directoryWatcher.setFileTime(e,i,false,false,null);r.emit("change",i,null)}}}}apply(e){this._compiler=e;const afterEnvironmentHook=()=>{let t=e.inputFileSystem;while(t&&t._inputFileSystem){t=t._inputFileSystem}if(!t._writeVirtualFile){const e=t.purge;t.purge=()=>{e.apply(t,[]);if(t._virtualFiles){Object.keys(t._virtualFiles).forEach((e=>{const r=t._virtualFiles[e];t._writeVirtualFile(e,r.stats,r.contents)}))}};t._writeVirtualFile=(e,r,i)=>{const o=getStatStorage(t);const l=getFileStorage(t);const c=getReadDirBackend(t);t._virtualFiles=t._virtualFiles||{};t._virtualFiles[e]={stats:r,contents:i};setData(o,e,createWebpackData(r));setData(l,e,createWebpackData(i));const u=e.split(/[\\/]/);let d=u.length-1;const _=u[0]?1:0;while(d>_){const e=u.slice(0,d).join(a.default.sep)||a.default.sep;try{t.readdirSync(e)}catch(t){const i=Date.now();const a=new s.VirtualStats({dev:8675309,nlink:0,uid:1e3,gid:1e3,rdev:0,blksize:4096,ino:n++,mode:16877,size:r.size,blocks:Math.floor(r.size/4096),atime:i,mtime:i,ctime:i,birthtime:i});setData(c,e,createWebpackData([]));setData(o,e,createWebpackData(a))}let i=getData(getReadDirBackend(t),e);i=i[1]||i.result;const l=u[d];if(i.indexOf(l)<0){const r=i.concat([l]).sort();setData(getReadDirBackend(t),e,createWebpackData(r))}else{break}d--}}}};const afterResolversHook=()=>{if(this._staticModules){for(const[e,t]of Object.entries(this._staticModules)){this.writeModule(e,t)}this._staticModules=null}};const watchRunHook=(t,r)=>{this._watcher=t.compiler||t;const i=e.inputFileSystem._virtualFiles;const a=e.fileTimestamps;if(i&&a&&typeof a.set==="function"){Object.keys(i).forEach((e=>{a.set(e,+i[e].stats.mtime)}))}r()};if(e.hooks){e.hooks.afterEnvironment.tap("VirtualModulesPlugin",afterEnvironmentHook);e.hooks.afterResolvers.tap("VirtualModulesPlugin",afterResolversHook);e.hooks.watchRun.tapAsync("VirtualModulesPlugin",watchRunHook)}else{e.plugin("after-environment",afterEnvironmentHook);e.plugin("after-resolvers",afterResolversHook);e.plugin("watch-run",watchRunHook)}}}e.exports=VirtualModulesPlugin},570:function(e,t,r){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.VirtualStats=void 0;const a=i(r(619));class VirtualStats{constructor(e){for(const t in e){if(!Object.prototype.hasOwnProperty.call(e,t)){continue}this[t]=e[t]}}_checkModeProperty(e){return(this.mode&a.default.S_IFMT)===e}isDirectory(){return this._checkModeProperty(a.default.S_IFDIR)}isFile(){return this._checkModeProperty(a.default.S_IFREG)}isBlockDevice(){return this._checkModeProperty(a.default.S_IFBLK)}isCharacterDevice(){return this._checkModeProperty(a.default.S_IFCHR)}isSymbolicLink(){return this._checkModeProperty(a.default.S_IFLNK)}isFIFO(){return this._checkModeProperty(a.default.S_IFIFO)}isSocket(){return this._checkModeProperty(a.default.S_IFSOCK)}}t.VirtualStats=VirtualStats},619:function(e){e.exports=require("constants")},622:function(e){e.exports=require("path")}};var t={};function __nccwpck_require__(r){var i=t[r];if(i!==undefined){return i.exports}var a=t[r]={exports:{}};var s=true;try{e[r].call(a.exports,a,a.exports,__nccwpck_require__);s=false}finally{if(s)delete t[r]}return a.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r=__nccwpck_require__(636);module.exports=r})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"webpack-virtual-modules","author":"SysGears INC","license":"MIT"}
|
|
@@ -18,8 +18,10 @@ export default function (): {
|
|
|
18
18
|
opts: IOpts;
|
|
19
19
|
}): void;
|
|
20
20
|
};
|
|
21
|
-
CallExpression
|
|
22
|
-
opts:
|
|
23
|
-
|
|
21
|
+
CallExpression: {
|
|
22
|
+
exit(path: Babel.NodePath<t.CallExpression>, { opts }: {
|
|
23
|
+
opts: IOpts;
|
|
24
|
+
}): void;
|
|
25
|
+
};
|
|
24
26
|
};
|
|
25
27
|
};
|
|
@@ -21,10 +21,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
23
23
|
const checkMatch_1 = require("./checkMatch");
|
|
24
|
-
const parseSpecifiers_1 = require("./parseSpecifiers");
|
|
25
|
-
function isCSS(val) {
|
|
26
|
-
return /\.(css|less|sass|scss|stylus|styl)(\?.+?)?$/.test(val);
|
|
27
|
-
}
|
|
28
24
|
function default_1() {
|
|
29
25
|
return {
|
|
30
26
|
pre() {
|
|
@@ -46,9 +42,6 @@ function default_1() {
|
|
|
46
42
|
visitor: {
|
|
47
43
|
Program: {
|
|
48
44
|
exit(path, { opts }) {
|
|
49
|
-
var _a;
|
|
50
|
-
const topDeclarations = [];
|
|
51
|
-
const bottomDeclarations = [];
|
|
52
45
|
let index = path.node.body.length - 1;
|
|
53
46
|
while (index >= 0) {
|
|
54
47
|
const node = path.node.body[index];
|
|
@@ -64,25 +57,8 @@ function default_1() {
|
|
|
64
57
|
opts,
|
|
65
58
|
path,
|
|
66
59
|
});
|
|
67
|
-
if (isMatch
|
|
68
|
-
|
|
69
|
-
const { properties, namespaceIdentifier } = (0, parseSpecifiers_1.parseSpecifiers)(node.specifiers);
|
|
70
|
-
const id = t.objectPattern(properties);
|
|
71
|
-
const init = t.awaitExpression(t.callExpression(t.import(), [
|
|
72
|
-
t.stringLiteral(isMatch ? replaceValue : node.source.value),
|
|
73
|
-
]));
|
|
74
|
-
if (namespaceIdentifier) {
|
|
75
|
-
topDeclarations.unshift(t.variableDeclaration('const', [
|
|
76
|
-
t.variableDeclarator(namespaceIdentifier, init),
|
|
77
|
-
properties.length &&
|
|
78
|
-
t.variableDeclarator(id, namespaceIdentifier),
|
|
79
|
-
].filter(Boolean)));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
topDeclarations.unshift(t.variableDeclaration('const', [
|
|
83
|
-
t.variableDeclarator(id, init),
|
|
84
|
-
]));
|
|
85
|
-
}
|
|
60
|
+
if (isMatch) {
|
|
61
|
+
node.source.value = replaceValue;
|
|
86
62
|
}
|
|
87
63
|
}
|
|
88
64
|
// export * from 'x';
|
|
@@ -93,28 +69,9 @@ function default_1() {
|
|
|
93
69
|
value: node.source.value,
|
|
94
70
|
opts,
|
|
95
71
|
path,
|
|
96
|
-
isExportAll: true,
|
|
97
72
|
});
|
|
98
73
|
if (isMatch) {
|
|
99
|
-
|
|
100
|
-
if (members.length) {
|
|
101
|
-
const id = t.identifier(`__all_exports_${node.source.value.replace(/([@\/\-])/g, '_')}`);
|
|
102
|
-
const init = t.awaitExpression(t.callExpression(t.import(), [
|
|
103
|
-
t.stringLiteral(replaceValue),
|
|
104
|
-
]));
|
|
105
|
-
topDeclarations.unshift(t.variableDeclaration('const', [
|
|
106
|
-
t.variableDeclarator(id, init),
|
|
107
|
-
]));
|
|
108
|
-
// replace node with export const { a, b, c } = __all_exports
|
|
109
|
-
// a, b, c was declared from opts.exportAllMembers
|
|
110
|
-
path.node.body[index] = t.exportNamedDeclaration(t.variableDeclaration('const', [
|
|
111
|
-
t.variableDeclarator(t.objectPattern(members.map((m) => t.objectProperty(t.identifier(m), t.identifier(m)))), id),
|
|
112
|
-
]));
|
|
113
|
-
}
|
|
114
|
-
// 有些 export * 只是为了类型
|
|
115
|
-
else {
|
|
116
|
-
path.node.body[index] = t.expressionStatement(t.numericLiteral(1));
|
|
117
|
-
}
|
|
74
|
+
node.source.value = replaceValue;
|
|
118
75
|
}
|
|
119
76
|
}
|
|
120
77
|
// export { x } from 'x';
|
|
@@ -127,56 +84,31 @@ function default_1() {
|
|
|
127
84
|
path,
|
|
128
85
|
});
|
|
129
86
|
if (isMatch) {
|
|
130
|
-
|
|
131
|
-
const id = t.objectPattern(properties);
|
|
132
|
-
const init = t.awaitExpression(t.callExpression(t.import(), [t.stringLiteral(replaceValue)]));
|
|
133
|
-
topDeclarations.unshift(t.variableDeclaration('const', [
|
|
134
|
-
t.variableDeclarator(id, init),
|
|
135
|
-
]));
|
|
136
|
-
node.source = null;
|
|
137
|
-
node.specifiers = node.specifiers.filter((specifier) => {
|
|
138
|
-
if (t.isExportSpecifier(specifier) &&
|
|
139
|
-
t.isIdentifier(specifier.local) &&
|
|
140
|
-
t.isIdentifier(specifier.exported)) {
|
|
141
|
-
specifier.local = specifier.exported;
|
|
142
|
-
}
|
|
143
|
-
return !(t.isExportSpecifier(specifier) &&
|
|
144
|
-
t.isIdentifier(specifier.exported) &&
|
|
145
|
-
specifier.exported.name === 'default');
|
|
146
|
-
});
|
|
147
|
-
if (!node.specifiers.length) {
|
|
148
|
-
path.node.body.splice(index, 1);
|
|
149
|
-
}
|
|
150
|
-
if (defaultIdentifier) {
|
|
151
|
-
bottomDeclarations.push(t.exportDefaultDeclaration(t.identifier(defaultIdentifier)));
|
|
152
|
-
}
|
|
87
|
+
node.source.value = replaceValue;
|
|
153
88
|
}
|
|
154
89
|
}
|
|
155
90
|
index -= 1;
|
|
156
91
|
}
|
|
157
|
-
path.node.body = [
|
|
158
|
-
...topDeclarations,
|
|
159
|
-
...path.node.body,
|
|
160
|
-
...bottomDeclarations,
|
|
161
|
-
];
|
|
162
92
|
},
|
|
163
93
|
},
|
|
164
|
-
CallExpression
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
node.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
94
|
+
CallExpression: {
|
|
95
|
+
exit(path, { opts }) {
|
|
96
|
+
const { node } = path;
|
|
97
|
+
if (t.isImport(node.callee) &&
|
|
98
|
+
node.arguments.length === 1 &&
|
|
99
|
+
node.arguments[0].type === 'StringLiteral') {
|
|
100
|
+
const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
cache: this.cache,
|
|
103
|
+
value: node.arguments[0].value,
|
|
104
|
+
opts,
|
|
105
|
+
path,
|
|
106
|
+
});
|
|
107
|
+
if (isMatch) {
|
|
108
|
+
node.arguments[0] = t.stringLiteral(replaceValue);
|
|
109
|
+
}
|
|
178
110
|
}
|
|
179
|
-
}
|
|
111
|
+
},
|
|
180
112
|
},
|
|
181
113
|
},
|
|
182
114
|
};
|
package/dist/dep/dep.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class Dep {
|
|
|
14
14
|
mfsu: MFSU;
|
|
15
15
|
});
|
|
16
16
|
buildExposeContent(): Promise<string>;
|
|
17
|
-
getRealFile():
|
|
17
|
+
getRealFile(): Promise<string | null>;
|
|
18
18
|
static buildDeps(opts: {
|
|
19
19
|
deps: Record<string, {
|
|
20
20
|
file: string;
|
|
@@ -23,4 +23,8 @@ export declare class Dep {
|
|
|
23
23
|
cwd: string;
|
|
24
24
|
mfsu: MFSU;
|
|
25
25
|
}): Dep[];
|
|
26
|
+
static getDepVersion(opts: {
|
|
27
|
+
dep: string;
|
|
28
|
+
cwd: string;
|
|
29
|
+
}): string;
|
|
26
30
|
}
|
package/dist/dep/dep.js
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
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
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -32,14 +13,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
32
13
|
};
|
|
33
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
15
|
exports.Dep = void 0;
|
|
16
|
+
const utils_1 = require("@umijs/utils");
|
|
35
17
|
const assert_1 = __importDefault(require("assert"));
|
|
18
|
+
const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
|
|
36
19
|
const fs_1 = require("fs");
|
|
37
20
|
const path_1 = require("path");
|
|
38
|
-
const process = __importStar(require("process"));
|
|
39
21
|
const constants_1 = require("../constants");
|
|
40
22
|
const trimFileContent_1 = require("../utils/trimFileContent");
|
|
41
23
|
const getExposeFromContent_1 = require("./getExposeFromContent");
|
|
42
|
-
const
|
|
24
|
+
const resolver = enhanced_resolve_1.default.create({
|
|
25
|
+
mainFields: ['module', 'browser', 'main'],
|
|
26
|
+
extensions: ['.js', '.json', '.mjs'],
|
|
27
|
+
// TODO: support exports
|
|
28
|
+
// tried to add exports, but it don't work with swr
|
|
29
|
+
exportsFields: [],
|
|
30
|
+
});
|
|
31
|
+
function resolve(context, path) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
43
38
|
class Dep {
|
|
44
39
|
constructor(opts) {
|
|
45
40
|
this.file = opts.file;
|
|
@@ -68,7 +63,7 @@ export * from '${this.file}';
|
|
|
68
63
|
`);
|
|
69
64
|
}
|
|
70
65
|
// none node natives
|
|
71
|
-
const realFile = this.getRealFile();
|
|
66
|
+
const realFile = yield this.getRealFile();
|
|
72
67
|
(0, assert_1.default)(realFile, `filePath not found of ${this.file}`);
|
|
73
68
|
const content = (0, fs_1.readFileSync)(realFile, 'utf-8');
|
|
74
69
|
return yield (0, getExposeFromContent_1.getExposeFromContent)({
|
|
@@ -79,28 +74,35 @@ export * from '${this.file}';
|
|
|
79
74
|
});
|
|
80
75
|
}
|
|
81
76
|
getRealFile() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
.map((base) => (0, path_1.join)(base, 'node_modules', this.file));
|
|
93
|
-
for (const path of absFiles) {
|
|
94
|
-
const realFile = (0, getFilePath_1.getFilePath)({ path });
|
|
95
|
-
if (realFile)
|
|
96
|
-
return realFile;
|
|
97
|
-
}
|
|
98
|
-
return null;
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
try {
|
|
79
|
+
// don't need to handle alias here
|
|
80
|
+
// it's already handled by babel plugin
|
|
81
|
+
return yield resolve(this.cwd, this.file);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
99
87
|
}
|
|
100
88
|
static buildDeps(opts) {
|
|
101
89
|
return Object.keys(opts.deps).map((file) => {
|
|
102
90
|
return new Dep(Object.assign(Object.assign({}, opts.deps[file]), { cwd: opts.cwd, mfsu: opts.mfsu }));
|
|
103
91
|
});
|
|
104
92
|
}
|
|
93
|
+
static getDepVersion(opts) {
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
if (!!process.binding('natives')[opts.dep]) {
|
|
96
|
+
return '*';
|
|
97
|
+
}
|
|
98
|
+
const dep = (0, path_1.isAbsolute)(opts.dep)
|
|
99
|
+
? opts.dep
|
|
100
|
+
: (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
|
|
101
|
+
const pkg = utils_1.pkgUp.sync({
|
|
102
|
+
cwd: dep,
|
|
103
|
+
});
|
|
104
|
+
(0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
|
|
105
|
+
return require(pkg).version;
|
|
106
|
+
}
|
|
105
107
|
}
|
|
106
108
|
exports.Dep = Dep;
|
|
@@ -8,9 +8,17 @@ export declare class DepBuilder {
|
|
|
8
8
|
completeFns: Function[];
|
|
9
9
|
isBuilding: boolean;
|
|
10
10
|
constructor(opts: IOpts);
|
|
11
|
-
|
|
11
|
+
buildWithWebpack(opts: {
|
|
12
|
+
onBuildComplete: Function;
|
|
12
13
|
deps: Dep[];
|
|
13
14
|
}): Promise<unknown>;
|
|
15
|
+
buildWithESBuild(opts: {
|
|
16
|
+
onBuildComplete: Function;
|
|
17
|
+
deps: Dep[];
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
build(opts: {
|
|
20
|
+
deps: Dep[];
|
|
21
|
+
}): Promise<void>;
|
|
14
22
|
onBuildComplete(fn: Function): void;
|
|
15
23
|
writeMFFiles(opts: {
|
|
16
24
|
deps: Dep[];
|
|
@@ -10,28 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DepBuilder = void 0;
|
|
13
|
+
const bundler_esbuild_1 = require("@umijs/bundler-esbuild");
|
|
13
14
|
const utils_1 = require("@umijs/utils");
|
|
14
15
|
const fs_1 = require("fs");
|
|
15
16
|
const path_1 = require("path");
|
|
16
17
|
const constants_1 = require("../constants");
|
|
17
18
|
const depChunkIdPrefixPlugin_1 = require("../webpackPlugins/depChunkIdPrefixPlugin");
|
|
19
|
+
const stripSourceMapUrlPlugin_1 = require("../webpackPlugins/stripSourceMapUrlPlugin");
|
|
20
|
+
const getESBuildEntry_1 = require("./getESBuildEntry");
|
|
18
21
|
class DepBuilder {
|
|
19
22
|
constructor(opts) {
|
|
20
23
|
this.completeFns = [];
|
|
21
24
|
this.isBuilding = false;
|
|
22
25
|
this.opts = opts;
|
|
23
26
|
}
|
|
24
|
-
|
|
27
|
+
buildWithWebpack(opts) {
|
|
25
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
this.isBuilding = true;
|
|
27
|
-
yield this.writeMFFiles({ deps: opts.deps });
|
|
28
29
|
const config = this.getWebpackConfig({ deps: opts.deps });
|
|
29
30
|
return new Promise((resolve, reject) => {
|
|
30
31
|
const compiler = this.opts.mfsu.opts.implementor(config);
|
|
31
32
|
compiler.run((err, stats) => {
|
|
32
|
-
|
|
33
|
-
this.completeFns.forEach((fn) => fn());
|
|
34
|
-
this.completeFns = [];
|
|
33
|
+
opts.onBuildComplete();
|
|
35
34
|
if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
|
|
36
35
|
if (err) {
|
|
37
36
|
reject(err);
|
|
@@ -50,6 +49,48 @@ class DepBuilder {
|
|
|
50
49
|
});
|
|
51
50
|
});
|
|
52
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: {
|
|
67
|
+
outputPath: tmpDir,
|
|
68
|
+
alias: this.opts.mfsu.alias,
|
|
69
|
+
externals: this.opts.mfsu.externals,
|
|
70
|
+
},
|
|
71
|
+
inlineStyle: true,
|
|
72
|
+
});
|
|
73
|
+
utils_1.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
|
|
74
|
+
opts.onBuildComplete();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
build(opts) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
this.isBuilding = true;
|
|
80
|
+
yield this.writeMFFiles({ deps: opts.deps });
|
|
81
|
+
const newOpts = Object.assign(Object.assign({}, opts), { onBuildComplete: () => {
|
|
82
|
+
this.isBuilding = false;
|
|
83
|
+
this.completeFns.forEach((fn) => fn());
|
|
84
|
+
this.completeFns = [];
|
|
85
|
+
} });
|
|
86
|
+
if (this.opts.mfsu.opts.buildDepWithESBuild) {
|
|
87
|
+
yield this.buildWithESBuild(newOpts);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
yield this.buildWithWebpack(newOpts);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
53
94
|
onBuildComplete(fn) {
|
|
54
95
|
if (this.isBuilding) {
|
|
55
96
|
this.completeFns.push(fn);
|
|
@@ -103,6 +144,9 @@ class DepBuilder {
|
|
|
103
144
|
};
|
|
104
145
|
depConfig.plugins = depConfig.plugins || [];
|
|
105
146
|
depConfig.plugins.push(new depChunkIdPrefixPlugin_1.DepChunkIdPrefixPlugin());
|
|
147
|
+
depConfig.plugins.push(new stripSourceMapUrlPlugin_1.StripSourceMapUrlPlugin({
|
|
148
|
+
webpack: this.opts.mfsu.opts.implementor,
|
|
149
|
+
}));
|
|
106
150
|
const exposes = opts.deps.reduce((memo, dep) => {
|
|
107
151
|
memo[`./${dep.shortFile}`] = (0, path_1.join)(this.opts.mfsu.opts.tmpBase, dep.filePath);
|
|
108
152
|
return memo;
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getESBuildEntry = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
function getESBuildEntry(opts) {
|
|
6
|
+
return `
|
|
7
|
+
(function() {
|
|
8
|
+
/******/ "use strict";
|
|
9
|
+
/******/ var __webpack_modules__ = ({});
|
|
10
|
+
/************************************************************************/
|
|
11
|
+
/******/ // The module cache
|
|
12
|
+
/******/ var __webpack_module_cache__ = {};
|
|
13
|
+
/******/
|
|
14
|
+
/******/ // The require function
|
|
15
|
+
/******/ function __webpack_require__(moduleId) {
|
|
16
|
+
/******/ // Check if module is in cache
|
|
17
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
18
|
+
/******/ if (cachedModule !== undefined) {
|
|
19
|
+
/******/ return cachedModule.exports;
|
|
20
|
+
/******/ }
|
|
21
|
+
/******/ // Create a new module (and put it into the cache)
|
|
22
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
23
|
+
/******/ id: moduleId,
|
|
24
|
+
/******/ loaded: false,
|
|
25
|
+
/******/ exports: {}
|
|
26
|
+
/******/ };
|
|
27
|
+
/******/
|
|
28
|
+
/******/ // Execute the module function
|
|
29
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
30
|
+
/******/
|
|
31
|
+
/******/ // Flag the module as loaded
|
|
32
|
+
/******/ module.loaded = true;
|
|
33
|
+
/******/
|
|
34
|
+
/******/ // Return the exports of the module
|
|
35
|
+
/******/ return module.exports;
|
|
36
|
+
/******/ }
|
|
37
|
+
/******/
|
|
38
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
39
|
+
/******/ __webpack_require__.m = __webpack_modules__;
|
|
40
|
+
/******/
|
|
41
|
+
/************************************************************************/
|
|
42
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
43
|
+
/******/ !function() {
|
|
44
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
45
|
+
/******/ __webpack_require__.n = function(module) {
|
|
46
|
+
/******/ var getter = module && module.__esModule ?
|
|
47
|
+
/******/ function() { return module['default']; } :
|
|
48
|
+
/******/ function() { return module; };
|
|
49
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
50
|
+
/******/ return getter;
|
|
51
|
+
/******/ };
|
|
52
|
+
/******/ }();
|
|
53
|
+
/******/
|
|
54
|
+
/******/ /* webpack/runtime/define property getters */
|
|
55
|
+
/******/ !function() {
|
|
56
|
+
/******/ // define getter functions for harmony exports
|
|
57
|
+
/******/ __webpack_require__.d = function(exports, definition) {
|
|
58
|
+
/******/ for(var key in definition) {
|
|
59
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
60
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
61
|
+
/******/ }
|
|
62
|
+
/******/ }
|
|
63
|
+
/******/ };
|
|
64
|
+
/******/ }();
|
|
65
|
+
/******/
|
|
66
|
+
/******/ /* webpack/runtime/ensure chunk */
|
|
67
|
+
/******/ !function() {
|
|
68
|
+
/******/ __webpack_require__.f = {};
|
|
69
|
+
/******/ // This file contains only the entry chunk.
|
|
70
|
+
/******/ // The chunk loading function for additional chunks
|
|
71
|
+
/******/ __webpack_require__.e = function(chunkId) {
|
|
72
|
+
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
73
|
+
/******/ __webpack_require__.f[key](chunkId, promises);
|
|
74
|
+
/******/ return promises;
|
|
75
|
+
/******/ }, []));
|
|
76
|
+
/******/ };
|
|
77
|
+
/******/ }();
|
|
78
|
+
/******/
|
|
79
|
+
/******/ /* webpack/runtime/get javascript chunk filename */
|
|
80
|
+
/******/ !function() {
|
|
81
|
+
/******/ // This function allow to reference async chunks
|
|
82
|
+
/******/ __webpack_require__.u = function(chunkId) {
|
|
83
|
+
/******/ // return url for filenames based on template
|
|
84
|
+
/******/ return "" + "mf-dep____vendor" + "." + "8b5e340b" + ".js";
|
|
85
|
+
/******/ };
|
|
86
|
+
/******/ }();
|
|
87
|
+
/******/
|
|
88
|
+
/******/ /* webpack/runtime/get mini-css chunk filename */
|
|
89
|
+
/******/ !function() {
|
|
90
|
+
/******/ // This function allow to reference all chunks
|
|
91
|
+
/******/ __webpack_require__.miniCssF = function(chunkId) {
|
|
92
|
+
/******/ // return url for filenames based on template
|
|
93
|
+
/******/ return undefined;
|
|
94
|
+
/******/ };
|
|
95
|
+
/******/ }();
|
|
96
|
+
/******/
|
|
97
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
98
|
+
/******/ !function() {
|
|
99
|
+
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
100
|
+
/******/ }();
|
|
101
|
+
/******/
|
|
102
|
+
/******/ /* webpack/runtime/load script */
|
|
103
|
+
/******/ !function() {
|
|
104
|
+
/******/ var inProgress = {};
|
|
105
|
+
/******/ // data-webpack is not used as build has no uniqueName
|
|
106
|
+
/******/ // loadScript function to load a script via script tag
|
|
107
|
+
/******/ __webpack_require__.l = function(url, done, key, chunkId) {
|
|
108
|
+
/******/ if(inProgress[url]) { inProgress[url].push(done); return; }
|
|
109
|
+
/******/ var script, needAttach;
|
|
110
|
+
/******/ if(key !== undefined) {
|
|
111
|
+
/******/ var scripts = document.getElementsByTagName("script");
|
|
112
|
+
/******/ for(var i = 0; i < scripts.length; i++) {
|
|
113
|
+
/******/ var s = scripts[i];
|
|
114
|
+
/******/ if(s.getAttribute("src") == url) { script = s; break; }
|
|
115
|
+
/******/ }
|
|
116
|
+
/******/ }
|
|
117
|
+
/******/ if(!script) {
|
|
118
|
+
/******/ needAttach = true;
|
|
119
|
+
/******/ script = document.createElement('script');
|
|
120
|
+
/******/
|
|
121
|
+
/******/ script.charset = 'utf-8';
|
|
122
|
+
/******/ script.timeout = 120;
|
|
123
|
+
/******/ if (__webpack_require__.nc) {
|
|
124
|
+
/******/ script.setAttribute("nonce", __webpack_require__.nc);
|
|
125
|
+
/******/ }
|
|
126
|
+
/******/
|
|
127
|
+
/******/ script.src = url;
|
|
128
|
+
/******/ }
|
|
129
|
+
/******/ inProgress[url] = [done];
|
|
130
|
+
/******/ var onScriptComplete = function(prev, event) {
|
|
131
|
+
/******/ // avoid mem leaks in IE.
|
|
132
|
+
/******/ script.onerror = script.onload = null;
|
|
133
|
+
/******/ clearTimeout(timeout);
|
|
134
|
+
/******/ var doneFns = inProgress[url];
|
|
135
|
+
/******/ delete inProgress[url];
|
|
136
|
+
/******/ script.parentNode && script.parentNode.removeChild(script);
|
|
137
|
+
/******/ doneFns && doneFns.forEach(function(fn) { return fn(event); });
|
|
138
|
+
/******/ if(prev) return prev(event);
|
|
139
|
+
/******/ }
|
|
140
|
+
/******/ ;
|
|
141
|
+
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
|
|
142
|
+
/******/ script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
143
|
+
/******/ script.onload = onScriptComplete.bind(null, script.onload);
|
|
144
|
+
/******/ needAttach && document.head.appendChild(script);
|
|
145
|
+
/******/ };
|
|
146
|
+
/******/ }();
|
|
147
|
+
/******/
|
|
148
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
149
|
+
/******/ !function() {
|
|
150
|
+
/******/ // define __esModule on exports
|
|
151
|
+
/******/ __webpack_require__.r = function(exports) {
|
|
152
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
153
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
154
|
+
/******/ }
|
|
155
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
156
|
+
/******/ };
|
|
157
|
+
/******/ }();
|
|
158
|
+
/******/
|
|
159
|
+
/******/ /* webpack/runtime/node module decorator */
|
|
160
|
+
/******/ !function() {
|
|
161
|
+
/******/ __webpack_require__.nmd = function(module) {
|
|
162
|
+
/******/ module.paths = [];
|
|
163
|
+
/******/ if (!module.children) module.children = [];
|
|
164
|
+
/******/ return module;
|
|
165
|
+
/******/ };
|
|
166
|
+
/******/ }();
|
|
167
|
+
/******/
|
|
168
|
+
/******/ /* webpack/runtime/publicPath */
|
|
169
|
+
/******/ !function() {
|
|
170
|
+
/******/ __webpack_require__.p = "/";
|
|
171
|
+
/******/ }();
|
|
172
|
+
/******/
|
|
173
|
+
/******/ /* webpack/runtime/jsonp chunk loading */
|
|
174
|
+
/******/ !function() {
|
|
175
|
+
/******/ // no baseURI
|
|
176
|
+
/******/
|
|
177
|
+
/******/ // object to store loaded and loading chunks
|
|
178
|
+
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
|
|
179
|
+
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
|
|
180
|
+
/******/ var installedChunks = {
|
|
181
|
+
/******/ "mf-dep_mf": 0
|
|
182
|
+
/******/ };
|
|
183
|
+
/******/
|
|
184
|
+
/******/ __webpack_require__.f.j = function(chunkId, promises) {
|
|
185
|
+
/******/ // JSONP chunk loading for javascript
|
|
186
|
+
/******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
|
|
187
|
+
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
|
|
188
|
+
/******/
|
|
189
|
+
/******/ // a Promise means "currently loading".
|
|
190
|
+
/******/ if(installedChunkData) {
|
|
191
|
+
/******/ promises.push(installedChunkData[2]);
|
|
192
|
+
/******/ } else {
|
|
193
|
+
/******/ if(true) { // all chunks have JS
|
|
194
|
+
/******/ // setup Promise in chunk cache
|
|
195
|
+
/******/ var promise = new Promise(function(resolve, reject) { installedChunkData = installedChunks[chunkId] = [resolve, reject]; });
|
|
196
|
+
/******/ promises.push(installedChunkData[2] = promise);
|
|
197
|
+
/******/
|
|
198
|
+
/******/ // start chunk loading
|
|
199
|
+
/******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId);
|
|
200
|
+
/******/ // create error before stack unwound to get useful stacktrace later
|
|
201
|
+
/******/ var error = new Error();
|
|
202
|
+
/******/ var loadingEnded = function(event) {
|
|
203
|
+
/******/ if(__webpack_require__.o(installedChunks, chunkId)) {
|
|
204
|
+
/******/ installedChunkData = installedChunks[chunkId];
|
|
205
|
+
/******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
|
|
206
|
+
/******/ if(installedChunkData) {
|
|
207
|
+
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
|
|
208
|
+
/******/ var realSrc = event && event.target && event.target.src;
|
|
209
|
+
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';
|
|
210
|
+
/******/ error.name = 'ChunkLoadError';
|
|
211
|
+
/******/ error.type = errorType;
|
|
212
|
+
/******/ error.request = realSrc;
|
|
213
|
+
/******/ installedChunkData[1](error);
|
|
214
|
+
/******/ }
|
|
215
|
+
/******/ }
|
|
216
|
+
/******/ };
|
|
217
|
+
/******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId, chunkId);
|
|
218
|
+
/******/ } else installedChunks[chunkId] = 0;
|
|
219
|
+
/******/ }
|
|
220
|
+
/******/ }
|
|
221
|
+
/******/ };
|
|
222
|
+
/******/
|
|
223
|
+
/******/ // no prefetching
|
|
224
|
+
/******/
|
|
225
|
+
/******/ // no preloaded
|
|
226
|
+
/******/
|
|
227
|
+
/******/ // no HMR
|
|
228
|
+
/******/
|
|
229
|
+
/******/ // no HMR manifest
|
|
230
|
+
/******/
|
|
231
|
+
/******/ // no on chunks loaded
|
|
232
|
+
/******/
|
|
233
|
+
/******/ // install a JSONP callback for chunk loading
|
|
234
|
+
/******/ var webpackJsonpCallback = function(parentChunkLoadingFunction, data) {
|
|
235
|
+
/******/ var chunkIds = data[0];
|
|
236
|
+
/******/ var moreModules = data[1];
|
|
237
|
+
/******/ var runtime = data[2];
|
|
238
|
+
/******/ // add "moreModules" to the modules object,
|
|
239
|
+
/******/ // then flag all "chunkIds" as loaded and fire callback
|
|
240
|
+
/******/ var moduleId, chunkId, i = 0;
|
|
241
|
+
/******/ if(chunkIds.some(function(id) { return installedChunks[id] !== 0; })) {
|
|
242
|
+
/******/ for(moduleId in moreModules) {
|
|
243
|
+
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
|
|
244
|
+
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
|
|
245
|
+
/******/ }
|
|
246
|
+
/******/ }
|
|
247
|
+
/******/ if(runtime) var result = runtime(__webpack_require__);
|
|
248
|
+
/******/ }
|
|
249
|
+
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
|
|
250
|
+
/******/ for(;i < chunkIds.length; i++) {
|
|
251
|
+
/******/ chunkId = chunkIds[i];
|
|
252
|
+
/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
|
|
253
|
+
/******/ installedChunks[chunkId][0]();
|
|
254
|
+
/******/ }
|
|
255
|
+
/******/ installedChunks[chunkIds[i]] = 0;
|
|
256
|
+
/******/ }
|
|
257
|
+
/******/
|
|
258
|
+
/******/ }
|
|
259
|
+
/******/
|
|
260
|
+
/******/ var chunkLoadingGlobal = self["webpackChunk"] = self["webpackChunk"] || [];
|
|
261
|
+
/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
|
|
262
|
+
/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
|
|
263
|
+
/******/ }();
|
|
264
|
+
/******/
|
|
265
|
+
/************************************************************************/
|
|
266
|
+
var __webpack_exports__ = {};
|
|
267
|
+
(function() {
|
|
268
|
+
var exports = __webpack_exports__;
|
|
269
|
+
var moduleMap = {
|
|
270
|
+
${opts.deps.map(getDepModuleStr).join(',\n')}
|
|
271
|
+
};
|
|
272
|
+
var get = function(module, getScope) {
|
|
273
|
+
__webpack_require__.R = getScope;
|
|
274
|
+
getScope = (
|
|
275
|
+
__webpack_require__.o(moduleMap, module)
|
|
276
|
+
? moduleMap[module]()
|
|
277
|
+
: Promise.resolve().then(function() {
|
|
278
|
+
throw new Error('Module "' + module + '" does not exist in container.');
|
|
279
|
+
})
|
|
280
|
+
);
|
|
281
|
+
__webpack_require__.R = undefined;
|
|
282
|
+
return getScope;
|
|
283
|
+
};
|
|
284
|
+
var init = function(shareScope, initScope) {
|
|
285
|
+
if (!__webpack_require__.S) return;
|
|
286
|
+
var oldScope = __webpack_require__.S["default"];
|
|
287
|
+
var name = "default"
|
|
288
|
+
if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");
|
|
289
|
+
__webpack_require__.S[name] = shareScope;
|
|
290
|
+
return __webpack_require__.I(name, initScope);
|
|
291
|
+
};
|
|
292
|
+
__webpack_require__.d(exports, {
|
|
293
|
+
get: function() { return get; },
|
|
294
|
+
init: function() { return init; }
|
|
295
|
+
});
|
|
296
|
+
self.mf = __webpack_exports__;
|
|
297
|
+
})();
|
|
298
|
+
})();
|
|
299
|
+
`;
|
|
300
|
+
}
|
|
301
|
+
exports.getESBuildEntry = getESBuildEntry;
|
|
302
|
+
function normalizeFile(file) {
|
|
303
|
+
return file.replace(/\//g, '_');
|
|
304
|
+
}
|
|
305
|
+
function getDepModuleStr(dep) {
|
|
306
|
+
return `
|
|
307
|
+
"./${dep.file}": function() {
|
|
308
|
+
return new Promise(resolve => {
|
|
309
|
+
import('./${constants_1.MF_VA_PREFIX}${normalizeFile(dep.file)}.js').then(module => {
|
|
310
|
+
resolve(() => module);
|
|
311
|
+
});
|
|
312
|
+
})
|
|
313
|
+
}
|
|
314
|
+
`.trim();
|
|
315
|
+
}
|
package/dist/mfsu.d.ts
CHANGED
package/dist/mfsu.js
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
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
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,8 +16,9 @@ exports.MFSU = void 0;
|
|
|
35
16
|
const utils_1 = require("@umijs/utils");
|
|
36
17
|
const fs_1 = require("fs");
|
|
37
18
|
const path_1 = require("path");
|
|
38
|
-
const process = __importStar(require("process"));
|
|
39
19
|
const mrmime_1 = require("../compiled/mrmime");
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const webpack_virtual_modules_1 = __importDefault(require("../compiled/webpack-virtual-modules"));
|
|
40
22
|
const autoExport_1 = __importDefault(require("./babelPlugins/autoExport"));
|
|
41
23
|
const awaitImport_1 = __importDefault(require("./babelPlugins/awaitImport/awaitImport"));
|
|
42
24
|
const getRealPath_1 = require("./babelPlugins/awaitImport/getRealPath");
|
|
@@ -62,6 +44,7 @@ class MFSU {
|
|
|
62
44
|
this.opts.cwd = this.opts.cwd || process.cwd();
|
|
63
45
|
this.depInfo = new depInfo_1.DepInfo({ mfsu: this });
|
|
64
46
|
this.depBuilder = new depBuilder_1.DepBuilder({ mfsu: this });
|
|
47
|
+
this.depInfo.loadCache();
|
|
65
48
|
}
|
|
66
49
|
setWebpackConfig(opts) {
|
|
67
50
|
var _a;
|
|
@@ -72,8 +55,23 @@ class MFSU {
|
|
|
72
55
|
// set alias and externals with reference for babel plugin
|
|
73
56
|
Object.assign(this.alias, ((_a = opts.config.resolve) === null || _a === void 0 ? void 0 : _a.alias) || {});
|
|
74
57
|
this.externals.push(...(0, makeArray_1.makeArray)(opts.config.externals || []));
|
|
58
|
+
// entry
|
|
59
|
+
const entry = {};
|
|
60
|
+
const virtualModules = {};
|
|
61
|
+
Object.keys(opts.config.entry).forEach((key) => {
|
|
62
|
+
const virtualPath = `./mfsu-virtual-entry/${key}.js`;
|
|
63
|
+
virtualModules[virtualPath] =
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
opts.config
|
|
66
|
+
.entry[key].map((entry) => `await import('${entry}')`)
|
|
67
|
+
.join('\n') + `\nexport default 1;`;
|
|
68
|
+
entry[key] = virtualPath;
|
|
69
|
+
});
|
|
70
|
+
opts.config.entry = entry;
|
|
71
|
+
// plugins
|
|
75
72
|
opts.config.plugins = opts.config.plugins || [];
|
|
76
73
|
opts.config.plugins.push(...[
|
|
74
|
+
new webpack_virtual_modules_1.default(virtualModules),
|
|
77
75
|
new this.opts.implementor.container.ModuleFederationPlugin({
|
|
78
76
|
name: '__',
|
|
79
77
|
remotes: {
|
|
@@ -148,10 +146,15 @@ class MFSU {
|
|
|
148
146
|
onCollect: ({ file, data, }) => {
|
|
149
147
|
this.depInfo.moduleGraph.onFileChange({
|
|
150
148
|
file,
|
|
149
|
+
// @ts-ignore
|
|
151
150
|
deps: [
|
|
152
151
|
...Array.from(data.matched).map((item) => ({
|
|
153
152
|
file: item.sourceValue,
|
|
154
153
|
isDependency: true,
|
|
154
|
+
version: dep_1.Dep.getDepVersion({
|
|
155
|
+
dep: item.sourceValue,
|
|
156
|
+
cwd: this.opts.cwd,
|
|
157
|
+
}),
|
|
155
158
|
})),
|
|
156
159
|
...Array.from(data.unMatched).map((item) => ({
|
|
157
160
|
file: (0, getRealPath_1.getRealPath)({
|
package/dist/moduleGraph.d.ts
CHANGED
package/dist/moduleGraph.js
CHANGED
|
@@ -65,7 +65,7 @@ class ModuleGraph {
|
|
|
65
65
|
});
|
|
66
66
|
this.fileToModules.forEach((value, key) => {
|
|
67
67
|
fileModules[key] = {
|
|
68
|
-
|
|
68
|
+
importedModules: Array.from(value.importedModules).map((item) => item.file),
|
|
69
69
|
};
|
|
70
70
|
if (value.isRoot) {
|
|
71
71
|
roots.push(key);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StripSourceMapUrlPlugin = void 0;
|
|
4
|
+
class StripSourceMapUrlPlugin {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
this.opts = opts;
|
|
7
|
+
}
|
|
8
|
+
apply(compiler) {
|
|
9
|
+
compiler.hooks.compilation.tap('StripSourceMapUrlPlugin', (compilation) => {
|
|
10
|
+
compilation.hooks.processAssets.tap({
|
|
11
|
+
name: 'StripSourceMapUrlPlugin',
|
|
12
|
+
stage: this.opts.webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVE,
|
|
13
|
+
}, (assets) => {
|
|
14
|
+
Object.keys(assets)
|
|
15
|
+
.filter((filename) => /\.js$/.test(filename))
|
|
16
|
+
.forEach((filename) => {
|
|
17
|
+
const asset = assets[filename];
|
|
18
|
+
const source = asset
|
|
19
|
+
.source()
|
|
20
|
+
.toString()
|
|
21
|
+
.replace(/# sourceMappingURL=(.+?\.map)/g, '# $1');
|
|
22
|
+
compilation.updateAsset(filename, new this.opts.webpack.sources.RawSource(source));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.StripSourceMapUrlPlugin = StripSourceMapUrlPlugin;
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/mfsu",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.9",
|
|
4
4
|
"description": "@umijs/mfsu",
|
|
5
|
+
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
|
|
6
|
+
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/umijs/umi-next"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
5
12
|
"main": "dist/index.js",
|
|
6
13
|
"types": "dist/index.d.ts",
|
|
7
14
|
"files": [
|
|
@@ -13,34 +20,34 @@
|
|
|
13
20
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
14
21
|
"dev": "pnpm build -- --watch"
|
|
15
22
|
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "https://github.com/umijs/umi-next"
|
|
19
|
-
},
|
|
20
|
-
"authors": [
|
|
21
|
-
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
22
|
-
],
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
25
|
-
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
|
|
26
|
-
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
28
|
-
},
|
|
29
23
|
"dependencies": {
|
|
30
|
-
"@umijs/bundler-
|
|
31
|
-
"@umijs/utils": "4.0.0-beta.
|
|
24
|
+
"@umijs/bundler-esbuild": "4.0.0-beta.9",
|
|
25
|
+
"@umijs/bundler-utils": "4.0.0-beta.9",
|
|
26
|
+
"@umijs/utils": "4.0.0-beta.9"
|
|
32
27
|
},
|
|
33
28
|
"devDependencies": {
|
|
34
29
|
"@types/express": "4.17.13",
|
|
30
|
+
"enhanced-resolve": "5.8.3",
|
|
35
31
|
"mrmime": "1.0.0",
|
|
36
|
-
"webpack": "5.61.0"
|
|
32
|
+
"webpack": "5.61.0",
|
|
33
|
+
"webpack-virtual-modules": "0.4.3"
|
|
37
34
|
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"authors": [
|
|
39
|
+
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
40
|
+
],
|
|
38
41
|
"compiledConfig": {
|
|
39
42
|
"deps": [
|
|
40
|
-
"mrmime"
|
|
43
|
+
"mrmime",
|
|
44
|
+
"webpack-virtual-modules"
|
|
41
45
|
],
|
|
42
46
|
"externals": {
|
|
43
47
|
"mrmime": "$$LOCAL"
|
|
44
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"excludeDtsDeps": [
|
|
50
|
+
"webpack-virtual-modules"
|
|
51
|
+
]
|
|
45
52
|
}
|
|
46
53
|
}
|
package/dist/dep/getFilePath.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFilePath = void 0;
|
|
4
|
-
const utils_1 = require("@umijs/utils");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
// similar with resolve.extensions in webpack config
|
|
8
|
-
const EXT_NAMES = ['.ts', '.tsx', '.jsx', '.mjs', '.js'];
|
|
9
|
-
function getPathWithExt(path) {
|
|
10
|
-
if ((0, fs_1.existsSync)(path) && (0, fs_1.statSync)(path).isFile()) {
|
|
11
|
-
return path;
|
|
12
|
-
}
|
|
13
|
-
for (const extName of EXT_NAMES) {
|
|
14
|
-
const newPath = `${path}${extName}`;
|
|
15
|
-
if ((0, fs_1.existsSync)(newPath) && (0, fs_1.statSync)(newPath).isFile()) {
|
|
16
|
-
return newPath;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
function getPathWithPkgJSON(path) {
|
|
22
|
-
// TODO: 这里是否会有 symlink 问题?
|
|
23
|
-
if ((0, fs_1.existsSync)(path) && (0, fs_1.statSync)(path).isDirectory()) {
|
|
24
|
-
const pkgPath = (0, path_1.join)(path, 'package.json');
|
|
25
|
-
if ((0, fs_1.existsSync)(pkgPath)) {
|
|
26
|
-
const pkg = JSON.parse((0, fs_1.readFileSync)(pkgPath, 'utf-8'));
|
|
27
|
-
// ref: https://webpack.js.org/configuration/resolve/#resolvemainfields
|
|
28
|
-
// TODO: support browser object
|
|
29
|
-
// ref: https://unpkg.alibaba-inc.com/browse/react-dom@17.0.2/package.json
|
|
30
|
-
const indexTarget = (0, path_1.join)(path, 'index.js');
|
|
31
|
-
return ((pkg.module &&
|
|
32
|
-
(getPathWithExt((0, path_1.join)(path, pkg.module)) ||
|
|
33
|
-
getPathWithIndexFile((0, path_1.join)(path, pkg.module)))) ||
|
|
34
|
-
(pkg.main &&
|
|
35
|
-
(getPathWithExt((0, path_1.join)(path, pkg.main)) ||
|
|
36
|
-
getPathWithIndexFile((0, path_1.join)(path, pkg.main)))) ||
|
|
37
|
-
getPathWithExt(indexTarget) ||
|
|
38
|
-
getPathWithIndexFile(indexTarget));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
function getPathWithIndexFile(path) {
|
|
44
|
-
if ((0, fs_1.existsSync)(path) && (0, fs_1.statSync)(path).isDirectory()) {
|
|
45
|
-
for (const extName of EXT_NAMES) {
|
|
46
|
-
const indexFilePath = (0, path_1.join)(path, `index${extName}`);
|
|
47
|
-
if ((0, fs_1.existsSync)(indexFilePath) && (0, fs_1.statSync)(indexFilePath).isFile()) {
|
|
48
|
-
return indexFilePath;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
function getFilePath({ path }) {
|
|
55
|
-
// 1. 文件存在
|
|
56
|
-
// 2. 加后缀
|
|
57
|
-
const pathWithExt = getPathWithExt(path);
|
|
58
|
-
if (pathWithExt) {
|
|
59
|
-
return (0, utils_1.winPath)(pathWithExt);
|
|
60
|
-
}
|
|
61
|
-
// 3. path + package.json
|
|
62
|
-
const pathWithPkgJSON = getPathWithPkgJSON(path);
|
|
63
|
-
if (pathWithPkgJSON) {
|
|
64
|
-
return (0, utils_1.winPath)(pathWithPkgJSON);
|
|
65
|
-
}
|
|
66
|
-
// 4. path + index.js
|
|
67
|
-
const pathWithIndexFile = getPathWithIndexFile(path);
|
|
68
|
-
if (pathWithIndexFile) {
|
|
69
|
-
return (0, utils_1.winPath)(pathWithIndexFile);
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
exports.getFilePath = getFilePath;
|