@vendure-io/docs-provider 0.8.2 → 0.9.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.
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/types.d.ts +49 -0
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/validate-admonitions.d.ts +59 -0
- package/dist/testing/validate-admonitions.d.ts.map +1 -0
- package/dist/testing.cjs +7 -4
- package/dist/testing.js +161 -103
- package/package.json +1 -1
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MdxCompilationResult, MdxTestReport } from './types';
|
|
2
|
-
export type { CompileMdxOptions, MdxCompilationResult, MdxTestReport, TestManifestOptions, } from './types';
|
|
2
|
+
export type { AdmonitionError, AdmonitionValidationReport, CompileMdxOptions, MdxCompilationResult, MdxTestReport, TestManifestOptions, ValidateAdmonitionsOptions, } from './types';
|
|
3
3
|
export { compileMdx, getDefaultRehypePlugins, getDefaultRemarkPlugins } from './mdx-compiler';
|
|
4
4
|
export { testManifestMdx } from './test-manifest';
|
|
5
|
+
export { ADMONITION_TYPES, formatAdmonitionReport, INVALID_ADMONITION_PATTERN, validateAdmonitions, } from './validate-admonitions';
|
|
5
6
|
/**
|
|
6
7
|
* Format a test report for console output.
|
|
7
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGlE,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAGlE,YAAY,EACV,eAAe,EACf,0BAA0B,EAC1B,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAC7F,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,wBAAwB,CAAA;AAE/B;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,UAAQ,GAAG,MAAM,CAgE/E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,IAAI,CACxC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,oBAAoB,KACzB,IAAI,CAcR"}
|
package/dist/testing/types.d.ts
CHANGED
|
@@ -73,4 +73,53 @@ export interface CompileMdxOptions {
|
|
|
73
73
|
*/
|
|
74
74
|
rehypePlugins?: PluggableList;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Error found during admonition syntax validation
|
|
78
|
+
*/
|
|
79
|
+
export interface AdmonitionError {
|
|
80
|
+
/** Relative path to the file from the manifest basePath */
|
|
81
|
+
file: string;
|
|
82
|
+
/** Absolute path to the file */
|
|
83
|
+
absolutePath: string;
|
|
84
|
+
/** Line number where the error was found (1-indexed) */
|
|
85
|
+
line: number;
|
|
86
|
+
/** Column number where the error was found (1-indexed) */
|
|
87
|
+
column: number;
|
|
88
|
+
/** The full content of the line containing the error */
|
|
89
|
+
content: string;
|
|
90
|
+
/** The type of admonition (warning, info, tip, etc.) */
|
|
91
|
+
admonitionType: string;
|
|
92
|
+
/** The label that was incorrectly space-separated */
|
|
93
|
+
label: string;
|
|
94
|
+
/** Suggested fix using bracket syntax */
|
|
95
|
+
suggestion: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Report from validating admonition syntax in a manifest
|
|
99
|
+
*/
|
|
100
|
+
export interface AdmonitionValidationReport {
|
|
101
|
+
/** Package ID from the manifest */
|
|
102
|
+
packageId: string;
|
|
103
|
+
/** Number of files that were scanned */
|
|
104
|
+
filesScanned: number;
|
|
105
|
+
/** List of validation errors found */
|
|
106
|
+
errors: AdmonitionError[];
|
|
107
|
+
/** Total time taken for validation in milliseconds */
|
|
108
|
+
totalTime: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Options for validating admonition syntax
|
|
112
|
+
*/
|
|
113
|
+
export interface ValidateAdmonitionsOptions {
|
|
114
|
+
/**
|
|
115
|
+
* Stop on first error.
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
failFast?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Callback invoked for each error found.
|
|
121
|
+
* Useful for real-time reporting.
|
|
122
|
+
*/
|
|
123
|
+
onError?: (error: AdmonitionError) => void;
|
|
124
|
+
}
|
|
76
125
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/testing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAA;IAChB,yCAAyC;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,eAAe,EAAE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;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,sCAAsC;IACtC,MAAM,EAAE,eAAe,EAAE,CAAA;IACzB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;CAC3C"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DocsPackageManifest } from '../types';
|
|
2
|
+
import { AdmonitionValidationReport, ValidateAdmonitionsOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Supported admonition types in remark-directive
|
|
5
|
+
*/
|
|
6
|
+
export declare const ADMONITION_TYPES: readonly ["warning", "info", "tip", "note", "caution", "danger"];
|
|
7
|
+
/**
|
|
8
|
+
* Pattern that matches invalid admonition syntax with space-separated labels.
|
|
9
|
+
*
|
|
10
|
+
* Valid: :::warning[Deprecated]
|
|
11
|
+
* Invalid: :::warning Deprecated
|
|
12
|
+
*
|
|
13
|
+
* This pattern captures:
|
|
14
|
+
* - Group 1: The admonition type (warning, info, tip, etc.)
|
|
15
|
+
* - Group 2: The label text (everything after the space until end of line)
|
|
16
|
+
*/
|
|
17
|
+
export declare const INVALID_ADMONITION_PATTERN: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* Validate admonition syntax in all MDX files of a manifest.
|
|
20
|
+
*
|
|
21
|
+
* The remark-directive v4 plugin requires square bracket syntax for labels:
|
|
22
|
+
* - Valid: `:::warning[Deprecated]`
|
|
23
|
+
* - Invalid: `:::warning Deprecated`
|
|
24
|
+
*
|
|
25
|
+
* This function scans all MDX files in the manifest and reports any
|
|
26
|
+
* admonitions using the invalid space-separated label syntax.
|
|
27
|
+
*
|
|
28
|
+
* @param manifest - The documentation package manifest to validate
|
|
29
|
+
* @param options - Optional configuration for validation
|
|
30
|
+
* @returns A report containing all validation errors
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { manifest } from '../src/manifest'
|
|
35
|
+
* import { validateAdmonitions, formatAdmonitionReport } from '@vendure-io/docs-provider/testing'
|
|
36
|
+
*
|
|
37
|
+
* const report = validateAdmonitions(manifest)
|
|
38
|
+
*
|
|
39
|
+
* if (report.errors.length > 0) {
|
|
40
|
+
* console.error(formatAdmonitionReport(report))
|
|
41
|
+
* process.exit(1)
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateAdmonitions(manifest: DocsPackageManifest, options?: ValidateAdmonitionsOptions): AdmonitionValidationReport;
|
|
46
|
+
/**
|
|
47
|
+
* Format an admonition validation report for console output.
|
|
48
|
+
*
|
|
49
|
+
* @param report - The validation report to format
|
|
50
|
+
* @returns A formatted string suitable for console output
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const report = validateAdmonitions(manifest)
|
|
55
|
+
* console.log(formatAdmonitionReport(report))
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function formatAdmonitionReport(report: AdmonitionValidationReport): string;
|
|
59
|
+
//# sourceMappingURL=validate-admonitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-admonitions.d.ts","sourceRoot":"","sources":["../../src/testing/validate-admonitions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnD,OAAO,KAAK,EAAmB,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEtG;;GAEG;AACH,eAAO,MAAM,gBAAgB,kEAAmE,CAAA;AAEhG;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,QAEtC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,mBAAmB,EAC7B,OAAO,CAAC,EAAE,0BAA0B,GACnC,0BAA0B,CAuD5B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,0BAA0B,GAAG,MAAM,CAsCjF"}
|
package/dist/testing.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
${
|
|
3
|
-
`)
|
|
4
|
-
`)}}
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@mdx-js/mdx"),F=require("rehype-slug"),x=require("remark-directive"),D=require("remark-gfm"),g=require("unist-util-visit"),E=require("fs/promises"),P=require("./manifest-BkO3d77g.cjs"),R=require("node:fs"),M=require("node:path"),$={info:"info",note:"note",tip:"tip",warning:"warning",caution:"caution",danger:"danger"},N={info:"Info",note:"Note",tip:"Tip",warning:"Warning",caution:"Caution",danger:"Danger"},S=()=>s=>{g.visit(s,"containerDirective",e=>{var c;const t=e.name.toLowerCase();if(!(t in $))return;const i=$[t];let r;if(e.children.length>0){const l=e.children[0];if(l.type==="paragraph"&&"data"in l&&((c=l.data)==null?void 0:c.directiveLabel)===!0){const u=[];for(const o of l.children)o.type==="text"&&u.push(o.value);u.length>0&&(r=u.join("")),e.children=e.children.slice(1)}}const n=r||N[t],a=e.data||(e.data={});a.hName="Callout",a.hProperties={type:i,title:n}})};function b(){return s=>{g.visit(s,"code",e=>{if(!e.meta)return;const t=e.meta.match(/(?:title|filename)=["']([^"']+)["']/);if(!t)return;const i=t[1];e.value.trim().startsWith("// filename:")||(e.value=`// filename: ${i}
|
|
2
|
+
${e.value}`)})}}const _=()=>s=>{const e=[];g.visit(s,"html",(t,i,r)=>{i!==void 0&&r&&typeof t.value=="string"&&t.value.trim().startsWith("<!--")&&t.value.trim().endsWith("-->")&&e.push(i)});for(const t of e.reverse())s.children.splice(t,1)},L=["@theme/Tabs","@theme/TabItem"],O=()=>s=>{const e=[];g.visit(s,"mdxjsEsm",t=>{const i=t.value;L.some(n=>i.includes(`from '${n}'`)||i.includes(`from "${n}"`))&&e.push(t)});for(const t of e){const i=s.children.indexOf(t);i!==-1&&s.children.splice(i,1)}};function v(){return[D,x,S,b,O,_]}function I(){return[F]}async function y(s,e,t){var a,c,l,u;const i=performance.now(),r=(t==null?void 0:t.remarkPlugins)??v(),n=(t==null?void 0:t.rehypePlugins)??I();try{return await A.compile(s,{remarkPlugins:r,rehypePlugins:n,outputFormat:"function-body",development:!1}),{filePath:e,success:!0,compilationTime:performance.now()-i}}catch(o){const f=performance.now()-i;let m="Unknown compilation error",h,p;if(o instanceof Error){m=o.message;const d=o;if(d.line!==void 0?h=d.line:((c=(a=d.position)==null?void 0:a.start)==null?void 0:c.line)!==void 0&&(h=d.position.start.line),d.column!==void 0?p=d.column:((u=(l=d.position)==null?void 0:l.start)==null?void 0:u.column)!==void 0&&(p=d.position.start.column),h===void 0){const T=m.match(/\((\d+):(\d+)\)/);T&&(h=parseInt(T[1],10),p=parseInt(T[2],10))}}return{filePath:e,success:!1,error:m,line:h,column:p,compilationTime:f}}}async function q(s,e){const t=performance.now(),i=P.getLeafNodes(s),r=[];let n=0,a=0;for(let c=0;c<i.length;c++){const l=i[c];if(!l.file)continue;const u=l.file;try{const o=await E.readFile(u,"utf-8"),f=await y(o,l.file,{remarkPlugins:e==null?void 0:e.remarkPlugins,rehypePlugins:e==null?void 0:e.rehypePlugins});if(r.push(f),f.success?n++:a++,e!=null&&e.onProgress&&e.onProgress(c+1,i.length,f),e!=null&&e.failFast&&!f.success)break}catch(o){const f=o instanceof Error?o.message:"Unknown error reading file",m={filePath:l.file,success:!1,error:`Failed to read file: ${f}`,compilationTime:0};if(r.push(m),a++,e!=null&&e.onProgress&&e.onProgress(c+1,i.length,m),e!=null&&e.failFast)break}}return{packageId:s.id,totalFiles:r.length,passed:n,failed:a,results:r,totalTime:performance.now()-t}}const k=["warning","info","tip","note","caution","danger"],w=new RegExp(`^:::(${k.join("|")}) ([A-Z].*)$`);function j(s,e){const t=performance.now(),i=[],r=P.getLeafNodes(s);let n=0;for(const a of r){if(!a.file)continue;n++;const l=R.readFileSync(a.file,"utf-8").split(`
|
|
3
|
+
`);for(let u=0;u<l.length;u++){const o=l[u],f=o.match(w);if(f){const[,m,h]=f,p={file:s.basePath?M.relative(s.basePath,a.file):a.file,absolutePath:a.file,line:u+1,column:1,content:o.trim(),admonitionType:m,label:h,suggestion:`:::${m}[${h}]`};if(i.push(p),e!=null&&e.onError&&e.onError(p),e!=null&&e.failFast&&i.length>0)return{packageId:s.id,filesScanned:n,errors:i,totalTime:performance.now()-t}}}}return{packageId:s.id,filesScanned:n,errors:i,totalTime:performance.now()-t}}function C(s){const e=[];if(e.push(""),e.push(`Admonition Syntax Report: ${s.packageId}`),e.push("=".repeat(50)),e.push(""),e.push(`Files scanned: ${s.filesScanned}`),e.push(`Errors found: ${s.errors.length}`),e.push(`Total time: ${s.totalTime.toFixed(2)}ms`),e.push(""),s.errors.length===0)return e.push("All admonitions use correct bracket syntax!"),e.push(""),e.join(`
|
|
4
|
+
`);e.push("Errors:"),e.push("-".repeat(50)),e.push("");for(const t of s.errors)e.push(` ${t.file}:${t.line}`),e.push(` ${t.content}`),e.push(` Fix: ${t.suggestion}`),e.push("");return e.push("Admonitions with custom titles must use bracket syntax:"),e.push(" Before: :::warning Deprecated"),e.push(" After: :::warning[Deprecated]"),e.push(""),e.push("See: https://github.com/remarkjs/remark-directive"),e.push(""),e.join(`
|
|
5
|
+
`)}function U(s,e=!1){const t=[];t.push(""),t.push(`MDX Compilation Report: ${s.packageId}`),t.push("=".repeat(50)),t.push("");const i=s.totalFiles>0?(s.passed/s.totalFiles*100).toFixed(1):"0";if(t.push(`Total files: ${s.totalFiles}`),t.push(`Passed: ${s.passed} (${i}%)`),t.push(`Failed: ${s.failed}`),t.push(`Total time: ${s.totalTime.toFixed(2)}ms`),t.push(""),e){t.push("Results:"),t.push("-".repeat(50));for(const r of s.results){const n=r.success?"[PASS]":"[FAIL]",a=`(${r.compilationTime.toFixed(2)}ms)`;if(t.push(`${n} ${r.filePath} ${a}`),!r.success&&r.error){const c=r.line?` (line ${r.line}${r.column?`:${r.column}`:""})`:"";t.push(` Error${c}: ${r.error}`)}}}else if(s.failed>0){t.push("Failures:"),t.push("-".repeat(50));for(const r of s.results.filter(n=>!n.success))if(t.push(`[FAIL] ${r.filePath}`),r.error){const n=r.line?` (line ${r.line}${r.column?`:${r.column}`:""})`:"";t.push(` Error${n}: ${r.error}`)}}return t.push(""),s.failed===0?t.push("All MDX files compiled successfully!"):t.push(`${s.failed} file(s) failed to compile.`),t.push(""),t.join(`
|
|
6
|
+
`)}function W(){return(s,e,t)=>{const i=t.success?"✓":"✗",r=(s/e*100).toFixed(0);process.stdout.write(`\r[${s}/${e}] (${r}%) ${i} ${t.filePath}`),process.stdout.write("\x1B[K"),s===e&&process.stdout.write(`
|
|
7
|
+
`)}}exports.ADMONITION_TYPES=k;exports.INVALID_ADMONITION_PATTERN=w;exports.compileMdx=y;exports.createProgressReporter=W;exports.formatAdmonitionReport=C;exports.formatTestReport=U;exports.getDefaultRehypePlugins=I;exports.getDefaultRemarkPlugins=v;exports.testManifestMdx=q;exports.validateAdmonitions=j;
|
package/dist/testing.js
CHANGED
|
@@ -1,98 +1,100 @@
|
|
|
1
|
-
import { compile as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { compile as v } from "@mdx-js/mdx";
|
|
2
|
+
import w from "rehype-slug";
|
|
3
|
+
import k from "remark-directive";
|
|
4
|
+
import y from "remark-gfm";
|
|
5
5
|
import { visit as g } from "unist-util-visit";
|
|
6
|
-
import { readFile as
|
|
7
|
-
import { h as
|
|
8
|
-
|
|
6
|
+
import { readFile as F } from "fs/promises";
|
|
7
|
+
import { h as P } from "./manifest-DlSWyjsA.js";
|
|
8
|
+
import { readFileSync as I } from "node:fs";
|
|
9
|
+
import { relative as x } from "node:path";
|
|
10
|
+
const T = {
|
|
9
11
|
info: "info",
|
|
10
12
|
note: "note",
|
|
11
13
|
tip: "tip",
|
|
12
14
|
warning: "warning",
|
|
13
15
|
caution: "caution",
|
|
14
16
|
danger: "danger"
|
|
15
|
-
},
|
|
17
|
+
}, E = {
|
|
16
18
|
info: "Info",
|
|
17
19
|
note: "Note",
|
|
18
20
|
tip: "Tip",
|
|
19
21
|
warning: "Warning",
|
|
20
22
|
caution: "Caution",
|
|
21
23
|
danger: "Danger"
|
|
22
|
-
},
|
|
23
|
-
g(r, "containerDirective", (
|
|
24
|
-
var
|
|
25
|
-
const
|
|
26
|
-
if (!(
|
|
24
|
+
}, A = () => (r) => {
|
|
25
|
+
g(r, "containerDirective", (e) => {
|
|
26
|
+
var o;
|
|
27
|
+
const t = e.name.toLowerCase();
|
|
28
|
+
if (!(t in T))
|
|
27
29
|
return;
|
|
28
|
-
const i =
|
|
30
|
+
const i = T[t];
|
|
29
31
|
let s;
|
|
30
|
-
if (
|
|
31
|
-
const l =
|
|
32
|
-
if (l.type === "paragraph" && "data" in l && ((
|
|
32
|
+
if (e.children.length > 0) {
|
|
33
|
+
const l = e.children[0];
|
|
34
|
+
if (l.type === "paragraph" && "data" in l && ((o = l.data) == null ? void 0 : o.directiveLabel) === !0) {
|
|
33
35
|
const u = [];
|
|
34
|
-
for (const
|
|
35
|
-
|
|
36
|
-
u.length > 0 && (s = u.join("")),
|
|
36
|
+
for (const c of l.children)
|
|
37
|
+
c.type === "text" && u.push(c.value);
|
|
38
|
+
u.length > 0 && (s = u.join("")), e.children = e.children.slice(1);
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
|
-
const n = s ||
|
|
40
|
-
|
|
41
|
+
const n = s || E[t], a = e.data || (e.data = {});
|
|
42
|
+
a.hName = "Callout", a.hProperties = {
|
|
41
43
|
type: i,
|
|
42
44
|
title: n
|
|
43
45
|
};
|
|
44
46
|
});
|
|
45
47
|
};
|
|
46
|
-
function
|
|
48
|
+
function D() {
|
|
47
49
|
return (r) => {
|
|
48
|
-
g(r, "code", (
|
|
49
|
-
if (!
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
const i =
|
|
53
|
-
|
|
54
|
-
${
|
|
50
|
+
g(r, "code", (e) => {
|
|
51
|
+
if (!e.meta) return;
|
|
52
|
+
const t = e.meta.match(/(?:title|filename)=["']([^"']+)["']/);
|
|
53
|
+
if (!t) return;
|
|
54
|
+
const i = t[1];
|
|
55
|
+
e.value.trim().startsWith("// filename:") || (e.value = `// filename: ${i}
|
|
56
|
+
${e.value}`);
|
|
55
57
|
});
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
g(r, "html", (
|
|
61
|
-
i !== void 0 && s && typeof
|
|
60
|
+
const S = () => (r) => {
|
|
61
|
+
const e = [];
|
|
62
|
+
g(r, "html", (t, i, s) => {
|
|
63
|
+
i !== void 0 && s && typeof t.value == "string" && t.value.trim().startsWith("<!--") && t.value.trim().endsWith("-->") && e.push(i);
|
|
62
64
|
});
|
|
63
|
-
for (const
|
|
64
|
-
r.children.splice(
|
|
65
|
-
},
|
|
66
|
-
const
|
|
67
|
-
g(r, "mdxjsEsm", (
|
|
68
|
-
const i =
|
|
69
|
-
|
|
65
|
+
for (const t of e.reverse())
|
|
66
|
+
r.children.splice(t, 1);
|
|
67
|
+
}, R = ["@theme/Tabs", "@theme/TabItem"], b = () => (r) => {
|
|
68
|
+
const e = [];
|
|
69
|
+
g(r, "mdxjsEsm", (t) => {
|
|
70
|
+
const i = t.value;
|
|
71
|
+
R.some(
|
|
70
72
|
(n) => i.includes(`from '${n}'`) || i.includes(`from "${n}"`)
|
|
71
|
-
) &&
|
|
73
|
+
) && e.push(t);
|
|
72
74
|
});
|
|
73
|
-
for (const
|
|
74
|
-
const i = r.children.indexOf(
|
|
75
|
+
for (const t of e) {
|
|
76
|
+
const i = r.children.indexOf(t);
|
|
75
77
|
i !== -1 && r.children.splice(i, 1);
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
|
-
function
|
|
80
|
+
function M() {
|
|
79
81
|
return [
|
|
82
|
+
y,
|
|
80
83
|
k,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
M
|
|
84
|
+
A,
|
|
85
|
+
D,
|
|
86
|
+
b,
|
|
87
|
+
S
|
|
86
88
|
];
|
|
87
89
|
}
|
|
88
|
-
function
|
|
89
|
-
return [
|
|
90
|
+
function N() {
|
|
91
|
+
return [w];
|
|
90
92
|
}
|
|
91
|
-
async function L(r,
|
|
92
|
-
var
|
|
93
|
-
const i = performance.now(), s = (
|
|
93
|
+
async function L(r, e, t) {
|
|
94
|
+
var a, o, l, u;
|
|
95
|
+
const i = performance.now(), s = (t == null ? void 0 : t.remarkPlugins) ?? M(), n = (t == null ? void 0 : t.rehypePlugins) ?? N();
|
|
94
96
|
try {
|
|
95
|
-
return await
|
|
97
|
+
return await v(r, {
|
|
96
98
|
remarkPlugins: s,
|
|
97
99
|
rehypePlugins: n,
|
|
98
100
|
// Don't output to JS, just compile to check for errors
|
|
@@ -100,54 +102,54 @@ async function L(r, t, e) {
|
|
|
100
102
|
// Suppress development warnings about missing 'development' option
|
|
101
103
|
development: !1
|
|
102
104
|
}), {
|
|
103
|
-
filePath:
|
|
105
|
+
filePath: e,
|
|
104
106
|
success: !0,
|
|
105
107
|
compilationTime: performance.now() - i
|
|
106
108
|
};
|
|
107
|
-
} catch (
|
|
109
|
+
} catch (c) {
|
|
108
110
|
const f = performance.now() - i;
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
const $ =
|
|
115
|
-
$ && (
|
|
111
|
+
let m = "Unknown compilation error", h, p;
|
|
112
|
+
if (c instanceof Error) {
|
|
113
|
+
m = c.message;
|
|
114
|
+
const d = c;
|
|
115
|
+
if (d.line !== void 0 ? h = d.line : ((o = (a = d.position) == null ? void 0 : a.start) == null ? void 0 : o.line) !== void 0 && (h = d.position.start.line), d.column !== void 0 ? p = d.column : ((u = (l = d.position) == null ? void 0 : l.start) == null ? void 0 : u.column) !== void 0 && (p = d.position.start.column), h === void 0) {
|
|
116
|
+
const $ = m.match(/\((\d+):(\d+)\)/);
|
|
117
|
+
$ && (h = parseInt($[1], 10), p = parseInt($[2], 10));
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
return {
|
|
119
|
-
filePath:
|
|
121
|
+
filePath: e,
|
|
120
122
|
success: !1,
|
|
121
|
-
error:
|
|
122
|
-
line:
|
|
123
|
+
error: m,
|
|
124
|
+
line: h,
|
|
123
125
|
column: p,
|
|
124
126
|
compilationTime: f
|
|
125
127
|
};
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
|
-
async function
|
|
129
|
-
const
|
|
130
|
-
let n = 0,
|
|
131
|
-
for (let
|
|
132
|
-
const l = i[
|
|
130
|
+
async function H(r, e) {
|
|
131
|
+
const t = performance.now(), i = P(r), s = [];
|
|
132
|
+
let n = 0, a = 0;
|
|
133
|
+
for (let o = 0; o < i.length; o++) {
|
|
134
|
+
const l = i[o];
|
|
133
135
|
if (!l.file)
|
|
134
136
|
continue;
|
|
135
137
|
const u = l.file;
|
|
136
138
|
try {
|
|
137
|
-
const
|
|
138
|
-
remarkPlugins:
|
|
139
|
-
rehypePlugins:
|
|
139
|
+
const c = await F(u, "utf-8"), f = await L(c, l.file, {
|
|
140
|
+
remarkPlugins: e == null ? void 0 : e.remarkPlugins,
|
|
141
|
+
rehypePlugins: e == null ? void 0 : e.rehypePlugins
|
|
140
142
|
});
|
|
141
|
-
if (s.push(f), f.success ? n++ :
|
|
143
|
+
if (s.push(f), f.success ? n++ : a++, e != null && e.onProgress && e.onProgress(o + 1, i.length, f), e != null && e.failFast && !f.success)
|
|
142
144
|
break;
|
|
143
|
-
} catch (
|
|
144
|
-
const f =
|
|
145
|
+
} catch (c) {
|
|
146
|
+
const f = c instanceof Error ? c.message : "Unknown error reading file", m = {
|
|
145
147
|
filePath: l.file,
|
|
146
148
|
success: !1,
|
|
147
149
|
error: `Failed to read file: ${f}`,
|
|
148
150
|
compilationTime: 0
|
|
149
151
|
};
|
|
150
|
-
if (s.push(
|
|
152
|
+
if (s.push(m), a++, e != null && e.onProgress && e.onProgress(o + 1, i.length, m), e != null && e.failFast)
|
|
151
153
|
break;
|
|
152
154
|
}
|
|
153
155
|
}
|
|
@@ -155,47 +157,103 @@ async function O(r, t) {
|
|
|
155
157
|
packageId: r.id,
|
|
156
158
|
totalFiles: s.length,
|
|
157
159
|
passed: n,
|
|
158
|
-
failed:
|
|
160
|
+
failed: a,
|
|
159
161
|
results: s,
|
|
160
|
-
totalTime: performance.now() -
|
|
162
|
+
totalTime: performance.now() - t
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const C = ["warning", "info", "tip", "note", "caution", "danger"], j = new RegExp(
|
|
166
|
+
`^:::(${C.join("|")}) ([A-Z].*)$`
|
|
167
|
+
);
|
|
168
|
+
function K(r, e) {
|
|
169
|
+
const t = performance.now(), i = [], s = P(r);
|
|
170
|
+
let n = 0;
|
|
171
|
+
for (const a of s) {
|
|
172
|
+
if (!a.file) continue;
|
|
173
|
+
n++;
|
|
174
|
+
const l = I(a.file, "utf-8").split(`
|
|
175
|
+
`);
|
|
176
|
+
for (let u = 0; u < l.length; u++) {
|
|
177
|
+
const c = l[u], f = c.match(j);
|
|
178
|
+
if (f) {
|
|
179
|
+
const [, m, h] = f, p = {
|
|
180
|
+
file: r.basePath ? x(r.basePath, a.file) : a.file,
|
|
181
|
+
absolutePath: a.file,
|
|
182
|
+
line: u + 1,
|
|
183
|
+
column: 1,
|
|
184
|
+
content: c.trim(),
|
|
185
|
+
admonitionType: m,
|
|
186
|
+
label: h,
|
|
187
|
+
suggestion: `:::${m}[${h}]`
|
|
188
|
+
};
|
|
189
|
+
if (i.push(p), e != null && e.onError && e.onError(p), e != null && e.failFast && i.length > 0)
|
|
190
|
+
return {
|
|
191
|
+
packageId: r.id,
|
|
192
|
+
filesScanned: n,
|
|
193
|
+
errors: i,
|
|
194
|
+
totalTime: performance.now() - t
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
packageId: r.id,
|
|
201
|
+
filesScanned: n,
|
|
202
|
+
errors: i,
|
|
203
|
+
totalTime: performance.now() - t
|
|
161
204
|
};
|
|
162
205
|
}
|
|
163
|
-
function
|
|
206
|
+
function Z(r) {
|
|
164
207
|
const e = [];
|
|
165
|
-
e.push(""), e.push(`
|
|
208
|
+
if (e.push(""), e.push(`Admonition Syntax Report: ${r.packageId}`), e.push("=".repeat(50)), e.push(""), e.push(`Files scanned: ${r.filesScanned}`), e.push(`Errors found: ${r.errors.length}`), e.push(`Total time: ${r.totalTime.toFixed(2)}ms`), e.push(""), r.errors.length === 0)
|
|
209
|
+
return e.push("All admonitions use correct bracket syntax!"), e.push(""), e.join(`
|
|
210
|
+
`);
|
|
211
|
+
e.push("Errors:"), e.push("-".repeat(50)), e.push("");
|
|
212
|
+
for (const t of r.errors)
|
|
213
|
+
e.push(` ${t.file}:${t.line}`), e.push(` ${t.content}`), e.push(` Fix: ${t.suggestion}`), e.push("");
|
|
214
|
+
return e.push("Admonitions with custom titles must use bracket syntax:"), e.push(" Before: :::warning Deprecated"), e.push(" After: :::warning[Deprecated]"), e.push(""), e.push("See: https://github.com/remarkjs/remark-directive"), e.push(""), e.join(`
|
|
215
|
+
`);
|
|
216
|
+
}
|
|
217
|
+
function q(r, e = !1) {
|
|
218
|
+
const t = [];
|
|
219
|
+
t.push(""), t.push(`MDX Compilation Report: ${r.packageId}`), t.push("=".repeat(50)), t.push("");
|
|
166
220
|
const i = r.totalFiles > 0 ? (r.passed / r.totalFiles * 100).toFixed(1) : "0";
|
|
167
|
-
if (
|
|
168
|
-
|
|
221
|
+
if (t.push(`Total files: ${r.totalFiles}`), t.push(`Passed: ${r.passed} (${i}%)`), t.push(`Failed: ${r.failed}`), t.push(`Total time: ${r.totalTime.toFixed(2)}ms`), t.push(""), e) {
|
|
222
|
+
t.push("Results:"), t.push("-".repeat(50));
|
|
169
223
|
for (const s of r.results) {
|
|
170
|
-
const n = s.success ? "[PASS]" : "[FAIL]",
|
|
171
|
-
if (
|
|
172
|
-
const
|
|
173
|
-
|
|
224
|
+
const n = s.success ? "[PASS]" : "[FAIL]", a = `(${s.compilationTime.toFixed(2)}ms)`;
|
|
225
|
+
if (t.push(`${n} ${s.filePath} ${a}`), !s.success && s.error) {
|
|
226
|
+
const o = s.line ? ` (line ${s.line}${s.column ? `:${s.column}` : ""})` : "";
|
|
227
|
+
t.push(` Error${o}: ${s.error}`);
|
|
174
228
|
}
|
|
175
229
|
}
|
|
176
230
|
} else if (r.failed > 0) {
|
|
177
|
-
|
|
231
|
+
t.push("Failures:"), t.push("-".repeat(50));
|
|
178
232
|
for (const s of r.results.filter((n) => !n.success))
|
|
179
|
-
if (
|
|
233
|
+
if (t.push(`[FAIL] ${s.filePath}`), s.error) {
|
|
180
234
|
const n = s.line ? ` (line ${s.line}${s.column ? `:${s.column}` : ""})` : "";
|
|
181
|
-
|
|
235
|
+
t.push(` Error${n}: ${s.error}`);
|
|
182
236
|
}
|
|
183
237
|
}
|
|
184
|
-
return
|
|
238
|
+
return t.push(""), r.failed === 0 ? t.push("All MDX files compiled successfully!") : t.push(`${r.failed} file(s) failed to compile.`), t.push(""), t.join(`
|
|
185
239
|
`);
|
|
186
240
|
}
|
|
187
|
-
function
|
|
188
|
-
return (r,
|
|
189
|
-
const i =
|
|
190
|
-
process.stdout.write(`\r[${r}/${
|
|
241
|
+
function z() {
|
|
242
|
+
return (r, e, t) => {
|
|
243
|
+
const i = t.success ? "✓" : "✗", s = (r / e * 100).toFixed(0);
|
|
244
|
+
process.stdout.write(`\r[${r}/${e}] (${s}%) ${i} ${t.filePath}`), process.stdout.write("\x1B[K"), r === e && process.stdout.write(`
|
|
191
245
|
`);
|
|
192
246
|
};
|
|
193
247
|
}
|
|
194
248
|
export {
|
|
249
|
+
C as ADMONITION_TYPES,
|
|
250
|
+
j as INVALID_ADMONITION_PATTERN,
|
|
195
251
|
L as compileMdx,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
252
|
+
z as createProgressReporter,
|
|
253
|
+
Z as formatAdmonitionReport,
|
|
254
|
+
q as formatTestReport,
|
|
255
|
+
N as getDefaultRehypePlugins,
|
|
256
|
+
M as getDefaultRemarkPlugins,
|
|
257
|
+
H as testManifestMdx,
|
|
258
|
+
K as validateAdmonitions
|
|
201
259
|
};
|