@umijs/mfsu 4.0.0-beta.9 → 4.0.0-canary-20240513.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/is-absolute-url/LICENSE +9 -0
- package/compiled/is-absolute-url/index.d.ts +20 -0
- package/compiled/is-absolute-url/index.js +1 -0
- package/compiled/is-absolute-url/package.json +1 -0
- package/compiled/mrmime/package.json +1 -1
- package/compiled/webpack-virtual-modules/index.js +1 -1
- package/compiled/webpack-virtual-modules/package.json +1 -1
- package/dist/babelPlugins/awaitImport/MFImport.d.ts +24 -0
- package/dist/babelPlugins/awaitImport/MFImport.js +66 -0
- package/dist/babelPlugins/awaitImport/awaitImport.d.ts +1 -1
- package/dist/babelPlugins/awaitImport/awaitImport.js +111 -112
- package/dist/babelPlugins/awaitImport/checkMatch.d.ts +3 -1
- package/dist/babelPlugins/awaitImport/checkMatch.js +166 -109
- package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +2 -2
- package/dist/babelPlugins/awaitImport/getAliasedPath.js +44 -33
- package/dist/babelPlugins/awaitImport/getRealPath.js +42 -21
- package/dist/babelPlugins/awaitImport/isExternals.js +55 -26
- package/dist/babelPlugins/awaitImport/parseSpecifiers.js +62 -47
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +50 -10
- package/dist/dep/dep.d.ts +7 -3
- package/dist/dep/dep.js +117 -95
- package/dist/dep/getCJSExports.js +83 -47
- package/dist/dep/getExposeFromContent.js +99 -74
- package/dist/dep/getModuleExports.js +58 -43
- package/dist/depBuilder/depBuilder.d.ts +6 -1
- package/dist/depBuilder/depBuilder.js +222 -159
- package/dist/depBuilder/getESBuildEntry.d.ts +1 -0
- package/dist/depBuilder/getESBuildEntry.js +50 -14
- package/dist/depInfo.d.ts +20 -5
- package/dist/depInfo.js +90 -39
- package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
- package/dist/esbuildHandlers/autoCssModules.js +48 -0
- package/dist/esbuildHandlers/awaitImport/index.d.ts +15 -0
- package/dist/esbuildHandlers/awaitImport/index.js +86 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +35 -13
- package/dist/loader/esbuild.d.ts +5 -0
- package/dist/loader/esbuild.js +79 -0
- package/dist/mfsu/mfsu.d.ts +69 -0
- package/dist/mfsu/mfsu.js +319 -0
- package/dist/mfsu/strategyCompileTime.d.ts +20 -0
- package/dist/mfsu/strategyCompileTime.js +142 -0
- package/dist/mfsu/strategyStaticAnalyze.d.ts +24 -0
- package/dist/mfsu/strategyStaticAnalyze.js +196 -0
- package/dist/moduleGraph.d.ts +5 -8
- package/dist/moduleGraph.js +228 -178
- package/dist/staticDepInfo/importParser.d.ts +4 -0
- package/dist/staticDepInfo/importParser.js +28 -0
- package/dist/staticDepInfo/simulations/babel-plugin-import.d.ts +15 -0
- package/dist/staticDepInfo/simulations/babel-plugin-import.js +118 -0
- package/dist/staticDepInfo/staticDepInfo.d.ts +61 -0
- package/dist/staticDepInfo/staticDepInfo.js +274 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +33 -8
- package/dist/utils/makeArray.js +29 -5
- package/dist/utils/resolveUtils.d.ts +1 -0
- package/dist/utils/resolveUtils.js +104 -0
- package/dist/utils/trimFileContent.js +29 -5
- package/dist/utils/webpackUtils.d.ts +3 -0
- package/dist/utils/webpackUtils.js +80 -0
- package/dist/webpackPlugins/buildDepPlugin.d.ts +4 -3
- package/dist/webpackPlugins/buildDepPlugin.js +61 -17
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +1 -1
- package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +47 -19
- package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +55 -27
- package/dist/webpackPlugins/writeCachePlugin.js +45 -15
- package/package.json +23 -19
- package/vendors/importParser/_importParser.js +683 -0
- package/vendors/importParser/importParser.jison +105 -0
- package/dist/babelPlugins/autoExport.d.ts +0 -7
- package/dist/babelPlugins/autoExport.js +0 -61
- package/dist/mfsu.d.ts +0 -54
- package/dist/mfsu.js +0 -179
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Check if a URL is absolute.
|
|
3
|
+
|
|
4
|
+
@param url - The URL to check.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import isAbsoluteUrl from './is-absolute-url';
|
|
9
|
+
|
|
10
|
+
isAbsoluteUrl('http://sindresorhus.com/foo/bar');
|
|
11
|
+
//=> true
|
|
12
|
+
|
|
13
|
+
isAbsoluteUrl('//sindresorhus.com');
|
|
14
|
+
//=> false
|
|
15
|
+
|
|
16
|
+
isAbsoluteUrl('foo/bar');
|
|
17
|
+
//=> false
|
|
18
|
+
```
|
|
19
|
+
*/
|
|
20
|
+
export default function isAbsoluteUrl(url: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";var e={};!function(){e.d=function(t,n){for(var o in n){if(e.o(n,o)&&!e.o(t,o)){Object.defineProperty(t,o,{enumerable:true,get:n[o]})}}}}();!function(){e.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}}();!function(){e.r=function(e){if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}}();if(typeof e!=="undefined")e.ab=__dirname+"/";var t={};e.r(t);e.d(t,{default:function(){return isAbsoluteUrl}});const n=/^[a-zA-Z][a-zA-Z\d+\-.]*?:/;const o=/^[a-zA-Z]:\\/;function isAbsoluteUrl(e){if(typeof e!=="string"){throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``)}if(o.test(e)){return false}return n.test(e)}module.exports=t})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"is-absolute-url","version":"4.0.1","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mrmime","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"license":"MIT","types":"index.d.ts"}
|
|
1
|
+
{"name":"mrmime","version":"1.0.1","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"license":"MIT","types":"index.d.ts"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";var e={
|
|
1
|
+
(function(){"use strict";var e={984:function(e,t,i){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};const a=r(i(17));const s=i(584);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 i=t._currentLevel;const r=t._levels[i];return{result:e,level:r}}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,i){const r=i(e);if(e._data instanceof Map){e._data.set(t,r)}else if(e._data){e.data[t]=r}else if(e.data instanceof Map){e.data.set(t,r)}else{e.data[t]=r}}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 i=t?t.length:0;const r=Date.now();const a=new Date(r);const o=new s.VirtualStats({dev:8675309,nlink:0,uid:1e3,gid:1e3,rdev:0,blksize:4096,ino:n++,mode:33188,size:i,blocks:Math.floor(i/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 e=c.watcher.fileWatchers instanceof Map?Array.from(c.watcher.fileWatchers.values()):c.watcher.fileWatchers;for(let t of e){if("watcher"in t){t=t.watcher}if(t.path===l){if(process.env.DEBUG)console.log(this._compiler.name,"Emit file change:",l,r);delete t.directoryWatcher._cachedTimeInfoEntries;t.emit("change",r,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 i=t._virtualFiles[e];t._writeVirtualFile(e,i.stats,i.contents)}))}};t._writeVirtualFile=(e,i,r)=>{const o=getStatStorage(t);const l=getFileStorage(t);const c=getReadDirBackend(t);t._virtualFiles=t._virtualFiles||{};t._virtualFiles[e]={stats:i,contents:r};setData(o,e,createWebpackData(i));setData(l,e,createWebpackData(r));const u=e.split(/[\\/]/);let d=u.length-1;const f=u[0]?1:0;while(d>f){const e=u.slice(0,d).join(a.default.sep)||a.default.sep;try{t.readdirSync(e)}catch(t){const r=Date.now();const a=new s.VirtualStats({dev:8675309,nlink:0,uid:1e3,gid:1e3,rdev:0,blksize:4096,ino:n++,mode:16877,size:i.size,blocks:Math.floor(i.size/4096),atime:r,mtime:r,ctime:r,birthtime:r});setData(c,e,createWebpackData([]));setData(o,e,createWebpackData(a))}let r=getData(getReadDirBackend(t),e);r=r[1]||r.result;const l=u[d];if(r.indexOf(l)<0){const i=r.concat([l]).sort();setData(getReadDirBackend(t),e,createWebpackData(i))}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 t=typeof e.webpack==="undefined"?4:5;const watchRunHook=(i,r)=>{this._watcher=i.compiler||i;const a=e.inputFileSystem._virtualFiles;const s=e.fileTimestamps;if(a&&s&&typeof s.set==="function"){Object.keys(a).forEach((e=>{const i=+a[e].stats.mtime;s.set(e,t===4?i:{safeTime:i,timestamp:i})}))}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},584:function(e,t,i){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:true});t.VirtualStats=void 0;const a=r(i(57));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},57:function(e){e.exports=require("constants")},17:function(e){e.exports=require("path")}};var t={};function __nccwpck_require__(i){var r=t[i];if(r!==undefined){return r.exports}var a=t[i]={exports:{}};var s=true;try{e[i].call(a.exports,a,a.exports,__nccwpck_require__);s=false}finally{if(s)delete t[i]}return a.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var i=__nccwpck_require__(984);module.exports=i})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"webpack-virtual-modules","author":"SysGears INC","license":"MIT"}
|
|
1
|
+
{"name":"webpack-virtual-modules","version":"0.5.0","author":"SysGears INC","license":"MIT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
|
|
2
|
+
import * as t from '@umijs/bundler-utils/compiled/babel/types';
|
|
3
|
+
export interface IOpts {
|
|
4
|
+
resolveImportSource: (importSource: string) => string;
|
|
5
|
+
exportAllMembers?: Record<string, string[]>;
|
|
6
|
+
unMatchLibs?: string[];
|
|
7
|
+
remoteName?: string;
|
|
8
|
+
alias?: Record<string, string>;
|
|
9
|
+
externals?: any;
|
|
10
|
+
}
|
|
11
|
+
export default function (): {
|
|
12
|
+
visitor: {
|
|
13
|
+
Program: {
|
|
14
|
+
exit(path: Babel.NodePath<t.Program>, { opts }: {
|
|
15
|
+
opts: IOpts;
|
|
16
|
+
}): void;
|
|
17
|
+
};
|
|
18
|
+
CallExpression: {
|
|
19
|
+
exit(path: Babel.NodePath<t.CallExpression>, { opts }: {
|
|
20
|
+
opts: IOpts;
|
|
21
|
+
}): void;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/babelPlugins/awaitImport/MFImport.ts
|
|
30
|
+
var MFImport_exports = {};
|
|
31
|
+
__export(MFImport_exports, {
|
|
32
|
+
default: () => MFImport_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(MFImport_exports);
|
|
35
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
|
+
function MFImport_default() {
|
|
37
|
+
return {
|
|
38
|
+
visitor: {
|
|
39
|
+
Program: {
|
|
40
|
+
exit(path, { opts }) {
|
|
41
|
+
let index = path.node.body.length - 1;
|
|
42
|
+
while (index >= 0) {
|
|
43
|
+
const node = path.node.body[index];
|
|
44
|
+
if (t.isImportDeclaration(node)) {
|
|
45
|
+
node.source.value = opts.resolveImportSource(node.source.value);
|
|
46
|
+
} else if (t.isExportAllDeclaration(node)) {
|
|
47
|
+
node.source.value = opts.resolveImportSource(node.source.value);
|
|
48
|
+
} else if (t.isExportNamedDeclaration(node) && node.source) {
|
|
49
|
+
node.source.value = opts.resolveImportSource(node.source.value);
|
|
50
|
+
}
|
|
51
|
+
index -= 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
CallExpression: {
|
|
56
|
+
exit(path, { opts }) {
|
|
57
|
+
const { node } = path;
|
|
58
|
+
if (t.isImport(node.callee) && node.arguments.length === 1 && t.isStringLiteral(node.arguments[0])) {
|
|
59
|
+
const newValue = opts.resolveImportSource(node.arguments[0].value);
|
|
60
|
+
node.arguments[0].value = newValue;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -4,7 +4,7 @@ export interface IOpts {
|
|
|
4
4
|
onTransformDeps?: Function;
|
|
5
5
|
onCollect?: Function;
|
|
6
6
|
exportAllMembers?: Record<string, string[]>;
|
|
7
|
-
unMatchLibs?: string
|
|
7
|
+
unMatchLibs?: Array<string | RegExp>;
|
|
8
8
|
remoteName?: string;
|
|
9
9
|
alias?: Record<string, string>;
|
|
10
10
|
externals?: any;
|
|
@@ -1,116 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
20
18
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/babelPlugins/awaitImport/awaitImport.ts
|
|
30
|
+
var awaitImport_exports = {};
|
|
31
|
+
__export(awaitImport_exports, {
|
|
32
|
+
default: () => awaitImport_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(awaitImport_exports);
|
|
35
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
|
+
var import_checkMatch = require("./checkMatch");
|
|
37
|
+
function awaitImport_default() {
|
|
38
|
+
return {
|
|
39
|
+
pre() {
|
|
40
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
41
|
+
},
|
|
42
|
+
post(state) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const { cache } = this;
|
|
45
|
+
if (cache.has(state.opts.filename)) {
|
|
46
|
+
(_b = (_a = this.opts).onCollect) == null ? void 0 : _b.call(_a, {
|
|
47
|
+
file: state.opts.filename,
|
|
48
|
+
data: cache.get(state.opts.filename)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
visitor: {
|
|
53
|
+
Program: {
|
|
54
|
+
exit(path, { opts }) {
|
|
55
|
+
let index = path.node.body.length - 1;
|
|
56
|
+
while (index >= 0) {
|
|
57
|
+
const node = path.node.body[index];
|
|
58
|
+
if (t.isImportDeclaration(node)) {
|
|
59
|
+
const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
|
|
35
60
|
// @ts-ignore
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
cache: this.cache,
|
|
62
|
+
value: node.source.value,
|
|
63
|
+
opts,
|
|
64
|
+
path
|
|
65
|
+
});
|
|
66
|
+
if (isMatch) {
|
|
67
|
+
node.source.value = replaceValue;
|
|
68
|
+
}
|
|
69
|
+
} else if (t.isExportAllDeclaration(node)) {
|
|
70
|
+
const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
cache: this.cache,
|
|
73
|
+
value: node.source.value,
|
|
74
|
+
opts,
|
|
75
|
+
path
|
|
76
|
+
});
|
|
77
|
+
if (isMatch) {
|
|
78
|
+
node.source.value = replaceValue;
|
|
79
|
+
}
|
|
80
|
+
} else if (t.isExportNamedDeclaration(node) && node.source) {
|
|
81
|
+
const { isMatch, replaceValue } = (0, import_checkMatch.checkMatch)({
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
cache: this.cache,
|
|
84
|
+
value: node.source.value,
|
|
85
|
+
opts,
|
|
86
|
+
path
|
|
87
|
+
});
|
|
88
|
+
if (isMatch) {
|
|
89
|
+
node.source.value = replaceValue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
index -= 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
CallExpression: {
|
|
97
|
+
exit(path, { opts }) {
|
|
98
|
+
const { node } = path;
|
|
99
|
+
if (t.isImport(node.callee) && node.arguments.length === 1 && node.arguments[0].type === "StringLiteral") {
|
|
100
|
+
const { isMatch, replaceValue } = (0, import_checkMatch.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);
|
|
40
109
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
while (index >= 0) {
|
|
47
|
-
const node = path.node.body[index];
|
|
48
|
-
// import x from 'x';
|
|
49
|
-
// import * as x from 'x';
|
|
50
|
-
// import x, * as xx from 'x';
|
|
51
|
-
// import { x } from 'x';
|
|
52
|
-
if (t.isImportDeclaration(node)) {
|
|
53
|
-
const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
cache: this.cache,
|
|
56
|
-
value: node.source.value,
|
|
57
|
-
opts,
|
|
58
|
-
path,
|
|
59
|
-
});
|
|
60
|
-
if (isMatch) {
|
|
61
|
-
node.source.value = replaceValue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// export * from 'x';
|
|
65
|
-
else if (t.isExportAllDeclaration(node)) {
|
|
66
|
-
const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
cache: this.cache,
|
|
69
|
-
value: node.source.value,
|
|
70
|
-
opts,
|
|
71
|
-
path,
|
|
72
|
-
});
|
|
73
|
-
if (isMatch) {
|
|
74
|
-
node.source.value = replaceValue;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// export { x } from 'x';
|
|
78
|
-
else if (t.isExportNamedDeclaration(node) && node.source) {
|
|
79
|
-
const { isMatch, replaceValue } = (0, checkMatch_1.checkMatch)({
|
|
80
|
-
// @ts-ignore
|
|
81
|
-
cache: this.cache,
|
|
82
|
-
value: node.source.value,
|
|
83
|
-
opts,
|
|
84
|
-
path,
|
|
85
|
-
});
|
|
86
|
-
if (isMatch) {
|
|
87
|
-
node.source.value = replaceValue;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
index -= 1;
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
},
|
|
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
|
-
}
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
115
|
}
|
|
116
|
-
exports.default = default_1;
|
|
@@ -1,15 +1,17 @@
|
|
|
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;
|
|
14
|
+
value: string;
|
|
13
15
|
};
|
|
14
16
|
export declare function getPath({ value, opts }: {
|
|
15
17
|
value: string;
|