dumi 2.4.32 → 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,
|
|
@@ -124,7 +124,10 @@ var compile_default = (api) => {
|
|
|
124
124
|
content: (0, import_utoopackLoaders.buildLoaderContextContent)(
|
|
125
125
|
techStacks,
|
|
126
126
|
((_a = api.service.themeData) == null ? void 0 : _a.builtins) ?? {},
|
|
127
|
-
api.appData.routes ?? {}
|
|
127
|
+
api.appData.routes ?? {},
|
|
128
|
+
api.config.extraRemarkPlugins,
|
|
129
|
+
api.config.extraRehypePlugins,
|
|
130
|
+
((_b = api.service.configManager) == null ? void 0 : _b.files) ?? []
|
|
128
131
|
)
|
|
129
132
|
});
|
|
130
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
|
|
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,34 +61,120 @@ function findInRequireCache(target) {
|
|
|
59
61
|
}
|
|
60
62
|
return null;
|
|
61
63
|
}
|
|
62
|
-
function
|
|
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
|
+
}
|
|
114
|
+
function toRequireRef(found) {
|
|
115
|
+
const modRef = `require(${JSON.stringify(found.modulePath)})`;
|
|
116
|
+
return found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
117
|
+
}
|
|
118
|
+
function toPluginTargetRef(target, sourceFiles) {
|
|
119
|
+
if (typeof target === "string")
|
|
120
|
+
return JSON.stringify(target);
|
|
121
|
+
const found = findInRequireCache(target) ?? findInSourceFiles(target, sourceFiles);
|
|
122
|
+
if (!found) {
|
|
123
|
+
const name = target.name ? ` "${target.name}"` : "";
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Utoopack markdown loader requires extra unified plugin function${name} to be exported from a module.`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return toRequireRef(found);
|
|
129
|
+
}
|
|
130
|
+
function toPluginRefs(plugins = [], sourceFiles = []) {
|
|
131
|
+
return `[${plugins.map((plugin) => {
|
|
132
|
+
if (Array.isArray(plugin)) {
|
|
133
|
+
const [target, options] = plugin;
|
|
134
|
+
const optionsRef = typeof options === "undefined" ? "undefined" : JSON.stringify(options);
|
|
135
|
+
return `[${toPluginTargetRef(
|
|
136
|
+
target,
|
|
137
|
+
sourceFiles
|
|
138
|
+
)}, ${optionsRef}]`;
|
|
139
|
+
}
|
|
140
|
+
return toPluginTargetRef(plugin, sourceFiles);
|
|
141
|
+
}).join(", ")}]`;
|
|
142
|
+
}
|
|
143
|
+
function buildLoaderContextContent(techStacks, builtins = {}, routes = {}, extraRemarkPlugins = [], extraRehypePlugins = [], sourceFiles = []) {
|
|
63
144
|
const refs = [];
|
|
64
145
|
for (const ts of techStacks) {
|
|
65
146
|
const ctor = ts.constructor;
|
|
66
147
|
if (ctor !== Object) {
|
|
67
148
|
const found = findInRequireCache(ctor);
|
|
68
149
|
if (found) {
|
|
69
|
-
|
|
70
|
-
const ctorRef = found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
71
|
-
refs.push(`new (${ctorRef})()`);
|
|
150
|
+
refs.push(`new (${toRequireRef(found)})()`);
|
|
72
151
|
}
|
|
73
152
|
} else {
|
|
74
153
|
const found = findInRequireCache(ts);
|
|
75
154
|
if (found) {
|
|
76
|
-
|
|
77
|
-
const ref = found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
78
|
-
refs.push(ref);
|
|
155
|
+
refs.push(toRequireRef(found));
|
|
79
156
|
}
|
|
80
157
|
}
|
|
81
158
|
}
|
|
82
159
|
return `'use strict';
|
|
160
|
+
try {
|
|
161
|
+
require('@umijs/utils').register.register({ implementor: require('@umijs/bundler-utils/compiled/esbuild') });
|
|
162
|
+
} catch (_) {}
|
|
83
163
|
exports.techStacks = [${refs.join(", ")}];
|
|
84
164
|
exports.builtins = ${JSON.stringify(builtins)};
|
|
85
165
|
exports.routes = ${JSON.stringify(routes)};
|
|
166
|
+
exports.extraRemarkPlugins = ${toPluginRefs(
|
|
167
|
+
extraRemarkPlugins,
|
|
168
|
+
sourceFiles
|
|
169
|
+
)};
|
|
170
|
+
exports.extraRehypePlugins = ${toPluginRefs(
|
|
171
|
+
extraRehypePlugins,
|
|
172
|
+
sourceFiles
|
|
173
|
+
)};
|
|
86
174
|
`;
|
|
87
175
|
}
|
|
88
176
|
var getUtoopackRules = (api, config = api.config) => {
|
|
89
|
-
const disableLiveDemo = (0,
|
|
177
|
+
const disableLiveDemo = (0, import_utils2.shouldDisabledLiveDemo)(api);
|
|
90
178
|
const loaderContextPath = import_path.default.join(
|
|
91
179
|
api.paths.absTmpPath,
|
|
92
180
|
LOADER_CTX_FILENAME
|
|
@@ -317,7 +317,7 @@ function getDepsCacheKey(deps = []) {
|
|
|
317
317
|
var deferrer = {};
|
|
318
318
|
var depsMapping = {};
|
|
319
319
|
function mdLoader(content) {
|
|
320
|
-
var _a;
|
|
320
|
+
var _a, _b, _c;
|
|
321
321
|
let opts = this.getOptions();
|
|
322
322
|
const loaderContextPath = opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY];
|
|
323
323
|
if (loaderContextPath) {
|
|
@@ -331,6 +331,12 @@ function mdLoader(content) {
|
|
|
331
331
|
if (ctx.routes && !Object.keys(opts.routes ?? {}).length) {
|
|
332
332
|
opts.routes = ctx.routes;
|
|
333
333
|
}
|
|
334
|
+
if (ctx.extraRemarkPlugins && !((_b = opts.extraRemarkPlugins) == null ? void 0 : _b.length)) {
|
|
335
|
+
opts.extraRemarkPlugins = ctx.extraRemarkPlugins;
|
|
336
|
+
}
|
|
337
|
+
if (ctx.extraRehypePlugins && !((_c = opts.extraRehypePlugins) == null ? void 0 : _c.length)) {
|
|
338
|
+
opts.extraRehypePlugins = ctx.extraRehypePlugins;
|
|
339
|
+
}
|
|
334
340
|
}
|
|
335
341
|
const cb = this.async();
|
|
336
342
|
if (process.env.NODE_ENV === "production" && ["onResolveDemos", "onResolveAtomMeta"].some((k) => k in opts)) {
|