@mintlify/previewing 4.0.1461 → 4.0.1463
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/dist/__tests__/listener-graphql-packages.test.d.ts +1 -0
- package/dist/__tests__/listener-graphql-packages.test.js +68 -0
- package/dist/__tests__/listener-package-manifest.test.d.ts +1 -0
- package/dist/__tests__/listener-package-manifest.test.js +103 -0
- package/dist/__tests__/packages-builder.test.d.ts +1 -0
- package/dist/__tests__/packages-builder.test.js +88 -0
- package/dist/__tests__/packages-collect.test.d.ts +1 -0
- package/dist/__tests__/packages-collect.test.js +387 -0
- package/dist/__tests__/packages-dev-snippets.test.d.ts +1 -0
- package/dist/__tests__/packages-dev-snippets.test.js +457 -0
- package/dist/__tests__/packages-dev.test.d.ts +1 -0
- package/dist/__tests__/packages-dev.test.js +1304 -0
- package/dist/__tests__/packages-flag.test.d.ts +1 -0
- package/dist/__tests__/packages-flag.test.js +146 -0
- package/dist/__tests__/packages-imports.test.d.ts +1 -0
- package/dist/__tests__/packages-imports.test.js +68 -0
- package/dist/__tests__/packages-island-errors.test.d.ts +1 -0
- package/dist/__tests__/packages-island-errors.test.js +128 -0
- package/dist/__tests__/packages-serve.test.d.ts +1 -0
- package/dist/__tests__/packages-serve.test.js +73 -0
- package/dist/__tests__/packages-setup.test.d.ts +1 -0
- package/dist/__tests__/packages-setup.test.js +160 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/local-preview/index.js +6 -0
- package/dist/local-preview/listener/index.d.ts +1 -0
- package/dist/local-preview/listener/index.js +10 -1
- package/dist/local-preview/listener/regenerateAllSnippets.js +2 -0
- package/dist/local-preview/listener/resolve-imports-from-import-closure.js +3 -0
- package/dist/local-preview/listener/resolveAllImports.js +2 -0
- package/dist/local-preview/packages/dev.d.ts +88 -0
- package/dist/local-preview/packages/dev.js +478 -0
- package/dist/local-preview/packages/index.d.ts +8 -0
- package/dist/local-preview/packages/index.js +89 -0
- package/dist/local-preview/packages/serve.d.ts +8 -0
- package/dist/local-preview/packages/serve.js +41 -0
- package/dist/local-preview/packages/state.d.ts +6 -0
- package/dist/local-preview/packages/state.js +6 -0
- package/dist/local-preview/run.js +8 -0
- package/dist/logging-state.d.ts +1 -0
- package/dist/logging-state.js +5 -0
- package/dist/packages/builder.d.ts +6 -0
- package/dist/packages/builder.js +17 -0
- package/dist/packages/collect.d.ts +61 -0
- package/dist/packages/collect.js +240 -0
- package/dist/packages/errno.d.ts +1 -0
- package/dist/packages/errno.js +3 -0
- package/dist/packages/flag.d.ts +1 -0
- package/dist/packages/flag.js +1 -0
- package/dist/packages/index.d.ts +3 -0
- package/dist/packages/index.js +3 -0
- package/dist/packages/setup.d.ts +18 -0
- package/dist/packages/setup.js +81 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { parsePackageJsonDependencies } from '@mintlify/common';
|
|
2
|
+
import { getConfigObj } from '@mintlify/prebuild';
|
|
3
|
+
import { packagesSchema } from '@mintlify/validation';
|
|
4
|
+
import { readFile } from 'fs/promises';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { errnoCode } from './errno.js';
|
|
7
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
|
+
export class DocsJsonError extends Error {
|
|
9
|
+
constructor(problems) {
|
|
10
|
+
super(problems.join('\n'));
|
|
11
|
+
this.problems = problems;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class InvalidPackagesError extends DocsJsonError {
|
|
15
|
+
constructor(problems, variables) {
|
|
16
|
+
super(problems);
|
|
17
|
+
this.variables = variables;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
21
|
+
const readText = async (path) => {
|
|
22
|
+
try {
|
|
23
|
+
return { content: await readFile(path, 'utf8') };
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (errnoCode(error) === 'ENOENT')
|
|
27
|
+
return {};
|
|
28
|
+
return { error: `could not be read: ${messageOf(error)}` };
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const normalizeProviderPath = (provider) => `/${provider.replace(/\\/g, '/').replace(/^\/+/, '')}`;
|
|
32
|
+
const readVariables = (value) => {
|
|
33
|
+
if (!isRecord(value))
|
|
34
|
+
return undefined;
|
|
35
|
+
const variables = {};
|
|
36
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
37
|
+
if (typeof entry === 'string')
|
|
38
|
+
variables[key] = entry;
|
|
39
|
+
}
|
|
40
|
+
return variables;
|
|
41
|
+
};
|
|
42
|
+
export const readPackagesSetup = async (docsRoot) => {
|
|
43
|
+
let docsConfig;
|
|
44
|
+
try {
|
|
45
|
+
docsConfig = await getConfigObj(docsRoot, 'docs');
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new DocsJsonError([`docs.json could not be loaded: ${messageOf(error)}`]);
|
|
49
|
+
}
|
|
50
|
+
if (docsConfig === null)
|
|
51
|
+
return undefined;
|
|
52
|
+
if (!isRecord(docsConfig))
|
|
53
|
+
throw new DocsJsonError(['docs.json is not a JSON object']);
|
|
54
|
+
if (!('packages' in docsConfig))
|
|
55
|
+
return undefined;
|
|
56
|
+
const parsed = packagesSchema.safeParse(docsConfig.packages);
|
|
57
|
+
if (!parsed.success) {
|
|
58
|
+
throw new InvalidPackagesError(parsed.error.issues.map((issue) => `docs.json ${['packages', ...issue.path].join('.')}: ${issue.message}`), readVariables(docsConfig.variables));
|
|
59
|
+
}
|
|
60
|
+
const packages = parsed.data;
|
|
61
|
+
if (packages.provider !== undefined)
|
|
62
|
+
packages.provider = normalizeProviderPath(packages.provider);
|
|
63
|
+
const errors = [];
|
|
64
|
+
const packageJson = await readText(join(docsRoot, 'package.json'));
|
|
65
|
+
const dependencies = packageJson.content === undefined
|
|
66
|
+
? undefined
|
|
67
|
+
: parsePackageJsonDependencies(packageJson.content);
|
|
68
|
+
const problem = packageJson.error ?? dependencies?.error;
|
|
69
|
+
const packageJsonError = problem && `package.json ${problem}`;
|
|
70
|
+
if (packageJsonError)
|
|
71
|
+
errors.push(packageJsonError);
|
|
72
|
+
else if (!dependencies)
|
|
73
|
+
errors.push('docs.json sets "packages" but there is no package.json next to it.');
|
|
74
|
+
return {
|
|
75
|
+
packages,
|
|
76
|
+
packageNames: dependencies?.error ? new Set() : (dependencies?.packageNames ?? new Set()),
|
|
77
|
+
variables: readVariables(docsConfig.variables),
|
|
78
|
+
errors,
|
|
79
|
+
...(packageJsonError && { packageJsonError }),
|
|
80
|
+
};
|
|
81
|
+
};
|