dumi 2.4.46 → 2.4.48-alpha.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.
@@ -29,9 +29,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/loaders/markdown/index.ts
30
30
  var markdown_exports = {};
31
31
  __export(markdown_exports, {
32
+ addDemoFileDependency: () => addDemoFileDependency,
33
+ createDependencyReader: () => createDependencyReader,
34
+ createStableTransform: () => createStableTransform,
32
35
  default: () => mdLoader,
36
+ emitDemo: () => emitDemo,
33
37
  getDemoSourceFiles: () => getDemoSourceFiles,
34
- getMdLoaderCacheSync: () => getMdLoaderCacheSync
38
+ getDepsCacheKey: () => getDepsCacheKey,
39
+ getMdLoaderCacheResult: () => getMdLoaderCacheResult,
40
+ getMdLoaderCacheSync: () => getMdLoaderCacheSync,
41
+ getMdTransformCacheKeys: () => getMdTransformCacheKeys
35
42
  });
36
43
  module.exports = __toCommonJS(markdown_exports);
37
44
  var import_utoopackLoaders = require("../../features/compile/utoopackLoaders");
@@ -40,8 +47,61 @@ var import_utils = require("../../utils");
40
47
  var import_fs = __toESM(require("fs"));
41
48
  var import_path = __toESM(require("path"));
42
49
  var import_plugin_utils = require("umi/plugin-utils");
50
+ var import_sharedCache = require("./sharedCache");
43
51
  var import_transformer = __toESM(require("./transformer"));
44
52
  var import_rehypeText = require("./transformer/rehypeText");
53
+ var MD_LOADER_RUNTIME_OPTION_KEYS = [
54
+ "mode",
55
+ "builtins",
56
+ "onResolveDemos",
57
+ "onResolveAtomMeta",
58
+ "demoAssetsFile",
59
+ "cacheDirectory",
60
+ "cacheEpoch"
61
+ ];
62
+ function getMdTransformCacheKeys({
63
+ resourcePath,
64
+ content,
65
+ useUtoopackDemoHMR,
66
+ opts
67
+ }) {
68
+ const depsHintKey = [
69
+ resourcePath,
70
+ useUtoopackDemoHMR,
71
+ JSON.stringify(import_plugin_utils.lodash.omit(opts, MD_LOADER_RUNTIME_OPTION_KEYS))
72
+ ].join(":");
73
+ return {
74
+ depsHintKey,
75
+ baseCacheKey: [depsHintKey, (0, import_utils.getContentHash)(content)].join(":")
76
+ };
77
+ }
78
+ function getStatRevision(stat) {
79
+ return [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeNs, stat.ctimeNs].map(String).join(":");
80
+ }
81
+ async function getFileRevision(file) {
82
+ return getStatRevision(await import_fs.default.promises.stat(file, { bigint: true }));
83
+ }
84
+ function isMissingFsError(err) {
85
+ return (err == null ? void 0 : err.code) === "ENOENT" || (err == null ? void 0 : err.code) === "ENOTDIR";
86
+ }
87
+ async function getMissingParentRevision(file) {
88
+ let current = file;
89
+ while (true) {
90
+ try {
91
+ const revision = getStatRevision(
92
+ await import_fs.default.promises.stat(current, { bigint: true })
93
+ );
94
+ return `${import_path.default.normalize(current)}:${current === file ? "<appeared>:" : ""}${revision}`;
95
+ } catch (err) {
96
+ if (!isMissingFsError(err))
97
+ throw err;
98
+ const parent = import_path.default.dirname(current);
99
+ if (parent === current)
100
+ return `${current}:<missing>`;
101
+ current = parent;
102
+ }
103
+ }
104
+ }
45
105
  function isMalformedCacheError(err) {
46
106
  return err instanceof SyntaxError || err instanceof Error && /Unexpected end of JSON input|Unterminated string in JSON/.test(
47
107
  err.message
@@ -56,25 +116,40 @@ function getMdLoaderCacheSync(cache, key, defaultValue) {
56
116
  throw err;
57
117
  }
58
118
  }
59
- function getDemoSidecarFiles(file) {
119
+ function getDemoSidecarFile(file) {
60
120
  const { dir, name } = import_path.default.parse(file);
61
- const mdFile = import_path.default.join(dir, `${name}.md`);
62
- return import_fs.default.existsSync(mdFile) ? [mdFile] : [];
121
+ return import_path.default.join(dir, `${name}.md`);
63
122
  }
64
- function getDemoSourceFiles(demos = []) {
123
+ function collectDemoSourceFiles(demos = [], includeMissingSidecars = false) {
65
124
  const files = /* @__PURE__ */ new Set();
66
125
  demos.forEach((demo) => {
67
126
  if ("resolveMap" in demo) {
68
127
  Object.values(demo.resolveMap).filter((p) => import_path.default.isAbsolute(p)).forEach((file) => {
69
128
  files.add(file);
70
- getDemoSidecarFiles(file).forEach(
71
- (sidecarFile) => files.add(sidecarFile)
72
- );
129
+ const sidecarFile = getDemoSidecarFile(file);
130
+ if (includeMissingSidecars || import_fs.default.existsSync(sidecarFile)) {
131
+ files.add(sidecarFile);
132
+ }
73
133
  });
74
134
  }
75
135
  });
76
136
  return Array.from(files);
77
137
  }
138
+ function getDemoSourceFiles(demos = []) {
139
+ return collectDemoSourceFiles(demos);
140
+ }
141
+ function getDemoCacheFiles(demos = []) {
142
+ return collectDemoSourceFiles(demos, true);
143
+ }
144
+ function addDemoFileDependency(loaderContext, opts, file) {
145
+ if (import_fs.default.existsSync(file) || import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts) {
146
+ loaderContext.addDependency(file);
147
+ } else if (loaderContext.addMissingDependency) {
148
+ loaderContext.addMissingDependency(file);
149
+ } else {
150
+ loaderContext.addDependency(file);
151
+ }
152
+ }
78
153
  function isRelativePath(path2) {
79
154
  return /^\.{1,2}(?!\w)/.test(path2);
80
155
  }
@@ -143,6 +218,21 @@ export default DumiMarkdownContent;`;
143
218
  }
144
219
  function emitDemo(opts, ret) {
145
220
  const { demos } = ret.meta;
221
+ const demoHMRVersions = Object.fromEntries(
222
+ (demos ?? []).flatMap((demo) => {
223
+ const hmrVersion = demo.__dumiUtoopackHMRVersion;
224
+ return typeof hmrVersion === "string" ? [[demo.id, hmrVersion]] : [];
225
+ })
226
+ );
227
+ const enableDemoHMR = opts.useUtoopackDemoHMR === true && Object.keys(demoHMRVersions).length > 0;
228
+ const demoHMRModuleId = JSON.stringify(
229
+ (0, import_plugin_utils.winPath)(`${this.resourcePath}?type=demo`)
230
+ );
231
+ const enableUtoopackSelfAccept = enableDemoHMR && import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts;
232
+ const renderedDemos = demos == null ? void 0 : demos.map((demo) => ({
233
+ ...demo,
234
+ renderedPreviewerProps: "previewerProps" in demo && demo.previewerProps ? JSON.stringify(demo.previewerProps) : void 0
235
+ }));
146
236
  const shareDepsMap = {};
147
237
  const demoDepsMap = {};
148
238
  const relativeDepsMap = {};
@@ -185,6 +275,9 @@ function emitDemo(opts, ret) {
185
275
  return import_plugin_utils.Mustache.render(
186
276
  `import React from 'react';
187
277
  import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
278
+ {{#enableDemoHMR}}
279
+ import { registerDemoHMRModule } from 'dumi/dist/client/theme-api/DumiDemo/hmr';
280
+ {{/enableDemoHMR}}
188
281
  {{#dedupedDemosDeps}}
189
282
  import * as {{{specifier}}} from '{{{key}}}';
190
283
  {{/dedupedDemosDeps}}
@@ -199,13 +292,29 @@ export const demos = {
199
292
  routeId: '{{{routeId}}}',
200
293
  {{/routeId}}
201
294
  context: {{{renderContext}}},
295
+ {{#previewerProps}}
296
+ previewerProps: {{{renderedPreviewerProps}}},
297
+ {{/previewerProps}}
202
298
  renderOpts: {{{renderRenderOpts}}},
203
299
  },
204
300
  {{/demos}}
205
- };`,
301
+ };{{#enableUtoopackSelfAccept}}
302
+ if (
303
+ typeof __turbopack_context__ !== 'undefined' &&
304
+ typeof __turbopack_context__.m?.hot?.accept === 'function'
305
+ ) {
306
+ __turbopack_context__.m.hot.accept();
307
+ }
308
+ {{/enableUtoopackSelfAccept}}{{#enableDemoHMR}}
309
+ registerDemoHMRModule({{{demoHMRModuleId}}}, {{{demoHMRVersions}}});
310
+ {{/enableDemoHMR}}`,
206
311
  {
207
- demos,
312
+ demos: renderedDemos,
208
313
  dedupedDemosDeps,
314
+ demoHMRModuleId,
315
+ demoHMRVersions: JSON.stringify(demoHMRVersions),
316
+ enableDemoHMR,
317
+ enableUtoopackSelfAccept,
209
318
  routeId,
210
319
  renderAsset: function renderAsset() {
211
320
  if (!("asset" in this))
@@ -345,7 +454,9 @@ function emit(opts, ret) {
345
454
  const { demos, embeds } = ret.meta;
346
455
  embeds.forEach((file) => this.addDependency(file));
347
456
  if (opts.mode !== "demo-index") {
348
- getDemoSourceFiles(demos).forEach((file) => this.addDependency(file));
457
+ getDemoCacheFiles(demos).forEach(
458
+ (file) => addDemoFileDependency(this, opts, file)
459
+ );
349
460
  }
350
461
  if (this.resourceQuery.includes("watch=parent"))
351
462
  return null;
@@ -362,20 +473,108 @@ function emit(opts, ret) {
362
473
  return emitDefault.call(this, opts, ret);
363
474
  }
364
475
  }
365
- function getDepsCacheKey(deps = []) {
476
+ function normalizeDeps(deps = []) {
477
+ return Array.from(new Set(deps)).sort();
478
+ }
479
+ var readDependencyFromFs = (file) => import_fs.default.promises.readFile(file, "utf-8");
480
+ async function getDepsCacheKey(deps = [], readDependency = readDependencyFromFs) {
366
481
  return JSON.stringify(
367
- deps.map(
368
- (file) => `${file}:${(0, import_utils.getContentHash)(import_fs.default.readFileSync(file, "utf-8"))}`
482
+ await Promise.all(
483
+ normalizeDeps(deps).map(async (file) => {
484
+ try {
485
+ const content = await readDependency(file);
486
+ return `${file}:${(0, import_utils.getContentHash)(content)}:${await getFileRevision(
487
+ file
488
+ )}`;
489
+ } catch (err) {
490
+ if (isMissingFsError(err)) {
491
+ return `${file}:<missing>:${await getMissingParentRevision(file)}`;
492
+ }
493
+ throw err;
494
+ }
495
+ })
369
496
  )
370
497
  );
371
498
  }
499
+ function getMdLoaderCacheRecord(cache, key) {
500
+ const record = getMdLoaderCacheSync(
501
+ cache,
502
+ key,
503
+ void 0
504
+ );
505
+ return (record == null ? void 0 : record.version) === 2 ? record : void 0;
506
+ }
507
+ async function getValidMdLoaderCacheRecord(cache, key, readDependency = readDependencyFromFs) {
508
+ const record = getMdLoaderCacheRecord(cache, key);
509
+ if (!record)
510
+ return void 0;
511
+ if (record.depsKey === await getDepsCacheKey(record.deps, readDependency)) {
512
+ return record;
513
+ }
514
+ return void 0;
515
+ }
516
+ async function getMdLoaderCacheResult(cache, key, readDependency = readDependencyFromFs) {
517
+ var _a;
518
+ return (_a = await getValidMdLoaderCacheRecord(cache, key, readDependency)) == null ? void 0 : _a.result;
519
+ }
520
+ async function createStableTransform({
521
+ initialDeps,
522
+ createValue,
523
+ getDeps,
524
+ readDependency = readDependencyFromFs,
525
+ onDepsDiscovered,
526
+ maxAttempts = 3
527
+ }) {
528
+ let expectedDeps = initialDeps && normalizeDeps(initialDeps);
529
+ for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
530
+ const beforeKey = expectedDeps ? await getDepsCacheKey(expectedDeps, readDependency) : void 0;
531
+ const result = await createValue();
532
+ const deps = normalizeDeps(getDeps(result));
533
+ const depsKey = await getDepsCacheKey(deps, readDependency);
534
+ onDepsDiscovered == null ? void 0 : onDepsDiscovered(deps);
535
+ if (expectedDeps && JSON.stringify(expectedDeps) === JSON.stringify(deps) && beforeKey === depsKey) {
536
+ return { version: 2, deps, depsKey, result };
537
+ }
538
+ expectedDeps = deps;
539
+ }
540
+ throw Object.assign(
541
+ new Error("Markdown dependencies changed repeatedly while transforming"),
542
+ { code: "EDEPSUNSTABLE" }
543
+ );
544
+ }
545
+ function createDependencyReader(loaderContext, useUtoopack, mode) {
546
+ var _a;
547
+ if (useUtoopack && mode !== "demo-index" && ((_a = loaderContext.fs) == null ? void 0 : _a.readFile)) {
548
+ return (file) => new Promise((resolve, reject) => {
549
+ loaderContext.fs.readFile(
550
+ file,
551
+ (err, data) => {
552
+ if (err)
553
+ reject(err);
554
+ else
555
+ resolve(
556
+ Buffer.isBuffer(data) ? data.toString("utf-8") : String(data)
557
+ );
558
+ }
559
+ );
560
+ });
561
+ }
562
+ return readDependencyFromFs;
563
+ }
564
+ function getMdTransformDepsHint(cache, key) {
565
+ const hint = getMdLoaderCacheSync(
566
+ cache,
567
+ key,
568
+ void 0
569
+ );
570
+ return (hint == null ? void 0 : hint.version) === 1 ? normalizeDeps(hint.deps) : void 0;
571
+ }
372
572
  var deferrer = {};
373
- var depsMapping = {};
374
573
  function mdLoader(content) {
375
574
  var _a, _b, _c;
376
575
  let opts = this.getOptions();
377
576
  const loaderContextPath = opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY];
378
- const useUtoopackDemoHMR = process.env.NODE_ENV !== "production" && Boolean(loaderContextPath);
577
+ const useUtoopackDemoHMR = opts.useUtoopackDemoHMR === true && Boolean(loaderContextPath);
379
578
  if (loaderContextPath) {
380
579
  const ctx = require(loaderContextPath);
381
580
  if (!((_a = opts.techStacks) == null ? void 0 : _a.length)) {
@@ -403,47 +602,119 @@ function mdLoader(content) {
403
602
  )) {
404
603
  this.cacheable(false);
405
604
  }
406
- const cache = (0, import_utils.getCache)("md-loader");
407
- const baseCacheKey = [
408
- this.resourcePath,
409
- (0, import_utils.getContentHash)(content),
605
+ const cacheEpoch = opts.cacheEpoch;
606
+ const cacheNamespace = useUtoopackDemoHMR && cacheEpoch ? (0, import_utoopackLoaders.getUtoopackMdCacheNamespace)(cacheEpoch) : "md-loader";
607
+ const cache = (0, import_utils.getCache)(cacheNamespace, opts.cacheDirectory);
608
+ const depsHintCache = (0, import_utils.getCache)("md-loader-deps", opts.cacheDirectory);
609
+ const readDependency = createDependencyReader(
610
+ this,
410
611
  useUtoopackDemoHMR,
411
- JSON.stringify(import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]))
412
- ].join(":");
413
- const cacheKey = [
414
- baseCacheKey,
415
- getDepsCacheKey(depsMapping[this.resourcePath])
416
- ].join(":");
417
- const cacheRet = getMdLoaderCacheSync(cache, cacheKey, "");
418
- if (cacheRet) {
419
- cb(null, emit.call(this, opts, cacheRet));
420
- return;
421
- } else if (cacheKey in deferrer) {
422
- deferrer[cacheKey].then((res) => {
423
- cb(null, emit.call(this, opts, res));
424
- }).catch(cb);
425
- return;
426
- }
427
- deferrer[cacheKey] = (0, import_transformer.default)(content, {
428
- ...import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]),
429
- fileAbsPath: (0, import_plugin_utils.winPath)(this.resourcePath),
430
- useUtoopackDemoHMR
612
+ opts.mode
613
+ );
614
+ const { baseCacheKey, depsHintKey } = getMdTransformCacheKeys({
615
+ resourcePath: this.resourcePath,
616
+ content,
617
+ useUtoopackDemoHMR,
618
+ opts
431
619
  });
432
- deferrer[cacheKey].then((ret) => {
433
- depsMapping[this.resourcePath] = ret.meta.embeds.concat(
434
- getDemoSourceFiles(ret.meta.demos)
435
- );
436
- const finalCacheKey = [
620
+ const createTransform = async () => {
621
+ return (0, import_transformer.default)(content, {
622
+ ...import_plugin_utils.lodash.omit(opts, [
623
+ "mode",
624
+ "builtins",
625
+ "onResolveDemos",
626
+ "cacheDirectory",
627
+ "cacheEpoch"
628
+ ]),
629
+ fileAbsPath: (0, import_plugin_utils.winPath)(this.resourcePath),
630
+ useUtoopackDemoHMR
631
+ });
632
+ };
633
+ const getTransformDeps = (ret) => normalizeDeps(ret.meta.embeds.concat(getDemoCacheFiles(ret.meta.demos)));
634
+ const saveDepsHint = (deps) => {
635
+ depsHintCache.setSync(depsHintKey, {
636
+ version: 1,
637
+ deps: normalizeDeps(deps)
638
+ });
639
+ };
640
+ const cacheWithPath = cache;
641
+ const getTransform = async () => {
642
+ var _a2;
643
+ const cached = await getValidMdLoaderCacheRecord(
644
+ cache,
437
645
  baseCacheKey,
438
- getDepsCacheKey(depsMapping[this.resourcePath])
439
- ].join(":");
440
- cache.setSync(finalCacheKey, ret);
441
- cb(null, emit.call(this, opts, ret));
442
- delete deferrer[cacheKey];
443
- }).catch(cb);
646
+ readDependency
647
+ );
648
+ if (cached)
649
+ return cached;
650
+ const initialDeps = getMdTransformDepsHint(depsHintCache, depsHintKey) ?? ((_a2 = getMdLoaderCacheRecord(cache, baseCacheKey)) == null ? void 0 : _a2.deps);
651
+ const depsFingerprint = initialDeps ? await getDepsCacheKey(initialDeps, readDependency) : "<discover>";
652
+ const deferrerKey = [cacheNamespace, baseCacheKey, depsFingerprint].join(
653
+ ":"
654
+ );
655
+ if (deferrerKey in deferrer)
656
+ return deferrer[deferrerKey];
657
+ const createRecord = async () => {
658
+ if (useUtoopackDemoHMR) {
659
+ return createStableTransform({
660
+ initialDeps,
661
+ createValue: createTransform,
662
+ getDeps: getTransformDeps,
663
+ readDependency,
664
+ onDepsDiscovered: saveDepsHint
665
+ });
666
+ }
667
+ const result = await createTransform();
668
+ const deps = getTransformDeps(result);
669
+ const record = {
670
+ version: 2,
671
+ deps,
672
+ depsKey: await getDepsCacheKey(deps),
673
+ result
674
+ };
675
+ saveDepsHint(deps);
676
+ return record;
677
+ };
678
+ const saveRecord = (record) => {
679
+ cache.setSync(baseCacheKey, record);
680
+ saveDepsHint(record.deps);
681
+ };
682
+ const pending = useUtoopackDemoHMR && cacheWithPath.path ? (0, import_sharedCache.getOrCreateWithFileLock)({
683
+ lockPath: `${cacheWithPath.path(`transform:${baseCacheKey}`)}.lock`,
684
+ getValue: () => getValidMdLoaderCacheRecord(cache, baseCacheKey, readDependency),
685
+ createValue: createRecord,
686
+ setValue: saveRecord
687
+ }) : (async () => {
688
+ const current = await getValidMdLoaderCacheRecord(
689
+ cache,
690
+ baseCacheKey,
691
+ readDependency
692
+ );
693
+ if (current)
694
+ return current;
695
+ const created = await createRecord();
696
+ saveRecord(created);
697
+ return created;
698
+ })();
699
+ deferrer[deferrerKey] = pending;
700
+ try {
701
+ return await pending;
702
+ } finally {
703
+ if (deferrer[deferrerKey] === pending)
704
+ delete deferrer[deferrerKey];
705
+ }
706
+ };
707
+ getTransform().then((record) => cb(null, emit.call(this, opts, record.result))).catch(cb);
444
708
  }
445
709
  // Annotate the CommonJS export names for ESM import in node:
446
710
  0 && (module.exports = {
711
+ addDemoFileDependency,
712
+ createDependencyReader,
713
+ createStableTransform,
714
+ emitDemo,
447
715
  getDemoSourceFiles,
448
- getMdLoaderCacheSync
716
+ getDepsCacheKey,
717
+ getMdLoaderCacheResult,
718
+ getMdLoaderCacheSync,
719
+ getMdTransformCacheKeys
449
720
  });
@@ -0,0 +1,11 @@
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 {};
@@ -0,0 +1,131 @@
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
+ });
@@ -1,4 +1,5 @@
1
1
  import type { IParsedBlockAsset } from '../../../assetParsers/block';
2
+ import type { IDumiDemoProps } from '@/client/theme-api/DumiDemo';
2
3
  import type { ILocalesConfig, IRouteMeta } from '@/client/theme-api/types';
3
4
  import type { IApi, IDumiConfig, IDumiTechStack } from '../../../types';
4
5
  import { type ResolveOptions } from 'enhanced-resolve';
@@ -23,6 +24,9 @@ declare module 'vfile' {
23
24
  component: string;
24
25
  asset: IParsedBlockAsset['asset'];
25
26
  resolveMap: IParsedBlockAsset['resolveMap'];
27
+ previewerProps?: IDumiDemoProps['previewerProps'];
28
+ /** Internal semantic version used by the utoopack demo HMR runtime. */
29
+ __dumiUtoopackHMRVersion?: string;
26
30
  renderOpts: {
27
31
  type?: string;
28
32
  rendererPath?: string;