dumi 2.4.51 → 2.4.53

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.
Files changed (34) hide show
  1. package/compiled/file-system-cache/LICENSE +134 -0
  2. package/compiled/file-system-cache/index.d.ts +3 -0
  3. package/compiled/file-system-cache/index.js +1 -0
  4. package/compiled/file-system-cache/package.json +1 -0
  5. package/dist/assetParsers/block.d.ts +3 -0
  6. package/dist/assetParsers/block.js +82 -15
  7. package/dist/features/compile/index.js +6 -1
  8. package/dist/features/compile/utoopackLoaders.d.ts +3 -2
  9. package/dist/features/compile/utoopackLoaders.js +8 -6
  10. package/dist/features/meta.js +4 -4
  11. package/dist/features/tabs/utils.d.ts +3 -0
  12. package/dist/features/tabs/utils.js +41 -0
  13. package/dist/features/tabs.d.ts +1 -3
  14. package/dist/features/tabs.js +12 -19
  15. package/dist/loaders/constants.d.ts +2 -0
  16. package/dist/loaders/constants.js +32 -0
  17. package/dist/loaders/demo/index.js +3 -3
  18. package/dist/loaders/markdown/index.js +161 -68
  19. package/dist/loaders/markdown/transformer/index.d.ts +2 -0
  20. package/dist/loaders/markdown/transformer/index.js +1 -0
  21. package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -0
  22. package/dist/loaders/markdown/transformer/rehypeDemo.js +17 -9
  23. package/dist/loaders/markdown/transformer/rehypeJsxify.js +1 -1
  24. package/dist/loaders/markdown/transformer/rehypeLink.js +32 -18
  25. package/dist/loaders/markdown/transformer/rehypeRaw.js +2 -2
  26. package/dist/loaders/markdown/transformer/rehypeText.d.ts +2 -1
  27. package/dist/loaders/markdown/transformer/rehypeText.js +3 -3
  28. package/dist/loaders/markdown/transformer/remarkBreaks.js +4 -4
  29. package/dist/loaders/markdown/transformer/remarkEmbed.js +2 -2
  30. package/dist/loaders/markdown/transformer/remarkMeta.js +9 -9
  31. package/dist/techStacks/utils.js +2 -2
  32. package/dist/utils.d.ts +2 -1
  33. package/dist/utils.js +16 -16
  34. package/package.json +1 -1
@@ -33,18 +33,23 @@ __export(block_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(block_exports);
35
35
  var import_utils = require("../utils");
36
- var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
36
+ var import_utils2 = require("@umijs/utils");
37
37
  var import_assert = __toESM(require("assert"));
38
38
  var import_fs = __toESM(require("fs"));
39
39
  var import_path = __toESM(require("path"));
40
- var import_plugin_utils = require("umi/plugin-utils");
41
40
  var import_constants = require("../constants");
42
41
  var MAX_BLOCK_ASSET_CACHE_SIZE = 512;
43
42
  var blockAssetCache = /* @__PURE__ */ new Map();
43
+ var MAX_SIDE_EFFECT_IMPORT_CACHE_ENTRIES = 512;
44
+ var MAX_SIDE_EFFECT_IMPORT_CACHE_CHARACTERS = 1024 * 1024;
45
+ var sideEffectImportCache = /* @__PURE__ */ new Map();
46
+ var sideEffectImportCacheCharacters = 0;
44
47
  function cloneParsedBlockAsset(ret) {
48
+ var _a;
45
49
  return {
46
50
  asset: JSON.parse(JSON.stringify(ret.asset)),
47
51
  resolveMap: { ...ret.resolveMap },
52
+ sideEffectStyles: (_a = ret.sideEffectStyles) == null ? void 0 : _a.slice(),
48
53
  frontmatter: ret.frontmatter ? JSON.parse(JSON.stringify(ret.frontmatter)) : ret.frontmatter
49
54
  };
50
55
  }
@@ -57,13 +62,13 @@ function getContentHashFromFile(file) {
57
62
  }
58
63
  function getDepsKey(deps) {
59
64
  return JSON.stringify(
60
- Array.from(new Set(deps)).sort().map((file) => `${(0, import_plugin_utils.winPath)(file)}:${getContentHashFromFile(file)}`)
65
+ Array.from(new Set(deps)).sort().map((file) => `${(0, import_utils2.winPath)(file)}:${getContentHashFromFile(file)}`)
61
66
  );
62
67
  }
63
68
  function getParseCacheKey(opts) {
64
69
  const entryContent = opts.entryPointCode ?? import_fs.default.readFileSync(opts.fileAbsPath, "utf-8");
65
70
  return JSON.stringify({
66
- file: (0, import_plugin_utils.winPath)(opts.fileAbsPath),
71
+ file: (0, import_utils2.winPath)(opts.fileAbsPath),
67
72
  fileLocale: opts.fileLocale,
68
73
  id: opts.id,
69
74
  refAtomIds: opts.refAtomIds,
@@ -72,7 +77,8 @@ function getParseCacheKey(opts) {
72
77
  runtimeOpts: opts.techStack.runtimeOpts,
73
78
  hasOnBlockLoad: Boolean(opts.techStack.onBlockLoad),
74
79
  hasGenerateMetadata: Boolean(opts.techStack.generateMetadata),
75
- hasGenerateSources: Boolean(opts.techStack.generateSources)
80
+ hasGenerateSources: Boolean(opts.techStack.generateSources),
81
+ collectSideEffectStyles: Boolean(opts.collectSideEffectStyles)
76
82
  });
77
83
  }
78
84
  function getParseDeps(ret, entryFile) {
@@ -98,6 +104,48 @@ function setCachedBlockAsset(cacheKey, ret, deps) {
98
104
  result: cloneParsedBlockAsset(ret)
99
105
  });
100
106
  }
107
+ function getSideEffectImports(code, ext) {
108
+ const cacheKey = process.env.DUMI_CACHE === "none" ? "" : `${ext}\0${code}`;
109
+ const cached = cacheKey ? sideEffectImportCache.get(cacheKey) : void 0;
110
+ if (cached)
111
+ return cached.imports;
112
+ const imports = /* @__PURE__ */ Object.create(null);
113
+ const { parseSync } = require("@swc/core");
114
+ try {
115
+ const program = parseSync(
116
+ code,
117
+ ext === ".ts" || ext === ".tsx" ? { syntax: "typescript", tsx: ext === ".tsx", decorators: true } : { syntax: "ecmascript", jsx: ext === ".jsx", decorators: true }
118
+ );
119
+ for (const item of program.body) {
120
+ if (item.type === "ImportDeclaration") {
121
+ if (item.typeOnly || item.specifiers.length > 0 && item.specifiers.every(
122
+ (specifier) => specifier.type === "ImportSpecifier" && specifier.isTypeOnly
123
+ )) {
124
+ continue;
125
+ }
126
+ const source = item.source.value;
127
+ imports[source] = imports[source] !== false && item.specifiers.length === 0;
128
+ } else if ((item.type === "ExportNamedDeclaration" || item.type === "ExportAllDeclaration") && item.source && !(item.type === "ExportNamedDeclaration" && item.typeOnly)) {
129
+ imports[item.source.value] = false;
130
+ }
131
+ }
132
+ } catch {
133
+ return {};
134
+ }
135
+ if (cacheKey) {
136
+ const size = cacheKey.length + Object.keys(imports).reduce((total, source) => total + source.length, 0);
137
+ if (size <= MAX_SIDE_EFFECT_IMPORT_CACHE_CHARACTERS) {
138
+ while (sideEffectImportCache.size >= MAX_SIDE_EFFECT_IMPORT_CACHE_ENTRIES || sideEffectImportCacheCharacters + size > MAX_SIDE_EFFECT_IMPORT_CACHE_CHARACTERS) {
139
+ const first = sideEffectImportCache.entries().next().value;
140
+ sideEffectImportCache.delete(first[0]);
141
+ sideEffectImportCacheCharacters -= first[1].size;
142
+ }
143
+ sideEffectImportCache.set(cacheKey, { imports, size });
144
+ sideEffectImportCacheCharacters += size;
145
+ }
146
+ }
147
+ return imports;
148
+ }
101
149
  async function parseBlockAsset(opts) {
102
150
  const cacheKey = opts.cacheable ? getParseCacheKey(opts) : "";
103
151
  const cached = cacheKey ? getCachedBlockAsset(cacheKey) : void 0;
@@ -114,9 +162,14 @@ async function parseBlockAsset(opts) {
114
162
  const result = {
115
163
  asset,
116
164
  resolveMap: {},
165
+ sideEffectStyles: [],
117
166
  frontmatter: null
118
167
  };
119
- const deferrer = (0, import_esbuild.build)({
168
+ const styleImports = /* @__PURE__ */ new Map();
169
+ const {
170
+ build
171
+ } = require("@umijs/bundler-utils/compiled/esbuild");
172
+ const deferrer = build({
120
173
  // do not emit file
121
174
  write: false,
122
175
  // enable bundle for trigger onResolve hook, but all deps will be externalized
@@ -132,13 +185,21 @@ async function parseBlockAsset(opts) {
132
185
  name: "plugin-dumi-collect-deps",
133
186
  setup: (builder) => {
134
187
  builder.onResolve({ filter: /.*/ }, (args) => {
135
- if (args.kind !== "entry-point" && !args.path.startsWith(".")) {
136
- const resolved = opts.resolver(args.resolveDir, args.path);
137
- (0, import_assert.default)(
138
- resolved,
139
- `Can't resolve ${args.path} from ${args.resolveDir}`
188
+ var _a, _b;
189
+ const resolved = args.kind === "entry-point" ? import_path.default.join(args.resolveDir, args.path) : opts.resolver(args.resolveDir, args.path);
190
+ (0, import_assert.default)(
191
+ resolved,
192
+ `Can't resolve ${args.path} from ${args.resolveDir}`
193
+ );
194
+ if (opts.collectSideEffectStyles && opts.techStack.runtimeOpts && args.kind !== "entry-point" && !/[?#]/.test(args.path) && /\.(css|less|sass|scss|styl)$/i.test(resolved) && !/\.module\.[^.]+$/i.test(resolved)) {
195
+ const key = args.path.startsWith(".") ? (0, import_utils2.winPath)(resolved) : args.path;
196
+ styleImports.set(
197
+ key,
198
+ styleImports.get(key) !== false && args.kind === "import-statement" && ((_b = (_a = args.pluginData) == null ? void 0 : _a.sideEffectImports) == null ? void 0 : _b[args.path]) === true
140
199
  );
141
- const pkgJsonPath = import_plugin_utils.pkgUp.pkgUpSync({
200
+ }
201
+ if (args.kind !== "entry-point" && !args.path.startsWith(".")) {
202
+ const pkgJsonPath = import_utils2.pkgUp.pkgUpSync({
142
203
  cwd: resolved
143
204
  });
144
205
  if (pkgJsonPath) {
@@ -153,7 +214,7 @@ async function parseBlockAsset(opts) {
153
214
  return { path: args.path, external: true };
154
215
  }
155
216
  return {
156
- path: args.kind !== "entry-point" ? opts.resolver(args.resolveDir, args.path) : import_path.default.join(args.resolveDir, args.path),
217
+ path: resolved,
157
218
  pluginData: {
158
219
  kind: args.kind,
159
220
  resolveDir: args.resolveDir,
@@ -165,7 +226,7 @@ async function parseBlockAsset(opts) {
165
226
  let ext = import_path.default.extname(args.path);
166
227
  const techStack = opts.techStack;
167
228
  const isEntryPoint = args.pluginData.kind === "entry-point";
168
- const filename = `${isEntryPoint ? "index" : (0, import_plugin_utils.winPath)(
229
+ const filename = `${isEntryPoint ? "index" : (0, import_utils2.winPath)(
169
230
  import_path.default.format({
170
231
  ...import_path.default.parse(args.pluginData.source),
171
232
  base: "",
@@ -219,7 +280,10 @@ async function parseBlockAsset(opts) {
219
280
  return {
220
281
  // only continue to load for module files
221
282
  contents: isModule ? contents ?? file.value : "",
222
- loader: isModule ? ext.slice(1) : "text"
283
+ loader: isModule ? ext.slice(1) : "text",
284
+ pluginData: {
285
+ sideEffectImports: opts.collectSideEffectStyles && isModule ? getSideEffectImports(contents ?? file.value, ext) : {}
286
+ }
223
287
  };
224
288
  }
225
289
  });
@@ -233,6 +297,9 @@ async function parseBlockAsset(opts) {
233
297
  } catch {
234
298
  hasError = true;
235
299
  }
300
+ if (!hasError) {
301
+ result.sideEffectStyles = Array.from(styleImports).filter(([, sideEffectOnly]) => sideEffectOnly).map(([key]) => key);
302
+ }
236
303
  if (!hasError && cacheKey) {
237
304
  setCachedBlockAsset(
238
305
  cacheKey,
@@ -37,6 +37,7 @@ __export(compile_exports, {
37
37
  module.exports = __toCommonJS(compile_exports);
38
38
  var import_react = __toESM(require("../../techStacks/react"));
39
39
  var import_utils = require("../../utils");
40
+ var import_crypto = require("crypto");
40
41
  var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
41
42
  var import_fs = __toESM(require("fs"));
42
43
  var import_path = __toESM(require("path"));
@@ -80,6 +81,7 @@ function normalizeMakoAliases(alias, cwd) {
80
81
  return normalizedAlias;
81
82
  }
82
83
  var compile_default = (api) => {
84
+ let utoopackCacheSession;
83
85
  api.describe({ key: "dumi:compile" });
84
86
  api.register({
85
87
  key: "registerTechStack",
@@ -130,6 +132,7 @@ var compile_default = (api) => {
130
132
  var _a, _b;
131
133
  if (api.config.utoopack) {
132
134
  const demoAssetsFile = getUtoopackDemoAssetsFile(api);
135
+ const cacheSession = api.env === "development" && process.env.DUMI_CACHE !== "none" ? utoopackCacheSession ?? (utoopackCacheSession = (0, import_crypto.randomBytes)(16).toString("hex")) : void 0;
133
136
  if (demoAssetsFile)
134
137
  import_fs.default.rmSync(demoAssetsFile, { force: true });
135
138
  api.writeTmpFile({
@@ -142,7 +145,9 @@ var compile_default = (api) => {
142
145
  api.config.extraRemarkPlugins,
143
146
  api.config.extraRehypePlugins,
144
147
  ((_b = api.service.configManager) == null ? void 0 : _b.files) ?? [],
145
- demoAssetsFile
148
+ demoAssetsFile,
149
+ api.config.alias,
150
+ cacheSession
146
151
  )
147
152
  });
148
153
  }
@@ -1,9 +1,10 @@
1
+ import { UTOOPACK_LOADER_CTX_KEY } from '../../loaders/constants';
1
2
  import type { IApi, IDumiTechStack } from '../../types';
2
- export declare const UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
3
+ export { UTOOPACK_LOADER_CTX_KEY };
3
4
  export declare const LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
4
5
  export declare const UTOOPACK_DEMO_ASSETS_FILENAME = "dumi-utoopack-demo-assets.jsonl";
5
6
  export declare function buildLoaderContextContent(techStacks: IDumiTechStack[], builtins?: Record<string, {
6
7
  specifier: string;
7
8
  source: string;
8
- }>, routes?: Record<string, unknown>, extraRemarkPlugins?: IApi['config']['extraRemarkPlugins'], extraRehypePlugins?: IApi['config']['extraRehypePlugins'], sourceFiles?: string[], demoAssetsFile?: string): string;
9
+ }>, routes?: Record<string, unknown>, extraRemarkPlugins?: IApi['config']['extraRemarkPlugins'], extraRehypePlugins?: IApi['config']['extraRehypePlugins'], sourceFiles?: string[], demoAssetsFile?: string, alias?: IApi['config']['alias'], cacheSession?: string): string;
9
10
  export declare const getUtoopackRules: (api: IApi, config?: IApi['config']) => Record<string, unknown>;
@@ -31,11 +31,12 @@ var utoopackLoaders_exports = {};
31
31
  __export(utoopackLoaders_exports, {
32
32
  LOADER_CTX_FILENAME: () => LOADER_CTX_FILENAME,
33
33
  UTOOPACK_DEMO_ASSETS_FILENAME: () => UTOOPACK_DEMO_ASSETS_FILENAME,
34
- UTOOPACK_LOADER_CTX_KEY: () => UTOOPACK_LOADER_CTX_KEY,
34
+ UTOOPACK_LOADER_CTX_KEY: () => import_constants.UTOOPACK_LOADER_CTX_KEY,
35
35
  buildLoaderContextContent: () => buildLoaderContextContent,
36
36
  getUtoopackRules: () => getUtoopackRules
37
37
  });
38
38
  module.exports = __toCommonJS(utoopackLoaders_exports);
39
+ var import_constants = require("../../loaders/constants");
39
40
  var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
40
41
  var import_utils = require("@umijs/utils");
41
42
  var import_path = __toESM(require("path"));
@@ -43,7 +44,6 @@ var import_utils2 = require("./utils");
43
44
  var mdLoaderPath = require.resolve("../../loaders/markdown");
44
45
  var utilsRegisterPath = require.resolve("@umijs/utils");
45
46
  var esbuildImplementorPath = require.resolve("@umijs/bundler-utils/compiled/esbuild");
46
- var UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
47
47
  var LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
48
48
  var UTOOPACK_DEMO_ASSETS_FILENAME = "dumi-utoopack-demo-assets.jsonl";
49
49
  function toSerializable(value) {
@@ -171,7 +171,7 @@ function toPluginRefs(plugins = [], sourceFiles = []) {
171
171
  return toPluginTargetRef(plugin, sourceFiles);
172
172
  }).join(", ")}]`;
173
173
  }
174
- function buildLoaderContextContent(techStacks, builtins = {}, routes = {}, extraRemarkPlugins = [], extraRehypePlugins = [], sourceFiles = [], demoAssetsFile) {
174
+ function buildLoaderContextContent(techStacks, builtins = {}, routes = {}, extraRemarkPlugins = [], extraRehypePlugins = [], sourceFiles = [], demoAssetsFile, alias, cacheSession) {
175
175
  const refs = toTechStackRefs(techStacks);
176
176
  return `'use strict';
177
177
  try {
@@ -186,7 +186,9 @@ try {
186
186
  exports.techStacks = [${refs.join(", ")}];
187
187
  exports.builtins = ${JSON.stringify(builtins)};
188
188
  exports.routes = ${JSON.stringify(routes)};
189
- exports.demoAssetsFile = ${JSON.stringify(demoAssetsFile)};
189
+ exports.alias = ${JSON.stringify(alias)};
190
+ ` + (cacheSession === void 0 ? "" : `exports.cacheSession = ${JSON.stringify(cacheSession)};
191
+ `) + `exports.demoAssetsFile = ${JSON.stringify(demoAssetsFile)};
190
192
  exports.extraRemarkPlugins = ${toPluginRefs(
191
193
  extraRemarkPlugins,
192
194
  sourceFiles
@@ -223,13 +225,13 @@ var getUtoopackRules = (api, config = api.config) => {
223
225
  config.extraBabelPlugins,
224
226
  api.cwd
225
227
  ),
226
- [UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
228
+ [import_constants.UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
227
229
  });
228
230
  const externalDemoLoader = {
229
231
  loader: require.resolve("../../loaders/demo"),
230
232
  options: toSerializable({
231
233
  cwd: api.cwd,
232
- [UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
234
+ [import_constants.UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
233
235
  })
234
236
  };
235
237
  return {
@@ -36,9 +36,9 @@ __export(meta_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(meta_exports);
38
38
  var import_utils = require("../utils");
39
+ var import_utils2 = require("@umijs/utils");
39
40
  var import_path = __toESM(require("path"));
40
- var import_plugin_utils = require("umi/plugin-utils");
41
- var import_tabs = require("./tabs");
41
+ var import_utils3 = require("./tabs/utils");
42
42
  var TABS_META_PATH = "dumi/meta/tabs.ts";
43
43
  var ATOMS_META_PATH = "dumi/meta/atoms.ts";
44
44
  var DEMO_INDEX_META_PATH = "dumi/meta/demoIndex.ts";
@@ -51,10 +51,10 @@ var meta_default = (api) => {
51
51
  fn: (routes) => {
52
52
  metaFiles.length = 0;
53
53
  Object.values(routes).forEach((route) => {
54
- if (!route.isLayout && !/\*|:/.test(route.path) && route.file && !(0, import_tabs.isTabRouteFile)(route.file)) {
54
+ if (!route.isLayout && !/\*|:/.test(route.path) && route.file && !(0, import_utils3.isTabRouteFile)(route.file)) {
55
55
  metaFiles.push({
56
56
  index: metaFiles.length,
57
- file: (0, import_plugin_utils.winPath)(route.file),
57
+ file: (0, import_utils2.winPath)(route.file),
58
58
  id: route.id
59
59
  });
60
60
  }
@@ -0,0 +1,3 @@
1
+ export declare function isTabRouteFile(file: string): boolean;
2
+ export declare function getTabKeyFromFile(file: string): string;
3
+ export declare function getHostForTabRouteFile(file: string): string;
@@ -0,0 +1,41 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/features/tabs/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ getHostForTabRouteFile: () => getHostForTabRouteFile,
23
+ getTabKeyFromFile: () => getTabKeyFromFile,
24
+ isTabRouteFile: () => isTabRouteFile
25
+ });
26
+ module.exports = __toCommonJS(utils_exports);
27
+ function isTabRouteFile(file) {
28
+ return file.includes("$tab-");
29
+ }
30
+ function getTabKeyFromFile(file) {
31
+ return file.match(/\$tab-([^.]+)/)[1];
32
+ }
33
+ function getHostForTabRouteFile(file) {
34
+ return file.replace(/\$tab-[^.]+\./, "");
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ getHostForTabRouteFile,
39
+ getTabKeyFromFile,
40
+ isTabRouteFile
41
+ });
@@ -1,4 +1,5 @@
1
1
  import type { IApi } from '../types';
2
+ export { getHostForTabRouteFile, getTabKeyFromFile, isTabRouteFile, } from './tabs/utils';
2
3
  export interface IContentTab {
3
4
  key: string;
4
5
  id?: string;
@@ -7,9 +8,6 @@ export interface IContentTab {
7
8
  titleIntlId?: string;
8
9
  component: string;
9
10
  }
10
- export declare function isTabRouteFile(file: string): boolean;
11
- export declare function getTabKeyFromFile(file: string): string;
12
- export declare function getHostForTabRouteFile(file: string): string;
13
11
  export default _default;
14
12
  /**
15
13
  * plugin for add conventional tab and plugin tab into page content
@@ -30,24 +30,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var tabs_exports = {};
31
31
  __export(tabs_exports, {
32
32
  default: () => tabs_default,
33
- getHostForTabRouteFile: () => getHostForTabRouteFile,
34
- getTabKeyFromFile: () => getTabKeyFromFile,
35
- isTabRouteFile: () => isTabRouteFile
33
+ getHostForTabRouteFile: () => import_utils4.getHostForTabRouteFile,
34
+ getTabKeyFromFile: () => import_utils4.getTabKeyFromFile,
35
+ isTabRouteFile: () => import_utils4.isTabRouteFile
36
36
  });
37
37
  module.exports = __toCommonJS(tabs_exports);
38
38
  var import_utils = require("@umijs/core/dist/route/utils");
39
+ var import_utils2 = require("@umijs/utils");
39
40
  var import_path = __toESM(require("path"));
40
- var import_plugin_utils = require("umi/plugin-utils");
41
41
  var import_meta = require("./meta");
42
- function isTabRouteFile(file) {
43
- return file.includes("$tab-");
44
- }
45
- function getTabKeyFromFile(file) {
46
- return file.match(/\$tab-([^.]+)/)[1];
47
- }
48
- function getHostForTabRouteFile(file) {
49
- return file.replace(/\$tab-[^.]+\./, "");
50
- }
42
+ var import_utils3 = require("./tabs/utils");
43
+ var import_utils4 = require("./tabs/utils");
51
44
  var tabs_default = (api) => {
52
45
  let tabsFromPlugins;
53
46
  const routesTabMapping = {};
@@ -59,7 +52,7 @@ var tabs_default = (api) => {
59
52
  });
60
53
  tabsFromPlugins.forEach((tab) => {
61
54
  tab.id ?? (tab.id = `plugin-tab-${tab.key}`);
62
- tab.component = (0, import_plugin_utils.winPath)(tab.component);
55
+ tab.component = (0, import_utils2.winPath)(tab.component);
63
56
  });
64
57
  return memo;
65
58
  });
@@ -67,11 +60,11 @@ var tabs_default = (api) => {
67
60
  tabs.length = 0;
68
61
  Object.values(routes).forEach((route) => {
69
62
  var _a;
70
- if (route.file && isTabRouteFile(route.file)) {
63
+ if (route.file && (0, import_utils3.isTabRouteFile)(route.file)) {
71
64
  delete routes[route.id];
72
- const rtlFile = (0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, route.file));
65
+ const rtlFile = (0, import_utils2.winPath)(import_path.default.relative(api.cwd, route.file));
73
66
  const routeId = (0, import_utils.createRouteId)(rtlFile);
74
- const tabKey = getTabKeyFromFile(rtlFile);
67
+ const tabKey = (0, import_utils3.getTabKeyFromFile)(rtlFile);
75
68
  const parentFile = route.file.replace(/\$tab-[^.]+\./, "");
76
69
  tabs.push({
77
70
  index: tabs.length,
@@ -101,7 +94,7 @@ var tabs_default = (api) => {
101
94
  index: tabs.length + index,
102
95
  key: tab.key,
103
96
  id: tab.id,
104
- title: tab.title || import_plugin_utils.lodash.startCase(import_path.default.parse(tab.component).name),
97
+ title: tab.title || import_utils2.lodash.startCase(import_path.default.parse(tab.component).name),
105
98
  titleIntlId: tab.titleIntlId,
106
99
  file: tab.component
107
100
  }))
@@ -133,7 +126,7 @@ var tabs_default = (api) => {
133
126
  api.writeTmpFile({
134
127
  noPluginDir: true,
135
128
  path: import_meta.TABS_META_PATH,
136
- content: import_plugin_utils.Mustache.render(
129
+ content: import_utils2.Mustache.render(
137
130
  `{{#tabs}}
138
131
  import * as tab{{{index}}} from '{{{file}}}';
139
132
  {{/tabs}}
@@ -0,0 +1,2 @@
1
+ export declare const UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
2
+ export declare const CONTENT_TEXTS_OBJ_NAME = "$$contentTexts";
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/loaders/constants.ts
20
+ var constants_exports = {};
21
+ __export(constants_exports, {
22
+ CONTENT_TEXTS_OBJ_NAME: () => CONTENT_TEXTS_OBJ_NAME,
23
+ UTOOPACK_LOADER_CTX_KEY: () => UTOOPACK_LOADER_CTX_KEY
24
+ });
25
+ module.exports = __toCommonJS(constants_exports);
26
+ var UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
27
+ var CONTENT_TEXTS_OBJ_NAME = "$$contentTexts";
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ CONTENT_TEXTS_OBJ_NAME,
31
+ UTOOPACK_LOADER_CTX_KEY
32
+ });
@@ -22,13 +22,13 @@ __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
+ var import_constants = require("../constants");
26
26
  var import_utils = require("@umijs/utils");
27
27
  function demoLoader(raw) {
28
28
  const opts = this.getOptions();
29
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]);
30
+ if (!techStacks && opts[import_constants.UTOOPACK_LOADER_CTX_KEY]) {
31
+ const ctx = require(opts[import_constants.UTOOPACK_LOADER_CTX_KEY]);
32
32
  techStacks = ctx.techStacks;
33
33
  }
34
34
  const techStackName = new URLSearchParams(this.resourceQuery).get(