dumi 2.4.23 → 2.5.0-beta.0
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/crates/swc_plugin_react_demo.wasm +0 -0
- package/dist/features/compile/index.js +35 -0
- package/dist/features/compile/utoopackLoaders.d.ts +8 -0
- package/dist/features/compile/utoopackLoaders.js +228 -0
- package/dist/features/derivative.js +1 -1
- package/dist/features/exports.js +2 -2
- package/dist/features/locales.js +3 -3
- package/dist/features/meta.js +6 -2
- package/dist/features/parser.js +12 -1
- package/dist/features/theme/index.js +35 -15
- package/dist/loaders/demo/index.js +7 -1
- package/dist/loaders/markdown/index.js +42 -13
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +9 -0
- package/package.json +7 -7
|
Binary file
|
|
@@ -40,6 +40,7 @@ var import_path = __toESM(require("path"));
|
|
|
40
40
|
var import_assets = require("../assets");
|
|
41
41
|
var import_makoHooks = require("./makoHooks");
|
|
42
42
|
var import_utils2 = require("./utils");
|
|
43
|
+
var import_utoopackLoaders = require("./utoopackLoaders");
|
|
43
44
|
var techStacks = [];
|
|
44
45
|
var compile_default = (api) => {
|
|
45
46
|
api.describe({ key: "dumi:compile" });
|
|
@@ -87,6 +88,21 @@ var compile_default = (api) => {
|
|
|
87
88
|
);
|
|
88
89
|
}
|
|
89
90
|
});
|
|
91
|
+
api.onGenerateFiles({
|
|
92
|
+
fn() {
|
|
93
|
+
var _a;
|
|
94
|
+
if (api.config.utoopack) {
|
|
95
|
+
api.writeTmpFile({
|
|
96
|
+
noPluginDir: true,
|
|
97
|
+
path: import_utoopackLoaders.LOADER_CTX_FILENAME,
|
|
98
|
+
content: (0, import_utoopackLoaders.buildLoaderContextContent)(
|
|
99
|
+
techStacks,
|
|
100
|
+
((_a = api.service.themeData) == null ? void 0 : _a.builtins) ?? {}
|
|
101
|
+
)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
90
106
|
api.addRuntimePlugin(
|
|
91
107
|
() => techStacks.reduce((acc, techStack) => {
|
|
92
108
|
var _a;
|
|
@@ -175,6 +191,25 @@ var compile_default = (api) => {
|
|
|
175
191
|
return memo;
|
|
176
192
|
}
|
|
177
193
|
});
|
|
194
|
+
api.modifyConfig({
|
|
195
|
+
before: "utoopack",
|
|
196
|
+
fn: (memo) => {
|
|
197
|
+
var _a;
|
|
198
|
+
if (memo.utoopack) {
|
|
199
|
+
memo.utoopack = {
|
|
200
|
+
...memo.utoopack,
|
|
201
|
+
module: {
|
|
202
|
+
...memo.utoopack.module || {},
|
|
203
|
+
rules: {
|
|
204
|
+
...((_a = memo.utoopack.module) == null ? void 0 : _a.rules) || {},
|
|
205
|
+
...(0, import_utoopackLoaders.getUtoopackRules)(api)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return memo;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
178
213
|
};
|
|
179
214
|
// Annotate the CommonJS export names for ESM import in node:
|
|
180
215
|
0 && (module.exports = {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IApi, IDumiTechStack } from "../../types";
|
|
2
|
+
export declare const UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
|
|
3
|
+
export declare const LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
|
|
4
|
+
export declare function buildLoaderContextContent(techStacks: IDumiTechStack[], builtins?: Record<string, {
|
|
5
|
+
specifier: string;
|
|
6
|
+
source: string;
|
|
7
|
+
}>): string;
|
|
8
|
+
export declare const getUtoopackRules: (api: IApi) => Record<string, unknown>;
|
|
@@ -0,0 +1,228 @@
|
|
|
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/features/compile/utoopackLoaders.ts
|
|
30
|
+
var utoopackLoaders_exports = {};
|
|
31
|
+
__export(utoopackLoaders_exports, {
|
|
32
|
+
LOADER_CTX_FILENAME: () => LOADER_CTX_FILENAME,
|
|
33
|
+
UTOOPACK_LOADER_CTX_KEY: () => UTOOPACK_LOADER_CTX_KEY,
|
|
34
|
+
buildLoaderContextContent: () => buildLoaderContextContent,
|
|
35
|
+
getUtoopackRules: () => getUtoopackRules
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(utoopackLoaders_exports);
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_utils = require("./utils");
|
|
40
|
+
var mdLoaderPath = require.resolve("../../loaders/markdown");
|
|
41
|
+
var UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
|
|
42
|
+
var LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
|
|
43
|
+
function toSerializable(value) {
|
|
44
|
+
return JSON.parse(JSON.stringify(value));
|
|
45
|
+
}
|
|
46
|
+
function findInRequireCache(target) {
|
|
47
|
+
for (const [filename, mod] of Object.entries(require.cache)) {
|
|
48
|
+
if (!(mod == null ? void 0 : mod.exports))
|
|
49
|
+
continue;
|
|
50
|
+
const exp = mod.exports;
|
|
51
|
+
if (exp === target)
|
|
52
|
+
return { modulePath: filename, exportName: "module.exports" };
|
|
53
|
+
if ((exp == null ? void 0 : exp.default) === target)
|
|
54
|
+
return { modulePath: filename, exportName: "default" };
|
|
55
|
+
for (const [k, v] of Object.entries(exp)) {
|
|
56
|
+
if (v === target)
|
|
57
|
+
return { modulePath: filename, exportName: k };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
function buildLoaderContextContent(techStacks, builtins = {}) {
|
|
63
|
+
const refs = [];
|
|
64
|
+
for (const ts of techStacks) {
|
|
65
|
+
const ctor = ts.constructor;
|
|
66
|
+
if (ctor !== Object) {
|
|
67
|
+
const found = findInRequireCache(ctor);
|
|
68
|
+
if (found) {
|
|
69
|
+
const modRef = `require(${JSON.stringify(found.modulePath)})`;
|
|
70
|
+
const ctorRef = found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
71
|
+
refs.push(`new (${ctorRef})()`);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
const found = findInRequireCache(ts);
|
|
75
|
+
if (found) {
|
|
76
|
+
const modRef = `require(${JSON.stringify(found.modulePath)})`;
|
|
77
|
+
const ref = found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
78
|
+
refs.push(ref);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return `'use strict';
|
|
83
|
+
exports.techStacks = [${refs.join(", ")}];
|
|
84
|
+
exports.builtins = ${JSON.stringify(builtins)};
|
|
85
|
+
`;
|
|
86
|
+
}
|
|
87
|
+
var getUtoopackRules = (api) => {
|
|
88
|
+
const disableLiveDemo = (0, import_utils.shouldDisabledLiveDemo)(api);
|
|
89
|
+
const loaderContextPath = import_path.default.join(
|
|
90
|
+
api.paths.absTmpPath,
|
|
91
|
+
LOADER_CTX_FILENAME
|
|
92
|
+
);
|
|
93
|
+
const cfgResolve = api.config.resolve ?? {};
|
|
94
|
+
const serializableBaseOpts = toSerializable({
|
|
95
|
+
cwd: api.cwd,
|
|
96
|
+
alias: api.config.alias || {},
|
|
97
|
+
resolve: {
|
|
98
|
+
atomDirs: cfgResolve.atomDirs ?? [{ type: "component", dir: "src" }],
|
|
99
|
+
docDirs: cfgResolve.docDirs ?? ["docs"],
|
|
100
|
+
codeBlockMode: cfgResolve.codeBlockMode ?? "active",
|
|
101
|
+
forceKebabCaseRouting: cfgResolve.forceKebabCaseRouting ?? true,
|
|
102
|
+
...cfgResolve.entryFile ? { entryFile: cfgResolve.entryFile } : {}
|
|
103
|
+
},
|
|
104
|
+
routes: api.appData.routes || {},
|
|
105
|
+
builtins: {},
|
|
106
|
+
locales: api.config.locales || [],
|
|
107
|
+
pkg: api.pkg,
|
|
108
|
+
disableLiveDemo,
|
|
109
|
+
[UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
// handle ?watch=parent virtual module: return empty content to establish file-watching dependency
|
|
113
|
+
"**/*": [
|
|
114
|
+
{
|
|
115
|
+
condition: { query: /^\?watch=parent$/ },
|
|
116
|
+
loaders: [require.resolve("../../loaders/null")],
|
|
117
|
+
as: "*.js"
|
|
118
|
+
},
|
|
119
|
+
// handle raw content for demo source display (?dumi-raw)
|
|
120
|
+
{
|
|
121
|
+
condition: { query: /^\?dumi-raw$/ },
|
|
122
|
+
loaders: [
|
|
123
|
+
require.resolve("../../loaders/post-raw"),
|
|
124
|
+
require.resolve("raw-loader"),
|
|
125
|
+
require.resolve("../../loaders/pre-raw")
|
|
126
|
+
],
|
|
127
|
+
as: "*.js"
|
|
128
|
+
},
|
|
129
|
+
// handle external demo component files (?techStack=xxx)
|
|
130
|
+
// techStacks are NOT serializable; pass loaderContextPath and hydrate in the loader
|
|
131
|
+
{
|
|
132
|
+
condition: { query: /^\?techStack=.*$/ },
|
|
133
|
+
loaders: [
|
|
134
|
+
{
|
|
135
|
+
loader: require.resolve("../../loaders/demo"),
|
|
136
|
+
options: toSerializable({
|
|
137
|
+
cwd: api.cwd,
|
|
138
|
+
[UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
as: "*.js"
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
// extract frontmatter/toc metadata from JS/TS page components (?type=frontmatter)
|
|
146
|
+
// NOTE:
|
|
147
|
+
// - Markdown ?type=frontmatter is already handled by the '*.md' rule below.
|
|
148
|
+
// - After the md loader outputs JS, utoopack will expose that virtual module as
|
|
149
|
+
// '*.md.js?type=frontmatter'. Without the extra path guard here, this JS rule
|
|
150
|
+
// runs again and page-loader overwrites markdown frontmatter with filename-based
|
|
151
|
+
// fallbacks like "Docs" / "C Md".
|
|
152
|
+
// - Excluding '*.md.js' keeps the markdown frontmatter result intact while still
|
|
153
|
+
// allowing real JS/TS page components to use page-loader.
|
|
154
|
+
"*.{js,jsx,ts,tsx}": {
|
|
155
|
+
condition: {
|
|
156
|
+
all: [
|
|
157
|
+
{ query: /^\?type=frontmatter$/ },
|
|
158
|
+
{ not: { path: /\.md\.js$/ } }
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
loaders: [require.resolve("../../loaders/page")],
|
|
162
|
+
as: "*.js"
|
|
163
|
+
},
|
|
164
|
+
// handle markdown files with different modes based on query type
|
|
165
|
+
"*.md": [
|
|
166
|
+
{
|
|
167
|
+
condition: { query: /^\?type=frontmatter$/ },
|
|
168
|
+
loaders: [
|
|
169
|
+
{
|
|
170
|
+
loader: mdLoaderPath,
|
|
171
|
+
options: { ...serializableBaseOpts, mode: "frontmatter" }
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
as: "*.js"
|
|
175
|
+
},
|
|
176
|
+
// extract plain text for full-text search
|
|
177
|
+
{
|
|
178
|
+
condition: { query: /^\?type=text$/ },
|
|
179
|
+
loaders: [
|
|
180
|
+
{
|
|
181
|
+
loader: mdLoaderPath,
|
|
182
|
+
options: { ...serializableBaseOpts, mode: "text" }
|
|
183
|
+
}
|
|
184
|
+
],
|
|
185
|
+
as: "*.js"
|
|
186
|
+
},
|
|
187
|
+
// extract demo index metadata from markdown
|
|
188
|
+
{
|
|
189
|
+
condition: { query: /^\?type=demo-index$/ },
|
|
190
|
+
loaders: [
|
|
191
|
+
{
|
|
192
|
+
loader: mdLoaderPath,
|
|
193
|
+
options: { ...serializableBaseOpts, mode: "demo-index" }
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
as: "*.js"
|
|
197
|
+
},
|
|
198
|
+
// compile inline demo code blocks
|
|
199
|
+
{
|
|
200
|
+
condition: { query: /^\?type=demo$/ },
|
|
201
|
+
loaders: [
|
|
202
|
+
{
|
|
203
|
+
loader: mdLoaderPath,
|
|
204
|
+
options: { ...serializableBaseOpts, mode: "demo" }
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
as: "*.js"
|
|
208
|
+
},
|
|
209
|
+
// default: transform markdown into a React page component
|
|
210
|
+
{
|
|
211
|
+
loaders: [
|
|
212
|
+
{
|
|
213
|
+
loader: mdLoaderPath,
|
|
214
|
+
options: serializableBaseOpts
|
|
215
|
+
}
|
|
216
|
+
],
|
|
217
|
+
as: "*.js"
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
223
|
+
0 && (module.exports = {
|
|
224
|
+
LOADER_CTX_FILENAME,
|
|
225
|
+
UTOOPACK_LOADER_CTX_KEY,
|
|
226
|
+
buildLoaderContextContent,
|
|
227
|
+
getUtoopackRules
|
|
228
|
+
});
|
|
@@ -92,7 +92,7 @@ var derivative_default = (api) => {
|
|
|
92
92
|
}
|
|
93
93
|
(0, import_assert.default)(
|
|
94
94
|
!api.config.ssr || api.config.ssr.builder === "webpack" || api.config.ssr.builder === "mako",
|
|
95
|
-
"Only `webpack` and mako` builder is supported in SSR mode!"
|
|
95
|
+
"Only `webpack` and `mako` builder is supported in SSR mode!"
|
|
96
96
|
);
|
|
97
97
|
(0, import_assert.default)(
|
|
98
98
|
((_a = api.config.cssLoader) == null ? void 0 : _a.modules) === void 0 && api.config.cssLoaderModules === void 0,
|
package/dist/features/exports.js
CHANGED
|
@@ -32,7 +32,7 @@ __export(exports_exports, {
|
|
|
32
32
|
default: () => exports_default
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(exports_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_utils = require("../utils");
|
|
36
36
|
var exports_default = (api) => {
|
|
37
37
|
api.describe({ key: "dumi:exports" });
|
|
38
38
|
api.modifyConfig((memo) => {
|
|
@@ -44,7 +44,7 @@ var exports_default = (api) => {
|
|
|
44
44
|
noPluginDir: true,
|
|
45
45
|
path: "dumi/exports.ts",
|
|
46
46
|
content: `export * from '../exports';
|
|
47
|
-
export * from '${(0,
|
|
47
|
+
export * from '${(0, import_utils.toImportSpecifier)(require.resolve("../client/theme-api"))}';
|
|
48
48
|
export * from './meta/exports';`
|
|
49
49
|
});
|
|
50
50
|
});
|
package/dist/features/locales.js
CHANGED
|
@@ -33,8 +33,8 @@ __export(locales_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(locales_exports);
|
|
35
35
|
var import_constants = require("../constants");
|
|
36
|
+
var import_utils = require("../utils");
|
|
36
37
|
var import_path = __toESM(require("path"));
|
|
37
|
-
var import_plugin_utils = require("umi/plugin-utils");
|
|
38
38
|
var locales_default = (api) => {
|
|
39
39
|
var _a;
|
|
40
40
|
api.describe({
|
|
@@ -114,10 +114,10 @@ export const messages = ${JSON.stringify(
|
|
|
114
114
|
content: `
|
|
115
115
|
import { history } from 'dumi';
|
|
116
116
|
import React, { useState, useLayoutEffect, useCallback, type ReactNode } from 'react';
|
|
117
|
-
import { RawIntlProvider, createIntl, createIntlCache } from '${(0,
|
|
117
|
+
import { RawIntlProvider, createIntl, createIntlCache } from '${(0, import_utils.toImportSpecifier)(
|
|
118
118
|
import_path.default.dirname(require.resolve("react-intl/package"))
|
|
119
119
|
)}';
|
|
120
|
-
import { useIsomorphicLayoutEffect } from '${(0,
|
|
120
|
+
import { useIsomorphicLayoutEffect } from '${(0, import_utils.toImportSpecifier)(
|
|
121
121
|
require.resolve("../client/theme-api/utils")
|
|
122
122
|
)}'
|
|
123
123
|
import { locales, messages } from './config';
|
package/dist/features/meta.js
CHANGED
|
@@ -98,8 +98,12 @@ var meta_default = (api) => {
|
|
|
98
98
|
path: "dumi/meta/runtime.ts",
|
|
99
99
|
tplPath: require.resolve("../templates/meta/runtime.ts.tpl"),
|
|
100
100
|
context: {
|
|
101
|
-
deepmerge: (0,
|
|
102
|
-
|
|
101
|
+
deepmerge: (0, import_utils.toImportSpecifier)(
|
|
102
|
+
import_path.default.dirname(require.resolve("deepmerge/package"))
|
|
103
|
+
),
|
|
104
|
+
rc_util: (0, import_utils.toImportSpecifier)(
|
|
105
|
+
import_path.default.dirname(require.resolve("rc-util/package"))
|
|
106
|
+
)
|
|
103
107
|
}
|
|
104
108
|
});
|
|
105
109
|
api.writeTmpFile({
|
package/dist/features/parser.js
CHANGED
|
@@ -55,6 +55,10 @@ function filterIgnoredProps(props) {
|
|
|
55
55
|
}
|
|
56
56
|
var parser_default = (api) => {
|
|
57
57
|
let prevData;
|
|
58
|
+
const fallbackData = {
|
|
59
|
+
components: {},
|
|
60
|
+
functions: {}
|
|
61
|
+
};
|
|
58
62
|
const writeAtomsMetaFile = (data) => {
|
|
59
63
|
const components = import_utils.lodash.mapValues(data.components, (component) => ({
|
|
60
64
|
...component,
|
|
@@ -114,7 +118,14 @@ var parser_default = (api) => {
|
|
|
114
118
|
});
|
|
115
119
|
api.onGenerateFiles(async () => {
|
|
116
120
|
if (api.env === "production") {
|
|
117
|
-
|
|
121
|
+
try {
|
|
122
|
+
writeAtomsMetaFile(await api.service.atomParser.parse());
|
|
123
|
+
} catch (err) {
|
|
124
|
+
api.logger.warn(
|
|
125
|
+
`apiParser parse failed, fallback to empty metadata: ${err instanceof Error ? err.message : String(err)}`
|
|
126
|
+
);
|
|
127
|
+
writeAtomsMetaFile(fallbackData);
|
|
128
|
+
}
|
|
118
129
|
} else if (prevData) {
|
|
119
130
|
writeAtomsMetaFile(prevData);
|
|
120
131
|
}
|
|
@@ -42,7 +42,9 @@ var import_path = __toESM(require("path"));
|
|
|
42
42
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
43
43
|
var import_derivative = require("../derivative");
|
|
44
44
|
var import_loader = __toESM(require("./loader"));
|
|
45
|
-
var DEFAULT_THEME_PATH =
|
|
45
|
+
var DEFAULT_THEME_PATH = (0, import_plugin_utils.winPath)(
|
|
46
|
+
import_path.default.join(__dirname, "../../../theme-default")
|
|
47
|
+
);
|
|
46
48
|
var DEFAULT_LOADING_PATH = (0, import_plugin_utils.winPath)(
|
|
47
49
|
import_path.default.resolve(__dirname, "../../client/pages/Loading")
|
|
48
50
|
);
|
|
@@ -163,19 +165,27 @@ var theme_default = (api) => {
|
|
|
163
165
|
});
|
|
164
166
|
api.modifyConfig((memo) => {
|
|
165
167
|
var _a, _b, _c, _d;
|
|
168
|
+
themeMapKeys.forEach((key) => {
|
|
169
|
+
Object.values(pkgThemeData[key] || {}).forEach((item) => {
|
|
170
|
+
memo.alias[`dumi/theme/${key}/${item.specifier}`] = (0, import_plugin_utils.winPath)(
|
|
171
|
+
item.source
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
166
175
|
if (localThemeData) {
|
|
167
176
|
themeMapKeys.forEach((key) => {
|
|
168
177
|
Object.values(localThemeData[key] || {}).forEach((item) => {
|
|
169
|
-
memo.alias[`dumi/theme/${key}/${item.specifier}`] =
|
|
178
|
+
memo.alias[`dumi/theme/${key}/${item.specifier}`] = (0, import_plugin_utils.winPath)(
|
|
179
|
+
item.source
|
|
180
|
+
);
|
|
170
181
|
});
|
|
171
182
|
});
|
|
172
183
|
}
|
|
173
184
|
memo.alias["dumi/theme"] = "dumi/theme-original";
|
|
174
|
-
memo.alias["dumi/theme-original"] =
|
|
175
|
-
api.paths.absTmpPath,
|
|
176
|
-
"dumi/theme"
|
|
185
|
+
memo.alias["dumi/theme-original"] = (0, import_plugin_utils.winPath)(
|
|
186
|
+
import_path.default.join(api.paths.absTmpPath, "dumi/theme")
|
|
177
187
|
);
|
|
178
|
-
memo.alias["dumi/theme-default"] = DEFAULT_THEME_PATH;
|
|
188
|
+
memo.alias["dumi/theme-default"] = (0, import_plugin_utils.winPath)(DEFAULT_THEME_PATH);
|
|
179
189
|
memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
|
|
180
190
|
memo.extraBabelIncludes.push(
|
|
181
191
|
import_path.default.resolve(__dirname, "../../client/theme-api")
|
|
@@ -233,11 +243,11 @@ var theme_default = (api) => {
|
|
|
233
243
|
api.writeTmpFile({
|
|
234
244
|
noPluginDir: true,
|
|
235
245
|
path: "dumi/theme/loading.tsx",
|
|
236
|
-
content: `${enableNProgress ? `import nprogress from '${(0,
|
|
246
|
+
content: `${enableNProgress ? `import nprogress from '${(0, import_utils.toImportSpecifier)(
|
|
237
247
|
import_path.default.dirname(require.resolve("nprogress/package"))
|
|
238
248
|
)}';
|
|
239
249
|
import './nprogress.css';` : ""}
|
|
240
|
-
import UserLoading from '${globalLoading}';
|
|
250
|
+
import UserLoading from '${(0, import_utils.toImportSpecifier)(globalLoading)}';
|
|
241
251
|
import React, { useLayoutEffect, type FC } from 'react';
|
|
242
252
|
import { useSiteData } from 'dumi';
|
|
243
253
|
|
|
@@ -271,10 +281,12 @@ export default DumiLoading;
|
|
|
271
281
|
const exports = await getModuleExports(item.source);
|
|
272
282
|
const contents = [];
|
|
273
283
|
if (exports.includes("default")) {
|
|
274
|
-
contents.push(
|
|
284
|
+
contents.push(
|
|
285
|
+
`export { default } from '${(0, import_utils.toImportSpecifier)(item.source)}';`
|
|
286
|
+
);
|
|
275
287
|
}
|
|
276
288
|
if (exports.some((exp) => exp !== "default")) {
|
|
277
|
-
contents.push(`export * from '${item.source}';`);
|
|
289
|
+
contents.push(`export * from '${(0, import_utils.toImportSpecifier)(item.source)}';`);
|
|
278
290
|
}
|
|
279
291
|
api.writeTmpFile({
|
|
280
292
|
noPluginDir: true,
|
|
@@ -293,9 +305,13 @@ export default DumiLoading;
|
|
|
293
305
|
path: "dumi/theme/ContextWrapper.tsx",
|
|
294
306
|
tplPath: require.resolve("../../templates/ContextWrapper.ts.tpl"),
|
|
295
307
|
context: {
|
|
296
|
-
contextPath: (0,
|
|
297
|
-
|
|
298
|
-
|
|
308
|
+
contextPath: (0, import_utils.toImportSpecifier)(
|
|
309
|
+
require.resolve("../../client/theme-api/context")
|
|
310
|
+
),
|
|
311
|
+
defaultExport: hasDefaultExport ? `import entryDefaultExport from '${(0, import_utils.toImportSpecifier)(entryFile)}';` : "",
|
|
312
|
+
namedExport: hasNamedExport ? `import * as entryMemberExports from '${(0, import_utils.toImportSpecifier)(
|
|
313
|
+
entryFile
|
|
314
|
+
)}';` : "",
|
|
299
315
|
hasDefaultExport,
|
|
300
316
|
hasNamedExport,
|
|
301
317
|
pkg: JSON.stringify(
|
|
@@ -309,7 +325,9 @@ export default DumiLoading;
|
|
|
309
325
|
api.config.themeConfig
|
|
310
326
|
)
|
|
311
327
|
),
|
|
312
|
-
rc_util: (0,
|
|
328
|
+
rc_util: (0, import_utils.toImportSpecifier)(
|
|
329
|
+
import_path.default.dirname(require.resolve("rc-util/package"))
|
|
330
|
+
),
|
|
313
331
|
_2_level_nav_available: api.appData._2LevelNavAvailable
|
|
314
332
|
}
|
|
315
333
|
});
|
|
@@ -405,7 +423,9 @@ export default DumiLoading;
|
|
|
405
423
|
},
|
|
406
424
|
{
|
|
407
425
|
specifier: "{ setPluginManager as setDumiPluginManager }",
|
|
408
|
-
source: (0,
|
|
426
|
+
source: (0, import_utils.toImportSpecifier)(
|
|
427
|
+
require.resolve("../../client/theme-api/utils")
|
|
428
|
+
)
|
|
409
429
|
}
|
|
410
430
|
]);
|
|
411
431
|
api.addEntryCode(() => "setDumiPluginManager(getDumiPluginManager());");
|
|
@@ -22,13 +22,19 @@ __export(demo_exports, {
|
|
|
22
22
|
default: () => demoLoader
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(demo_exports);
|
|
25
|
+
var import_utoopackLoaders = require("../../features/compile/utoopackLoaders");
|
|
25
26
|
var import_utils = require("@umijs/utils");
|
|
26
27
|
function demoLoader(raw) {
|
|
27
28
|
const opts = this.getOptions();
|
|
29
|
+
let techStacks = opts.techStacks;
|
|
30
|
+
if (!techStacks && opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY]) {
|
|
31
|
+
const ctx = require(opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY]);
|
|
32
|
+
techStacks = ctx.techStacks;
|
|
33
|
+
}
|
|
28
34
|
const techStackName = new URLSearchParams(this.resourceQuery).get(
|
|
29
35
|
"techStack"
|
|
30
36
|
);
|
|
31
|
-
const techStack =
|
|
37
|
+
const techStack = techStacks.find((t) => t.name === techStackName);
|
|
32
38
|
let code = techStack.transformCode(raw, {
|
|
33
39
|
type: "external",
|
|
34
40
|
fileAbsPath: this.resourcePath
|
|
@@ -32,6 +32,7 @@ __export(markdown_exports, {
|
|
|
32
32
|
default: () => mdLoader
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(markdown_exports);
|
|
35
|
+
var import_utoopackLoaders = require("../../features/compile/utoopackLoaders");
|
|
35
36
|
var import_tabs = require("../../features/tabs");
|
|
36
37
|
var import_utils = require("../../utils");
|
|
37
38
|
var import_fs = __toESM(require("fs"));
|
|
@@ -62,11 +63,11 @@ function emitDefault(opts, ret) {
|
|
|
62
63
|
if (frontmatter.atomId && opts.onResolveAtomMeta) {
|
|
63
64
|
opts.onResolveAtomMeta(frontmatter.atomId, frontmatter);
|
|
64
65
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const embeddedMdFiles = (ret.meta.embeds ?? []).filter(
|
|
67
|
+
(filePath) => filePath.endsWith(".md") && !filePath.includes("node_modules")
|
|
68
|
+
);
|
|
68
69
|
return `${Object.values(opts.builtins).map((item) => `import ${item.specifier} from '${(0, import_plugin_utils.winPath)(item.source)}';`).join("\n")}
|
|
69
|
-
${
|
|
70
|
+
${embeddedMdFiles.map(
|
|
70
71
|
(md) => `
|
|
71
72
|
import '${(0, import_plugin_utils.winPath)(md)}?watch=parent';
|
|
72
73
|
`
|
|
@@ -134,7 +135,7 @@ function emitDemo(opts, ret) {
|
|
|
134
135
|
}, []);
|
|
135
136
|
return import_plugin_utils.Mustache.render(
|
|
136
137
|
`import React from 'react';
|
|
137
|
-
import '${(0, import_plugin_utils.winPath)(this.
|
|
138
|
+
import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
|
|
138
139
|
{{#dedupedDemosDeps}}
|
|
139
140
|
import * as {{{specifier}}} from '{{{key}}}';
|
|
140
141
|
{{/dedupedDemosDeps}}
|
|
@@ -162,7 +163,7 @@ export const demos = {
|
|
|
162
163
|
var _a;
|
|
163
164
|
if (((_a = asset.dependencies[file]) == null ? void 0 : _a.type) === "FILE") {
|
|
164
165
|
let assetValue = `{{{require('-!${resolveMap[file]}?dumi-raw').default}}}`;
|
|
165
|
-
if (process.env.OKAM) {
|
|
166
|
+
if (process.env.OKAM || opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY]) {
|
|
166
167
|
assetValue = `{{{require('${resolveMap[file]}?dumi-raw').default}}}`;
|
|
167
168
|
}
|
|
168
169
|
asset = import_plugin_utils.lodash.cloneDeep(asset);
|
|
@@ -222,7 +223,7 @@ function emitDemoIndex(opts, ret) {
|
|
|
222
223
|
const { demos } = ret.meta;
|
|
223
224
|
return import_plugin_utils.Mustache.render(
|
|
224
225
|
`
|
|
225
|
-
import '${(0, import_plugin_utils.winPath)(this.
|
|
226
|
+
import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
|
|
226
227
|
export const demoIndex = {
|
|
227
228
|
ids: {{{ids}}},
|
|
228
229
|
getter: {{{getter}}}
|
|
@@ -239,11 +240,28 @@ function emitDemoIndex(opts, ret) {
|
|
|
239
240
|
}
|
|
240
241
|
function emitFrontmatter(opts, ret) {
|
|
241
242
|
const { frontmatter, toc } = ret.meta;
|
|
243
|
+
const resourcePath = (0, import_plugin_utils.winPath)(this.resourcePath);
|
|
244
|
+
const isUtoopack = import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts;
|
|
245
|
+
if (isUtoopack) {
|
|
246
|
+
const rendered = import_plugin_utils.Mustache.render(
|
|
247
|
+
`import '${resourcePath}?watch=parent';
|
|
248
|
+
globalThis.__DUMI_FM__ = globalThis.__DUMI_FM__ || {};
|
|
249
|
+
globalThis.__DUMI_TOC__ = globalThis.__DUMI_TOC__ || {};
|
|
250
|
+
globalThis.__DUMI_FM__['${resourcePath}'] = {{{frontmatter}}};
|
|
251
|
+
globalThis.__DUMI_TOC__['${resourcePath}'] = {{{toc}}};
|
|
252
|
+
export const frontmatter = globalThis.__DUMI_FM__['${resourcePath}'];
|
|
253
|
+
export const toc = globalThis.__DUMI_TOC__['${resourcePath}'];`,
|
|
254
|
+
{
|
|
255
|
+
toc: JSON.stringify(toc),
|
|
256
|
+
frontmatter: JSON.stringify(frontmatter)
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
return rendered;
|
|
260
|
+
}
|
|
242
261
|
return import_plugin_utils.Mustache.render(
|
|
243
|
-
`
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
export const frontmatter = {{{frontmatter}}};`,
|
|
262
|
+
`import '${resourcePath}?watch=parent';
|
|
263
|
+
export const toc = new Proxy({{{toc}}}, {});
|
|
264
|
+
export const frontmatter = new Proxy({{{frontmatter}}}, {});`,
|
|
247
265
|
{
|
|
248
266
|
toc: JSON.stringify(toc),
|
|
249
267
|
frontmatter: JSON.stringify(frontmatter)
|
|
@@ -254,7 +272,7 @@ function emitText(opts, ret) {
|
|
|
254
272
|
const { texts } = ret.meta;
|
|
255
273
|
return import_plugin_utils.Mustache.render(
|
|
256
274
|
`
|
|
257
|
-
import '${(0, import_plugin_utils.winPath)(this.
|
|
275
|
+
import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
|
|
258
276
|
export const texts = {{{texts}}};
|
|
259
277
|
`,
|
|
260
278
|
{
|
|
@@ -291,7 +309,18 @@ function getDepsCacheKey(deps = []) {
|
|
|
291
309
|
var deferrer = {};
|
|
292
310
|
var depsMapping = {};
|
|
293
311
|
function mdLoader(content) {
|
|
294
|
-
|
|
312
|
+
var _a;
|
|
313
|
+
let opts = this.getOptions();
|
|
314
|
+
const loaderContextPath = opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY];
|
|
315
|
+
if (loaderContextPath) {
|
|
316
|
+
const ctx = require(loaderContextPath);
|
|
317
|
+
if (!((_a = opts.techStacks) == null ? void 0 : _a.length)) {
|
|
318
|
+
opts.techStacks = ctx.techStacks;
|
|
319
|
+
}
|
|
320
|
+
if (ctx.builtins && !Object.keys(opts.builtins ?? {}).length) {
|
|
321
|
+
opts.builtins = ctx.builtins;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
295
324
|
const cb = this.async();
|
|
296
325
|
if (process.env.NODE_ENV === "production" && ["onResolveDemos", "onResolveAtomMeta"].some((k) => k in opts)) {
|
|
297
326
|
this.cacheable(false);
|
package/dist/utils.d.ts
CHANGED
|
@@ -60,3 +60,8 @@ export declare function runLoaders(options: RunLoaderOption, callback: (err: Nod
|
|
|
60
60
|
* check if version is in range
|
|
61
61
|
*/
|
|
62
62
|
export declare function isVersionInRange(version: string, range: string | Range, options?: RangeOptions): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* normalize module specifier for generated import/export statements
|
|
65
|
+
* keep package/bare specifiers unchanged and normalize path separators
|
|
66
|
+
*/
|
|
67
|
+
export declare function toImportSpecifier(source: string): string;
|
package/dist/utils.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(utils_exports, {
|
|
|
42
42
|
isVersionInRange: () => isVersionInRange,
|
|
43
43
|
parseCodeFrontmatter: () => parseCodeFrontmatter,
|
|
44
44
|
runLoaders: () => runLoaders,
|
|
45
|
+
toImportSpecifier: () => toImportSpecifier,
|
|
45
46
|
tryFatherBuildConfigs: () => tryFatherBuildConfigs
|
|
46
47
|
});
|
|
47
48
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -181,6 +182,13 @@ function isVersionInRange(version, range, options = { includePrerelease: true })
|
|
|
181
182
|
}
|
|
182
183
|
return false;
|
|
183
184
|
}
|
|
185
|
+
function toImportSpecifier(source) {
|
|
186
|
+
if (!source)
|
|
187
|
+
return source;
|
|
188
|
+
if (/^(?:node|data|file):/.test(source))
|
|
189
|
+
return source;
|
|
190
|
+
return (0, import_plugin_utils.winPath)(source);
|
|
191
|
+
}
|
|
184
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
185
193
|
0 && (module.exports = {
|
|
186
194
|
_setFSCacheDir,
|
|
@@ -196,5 +204,6 @@ function isVersionInRange(version, range, options = { includePrerelease: true })
|
|
|
196
204
|
isVersionInRange,
|
|
197
205
|
parseCodeFrontmatter,
|
|
198
206
|
runLoaders,
|
|
207
|
+
toImportSpecifier,
|
|
199
208
|
tryFatherBuildConfigs
|
|
200
209
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-beta.0",
|
|
4
4
|
"description": "📖 Documentation Generator of React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"@swc/core": "1.9.2",
|
|
66
66
|
"@types/hast": "^2.3.5",
|
|
67
67
|
"@types/mdast": "^3.0.12",
|
|
68
|
-
"@umijs/bundler-utils": "^4.
|
|
69
|
-
"@umijs/core": "^4.
|
|
70
|
-
"@umijs/utils": "^4.
|
|
68
|
+
"@umijs/bundler-utils": "^4.6.48",
|
|
69
|
+
"@umijs/core": "^4.6.48",
|
|
70
|
+
"@umijs/utils": "^4.6.48",
|
|
71
71
|
"animated-scroll-to": "^2.3.0",
|
|
72
72
|
"classnames": "2.3.2",
|
|
73
73
|
"codesandbox-import-utils": "^2.2.3",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"sass": "^1.64.1",
|
|
120
120
|
"sitemap": "^7.1.1",
|
|
121
121
|
"sucrase": "^3.34.0",
|
|
122
|
-
"umi": "^4.
|
|
122
|
+
"umi": "^4.6.48",
|
|
123
123
|
"unified": "^10.1.2",
|
|
124
124
|
"unist-util-visit": "^4.1.2",
|
|
125
125
|
"unist-util-visit-parents": "^5.1.3",
|
|
@@ -142,7 +142,7 @@
|
|
|
142
142
|
"@types/react": "^18.2.17",
|
|
143
143
|
"@types/react-copy-to-clipboard": "^5.0.4",
|
|
144
144
|
"@types/react-dom": "^18.2.7",
|
|
145
|
-
"@umijs/lint": "^4.
|
|
145
|
+
"@umijs/lint": "^4.6.48",
|
|
146
146
|
"@umijs/plugins": "4.0.32",
|
|
147
147
|
"eslint": "^8.46.0",
|
|
148
148
|
"esno": "^4.7.0",
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
],
|
|
178
178
|
"scripts": {
|
|
179
179
|
"build": "father build && npm run build:crates",
|
|
180
|
-
"build:crates": "cargo build --target wasm32-wasip1 -r --
|
|
180
|
+
"build:crates": "cargo build --target wasm32-wasip1 -r --artifact-dir compiled/crates -Z unstable-options",
|
|
181
181
|
"build:deps": "node scripts/pre-bundle-worker.js && father prebundle",
|
|
182
182
|
"build:suites": "pnpm run --filter=\"./suites/**\" build",
|
|
183
183
|
"dev": "father dev",
|