@umijs/mfsu 4.0.34 → 4.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dep/dep.js +2 -23
- package/dist/depBuilder/depBuilder.js +4 -1
- package/dist/depBuilder/getESBuildEntry.d.ts +1 -0
- package/dist/depBuilder/getESBuildEntry.js +1 -1
- package/dist/mfsu/mfsu.js +5 -10
- package/dist/utils/resolveUtils.d.ts +1 -0
- package/dist/utils/resolveUtils.js +89 -0
- package/dist/utils/webpackUtils.d.ts +2 -1
- package/dist/utils/webpackUtils.js +21 -2
- package/package.json +4 -4
package/dist/dep/dep.js
CHANGED
|
@@ -27,33 +27,12 @@ __export(dep_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(dep_exports);
|
|
28
28
|
var import_utils = require("@umijs/utils");
|
|
29
29
|
var import_assert = __toESM(require("assert"));
|
|
30
|
-
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
31
30
|
var import_fs = require("fs");
|
|
32
31
|
var import_path = require("path");
|
|
33
32
|
var import_constants = require("../constants");
|
|
34
33
|
var import_trimFileContent = require("../utils/trimFileContent");
|
|
35
34
|
var import_getExposeFromContent = require("./getExposeFromContent");
|
|
36
|
-
var
|
|
37
|
-
mainFields: ["module", "browser", "main"],
|
|
38
|
-
extensions: [".wasm", ".mjs", ".js", ".jsx", ".ts", ".tsx", ".json"],
|
|
39
|
-
exportsFields: ["exports"],
|
|
40
|
-
conditionNames: ["import", "module", "require", "node"],
|
|
41
|
-
symlinks: false
|
|
42
|
-
});
|
|
43
|
-
async function resolve(context, path) {
|
|
44
|
-
return new Promise((resolve2, reject) => {
|
|
45
|
-
resolver(context, path, (err, result) => err ? reject(err) : resolve2(result));
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
async function resolveFromContexts(contexts, path) {
|
|
49
|
-
for (const context of contexts) {
|
|
50
|
-
try {
|
|
51
|
-
return await resolve(context, path);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
throw new Error(`Can't resolve ${path} from ${contexts.join(", ")}`);
|
|
56
|
-
}
|
|
35
|
+
var import_resolveUtils = require("../utils/resolveUtils");
|
|
57
36
|
var Dep = class {
|
|
58
37
|
constructor(opts) {
|
|
59
38
|
this.file = (0, import_utils.winPath)(opts.file);
|
|
@@ -95,7 +74,7 @@ export * from '${this.file}';
|
|
|
95
74
|
if (this.importer) {
|
|
96
75
|
contexts.push((0, import_path.dirname)(this.importer));
|
|
97
76
|
}
|
|
98
|
-
return await resolveFromContexts(contexts, this.file);
|
|
77
|
+
return await (0, import_resolveUtils.resolveFromContexts)(contexts, this.file);
|
|
99
78
|
} catch (e) {
|
|
100
79
|
return null;
|
|
101
80
|
}
|
|
@@ -60,7 +60,10 @@ var DepBuilder = class {
|
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
async buildWithESBuild(opts) {
|
|
63
|
-
const entryContent = (0, import_getESBuildEntry.getESBuildEntry)({
|
|
63
|
+
const entryContent = (0, import_getESBuildEntry.getESBuildEntry)({
|
|
64
|
+
mfName: this.opts.mfsu.opts.mfName,
|
|
65
|
+
deps: opts.deps
|
|
66
|
+
});
|
|
64
67
|
const ENTRY_FILE = "esbuild-entry.js";
|
|
65
68
|
const tmpDir = this.opts.mfsu.opts.tmpBase;
|
|
66
69
|
const entryPath = (0, import_path.join)(tmpDir, ENTRY_FILE);
|
package/dist/mfsu/mfsu.js
CHANGED
|
@@ -41,6 +41,7 @@ var import_depBuilder = require("../depBuilder/depBuilder");
|
|
|
41
41
|
var import_awaitImport = __toESM(require("../esbuildHandlers/awaitImport"));
|
|
42
42
|
var import_types = require("../types");
|
|
43
43
|
var import_makeArray = require("../utils/makeArray");
|
|
44
|
+
var import_webpackUtils = require("../utils/webpackUtils");
|
|
44
45
|
var import_buildDepPlugin = require("../webpackPlugins/buildDepPlugin");
|
|
45
46
|
var import_strategyCompileTime = require("./strategyCompileTime");
|
|
46
47
|
var import_strategyStaticAnalyze = require("./strategyStaticAnalyze");
|
|
@@ -106,17 +107,11 @@ var MFSU = class {
|
|
|
106
107
|
let index = 1;
|
|
107
108
|
let hasDefaultExport = false;
|
|
108
109
|
const entryFiles = import_utils.lodash.isArray(entryObject[key]) ? entryObject[key] : [entryObject[key]];
|
|
110
|
+
const resolver = (0, import_webpackUtils.getResolver)(opts.config);
|
|
109
111
|
for (let entry2 of entryFiles) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
(0, import_path.join)(entry2, "index.ts"),
|
|
114
|
-
(0, import_path.join)(entry2, "index.jsx"),
|
|
115
|
-
(0, import_path.join)(entry2, "index.js")
|
|
116
|
-
]);
|
|
117
|
-
(0, import_assert.default)(realEntry, `entry file not found, please configure the specific entry path. (e.g. 'src/index.tsx')`);
|
|
118
|
-
entry2 = realEntry;
|
|
119
|
-
}
|
|
112
|
+
const realEntry = resolver(entry2);
|
|
113
|
+
(0, import_assert.default)(realEntry, `entry file not found (${entry2}), please configure the specific entry path. (e.g. 'src/index.tsx')`);
|
|
114
|
+
entry2 = realEntry;
|
|
120
115
|
const content = (0, import_fs.readFileSync)(entry2, "utf-8");
|
|
121
116
|
const [_imports, exports] = await (0, import_bundler_utils.parseModule)({ content, path: entry2 });
|
|
122
117
|
if (exports.length) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveFromContexts(contexts: string[], path: string): Promise<string>;
|
|
@@ -0,0 +1,89 @@
|
|
|
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/utils/resolveUtils.ts
|
|
23
|
+
var resolveUtils_exports = {};
|
|
24
|
+
__export(resolveUtils_exports, {
|
|
25
|
+
resolveFromContexts: () => resolveFromContexts
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(resolveUtils_exports);
|
|
28
|
+
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
29
|
+
var ORDERED_MAIN_FIELDS = ["browser", "module", "main"];
|
|
30
|
+
var SUPPORTED_EXTS = [".wasm", ".mjs", ".js", ".jsx", ".ts", ".tsx", ".json"];
|
|
31
|
+
var EXPORTS_FIELDS = ["exports"];
|
|
32
|
+
var browserResolver = import_enhanced_resolve.default.create({
|
|
33
|
+
mainFields: ORDERED_MAIN_FIELDS,
|
|
34
|
+
extensions: SUPPORTED_EXTS,
|
|
35
|
+
exportsFields: EXPORTS_FIELDS,
|
|
36
|
+
conditionNames: ["browser", "import"],
|
|
37
|
+
symlinks: false
|
|
38
|
+
});
|
|
39
|
+
var esmResolver = import_enhanced_resolve.default.create({
|
|
40
|
+
mainFields: ORDERED_MAIN_FIELDS,
|
|
41
|
+
extensions: SUPPORTED_EXTS,
|
|
42
|
+
exportsFields: EXPORTS_FIELDS,
|
|
43
|
+
conditionNames: ["module"],
|
|
44
|
+
symlinks: false
|
|
45
|
+
});
|
|
46
|
+
var cjsResolver = import_enhanced_resolve.default.create({
|
|
47
|
+
mainFields: ORDERED_MAIN_FIELDS,
|
|
48
|
+
extensions: SUPPORTED_EXTS,
|
|
49
|
+
exportsFields: EXPORTS_FIELDS,
|
|
50
|
+
conditionNames: ["require", "node"],
|
|
51
|
+
symlinks: false
|
|
52
|
+
});
|
|
53
|
+
async function resolveWith(resolver, context, path) {
|
|
54
|
+
return new Promise((resolve2, reject) => {
|
|
55
|
+
resolver(context, path, (err, result) => err ? reject(err) : resolve2(result));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function tryResolvers(rs, context, path) {
|
|
59
|
+
let result = "";
|
|
60
|
+
let lastError = null;
|
|
61
|
+
for (const r of rs) {
|
|
62
|
+
try {
|
|
63
|
+
result = await resolveWith(r, context, path);
|
|
64
|
+
return result;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
lastError = e;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!result) {
|
|
70
|
+
throw lastError || Error(`can't resolve ${path} from ${context}`);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
async function resolve(context, path) {
|
|
75
|
+
return await tryResolvers([browserResolver, esmResolver, cjsResolver], context, path);
|
|
76
|
+
}
|
|
77
|
+
async function resolveFromContexts(contexts, path) {
|
|
78
|
+
for (const context of contexts) {
|
|
79
|
+
try {
|
|
80
|
+
return await resolve(context, path);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`Can't resolve ${path} from ${contexts.join(", ")}`);
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
resolveFromContexts
|
|
89
|
+
});
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
2
|
export declare function extractBabelPluginImportOptions(webpackConfig: Configuration): Map<string, any>;
|
|
3
|
+
export declare function getResolver(opts: Configuration): (path: string) => string | false;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,15 +16,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
17
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
21
|
|
|
19
22
|
// src/utils/webpackUtils.ts
|
|
20
23
|
var webpackUtils_exports = {};
|
|
21
24
|
__export(webpackUtils_exports, {
|
|
22
|
-
extractBabelPluginImportOptions: () => extractBabelPluginImportOptions
|
|
25
|
+
extractBabelPluginImportOptions: () => extractBabelPluginImportOptions,
|
|
26
|
+
getResolver: () => getResolver
|
|
23
27
|
});
|
|
24
28
|
module.exports = __toCommonJS(webpackUtils_exports);
|
|
29
|
+
var import_webpack = require("webpack");
|
|
25
30
|
var import_utils = require("@umijs/utils");
|
|
31
|
+
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
26
32
|
var { property, compact, flatMap } = import_utils.lodash;
|
|
27
33
|
function extractBabelPluginImportOptions(webpackConfig) {
|
|
28
34
|
var _a;
|
|
@@ -41,7 +47,20 @@ function extractBabelPluginImportOptions(webpackConfig) {
|
|
|
41
47
|
}
|
|
42
48
|
return configs;
|
|
43
49
|
}
|
|
50
|
+
function getResolver(opts) {
|
|
51
|
+
const context = opts.context ?? process.cwd();
|
|
52
|
+
const resolveDefaults = {
|
|
53
|
+
extensions: [".tsx", ".ts", ".jsx", ".js"],
|
|
54
|
+
roots: [context]
|
|
55
|
+
};
|
|
56
|
+
const mergedResolve = import_webpack.util.cleverMerge(resolveDefaults, opts.resolve);
|
|
57
|
+
const resolver = import_enhanced_resolve.default.create.sync(mergedResolve);
|
|
58
|
+
return (path) => {
|
|
59
|
+
return resolver(context, path);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
44
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
63
|
0 && (module.exports = {
|
|
46
|
-
extractBabelPluginImportOptions
|
|
64
|
+
extractBabelPluginImportOptions,
|
|
65
|
+
getResolver
|
|
47
66
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/mfsu",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.36",
|
|
4
4
|
"description": "@umijs/mfsu",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/mfsu#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"test": "umi-scripts jest-turbo"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@umijs/bundler-esbuild": "4.0.
|
|
27
|
-
"@umijs/bundler-utils": "4.0.
|
|
28
|
-
"@umijs/utils": "4.0.
|
|
26
|
+
"@umijs/bundler-esbuild": "4.0.36",
|
|
27
|
+
"@umijs/bundler-utils": "4.0.36",
|
|
28
|
+
"@umijs/utils": "4.0.36",
|
|
29
29
|
"enhanced-resolve": "5.9.3",
|
|
30
30
|
"is-equal": "^1.6.4"
|
|
31
31
|
},
|