dumi 2.4.48-alpha.0 → 2.4.48

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.
@@ -53,17 +53,6 @@ var DUMI_DEMO_TAG = "DumiDemo";
53
53
  var DUMI_DEMO_GRID_TAG = "DumiDemoGrid";
54
54
  var SKIP_DEMO_PARSE = "pure";
55
55
  var ALWAYS_DEMO_PARSE = "demo";
56
- function getStableContentHash(value) {
57
- const serialized = JSON.stringify(value, (_key, nestedValue) => {
58
- if (nestedValue && typeof nestedValue === "object" && !Array.isArray(nestedValue)) {
59
- return Object.fromEntries(
60
- Object.keys(nestedValue).sort().map((key) => [key, nestedValue[key]])
61
- );
62
- }
63
- return nestedValue;
64
- });
65
- return (0, import_utils.getContentHash)(serialized);
66
- }
67
56
  var skipDemoRE = new RegExp(
68
57
  /** 注意前面有空格 ==> */
69
58
  ` ${SKIP_DEMO_PARSE}`
@@ -270,135 +259,99 @@ function rehypeDemo(opts) {
270
259
  (0, import_block.default)({
271
260
  ...parseOpts,
272
261
  cacheable: opts.useUtoopackDemoHMR
273
- }).then(async ({ asset, resolveMap, frontmatter }) => {
274
- var _a2, _b2, _c2, _d;
275
- if (demoIds.indexOf(parseOpts.id) !== demoIds.lastIndexOf(parseOpts.id)) {
276
- const startLine = (_a2 = node.position) == null ? void 0 : _a2.start.line;
277
- const suffix = startLine ? `:${startLine}` : "";
278
- import_plugin_utils.logger.warn(
279
- `Duplicate demo id found due to filename conflicts, please consider adding a unique id to code tag to resolve this.
262
+ }).then(
263
+ async ({ asset, resolveMap, frontmatter }) => {
264
+ var _a2, _b2, _c2;
265
+ if (demoIds.indexOf(parseOpts.id) !== demoIds.lastIndexOf(parseOpts.id)) {
266
+ const startLine = (_a2 = node.position) == null ? void 0 : _a2.start.line;
267
+ const suffix = startLine ? `:${startLine}` : "";
268
+ import_plugin_utils.logger.warn(
269
+ `Duplicate demo id found due to filename conflicts, please consider adding a unique id to code tag to resolve this.
280
270
  at ${opts.fileAbsPath}${suffix}`
271
+ );
272
+ }
273
+ const { src, className, ...restAttrs } = codeNode.properties || {};
274
+ const validAssetAttrs = [
275
+ "title",
276
+ "snapshot",
277
+ "keywords"
278
+ ];
279
+ const techStackOpts = {
280
+ type: codeType,
281
+ mdAbsPath: opts.fileAbsPath,
282
+ fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
283
+ entryPointCode: parseOpts.entryPointCode
284
+ };
285
+ Object.keys(restAttrs).forEach((key) => {
286
+ if (restAttrs[key] === "")
287
+ restAttrs[key] = true;
288
+ });
289
+ const originalProps = Object.assign(
290
+ {},
291
+ frontmatter,
292
+ restAttrs
281
293
  );
282
- }
283
- const { src, className, ...restAttrs } = codeNode.properties || {};
284
- const validAssetAttrs = [
285
- "title",
286
- "snapshot",
287
- "keywords"
288
- ];
289
- const techStackOpts = {
290
- type: codeType,
291
- mdAbsPath: opts.fileAbsPath,
292
- fileAbsPath: codeType === "external" ? parseOpts.fileAbsPath : void 0,
293
- entryPointCode: parseOpts.entryPointCode
294
- };
295
- Object.keys(restAttrs).forEach((key) => {
296
- if (restAttrs[key] === "")
297
- restAttrs[key] = true;
298
- });
299
- const originalProps = Object.assign({}, frontmatter, restAttrs);
300
- validAssetAttrs.forEach((key) => {
301
- if (originalProps[key])
302
- asset[key] = originalProps[key];
303
- });
304
- const isInlineDemo = Boolean(
305
- / inline/.test(String((_b2 = codeNode.data) == null ? void 0 : _b2.meta)) || originalProps.inline
306
- );
307
- const shouldDeferPreviewerProps = Boolean(
308
- opts.useUtoopackDemoHMR && codeType === "external" && !isInlineDemo && !(runtimeOpts == null ? void 0 : runtimeOpts.rendererPath) && ((_c2 = runtimeOpts == null ? void 0 : runtimeOpts.deferPreviewerProps) == null ? void 0 : _c2.length)
309
- );
310
- if (opts.useUtoopackDemoHMR && !shouldDeferPreviewerProps) {
311
- propDemo.version = getStableContentHash(asset.dependencies);
312
- }
313
- if (isInlineDemo) {
314
- propDemo.inline = true;
294
+ validAssetAttrs.forEach((key) => {
295
+ if (originalProps[key])
296
+ asset[key] = originalProps[key];
297
+ });
298
+ if (opts.useUtoopackDemoHMR) {
299
+ propDemo.version = (0, import_utils.getContentHash)(
300
+ JSON.stringify(asset.dependencies)
301
+ );
302
+ }
303
+ if (/ inline/.test(String((_b2 = codeNode.data) == null ? void 0 : _b2.meta)) || originalProps.inline) {
304
+ propDemo.inline = true;
305
+ return {
306
+ // TODO: special id for inline demo
307
+ id: asset.id,
308
+ component,
309
+ renderOpts: {
310
+ rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
311
+ preflightPath: runtimeOpts == null ? void 0 : runtimeOpts.preflightPath
312
+ }
313
+ };
314
+ }
315
+ Object.assign(
316
+ previewerProps,
317
+ await ((_c2 = techStack.generatePreviewerProps) == null ? void 0 : _c2.call(
318
+ techStack,
319
+ originalProps,
320
+ techStackOpts
321
+ )) || originalProps
322
+ );
323
+ if (previewerProps.description) {
324
+ const { unified } = await import("unified");
325
+ const { default: remarkParse } = await import("remark-parse");
326
+ const { default: remarkGfm } = await import("remark-gfm");
327
+ const { default: remarkRehype } = await import("remark-rehype");
328
+ const { default: rehypeStringify } = await import("rehype-stringify");
329
+ const { convert } = require("html-to-text");
330
+ const result = await unified().use(remarkParse).use(remarkGfm).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeStringify, { allowDangerousHtml: true }).process(previewerProps.description);
331
+ previewerProps.description = String(result.value);
332
+ asset.description = convert(result.value, {
333
+ wordwrap: false
334
+ });
335
+ }
315
336
  return {
316
- // TODO: special id for inline demo
317
337
  id: asset.id,
318
338
  component,
339
+ asset: techStack.generateMetadata ? await techStack.generateMetadata(asset, techStackOpts) : asset,
340
+ /**
341
+ * keep `generateSources` rather than `generateResolveMap` for compatibility
342
+ */
343
+ resolveMap: techStack.generateSources ? await techStack.generateSources(
344
+ resolveMap,
345
+ techStackOpts
346
+ ) : resolveMap,
319
347
  renderOpts: {
320
348
  rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
349
+ compilePath: runtimeOpts == null ? void 0 : runtimeOpts.compilePath,
321
350
  preflightPath: runtimeOpts == null ? void 0 : runtimeOpts.preflightPath
322
351
  }
323
352
  };
324
353
  }
325
- Object.assign(
326
- previewerProps,
327
- await ((_d = techStack.generatePreviewerProps) == null ? void 0 : _d.call(
328
- techStack,
329
- originalProps,
330
- techStackOpts
331
- )) || originalProps
332
- );
333
- if (previewerProps.description) {
334
- const { unified } = await import("unified");
335
- const { default: remarkParse } = await import("remark-parse");
336
- const { default: remarkGfm } = await import("remark-gfm");
337
- const { default: remarkRehype } = await import("remark-rehype");
338
- const { default: rehypeStringify } = await import("rehype-stringify");
339
- const { convert } = require("html-to-text");
340
- const result = await unified().use(remarkParse).use(remarkGfm).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeStringify, { allowDangerousHtml: true }).process(previewerProps.description);
341
- previewerProps.description = String(result.value);
342
- asset.description = convert(result.value, {
343
- wordwrap: false
344
- });
345
- }
346
- const finalAsset = techStack.generateMetadata ? await techStack.generateMetadata(asset, techStackOpts) : asset;
347
- const finalResolveMap = techStack.generateSources ? await techStack.generateSources(resolveMap, techStackOpts) : resolveMap;
348
- const deferredPreviewerProps = {};
349
- const renderOpts = {
350
- rendererPath: runtimeOpts == null ? void 0 : runtimeOpts.rendererPath,
351
- compilePath: runtimeOpts == null ? void 0 : runtimeOpts.compilePath,
352
- preflightPath: runtimeOpts == null ? void 0 : runtimeOpts.preflightPath
353
- };
354
- if (shouldDeferPreviewerProps) {
355
- runtimeOpts.deferPreviewerProps.forEach((key) => {
356
- if (key in previewerProps) {
357
- deferredPreviewerProps[key] = previewerProps[key];
358
- delete previewerProps[key];
359
- }
360
- });
361
- const versionDependencies = Object.fromEntries(
362
- Object.entries(finalAsset.dependencies).map(
363
- ([key, dependency]) => {
364
- const resolved = finalResolveMap[key];
365
- return [
366
- key,
367
- dependency.type === "FILE" && typeof resolved === "string" && import_path.default.isAbsolute(resolved) ? { ...dependency, value: "<dumi-raw>" } : dependency
368
- ];
369
- }
370
- )
371
- );
372
- propDemo.version = getStableContentHash({
373
- component,
374
- asset: {
375
- ...finalAsset,
376
- dependencies: versionDependencies
377
- },
378
- resolveMap: finalResolveMap,
379
- renderOpts
380
- });
381
- propDemo.__dumiUtoopackHMR = (0, import_plugin_utils.winPath)(
382
- `${opts.fileAbsPath}?type=demo`
383
- );
384
- }
385
- const dumiUtoopackHMRVersion = shouldDeferPreviewerProps ? getStableContentHash({
386
- component,
387
- asset: finalAsset,
388
- resolveMap: finalResolveMap,
389
- previewerProps: deferredPreviewerProps,
390
- renderOpts
391
- }) : void 0;
392
- return {
393
- id: asset.id,
394
- component,
395
- asset: finalAsset,
396
- resolveMap: finalResolveMap,
397
- ...Object.keys(deferredPreviewerProps).length ? { previewerProps: deferredPreviewerProps } : {},
398
- ...dumiUtoopackHMRVersion ? { __dumiUtoopackHMRVersion: dumiUtoopackHMRVersion } : {},
399
- renderOpts
400
- };
401
- })
354
+ )
402
355
  );
403
356
  demosPropData.push({
404
357
  demo: propDemo,
@@ -37,8 +37,7 @@ var ReactTechStack = class {
37
37
  constructor() {
38
38
  this.name = "react";
39
39
  this.runtimeOpts = {
40
- compilePath: require.resolve("../client/misc/reactDemoCompiler"),
41
- deferPreviewerProps: ["jsx"]
40
+ compilePath: require.resolve("../client/misc/reactDemoCompiler")
42
41
  };
43
42
  }
44
43
  isSupported(...[, lang]) {
package/dist/types.d.ts CHANGED
@@ -76,12 +76,6 @@ export interface IDumiTechStackRuntimeOpts {
76
76
  * path to runtime plugin for this tech stack
77
77
  */
78
78
  pluginPath?: string;
79
- /**
80
- * Previewer props that are derived from demo source code and may be loaded
81
- * with the demo runtime instead of being embedded in the Markdown page.
82
- * This is only used by the utoopack development HMR fast path.
83
- */
84
- deferPreviewerProps?: string[];
85
79
  }
86
80
  export declare abstract class IDumiTechStack {
87
81
  /**
package/dist/utils.d.ts CHANGED
@@ -28,8 +28,7 @@ export declare function parseCodeFrontmatter(raw: string): {
28
28
  };
29
29
  declare const caches: Record<string, ReturnType<typeof Cache>>;
30
30
  export declare function _setFSCacheDir(dir: string): void;
31
- export declare function resolveDumiCacheDir(cwd: string, cacheDirectoryPath?: string | false): string;
32
- export declare function getCache(ns: string, baseDir?: string): (typeof caches)['0'];
31
+ export declare function getCache(ns: string): (typeof caches)['0'];
33
32
  /**
34
33
  * try to get father config
35
34
  */
package/dist/utils.js CHANGED
@@ -41,7 +41,6 @@ __export(utils_exports, {
41
41
  getProjectRoot: () => getProjectRoot,
42
42
  isVersionInRange: () => isVersionInRange,
43
43
  parseCodeFrontmatter: () => parseCodeFrontmatter,
44
- resolveDumiCacheDir: () => resolveDumiCacheDir,
45
44
  runLoaders: () => runLoaders,
46
45
  toImportSpecifier: () => toImportSpecifier,
47
46
  tryFatherBuildConfigs: () => tryFatherBuildConfigs
@@ -95,10 +94,7 @@ var caches = {};
95
94
  function _setFSCacheDir(dir) {
96
95
  cacheDir = dir;
97
96
  }
98
- function resolveDumiCacheDir(cwd, cacheDirectoryPath) {
99
- return cacheDirectoryPath ? import_path.default.resolve(cwd, cacheDirectoryPath, "dumi") : import_path.default.resolve(cwd, import_constants.FS_CACHE_DIR);
100
- }
101
- function getCache(ns, baseDir = cacheDir) {
97
+ function getCache(ns) {
102
98
  if (process.env.DUMI_CACHE === "none") {
103
99
  return { set() {
104
100
  }, get() {
@@ -106,8 +102,7 @@ function getCache(ns, baseDir = cacheDir) {
106
102
  }, getSync() {
107
103
  } };
108
104
  }
109
- const basePath = import_path.default.resolve(baseDir, ns);
110
- return caches[basePath] ?? (caches[basePath] = (0, import_file_system_cache.default)({ basePath }));
105
+ return caches[ns] ?? (caches[ns] = (0, import_file_system_cache.default)({ basePath: import_path.default.resolve(cacheDir, ns) }));
111
106
  }
112
107
  async function tryFatherBuildConfigs(cwd) {
113
108
  let configs = [];
@@ -208,7 +203,6 @@ function toImportSpecifier(source) {
208
203
  getProjectRoot,
209
204
  isVersionInRange,
210
205
  parseCodeFrontmatter,
211
- resolveDumiCacheDir,
212
206
  runLoaders,
213
207
  toImportSpecifier,
214
208
  tryFatherBuildConfigs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.4.48-alpha.0",
3
+ "version": "2.4.48",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -69,9 +69,9 @@
69
69
  "@swc/core": "1.9.2",
70
70
  "@types/hast": "^2.3.5",
71
71
  "@types/mdast": "^3.0.12",
72
- "@umijs/bundler-utils": "^4.6.79",
73
- "@umijs/core": "^4.6.79",
74
- "@umijs/utils": "^4.6.79",
72
+ "@umijs/bundler-utils": "^4.6.82",
73
+ "@umijs/core": "^4.6.82",
74
+ "@umijs/utils": "^4.6.82",
75
75
  "animated-scroll-to": "^2.3.0",
76
76
  "classnames": "2.3.2",
77
77
  "codesandbox-import-utils": "^2.2.3",
@@ -101,7 +101,6 @@
101
101
  "prism-react-renderer": "^1.3.5",
102
102
  "prism-themes": "^1.9.0",
103
103
  "prismjs": "^1.29.0",
104
- "proper-lockfile": "^4.1.2",
105
104
  "raw-loader": "^4.0.2",
106
105
  "rc-motion": "^2.7.3",
107
106
  "rc-tabs": "^12.10.0",
@@ -124,7 +123,7 @@
124
123
  "sass": "^1.64.1",
125
124
  "sitemap": "^7.1.1",
126
125
  "sucrase": "^3.34.0",
127
- "umi": "^4.6.79",
126
+ "umi": "^4.6.82",
128
127
  "unified": "^10.1.2",
129
128
  "unist-util-visit": "^4.1.2",
130
129
  "unist-util-visit-parents": "^5.1.3",
@@ -144,13 +143,12 @@
144
143
  "@types/node": "^18.17.1",
145
144
  "@types/pluralize": "^0.0.30",
146
145
  "@types/prismjs": "^1.26.0",
147
- "@types/proper-lockfile": "^4.1.4",
148
146
  "@types/react": "^18.2.17",
149
147
  "@types/react-copy-to-clipboard": "^5.0.4",
150
148
  "@types/react-dom": "^18.2.7",
151
149
  "@typescript/native-preview": "7.0.0-dev.20260623.1",
152
- "@umijs/lint": "^4.6.79",
153
- "@umijs/plugins": "4.6.79",
150
+ "@umijs/lint": "^4.6.82",
151
+ "@umijs/plugins": "4.6.82",
154
152
  "eslint": "^8.46.0",
155
153
  "esno": "^4.7.0",
156
154
  "fast-glob": "^3.3.1",
@@ -21,9 +21,6 @@ var SourceCodeEditor = function SourceCodeEditor(props) {
21
21
  _useState4 = _slicedToArray(_useState3, 2),
22
22
  code = _useState4[0],
23
23
  setCode = _useState4[1];
24
- useEffect(function () {
25
- setCode(props.initialValue);
26
- }, [props.initialValue]);
27
24
 
28
25
  // generate style from pre element, for adapting to the custom theme
29
26
  useEffect(function () {
@@ -1,5 +0,0 @@
1
- export type DemoHMRListener = () => void;
2
- export declare function registerDemoHMRModule(moduleId: string, semanticVersions: Record<string, string>): void;
3
- export declare function getDemoHMRRevision(moduleId: string, demoId: string): number;
4
- export declare function subscribeDemoHMR(moduleId: string, demoId: string, listener: DemoHMRListener): () => void;
5
- export declare function resetDemoHMRStoreForTest(): void;
@@ -1,67 +0,0 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- var DEMO_HMR_STORE_KEY = Symbol.for('dumi.demo-hmr-store');
8
- function getDemoHMRKey(moduleId, demoId) {
9
- return JSON.stringify([moduleId, demoId]);
10
- }
11
- function getDemoHMRStore() {
12
- var _globalStore$DEMO_HMR;
13
- var globalStore = globalThis;
14
- return (_globalStore$DEMO_HMR = globalStore[DEMO_HMR_STORE_KEY]) !== null && _globalStore$DEMO_HMR !== void 0 ? _globalStore$DEMO_HMR : globalStore[DEMO_HMR_STORE_KEY] = {
15
- moduleVersions: new Map(),
16
- revisions: new Map(),
17
- listeners: new Map()
18
- };
19
- }
20
- export function registerDemoHMRModule(moduleId, semanticVersions) {
21
- var store = getDemoHMRStore();
22
- var previousVersions = store.moduleVersions.get(moduleId);
23
- if (!previousVersions) {
24
- store.moduleVersions.set(moduleId, new Map(Object.entries(semanticVersions)));
25
- return;
26
- }
27
- for (var _i = 0, _Object$entries = Object.entries(semanticVersions); _i < _Object$entries.length; _i++) {
28
- var _store$revisions$get, _store$listeners$get;
29
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
30
- demoId = _Object$entries$_i[0],
31
- nextVersion = _Object$entries$_i[1];
32
- if (!previousVersions.has(demoId)) {
33
- previousVersions.set(demoId, nextVersion);
34
- continue;
35
- }
36
- if (previousVersions.get(demoId) === nextVersion) continue;
37
- previousVersions.set(demoId, nextVersion);
38
- var key = getDemoHMRKey(moduleId, demoId);
39
- store.revisions.set(key, ((_store$revisions$get = store.revisions.get(key)) !== null && _store$revisions$get !== void 0 ? _store$revisions$get : 0) + 1);
40
- (_store$listeners$get = store.listeners.get(key)) === null || _store$listeners$get === void 0 || _store$listeners$get.forEach(function (listener) {
41
- return listener();
42
- });
43
- }
44
- }
45
- export function getDemoHMRRevision(moduleId, demoId) {
46
- var _getDemoHMRStore$revi;
47
- return (_getDemoHMRStore$revi = getDemoHMRStore().revisions.get(getDemoHMRKey(moduleId, demoId))) !== null && _getDemoHMRStore$revi !== void 0 ? _getDemoHMRStore$revi : 0;
48
- }
49
- export function subscribeDemoHMR(moduleId, demoId, listener) {
50
- var store = getDemoHMRStore();
51
- var key = getDemoHMRKey(moduleId, demoId);
52
- var listeners = store.listeners.get(key);
53
- if (!listeners) {
54
- listeners = new Set();
55
- store.listeners.set(key, listeners);
56
- }
57
- var currentListeners = listeners;
58
- currentListeners.add(listener);
59
- return function () {
60
- currentListeners.delete(listener);
61
- if (currentListeners.size === 0) store.listeners.delete(key);
62
- };
63
- }
64
- export function resetDemoHMRStoreForTest() {
65
- var globalStore = globalThis;
66
- delete globalStore[DEMO_HMR_STORE_KEY];
67
- }
@@ -1,11 +0,0 @@
1
- interface ISharedCacheOptions<T> {
2
- lockPath: string;
3
- getValue: () => T | undefined | Promise<T | undefined>;
4
- createValue: () => Promise<T>;
5
- setValue: (value: T) => void;
6
- retryMs?: number;
7
- staleMs?: number;
8
- lockTimeoutMs?: number;
9
- }
10
- export declare function getOrCreateWithFileLock<T>({ lockPath, getValue, createValue, setValue, retryMs, staleMs, lockTimeoutMs, }: ISharedCacheOptions<T>): Promise<T>;
11
- export {};
@@ -1,131 +0,0 @@
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/loaders/markdown/sharedCache.ts
30
- var sharedCache_exports = {};
31
- __export(sharedCache_exports, {
32
- getOrCreateWithFileLock: () => getOrCreateWithFileLock
33
- });
34
- module.exports = __toCommonJS(sharedCache_exports);
35
- var import_fs = __toESM(require("fs"));
36
- var import_path = __toESM(require("path"));
37
- var import_proper_lockfile = require("proper-lockfile");
38
- function delay(ms) {
39
- return new Promise((resolve) => {
40
- setTimeout(resolve, ms);
41
- });
42
- }
43
- async function acquireFileLock(lockPath, retryMs, staleMs, lockTimeoutMs, onCompromised) {
44
- const deadline = Date.now() + lockTimeoutMs;
45
- while (true) {
46
- try {
47
- return await (0, import_proper_lockfile.lock)(lockPath, {
48
- lockfilePath: lockPath,
49
- onCompromised,
50
- realpath: false,
51
- stale: staleMs,
52
- update: Math.min(10 * 1e3, staleMs / 2)
53
- });
54
- } catch (err) {
55
- if ((err == null ? void 0 : err.code) !== "ELOCKED")
56
- throw err;
57
- if (Date.now() >= deadline) {
58
- throw Object.assign(
59
- new Error(`Timed out waiting for cache lock: ${lockPath}`),
60
- { cause: err, code: "ELOCKTIMEOUT" }
61
- );
62
- }
63
- await delay(retryMs + Math.floor(Math.random() * retryMs));
64
- }
65
- }
66
- }
67
- async function getOrCreateWithFileLock({
68
- lockPath,
69
- getValue,
70
- createValue,
71
- setValue,
72
- retryMs = 20,
73
- staleMs = 5 * 60 * 1e3,
74
- lockTimeoutMs = 10 * 60 * 1e3
75
- }) {
76
- const cached = await getValue();
77
- if (cached !== void 0)
78
- return cached;
79
- import_fs.default.mkdirSync(import_path.default.dirname(lockPath), { recursive: true });
80
- let compromisedError;
81
- const release = await acquireFileLock(
82
- lockPath,
83
- retryMs,
84
- staleMs,
85
- lockTimeoutMs,
86
- (err) => {
87
- compromisedError = err;
88
- }
89
- );
90
- let result;
91
- let operationError;
92
- let hasOperationError = false;
93
- try {
94
- const lockedCache = await getValue();
95
- if (lockedCache === void 0) {
96
- const created = await createValue();
97
- if (compromisedError)
98
- throw compromisedError;
99
- setValue(created);
100
- result = created;
101
- } else {
102
- result = lockedCache;
103
- }
104
- } catch (err) {
105
- operationError = err;
106
- hasOperationError = true;
107
- }
108
- let releaseError;
109
- let hasReleaseError = false;
110
- try {
111
- await release();
112
- } catch (err) {
113
- if (!compromisedError || (err == null ? void 0 : err.code) !== "ERELEASED") {
114
- releaseError = err;
115
- hasReleaseError = true;
116
- }
117
- }
118
- if (compromisedError && !hasOperationError) {
119
- operationError = compromisedError;
120
- hasOperationError = true;
121
- }
122
- if (hasOperationError)
123
- throw operationError;
124
- if (hasReleaseError)
125
- throw releaseError;
126
- return result;
127
- }
128
- // Annotate the CommonJS export names for ESM import in node:
129
- 0 && (module.exports = {
130
- getOrCreateWithFileLock
131
- });