@mui/internal-docs-infra 0.12.1-canary.2 → 0.12.1-canary.21
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/ChunkProvider/PreloadProvider.mjs +1 -2
- package/ChunkProvider/usePreload.d.mts +1 -1
- package/ChunkProvider/usePreload.mjs +0 -1
- package/CodeControllerContext/CodeControllerContext.d.mts +45 -10
- package/CodeControllerContext/CodeControllerContext.mjs +15 -1
- package/CodeHighlighter/CodeHighlighterClient.d.mts +3 -2
- package/CodeHighlighter/CodeHighlighterClient.mjs +113 -18
- package/CodeHighlighter/CodeHighlighterContext.d.mts +9 -3
- package/CodeHighlighter/buildStringFallback.d.mts +1 -1
- package/CodeHighlighter/codeToFallbackProps.d.mts +1 -1
- package/CodeHighlighter/createClientProps.mjs +3 -0
- package/CodeHighlighter/fallbackCompression.d.mts +1 -1
- package/CodeHighlighter/parseControlledCode.d.mts +13 -4
- package/CodeHighlighter/parseControlledCode.mjs +41 -49
- package/CodeHighlighter/types.d.mts +21 -0
- package/CodeHighlighter/useGrammarsReady.mjs +44 -9
- package/CodeProvider/CodeProvider.d.mts +1 -1
- package/CodeProvider/CodeProviderLazy.d.mts +1 -1
- package/CodeProvider/createParseSourceWorkerClient.d.mts +6 -0
- package/CodeProvider/createParseSourceWorkerClient.mjs +83 -15
- package/CodeProvider/useCodeProviderValue.mjs +50 -4
- package/abstractCreateDemo/abstractCreateDemo.d.mts +15 -1
- package/abstractCreateDemo/abstractCreateDemo.mjs +8 -0
- package/abstractCreateDemoClient/abstractCreateDemoClient.mjs +4 -0
- package/abstractCreateTypes/abstractCreateTypes.d.mts +12 -1
- package/abstractCreateTypes/abstractCreateTypes.mjs +4 -0
- package/abstractCreateTypes/typesToJsx.d.mts +8 -0
- package/abstractCreateTypes/typesToJsx.mjs +2 -1
- package/cli/loadNextConfig.d.mts +9 -0
- package/cli/loadNextConfig.mjs +11 -2
- package/cli/runValidate.mjs +15 -7
- package/cli/validateWorker.d.mts +1 -0
- package/cli/validateWorker.mjs +2 -1
- package/createDemoData/createDemoData.d.mts +1 -1
- package/package.json +34 -5
- package/pipeline/cacheUtils/constants.d.mts +5 -0
- package/pipeline/cacheUtils/constants.mjs +5 -0
- package/pipeline/cacheUtils/hashCacheContent.d.mts +5 -0
- package/pipeline/cacheUtils/hashCacheContent.mjs +9 -0
- package/pipeline/cacheUtils/index.d.mts +9 -0
- package/pipeline/cacheUtils/index.mjs +7 -0
- package/pipeline/cacheUtils/loadFileCache.d.mts +13 -0
- package/pipeline/cacheUtils/loadFileCache.mjs +20 -0
- package/pipeline/cacheUtils/loadFileCacheEntry.d.mts +13 -0
- package/pipeline/cacheUtils/loadFileCacheEntry.mjs +47 -0
- package/pipeline/cacheUtils/resolveCachePath.d.mts +16 -0
- package/pipeline/cacheUtils/resolveCachePath.mjs +24 -0
- package/pipeline/cacheUtils/saveFileCache.d.mts +17 -0
- package/pipeline/cacheUtils/saveFileCache.mjs +54 -0
- package/pipeline/cacheUtils/types.d.mts +23 -0
- package/pipeline/cacheUtils/types.mjs +1 -0
- package/pipeline/cacheUtils/withFileCache.d.mts +40 -0
- package/pipeline/cacheUtils/withFileCache.mjs +81 -0
- package/pipeline/hastUtils/hastUtils.d.mts +1 -1
- package/pipeline/hastUtils/hastUtils.mjs +0 -1
- package/pipeline/loadIsomorphicCodeSource/loadIsomorphicCodeSource.d.mts +1 -1
- package/pipeline/loadIsomorphicCodeSource/loadIsomorphicCodeSource.mjs +1 -1
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.mjs +0 -1
- package/pipeline/loadIsomorphicCodeVariant/diffHast.d.mts +1 -1
- package/pipeline/loadIsomorphicCodeVariant/hasAllCodeVariants.d.mts +1 -1
- package/pipeline/loadIsomorphicCodeVariant/maybeCodeInitialData.d.mts +1 -1
- package/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.d.mts +6 -0
- package/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.mjs +2 -1
- package/pipeline/loadPrecomputedTypes/loadPrecomputedTypes.d.mts +6 -0
- package/pipeline/loadPrecomputedTypes/loadPrecomputedTypes.mjs +5 -1
- package/pipeline/loadServerCodeMeta/resolveModulePathWithFs.d.mts +1 -1
- package/pipeline/loadServerCodeMeta/resolveModulePathWithFs.mjs +0 -1
- package/pipeline/loadServerPageIndex/enrichPageIndex.d.mts +15 -0
- package/pipeline/loadServerPageIndex/enrichPageIndex.mjs +50 -0
- package/pipeline/loadServerPageIndex/extractPrefixAndTitle.d.mts +19 -0
- package/pipeline/loadServerPageIndex/extractPrefixAndTitle.mjs +80 -0
- package/pipeline/loadServerPageIndex/index.d.mts +5 -2
- package/pipeline/loadServerPageIndex/index.mjs +4 -1
- package/pipeline/loadServerPageIndex/loadServerPageIndex.d.mts +13 -22
- package/pipeline/loadServerPageIndex/loadServerPageIndex.mjs +32 -124
- package/pipeline/loadServerPageIndex/resolvePageIndexCacheKey.d.mts +13 -0
- package/pipeline/loadServerPageIndex/resolvePageIndexCacheKey.mjs +23 -0
- package/pipeline/loadServerTypes/highlightTypes.d.mts +3 -3
- package/pipeline/loadServerTypes/highlightTypesMeta.d.mts +4 -4
- package/pipeline/loadServerTypes/loadServerTypes.d.mts +2 -2
- package/pipeline/loadServerTypes/loadServerTypes.mjs +67 -7
- package/pipeline/loadServerTypesMeta/createOptimizedProgram.d.mts +2 -1
- package/pipeline/loadServerTypesMeta/formatClass.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatComponent.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatFunction.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatHook.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatRaw.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/formatType.d.mts +1 -1
- package/pipeline/loadServerTypesMeta/loadServerTypesMeta.d.mts +7 -7
- package/pipeline/loadServerTypesMeta/loadServerTypesMeta.mjs +1 -1
- package/pipeline/loadServerTypesMeta/processTypes.d.mts +2 -2
- package/pipeline/loadServerTypesMeta/worker.d.mts +1 -1
- package/pipeline/loadServerTypesText/loadServerTypesText.d.mts +16 -2
- package/pipeline/loadServerTypesText/loadServerTypesText.mjs +30 -8
- package/pipeline/loadServerTypesText/normalizeTypesSourceDataForCache.d.mts +2 -0
- package/pipeline/loadServerTypesText/normalizeTypesSourceDataForCache.mjs +144 -0
- package/pipeline/loadServerTypesText/resolveTypesCacheKey.d.mts +19 -0
- package/pipeline/loadServerTypesText/resolveTypesCacheKey.mjs +29 -0
- package/pipeline/loaderUtils/parseImportsAndComments.d.mts +5 -3
- package/pipeline/loaderUtils/parseImportsAndComments.mjs +284 -40
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.d.mts +2 -2
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.mjs +2 -3
- package/pipeline/parseSource/detectFileTypes.d.mts +16 -0
- package/pipeline/parseSource/detectFileTypes.mjs +44 -0
- package/pipeline/syncPageIndex/mergeMetadataMarkdown.d.mts +25 -1
- package/pipeline/syncPageIndex/mergeMetadataMarkdown.mjs +79 -49
- package/pipeline/syncPageIndex/metadataToMarkdown.d.mts +15 -1
- package/pipeline/syncPageIndex/metadataToMarkdown.mjs +32 -10
- package/pipeline/syncPageIndex/syncPageIndex.d.mts +12 -0
- package/pipeline/syncPageIndex/syncPageIndex.mjs +154 -40
- package/pipeline/syncTypes/generateTypesMarkdown.d.mts +2 -2
- package/pipeline/syncTypes/syncTypes.d.mts +7 -0
- package/pipeline/syncTypes/syncTypes.mjs +31 -1
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.mjs +1 -1
- package/pipeline/transformMarkdownCode/transformMarkdownCode.mjs +25 -15
- package/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.mjs +3 -0
- package/pipeline/transformMarkdownMetadata/types.d.mts +8 -1
- package/useCode/EditableEngine.d.mts +1 -1
- package/useCode/Pre.d.mts +9 -2
- package/useCode/Pre.mjs +4 -3
- package/useCode/TransformEngine.d.mts +1 -1
- package/useCode/useCode.d.mts +17 -1
- package/useCode/useCode.mjs +22 -1
- package/useCode/useCopyFunctionality.d.mts +2 -2
- package/useCode/useEditable.browser.mjs +0 -1
- package/useCode/useFileNavigation.d.mts +3 -0
- package/useCode/useFileNavigation.mjs +3 -1
- package/useCode/useSourceEditing.mjs +45 -10
- package/useCode/useSourceEnhancing.mjs +41 -9
- package/useCode/useTransformManagement.d.mts +2 -2
- package/useCode/useTransformManagement.mjs +19 -3
- package/useCode/useUIState.d.mts +4 -0
- package/useCode/useUIState.mjs +8 -1
- package/useCode/useVariantSelection.d.mts +1 -1
- package/useCoordinated/useCoordinated.d.mts +1 -1
- package/useCoordinated/useCoordinatedLocalStorage.d.mts +1 -1
- package/useCoordinated/useCoordinatedLocalStorage.mjs +0 -1
- package/useCoordinated/useCoordinatedPreference.d.mts +1 -1
- package/useCoordinated/useCoordinatedPreference.mjs +0 -1
- package/useCrossTabState/index.d.mts +2 -0
- package/useCrossTabState/index.mjs +2 -0
- package/useCrossTabState/useCrossTabMirror.d.mts +26 -0
- package/useCrossTabState/useCrossTabMirror.mjs +108 -0
- package/useCrossTabState/useCrossTabState.d.mts +21 -0
- package/useCrossTabState/useCrossTabState.mjs +31 -0
- package/useDemo/exportVariant.mjs +2 -4
- package/useDemo/exportVariantAsCra.d.mts +1 -1
- package/useDemo/exportVariantAsCra.mjs +0 -1
- package/useDemo/useDemo.d.mts +4 -1
- package/useDemo/useDemo.mjs +5 -0
- package/useDemoController/BuildEngine.d.mts +2 -0
- package/useDemoController/BuildEngine.mjs +10 -0
- package/useDemoController/DemoRunner.d.mts +34 -0
- package/useDemoController/DemoRunner.mjs +83 -0
- package/useDemoController/ErrorBoundary.d.mts +34 -0
- package/useDemoController/ErrorBoundary.mjs +49 -0
- package/useDemoController/Runner.d.mts +44 -0
- package/useDemoController/Runner.mjs +71 -0
- package/useDemoController/absolutizeImports.d.mts +13 -0
- package/useDemoController/absolutizeImports.mjs +73 -0
- package/useDemoController/buildScope.d.mts +48 -0
- package/useDemoController/buildScope.mjs +270 -0
- package/useDemoController/collectSources.d.mts +67 -0
- package/useDemoController/collectSources.mjs +92 -0
- package/useDemoController/compileCssModule.d.mts +64 -0
- package/useDemoController/compileCssModule.mjs +40 -0
- package/useDemoController/compileCssWithPostcss.d.mts +17 -0
- package/useDemoController/compileCssWithPostcss.mjs +89 -0
- package/useDemoController/compileModule.d.mts +14 -0
- package/useDemoController/compileModule.mjs +17 -0
- package/useDemoController/constants.d.mts +13 -0
- package/useDemoController/constants.mjs +13 -0
- package/useDemoController/createRequire.d.mts +10 -0
- package/useDemoController/createRequire.mjs +17 -0
- package/useDemoController/createTranspileWorkerClient.d.mts +27 -0
- package/useDemoController/createTranspileWorkerClient.mjs +139 -0
- package/useDemoController/cssModules.d.mts +47 -0
- package/useDemoController/currentBrowserTarget.d.mts +16 -0
- package/useDemoController/currentBrowserTarget.mjs +36 -0
- package/useDemoController/evalCode.d.mts +12 -0
- package/useDemoController/evalCode.mjs +35 -0
- package/useDemoController/generateCssModuleSource.d.mts +11 -0
- package/useDemoController/generateCssModuleSource.mjs +55 -0
- package/useDemoController/generateElement.d.mts +21 -0
- package/useDemoController/generateElement.mjs +26 -0
- package/useDemoController/hashString.d.mts +11 -0
- package/useDemoController/hashString.mjs +20 -0
- package/useDemoController/importCode.d.mts +11 -0
- package/useDemoController/importCode.mjs +15 -0
- package/useDemoController/index.d.mts +1 -0
- package/useDemoController/index.mjs +1 -0
- package/useDemoController/instantiateElement.d.mts +24 -0
- package/useDemoController/instantiateElement.mjs +57 -0
- package/useDemoController/instantiateModule.d.mts +17 -0
- package/useDemoController/instantiateModule.mjs +24 -0
- package/useDemoController/resolveCssImports.d.mts +27 -0
- package/useDemoController/resolveCssImports.mjs +79 -0
- package/useDemoController/transformCode.d.mts +14 -0
- package/useDemoController/transformCode.mjs +42 -0
- package/useDemoController/transpileClientSingleton.d.mts +10 -0
- package/useDemoController/transpileClientSingleton.mjs +83 -0
- package/useDemoController/transpileSource.d.mts +29 -0
- package/useDemoController/transpileSource.mjs +36 -0
- package/useDemoController/transpileWorker.d.mts +14 -0
- package/useDemoController/transpileWorker.mjs +41 -0
- package/useDemoController/types.d.mts +30 -0
- package/useDemoController/types.mjs +1 -0
- package/useDemoController/useDemoController.d.mts +54 -0
- package/useDemoController/useDemoController.mjs +186 -0
- package/useDemoController/useRunner.d.mts +53 -0
- package/useDemoController/useRunner.mjs +118 -0
- package/useDemoController/useVariantBuilds.d.mts +31 -0
- package/useDemoController/useVariantBuilds.mjs +188 -0
- package/useSearch/types.d.mts +1 -1
- package/useType/TypesDataProvider.d.mts +1 -1
- package/useType/TypesDataProvider.mjs +1 -2
- package/useType/useType.d.mts +1 -1
- package/useType/useTypeProp.d.mts +1 -1
- package/withDocsInfra/withDeploymentConfig.mjs +57 -0
- package/withDocsInfra/withDocsInfra.d.mts +14 -0
- package/withDocsInfra/withDocsInfra.mjs +25 -11
package/cli/runValidate.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { fileURLToPath } from 'url';
|
|
|
10
10
|
import { Worker } from 'node:worker_threads';
|
|
11
11
|
import { createPerformanceLogger, logPerformance, nameMark, performanceMeasure } from "../pipeline/loadPrecomputedCodeHighlighter/performanceLogger.mjs";
|
|
12
12
|
import { terminateWorkerManager } from "../pipeline/loadServerTypesMeta/workerManager.mjs";
|
|
13
|
+
import { DEFAULT_CACHE_DIR } from "../pipeline/cacheUtils/index.mjs";
|
|
13
14
|
import { extractDocsInfraOptionsFromNextConfig } from "./loadNextConfig.mjs";
|
|
14
15
|
import { ensureDemoClients } from "./ensureDemoClients.mjs";
|
|
15
16
|
import { ensureDemoPages } from "./ensureDemoPages.mjs";
|
|
@@ -89,10 +90,14 @@ const runValidate = {
|
|
|
89
90
|
descriptionReplacements,
|
|
90
91
|
useVisibleDescription = false,
|
|
91
92
|
socketDir: configSocketDir,
|
|
93
|
+
cacheDir: configCacheDir,
|
|
92
94
|
demoClientRequirements = [],
|
|
93
95
|
demoPageRequirements = []
|
|
94
96
|
} = await extractDocsInfraOptionsFromNextConfig(cwd);
|
|
95
97
|
const socketDir = configSocketDir ? path.resolve(cwd, configSocketDir) : undefined;
|
|
98
|
+
// Use the same page-index cache directory that the sitemap loader reads at build time.
|
|
99
|
+
// The index validation pass writes cache entries even when committed indexes are current.
|
|
100
|
+
const cacheDir = configCacheDir ?? DEFAULT_CACHE_DIR;
|
|
96
101
|
|
|
97
102
|
// If neither flag is set, run both. If one is set, run only that one.
|
|
98
103
|
const runIndexes = !typesOnly || indexesOnly;
|
|
@@ -189,8 +194,8 @@ const runValidate = {
|
|
|
189
194
|
try {
|
|
190
195
|
// === Validate page.mdx index files ===
|
|
191
196
|
if (runIndexes) {
|
|
192
|
-
const markerDir = '
|
|
193
|
-
const markerDirPath = path.
|
|
197
|
+
const markerDir = path.posix.join(cacheDir, 'index-updates');
|
|
198
|
+
const markerDirPath = path.resolve(cwd, markerDir);
|
|
194
199
|
try {
|
|
195
200
|
await rm(markerDirPath, {
|
|
196
201
|
recursive: true,
|
|
@@ -222,7 +227,8 @@ const runValidate = {
|
|
|
222
227
|
baseDir: cwd,
|
|
223
228
|
onlyUpdateIndexes: true,
|
|
224
229
|
markerDir,
|
|
225
|
-
useVisibleDescription
|
|
230
|
+
useVisibleDescription,
|
|
231
|
+
cacheDir
|
|
226
232
|
};
|
|
227
233
|
const indexResults = await Promise.all(pageMdxFiles.map(filePath => {
|
|
228
234
|
const taskId = taskIdCounter;
|
|
@@ -263,8 +269,8 @@ const runValidate = {
|
|
|
263
269
|
// === Validate types.ts files ===
|
|
264
270
|
if (runTypes) {
|
|
265
271
|
// Use same marker directory structure for index updates from types
|
|
266
|
-
const typesMarkerDir = '
|
|
267
|
-
const typesMarkerDirPath = path.
|
|
272
|
+
const typesMarkerDir = path.posix.join(cacheDir, 'types-index-updates');
|
|
273
|
+
const typesMarkerDirPath = path.resolve(cwd, typesMarkerDir);
|
|
268
274
|
try {
|
|
269
275
|
await rm(typesMarkerDirPath, {
|
|
270
276
|
recursive: true,
|
|
@@ -289,11 +295,13 @@ const runValidate = {
|
|
|
289
295
|
syncTypesOptions: {
|
|
290
296
|
updateParentIndex: {
|
|
291
297
|
baseDir: cwd,
|
|
292
|
-
markerDir: typesMarkerDir
|
|
298
|
+
markerDir: typesMarkerDir,
|
|
299
|
+
cacheDir
|
|
293
300
|
},
|
|
294
301
|
ordering,
|
|
295
302
|
descriptionReplacements,
|
|
296
|
-
socketDir
|
|
303
|
+
socketDir,
|
|
304
|
+
cacheDir
|
|
297
305
|
}
|
|
298
306
|
});
|
|
299
307
|
}));
|
package/cli/validateWorker.d.mts
CHANGED
package/cli/validateWorker.mjs
CHANGED
|
@@ -74,7 +74,8 @@ if (parentPort) {
|
|
|
74
74
|
updateParentIndex: excludeFromIndex ? undefined : task.syncTypesOptions.updateParentIndex,
|
|
75
75
|
ordering: task.syncTypesOptions.ordering,
|
|
76
76
|
descriptionReplacements: task.syncTypesOptions.descriptionReplacements,
|
|
77
|
-
socketDir: task.syncTypesOptions.socketDir
|
|
77
|
+
socketDir: task.syncTypesOptions.socketDir,
|
|
78
|
+
cacheDir: task.syncTypesOptions.cacheDir
|
|
78
79
|
});
|
|
79
80
|
parentPort.postMessage({
|
|
80
81
|
type: 'types',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { CreateDemoDataMeta, DemoData, DemoGlobalData, DemoGlobalProvider } from "./types.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Creates demo data for displaying code examples with syntax highlighting.
|
|
5
5
|
* A variant is a different implementation style of the same component.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-docs-infra",
|
|
3
|
-
"version": "0.12.1-canary.
|
|
3
|
+
"version": "0.12.1-canary.21",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "MUI Infra - internal documentation creation tools.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,24 +29,34 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/mui/mui-public/tree/master/packages/docs-infra",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@babel/runtime": "^7.29.
|
|
32
|
+
"@babel/runtime": "^7.29.7",
|
|
33
|
+
"@csstools/postcss-light-dark-function": "^3.0.1",
|
|
34
|
+
"@csstools/postcss-relative-color-syntax": "^4.0.5",
|
|
35
|
+
"@csstools/postcss-stepped-value-functions": "^5.0.3",
|
|
33
36
|
"@orama/orama": "^3.1.18",
|
|
34
37
|
"@orama/plugin-qps": "^3.1.18",
|
|
35
38
|
"@orama/stemmers": "^3.1.18",
|
|
36
39
|
"@orama/stopwords": "^3.1.18",
|
|
37
40
|
"@wooorm/starry-night": "^3.9.0",
|
|
41
|
+
"autoprefixer": "^10.5.0",
|
|
38
42
|
"chalk": "^5.6.2",
|
|
39
43
|
"clipboard-copy": "^4.0.1",
|
|
40
|
-
"es-toolkit": "^1.
|
|
44
|
+
"es-toolkit": "^1.49.0",
|
|
41
45
|
"fflate": "^0.8.2",
|
|
42
46
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
43
47
|
"hast-util-to-text": "^4.0.2",
|
|
48
|
+
"icss-utils": "^5.1.0",
|
|
44
49
|
"import-meta-resolve": "^4.2.0",
|
|
45
50
|
"jiti": "^2.7.0",
|
|
46
51
|
"jsondiffpatch": "^0.7.3",
|
|
47
52
|
"kebab-case": "^2.0.2",
|
|
48
53
|
"lz-string": "^1.5.0",
|
|
49
54
|
"path-module": "^0.1.2",
|
|
55
|
+
"postcss": "^8.5.15",
|
|
56
|
+
"postcss-modules-extract-imports": "^3.1.0",
|
|
57
|
+
"postcss-modules-local-by-default": "^4.2.0",
|
|
58
|
+
"postcss-modules-scope": "^3.2.1",
|
|
59
|
+
"postcss-modules-values": "^4.0.0",
|
|
50
60
|
"proper-lockfile": "^4.1.2",
|
|
51
61
|
"remark-gfm": "^4.0.1",
|
|
52
62
|
"remark-mdx": "^3.1.1",
|
|
@@ -58,7 +68,6 @@
|
|
|
58
68
|
"uint8-to-base64": "^0.2.1",
|
|
59
69
|
"unified": "^11.0.5",
|
|
60
70
|
"unist-util-visit": "^5.1.0",
|
|
61
|
-
"use-editable": "^2.3.3",
|
|
62
71
|
"vscode-oniguruma": "^2.0.1",
|
|
63
72
|
"yargs": "^18.0.0",
|
|
64
73
|
"zx": "^8.8.5"
|
|
@@ -331,6 +340,16 @@
|
|
|
331
340
|
"default": "./useCopier/index.mjs"
|
|
332
341
|
}
|
|
333
342
|
},
|
|
343
|
+
"./useCrossTabState": {
|
|
344
|
+
"import": {
|
|
345
|
+
"types": "./useCrossTabState/index.d.mts",
|
|
346
|
+
"default": "./useCrossTabState/index.mjs"
|
|
347
|
+
},
|
|
348
|
+
"default": {
|
|
349
|
+
"types": "./useCrossTabState/index.d.mts",
|
|
350
|
+
"default": "./useCrossTabState/index.mjs"
|
|
351
|
+
}
|
|
352
|
+
},
|
|
334
353
|
"./useDemo": {
|
|
335
354
|
"import": {
|
|
336
355
|
"types": "./useDemo/index.d.mts",
|
|
@@ -341,6 +360,16 @@
|
|
|
341
360
|
"default": "./useDemo/index.mjs"
|
|
342
361
|
}
|
|
343
362
|
},
|
|
363
|
+
"./useDemoController": {
|
|
364
|
+
"import": {
|
|
365
|
+
"types": "./useDemoController/index.d.mts",
|
|
366
|
+
"default": "./useDemoController/index.mjs"
|
|
367
|
+
},
|
|
368
|
+
"default": {
|
|
369
|
+
"types": "./useDemoController/index.d.mts",
|
|
370
|
+
"default": "./useDemoController/index.mjs"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
344
373
|
"./useErrors": {
|
|
345
374
|
"import": {
|
|
346
375
|
"types": "./useErrors/index.d.mts",
|
|
@@ -775,5 +804,5 @@
|
|
|
775
804
|
"bin": {
|
|
776
805
|
"docs-infra": "./cli/index.mjs"
|
|
777
806
|
},
|
|
778
|
-
"gitSha": "
|
|
807
|
+
"gitSha": "d7a721986aed46adb128a9b200b12729c7a55378"
|
|
779
808
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Computes the sha256 hex digest of cache source content. Used to validate that a
|
|
5
|
+
* cached value still matches the file it was derived from.
|
|
6
|
+
*/
|
|
7
|
+
export function hashCacheContent(content) {
|
|
8
|
+
return createHash('sha256').update(content).digest('hex');
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { hashCacheContent } from "./hashCacheContent.mjs";
|
|
2
|
+
export { loadFileCache } from "./loadFileCache.mjs";
|
|
3
|
+
export { loadFileCacheEntry } from "./loadFileCacheEntry.mjs";
|
|
4
|
+
export { saveFileCache } from "./saveFileCache.mjs";
|
|
5
|
+
export { resolveCachePath } from "./resolveCachePath.mjs";
|
|
6
|
+
export { withFileCache } from "./withFileCache.mjs";
|
|
7
|
+
export type { FileCacheTask } from "./withFileCache.mjs";
|
|
8
|
+
export { DEFAULT_CACHE_DIR } from "./constants.mjs";
|
|
9
|
+
export type { FileCacheRef, FileCacheEntry } from "./types.mjs";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { hashCacheContent } from "./hashCacheContent.mjs";
|
|
2
|
+
export { loadFileCache } from "./loadFileCache.mjs";
|
|
3
|
+
export { loadFileCacheEntry } from "./loadFileCacheEntry.mjs";
|
|
4
|
+
export { saveFileCache } from "./saveFileCache.mjs";
|
|
5
|
+
export { resolveCachePath } from "./resolveCachePath.mjs";
|
|
6
|
+
export { withFileCache } from "./withFileCache.mjs";
|
|
7
|
+
export { DEFAULT_CACHE_DIR } from "./constants.mjs";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FileCacheRef } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Reads a cache entry and returns its data only when the stored hash matches the
|
|
4
|
+
* current content.
|
|
5
|
+
*
|
|
6
|
+
* Best-effort by design: a missing file, an unreadable file, malformed JSON, or a
|
|
7
|
+
* hash mismatch all resolve to `null` (a cache miss) rather than throwing, so a
|
|
8
|
+
* stale or corrupt cache can never break a build — it is simply recomputed.
|
|
9
|
+
*
|
|
10
|
+
* To overlap the cache read with reading the source file, use {@link loadFileCacheEntry}
|
|
11
|
+
* directly and compare the hash yourself.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadFileCache<T>(ref: FileCacheRef, content: string): Promise<T | null>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { hashCacheContent } from "./hashCacheContent.mjs";
|
|
2
|
+
import { loadFileCacheEntry } from "./loadFileCacheEntry.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Reads a cache entry and returns its data only when the stored hash matches the
|
|
5
|
+
* current content.
|
|
6
|
+
*
|
|
7
|
+
* Best-effort by design: a missing file, an unreadable file, malformed JSON, or a
|
|
8
|
+
* hash mismatch all resolve to `null` (a cache miss) rather than throwing, so a
|
|
9
|
+
* stale or corrupt cache can never break a build — it is simply recomputed.
|
|
10
|
+
*
|
|
11
|
+
* To overlap the cache read with reading the source file, use {@link loadFileCacheEntry}
|
|
12
|
+
* directly and compare the hash yourself.
|
|
13
|
+
*/
|
|
14
|
+
export async function loadFileCache(ref, content) {
|
|
15
|
+
const entry = await loadFileCacheEntry(ref);
|
|
16
|
+
if (!entry || entry.hash !== hashCacheContent(content)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return entry.data;
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FileCacheEntry, FileCacheRef } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Reads and parses a cache entry without validating it against any content.
|
|
4
|
+
*
|
|
5
|
+
* Best-effort: a missing file, an unreadable file, malformed JSON, or a path-containment failure
|
|
6
|
+
* all resolve to `null` (a cache miss) rather than throwing — so a stale or corrupt cache never
|
|
7
|
+
* breaks a build. Use this to read the cache in parallel with the source file, then compare
|
|
8
|
+
* `entry.hash` against `hashCacheContent(content)` once both reads complete.
|
|
9
|
+
*
|
|
10
|
+
* A non-missing read failure (e.g. a permissions error silently disabling the cache) is logged
|
|
11
|
+
* under DEBUG rather than masquerading as a cold cache.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadFileCacheEntry<T>(ref: FileCacheRef): Promise<FileCacheEntry<T> | null>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolveCachePath } from "./resolveCachePath.mjs";
|
|
3
|
+
// Set DOCS_INFRA_CACHE_DEBUG=1 to surface non-missing read failures and corrupt entries.
|
|
4
|
+
const DEBUG = Boolean(process.env.DOCS_INFRA_CACHE_DEBUG);
|
|
5
|
+
function isFileCacheEntry(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && 'hash' in value && 'data' in value && typeof value.hash === 'string';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reads and parses a cache entry without validating it against any content.
|
|
11
|
+
*
|
|
12
|
+
* Best-effort: a missing file, an unreadable file, malformed JSON, or a path-containment failure
|
|
13
|
+
* all resolve to `null` (a cache miss) rather than throwing — so a stale or corrupt cache never
|
|
14
|
+
* breaks a build. Use this to read the cache in parallel with the source file, then compare
|
|
15
|
+
* `entry.hash` against `hashCacheContent(content)` once both reads complete.
|
|
16
|
+
*
|
|
17
|
+
* A non-missing read failure (e.g. a permissions error silently disabling the cache) is logged
|
|
18
|
+
* under DEBUG rather than masquerading as a cold cache.
|
|
19
|
+
*/
|
|
20
|
+
export async function loadFileCacheEntry(ref) {
|
|
21
|
+
let raw;
|
|
22
|
+
try {
|
|
23
|
+
raw = await readFile(resolveCachePath(ref), 'utf-8');
|
|
24
|
+
} catch (error) {
|
|
25
|
+
const isMissing = error instanceof Error && error.code === 'ENOENT';
|
|
26
|
+
if (DEBUG && !isMissing) {
|
|
27
|
+
console.warn(`[docs-infra cache] read failed for ${ref.namespace}/${ref.cacheKey}:`, error);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = JSON.parse(raw);
|
|
34
|
+
} catch {
|
|
35
|
+
if (DEBUG) {
|
|
36
|
+
console.warn(`[docs-infra cache] ignoring corrupt entry ${ref.namespace}/${ref.cacheKey}`);
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (!isFileCacheEntry(parsed)) {
|
|
41
|
+
if (DEBUG) {
|
|
42
|
+
console.warn(`[docs-infra cache] ignoring malformed entry ${ref.namespace}/${ref.cacheKey}`);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileCacheRef } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the absolute path of a cache entry: `{cacheDir}/{namespace}/{cacheKey}.json`.
|
|
4
|
+
*
|
|
5
|
+
* Relative `cacheDir` values resolve against the current working directory so that readers and
|
|
6
|
+
* writers running from the same project root agree on the location. `cacheKey` may contain `/`
|
|
7
|
+
* separators, which become nested directories.
|
|
8
|
+
*
|
|
9
|
+
* Fails fast if a `namespace`/`cacheKey` segment (e.g. a `..`) would escape the cache directory,
|
|
10
|
+
* so a malformed route can never read or write outside `{cacheDir}`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveCachePath({
|
|
13
|
+
cacheDir,
|
|
14
|
+
namespace,
|
|
15
|
+
cacheKey
|
|
16
|
+
}: FileCacheRef): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolve, sep } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the absolute path of a cache entry: `{cacheDir}/{namespace}/{cacheKey}.json`.
|
|
4
|
+
*
|
|
5
|
+
* Relative `cacheDir` values resolve against the current working directory so that readers and
|
|
6
|
+
* writers running from the same project root agree on the location. `cacheKey` may contain `/`
|
|
7
|
+
* separators, which become nested directories.
|
|
8
|
+
*
|
|
9
|
+
* Fails fast if a `namespace`/`cacheKey` segment (e.g. a `..`) would escape the cache directory,
|
|
10
|
+
* so a malformed route can never read or write outside `{cacheDir}`.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveCachePath({
|
|
13
|
+
cacheDir,
|
|
14
|
+
namespace,
|
|
15
|
+
cacheKey
|
|
16
|
+
}) {
|
|
17
|
+
const base = resolve(cacheDir);
|
|
18
|
+
const full = resolve(base, namespace, `${cacheKey}.json`);
|
|
19
|
+
const baseWithSep = base.endsWith(sep) ? base : `${base}${sep}`;
|
|
20
|
+
if (!full.startsWith(baseWithSep)) {
|
|
21
|
+
throw new Error(`Cache path for "${namespace}/${cacheKey}" escapes the cache directory "${cacheDir}".`);
|
|
22
|
+
}
|
|
23
|
+
return full;
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FileCacheEntry, FileCacheRef } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Writes a precomputed cache entry (`{ hash, data }`) atomically (temp file + rename) so a
|
|
4
|
+
* concurrent reader never observes a half-written file. Creates the cache directory tree as needed.
|
|
5
|
+
*
|
|
6
|
+
* Fails fast: any filesystem error propagates so a misconfigured cache directory surfaces loudly at
|
|
7
|
+
* build time. Callers that treat the write as best-effort (e.g. {@link withFileCache}) catch it.
|
|
8
|
+
*
|
|
9
|
+
* Use this (rather than {@link saveFileCache}) when the hash is already known, so the (possibly
|
|
10
|
+
* large) hash-input string does not have to be retained just to be re-hashed here.
|
|
11
|
+
*/
|
|
12
|
+
export declare function saveFileCacheEntry<T>(ref: FileCacheRef, entry: FileCacheEntry<T>): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Writes a cache entry as `{ hash: sha256(content), data }`. Convenience over
|
|
15
|
+
* {@link saveFileCacheEntry} for callers that hold the source `content` and want it hashed here.
|
|
16
|
+
*/
|
|
17
|
+
export declare function saveFileCache<T>(ref: FileCacheRef, content: string, data: T): Promise<void>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { threadId } from 'node:worker_threads';
|
|
4
|
+
import { hashCacheContent } from "./hashCacheContent.mjs";
|
|
5
|
+
import { resolveCachePath } from "./resolveCachePath.mjs";
|
|
6
|
+
let tempCounter = 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Writes a precomputed cache entry (`{ hash, data }`) atomically (temp file + rename) so a
|
|
10
|
+
* concurrent reader never observes a half-written file. Creates the cache directory tree as needed.
|
|
11
|
+
*
|
|
12
|
+
* Fails fast: any filesystem error propagates so a misconfigured cache directory surfaces loudly at
|
|
13
|
+
* build time. Callers that treat the write as best-effort (e.g. {@link withFileCache}) catch it.
|
|
14
|
+
*
|
|
15
|
+
* Use this (rather than {@link saveFileCache}) when the hash is already known, so the (possibly
|
|
16
|
+
* large) hash-input string does not have to be retained just to be re-hashed here.
|
|
17
|
+
*/
|
|
18
|
+
export async function saveFileCacheEntry(ref, entry) {
|
|
19
|
+
const cachePath = resolveCachePath(ref);
|
|
20
|
+
await mkdir(dirname(cachePath), {
|
|
21
|
+
recursive: true
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Write to a temp file then atomically rename over the target, so a torn write can never corrupt
|
|
25
|
+
// the cache file an in-flight reader is parsing. The temp name includes pid + threadId + a counter
|
|
26
|
+
// so two concurrent writers (including across worker_threads, which share a pid) never collide on
|
|
27
|
+
// it. The serialized string is transient.
|
|
28
|
+
tempCounter += 1;
|
|
29
|
+
const tempPath = `${cachePath}.${process.pid}.${threadId}.${tempCounter}.tmp`;
|
|
30
|
+
try {
|
|
31
|
+
await writeFile(tempPath, JSON.stringify(entry), 'utf-8');
|
|
32
|
+
await rename(tempPath, cachePath);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
try {
|
|
35
|
+
await rm(tempPath, {
|
|
36
|
+
force: true
|
|
37
|
+
});
|
|
38
|
+
} catch {
|
|
39
|
+
// Best-effort cleanup of the temp file; ignore.
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Writes a cache entry as `{ hash: sha256(content), data }`. Convenience over
|
|
47
|
+
* {@link saveFileCacheEntry} for callers that hold the source `content` and want it hashed here.
|
|
48
|
+
*/
|
|
49
|
+
export async function saveFileCache(ref, content, data) {
|
|
50
|
+
return saveFileCacheEntry(ref, {
|
|
51
|
+
hash: hashCacheContent(content),
|
|
52
|
+
data
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference to a single cache entry on disk.
|
|
3
|
+
*
|
|
4
|
+
* The entry is stored at `{cacheDir}/{namespace}/{cacheKey}.json`. `cacheKey` may
|
|
5
|
+
* contain `/` separators to nest entries (e.g. `utilities/parsing`).
|
|
6
|
+
*/
|
|
7
|
+
export interface FileCacheRef {
|
|
8
|
+
/** Root cache directory. Relative paths resolve against the current working directory. */
|
|
9
|
+
cacheDir: string;
|
|
10
|
+
/** Subdirectory grouping related entries (e.g. `pages-index`). */
|
|
11
|
+
namespace: string;
|
|
12
|
+
/** Entry key, used as the file name without extension. May contain `/` for nesting. */
|
|
13
|
+
cacheKey: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* On-disk shape of a cache entry: the validating content hash plus the cached value.
|
|
17
|
+
*/
|
|
18
|
+
export interface FileCacheEntry<T> {
|
|
19
|
+
/** sha256 hex digest of the source content the cached value was derived from. */
|
|
20
|
+
hash: string;
|
|
21
|
+
/** The cached value. */
|
|
22
|
+
data: T;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FileCacheRef } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* A read-through file cache task: fetch an origin, derive its validating content, and either
|
|
4
|
+
* return the cached result or compute a fresh one.
|
|
5
|
+
*/
|
|
6
|
+
export interface FileCacheTask<TOrigin, TData> {
|
|
7
|
+
/** The cache entry to use, or `undefined` to bypass the cache entirely. */
|
|
8
|
+
ref: FileCacheRef | undefined;
|
|
9
|
+
/** Fetches the origin (e.g. reads the source file). Runs concurrently with the cache read. */
|
|
10
|
+
readOrigin: () => Promise<TOrigin> | TOrigin;
|
|
11
|
+
/**
|
|
12
|
+
* Derives the string whose sha256 validates the cache from the origin — e.g. the file content,
|
|
13
|
+
* or the content combined with the options that affect the result. May differ from what the
|
|
14
|
+
* processor consumes.
|
|
15
|
+
*/
|
|
16
|
+
getCacheContent: (origin: TOrigin) => string;
|
|
17
|
+
/** Computes the result from the origin on a cache miss. */
|
|
18
|
+
processor: (origin: TOrigin) => Promise<TData> | TData;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Standardizes the read-through cache flow shared by the page-index and types caches:
|
|
22
|
+
*
|
|
23
|
+
* 1. Read the cache entry while fetching and hashing the origin, so the two reads overlap and the
|
|
24
|
+
* hash is ready before the cache read resolves.
|
|
25
|
+
* 2. On a hash match, return the cached data and skip the processor.
|
|
26
|
+
* 3. On a miss (or with no `ref`), run the processor and return its result.
|
|
27
|
+
*
|
|
28
|
+
* A rejection from `readOrigin`/`getCacheContent` surfaces to the caller; the in-flight cache read
|
|
29
|
+
* is abandoned safely because {@link loadFileCacheEntry} never rejects. Populating the cache is
|
|
30
|
+
* **best-effort** — a write failure (e.g. an unwritable cache dir) is swallowed (logged under
|
|
31
|
+
* DEBUG) and the freshly computed result is returned regardless, so a cache hiccup never fails the
|
|
32
|
+
* caller or drops its output. The explicit build/validate writers (syncPageIndex/syncTypes) call
|
|
33
|
+
* {@link saveFileCache} directly and stay fail-fast.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withFileCache<TOrigin, TData>({
|
|
36
|
+
ref,
|
|
37
|
+
readOrigin,
|
|
38
|
+
getCacheContent,
|
|
39
|
+
processor
|
|
40
|
+
}: FileCacheTask<TOrigin, TData>): Promise<TData>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { hashCacheContent } from "./hashCacheContent.mjs";
|
|
2
|
+
import { loadFileCacheEntry } from "./loadFileCacheEntry.mjs";
|
|
3
|
+
import { saveFileCacheEntry } from "./saveFileCache.mjs";
|
|
4
|
+
// Set DOCS_INFRA_CACHE_DEBUG=1 to log cache hit/miss and best-effort write failures.
|
|
5
|
+
const DEBUG = Boolean(process.env.DOCS_INFRA_CACHE_DEBUG);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A read-through file cache task: fetch an origin, derive its validating content, and either
|
|
9
|
+
* return the cached result or compute a fresh one.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Standardizes the read-through cache flow shared by the page-index and types caches:
|
|
14
|
+
*
|
|
15
|
+
* 1. Read the cache entry while fetching and hashing the origin, so the two reads overlap and the
|
|
16
|
+
* hash is ready before the cache read resolves.
|
|
17
|
+
* 2. On a hash match, return the cached data and skip the processor.
|
|
18
|
+
* 3. On a miss (or with no `ref`), run the processor and return its result.
|
|
19
|
+
*
|
|
20
|
+
* A rejection from `readOrigin`/`getCacheContent` surfaces to the caller; the in-flight cache read
|
|
21
|
+
* is abandoned safely because {@link loadFileCacheEntry} never rejects. Populating the cache is
|
|
22
|
+
* **best-effort** — a write failure (e.g. an unwritable cache dir) is swallowed (logged under
|
|
23
|
+
* DEBUG) and the freshly computed result is returned regardless, so a cache hiccup never fails the
|
|
24
|
+
* caller or drops its output. The explicit build/validate writers (syncPageIndex/syncTypes) call
|
|
25
|
+
* {@link saveFileCache} directly and stay fail-fast.
|
|
26
|
+
*/
|
|
27
|
+
export async function withFileCache({
|
|
28
|
+
ref,
|
|
29
|
+
readOrigin,
|
|
30
|
+
getCacheContent,
|
|
31
|
+
processor
|
|
32
|
+
}) {
|
|
33
|
+
if (!ref) {
|
|
34
|
+
return processor(await readOrigin());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Start the cache read so it overlaps fetching and hashing the origin.
|
|
38
|
+
const cacheEntryPromise = loadFileCacheEntry(ref);
|
|
39
|
+
const origin = await readOrigin();
|
|
40
|
+
// Hash the cache content without binding it to a variable: the hash-input string can be large
|
|
41
|
+
// (e.g. a multi-MB JSON of the loaded types), and it is only needed to compute the hash — so we
|
|
42
|
+
// let it be collected immediately rather than retaining it through the cache read, the processor,
|
|
43
|
+
// and the write. saveFileCacheEntry below reuses the hash, so the content is never needed again.
|
|
44
|
+
const contentHash = hashCacheContent(getCacheContent(origin));
|
|
45
|
+
let cacheEntry = await cacheEntryPromise;
|
|
46
|
+
if (cacheEntry && cacheEntry.hash === contentHash) {
|
|
47
|
+
if (DEBUG) {
|
|
48
|
+
console.warn(`[docs-infra cache] hit ${ref.namespace}/${ref.cacheKey}`);
|
|
49
|
+
}
|
|
50
|
+
return cacheEntry.data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Distinguish a stale (warm-but-mismatched) miss from a cold one — a perpetual writer/reader hash
|
|
54
|
+
// divergence surfaces here, and is exactly the failure DEBUG exists to make visible. Drop the
|
|
55
|
+
// stale entry before the processor runs so its (possibly multi-MB) data is not retained alongside
|
|
56
|
+
// the freshly computed result.
|
|
57
|
+
const wasStale = Boolean(cacheEntry);
|
|
58
|
+
cacheEntry = null;
|
|
59
|
+
if (DEBUG && wasStale) {
|
|
60
|
+
console.warn(`[docs-infra cache] stale ${ref.namespace}/${ref.cacheKey} (hash mismatch, recomputing)`);
|
|
61
|
+
}
|
|
62
|
+
const data = await processor(origin);
|
|
63
|
+
try {
|
|
64
|
+
await saveFileCacheEntry(ref, {
|
|
65
|
+
hash: contentHash,
|
|
66
|
+
data
|
|
67
|
+
});
|
|
68
|
+
if (DEBUG) {
|
|
69
|
+
console.warn(`[docs-infra cache] miss → wrote ${ref.namespace}/${ref.cacheKey}`);
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
// Best-effort: any save failure — IO, the resolveCachePath traversal guard, or a serialization
|
|
73
|
+
// error on non-JSON-safe data — is swallowed so a misconfigured cache can never drop a page or
|
|
74
|
+
// fail a build; the computed result is returned regardless. The fail-fast writers (syncPageIndex
|
|
75
|
+
// and syncTypes, via saveFileCache) surface these instead. DEBUG logs them here.
|
|
76
|
+
if (DEBUG) {
|
|
77
|
+
console.warn(`[docs-infra cache] write failed for ${ref.namespace}/${ref.cacheKey}:`, error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
2
|
import type { Nodes as HastNodes } from 'hast';
|
|
3
3
|
import type { Components } from 'hast-util-to-jsx-runtime';
|
|
4
|
-
import {
|
|
4
|
+
import type { FallbackNode } from "./fallbackFormat.mjs";
|
|
5
5
|
export declare function hastToJsx(hast: HastNodes, components?: Partial<Components>): React.ReactNode;
|
|
6
6
|
export declare function hastOrJsonToJsx(hastOrJson: HastNodes | {
|
|
7
7
|
hastJson: string;
|
|
@@ -3,7 +3,6 @@ import { toText } from 'hast-util-to-text';
|
|
|
3
3
|
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
4
4
|
import { decompressHast } from "./hastCompression.mjs";
|
|
5
5
|
import { fallbackToText } from "./fallbackFormat.mjs";
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* Resolve the DEFLATE dictionary text for a `hastCompressed` payload from a
|
|
9
8
|
* compact `fallback`. The loader compresses each file with its own fallback
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LoadSource } from "../../CodeHighlighter/types.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import type { StoreAtMode } from "../loaderUtils/processRelativeImports.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Imports record passed to {@link LoadIsomorphicCodeSourceOptions.resolveImports}.
|
|
5
5
|
*
|
|
@@ -50,7 +50,7 @@ export function createLoadIsomorphicCodeSource(options) {
|
|
|
50
50
|
externals,
|
|
51
51
|
comments,
|
|
52
52
|
code: processedCode
|
|
53
|
-
} =
|
|
53
|
+
} = parseImportsAndComments(source, url, {
|
|
54
54
|
removeCommentsWithPrefix,
|
|
55
55
|
notableCommentsPrefix
|
|
56
56
|
});
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import { decodeHastSource } from "./decodeHastSource.mjs";
|
|
11
11
|
import { frameFallbackFromSpans } from "../hastUtils/index.mjs";
|
|
12
12
|
import { applyCodeTransformWithComments as applyCodeTransformWithCommentsCore, applyCodeTransformsWithComments as applyCodeTransformsWithCommentsCore } from "./applyCodeTransformWithComments.mjs";
|
|
13
|
-
|
|
14
13
|
// The built-in hast helpers, bound once for callers that don't inject their own
|
|
15
14
|
// (the `loadIsomorphicCodeVariant` server/build pipeline, tests, etc.).
|
|
16
15
|
const builtinDeps = {
|