dumi 2.4.33 → 2.4.34
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.
|
@@ -116,7 +116,7 @@ var compile_default = (api) => {
|
|
|
116
116
|
});
|
|
117
117
|
api.onGenerateFiles({
|
|
118
118
|
fn() {
|
|
119
|
-
var _a;
|
|
119
|
+
var _a, _b;
|
|
120
120
|
if (api.config.utoopack) {
|
|
121
121
|
api.writeTmpFile({
|
|
122
122
|
noPluginDir: true,
|
|
@@ -126,7 +126,8 @@ var compile_default = (api) => {
|
|
|
126
126
|
((_a = api.service.themeData) == null ? void 0 : _a.builtins) ?? {},
|
|
127
127
|
api.appData.routes ?? {},
|
|
128
128
|
api.config.extraRemarkPlugins,
|
|
129
|
-
api.config.extraRehypePlugins
|
|
129
|
+
api.config.extraRehypePlugins,
|
|
130
|
+
((_b = api.service.configManager) == null ? void 0 : _b.files) ?? []
|
|
130
131
|
)
|
|
131
132
|
});
|
|
132
133
|
}
|
|
@@ -4,5 +4,5 @@ export declare const LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
|
|
|
4
4
|
export declare function buildLoaderContextContent(techStacks: IDumiTechStack[], builtins?: Record<string, {
|
|
5
5
|
specifier: string;
|
|
6
6
|
source: string;
|
|
7
|
-
}>, routes?: Record<string, unknown>, extraRemarkPlugins?: IApi['config']['extraRemarkPlugins'], extraRehypePlugins?: IApi['config']['extraRehypePlugins']): string;
|
|
7
|
+
}>, routes?: Record<string, unknown>, extraRemarkPlugins?: IApi['config']['extraRemarkPlugins'], extraRehypePlugins?: IApi['config']['extraRehypePlugins'], sourceFiles?: string[]): string;
|
|
8
8
|
export declare const getUtoopackRules: (api: IApi, config?: IApi['config']) => Record<string, unknown>;
|
|
@@ -35,8 +35,10 @@ __export(utoopackLoaders_exports, {
|
|
|
35
35
|
getUtoopackRules: () => getUtoopackRules
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(utoopackLoaders_exports);
|
|
38
|
+
var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
39
|
+
var import_utils = require("@umijs/utils");
|
|
38
40
|
var import_path = __toESM(require("path"));
|
|
39
|
-
var
|
|
41
|
+
var import_utils2 = require("./utils");
|
|
40
42
|
var mdLoaderPath = require.resolve("../../loaders/markdown");
|
|
41
43
|
var UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
|
|
42
44
|
var LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
|
|
@@ -59,14 +61,64 @@ function findInRequireCache(target) {
|
|
|
59
61
|
}
|
|
60
62
|
return null;
|
|
61
63
|
}
|
|
64
|
+
function normalizeFnSource(fn) {
|
|
65
|
+
return Function.prototype.toString.call(fn).replace(/\s+/g, " ");
|
|
66
|
+
}
|
|
67
|
+
function isSameFunction(candidate, target) {
|
|
68
|
+
return typeof candidate === "function" && candidate.name === target.name && normalizeFnSource(candidate) === normalizeFnSource(target);
|
|
69
|
+
}
|
|
70
|
+
function findInModuleExports(target, mod) {
|
|
71
|
+
const exp = mod.exports;
|
|
72
|
+
if (!exp)
|
|
73
|
+
return null;
|
|
74
|
+
if (isSameFunction(exp, target)) {
|
|
75
|
+
return { modulePath: mod.filename, exportName: "module.exports" };
|
|
76
|
+
}
|
|
77
|
+
if (isSameFunction(exp == null ? void 0 : exp.default, target)) {
|
|
78
|
+
return { modulePath: mod.filename, exportName: "default" };
|
|
79
|
+
}
|
|
80
|
+
for (const [k, v] of Object.entries(exp)) {
|
|
81
|
+
if (isSameFunction(v, target)) {
|
|
82
|
+
return { modulePath: mod.filename, exportName: k };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
function findInSourceFiles(target, sourceFiles) {
|
|
88
|
+
import_utils.register.register({ implementor: import_esbuild.default });
|
|
89
|
+
import_utils.register.clearFiles();
|
|
90
|
+
try {
|
|
91
|
+
for (const file of sourceFiles) {
|
|
92
|
+
try {
|
|
93
|
+
require(file);
|
|
94
|
+
const mod = require.cache[file];
|
|
95
|
+
if (!(mod == null ? void 0 : mod.exports))
|
|
96
|
+
continue;
|
|
97
|
+
const found = findInModuleExports(target, mod);
|
|
98
|
+
if (found)
|
|
99
|
+
return found;
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
} finally {
|
|
105
|
+
for (const file of import_utils.register.getFiles()) {
|
|
106
|
+
delete require.cache[file];
|
|
107
|
+
}
|
|
108
|
+
for (const file of sourceFiles) {
|
|
109
|
+
delete require.cache[file];
|
|
110
|
+
}
|
|
111
|
+
import_utils.register.restore();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
62
114
|
function toRequireRef(found) {
|
|
63
115
|
const modRef = `require(${JSON.stringify(found.modulePath)})`;
|
|
64
116
|
return found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
65
117
|
}
|
|
66
|
-
function toPluginTargetRef(target) {
|
|
118
|
+
function toPluginTargetRef(target, sourceFiles) {
|
|
67
119
|
if (typeof target === "string")
|
|
68
120
|
return JSON.stringify(target);
|
|
69
|
-
const found = findInRequireCache(target);
|
|
121
|
+
const found = findInRequireCache(target) ?? findInSourceFiles(target, sourceFiles);
|
|
70
122
|
if (!found) {
|
|
71
123
|
const name = target.name ? ` "${target.name}"` : "";
|
|
72
124
|
throw new Error(
|
|
@@ -75,19 +127,20 @@ function toPluginTargetRef(target) {
|
|
|
75
127
|
}
|
|
76
128
|
return toRequireRef(found);
|
|
77
129
|
}
|
|
78
|
-
function toPluginRefs(plugins = []) {
|
|
130
|
+
function toPluginRefs(plugins = [], sourceFiles = []) {
|
|
79
131
|
return `[${plugins.map((plugin) => {
|
|
80
132
|
if (Array.isArray(plugin)) {
|
|
81
133
|
const [target, options] = plugin;
|
|
82
134
|
const optionsRef = typeof options === "undefined" ? "undefined" : JSON.stringify(options);
|
|
83
135
|
return `[${toPluginTargetRef(
|
|
84
|
-
target
|
|
136
|
+
target,
|
|
137
|
+
sourceFiles
|
|
85
138
|
)}, ${optionsRef}]`;
|
|
86
139
|
}
|
|
87
|
-
return toPluginTargetRef(plugin);
|
|
140
|
+
return toPluginTargetRef(plugin, sourceFiles);
|
|
88
141
|
}).join(", ")}]`;
|
|
89
142
|
}
|
|
90
|
-
function buildLoaderContextContent(techStacks, builtins = {}, routes = {}, extraRemarkPlugins = [], extraRehypePlugins = []) {
|
|
143
|
+
function buildLoaderContextContent(techStacks, builtins = {}, routes = {}, extraRemarkPlugins = [], extraRehypePlugins = [], sourceFiles = []) {
|
|
91
144
|
const refs = [];
|
|
92
145
|
for (const ts of techStacks) {
|
|
93
146
|
const ctor = ts.constructor;
|
|
@@ -104,15 +157,24 @@ function buildLoaderContextContent(techStacks, builtins = {}, routes = {}, extra
|
|
|
104
157
|
}
|
|
105
158
|
}
|
|
106
159
|
return `'use strict';
|
|
160
|
+
try {
|
|
161
|
+
require('@umijs/utils').register.register({ implementor: require('@umijs/bundler-utils/compiled/esbuild') });
|
|
162
|
+
} catch (_) {}
|
|
107
163
|
exports.techStacks = [${refs.join(", ")}];
|
|
108
164
|
exports.builtins = ${JSON.stringify(builtins)};
|
|
109
165
|
exports.routes = ${JSON.stringify(routes)};
|
|
110
|
-
exports.extraRemarkPlugins = ${toPluginRefs(
|
|
111
|
-
|
|
166
|
+
exports.extraRemarkPlugins = ${toPluginRefs(
|
|
167
|
+
extraRemarkPlugins,
|
|
168
|
+
sourceFiles
|
|
169
|
+
)};
|
|
170
|
+
exports.extraRehypePlugins = ${toPluginRefs(
|
|
171
|
+
extraRehypePlugins,
|
|
172
|
+
sourceFiles
|
|
173
|
+
)};
|
|
112
174
|
`;
|
|
113
175
|
}
|
|
114
176
|
var getUtoopackRules = (api, config = api.config) => {
|
|
115
|
-
const disableLiveDemo = (0,
|
|
177
|
+
const disableLiveDemo = (0, import_utils2.shouldDisabledLiveDemo)(api);
|
|
116
178
|
const loaderContextPath = import_path.default.join(
|
|
117
179
|
api.paths.absTmpPath,
|
|
118
180
|
LOADER_CTX_FILENAME
|