@mintlify/previewing 4.0.854 → 4.0.855
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/local-preview/listener/generate.js +2 -1
- package/dist/local-preview/listener/generatePagesWithImports.js +2 -1
- package/dist/local-preview/listener/getDocsState.d.ts +1 -1
- package/dist/local-preview/listener/getDocsState.js +3 -3
- package/dist/local-preview/listener/getSnippets.js +2 -1
- package/dist/local-preview/listener/importCache.js +4 -4
- package/dist/local-preview/listener/index.js +19 -13
- package/dist/local-preview/listener/update.d.ts +3 -3
- package/dist/local-preview/listener/update.js +6 -6
- package/dist/local-preview/listener/utils.d.ts +3 -1
- package/dist/local-preview/listener/utils.js +18 -2
- package/dist/logging-state.d.ts +5 -1
- package/dist/logging-state.js +22 -1
- package/dist/logs.js +4 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -2,6 +2,7 @@ import { categorizeFilePaths, createPage, generateDecoratedDocsNavigationFromPag
|
|
|
2
2
|
import { promises as _promises } from 'fs';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { CMD_EXEC_PATH } from '../../constants.js';
|
|
5
|
+
import { handleParseError } from './utils.js';
|
|
5
6
|
const { readFile } = _promises;
|
|
6
7
|
const createFilenamePageMetadataMap = async ({ contentDirectoryPath, contentFilenames, openApiFiles, asyncApiFiles, pagesAcc = {}, }) => {
|
|
7
8
|
const contentPromises = [];
|
|
@@ -9,7 +10,7 @@ const createFilenamePageMetadataMap = async ({ contentDirectoryPath, contentFile
|
|
|
9
10
|
contentPromises.push((async () => {
|
|
10
11
|
const sourcePath = join(contentDirectoryPath, filename);
|
|
11
12
|
const contentStr = (await readFile(sourcePath)).toString();
|
|
12
|
-
const { slug, pageMetadata } = await createPage(filename, contentStr, contentDirectoryPath, openApiFiles, asyncApiFiles,
|
|
13
|
+
const { slug, pageMetadata } = await createPage(filename, contentStr, contentDirectoryPath, openApiFiles, asyncApiFiles, handleParseError);
|
|
13
14
|
pagesAcc = {
|
|
14
15
|
...pagesAcc,
|
|
15
16
|
[slug]: pageMetadata,
|
|
@@ -6,6 +6,7 @@ import { join } from 'path';
|
|
|
6
6
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH } from '../../constants.js';
|
|
7
7
|
import { getProcessedSnippets } from './getSnippets.js';
|
|
8
8
|
import { getImportedFilesFromCache } from './importCache.js';
|
|
9
|
+
import { handleParseError } from './utils.js';
|
|
9
10
|
const { readFile } = _promises;
|
|
10
11
|
export const generatePagesWithImports = async (updatedSnippets) => {
|
|
11
12
|
const snippets = await getProcessedSnippets();
|
|
@@ -21,7 +22,7 @@ export const generatePagesWithImports = async (updatedSnippets) => {
|
|
|
21
22
|
const sourcePath = join(CMD_EXEC_PATH, pageFilename);
|
|
22
23
|
const contentStr = (await readFile(sourcePath)).toString();
|
|
23
24
|
try {
|
|
24
|
-
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, sourcePath);
|
|
25
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, sourcePath, handleParseError);
|
|
25
26
|
const importsResponse = await findAndRemoveImports(tree);
|
|
26
27
|
if (Object.keys(importsResponse.importMap).some((importPath) => {
|
|
27
28
|
const resolvedPath = resolveImportPath(importPath, pageFilename);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DecoratedNavigationPage, MintConfig, OpenApiFile } from '@mintlify/models';
|
|
2
2
|
import { DocsConfig } from '@mintlify/validation';
|
|
3
|
-
export declare const getDocsState: () => Promise<{
|
|
3
|
+
export declare const getDocsState: (onError?: (message: string) => void) => Promise<{
|
|
4
4
|
mintConfig?: MintConfig;
|
|
5
5
|
pagesAcc: Record<string, DecoratedNavigationPage>;
|
|
6
6
|
openApiFiles: OpenApiFile[];
|
|
@@ -3,11 +3,11 @@ import { upgradeToDocsConfig } from '@mintlify/validation';
|
|
|
3
3
|
import fse from 'fs-extra';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { CMD_EXEC_PATH, CLIENT_PATH } from '../../constants.js';
|
|
6
|
-
export const getDocsState = async () => {
|
|
6
|
+
export const getDocsState = async (onError) => {
|
|
7
7
|
const mintIgnore = await getMintIgnore(CMD_EXEC_PATH);
|
|
8
8
|
const { openApiFiles } = await categorizeFilePaths(CMD_EXEC_PATH, mintIgnore);
|
|
9
9
|
try {
|
|
10
|
-
const mintConfig = await MintConfigUpdater.getConfig(join(CMD_EXEC_PATH, 'mint.json'));
|
|
10
|
+
const mintConfig = await MintConfigUpdater.getConfig(join(CMD_EXEC_PATH, 'mint.json'), onError);
|
|
11
11
|
const docsConfig = upgradeToDocsConfig(mintConfig);
|
|
12
12
|
const { mintConfig: newMintConfig } = await generateOpenApiAnchorsOrTabs(mintConfig, openApiFiles, CLIENT_PATH);
|
|
13
13
|
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } = await generateOpenApiDivisions(docsConfig, openApiFiles, CLIENT_PATH);
|
|
@@ -22,7 +22,7 @@ export const getDocsState = async () => {
|
|
|
22
22
|
const docsJsonPath = join(CMD_EXEC_PATH, 'docs.json');
|
|
23
23
|
if (!(await fse.pathExists(docsJsonPath)))
|
|
24
24
|
throw new Error('No config found');
|
|
25
|
-
const docsConfig = await DocsConfigUpdater.getConfig(docsJsonPath);
|
|
25
|
+
const docsConfig = await DocsConfigUpdater.getConfig(docsJsonPath, onError);
|
|
26
26
|
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } = await generateOpenApiDivisions(docsConfig, openApiFiles, CLIENT_PATH);
|
|
27
27
|
return { pagesAcc, openApiFiles: newOpenApiFiles, docsConfig: newDocsConfig };
|
|
28
28
|
}
|
|
@@ -4,6 +4,7 @@ import { promises as _promises } from 'fs';
|
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { CMD_EXEC_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
6
6
|
import { getImportedFilesFromCache } from './importCache.js';
|
|
7
|
+
import { handleParseError } from './utils.js';
|
|
7
8
|
const { readFile } = _promises;
|
|
8
9
|
const getSnippetBase = async (baseDir) => {
|
|
9
10
|
const importedFiles = getImportedFilesFromCache();
|
|
@@ -21,7 +22,7 @@ const getSnippetBase = async (baseDir) => {
|
|
|
21
22
|
});
|
|
22
23
|
const promises = allSnippetFilenames.map(async (snippetFilename) => {
|
|
23
24
|
try {
|
|
24
|
-
const tree = await preparseMdxTree((await readFile(join(baseDir, snippetFilename))).toString(), baseDir, join(baseDir, snippetFilename));
|
|
25
|
+
const tree = await preparseMdxTree((await readFile(join(baseDir, snippetFilename))).toString(), baseDir, join(baseDir, snippetFilename), handleParseError);
|
|
25
26
|
return {
|
|
26
27
|
filename: optionallyAddLeadingSlash(snippetFilename),
|
|
27
28
|
tree,
|
|
@@ -5,7 +5,7 @@ import fse from 'fs-extra';
|
|
|
5
5
|
import { join } from 'path';
|
|
6
6
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
7
7
|
import { resolveAllImports } from './resolveAllImports.js';
|
|
8
|
-
import { normalizePathForComparison } from './utils.js';
|
|
8
|
+
import { handleParseError, normalizePathForComparison, suppressParseError } from './utils.js';
|
|
9
9
|
const fileImportsMap = new Map();
|
|
10
10
|
const importerCounts = new Map();
|
|
11
11
|
const addImporter = (path) => {
|
|
@@ -28,7 +28,7 @@ const extractFileImports = async (baseDir, filename) => {
|
|
|
28
28
|
const filePath = join(baseDir, filename);
|
|
29
29
|
try {
|
|
30
30
|
const content = (await fse.readFile(filePath)).toString();
|
|
31
|
-
const tree = await preparseMdxTree(content, baseDir, filePath);
|
|
31
|
+
const tree = await preparseMdxTree(content, baseDir, filePath, suppressParseError);
|
|
32
32
|
const importSources = extractImportSources(tree);
|
|
33
33
|
const imports = new Set();
|
|
34
34
|
for (const source of importSources) {
|
|
@@ -115,7 +115,7 @@ const isSnippetByFolder = (path) => {
|
|
|
115
115
|
};
|
|
116
116
|
const resolveFileImports = async (sourcePath, relativePath) => {
|
|
117
117
|
let contentStr = (await fse.readFile(sourcePath)).toString();
|
|
118
|
-
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, sourcePath);
|
|
118
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, sourcePath, handleParseError);
|
|
119
119
|
const importsResponse = await findAndRemoveImports(tree);
|
|
120
120
|
if (hasImports(importsResponse)) {
|
|
121
121
|
contentStr = stringifyTree(await resolveAllImports({ ...importsResponse, filename: relativePath }));
|
|
@@ -155,7 +155,7 @@ export const syncImportedFileLocations = async (changes) => {
|
|
|
155
155
|
if (await fse.pathExists(sourcePath)) {
|
|
156
156
|
try {
|
|
157
157
|
const contentStr = await resolveFileImports(sourcePath, relativePath);
|
|
158
|
-
const { pageContent } = await createPage(relativePath, contentStr, CMD_EXEC_PATH, [], [],
|
|
158
|
+
const { pageContent } = await createPage(relativePath, contentStr, CMD_EXEC_PATH, [], [], suppressParseError);
|
|
159
159
|
await fse.outputFile(join(NEXT_PROPS_PATH, relativePath), pageContent, { flag: 'w' });
|
|
160
160
|
}
|
|
161
161
|
catch (err) {
|
|
@@ -9,7 +9,7 @@ import fs from 'fs/promises';
|
|
|
9
9
|
import yaml from 'js-yaml';
|
|
10
10
|
import pathUtil from 'path';
|
|
11
11
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH, CLIENT_PATH } from '../../constants.js';
|
|
12
|
-
import { addChangeLog } from '../../logging-state.js';
|
|
12
|
+
import { addChangeLog, addErrorLog, clearErrorLogs, getCurrentErrorLogs, } from '../../logging-state.js';
|
|
13
13
|
import { AddedLog, DeletedLog, EditedLog, WarningLog, InfoLog, ErrorLog } from '../../logs.js';
|
|
14
14
|
import { generateDependentSnippets } from './generateDependentSnippets.js';
|
|
15
15
|
import { generatePagesWithImports } from './generatePagesWithImports.js';
|
|
@@ -17,7 +17,7 @@ import { getDocsState } from './getDocsState.js';
|
|
|
17
17
|
import { initializeImportCache, updateImportCacheForFile, removeFromImportCache, getImportedFilesFromCache, syncImportedFileLocations, } from './importCache.js';
|
|
18
18
|
import { resolveAllImports } from './resolveAllImports.js';
|
|
19
19
|
import { updateCustomLanguages, updateGeneratedNav, updateOpenApiFiles, upsertOpenApiFile, } from './update.js';
|
|
20
|
-
import { getMintIgnoreGlobs, isFileSizeValid, isJsonValid, shouldRegenerateNavForPage, } from './utils.js';
|
|
20
|
+
import { getMintIgnoreGlobs, handleParseError, isFileSizeValid, isJsonValid, shouldRegenerateNavForPage, suppressParseError, } from './utils.js';
|
|
21
21
|
const { readFile } = _promises;
|
|
22
22
|
const frontmatterHashes = new Map();
|
|
23
23
|
const listener = (callback, options = {}) => {
|
|
@@ -168,6 +168,7 @@ const validateConfigFiles = async () => {
|
|
|
168
168
|
* @returns FileCategory
|
|
169
169
|
*/
|
|
170
170
|
const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
171
|
+
clearErrorLogs();
|
|
171
172
|
const filePath = pathUtil.join(CMD_EXEC_PATH, filename);
|
|
172
173
|
const importChanges = await updateImportCacheForFile(CMD_EXEC_PATH, filename);
|
|
173
174
|
await syncImportedFileLocations(importChanges);
|
|
@@ -186,14 +187,13 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
|
186
187
|
switch (potentialCategory) {
|
|
187
188
|
case 'page': {
|
|
188
189
|
let contentStr = (await readFile(filePath)).toString();
|
|
189
|
-
regenerateNav = await shouldRegenerateNavForPage(filename, contentStr, frontmatterHashes);
|
|
190
|
-
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, filePath);
|
|
190
|
+
regenerateNav = await shouldRegenerateNavForPage(filename, contentStr, frontmatterHashes, handleParseError);
|
|
191
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, filePath, suppressParseError);
|
|
191
192
|
const importsResponse = await findAndRemoveImports(tree);
|
|
192
193
|
if (hasImports(importsResponse)) {
|
|
193
194
|
contentStr = stringifyTree(await resolveAllImports({ ...importsResponse, filename }));
|
|
194
195
|
}
|
|
195
|
-
|
|
196
|
-
const { pageContent } = await createPage(filename, contentStr, CMD_EXEC_PATH, [], [], true);
|
|
196
|
+
const { pageContent } = await createPage(filename, contentStr, CMD_EXEC_PATH, [], [], handleParseError);
|
|
197
197
|
await fse.outputFile(targetPath, pageContent, {
|
|
198
198
|
flag: 'w',
|
|
199
199
|
});
|
|
@@ -205,7 +205,7 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
|
205
205
|
}
|
|
206
206
|
case 'snippet-v2': {
|
|
207
207
|
let contentStr = (await readFile(filePath)).toString();
|
|
208
|
-
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, filePath);
|
|
208
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, filePath, handleParseError);
|
|
209
209
|
const importsResponse = await findAndRemoveImports(tree);
|
|
210
210
|
if (hasImports(importsResponse)) {
|
|
211
211
|
contentStr = stringifyTree(await resolveAllImports({ ...importsResponse, filename }));
|
|
@@ -221,21 +221,27 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
|
221
221
|
case 'docsConfig': {
|
|
222
222
|
const { valid, error } = isJsonValid(filePath);
|
|
223
223
|
if (!valid) {
|
|
224
|
-
|
|
224
|
+
addErrorLog(_jsx(ErrorLog, { message: `Syntax error in ${filename}: ${error}` }));
|
|
225
225
|
return null;
|
|
226
226
|
}
|
|
227
227
|
regenerateNav = true;
|
|
228
228
|
try {
|
|
229
|
-
const { mintConfig, openApiFiles, docsConfig } = await getDocsState();
|
|
229
|
+
const { mintConfig, openApiFiles, docsConfig } = await getDocsState(handleParseError);
|
|
230
230
|
if (mintConfig) {
|
|
231
231
|
await MintConfigUpdater.writeConfigFile(mintConfig, CLIENT_PATH);
|
|
232
232
|
}
|
|
233
233
|
await DocsConfigUpdater.writeConfigFile(docsConfig, CLIENT_PATH);
|
|
234
|
-
await updateOpenApiFiles(openApiFiles);
|
|
235
|
-
await updateCustomLanguages(docsConfig);
|
|
234
|
+
await updateOpenApiFiles(openApiFiles, suppressParseError);
|
|
235
|
+
await updateCustomLanguages(docsConfig, suppressParseError);
|
|
236
236
|
}
|
|
237
237
|
catch (err) {
|
|
238
|
-
|
|
238
|
+
if (getCurrentErrorLogs().length > 0) {
|
|
239
|
+
// no-op to suppress duplicate error logging
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
console.error(err);
|
|
244
|
+
}
|
|
239
245
|
}
|
|
240
246
|
break;
|
|
241
247
|
}
|
|
@@ -305,7 +311,7 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
|
305
311
|
}
|
|
306
312
|
if (regenerateNav) {
|
|
307
313
|
// TODO: Instead of re-generating the entire nav, optimize by just updating the specific page that changed.
|
|
308
|
-
await updateGeneratedNav();
|
|
314
|
+
await updateGeneratedNav(suppressParseError);
|
|
309
315
|
}
|
|
310
316
|
callback();
|
|
311
317
|
return category;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenApiFile } from '@mintlify/models';
|
|
2
2
|
import { DocsConfig } from '@mintlify/validation';
|
|
3
|
-
export declare const updateGeneratedNav: () => Promise<void>;
|
|
4
|
-
export declare const updateOpenApiFiles: (providedOpenApiFiles?: OpenApiFile[]) => Promise<void>;
|
|
3
|
+
export declare const updateGeneratedNav: (onError?: (message: string) => void) => Promise<void>;
|
|
4
|
+
export declare const updateOpenApiFiles: (providedOpenApiFiles?: OpenApiFile[], onError?: (message: string) => void) => Promise<void>;
|
|
5
5
|
export declare const upsertOpenApiFile: (openApiFile: OpenApiFile) => Promise<void>;
|
|
6
|
-
export declare const updateCustomLanguages: (docsConfig?: DocsConfig) => Promise<void>;
|
|
6
|
+
export declare const updateCustomLanguages: (docsConfig?: DocsConfig, onError?: (message: string) => void) => Promise<void>;
|
|
@@ -5,17 +5,17 @@ import { CMD_EXEC_PATH, NEXT_PROPS_PATH } from '../../constants.js';
|
|
|
5
5
|
import { generateNav } from './generate.js';
|
|
6
6
|
import { getDocsState } from './getDocsState.js';
|
|
7
7
|
import { readJsonFile } from './utils.js';
|
|
8
|
-
export const updateGeneratedNav = async () => {
|
|
9
|
-
const { pagesAcc, docsConfig } = await getDocsState();
|
|
8
|
+
export const updateGeneratedNav = async (onError) => {
|
|
9
|
+
const { pagesAcc, docsConfig } = await getDocsState(onError);
|
|
10
10
|
const generatedDocsNav = await generateNav(pagesAcc, docsConfig);
|
|
11
11
|
const targetDocsPath = join(NEXT_PROPS_PATH, 'generatedDocsNav.json');
|
|
12
12
|
await fse.outputFile(targetDocsPath, JSON.stringify(generatedDocsNav, null, 2), {
|
|
13
13
|
flag: 'w',
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
-
export const updateOpenApiFiles = async (providedOpenApiFiles) => {
|
|
16
|
+
export const updateOpenApiFiles = async (providedOpenApiFiles, onError) => {
|
|
17
17
|
if (providedOpenApiFiles == undefined) {
|
|
18
|
-
const { openApiFiles } = await getDocsState();
|
|
18
|
+
const { openApiFiles } = await getDocsState(onError);
|
|
19
19
|
providedOpenApiFiles = openApiFiles;
|
|
20
20
|
}
|
|
21
21
|
const targetPath = join(NEXT_PROPS_PATH, 'openApiFiles.json');
|
|
@@ -41,9 +41,9 @@ export const upsertOpenApiFile = async (openApiFile) => {
|
|
|
41
41
|
flag: 'w',
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
export const updateCustomLanguages = async (docsConfig) => {
|
|
44
|
+
export const updateCustomLanguages = async (docsConfig, onError) => {
|
|
45
45
|
if (docsConfig == undefined) {
|
|
46
|
-
docsConfig = (await getDocsState()).docsConfig;
|
|
46
|
+
docsConfig = (await getDocsState(onError)).docsConfig;
|
|
47
47
|
}
|
|
48
48
|
const customLanguages = await getCustomLanguages({
|
|
49
49
|
config: docsConfig,
|
|
@@ -7,5 +7,7 @@ export declare const isJsonValid: (filePath: string) => {
|
|
|
7
7
|
valid: boolean;
|
|
8
8
|
error?: string;
|
|
9
9
|
};
|
|
10
|
-
export declare const shouldRegenerateNavForPage: (filename: string, contentStr: string, frontmatterHashes: Map<string, string
|
|
10
|
+
export declare const shouldRegenerateNavForPage: (filename: string, contentStr: string, frontmatterHashes: Map<string, string>, onError?: (message: string) => void) => Promise<boolean>;
|
|
11
11
|
export declare function normalizePathForComparison(filePath: string): string;
|
|
12
|
+
export declare const handleParseError: (message: string) => void;
|
|
13
|
+
export declare const suppressParseError: () => void;
|
|
@@ -4,6 +4,7 @@ import { promises as _promises, readFileSync, existsSync } from 'fs';
|
|
|
4
4
|
import fse from 'fs-extra';
|
|
5
5
|
import pathUtil from 'path';
|
|
6
6
|
import { CMD_EXEC_PATH } from '../../constants.js';
|
|
7
|
+
import { addRawErrorLog } from '../../logging-state.js';
|
|
7
8
|
const { stat } = _promises;
|
|
8
9
|
export const getFileExtension = (filename) => {
|
|
9
10
|
return filename.substring(filename.lastIndexOf('.') + 1, filename.length) || filename;
|
|
@@ -41,7 +42,7 @@ export const isJsonValid = (filePath) => {
|
|
|
41
42
|
return { valid: false, error: error.message };
|
|
42
43
|
}
|
|
43
44
|
};
|
|
44
|
-
export const shouldRegenerateNavForPage = async (filename, contentStr, frontmatterHashes) => {
|
|
45
|
+
export const shouldRegenerateNavForPage = async (filename, contentStr, frontmatterHashes, onError) => {
|
|
45
46
|
try {
|
|
46
47
|
const { attributes: currentFrontmatter } = parseFrontmatter(contentStr);
|
|
47
48
|
const prevFrontmatterHash = frontmatterHashes.get(filename);
|
|
@@ -61,10 +62,25 @@ export const shouldRegenerateNavForPage = async (filename, contentStr, frontmatt
|
|
|
61
62
|
return false;
|
|
62
63
|
}
|
|
63
64
|
catch (error) {
|
|
64
|
-
|
|
65
|
+
const message = `Error parsing frontmatter for ${filename}, regenerating nav: ${error instanceof Error ? error.message : String(error)}`;
|
|
66
|
+
if (onError) {
|
|
67
|
+
onError(message);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
console.warn(message);
|
|
71
|
+
}
|
|
65
72
|
return true;
|
|
66
73
|
}
|
|
67
74
|
};
|
|
68
75
|
export function normalizePathForComparison(filePath) {
|
|
69
76
|
return optionallyAddLeadingSlash(filePath).toLowerCase();
|
|
70
77
|
}
|
|
78
|
+
export const handleParseError = (message) => {
|
|
79
|
+
const trimmed = message.trim();
|
|
80
|
+
if (trimmed) {
|
|
81
|
+
addRawErrorLog(trimmed);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export const suppressParseError = () => {
|
|
85
|
+
// no-op to suppress duplicate error logging
|
|
86
|
+
};
|
package/dist/logging-state.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare const setLoggingCallbacks: (setLogs: (logs: React.ReactNode[]) => void, setChangeLogs: (logs: React.ReactNode[]) => void) => void;
|
|
2
|
+
export declare const setLoggingCallbacks: (setLogs: (logs: React.ReactNode[]) => void, setChangeLogs: (logs: React.ReactNode[]) => void, setErrorLogs: (logs: React.ReactNode[]) => void) => void;
|
|
3
3
|
export declare const addLog: (log: React.ReactNode) => void;
|
|
4
4
|
export declare const addLogs: (...logs: React.ReactNode[]) => void;
|
|
5
5
|
export declare const addChangeLog: (log: React.ReactNode) => void;
|
|
6
|
+
export declare const addErrorLog: (log: React.ReactNode) => void;
|
|
7
|
+
export declare const addRawErrorLog: (message: string) => void;
|
|
8
|
+
export declare const clearErrorLogs: () => void;
|
|
6
9
|
export declare const clearLogs: () => void;
|
|
7
10
|
export declare const removeLastLog: () => void;
|
|
11
|
+
export declare const getCurrentErrorLogs: () => React.ReactNode[];
|
package/dist/logging-state.js
CHANGED
|
@@ -3,16 +3,19 @@ import React from 'react';
|
|
|
3
3
|
import { Logs } from './logs.js';
|
|
4
4
|
let currentLogs = [];
|
|
5
5
|
let currentChangeLogs = [];
|
|
6
|
+
let currentErrorLogs = [];
|
|
6
7
|
let setLogsCallback = null;
|
|
7
8
|
let setChangeLogsCallback = null;
|
|
9
|
+
let setErrorLogsCallback = null;
|
|
8
10
|
const ensureLoggingInstance = () => {
|
|
9
11
|
if (!setLogsCallback) {
|
|
10
12
|
render(React.createElement(Logs));
|
|
11
13
|
}
|
|
12
14
|
};
|
|
13
|
-
export const setLoggingCallbacks = (setLogs, setChangeLogs) => {
|
|
15
|
+
export const setLoggingCallbacks = (setLogs, setChangeLogs, setErrorLogs) => {
|
|
14
16
|
setLogsCallback = setLogs;
|
|
15
17
|
setChangeLogsCallback = setChangeLogs;
|
|
18
|
+
setErrorLogsCallback = setErrorLogs;
|
|
16
19
|
};
|
|
17
20
|
export const addLog = (log) => {
|
|
18
21
|
ensureLoggingInstance();
|
|
@@ -29,6 +32,21 @@ export const addChangeLog = (log) => {
|
|
|
29
32
|
currentChangeLogs = [...currentChangeLogs, log];
|
|
30
33
|
setChangeLogsCallback?.(currentChangeLogs);
|
|
31
34
|
};
|
|
35
|
+
export const addErrorLog = (log) => {
|
|
36
|
+
ensureLoggingInstance();
|
|
37
|
+
currentErrorLogs = [...currentErrorLogs, log];
|
|
38
|
+
setErrorLogsCallback?.(currentErrorLogs);
|
|
39
|
+
};
|
|
40
|
+
export const addRawErrorLog = (message) => {
|
|
41
|
+
ensureLoggingInstance();
|
|
42
|
+
currentErrorLogs = [...currentErrorLogs, message];
|
|
43
|
+
setErrorLogsCallback?.(currentErrorLogs);
|
|
44
|
+
};
|
|
45
|
+
export const clearErrorLogs = () => {
|
|
46
|
+
ensureLoggingInstance();
|
|
47
|
+
currentErrorLogs = [];
|
|
48
|
+
setErrorLogsCallback?.(currentErrorLogs);
|
|
49
|
+
};
|
|
32
50
|
export const clearLogs = () => {
|
|
33
51
|
ensureLoggingInstance();
|
|
34
52
|
currentLogs = [];
|
|
@@ -39,3 +57,6 @@ export const removeLastLog = () => {
|
|
|
39
57
|
currentLogs = currentLogs.slice(0, -1);
|
|
40
58
|
setLogsCallback?.(currentLogs);
|
|
41
59
|
};
|
|
60
|
+
export const getCurrentErrorLogs = () => {
|
|
61
|
+
return currentErrorLogs;
|
|
62
|
+
};
|
package/dist/logs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
3
|
import Spinner from 'ink-spinner';
|
|
4
4
|
import { useState, useEffect } from 'react';
|
|
@@ -93,8 +93,9 @@ export const RenamedLog = ({ before, after }) => {
|
|
|
93
93
|
export const Logs = () => {
|
|
94
94
|
const [logs, setLogs] = useState([]);
|
|
95
95
|
const [changeLogs, setChangeLogs] = useState([]);
|
|
96
|
+
const [errorLogs, setErrorLogs] = useState([]);
|
|
96
97
|
useEffect(() => {
|
|
97
|
-
setLoggingCallbacks(setLogs, setChangeLogs);
|
|
98
|
+
setLoggingCallbacks(setLogs, setChangeLogs, setErrorLogs);
|
|
98
99
|
}, []);
|
|
99
|
-
return (_jsxs(
|
|
100
|
+
return (_jsxs(Box, { flexDirection: "column", children: [logs.map((log, idx) => (_jsx(Box, { children: log }, idx))), changeLogs.length > 0 && (_jsxs(Box, { flexDirection: "column", alignItems: "flex-start", children: [_jsxs(Text, { children: [_jsx(Text, { dimColor: true, bold: true, children: "\u00B1" }), ' ', _jsx(Text, { children: "changes" })] }), changeLogs.map((log, idx) => (_jsx(Box, { children: log }, `change-${idx}`)))] })), errorLogs.length > 0 && (_jsxs(Box, { flexDirection: "column", alignItems: "flex-start", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { dimColor: true, bold: true, children: "!" }), ' ', _jsx(Text, { color: "red", bold: true, children: "errors" })] }), errorLogs.map((log, idx) => (_jsx(Box, { children: typeof log === 'string' ? _jsx(Text, { children: log }) : log }, `error-${idx}`)))] }))] }));
|
|
100
101
|
};
|