@umijs/mfsu 4.0.0-beta.7 → 4.0.0-canary.202200505.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +26 -90
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +2 -1
- package/dist/babelPlugins/awaitImport/checkMatch.js +12 -4
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +5 -10
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +5 -1
- package/dist/dep/dep.d.ts +4 -0
- package/dist/dep/dep.js +54 -50
- package/dist/dep/getExposeFromContent.js +44 -55
- package/dist/dep/getModuleExports.js +24 -35
- package/dist/depBuilder/depBuilder.js +73 -74
- package/dist/depBuilder/getESBuildEntry.js +18 -5
- package/dist/depInfo.d.ts +1 -1
- package/dist/depInfo.js +11 -4
- package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
- package/dist/esbuildHandlers/autoCssModules.js +24 -0
- package/dist/esbuildHandlers/awaitImport/index.d.ts +12 -0
- package/dist/esbuildHandlers/awaitImport/index.js +44 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10 -1
- package/dist/loader/esbuild.d.ts +5 -0
- package/dist/loader/esbuild.js +38 -0
- package/dist/mfsu.d.ts +14 -5
- package/dist/mfsu.js +205 -67
- package/dist/moduleGraph.d.ts +2 -1
- package/dist/moduleGraph.js +11 -3
- package/dist/types.d.ts +12 -0
- package/package.json +29 -24
- package/dist/babelPlugins/autoExport.d.ts +0 -7
- package/dist/babelPlugins/autoExport.js +0 -61
|
@@ -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
|
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -21,10 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
23
27
|
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
28
|
function default_1() {
|
|
29
29
|
return {
|
|
30
30
|
pre() {
|
|
@@ -46,9 +46,6 @@ function default_1() {
|
|
|
46
46
|
visitor: {
|
|
47
47
|
Program: {
|
|
48
48
|
exit(path, { opts }) {
|
|
49
|
-
var _a;
|
|
50
|
-
const topDeclarations = [];
|
|
51
|
-
const bottomDeclarations = [];
|
|
52
49
|
let index = path.node.body.length - 1;
|
|
53
50
|
while (index >= 0) {
|
|
54
51
|
const node = path.node.body[index];
|
|
@@ -64,25 +61,8 @@ function default_1() {
|
|
|
64
61
|
opts,
|
|
65
62
|
path,
|
|
66
63
|
});
|
|
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
|
-
}
|
|
64
|
+
if (isMatch) {
|
|
65
|
+
node.source.value = replaceValue;
|
|
86
66
|
}
|
|
87
67
|
}
|
|
88
68
|
// export * from 'x';
|
|
@@ -93,28 +73,9 @@ function default_1() {
|
|
|
93
73
|
value: node.source.value,
|
|
94
74
|
opts,
|
|
95
75
|
path,
|
|
96
|
-
isExportAll: true,
|
|
97
76
|
});
|
|
98
77
|
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
|
-
}
|
|
78
|
+
node.source.value = replaceValue;
|
|
118
79
|
}
|
|
119
80
|
}
|
|
120
81
|
// export { x } from 'x';
|
|
@@ -127,56 +88,31 @@ function default_1() {
|
|
|
127
88
|
path,
|
|
128
89
|
});
|
|
129
90
|
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
|
-
}
|
|
91
|
+
node.source.value = replaceValue;
|
|
153
92
|
}
|
|
154
93
|
}
|
|
155
94
|
index -= 1;
|
|
156
95
|
}
|
|
157
|
-
path.node.body = [
|
|
158
|
-
...topDeclarations,
|
|
159
|
-
...path.node.body,
|
|
160
|
-
...bottomDeclarations,
|
|
161
|
-
];
|
|
162
96
|
},
|
|
163
97
|
},
|
|
164
|
-
CallExpression
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
node.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
98
|
+
CallExpression: {
|
|
99
|
+
exit(path, { opts }) {
|
|
100
|
+
const { node } = path;
|
|
101
|
+
if (t.isImport(node.callee) &&
|
|
102
|
+
node.arguments.length === 1 &&
|
|
103
|
+
node.arguments[0].type === 'StringLiteral') {
|
|
104
|
+
const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
cache: this.cache,
|
|
107
|
+
value: node.arguments[0].value,
|
|
108
|
+
opts,
|
|
109
|
+
path,
|
|
110
|
+
});
|
|
111
|
+
if (isMatch) {
|
|
112
|
+
node.arguments[0] = t.stringLiteral(replaceValue);
|
|
113
|
+
}
|
|
178
114
|
}
|
|
179
|
-
}
|
|
115
|
+
},
|
|
180
116
|
},
|
|
181
117
|
},
|
|
182
118
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
|
|
2
2
|
import type { IOpts } from './awaitImport';
|
|
3
|
-
export declare function checkMatch({ value, path, opts, isExportAll, depth, cache, }: {
|
|
3
|
+
export declare function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }: {
|
|
4
4
|
value: string;
|
|
5
5
|
path?: Babel.NodePath;
|
|
6
6
|
opts?: IOpts;
|
|
7
7
|
isExportAll?: boolean;
|
|
8
8
|
depth?: number;
|
|
9
9
|
cache?: Map<string, any>;
|
|
10
|
+
filename?: string;
|
|
10
11
|
}): {
|
|
11
12
|
isMatch: boolean;
|
|
12
13
|
replaceValue: string;
|
|
@@ -12,7 +12,10 @@ const isExternals_1 = require("./isExternals");
|
|
|
12
12
|
// const UNMATCH_LIBS = ['umi', 'dumi', '@alipay/bigfish'];
|
|
13
13
|
const RE_NODE_MODULES = /node_modules/;
|
|
14
14
|
const RE_UMI_LOCAL_DEV = /umi(-next)?\/packages\//;
|
|
15
|
-
function
|
|
15
|
+
function isUmiLocalDev(path) {
|
|
16
|
+
return RE_UMI_LOCAL_DEV.test((0, utils_1.winPath)(path));
|
|
17
|
+
}
|
|
18
|
+
function checkMatch({ value, path, opts, isExportAll, depth, cache, filename, }) {
|
|
16
19
|
var _a, _b;
|
|
17
20
|
let isMatch;
|
|
18
21
|
let replaceValue = '';
|
|
@@ -20,9 +23,13 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
|
|
|
20
23
|
(0, assert_1.default)(depth <= 10, `endless loop detected in checkMatch, please check your alias config.`);
|
|
21
24
|
opts = opts || {};
|
|
22
25
|
const remoteName = opts.remoteName || 'mf';
|
|
26
|
+
// FIXME: hard code for vite mode
|
|
27
|
+
value = value.replace(/^@fs\//, '/');
|
|
23
28
|
if (
|
|
24
29
|
// unMatch specified libs
|
|
25
30
|
((_a = opts.unMatchLibs) === null || _a === void 0 ? void 0 : _a.includes(value)) ||
|
|
31
|
+
// do not match bundler-webpack/client/client/client.js
|
|
32
|
+
value.includes('client/client/client.js') ||
|
|
26
33
|
// already handled
|
|
27
34
|
value.startsWith(`${remoteName}/`) ||
|
|
28
35
|
// don't match dynamic path
|
|
@@ -38,7 +45,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
|
|
|
38
45
|
isMatch = false;
|
|
39
46
|
}
|
|
40
47
|
else if ((0, path_1.isAbsolute)(value)) {
|
|
41
|
-
isMatch = RE_NODE_MODULES.test(value) ||
|
|
48
|
+
isMatch = RE_NODE_MODULES.test(value) || isUmiLocalDev(value);
|
|
42
49
|
}
|
|
43
50
|
else {
|
|
44
51
|
const aliasedPath = (0, getAliasedPath_1.getAliasedPath)({
|
|
@@ -53,6 +60,7 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
|
|
|
53
60
|
isExportAll,
|
|
54
61
|
depth: depth + 1,
|
|
55
62
|
cache,
|
|
63
|
+
filename,
|
|
56
64
|
});
|
|
57
65
|
}
|
|
58
66
|
else {
|
|
@@ -63,10 +71,10 @@ function checkMatch({ value, path, opts, isExportAll, depth, cache, }) {
|
|
|
63
71
|
isMatch = !!(opts.exportAllMembers && value in opts.exportAllMembers);
|
|
64
72
|
}
|
|
65
73
|
if (isMatch) {
|
|
66
|
-
replaceValue = `${remoteName}/${value}`;
|
|
74
|
+
replaceValue = `${remoteName}/${(0, utils_1.winPath)(value)}`;
|
|
67
75
|
}
|
|
68
76
|
// @ts-ignore
|
|
69
|
-
const file = path === null || path === void 0 ? void 0 : path.hub.file.opts.filename;
|
|
77
|
+
const file = (path === null || path === void 0 ? void 0 : path.hub.file.opts.filename) || filename;
|
|
70
78
|
(_b = opts.onTransformDeps) === null || _b === void 0 ? void 0 : _b.call(opts, {
|
|
71
79
|
sourceValue: value,
|
|
72
80
|
replaceValue,
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAliasedPath = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
4
|
function getAliasedPath({ value, alias, }) {
|
|
6
5
|
const importValue = value;
|
|
6
|
+
// equal alias
|
|
7
|
+
if (alias[value]) {
|
|
8
|
+
return alias[value];
|
|
9
|
+
}
|
|
7
10
|
for (const key of Object.keys(alias)) {
|
|
8
11
|
const aliasValue = alias[key];
|
|
9
12
|
// exact alias
|
|
@@ -15,21 +18,13 @@ function getAliasedPath({ value, alias, }) {
|
|
|
15
18
|
else
|
|
16
19
|
continue;
|
|
17
20
|
}
|
|
18
|
-
// e.g. foo: path/to/foo
|
|
19
|
-
if (importValue === key) {
|
|
20
|
-
return aliasValue;
|
|
21
|
-
}
|
|
22
21
|
// e.g. foo: path/to/foo.js
|
|
23
|
-
|
|
24
|
-
if (importValue.startsWith(slashedKey)) {
|
|
22
|
+
if (importValue.startsWith(addLastSlash(key))) {
|
|
25
23
|
return importValue.replace(key, aliasValue);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
exports.getAliasedPath = getAliasedPath;
|
|
30
|
-
function isJSFile(path) {
|
|
31
|
-
return ['.js', '.jsx', '.ts', '.tsx'].includes((0, path_1.extname)(path));
|
|
32
|
-
}
|
|
33
28
|
function addLastSlash(path) {
|
|
34
29
|
return path.endsWith('/') ? path : `${path}/`;
|
|
35
30
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/dep/dep.d.ts
CHANGED
package/dist/dep/dep.js
CHANGED
|
@@ -1,92 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.Dep = void 0;
|
|
7
|
+
const utils_1 = require("@umijs/utils");
|
|
16
8
|
const assert_1 = __importDefault(require("assert"));
|
|
17
9
|
const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
|
|
18
10
|
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
19
12
|
const constants_1 = require("../constants");
|
|
20
13
|
const trimFileContent_1 = require("../utils/trimFileContent");
|
|
21
14
|
const getExposeFromContent_1 = require("./getExposeFromContent");
|
|
22
15
|
const resolver = enhanced_resolve_1.default.create({
|
|
23
16
|
mainFields: ['module', 'browser', 'main'],
|
|
24
17
|
extensions: ['.js', '.json', '.mjs'],
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
exportsFields: [],
|
|
18
|
+
exportsFields: ['exports'],
|
|
19
|
+
conditionNames: ['import', 'module', 'require', 'node'],
|
|
28
20
|
});
|
|
29
|
-
function resolve(context, path) {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
|
|
33
|
-
});
|
|
21
|
+
async function resolve(context, path) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
|
|
34
24
|
});
|
|
35
25
|
}
|
|
36
26
|
class Dep {
|
|
37
27
|
constructor(opts) {
|
|
38
|
-
this.file = opts.file;
|
|
28
|
+
this.file = (0, utils_1.winPath)(opts.file);
|
|
39
29
|
this.version = opts.version;
|
|
40
30
|
this.cwd = opts.cwd;
|
|
41
|
-
this.shortFile = this.file
|
|
31
|
+
this.shortFile = this.file;
|
|
42
32
|
this.normalizedFile = this.shortFile.replace(/\//g, '_').replace(/:/g, '_');
|
|
43
33
|
this.filePath = `${constants_1.MF_VA_PREFIX}${this.normalizedFile}.js`;
|
|
44
34
|
this.mfsu = opts.mfsu;
|
|
45
35
|
}
|
|
46
|
-
buildExposeContent() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
? `
|
|
36
|
+
async buildExposeContent() {
|
|
37
|
+
// node natives
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const isNodeNatives = !!process.binding('natives')[this.file];
|
|
40
|
+
if (isNodeNatives) {
|
|
41
|
+
return (0, trimFileContent_1.trimFileContent)(this.mfsu.opts.excludeNodeNatives
|
|
42
|
+
? `
|
|
54
43
|
const _ = require('${this.file}');
|
|
55
44
|
module.exports = _;
|
|
56
45
|
`
|
|
57
|
-
|
|
46
|
+
: `
|
|
58
47
|
import _ from '${this.file}';
|
|
59
48
|
export default _;
|
|
60
49
|
export * from '${this.file}';
|
|
61
50
|
`);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
51
|
+
}
|
|
52
|
+
// none node natives
|
|
53
|
+
const realFile = await this.getRealFile();
|
|
54
|
+
(0, assert_1.default)(realFile, `filePath not found of ${this.file}`);
|
|
55
|
+
const content = (0, fs_1.readFileSync)(realFile, 'utf-8');
|
|
56
|
+
return await (0, getExposeFromContent_1.getExposeFromContent)({
|
|
57
|
+
content,
|
|
58
|
+
filePath: realFile,
|
|
59
|
+
dep: this,
|
|
72
60
|
});
|
|
73
61
|
}
|
|
74
|
-
getRealFile() {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
});
|
|
62
|
+
async getRealFile() {
|
|
63
|
+
try {
|
|
64
|
+
// don't need to handle alias here
|
|
65
|
+
// it's already handled by babel plugin
|
|
66
|
+
return await resolve(this.cwd, this.file);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
85
71
|
}
|
|
86
72
|
static buildDeps(opts) {
|
|
87
73
|
return Object.keys(opts.deps).map((file) => {
|
|
88
|
-
return new Dep(
|
|
74
|
+
return new Dep({
|
|
75
|
+
...opts.deps[file],
|
|
76
|
+
cwd: opts.cwd,
|
|
77
|
+
mfsu: opts.mfsu,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
static getDepVersion(opts) {
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
if (!!process.binding('natives')[opts.dep]) {
|
|
84
|
+
return '*';
|
|
85
|
+
}
|
|
86
|
+
const dep = (0, path_1.isAbsolute)(opts.dep)
|
|
87
|
+
? opts.dep
|
|
88
|
+
: (0, path_1.join)(opts.cwd, 'node_modules', opts.dep);
|
|
89
|
+
const pkg = utils_1.pkgUp.pkgUpSync({
|
|
90
|
+
cwd: dep,
|
|
89
91
|
});
|
|
92
|
+
(0, assert_1.default)(pkg, `package.json not found for ${opts.dep}`);
|
|
93
|
+
return require(pkg).version;
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
96
|
exports.Dep = Dep;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -16,62 +7,60 @@ exports.getExposeFromContent = void 0;
|
|
|
16
7
|
const assert_1 = __importDefault(require("assert"));
|
|
17
8
|
const path_1 = require("path");
|
|
18
9
|
const getModuleExports_1 = require("./getModuleExports");
|
|
19
|
-
function getExposeFromContent(opts) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return `
|
|
10
|
+
async function getExposeFromContent(opts) {
|
|
11
|
+
// Support CSS
|
|
12
|
+
if (opts.filePath &&
|
|
13
|
+
/\.(css|less|scss|sass|stylus|styl)$/.test(opts.filePath)) {
|
|
14
|
+
return `import '${opts.dep.file}';`;
|
|
15
|
+
}
|
|
16
|
+
// Support Assets Files
|
|
17
|
+
if (opts.filePath &&
|
|
18
|
+
/\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(opts.filePath)) {
|
|
19
|
+
return `
|
|
30
20
|
import _ from '${opts.dep.file}';
|
|
31
21
|
export default _;`.trim();
|
|
22
|
+
}
|
|
23
|
+
(0, assert_1.default)(/(js|jsx|mjs|ts|tsx)$/.test(opts.filePath), `file type not supported for ${(0, path_1.basename)(opts.filePath)}.`);
|
|
24
|
+
const { exports, isCJS } = await (0, getModuleExports_1.getModuleExports)({
|
|
25
|
+
content: opts.content,
|
|
26
|
+
filePath: opts.filePath,
|
|
27
|
+
});
|
|
28
|
+
// cjs
|
|
29
|
+
if (isCJS) {
|
|
30
|
+
return [
|
|
31
|
+
`import _ from '${opts.dep.file}';`,
|
|
32
|
+
`export default _;`,
|
|
33
|
+
`export * from '${opts.dep.file}';`,
|
|
34
|
+
].join('\n');
|
|
35
|
+
}
|
|
36
|
+
// esm
|
|
37
|
+
else {
|
|
38
|
+
const ret = [];
|
|
39
|
+
let hasExports = false;
|
|
40
|
+
if (exports.includes('default')) {
|
|
41
|
+
ret.push(`import _ from '${opts.dep.file}';`);
|
|
42
|
+
ret.push(`export default _;`);
|
|
43
|
+
hasExports = true;
|
|
32
44
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
if (hasNonDefaultExports(exports) ||
|
|
46
|
+
// export * from 不会有 exports,只会有 imports
|
|
47
|
+
/export\s+\*\s+from/.test(opts.content)) {
|
|
48
|
+
ret.push(`export * from '${opts.dep.file}';`);
|
|
49
|
+
hasExports = true;
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let hasExports = false;
|
|
50
|
-
if (exports.includes('default')) {
|
|
51
|
+
if (!hasExports) {
|
|
52
|
+
// 只有 __esModule 的全量导出
|
|
53
|
+
if (exports.includes('__esModule')) {
|
|
51
54
|
ret.push(`import _ from '${opts.dep.file}';`);
|
|
52
55
|
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
56
|
ret.push(`export * from '${opts.dep.file}';`);
|
|
59
|
-
hasExports = true;
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
}
|
|
58
|
+
else {
|
|
59
|
+
ret.push(`import '${opts.dep.file}';`);
|
|
71
60
|
}
|
|
72
|
-
return ret.join('\n');
|
|
73
61
|
}
|
|
74
|
-
|
|
62
|
+
return ret.join('\n');
|
|
63
|
+
}
|
|
75
64
|
}
|
|
76
65
|
exports.getExposeFromContent = getExposeFromContent;
|
|
77
66
|
function hasNonDefaultExports(exports) {
|