@scalar/helpers
Advanced tools
+6
-0
| # @scalar/helpers | ||
| ## 0.8.1 | ||
| ### Patch Changes | ||
| - [#9377](https://github.com/scalar/scalar/pull/9377): fix: prevent the browser from freezing when pretty-printing deeply shared object graphs (e.g. the "Show Schema" toggle on recursive OpenAPI schemas). `prettyPrintJson` now always collapses repeated references instead of fully expanding every shared subtree, which previously grew exponentially. | ||
| ## 0.8.0 | ||
@@ -4,0 +10,0 @@ |
@@ -6,5 +6,8 @@ /** | ||
| /** | ||
| * JSON.stringify, but with circular dependencies replaced with '[Circular]' | ||
| * JSON.stringify, but with repeated and circular references replaced with '[Circular]'. | ||
| * | ||
| * Note: parsing real JSON never yields shared references, so for ordinary parsed data | ||
| * this produces output identical to a plain JSON.stringify. | ||
| */ | ||
| export declare function replaceCircularDependencies(content: any): string; | ||
| //# sourceMappingURL=pretty-print-json.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"pretty-print-json.d.ts","sourceRoot":"","sources":["../../src/json/pretty-print-json.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,KAAG,MAyBnF,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,GAAG,UAiBvD"} | ||
| {"version":3,"file":"pretty-print-json.d.ts","sourceRoot":"","sources":["../../src/json/pretty-print-json.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,KAAG,MA8BnF,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,GAAG,UAiBvD"} |
@@ -19,8 +19,12 @@ /** | ||
| if (typeof value === 'object') { | ||
| try { | ||
| return JSON.stringify(value, null, 2); | ||
| } | ||
| catch { | ||
| return replaceCircularDependencies(value); | ||
| } | ||
| /* | ||
| * Always serialize through the reference-aware path. A plain JSON.stringify only | ||
| * throws on *self*-referencing objects, but a structure that merely reuses the same | ||
| * object reference in many places (a "diamond" graph) serializes without error — by | ||
| * fully expanding every shared subtree. For a deeply shared graph that expansion grows | ||
| * exponentially and freezes the tab. This happens with deeply resolved, recursive | ||
| * OpenAPI schemas, where circular $refs are already cut to '[circular]' strings yet | ||
| * sibling types remain shared. Collapsing repeated references keeps the output linear. | ||
| */ | ||
| return replaceCircularDependencies(value); | ||
| } | ||
@@ -30,3 +34,6 @@ return value?.toString() ?? ''; | ||
| /** | ||
| * JSON.stringify, but with circular dependencies replaced with '[Circular]' | ||
| * JSON.stringify, but with repeated and circular references replaced with '[Circular]'. | ||
| * | ||
| * Note: parsing real JSON never yields shared references, so for ordinary parsed data | ||
| * this produces output identical to a plain JSON.stringify. | ||
| */ | ||
@@ -33,0 +40,0 @@ export function replaceCircularDependencies(content) { |
@@ -87,10 +87,7 @@ /** | ||
| /** | ||
| * Default file preamble. Used by `serializeReleaseNotes` when no preamble | ||
| * is supplied so the generator never accidentally writes a headerless file. | ||
| * | ||
| * The accompanying `RELEASE_NOTES.json` is the source of truth - this | ||
| * markdown file is a human-friendly view that gets regenerated on every | ||
| * release. Edits made directly to the markdown will be overwritten. | ||
| * Build the default markdown preamble for a product's `RELEASE_NOTES.md`. | ||
| * The JSON file remains the source of truth; this preamble documents that | ||
| * for humans browsing the repo or the Scalar docs site. | ||
| */ | ||
| export declare const DEFAULT_RELEASE_NOTES_PREAMBLE = "# Release notes\n\n<!--\n Auto-generated by the `release-notes-generator` command in\n `tooling/scripts` on every release. Newest entries on top.\n\n Source of truth: `RELEASE_NOTES.json` next to this file. The Scalar\n app's \"What's new\" modal imports the JSON directly; this markdown file\n is a derived, human-friendly view that gets regenerated on every\n release - edits made directly here will be overwritten.\n-->\n"; | ||
| export declare const buildReleaseNotesPreamble: (displayName?: string) => string; | ||
| /** | ||
@@ -103,5 +100,5 @@ * Serialize a list of entries into a `RELEASE_NOTES.md` document. | ||
| */ | ||
| export declare const serializeReleaseNotes: (entries: ReleaseNoteEntry[], options?: { | ||
| export declare const serializeReleaseNotes: (entries: readonly ReleaseNoteEntry[], options?: { | ||
| preamble?: string; | ||
| }) => string; | ||
| //# sourceMappingURL=release-notes.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"release-notes.d.ts","sourceRoot":"","sources":["../../src/markdown/release-notes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,yCAAyC;AACzC,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,sEAAsE;AACtE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,SAAS,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;CACd,CAAA;AAED,iCAAiC;AACjC,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,0CAA0C;AAC1C,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,kEAAkE;AAClE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAA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AO,CAAC,EAAE,YAAY,EAAE,CAAA;CACzB,CAAA;AAYD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,cAAc,MAAM,KAAG,MAIhE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAChC,SAAS,SAAS,gBAAgB,EAAE,EACpC,UAAS;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,KAClC,MASF,CAAA"} |
@@ -31,23 +31,22 @@ /** | ||
| */ | ||
| /** | ||
| * Default file preamble. Used by `serializeReleaseNotes` when no preamble | ||
| * is supplied so the generator never accidentally writes a headerless file. | ||
| * | ||
| * The accompanying `RELEASE_NOTES.json` is the source of truth - this | ||
| * markdown file is a human-friendly view that gets regenerated on every | ||
| * release. Edits made directly to the markdown will be overwritten. | ||
| */ | ||
| export const DEFAULT_RELEASE_NOTES_PREAMBLE = `# Release notes | ||
| <!-- | ||
| const RELEASE_NOTES_PREAMBLE_COMMENT = `<!-- | ||
| Auto-generated by the \`release-notes-generator\` command in | ||
| \`tooling/scripts\` on every release. Newest entries on top. | ||
| Source of truth: \`RELEASE_NOTES.json\` next to this file. The Scalar | ||
| app's "What's new" modal imports the JSON directly; this markdown file | ||
| is a derived, human-friendly view that gets regenerated on every | ||
| release - edits made directly here will be overwritten. | ||
| --> | ||
| `; | ||
| Source of truth: \`RELEASE_NOTES.json\` next to this file. Consumers | ||
| that need structured data should import the JSON directly; this | ||
| markdown file is a derived, human-friendly view that gets regenerated | ||
| on every release - edits made directly here will be overwritten. | ||
| -->`; | ||
| /** | ||
| * Build the default markdown preamble for a product's `RELEASE_NOTES.md`. | ||
| * The JSON file remains the source of truth; this preamble documents that | ||
| * for humans browsing the repo or the Scalar docs site. | ||
| */ | ||
| export const buildReleaseNotesPreamble = (displayName) => { | ||
| return [displayName ? `# ${displayName} release notes` : undefined, RELEASE_NOTES_PREAMBLE_COMMENT] | ||
| .filter(Boolean) | ||
| .join('\n'); | ||
| }; | ||
| /** | ||
| * Serialize a list of entries into a `RELEASE_NOTES.md` document. | ||
@@ -60,3 +59,3 @@ * Entries are emitted in the order provided - callers should sort newest | ||
| export const serializeReleaseNotes = (entries, options = {}) => { | ||
| const preamble = options.preamble ?? DEFAULT_RELEASE_NOTES_PREAMBLE; | ||
| const preamble = options.preamble ?? buildReleaseNotesPreamble(); | ||
| const sections = entries.map(serializeEntry); | ||
@@ -63,0 +62,0 @@ const body = sections.join('\n'); |
+2
-2
@@ -17,3 +17,3 @@ { | ||
| ], | ||
| "version": "0.8.0", | ||
| "version": "0.8.1", | ||
| "engines": { | ||
@@ -131,3 +131,3 @@ "node": ">=22" | ||
| "vitest": "4.1.0", | ||
| "@scalar/themes": "0.15.5" | ||
| "@scalar/themes": "0.15.6" | ||
| }, | ||
@@ -134,0 +134,0 @@ "scripts": { |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
267532
0.29%5691
0.11%