@shadow-js/vite 1.1.0 → 1.1.2
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/CHANGELOG.md +12 -0
- package/README.md +2 -0
- package/dist/dev/index.d.ts +1 -2
- package/dist/dev/internal/source-maps.d.ts +1 -2
- package/dist/dev/internal/source-maps.js.map +1 -1
- package/dist/dev/mdx.d.ts +1 -2
- package/dist/dev/mdx.js.map +1 -1
- package/dist/prod/index.js.map +1 -1
- package/dist/prod/internal/ids.js.map +1 -1
- package/dist/prod/internal/source-maps.js.map +1 -1
- package/dist/prod/mdx.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.2
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- The README starts with the ShadowJS banner, so the package page on npm shows it (the other packages already had it).
|
|
8
|
+
|
|
9
|
+
## 1.1.1
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Released at 1.1.1 with the other packages. No change to this package.
|
|
14
|
+
|
|
3
15
|
## 1.1.0
|
|
4
16
|
|
|
5
17
|
### Changed
|
package/README.md
CHANGED
package/dist/dev/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-maps.js","names":[],"sources":["../../../src/internal/source-maps.ts"],"sourcesContent":["/**\n * Source map helpers of the MDX plugin. `@mdx-js/mdx` turns the `.mdx` text into JSX, and the ShadowJS\n * compiler turns that JSX into the final code, so the plugin holds two maps: final code to JSX, and JSX\n * to `.mdx`. Build tools need the one map from the final code to the `.mdx` file, which {@link composeToSource}\n * builds. The helpers read and write the map format (version 3, base 64 VLQ) themselves: the plugin has\n * no runtime dependency besides the compiler, and the work is a few lines.\n */\n\n/** One decoded segment: generated column, then (source index, line, column and optionally a name index). */\nexport type Segment =\n | readonly [number]\n | readonly [number, number, number, number]\n | readonly [number, number, number, number, number];\n\n/** The parts of a version 3 source map this module reads. */\nexport interface RawMap {\n readonly mappings: string;\n readonly names?: readonly string[];\n}\n\n/** A version 3 source map this module writes. */\nexport interface ComposedMap {\n version: 3;\n file?: string;\n sources: string[];\n sourcesContent: string[];\n names: string[];\n mappings: string;\n}\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst VLQ_BASE_SHIFT = 5;\nconst VLQ_BASE = 1 << VLQ_BASE_SHIFT;\nconst VLQ_MASK = VLQ_BASE - 1;\nconst VLQ_CONTINUE = VLQ_BASE;\n\n/** Appends one signed number, as a base 64 VLQ, to `out`. */\nfunction writeVlq(out: string[], value: number): void {\n let rest = value < 0 ? (-value << 1) | 1 : value << 1;\n do {\n let digit = rest & VLQ_MASK;\n rest >>>= VLQ_BASE_SHIFT;\n if (rest > 0) digit |= VLQ_CONTINUE;\n out.push(BASE64.charAt(digit));\n } while (rest > 0);\n}\n\n/**\n * Decodes the `mappings` of a source map.\n *\n * @param mappings The `mappings` string: lines separated by `;`, segments by `,`.\n * @returns One list of segments per generated line.\n * @throws SyntaxError when a character is not base 64 or a number is cut off.\n * @internal\n */\nexport function decodeMappings(mappings: string): Segment[][] {\n const lines: Segment[][] = [];\n let line: Segment[] = [];\n let column = 0;\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n let numbers: number[] = [];\n let value = 0;\n let shift = 0;\n const finishSegment = (): void => {\n if (numbers.length === 0) return;\n const [dc = 0, ds, dl, dk, dn] = numbers;\n column += dc;\n if (numbers.length === 1) {\n line.push([column]);\n } else if (\n (numbers.length !== 4 && numbers.length !== 5) ||\n ds === undefined ||\n dl === undefined ||\n dk === undefined\n ) {\n throw new SyntaxError(`source map: a segment has ${numbers.length} fields.`);\n } else {\n source += ds;\n sourceLine += dl;\n sourceColumn += dk;\n if (dn === undefined) {\n line.push([column, source, sourceLine, sourceColumn]);\n } else {\n name += dn;\n line.push([column, source, sourceLine, sourceColumn, name]);\n }\n }\n numbers = [];\n };\n for (let i = 0; i < mappings.length; i += 1) {\n const char = mappings.charAt(i);\n if (char === \";\" || char === \",\") {\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n if (char === \";\") {\n lines.push(line);\n line = [];\n column = 0;\n }\n continue;\n }\n const digit = BASE64.indexOf(char);\n if (digit === -1) throw new SyntaxError(`source map: \"${char}\" is not a base 64 digit.`);\n value += (digit & VLQ_MASK) * 2 ** shift;\n if ((digit & VLQ_CONTINUE) !== 0) {\n shift += VLQ_BASE_SHIFT;\n } else {\n numbers.push(value % 2 === 1 ? -Math.floor(value / 2) : value / 2);\n value = 0;\n shift = 0;\n }\n }\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n lines.push(line);\n return lines;\n}\n\n/**\n * Encodes decoded mappings.\n *\n * @param lines One list of segments per generated line, each list sorted by generated column.\n * @returns The `mappings` string.\n * @internal\n */\nexport function encodeMappings(lines: readonly (readonly Segment[])[]): string {\n const out: string[] = [];\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n lines.forEach((line, index) => {\n if (index > 0) out.push(\";\");\n let column = 0;\n line.forEach((segment, position) => {\n if (position > 0) out.push(\",\");\n writeVlq(out, segment[0] - column);\n column = segment[0];\n if (segment.length === 1) return;\n writeVlq(out, segment[1] - source);\n writeVlq(out, segment[2] - sourceLine);\n writeVlq(out, segment[3] - sourceColumn);\n source = segment[1];\n sourceLine = segment[2];\n sourceColumn = segment[3];\n if (segment.length === 5) {\n writeVlq(out, segment[4] - name);\n name = segment[4];\n }\n });\n });\n return out.join(\"\");\n}\n\n/** The last segment of a line that starts at or before `column` and maps to a source position. */\nfunction segmentAt(\n line: readonly Segment[] | undefined,\n column: number,\n): Exclude<Segment, readonly [number]> | undefined {\n if (line === undefined) return undefined;\n let low = 0;\n let high = line.length - 1;\n let found: Exclude<Segment, readonly [number]> | undefined;\n while (low <= high) {\n const middle = (low + high) >> 1;\n const segment = line[middle];\n if (segment === undefined) break;\n if (segment[0] <= column) {\n if (segment.length > 1) found = segment as Exclude<Segment, readonly [number]>;\n low = middle + 1;\n } else {\n high = middle - 1;\n }\n }\n return found;\n}\n\n/**\n * Composes two maps into one that points at the first text. `outer` maps the final code to the middle\n * text (the JSX), `inner` maps the middle text to the original (the `.mdx` file). A position of the final\n * code that falls where `inner` maps nothing gets no mapping. A name recorded by `inner` wins, because it is\n * the earlier spelling.\n *\n * @param outer Final code to middle text.\n * @param inner Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @param file The name of the final file, if known.\n * @returns The map from the final code to the original file.\n * @internal\n */\nexport function composeToSource(\n outer: RawMap,\n inner: RawMap,\n source: string,\n content: string,\n file?: string,\n): ComposedMap {\n const inside = decodeMappings(inner.mappings);\n const names = [...(inner.names ?? [])];\n const known = new Map<string, number>(names.map((name, index) => [name, index]));\n const nameIndex = (name: string): number => {\n const existing = known.get(name);\n if (existing !== undefined) return existing;\n names.push(name);\n known.set(name, names.length - 1);\n return names.length - 1;\n };\n const lines = decodeMappings(outer.mappings).map((line) => {\n const out: Segment[] = [];\n for (const segment of line) {\n if (segment.length === 1) continue;\n const target = segmentAt(inside[segment[2]], segment[3]);\n if (target === undefined) continue;\n if (target.length === 5) {\n out.push([segment[0], 0, target[2], target[3], target[4]]);\n continue;\n }\n const outerName = segment.length === 5 ? outer.names?.[segment[4]] : undefined;\n out.push(\n outerName === undefined\n ? [segment[0], 0, target[2], target[3]]\n : [segment[0], 0, target[2], target[3], nameIndex(outerName)],\n );\n }\n return out;\n });\n const composed: ComposedMap = {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names,\n mappings: encodeMappings(lines),\n };\n if (file !== undefined) composed.file = file;\n return composed;\n}\n\n/**\n * The map of `@mdx-js/mdx` as a complete map of the original file: its one source named and embedded.\n *\n * @param map Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @returns The map.\n * @internal\n */\nexport function mapOfSource(map: RawMap, source: string, content: string): ComposedMap {\n return {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names: [...(map.names ?? [])],\n mappings: map.mappings,\n };\n}\n\n/** What `astring`, the JavaScript printer of `@mdx-js/mdx`, hands to `addMapping`. */\ninterface Mapping {\n readonly generated: { readonly line: number; readonly column: number };\n readonly original: { readonly line: number; readonly column: number } | null;\n readonly source?: string;\n readonly name?: string;\n}\n\n/**\n * The `SourceMapGenerator` the MDX plugin hands to `@mdx-js/mdx`, which uses it to record where each piece\n * of the JSX it prints came from. It has the part of the interface of the generator of the `source-map`\n * package that the printer calls (`addMapping`, `toJSON`), so the plugin needs no such package: `@mdx-js/mdx`\n * brings its own, which a package manager need not hoist to where this plugin can import it.\n *\n * @internal\n */\nexport class MappingCollector {\n readonly #file: string | undefined;\n readonly #sources: string[] = [];\n readonly #names: string[] = [];\n readonly #entries: Array<{\n line: number;\n column: number;\n source: number;\n sourceLine: number;\n sourceColumn: number;\n name: number | undefined;\n }> = [];\n\n /** @param options `file` is the name of the generated file. */\n constructor(options?: { readonly file?: string }) {\n this.#file = options?.file;\n }\n\n /** Records that the generated position came from the original one. A mapping without an original is skipped. */\n addMapping(mapping: Mapping): void {\n if (mapping.original === null) return;\n const origin = mapping.source ?? this.#file ?? \"\";\n let source = this.#sources.indexOf(origin);\n if (source === -1) source = this.#sources.push(origin) - 1;\n let name: number | undefined;\n if (mapping.name !== undefined) {\n name = this.#names.indexOf(mapping.name);\n if (name === -1) name = this.#names.push(mapping.name) - 1;\n }\n this.#entries.push({\n line: mapping.generated.line - 1,\n column: mapping.generated.column,\n source,\n sourceLine: mapping.original.line - 1,\n sourceColumn: mapping.original.column,\n name,\n });\n }\n\n /** The map as a version 3 source map object. */\n toJSON(): { version: 3; file?: string; sources: string[]; names: string[]; mappings: string } {\n const lines: Segment[][] = [];\n // The printer emits in order, but a stable sort keeps the map valid whatever the order.\n const sorted = [...this.#entries].sort((a, b) => a.line - b.line || a.column - b.column);\n for (const entry of sorted) {\n while (lines.length <= entry.line) lines.push([]);\n lines[entry.line]?.push(\n entry.name === undefined\n ? [entry.column, entry.source, entry.sourceLine, entry.sourceColumn]\n : [entry.column, entry.source, entry.sourceLine, entry.sourceColumn, entry.name],\n );\n }\n const map: {\n version: 3;\n file?: string;\n sources: string[];\n names: string[];\n mappings: string;\n } = {\n version: 3,\n sources: [...this.#sources],\n names: [...this.#names],\n mappings: encodeMappings(lines),\n };\n if (this.#file !== undefined) map.file = this.#file;\n return map;\n }\n}\n"],"mappings":";AA8BA,MAAM,SAAS;AACf,MAAM,iBAAiB;AACvB,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,eAAe;;AAGrB,SAAS,SAAS,KAAe,OAAqB;CACpD,IAAI,OAAO,QAAQ,IAAK,CAAC,SAAS,IAAK,IAAI,SAAS;CACpD,GAAG;EACD,IAAI,QAAQ,OAAO;EACnB,UAAU;EACV,IAAI,OAAO,GAAG,SAAS;EACvB,IAAI,KAAK,OAAO,OAAO,KAAK,CAAC;CAC/B,SAAS,OAAO;AAClB;;;;;;;;;AAUA,SAAgB,eAAe,UAA+B;CAC5D,MAAM,QAAqB,CAAC;CAC5B,IAAI,OAAkB,CAAC;CACvB,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,aAAa;CACjB,IAAI,eAAe;CACnB,IAAI,OAAO;CACX,IAAI,UAAoB,CAAC;CACzB,IAAI,QAAQ;CACZ,IAAI,QAAQ;CACZ,MAAM,sBAA4B;EAChC,IAAI,QAAQ,WAAW,GAAG;EAC1B,MAAM,CAAC,KAAK,GAAG,IAAI,IAAI,IAAI,MAAM;EACjC,UAAU;EACV,IAAI,QAAQ,WAAW,GACrB,KAAK,KAAK,CAAC,MAAM,CAAC;OACb,IACJ,QAAQ,WAAW,KAAK,QAAQ,WAAW,KAC5C,OAAO,KAAA,KACP,OAAO,KAAA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ts"],"sourcesContent":["/**\n * Source map helpers of the MDX plugin. `@mdx-js/mdx` turns the `.mdx` text into JSX, and the ShadowJS\n * compiler turns that JSX into the final code, so the plugin holds two maps: final code to JSX, and JSX\n * to `.mdx`. Build tools need the one map from the final code to the `.mdx` file, which {@link composeToSource}\n * builds. The helpers read and write the map format (version 3, base 64 VLQ) themselves: the plugin has\n * no runtime dependency besides the compiler, and the work is a few lines.\n */\n\n/** One decoded segment: generated column, then (source index, line, column and optionally a name index). */\nexport type Segment =\n | readonly [number]\n | readonly [number, number, number, number]\n | readonly [number, number, number, number, number];\n\n/** The parts of a version 3 source map this module reads. */\nexport interface RawMap {\n readonly mappings: string;\n readonly names?: readonly string[];\n}\n\n/** A version 3 source map this module writes. */\nexport interface ComposedMap {\n version: 3;\n file?: string;\n sources: string[];\n sourcesContent: string[];\n names: string[];\n mappings: string;\n}\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst VLQ_BASE_SHIFT = 5;\nconst VLQ_BASE = 1 << VLQ_BASE_SHIFT;\nconst VLQ_MASK = VLQ_BASE - 1;\nconst VLQ_CONTINUE = VLQ_BASE;\n\n/** Appends one signed number, as a base 64 VLQ, to `out`. */\nfunction writeVlq(out: string[], value: number): void {\n let rest = value < 0 ? (-value << 1) | 1 : value << 1;\n do {\n let digit = rest & VLQ_MASK;\n rest >>>= VLQ_BASE_SHIFT;\n if (rest > 0) digit |= VLQ_CONTINUE;\n out.push(BASE64.charAt(digit));\n } while (rest > 0);\n}\n\n/**\n * Decodes the `mappings` of a source map.\n *\n * @param mappings The `mappings` string: lines separated by `;`, segments by `,`.\n * @returns One list of segments per generated line.\n * @throws SyntaxError when a character is not base 64 or a number is cut off.\n * @internal\n */\nexport function decodeMappings(mappings: string): Segment[][] {\n const lines: Segment[][] = [];\n let line: Segment[] = [];\n let column = 0;\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n let numbers: number[] = [];\n let value = 0;\n let shift = 0;\n const finishSegment = (): void => {\n if (numbers.length === 0) return;\n const [dc = 0, ds, dl, dk, dn] = numbers;\n column += dc;\n if (numbers.length === 1) {\n line.push([column]);\n } else if (\n (numbers.length !== 4 && numbers.length !== 5) ||\n ds === undefined ||\n dl === undefined ||\n dk === undefined\n ) {\n throw new SyntaxError(`source map: a segment has ${numbers.length} fields.`);\n } else {\n source += ds;\n sourceLine += dl;\n sourceColumn += dk;\n if (dn === undefined) {\n line.push([column, source, sourceLine, sourceColumn]);\n } else {\n name += dn;\n line.push([column, source, sourceLine, sourceColumn, name]);\n }\n }\n numbers = [];\n };\n for (let i = 0; i < mappings.length; i += 1) {\n const char = mappings.charAt(i);\n if (char === \";\" || char === \",\") {\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n if (char === \";\") {\n lines.push(line);\n line = [];\n column = 0;\n }\n continue;\n }\n const digit = BASE64.indexOf(char);\n if (digit === -1) throw new SyntaxError(`source map: \"${char}\" is not a base 64 digit.`);\n value += (digit & VLQ_MASK) * 2 ** shift;\n if ((digit & VLQ_CONTINUE) !== 0) {\n shift += VLQ_BASE_SHIFT;\n } else {\n numbers.push(value % 2 === 1 ? -Math.floor(value / 2) : value / 2);\n value = 0;\n shift = 0;\n }\n }\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n lines.push(line);\n return lines;\n}\n\n/**\n * Encodes decoded mappings.\n *\n * @param lines One list of segments per generated line, each list sorted by generated column.\n * @returns The `mappings` string.\n * @internal\n */\nexport function encodeMappings(lines: readonly (readonly Segment[])[]): string {\n const out: string[] = [];\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n lines.forEach((line, index) => {\n if (index > 0) out.push(\";\");\n let column = 0;\n line.forEach((segment, position) => {\n if (position > 0) out.push(\",\");\n writeVlq(out, segment[0] - column);\n column = segment[0];\n if (segment.length === 1) return;\n writeVlq(out, segment[1] - source);\n writeVlq(out, segment[2] - sourceLine);\n writeVlq(out, segment[3] - sourceColumn);\n source = segment[1];\n sourceLine = segment[2];\n sourceColumn = segment[3];\n if (segment.length === 5) {\n writeVlq(out, segment[4] - name);\n name = segment[4];\n }\n });\n });\n return out.join(\"\");\n}\n\n/** The last segment of a line that starts at or before `column` and maps to a source position. */\nfunction segmentAt(\n line: readonly Segment[] | undefined,\n column: number,\n): Exclude<Segment, readonly [number]> | undefined {\n if (line === undefined) return undefined;\n let low = 0;\n let high = line.length - 1;\n let found: Exclude<Segment, readonly [number]> | undefined;\n while (low <= high) {\n const middle = (low + high) >> 1;\n const segment = line[middle];\n if (segment === undefined) break;\n if (segment[0] <= column) {\n if (segment.length > 1) found = segment as Exclude<Segment, readonly [number]>;\n low = middle + 1;\n } else {\n high = middle - 1;\n }\n }\n return found;\n}\n\n/**\n * Composes two maps into one that points at the first text. `outer` maps the final code to the middle\n * text (the JSX), `inner` maps the middle text to the original (the `.mdx` file). A position of the final\n * code that falls where `inner` maps nothing gets no mapping. A name recorded by `inner` wins, because it is\n * the earlier spelling.\n *\n * @param outer Final code to middle text.\n * @param inner Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @param file The name of the final file, if known.\n * @returns The map from the final code to the original file.\n * @internal\n */\nexport function composeToSource(\n outer: RawMap,\n inner: RawMap,\n source: string,\n content: string,\n file?: string,\n): ComposedMap {\n const inside = decodeMappings(inner.mappings);\n const names = [...(inner.names ?? [])];\n const known = new Map<string, number>(names.map((name, index) => [name, index]));\n const nameIndex = (name: string): number => {\n const existing = known.get(name);\n if (existing !== undefined) return existing;\n names.push(name);\n known.set(name, names.length - 1);\n return names.length - 1;\n };\n const lines = decodeMappings(outer.mappings).map((line) => {\n const out: Segment[] = [];\n for (const segment of line) {\n if (segment.length === 1) continue;\n const target = segmentAt(inside[segment[2]], segment[3]);\n if (target === undefined) continue;\n if (target.length === 5) {\n out.push([segment[0], 0, target[2], target[3], target[4]]);\n continue;\n }\n const outerName = segment.length === 5 ? outer.names?.[segment[4]] : undefined;\n out.push(\n outerName === undefined\n ? [segment[0], 0, target[2], target[3]]\n : [segment[0], 0, target[2], target[3], nameIndex(outerName)],\n );\n }\n return out;\n });\n const composed: ComposedMap = {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names,\n mappings: encodeMappings(lines),\n };\n if (file !== undefined) composed.file = file;\n return composed;\n}\n\n/**\n * The map of `@mdx-js/mdx` as a complete map of the original file: its one source named and embedded.\n *\n * @param map Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @returns The map.\n * @internal\n */\nexport function mapOfSource(map: RawMap, source: string, content: string): ComposedMap {\n return {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names: [...(map.names ?? [])],\n mappings: map.mappings,\n };\n}\n\n/** What `astring`, the JavaScript printer of `@mdx-js/mdx`, hands to `addMapping`. */\ninterface Mapping {\n readonly generated: { readonly line: number; readonly column: number };\n readonly original: { readonly line: number; readonly column: number } | null;\n readonly source?: string;\n readonly name?: string;\n}\n\n/**\n * The `SourceMapGenerator` the MDX plugin hands to `@mdx-js/mdx`, which uses it to record where each piece\n * of the JSX it prints came from. It has the part of the interface of the generator of the `source-map`\n * package that the printer calls (`addMapping`, `toJSON`), so the plugin needs no such package: `@mdx-js/mdx`\n * brings its own, which a package manager need not hoist to where this plugin can import it.\n *\n * @internal\n */\nexport class MappingCollector {\n readonly #file: string | undefined;\n readonly #sources: string[] = [];\n readonly #names: string[] = [];\n readonly #entries: Array<{\n line: number;\n column: number;\n source: number;\n sourceLine: number;\n sourceColumn: number;\n name: number | undefined;\n }> = [];\n\n /** @param options `file` is the name of the generated file. */\n constructor(options?: { readonly file?: string }) {\n this.#file = options?.file;\n }\n\n /** Records that the generated position came from the original one. A mapping without an original is skipped. */\n addMapping(mapping: Mapping): void {\n if (mapping.original === null) return;\n const origin = mapping.source ?? this.#file ?? \"\";\n let source = this.#sources.indexOf(origin);\n if (source === -1) source = this.#sources.push(origin) - 1;\n let name: number | undefined;\n if (mapping.name !== undefined) {\n name = this.#names.indexOf(mapping.name);\n if (name === -1) name = this.#names.push(mapping.name) - 1;\n }\n this.#entries.push({\n line: mapping.generated.line - 1,\n column: mapping.generated.column,\n source,\n sourceLine: mapping.original.line - 1,\n sourceColumn: mapping.original.column,\n name,\n });\n }\n\n /** The map as a version 3 source map object. */\n toJSON(): { version: 3; file?: string; sources: string[]; names: string[]; mappings: string } {\n const lines: Segment[][] = [];\n // The printer emits in order, but a stable sort keeps the map valid whatever the order.\n const sorted = [...this.#entries].sort((a, b) => a.line - b.line || a.column - b.column);\n for (const entry of sorted) {\n while (lines.length <= entry.line) lines.push([]);\n lines[entry.line]?.push(\n entry.name === undefined\n ? [entry.column, entry.source, entry.sourceLine, entry.sourceColumn]\n : [entry.column, entry.source, entry.sourceLine, entry.sourceColumn, entry.name],\n );\n }\n const map: {\n version: 3;\n file?: string;\n sources: string[];\n names: string[];\n mappings: string;\n } = {\n version: 3,\n sources: [...this.#sources],\n names: [...this.#names],\n mappings: encodeMappings(lines),\n };\n if (this.#file !== undefined) map.file = this.#file;\n return map;\n }\n}\n"],"mappings":";AA8BA,MAAM,SAAS;AACf,MAAM,iBAAiB;AACvB,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,eAAe;;AAGrB,SAAS,SAAS,KAAe,OAAqB;CACpD,IAAI,OAAO,QAAQ,IAAK,CAAC,SAAS,IAAK,IAAI,SAAS;CACpD,GAAG;EACD,IAAI,QAAQ,OAAO;EACnB,UAAU;EACV,IAAI,OAAO,GAAG,SAAS;EACvB,IAAI,KAAK,OAAO,OAAO,KAAK,CAAC;CAC/B,SAAS,OAAO;AAClB;;;;;;;;;AAUA,SAAgB,eAAe,UAA+B;CAC5D,MAAM,QAAqB,CAAC;CAC5B,IAAI,OAAkB,CAAC;CACvB,IAAI,SAAS;CACb,IAAI,SAAS;CACb,IAAI,aAAa;CACjB,IAAI,eAAe;CACnB,IAAI,OAAO;C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,MAAM;IAAY,MAAM;IAAc,MAAM;GAAI,CACnF;EACF;EACA,MAAM,MAMF;GACF,SAAS;GACT,SAAS,CAAC,GAAG,KAAK,QAAQ;GAC1B,OAAO,CAAC,GAAG,KAAK,MAAM;GACtB,UAAU,eAAe,KAAK;EAChC;EACA,IAAI,KAAK,UAAU,KAAA,GAAW,IAAI,OAAO,KAAK;EAC9C,OAAO;CACT;AACF"}
|
package/dist/dev/mdx.d.ts
CHANGED
package/dist/dev/mdx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx.js","names":[],"sources":["../../src/mdx.ts"],"sourcesContent":["import { CompileError, type CompilerPlugin, compile, validatePlugins } from \"@shadow-js/compiler\";\nimport type { Plugin } from \"vite\";\nimport { moduleFile } from \"./internal/ids\";\nimport {\n composeToSource,\n MappingCollector,\n mapOfSource,\n type RawMap,\n} from \"./internal/source-maps\";\n\n/**\n * `shadowMdx()`: a Vite plugin that turns `.mdx` (and `.md`) files into ShadowJS components. MDX is compiled to JSX by\n * `@mdx-js/mdx`, an optional peer, and the JSX goes through the ShadowJS compiler in the same step, so an MDX file needs no\n * other plugin to be compiled. The default export of a module is the component; the `export`s of the file (a `frontmatter`\n * from `remark-mdx-frontmatter`, a `meta` object) are named exports.\n * @packageDocumentation\n */\n\n/** The file `@mdx-js/mdx` answers: a `VFile`, whose `value` holds the code. */\ninterface MdxOutput {\n readonly value: string | Uint8Array;\n /** The source map of `value` to the MDX file, when the options carried a `SourceMapGenerator` that records one. */\n readonly map?: unknown;\n}\n\n/** What `compile` of `@mdx-js/mdx` accepts (the options this plugin sets, and the lists it hands on). */\ninterface MdxCompileOptions {\n readonly jsx: true;\n readonly jsxImportSource: string;\n readonly development: false;\n readonly format: \"mdx\" | \"md\";\n readonly remarkPlugins?: readonly unknown[];\n readonly rehypePlugins?: readonly unknown[];\n readonly recmaPlugins?: readonly unknown[];\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n readonly providerImportSource?: string;\n /** Asks for a source map from the JSX to the MDX file (`file.map` of the answer). */\n readonly SourceMapGenerator: typeof MappingCollector;\n}\n\n/** `compile` of `@mdx-js/mdx`, or a function with its shape. @since 1.0.0 */\nexport type MdxCompile = (\n file: { readonly value: string; readonly path: string },\n options: MdxCompileOptions,\n) => Promise<MdxOutput>;\n\n/** Options of {@link shadowMdx}. @since 1.0.0 */\nexport interface ShadowMdxOptions {\n /** Files to compile, matched against the module id without its query string. Default `/\\.mdx$/`. Add `.md` to read Markdown files too. */\n readonly include?: RegExp;\n /** Files to skip; checked first. Default: any path with a `node_modules` segment. */\n readonly exclude?: RegExp;\n /** Plugins of the Markdown syntax tree (`remark-frontmatter`, `remark-mdx-frontmatter`, `remark-gfm`, ...), as `@mdx-js/mdx` takes them. */\n readonly remarkPlugins?: readonly unknown[];\n /** Plugins of the HTML syntax tree (`rehype-slug`, `rehype-autolink-headings`, ...). */\n readonly rehypePlugins?: readonly unknown[];\n /** Plugins of the JavaScript syntax tree. They run before the plugin's own pass over the elements. */\n readonly recmaPlugins?: readonly unknown[];\n /**\n * How the elements of Markdown (`h1`, `p`, `a`, `code`, ...) are rendered.\n *\n * - `\"overridable\"`: each one is looked up in the `components` prop (and the provider), so an app can replace `a` or `h1`\n * for every page. Each looked-up element is rendered by `Dynamic`.\n * - `\"static\"`: each one is a plain element in the page's template, cloned in one call. The `components` prop still\n * supplies components the file names itself (`<Chart />`) and the `wrapper`, but cannot replace `h1` or `a`.\n *\n * Choose `\"static\"` for pages that never replace a Markdown element: documentation and blog posts render faster and ship\n * less code.\n * @default \"overridable\"\n */\n readonly elements?: \"overridable\" | \"static\";\n /** Options of `remark-rehype`. */\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n /**\n * A module that exports `useMDXComponents`, whose components every MDX file may use without a `components` prop (the\n * way `@mdx-js/react` works for React). Default: none; pass `components` to the file's component instead.\n */\n readonly providerImportSource?: string;\n /** `@mdx-js/mdx`, by module name, or your own `compile`. Default `\"@mdx-js/mdx\"`. */\n readonly mdx?: string | MdxCompile;\n /** Compiler plugins that run on the JSX of every MDX file (see `ShadowPluginOptions.plugins`). */\n readonly plugins?: readonly CompilerPlugin[];\n /**\n * Module the compiled code imports its runtime helpers from. Default `\"@shadow-js/web\"` (`\"@shadow-js/web/server\"` for SSR).\n * With `elements: \"overridable\"` the file also imports `Dynamic` from it, so a custom module must export `Dynamic`;\n * `\"@shadow-js/web/server\"` has none, so `Dynamic` is then imported from `\"@shadow-js/web\"`.\n */\n readonly moduleName?: string;\n}\n\n/** A node of the JavaScript syntax tree `@mdx-js/mdx` hands to recma plugins (ESTree with JSX), read structurally. */\ninterface EsNode {\n type: string;\n [key: string]: unknown;\n}\n\nfunction isNode(value: unknown): value is EsNode {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\n/**\n * The module `Dynamic` is imported from: the one `moduleName` names, so a project that points the runtime at\n * its own module (an alias, a re-export) does not need `@shadow-js/web` resolvable as well. The one exception\n * is the SSR helpers entry `@shadow-js/web/server`: it holds the server helpers and no `Dynamic`, which the\n * main entry provides (and Vite resolves to its server build in an SSR build).\n */\nfunction dynamicSourceOf(moduleName: string | undefined): string {\n if (moduleName === undefined || moduleName === \"@shadow-js/web/server\") return \"@shadow-js/web\";\n return moduleName;\n}\n\n/** The identifier `@mdx-js/mdx` binds the element lookup table to. */\nconst LOOKUP = \"_components\";\n/** The local name of `Dynamic`: it cannot clash with a name the file exports or imports. */\nconst DYNAMIC = \"_ShadowDynamic\";\n\n/**\n * Rewrites the elements `@mdx-js/mdx` looks up in its table (`<_components.h1>`): into plain `<h1>` for `\"static\"`, into\n * `<Dynamic component={_components.h1}>` for `\"overridable\"`. The lookup yields a string for a default element and a\n * function for an override, and a ShadowJS component tag must be a function.\n */\nfunction elementsPlugin(\n mode: \"overridable\" | \"static\",\n dynamicSource: string,\n): () => (tree: EsNode) => void {\n return () => (tree) => {\n let rewritten = 0;\n const pending: unknown[] = [tree];\n while (pending.length > 0) {\n const node = pending.pop();\n if (Array.isArray(node)) {\n for (const child of node) pending.push(child);\n continue;\n }\n if (!isNode(node)) continue;\n if (node.type === \"JSXElement\") {\n const opening = node[\"openingElement\"];\n const closing = node[\"closingElement\"];\n if (isNode(opening) && lookupName(opening[\"name\"]) !== undefined) {\n const tag = lookupName(opening[\"name\"]) as string;\n if (mode === \"static\") {\n opening[\"name\"] = identifier(tag);\n } else {\n opening[\"name\"] = identifier(DYNAMIC);\n const attributes = opening[\"attributes\"] as unknown[];\n attributes.unshift({\n type: \"JSXAttribute\",\n name: identifier(\"component\"),\n value: {\n type: \"JSXExpressionContainer\",\n expression: {\n type: \"MemberExpression\",\n object: { type: \"Identifier\", name: LOOKUP },\n property: { type: \"Identifier\", name: tag },\n computed: false,\n optional: false,\n },\n },\n });\n rewritten += 1;\n }\n if (isNode(closing)) closing[\"name\"] = identifier(mode === \"static\" ? tag : DYNAMIC);\n }\n }\n for (const value of Object.values(node)) {\n if (typeof value === \"object\" && value !== null) pending.push(value);\n }\n }\n if (rewritten > 0) {\n const body = tree[\"body\"] as unknown[];\n body.unshift({\n type: \"ImportDeclaration\",\n specifiers: [\n {\n type: \"ImportSpecifier\",\n imported: { type: \"Identifier\", name: \"Dynamic\" },\n local: { type: \"Identifier\", name: DYNAMIC },\n },\n ],\n source: { type: \"Literal\", value: dynamicSource, raw: JSON.stringify(dynamicSource) },\n attributes: [],\n });\n }\n };\n}\n\n/** The element name of `_components.name` as a JSX tag name, otherwise `undefined`. */\nfunction lookupName(name: unknown): string | undefined {\n if (!isNode(name) || name.type !== \"JSXMemberExpression\") return undefined;\n const object = name[\"object\"];\n const property = name[\"property\"];\n if (!isNode(object) || object.type !== \"JSXIdentifier\" || object[\"name\"] !== LOOKUP)\n return undefined;\n return isNode(property) && typeof property[\"name\"] === \"string\" ? property[\"name\"] : undefined;\n}\n\nfunction identifier(name: string): EsNode {\n return { type: \"JSXIdentifier\", name };\n}\n\nconst DEFAULT_INCLUDE = /\\.mdx$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n\n/** `@mdx-js/mdx` warns with a position; so do the errors of its parsers. */\ninterface Positioned {\n readonly message?: string;\n readonly line?: number | null;\n readonly column?: number | null;\n readonly reason?: string;\n}\n\nasync function loadMdx(specifier: string): Promise<MdxCompile> {\n let loaded: { compile?: unknown };\n try {\n loaded = (await import(specifier)) as { compile?: unknown };\n } catch (cause) {\n throw new Error(\n `shadowMdx: cannot load \"${specifier}\". Install it with \"npm install --save-dev ${specifier}\", or pass your own function as mdx.`,\n { cause },\n );\n }\n if (typeof loaded.compile !== \"function\") {\n throw new TypeError(`shadowMdx: the module \"${specifier}\" has no compile function.`);\n }\n const compileMdx = loaded.compile;\n return (file, options) =>\n Reflect.apply(compileMdx, undefined, [file, options]) as Promise<MdxOutput>;\n}\n\n/**\n * Creates the plugin that compiles MDX to ShadowJS components. It runs before Vite's own handling (`enforce: \"pre\"`), so Vite\n * never sees MDX or JSX. A file is compiled for the browser, or for the server in an SSR build; a syntax error in the MDX is\n * reported with its file, line and column. Hot updates reload the page: an MDX file has no component state worth keeping.\n *\n * @param options Which files, the remark, rehype and recma plugins, and the MDX compiler.\n * @returns A Vite plugin named `shadowjs-mdx`.\n * @throws TypeError when `include` or `exclude` is not a `RegExp`, or `plugins` is not a list of valid compiler plugins.\n * @example\n * // vite.config.ts\n * import { shadow } from \"@shadow-js/vite\";\n * import { shadowMdx } from \"@shadow-js/vite/mdx\";\n * import remarkFrontmatter from \"remark-frontmatter\";\n * import remarkMdxFrontmatter from \"remark-mdx-frontmatter\";\n *\n * export default {\n * plugins: [\n * shadowMdx({ remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter] }),\n * shadow(),\n * ],\n * };\n * @since 1.0.0\n */\nexport function shadowMdx(options: ShadowMdxOptions = {}): Plugin {\n for (const name of [\"include\", \"exclude\"] as const) {\n const value = options[name];\n if (value !== undefined && !(value instanceof RegExp)) {\n throw new TypeError(`shadowMdx(): \"${name}\" must be a RegExp (got ${typeof value}).`);\n }\n }\n const plugins =\n options.plugins === undefined ? [] : validatePlugins(options.plugins, \"shadowMdx(): plugins\");\n const include = statelessPattern(options.include ?? DEFAULT_INCLUDE);\n const exclude = statelessPattern(options.exclude ?? DEFAULT_EXCLUDE);\n let compileMdx: Promise<MdxCompile> | undefined;\n let dev = false;\n return {\n name: \"shadowjs-mdx\",\n enforce: \"pre\",\n config(_config, env) {\n dev = env.command === \"serve\";\n },\n async transform(code, id, transformOptions) {\n const { file, skip } = moduleFile(id);\n if (skip || exclude.test(file) || !include.test(file)) return null;\n compileMdx ??=\n typeof options.mdx === \"function\"\n ? Promise.resolve(options.mdx)\n : loadMdx(options.mdx ?? \"@mdx-js/mdx\");\n const mdx = await compileMdx;\n let jsx: string;\n let mdxMap: RawMap | undefined;\n try {\n const output = await mdx(\n { value: code, path: file },\n {\n jsx: true,\n jsxImportSource: options.moduleName ?? \"@shadow-js/web\",\n development: false,\n format: file.endsWith(\".mdx\") ? \"mdx\" : \"md\",\n ...(options.remarkPlugins === undefined\n ? {}\n : { remarkPlugins: options.remarkPlugins }),\n ...(options.rehypePlugins === undefined\n ? {}\n : { rehypePlugins: options.rehypePlugins }),\n recmaPlugins: [\n ...(options.recmaPlugins ?? []),\n elementsPlugin(\n options.elements ?? \"overridable\",\n dynamicSourceOf(options.moduleName),\n ),\n ],\n ...(options.remarkRehypeOptions === undefined\n ? {}\n : { remarkRehypeOptions: options.remarkRehypeOptions }),\n ...(options.providerImportSource === undefined\n ? {}\n : { providerImportSource: options.providerImportSource }),\n SourceMapGenerator: MappingCollector,\n },\n );\n jsx =\n typeof output.value === \"string\"\n ? output.value\n : Buffer.from(output.value).toString(\"utf8\");\n mdxMap = rawMapOf(output.map);\n } catch (error) {\n const found = error as Positioned;\n const position =\n typeof found.line === \"number\" && found.line > 0\n ? { line: found.line, column: Math.max((found.column ?? 1) - 1, 0) }\n : undefined;\n return this.error(found.reason ?? found.message ?? String(error), position);\n }\n try {\n const result = compile(jsx, {\n filename: `${file}.tsx`,\n generate: transformOptions?.ssr === true ? \"ssr\" : \"dom\",\n dev,\n autoReactive: true,\n hmr: false,\n ...(options.moduleName === undefined ? {} : { moduleName: options.moduleName }),\n ...(plugins.length > 0 ? { plugins } : {}),\n });\n // The positions of the JSX pass are those of the JSX that `@mdx-js/mdx` wrote, not of the MDX file the build\n // names: passed on, they would point at lines and columns of the generated code (the message carries them).\n for (const diagnostic of result.diagnostics) {\n if (diagnostic.severity === \"warning\") this.warn(diagnostic.message);\n }\n // Without JSX to compile the code is what `@mdx-js/mdx` wrote, and its own map already points at the file.\n if (!result.transformed) {\n return { code: jsx, map: mdxMap === undefined ? null : mapOfSource(mdxMap, file, code) };\n }\n // A map from the final code to the JSX is of no use to a debugger: compose it with the one from the JSX\n // to the MDX file. When `@mdx-js/mdx` (or a replacement given as `mdx`) answered no map, it stays as it was.\n return {\n code: result.code,\n map:\n result.map === null || mdxMap === undefined\n ? result.map\n : composeToSource(result.map, mdxMap, file, code),\n };\n } catch (error) {\n if (error instanceof CompileError) return this.error(error.message);\n throw error;\n }\n },\n };\n}\n\n/** Reads the map `@mdx-js/mdx` answers with, or `undefined` when it gave none that can be used. */\nfunction rawMapOf(value: unknown): RawMap | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const { mappings, names } = value as { mappings?: unknown; names?: unknown };\n if (typeof mappings !== \"string\") return undefined;\n return {\n mappings,\n names: Array.isArray(names)\n ? names.filter((name): name is string => typeof name === \"string\")\n : [],\n };\n}\n\n/** The same pattern without the `g` and `y` flags, so `test()` does not remember where the last call ended. */\nfunction statelessPattern(pattern: RegExp): RegExp {\n return pattern.global || pattern.sticky\n ? new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, \"\"))\n : pattern;\n}\n"],"mappings":";;;;AAgGA,SAAS,OAAO,OAAiC;CAC/C,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAElD;;;;;;;AAQA,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U,UAAU;CAC5B,IAAI,OAAO,aAAa,UAAU,OAAO,KAAA;CACzC,OAAO;EACL;EACA,OAAO,MAAM,QAAQ,KAAK,IACtB,MAAM,QAAQ,SAAyB,OAAO,SAAS,QAAQ,IAC/D,CAAC;CACP;AACF;;AAGA,SAAS,iBAAiB,SAAyB;CACjD,OAAO,QAAQ,UAAU,QAAQ,SAC7B,IAAI,OAAO,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,SAAS,EAAE,CAAC,IAC7D;AACN"}
|
|
1
|
+
{"version":3,"file":"mdx.js","names":[],"sources":["../../src/mdx.ts"],"sourcesContent":["import { CompileError, type CompilerPlugin, compile, validatePlugins } from \"@shadow-js/compiler\";\nimport type { Plugin } from \"vite\";\nimport { moduleFile } from \"./internal/ids\";\nimport {\n composeToSource,\n MappingCollector,\n mapOfSource,\n type RawMap,\n} from \"./internal/source-maps\";\n\n/**\n * `shadowMdx()`: a Vite plugin that turns `.mdx` (and `.md`) files into ShadowJS components. MDX is compiled to JSX by\n * `@mdx-js/mdx`, an optional peer, and the JSX goes through the ShadowJS compiler in the same step, so an MDX file needs no\n * other plugin to be compiled. The default export of a module is the component; the `export`s of the file (a `frontmatter`\n * from `remark-mdx-frontmatter`, a `meta` object) are named exports.\n * @packageDocumentation\n */\n\n/** The file `@mdx-js/mdx` answers: a `VFile`, whose `value` holds the code. */\ninterface MdxOutput {\n readonly value: string | Uint8Array;\n /** The source map of `value` to the MDX file, when the options carried a `SourceMapGenerator` that records one. */\n readonly map?: unknown;\n}\n\n/** What `compile` of `@mdx-js/mdx` accepts (the options this plugin sets, and the lists it hands on). */\ninterface MdxCompileOptions {\n readonly jsx: true;\n readonly jsxImportSource: string;\n readonly development: false;\n readonly format: \"mdx\" | \"md\";\n readonly remarkPlugins?: readonly unknown[];\n readonly rehypePlugins?: readonly unknown[];\n readonly recmaPlugins?: readonly unknown[];\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n readonly providerImportSource?: string;\n /** Asks for a source map from the JSX to the MDX file (`file.map` of the answer). */\n readonly SourceMapGenerator: typeof MappingCollector;\n}\n\n/** `compile` of `@mdx-js/mdx`, or a function with its shape. @since 1.0.0 */\nexport type MdxCompile = (\n file: { readonly value: string; readonly path: string },\n options: MdxCompileOptions,\n) => Promise<MdxOutput>;\n\n/** Options of {@link shadowMdx}. @since 1.0.0 */\nexport interface ShadowMdxOptions {\n /** Files to compile, matched against the module id without its query string. Default `/\\.mdx$/`. Add `.md` to read Markdown files too. */\n readonly include?: RegExp;\n /** Files to skip; checked first. Default: any path with a `node_modules` segment. */\n readonly exclude?: RegExp;\n /** Plugins of the Markdown syntax tree (`remark-frontmatter`, `remark-mdx-frontmatter`, `remark-gfm`, ...), as `@mdx-js/mdx` takes them. */\n readonly remarkPlugins?: readonly unknown[];\n /** Plugins of the HTML syntax tree (`rehype-slug`, `rehype-autolink-headings`, ...). */\n readonly rehypePlugins?: readonly unknown[];\n /** Plugins of the JavaScript syntax tree. They run before the plugin's own pass over the elements. */\n readonly recmaPlugins?: readonly unknown[];\n /**\n * How the elements of Markdown (`h1`, `p`, `a`, `code`, ...) are rendered.\n *\n * - `\"overridable\"`: each one is looked up in the `components` prop (and the provider), so an app can replace `a` or `h1`\n * for every page. Each looked-up element is rendered by `Dynamic`.\n * - `\"static\"`: each one is a plain element in the page's template, cloned in one call. The `components` prop still\n * supplies components the file names itself (`<Chart />`) and the `wrapper`, but cannot replace `h1` or `a`.\n *\n * Choose `\"static\"` for pages that never replace a Markdown element: documentation and blog posts render faster and ship\n * less code.\n * @default \"overridable\"\n */\n readonly elements?: \"overridable\" | \"static\";\n /** Options of `remark-rehype`. */\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n /**\n * A module that exports `useMDXComponents`, whose components every MDX file may use without a `components` prop (the\n * way `@mdx-js/react` works for React). Default: none; pass `components` to the file's component instead.\n */\n readonly providerImportSource?: string;\n /** `@mdx-js/mdx`, by module name, or your own `compile`. Default `\"@mdx-js/mdx\"`. */\n readonly mdx?: string | MdxCompile;\n /** Compiler plugins that run on the JSX of every MDX file (see `ShadowPluginOptions.plugins`). */\n readonly plugins?: readonly CompilerPlugin[];\n /**\n * Module the compiled code imports its runtime helpers from. Default `\"@shadow-js/web\"` (`\"@shadow-js/web/server\"` for SSR).\n * With `elements: \"overridable\"` the file also imports `Dynamic` from it, so a custom module must export `Dynamic`;\n * `\"@shadow-js/web/server\"` has none, so `Dynamic` is then imported from `\"@shadow-js/web\"`.\n */\n readonly moduleName?: string;\n}\n\n/** A node of the JavaScript syntax tree `@mdx-js/mdx` hands to recma plugins (ESTree with JSX), read structurally. */\ninterface EsNode {\n type: string;\n [key: string]: unknown;\n}\n\nfunction isNode(value: unknown): value is EsNode {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\n/**\n * The module `Dynamic` is imported from: the one `moduleName` names, so a project that points the runtime at\n * its own module (an alias, a re-export) does not need `@shadow-js/web` resolvable as well. The one exception\n * is the SSR helpers entry `@shadow-js/web/server`: it holds the server helpers and no `Dynamic`, which the\n * main entry provides (and Vite resolves to its server build in an SSR build).\n */\nfunction dynamicSourceOf(moduleName: string | undefined): string {\n if (moduleName === undefined || moduleName === \"@shadow-js/web/server\") return \"@shadow-js/web\";\n return moduleName;\n}\n\n/** The identifier `@mdx-js/mdx` binds the element lookup table to. */\nconst LOOKUP = \"_components\";\n/** The local name of `Dynamic`: it cannot clash with a name the file exports or imports. */\nconst DYNAMIC = \"_ShadowDynamic\";\n\n/**\n * Rewrites the elements `@mdx-js/mdx` looks up in its table (`<_components.h1>`): into plain `<h1>` for `\"static\"`, into\n * `<Dynamic component={_components.h1}>` for `\"overridable\"`. The lookup yields a string for a default element and a\n * function for an override, and a ShadowJS component tag must be a function.\n */\nfunction elementsPlugin(\n mode: \"overridable\" | \"static\",\n dynamicSource: string,\n): () => (tree: EsNode) => void {\n return () => (tree) => {\n let rewritten = 0;\n const pending: unknown[] = [tree];\n while (pending.length > 0) {\n const node = pending.pop();\n if (Array.isArray(node)) {\n for (const child of node) pending.push(child);\n continue;\n }\n if (!isNode(node)) continue;\n if (node.type === \"JSXElement\") {\n const opening = node[\"openingElement\"];\n const closing = node[\"closingElement\"];\n if (isNode(opening) && lookupName(opening[\"name\"]) !== undefined) {\n const tag = lookupName(opening[\"name\"]) as string;\n if (mode === \"static\") {\n opening[\"name\"] = identifier(tag);\n } else {\n opening[\"name\"] = identifier(DYNAMIC);\n const attributes = opening[\"attributes\"] as unknown[];\n attributes.unshift({\n type: \"JSXAttribute\",\n name: identifier(\"component\"),\n value: {\n type: \"JSXExpressionContainer\",\n expression: {\n type: \"MemberExpression\",\n object: { type: \"Identifier\", name: LOOKUP },\n property: { type: \"Identifier\", name: tag },\n computed: false,\n optional: false,\n },\n },\n });\n rewritten += 1;\n }\n if (isNode(closing)) closing[\"name\"] = identifier(mode === \"static\" ? tag : DYNAMIC);\n }\n }\n for (const value of Object.values(node)) {\n if (typeof value === \"object\" && value !== null) pending.push(value);\n }\n }\n if (rewritten > 0) {\n const body = tree[\"body\"] as unknown[];\n body.unshift({\n type: \"ImportDeclaration\",\n specifiers: [\n {\n type: \"ImportSpecifier\",\n imported: { type: \"Identifier\", name: \"Dynamic\" },\n local: { type: \"Identifier\", name: DYNAMIC },\n },\n ],\n source: { type: \"Literal\", value: dynamicSource, raw: JSON.stringify(dynamicSource) },\n attributes: [],\n });\n }\n };\n}\n\n/** The element name of `_components.name` as a JSX tag name, otherwise `undefined`. */\nfunction lookupName(name: unknown): string | undefined {\n if (!isNode(name) || name.type !== \"JSXMemberExpression\") return undefined;\n const object = name[\"object\"];\n const property = name[\"property\"];\n if (!isNode(object) || object.type !== \"JSXIdentifier\" || object[\"name\"] !== LOOKUP)\n return undefined;\n return isNode(property) && typeof property[\"name\"] === \"string\" ? property[\"name\"] : undefined;\n}\n\nfunction identifier(name: string): EsNode {\n return { type: \"JSXIdentifier\", name };\n}\n\nconst DEFAULT_INCLUDE = /\\.mdx$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n\n/** `@mdx-js/mdx` warns with a position; so do the errors of its parsers. */\ninterface Positioned {\n readonly message?: string;\n readonly line?: number | null;\n readonly column?: number | null;\n readonly reason?: string;\n}\n\nasync function loadMdx(specifier: string): Promise<MdxCompile> {\n let loaded: { compile?: unknown };\n try {\n loaded = (await import(specifier)) as { compile?: unknown };\n } catch (cause) {\n throw new Error(\n `shadowMdx: cannot load \"${specifier}\". Install it with \"npm install --save-dev ${specifier}\", or pass your own function as mdx.`,\n { cause },\n );\n }\n if (typeof loaded.compile !== \"function\") {\n throw new TypeError(`shadowMdx: the module \"${specifier}\" has no compile function.`);\n }\n const compileMdx = loaded.compile;\n return (file, options) =>\n Reflect.apply(compileMdx, undefined, [file, options]) as Promise<MdxOutput>;\n}\n\n/**\n * Creates the plugin that compiles MDX to ShadowJS components. It runs before Vite's own handling (`enforce: \"pre\"`), so Vite\n * never sees MDX or JSX. A file is compiled for the browser, or for the server in an SSR build; a syntax error in the MDX is\n * reported with its file, line and column. Hot updates reload the page: an MDX file has no component state worth keeping.\n *\n * @param options Which files, the remark, rehype and recma plugins, and the MDX compiler.\n * @returns A Vite plugin named `shadowjs-mdx`.\n * @throws TypeError when `include` or `exclude` is not a `RegExp`, or `plugins` is not a list of valid compiler plugins.\n * @example\n * // vite.config.ts\n * import { shadow } from \"@shadow-js/vite\";\n * import { shadowMdx } from \"@shadow-js/vite/mdx\";\n * import remarkFrontmatter from \"remark-frontmatter\";\n * import remarkMdxFrontmatter from \"remark-mdx-frontmatter\";\n *\n * export default {\n * plugins: [\n * shadowMdx({ remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter] }),\n * shadow(),\n * ],\n * };\n * @since 1.0.0\n */\nexport function shadowMdx(options: ShadowMdxOptions = {}): Plugin {\n for (const name of [\"include\", \"exclude\"] as const) {\n const value = options[name];\n if (value !== undefined && !(value instanceof RegExp)) {\n throw new TypeError(`shadowMdx(): \"${name}\" must be a RegExp (got ${typeof value}).`);\n }\n }\n const plugins =\n options.plugins === undefined ? [] : validatePlugins(options.plugins, \"shadowMdx(): plugins\");\n const include = statelessPattern(options.include ?? DEFAULT_INCLUDE);\n const exclude = statelessPattern(options.exclude ?? DEFAULT_EXCLUDE);\n let compileMdx: Promise<MdxCompile> | undefined;\n let dev = false;\n return {\n name: \"shadowjs-mdx\",\n enforce: \"pre\",\n config(_config, env) {\n dev = env.command === \"serve\";\n },\n async transform(code, id, transformOptions) {\n const { file, skip } = moduleFile(id);\n if (skip || exclude.test(file) || !include.test(file)) return null;\n compileMdx ??=\n typeof options.mdx === \"function\"\n ? Promise.resolve(options.mdx)\n : loadMdx(options.mdx ?? \"@mdx-js/mdx\");\n const mdx = await compileMdx;\n let jsx: string;\n let mdxMap: RawMap | undefined;\n try {\n const output = await mdx(\n { value: code, path: file },\n {\n jsx: true,\n jsxImportSource: options.moduleName ?? \"@shadow-js/web\",\n development: false,\n format: file.endsWith(\".mdx\") ? \"mdx\" : \"md\",\n ...(options.remarkPlugins === undefined\n ? {}\n : { remarkPlugins: options.remarkPlugins }),\n ...(options.rehypePlugins === undefined\n ? {}\n : { rehypePlugins: options.rehypePlugins }),\n recmaPlugins: [\n ...(options.recmaPlugins ?? []),\n elementsPlugin(\n options.elements ?? \"overridable\",\n dynamicSourceOf(options.moduleName),\n ),\n ],\n ...(options.remarkRehypeOptions === undefined\n ? {}\n : { remarkRehypeOptions: options.remarkRehypeOptions }),\n ...(options.providerImportSource === undefined\n ? {}\n : { providerImportSource: options.providerImportSource }),\n SourceMapGenerator: MappingCollector,\n },\n );\n jsx =\n typeof output.value === \"string\"\n ? output.value\n : Buffer.from(output.value).toString(\"utf8\");\n mdxMap = rawMapOf(output.map);\n } catch (error) {\n const found = error as Positioned;\n const position =\n typeof found.line === \"number\" && found.line > 0\n ? { line: found.line, column: Math.max((found.column ?? 1) - 1, 0) }\n : undefined;\n return this.error(found.reason ?? found.message ?? String(error), position);\n }\n try {\n const result = compile(jsx, {\n filename: `${file}.tsx`,\n generate: transformOptions?.ssr === true ? \"ssr\" : \"dom\",\n dev,\n autoReactive: true,\n hmr: false,\n ...(options.moduleName === undefined ? {} : { moduleName: options.moduleName }),\n ...(plugins.length > 0 ? { plugins } : {}),\n });\n // The positions of the JSX pass are those of the JSX that `@mdx-js/mdx` wrote, not of the MDX file the build\n // names: passed on, they would point at lines and columns of the generated code (the message carries them).\n for (const diagnostic of result.diagnostics) {\n if (diagnostic.severity === \"warning\") this.warn(diagnostic.message);\n }\n // Without JSX to compile the code is what `@mdx-js/mdx` wrote, and its own map already points at the file.\n if (!result.transformed) {\n return { code: jsx, map: mdxMap === undefined ? null : mapOfSource(mdxMap, file, code) };\n }\n // A map from the final code to the JSX is of no use to a debugger: compose it with the one from the JSX\n // to the MDX file. When `@mdx-js/mdx` (or a replacement given as `mdx`) answered no map, it stays as it was.\n return {\n code: result.code,\n map:\n result.map === null || mdxMap === undefined\n ? result.map\n : composeToSource(result.map, mdxMap, file, code),\n };\n } catch (error) {\n if (error instanceof CompileError) return this.error(error.message);\n throw error;\n }\n },\n };\n}\n\n/** Reads the map `@mdx-js/mdx` answers with, or `undefined` when it gave none that can be used. */\nfunction rawMapOf(value: unknown): RawMap | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const { mappings, names } = value as { mappings?: unknown; names?: unknown };\n if (typeof mappings !== \"string\") return undefined;\n return {\n mappings,\n names: Array.isArray(names)\n ? names.filter((name): name is string => typeof name === \"string\")\n : [],\n };\n}\n\n/** The same pattern without the `g` and `y` flags, so `test()` does not remember where the last call ended. */\nfunction statelessPattern(pattern: RegExp): RegExp {\n return pattern.global || pattern.sticky\n ? new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, \"\"))\n : pattern;\n}\n"],"mappings":";;;;AAgGA,SAAS,OAAO,OAAiC;CAC/C,OACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAElD;;;;;;;AAQA,SAAS,gBAAgB,YAA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,OAAO,aAAa,UAAU,OAAO,KAAA;CACzC,OAAO;EACL;EACA,OAAO,MAAM,QAAQ,KAAK,IACtB,MAAM,QAAQ,SAAyB,OAAO,SAAS,QAAQ,IAC/D,CAAC;CACP;AACF;;AAGA,SAAS,iBAAiB,SAAyB;CACjD,OAAO,QAAQ,UAAU,QAAQ,SAC7B,IAAI,OAAO,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,SAAS,EAAE,CAAC,IAC7D;AACN"}
|
package/dist/prod/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["compileWithJavaScript","compile$1","vite","DEFAULT_INCLUDE","DEFAULT_EXCLUDE","PLAIN_MODULE","stateless","pattern","transformsWithOxc","jsxConfig","shadow","name","value","options","plugins","validatePlugins","mode","verified","requireNative","backend","getBackend","\"SHADOW_COMPILER_BACKEND\"","run","compile","include","exclude","dev","hot","env","testing","\"VITEST\"","test","userConfig","domTests","moduleFile","id","skip","file","code","compileOptions","transformOptions","result","diagnostic","context","error","CompileError","loc"],"sources":["../../src/index.ts"],"sourcesContent":["import {\n CompileError,\n type CompileOptions,\n type CompileResult,\n type CompilerPlugin,\n compile,\n getBackend,\n validatePlugins,\n} from \"@shadow-js/compiler\";\nimport { compile as compileWithJavaScript } from \"@shadow-js/compiler/javascript\";\nimport type { Plugin } from \"vite\";\nimport * as vite from \"vite\";\nimport { moduleFile } from \"./internal/ids\";\n\n/**\n * Options of {@link shadow}. Every member is optional: the defaults compile a ShadowJS app for the\n * browser in `vite dev` and `vite build`, and for the server in SSR builds.\n * @see shadow\n * @since 1.0.0\n */\nexport interface ShadowPluginOptions {\n /**\n * Files to compile, matched against the module id without its query string. Plain `.ts` and `.js`\n * modules are compiled as well when they call `useStore`, whatever this is set to, so a\n * single-value `useStore` there takes the cell path. Files that `exclude` matches are never compiled,\n * and neither is a `?raw` or `?url` request (it is the file's text or address, not its source).\n * A `g` or `y` flag on the pattern is ignored: the pattern is matched from the start of every id.\n * @default /\\.[cm]?[jt]sx$/ (every `.jsx` and `.tsx` file)\n */\n include?: RegExp;\n /**\n * Files to skip. It is checked before `include`, so an excluded file is never compiled.\n * @default /[\\\\/]node_modules[\\\\/]/ (any path with a `node_modules` segment)\n */\n exclude?: RegExp;\n /**\n * Module the compiled code imports its runtime helpers from. The HMR runtime is read from\n * `<moduleName>/hmr`.\n * @default \"@shadow-js/web\" (`\"@shadow-js/web/server\"` for SSR transforms)\n */\n moduleName?: string;\n /**\n * Turn a `const` computed from reactive reads (`const double = count() * 2`) into a live value\n * inside components, so it updates without a function or `useMemo`. Set `false` to keep such\n * constants as written.\n * @default true\n */\n autoReactive?: boolean;\n /**\n * Hot-update top-level components in place during `vite dev`. It applies to the browser build\n * only: SSR transforms never get it. Test runners never hot-update modules unless this is set.\n * @default true in `vite dev`, false under a test runner\n */\n hmr?: boolean;\n /**\n * Development output: component names in the compiled code and the extra runtime checks.\n * Set `true` to get development output in a production build, or `false` to get it out of `vite dev`.\n * @default true for `vite dev` (command `serve`), false for `vite build`\n */\n dev?: boolean;\n /**\n * Run the browser build of ShadowJS under Vitest, instead of the server build that the `node`\n * condition selects. Tests that render on the server (`renderToString`) want `false`.\n * @default true when the Vitest environment is `happy-dom` or `jsdom`, otherwise false\n */\n domTests?: boolean;\n /**\n * Compiler plugins that run in the build on every module this plugin compiles: `\"pre\"` plugins\n * (the default) on the syntax tree before the compiler's own passes, `\"post\"` plugins on the\n * generated code, each group in list order. A plugin can report findings and change the module\n * (strip test attributes, collect translation keys, sort class names); it never reaches the\n * browser. Errors fail the build with the plugin's name and the position in the file; warnings go\n * to Vite's warning log. Only files that `include` matches are compiled, so a plugin sees plain\n * `.ts` modules only when `include` covers them. See `CompilerPlugin` in `@shadow-js/compiler`.\n * @default undefined (no plugins; nothing is added to the build)\n */\n plugins?: readonly CompilerPlugin[];\n /**\n * Which implementation of the compiler runs. `@shadow-js/compiler` holds three of the same compiler: a Rust addon (about ten times\n * faster on large apps), the same Rust code as WebAssembly, and the TypeScript implementation. `\"auto\"` uses the fastest one the\n * machine has. `\"native\"` requires the Rust or the WebAssembly implementation and fails, with the reason, when only TypeScript is\n * available; use it in CI to be sure builds are fast. `\"javascript\"` uses the TypeScript implementation only, for example to compare\n * outputs. The output is identical in every mode. A module compiled with compiler plugins is answered by the TypeScript\n * implementation in every mode. The environment variable `SHADOW_COMPILER_BACKEND` asks for one for the whole process.\n * @default \"auto\"\n */\n compiler?: \"auto\" | \"javascript\" | \"native\";\n}\n\n/** What the transform reports through: the plugin context's `warn` and `error`. */\ninterface TransformPluginContext {\n warn(message: string, position?: { line: number; column: number }): void;\n error(message: string, position?: { line: number; column: number }): never;\n}\n\n/** The part of Vitest's config this plugin reads and contributes. */\ninterface VitestSection {\n environment?: string;\n server?: { deps?: { inline?: Array<string | RegExp> } };\n}\n\nconst DEFAULT_INCLUDE = /\\.[cm]?[jt]sx$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n/**\n * Plain modules the compiler also reads, when they call `useStore`: a single-value `useStore(...)`\n * there becomes the cell path (see the compiler's store-cells pass). Other plain modules are untouched.\n */\nconst PLAIN_MODULE = /\\.[cm]?[jt]s$/;\n\n/**\n * The same pattern without the `g` and `y` flags. `test()` on a global or sticky pattern starts at the `lastIndex` the\n * previous call left, so the same file would match on one call and not on the next.\n */\nfunction stateless(pattern: RegExp): RegExp {\n return pattern.global || pattern.sticky\n ? new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, \"\"))\n : pattern;\n}\n\n/**\n * True when this Vite transforms with Oxc (Vite 8 and later, and the Rolldown builds of Vite 7); Vite 7 transforms with\n * esbuild. Found by what the module exports: only a Rolldown based Vite exports `rolldownVersion`.\n */\nconst transformsWithOxc = \"rolldownVersion\" in vite;\n\n/** The JSX runtime setting, under the key this Vite's transformer reads (`oxc` on Vite 8, `esbuild` on Vite 7). */\nfunction jsxConfig(): Record<string, unknown> {\n return transformsWithOxc\n ? { oxc: { jsx: { runtime: \"automatic\", importSource: \"@shadow-js/web\" } } }\n : { esbuild: { jsx: \"automatic\", jsxImportSource: \"@shadow-js/web\" } };\n}\n\n/**\n * Creates the Vite plugin that compiles a ShadowJS app's JSX and `useStore` calls with\n * `@shadow-js/compiler`. Add it to the Vite config of every ShadowJS app: it runs before Vite's own\n * TypeScript and JSX handling, so Vite never sees JSX. SSR builds get the server target. It also\n * sets the ShadowJS JSX import source and dedupes `@shadow-js/core` and `@shadow-js/web`. A compile\n * error is reported to Vite with its file, line and column.\n * @param options Include and exclude filters, the runtime module, the dev, HMR and test switches, and\n * the compiler plugins.\n * @returns A Vite plugin named `shadowjs` that runs with `enforce: \"pre\"`.\n * @throws {TypeError} When `include` or `exclude` is not a `RegExp`, `moduleName` is not a non-empty string, or `plugins` is\n * not a list of valid compiler plugins (a member without a unique `name` or a `transform` function, for example), naming the\n * option. The `transform` hook rethrows any error that is not a `CompileError`, which points at a compiler bug. A `CompileError` goes through Vite's `this.error`\n * instead, which fails the build with the file and position.\n * @example\n * // vite.config.ts\n * import { shadow } from \"@shadow-js/vite\"; // the default export is the same function\n * export default { plugins: [shadow()] };\n * @see ShadowPluginOptions\n * @since 1.0.0\n */\nexport function shadow(options: ShadowPluginOptions = {}): Plugin {\n for (const name of [\"include\", \"exclude\"] as const) {\n const value = options[name];\n if (value !== undefined && !(value instanceof RegExp)) {\n throw new TypeError(`shadow(): \"${name}\" must be a RegExp (got ${typeof value}).`);\n }\n }\n if (\n options.moduleName !== undefined &&\n (typeof options.moduleName !== \"string\" || options.moduleName === \"\")\n ) {\n throw new TypeError('shadow(): \"moduleName\" must be a non-empty string.');\n }\n if (\n options.compiler !== undefined &&\n options.compiler !== \"auto\" &&\n options.compiler !== \"javascript\" &&\n options.compiler !== \"native\"\n ) {\n throw new TypeError(\n `shadow(): \"compiler\" must be \"auto\", \"javascript\" or \"native\" (got ${JSON.stringify(options.compiler)}).`,\n );\n }\n const plugins =\n options.plugins === undefined ? [] : validatePlugins(options.plugins, \"shadow(): plugins\");\n // `@shadow-js/compiler` chooses its implementation once per process, on the first call. \"native\" asks it which one it chose and refuses\n // the TypeScript one, so a build that must be fast does not quietly become slow.\n const mode = options.compiler ?? \"auto\";\n let verified = mode !== \"native\";\n const requireNative = (): void => {\n if (verified) return;\n const backend = getBackend();\n if (backend.name === \"javascript\") {\n throw new Error(\n `shadow(): compiler: \"native\" needs the Rust or WebAssembly implementation of @shadow-js/compiler, and only the TypeScript one is available (${backend.notes.join(\"; \") || \"no reason was recorded\"}). Install @shadow-js/compiler with its optional dependencies (do not use --omit=optional), or use compiler: \"auto\". SHADOW_COMPILER_BACKEND=${process.env[\"SHADOW_COMPILER_BACKEND\"] ?? \"auto\"}.`,\n );\n }\n verified = true;\n };\n const run = mode === \"javascript\" ? compileWithJavaScript : compile;\n const include = stateless(options.include ?? DEFAULT_INCLUDE);\n const exclude = stateless(options.exclude ?? DEFAULT_EXCLUDE);\n let dev = options.dev ?? false;\n let hot = options.hmr !== false;\n return {\n name: \"shadowjs\",\n enforce: \"pre\",\n config(userConfig, env) {\n if (options.dev === undefined) dev = env.command === \"serve\";\n const testing = env.mode === \"test\" || process.env[\"VITEST\"] !== undefined;\n // Test runners serve modules but never hot update them, unless the caller asked for it.\n if (testing && options.hmr === undefined) hot = false;\n const test = (userConfig as { test?: VitestSection }).test;\n const domTests =\n testing &&\n (options.domTests ?? (test?.environment === \"happy-dom\" || test?.environment === \"jsdom\"));\n return {\n // `DUSK_PUBLIC_*` variables are readable in client code next to Vite's own `VITE_*` (Dusk\n // and the integration packages document `DUSK_PUBLIC_*`).\n envPrefix: [\"VITE_\", \"DUSK_PUBLIC_\"],\n // Dependency scanning and any file this plugin skips are parsed with the ShadowJS JSX\n // runtime types, never React's.\n ...jsxConfig(),\n resolve: {\n dedupe: [\"@shadow-js/core\", \"@shadow-js/web\"],\n // Vitest resolves packages with the `node` condition, which selects the inert server\n // build of ShadowJS; DOM tests need the browser build.\n ...(domTests ? { conditions: [\"browser\"] } : {}),\n },\n // Packages Node would load natively see the `node` condition too, so they go through Vite.\n ...(domTests ? { test: { server: { deps: { inline: [/@shadow-js\\//] } } } } : {}),\n optimizeDeps: { exclude: [\"@shadow-js/core\", \"@shadow-js/web\"] },\n };\n },\n transform(code, id, transformOptions) {\n // A virtual module (Vite's \\0 prefix) and a `?raw` or `?url` request are not source to compile.\n const { file, skip } = moduleFile(id);\n if (skip || exclude.test(file)) return null;\n if (!include.test(file) && !(PLAIN_MODULE.test(file) && code.includes(\"useStore\")))\n return null;\n const compileOptions: CompileOptions = {\n filename: file,\n generate: transformOptions?.ssr === true ? \"ssr\" : \"dom\",\n dev,\n autoReactive: options.autoReactive !== false,\n hmr: dev && hot && transformOptions?.ssr !== true,\n };\n if (options.moduleName !== undefined) compileOptions.moduleName = options.moduleName;\n if (plugins.length > 0) compileOptions.plugins = plugins;\n const finish = (\n context: TransformPluginContext,\n run: typeof compile,\n ): { code: string; map: CompileResult[\"map\"] } | null => {\n try {\n const result = run(code, compileOptions);\n for (const diagnostic of result.diagnostics) {\n if (diagnostic.severity === \"warning\") {\n context.warn(diagnostic.message, {\n line: diagnostic.line,\n column: diagnostic.column,\n });\n }\n }\n if (!result.transformed) return null;\n return { code: result.code, map: result.map };\n } catch (error) {\n if (error instanceof CompileError) {\n const loc = { file, line: error.diagnostic.line, column: error.diagnostic.column };\n return context.error(\n error.message,\n loc.line === 0 ? undefined : { line: loc.line, column: loc.column },\n );\n }\n throw error;\n }\n };\n requireNative();\n return finish(this, run);\n },\n };\n}\n\nexport default shadow;\n"],"mappings":"A,oOAqGA,MAAMG,EAAkB,iBAClBC,EAAkB,yBAKlBC,EAAe,gBAMrB,SAASC,EAAU,EAAyB,CAC1C,OAAOC,EAAQ,QAAUA,EAAQ,OAC7B,IAAI,OAAOA,EAAQ,OAAQA,EAAQ,MAAM,QAAQ,QAAS,EAAE,CAAC,EAC7DA,CACN,CAMA,MAAMC,EAAoB,oBAAqBN,EAG/C,SAASO,GAAqC,CAC5C,OAAOD,EACH,CAAE,I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AAQ,KAAKD,EAAW,QAAS,CAC/B,KAAMA,EAAW,KACjB,OAAQA,EAAW,MACrB,CAAC,EAIL,OADKD,EAAO,YACL,CAAE,KAAMA,EAAO,KAAM,IAAKA,EAAO,GAAI,EADZ,IAElC,OAASG,EAAO,CACd,GAAIA,aAAiBC,EAAc,CACjC,IAAMC,EAAM,CAAE,OAAM,KAAMF,EAAM,WAAW,KAAM,OAAQA,EAAM,WAAW,MAAO,EACjF,OAAOD,EAAQ,MACbC,EAAM,QACNE,EAAI,OAAS,EAAI,IAAA,GAAY,CAAE,KAAMA,EAAI,KAAM,OAAQA,EAAI,MAAO,CACpE,CACF,CACA,MAAMF,CACR,CACF,EAEO,CAAO,KAAMtB,CAAG,CACzB,CACF,CACF,C"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["compileWithJavaScript","moduleFile","CompileError","compile","getBackend","validatePlugins","compile$1","vite","DEFAULT_INCLUDE","DEFAULT_EXCLUDE","PLAIN_MODULE","stateless","pattern","transformsWithOxc","jsxConfig","shadow","options","name","value","plugins","mode","verified","requireNative","backend","\"SHADOW_COMPILER_BACKEND\"","run","include","exclude","dev","hot","userConfig","env","testing","\"VITEST\"","test","domTests","code","id","transformOptions","file","skip","compileOptions","context","result","diagnostic","error","loc"],"sources":["../../src/index.ts"],"sourcesContent":["import {\n CompileError,\n type CompileOptions,\n type CompileResult,\n type CompilerPlugin,\n compile,\n getBackend,\n validatePlugins,\n} from \"@shadow-js/compiler\";\nimport { compile as compileWithJavaScript } from \"@shadow-js/compiler/javascript\";\nimport type { Plugin } from \"vite\";\nimport * as vite from \"vite\";\nimport { moduleFile } from \"./internal/ids\";\n\n/**\n * Options of {@link shadow}. Every member is optional: the defaults compile a ShadowJS app for the\n * browser in `vite dev` and `vite build`, and for the server in SSR builds.\n * @see shadow\n * @since 1.0.0\n */\nexport interface ShadowPluginOptions {\n /**\n * Files to compile, matched against the module id without its query string. Plain `.ts` and `.js`\n * modules are compiled as well when they call `useStore`, whatever this is set to, so a\n * single-value `useStore` there takes the cell path. Files that `exclude` matches are never compiled,\n * and neither is a `?raw` or `?url` request (it is the file's text or address, not its source).\n * A `g` or `y` flag on the pattern is ignored: the pattern is matched from the start of every id.\n * @default /\\.[cm]?[jt]sx$/ (every `.jsx` and `.tsx` file)\n */\n include?: RegExp;\n /**\n * Files to skip. It is checked before `include`, so an excluded file is never compiled.\n * @default /[\\\\/]node_modules[\\\\/]/ (any path with a `node_modules` segment)\n */\n exclude?: RegExp;\n /**\n * Module the compiled code imports its runtime helpers from. The HMR runtime is read from\n * `<moduleName>/hmr`.\n * @default \"@shadow-js/web\" (`\"@shadow-js/web/server\"` for SSR transforms)\n */\n moduleName?: string;\n /**\n * Turn a `const` computed from reactive reads (`const double = count() * 2`) into a live value\n * inside components, so it updates without a function or `useMemo`. Set `false` to keep such\n * constants as written.\n * @default true\n */\n autoReactive?: boolean;\n /**\n * Hot-update top-level components in place during `vite dev`. It applies to the browser build\n * only: SSR transforms never get it. Test runners never hot-update modules unless this is set.\n * @default true in `vite dev`, false under a test runner\n */\n hmr?: boolean;\n /**\n * Development output: component names in the compiled code and the extra runtime checks.\n * Set `true` to get development output in a production build, or `false` to get it out of `vite dev`.\n * @default true for `vite dev` (command `serve`), false for `vite build`\n */\n dev?: boolean;\n /**\n * Run the browser build of ShadowJS under Vitest, instead of the server build that the `node`\n * condition selects. Tests that render on the server (`renderToString`) want `false`.\n * @default true when the Vitest environment is `happy-dom` or `jsdom`, otherwise false\n */\n domTests?: boolean;\n /**\n * Compiler plugins that run in the build on every module this plugin compiles: `\"pre\"` plugins\n * (the default) on the syntax tree before the compiler's own passes, `\"post\"` plugins on the\n * generated code, each group in list order. A plugin can report findings and change the module\n * (strip test attributes, collect translation keys, sort class names); it never reaches the\n * browser. Errors fail the build with the plugin's name and the position in the file; warnings go\n * to Vite's warning log. Only files that `include` matches are compiled, so a plugin sees plain\n * `.ts` modules only when `include` covers them. See `CompilerPlugin` in `@shadow-js/compiler`.\n * @default undefined (no plugins; nothing is added to the build)\n */\n plugins?: readonly CompilerPlugin[];\n /**\n * Which implementation of the compiler runs. `@shadow-js/compiler` holds three of the same compiler: a Rust addon (about ten times\n * faster on large apps), the same Rust code as WebAssembly, and the TypeScript implementation. `\"auto\"` uses the fastest one the\n * machine has. `\"native\"` requires the Rust or the WebAssembly implementation and fails, with the reason, when only TypeScript is\n * available; use it in CI to be sure builds are fast. `\"javascript\"` uses the TypeScript implementation only, for example to compare\n * outputs. The output is identical in every mode. A module compiled with compiler plugins is answered by the TypeScript\n * implementation in every mode. The environment variable `SHADOW_COMPILER_BACKEND` asks for one for the whole process.\n * @default \"auto\"\n */\n compiler?: \"auto\" | \"javascript\" | \"native\";\n}\n\n/** What the transform reports through: the plugin context's `warn` and `error`. */\ninterface TransformPluginContext {\n warn(message: string, position?: { line: number; column: number }): void;\n error(message: string, position?: { line: number; column: number }): never;\n}\n\n/** The part of Vitest's config this plugin reads and contributes. */\ninterface VitestSection {\n environment?: string;\n server?: { deps?: { inline?: Array<string | RegExp> } };\n}\n\nconst DEFAULT_INCLUDE = /\\.[cm]?[jt]sx$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n/**\n * Plain modules the compiler also reads, when they call `useStore`: a single-value `useStore(...)`\n * there becomes the cell path (see the compiler's store-cells pass). Other plain modules are untouched.\n */\nconst PLAIN_MODULE = /\\.[cm]?[jt]s$/;\n\n/**\n * The same pattern without the `g` and `y` flags. `test()` on a global or sticky pattern starts at the `lastIndex` the\n * previous call left, so the same file would match on one call and not on the next.\n */\nfunction stateless(pattern: RegExp): RegExp {\n return pattern.global || pattern.sticky\n ? new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, \"\"))\n : pattern;\n}\n\n/**\n * True when this Vite transforms with Oxc (Vite 8 and later, and the Rolldown builds of Vite 7); Vite 7 transforms with\n * esbuild. Found by what the module exports: only a Rolldown based Vite exports `rolldownVersion`.\n */\nconst transformsWithOxc = \"rolldownVersion\" in vite;\n\n/** The JSX runtime setting, under the key this Vite's transformer reads (`oxc` on Vite 8, `esbuild` on Vite 7). */\nfunction jsxConfig(): Record<string, unknown> {\n return transformsWithOxc\n ? { oxc: { jsx: { runtime: \"automatic\", importSource: \"@shadow-js/web\" } } }\n : { esbuild: { jsx: \"automatic\", jsxImportSource: \"@shadow-js/web\" } };\n}\n\n/**\n * Creates the Vite plugin that compiles a ShadowJS app's JSX and `useStore` calls with\n * `@shadow-js/compiler`. Add it to the Vite config of every ShadowJS app: it runs before Vite's own\n * TypeScript and JSX handling, so Vite never sees JSX. SSR builds get the server target. It also\n * sets the ShadowJS JSX import source and dedupes `@shadow-js/core` and `@shadow-js/web`. A compile\n * error is reported to Vite with its file, line and column.\n * @param options Include and exclude filters, the runtime module, the dev, HMR and test switches, and\n * the compiler plugins.\n * @returns A Vite plugin named `shadowjs` that runs with `enforce: \"pre\"`.\n * @throws {TypeError} When `include` or `exclude` is not a `RegExp`, `moduleName` is not a non-empty string, or `plugins` is\n * not a list of valid compiler plugins (a member without a unique `name` or a `transform` function, for example), naming the\n * option. The `transform` hook rethrows any error that is not a `CompileError`, which points at a compiler bug. A `CompileError` goes through Vite's `this.error`\n * instead, which fails the build with the file and position.\n * @example\n * // vite.config.ts\n * import { shadow } from \"@shadow-js/vite\"; // the default export is the same function\n * export default { plugins: [shadow()] };\n * @see ShadowPluginOptions\n * @since 1.0.0\n */\nexport function shadow(options: ShadowPluginOptions = {}): Plugin {\n for (const name of [\"include\", \"exclude\"] as const) {\n const value = options[name];\n if (value !== undefined && !(value instanceof RegExp)) {\n throw new TypeError(`shadow(): \"${name}\" must be a RegExp (got ${typeof value}).`);\n }\n }\n if (\n options.moduleName !== undefined &&\n (typeof options.moduleName !== \"string\" || options.moduleName === \"\")\n ) {\n throw new TypeError('shadow(): \"moduleName\" must be a non-empty string.');\n }\n if (\n options.compiler !== undefined &&\n options.compiler !== \"auto\" &&\n options.compiler !== \"javascript\" &&\n options.compiler !== \"native\"\n ) {\n throw new TypeError(\n `shadow(): \"compiler\" must be \"auto\", \"javascript\" or \"native\" (got ${JSON.stringify(options.compiler)}).`,\n );\n }\n const plugins =\n options.plugins === undefined ? [] : validatePlugins(options.plugins, \"shadow(): plugins\");\n // `@shadow-js/compiler` chooses its implementation once per process, on the first call. \"native\" asks it which one it chose and refuses\n // the TypeScript one, so a build that must be fast does not quietly become slow.\n const mode = options.compiler ?? \"auto\";\n let verified = mode !== \"native\";\n const requireNative = (): void => {\n if (verified) return;\n const backend = getBackend();\n if (backend.name === \"javascript\") {\n throw new Error(\n `shadow(): compiler: \"native\" needs the Rust or WebAssembly implementation of @shadow-js/compiler, and only the TypeScript one is available (${backend.notes.join(\"; \") || \"no reason was recorded\"}). Install @shadow-js/compiler with its optional dependencies (do not use --omit=optional), or use compiler: \"auto\". SHADOW_COMPILER_BACKEND=${process.env[\"SHADOW_COMPILER_BACKEND\"] ?? \"auto\"}.`,\n );\n }\n verified = true;\n };\n const run = mode === \"javascript\" ? compileWithJavaScript : compile;\n const include = stateless(options.include ?? DEFAULT_INCLUDE);\n const exclude = stateless(options.exclude ?? DEFAULT_EXCLUDE);\n let dev = options.dev ?? false;\n let hot = options.hmr !== false;\n return {\n name: \"shadowjs\",\n enforce: \"pre\",\n config(userConfig, env) {\n if (options.dev === undefined) dev = env.command === \"serve\";\n const testing = env.mode === \"test\" || process.env[\"VITEST\"] !== undefined;\n // Test runners serve modules but never hot update them, unless the caller asked for it.\n if (testing && options.hmr === undefined) hot = false;\n const test = (userConfig as { test?: VitestSection }).test;\n const domTests =\n testing &&\n (options.domTests ?? (test?.environment === \"happy-dom\" || test?.environment === \"jsdom\"));\n return {\n // `DUSK_PUBLIC_*` variables are readable in client code next to Vite's own `VITE_*` (Dusk\n // and the integration packages document `DUSK_PUBLIC_*`).\n envPrefix: [\"VITE_\", \"DUSK_PUBLIC_\"],\n // Dependency scanning and any file this plugin skips are parsed with the ShadowJS JSX\n // runtime types, never React's.\n ...jsxConfig(),\n resolve: {\n dedupe: [\"@shadow-js/core\", \"@shadow-js/web\"],\n // Vitest resolves packages with the `node` condition, which selects the inert server\n // build of ShadowJS; DOM tests need the browser build.\n ...(domTests ? { conditions: [\"browser\"] } : {}),\n },\n // Packages Node would load natively see the `node` condition too, so they go through Vite.\n ...(domTests ? { test: { server: { deps: { inline: [/@shadow-js\\//] } } } } : {}),\n optimizeDeps: { exclude: [\"@shadow-js/core\", \"@shadow-js/web\"] },\n };\n },\n transform(code, id, transformOptions) {\n // A virtual module (Vite's \\0 prefix) and a `?raw` or `?url` request are not source to compile.\n const { file, skip } = moduleFile(id);\n if (skip || exclude.test(file)) return null;\n if (!include.test(file) && !(PLAIN_MODULE.test(file) && code.includes(\"useStore\")))\n return null;\n const compileOptions: CompileOptions = {\n filename: file,\n generate: transformOptions?.ssr === true ? \"ssr\" : \"dom\",\n dev,\n autoReactive: options.autoReactive !== false,\n hmr: dev && hot && transformOptions?.ssr !== true,\n };\n if (options.moduleName !== undefined) compileOptions.moduleName = options.moduleName;\n if (plugins.length > 0) compileOptions.plugins = plugins;\n const finish = (\n context: TransformPluginContext,\n run: typeof compile,\n ): { code: string; map: CompileResult[\"map\"] } | null => {\n try {\n const result = run(code, compileOptions);\n for (const diagnostic of result.diagnostics) {\n if (diagnostic.severity === \"warning\") {\n context.warn(diagnostic.message, {\n line: diagnostic.line,\n column: diagnostic.column,\n });\n }\n }\n if (!result.transformed) return null;\n return { code: result.code, map: result.map };\n } catch (error) {\n if (error instanceof CompileError) {\n const loc = { file, line: error.diagnostic.line, column: error.diagnostic.column };\n return context.error(\n error.message,\n loc.line === 0 ? undefined : { line: loc.line, column: loc.column },\n );\n }\n throw error;\n }\n };\n requireNative();\n return finish(this, run);\n },\n };\n}\n\nexport default shadow;\n"],"mappings":"A,oOAqGA,MAAMQ,EAAkB,iBAClBC,EAAkB,yBAKlBC,EAAe,gBAMrB,SAASC,EAAUC,EAAyB,CAC1C,OAAOA,EAAQ,QAAUA,EAAQ,OAC7B,IAAI,OAAOA,EAAQ,OAAQ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B,GA4BjDG,EAAc,IA1BZoB,EACAjB,IACuD,CACvD,GAAI,CACF,IAAMkB,EAASlB,EAAIW,EAAMK,CAAc,EACvC,IAAK,IAAMG,KAAcD,EAAO,YAC1BC,EAAW,WAAa,WAC1BF,EAAQ,KAAKE,EAAW,QAAS,CAC/B,KAAMA,EAAW,KACjB,OAAQA,EAAW,MACrB,CAAC,EAIL,OADKD,EAAO,YACL,CAAE,KAAMA,EAAO,KAAM,IAAKA,EAAO,GAAI,EADZ,IAElC,OAASE,EAAO,CACd,GAAIA,aAAiB3C,EAAc,CACjC,IAAM4C,EAAM,CAAEP,OAAM,KAAMM,EAAM,WAAW,KAAM,OAAQA,EAAM,WAAW,MAAO,EACjF,OAAOH,EAAQ,MACbG,EAAM,QACNC,EAAI,OAAS,EAAI,IAAA,GAAY,CAAE,KAAMA,EAAI,KAAM,OAAQA,EAAI,MAAO,CACpE,CACF,CACA,MAAMD,CACR,CACF,EAEO,CAAO,KAAMpB,CAAG,CACzB,CACF,CACF,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ids.js","names":["BYTES_QUERY","moduleFile","
|
|
1
|
+
{"version":3,"file":"ids.js","names":["BYTES_QUERY","moduleFile","id","query"],"sources":["../../../src/internal/ids.ts"],"sourcesContent":["/**\n * Vite's own test for a request that asks for the bytes of a file instead of its module: `?raw` (the\n * text) and `?url` (the address). Same patterns as Vite's `rawRE` and `urlRE`, applied to the query only.\n */\nconst BYTES_QUERY = /[?&](?:raw|url)(?:&|$)/;\n\n/**\n * Splits a module id from Vite into the file it names and whether a compiler should leave it alone.\n *\n * - A virtual module (Vite's `\\0` prefix) belongs to the plugin that made it.\n * - A `?raw` or `?url` request is answered with an `export default \"<text or address>\"` module; that is\n * not the source of the file, so compiling it as JSX or MDX would read a string as a program.\n *\n * Every other query (`?v=`, `?t=`, `?import`) is a cache or HMR marker on the same source and is ignored.\n *\n * @param id The module id Vite passes to `transform`.\n * @returns The file part of the id (no query) and `skip`, true when the module is not to be compiled.\n * @internal\n */\nexport function moduleFile(id: string): { file: string; skip: boolean } {\n const query = id.indexOf(\"?\");\n const file = query === -1 ? id : id.slice(0, query);\n const skip = id.startsWith(\"\\0\") || (query !== -1 && BYTES_QUERY.test(id.slice(query)));\n return { file, skip };\n}\n"],"mappings":"AAIA,MAAMA,EAAc,yBAepB,SAAgBC,EAAWC,EAA6C,CACtE,IAAMC,EAAQD,EAAG,QAAQ,GAAG,EAG5B,MAAO,CAAE,KAFIC,IAAU,GAAKD,EAAKA,EAAG,MAAM,EAAGC,CAAK,EAEnC,KADFD,EAAG,WAAW,IAAI,GAAMC,IAAU,IAAMH,EAAY,KAAKE,EAAG,MAAMC,CAAK,CAAC,CACjE,CACtB,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-maps.js","names":["BASE64","writeVlq","rest","value","digit","out","decodeMappings","lines","line","column","source","sourceLine","sourceColumn","name","numbers","shift","finishSegment","dc","ds","dl","dk","dn","i","mappings","char","encodeMappings","index","position","segment","segmentAt","low","high","found","middle","composeToSource","inside","inner","names","known","nameIndex","existing","outer","target","outerName","composed","content","file","mapOfSource","map","MappingCollector","#file","options","mapping","origin","#sources","#names","#entries","sorted","a","b","entry"],"sources":["../../../src/internal/source-maps.ts"],"sourcesContent":["/**\n * Source map helpers of the MDX plugin. `@mdx-js/mdx` turns the `.mdx` text into JSX, and the ShadowJS\n * compiler turns that JSX into the final code, so the plugin holds two maps: final code to JSX, and JSX\n * to `.mdx`. Build tools need the one map from the final code to the `.mdx` file, which {@link composeToSource}\n * builds. The helpers read and write the map format (version 3, base 64 VLQ) themselves: the plugin has\n * no runtime dependency besides the compiler, and the work is a few lines.\n */\n\n/** One decoded segment: generated column, then (source index, line, column and optionally a name index). */\nexport type Segment =\n | readonly [number]\n | readonly [number, number, number, number]\n | readonly [number, number, number, number, number];\n\n/** The parts of a version 3 source map this module reads. */\nexport interface RawMap {\n readonly mappings: string;\n readonly names?: readonly string[];\n}\n\n/** A version 3 source map this module writes. */\nexport interface ComposedMap {\n version: 3;\n file?: string;\n sources: string[];\n sourcesContent: string[];\n names: string[];\n mappings: string;\n}\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst VLQ_BASE_SHIFT = 5;\nconst VLQ_BASE = 1 << VLQ_BASE_SHIFT;\nconst VLQ_MASK = VLQ_BASE - 1;\nconst VLQ_CONTINUE = VLQ_BASE;\n\n/** Appends one signed number, as a base 64 VLQ, to `out`. */\nfunction writeVlq(out: string[], value: number): void {\n let rest = value < 0 ? (-value << 1) | 1 : value << 1;\n do {\n let digit = rest & VLQ_MASK;\n rest >>>= VLQ_BASE_SHIFT;\n if (rest > 0) digit |= VLQ_CONTINUE;\n out.push(BASE64.charAt(digit));\n } while (rest > 0);\n}\n\n/**\n * Decodes the `mappings` of a source map.\n *\n * @param mappings The `mappings` string: lines separated by `;`, segments by `,`.\n * @returns One list of segments per generated line.\n * @throws SyntaxError when a character is not base 64 or a number is cut off.\n * @internal\n */\nexport function decodeMappings(mappings: string): Segment[][] {\n const lines: Segment[][] = [];\n let line: Segment[] = [];\n let column = 0;\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n let numbers: number[] = [];\n let value = 0;\n let shift = 0;\n const finishSegment = (): void => {\n if (numbers.length === 0) return;\n const [dc = 0, ds, dl, dk, dn] = numbers;\n column += dc;\n if (numbers.length === 1) {\n line.push([column]);\n } else if (\n (numbers.length !== 4 && numbers.length !== 5) ||\n ds === undefined ||\n dl === undefined ||\n dk === undefined\n ) {\n throw new SyntaxError(`source map: a segment has ${numbers.length} fields.`);\n } else {\n source += ds;\n sourceLine += dl;\n sourceColumn += dk;\n if (dn === undefined) {\n line.push([column, source, sourceLine, sourceColumn]);\n } else {\n name += dn;\n line.push([column, source, sourceLine, sourceColumn, name]);\n }\n }\n numbers = [];\n };\n for (let i = 0; i < mappings.length; i += 1) {\n const char = mappings.charAt(i);\n if (char === \";\" || char === \",\") {\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n if (char === \";\") {\n lines.push(line);\n line = [];\n column = 0;\n }\n continue;\n }\n const digit = BASE64.indexOf(char);\n if (digit === -1) throw new SyntaxError(`source map: \"${char}\" is not a base 64 digit.`);\n value += (digit & VLQ_MASK) * 2 ** shift;\n if ((digit & VLQ_CONTINUE) !== 0) {\n shift += VLQ_BASE_SHIFT;\n } else {\n numbers.push(value % 2 === 1 ? -Math.floor(value / 2) : value / 2);\n value = 0;\n shift = 0;\n }\n }\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n lines.push(line);\n return lines;\n}\n\n/**\n * Encodes decoded mappings.\n *\n * @param lines One list of segments per generated line, each list sorted by generated column.\n * @returns The `mappings` string.\n * @internal\n */\nexport function encodeMappings(lines: readonly (readonly Segment[])[]): string {\n const out: string[] = [];\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n lines.forEach((line, index) => {\n if (index > 0) out.push(\";\");\n let column = 0;\n line.forEach((segment, position) => {\n if (position > 0) out.push(\",\");\n writeVlq(out, segment[0] - column);\n column = segment[0];\n if (segment.length === 1) return;\n writeVlq(out, segment[1] - source);\n writeVlq(out, segment[2] - sourceLine);\n writeVlq(out, segment[3] - sourceColumn);\n source = segment[1];\n sourceLine = segment[2];\n sourceColumn = segment[3];\n if (segment.length === 5) {\n writeVlq(out, segment[4] - name);\n name = segment[4];\n }\n });\n });\n return out.join(\"\");\n}\n\n/** The last segment of a line that starts at or before `column` and maps to a source position. */\nfunction segmentAt(\n line: readonly Segment[] | undefined,\n column: number,\n): Exclude<Segment, readonly [number]> | undefined {\n if (line === undefined) return undefined;\n let low = 0;\n let high = line.length - 1;\n let found: Exclude<Segment, readonly [number]> | undefined;\n while (low <= high) {\n const middle = (low + high) >> 1;\n const segment = line[middle];\n if (segment === undefined) break;\n if (segment[0] <= column) {\n if (segment.length > 1) found = segment as Exclude<Segment, readonly [number]>;\n low = middle + 1;\n } else {\n high = middle - 1;\n }\n }\n return found;\n}\n\n/**\n * Composes two maps into one that points at the first text. `outer` maps the final code to the middle\n * text (the JSX), `inner` maps the middle text to the original (the `.mdx` file). A position of the final\n * code that falls where `inner` maps nothing gets no mapping. A name recorded by `inner` wins, because it is\n * the earlier spelling.\n *\n * @param outer Final code to middle text.\n * @param inner Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @param file The name of the final file, if known.\n * @returns The map from the final code to the original file.\n * @internal\n */\nexport function composeToSource(\n outer: RawMap,\n inner: RawMap,\n source: string,\n content: string,\n file?: string,\n): ComposedMap {\n const inside = decodeMappings(inner.mappings);\n const names = [...(inner.names ?? [])];\n const known = new Map<string, number>(names.map((name, index) => [name, index]));\n const nameIndex = (name: string): number => {\n const existing = known.get(name);\n if (existing !== undefined) return existing;\n names.push(name);\n known.set(name, names.length - 1);\n return names.length - 1;\n };\n const lines = decodeMappings(outer.mappings).map((line) => {\n const out: Segment[] = [];\n for (const segment of line) {\n if (segment.length === 1) continue;\n const target = segmentAt(inside[segment[2]], segment[3]);\n if (target === undefined) continue;\n if (target.length === 5) {\n out.push([segment[0], 0, target[2], target[3], target[4]]);\n continue;\n }\n const outerName = segment.length === 5 ? outer.names?.[segment[4]] : undefined;\n out.push(\n outerName === undefined\n ? [segment[0], 0, target[2], target[3]]\n : [segment[0], 0, target[2], target[3], nameIndex(outerName)],\n );\n }\n return out;\n });\n const composed: ComposedMap = {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names,\n mappings: encodeMappings(lines),\n };\n if (file !== undefined) composed.file = file;\n return composed;\n}\n\n/**\n * The map of `@mdx-js/mdx` as a complete map of the original file: its one source named and embedded.\n *\n * @param map Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @returns The map.\n * @internal\n */\nexport function mapOfSource(map: RawMap, source: string, content: string): ComposedMap {\n return {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names: [...(map.names ?? [])],\n mappings: map.mappings,\n };\n}\n\n/** What `astring`, the JavaScript printer of `@mdx-js/mdx`, hands to `addMapping`. */\ninterface Mapping {\n readonly generated: { readonly line: number; readonly column: number };\n readonly original: { readonly line: number; readonly column: number } | null;\n readonly source?: string;\n readonly name?: string;\n}\n\n/**\n * The `SourceMapGenerator` the MDX plugin hands to `@mdx-js/mdx`, which uses it to record where each piece\n * of the JSX it prints came from. It has the part of the interface of the generator of the `source-map`\n * package that the printer calls (`addMapping`, `toJSON`), so the plugin needs no such package: `@mdx-js/mdx`\n * brings its own, which a package manager need not hoist to where this plugin can import it.\n *\n * @internal\n */\nexport class MappingCollector {\n readonly #file: string | undefined;\n readonly #sources: string[] = [];\n readonly #names: string[] = [];\n readonly #entries: Array<{\n line: number;\n column: number;\n source: number;\n sourceLine: number;\n sourceColumn: number;\n name: number | undefined;\n }> = [];\n\n /** @param options `file` is the name of the generated file. */\n constructor(options?: { readonly file?: string }) {\n this.#file = options?.file;\n }\n\n /** Records that the generated position came from the original one. A mapping without an original is skipped. */\n addMapping(mapping: Mapping): void {\n if (mapping.original === null) return;\n const origin = mapping.source ?? this.#file ?? \"\";\n let source = this.#sources.indexOf(origin);\n if (source === -1) source = this.#sources.push(origin) - 1;\n let name: number | undefined;\n if (mapping.name !== undefined) {\n name = this.#names.indexOf(mapping.name);\n if (name === -1) name = this.#names.push(mapping.name) - 1;\n }\n this.#entries.push({\n line: mapping.generated.line - 1,\n column: mapping.generated.column,\n source,\n sourceLine: mapping.original.line - 1,\n sourceColumn: mapping.original.column,\n name,\n });\n }\n\n /** The map as a version 3 source map object. */\n toJSON(): { version: 3; file?: string; sources: string[]; names: string[]; mappings: string } {\n const lines: Segment[][] = [];\n // The printer emits in order, but a stable sort keeps the map valid whatever the order.\n const sorted = [...this.#entries].sort((a, b) => a.line - b.line || a.column - b.column);\n for (const entry of sorted) {\n while (lines.length <= entry.line) lines.push([]);\n lines[entry.line]?.push(\n entry.name === undefined\n ? [entry.column, entry.source, entry.sourceLine, entry.sourceColumn]\n : [entry.column, entry.source, entry.sourceLine, entry.sourceColumn, entry.name],\n );\n }\n const map: {\n version: 3;\n file?: string;\n sources: string[];\n names: string[];\n mappings: string;\n } = {\n version: 3,\n sources: [...this.#sources],\n names: [...this.#names],\n mappings: encodeMappings(lines),\n };\n if (this.#file !== undefined) map.file = this.#file;\n return map;\n }\n}\n"],"mappings":"AA8BA,MAAMA,EAAS,mEAOf,SAASC,EAAS,EAAe,EAAqB,CACpD,IAAIC,EAAOC,EAAQ,EAAK,CAACA,GAAS,EAAK,EAAIA,GAAS,EACpD,EAAG,CACD,IAAIC,EAAQF,EAAO,GACnB,KAAU,EACNA,EAAO,IAAG,GAAS,IACvBG,EAAI,KAAKL,EAAO,OAAOI,CAAK,CAAC,CAC/B,OAASF,EAAO,EAClB,CAUA,SAAgBI,EAAe,EAA+B,CAC5D,IAAMC,EAAqB,CAAC,EACxBC,EAAkB,CAAC,EACnBC,EAAS,EACTC,EAAS,EACTC,EAAa,EACbC,EAAe,EACfC,EAAO,EACPC,EAAoB,CAAC,EACrBX,EAAQ,EACRY,EAAQ,EACNC,MAA4B,CAChC,GAAIF,EAAQ,SAAW,EAAG,OAC1B,GAAM,CAACG,EAAK,EAAGC,EAAIC,EAAIC,EAAIC,GAAMP,EAEjC,GADA,GAAUG,EACNH,EAAQ,SAAW,EACrBN,EAAK,KAAK,CAACC,CAAM,CAAC,OACb,GACJK,EAAQ,SAAW,GAAKA,EAAQ,SAAW,GAC5CI,IAAO,IAAA,IACPC,IAAO,IAAA,IACPC,IAAO,IAAA,GAEP,MAAU,YAAY,6BAA6BN,EAAQ,OAAO,SAAS,MAE3E,IAAUI,EACV,GAAcC,EACd,GAAgBC,EACZC,IAAO,IAAA,GACTb,EAAK,KAAK,CAACC,EAAQC,EAAQC,EAAYC,CAAY,CAAC,GAEpD,GAAQS,EACRb,EAAK,KAAK,CAACC,EAAQC,EAAQC,EAAYC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AKH,EAAQ,IAAI,EAAI,IAE3D,KAAKI,GAAS,KAAK,CACjB,KAAMJ,EAAQ,UAAU,KAAO,EAC/B,OAAQA,EAAQ,UAAU,OAC1B,SACA,WAAYA,EAAQ,SAAS,KAAO,EACpC,aAAcA,EAAQ,SAAS,OAC/B,MACF,CAAC,CACH,CAGA,QAA8F,CAC5F,IAAM7C,EAAqB,CAAC,EAEtBkD,EAAS,CAAC,GAAG,KAAKD,EAAQ,CAAC,CAAC,MAAM,EAAG,IAAME,EAAE,KAAOC,EAAE,MAAQD,EAAE,OAASC,EAAE,MAAM,EACvF,IAAK,IAAMC,KAASH,EAAQ,CAC1B,KAAOlD,EAAM,QAAUqD,EAAM,MAAMrD,EAAM,KAAK,CAAC,CAAC,EAChDA,EAAMqD,EAAM,KAAK,EAAE,KACjBA,EAAM,OAAS,IAAA,GACX,CAACA,EAAM,OAAQA,EAAM,OAAQA,EAAM,WAAYA,EAAM,YAAY,EACjE,CAACA,EAAM,OAAQA,EAAM,OAAQA,EAAM,WAAYA,EAAM,aAAcA,EAAM,IAAI,CACnF,CACF,CACA,IAAMZ,EAMF,CACF,QAAS,EACT,QAAS,CAAC,GAAG,KAAKM,EAAQ,EAC1B,MAAO,CAAC,GAAG,KAAKC,EAAM,EACtB,SAAU9B,EAAelB,CAAK,CAChC,EAEA,OADI,KAAK2C,KAAU,IAAA,KAAW,EAAI,KAAO,KAAKA,IACvCF,CACT,CACF,E"}
|
|
1
|
+
{"version":3,"file":"source-maps.js","names":["BASE64","writeVlq","out","value","rest","digit","decodeMappings","mappings","lines","line","column","source","sourceLine","sourceColumn","name","numbers","shift","finishSegment","dc","ds","dl","dk","dn","i","char","encodeMappings","index","segment","position","segmentAt","low","high","found","middle","composeToSource","outer","inner","content","file","inside","names","known","nameIndex","existing","target","outerName","composed","mapOfSource","map","MappingCollector","#file","#sources","#names","#entries","options","mapping","origin","sorted","a","b","entry"],"sources":["../../../src/internal/source-maps.ts"],"sourcesContent":["/**\n * Source map helpers of the MDX plugin. `@mdx-js/mdx` turns the `.mdx` text into JSX, and the ShadowJS\n * compiler turns that JSX into the final code, so the plugin holds two maps: final code to JSX, and JSX\n * to `.mdx`. Build tools need the one map from the final code to the `.mdx` file, which {@link composeToSource}\n * builds. The helpers read and write the map format (version 3, base 64 VLQ) themselves: the plugin has\n * no runtime dependency besides the compiler, and the work is a few lines.\n */\n\n/** One decoded segment: generated column, then (source index, line, column and optionally a name index). */\nexport type Segment =\n | readonly [number]\n | readonly [number, number, number, number]\n | readonly [number, number, number, number, number];\n\n/** The parts of a version 3 source map this module reads. */\nexport interface RawMap {\n readonly mappings: string;\n readonly names?: readonly string[];\n}\n\n/** A version 3 source map this module writes. */\nexport interface ComposedMap {\n version: 3;\n file?: string;\n sources: string[];\n sourcesContent: string[];\n names: string[];\n mappings: string;\n}\n\nconst BASE64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\nconst VLQ_BASE_SHIFT = 5;\nconst VLQ_BASE = 1 << VLQ_BASE_SHIFT;\nconst VLQ_MASK = VLQ_BASE - 1;\nconst VLQ_CONTINUE = VLQ_BASE;\n\n/** Appends one signed number, as a base 64 VLQ, to `out`. */\nfunction writeVlq(out: string[], value: number): void {\n let rest = value < 0 ? (-value << 1) | 1 : value << 1;\n do {\n let digit = rest & VLQ_MASK;\n rest >>>= VLQ_BASE_SHIFT;\n if (rest > 0) digit |= VLQ_CONTINUE;\n out.push(BASE64.charAt(digit));\n } while (rest > 0);\n}\n\n/**\n * Decodes the `mappings` of a source map.\n *\n * @param mappings The `mappings` string: lines separated by `;`, segments by `,`.\n * @returns One list of segments per generated line.\n * @throws SyntaxError when a character is not base 64 or a number is cut off.\n * @internal\n */\nexport function decodeMappings(mappings: string): Segment[][] {\n const lines: Segment[][] = [];\n let line: Segment[] = [];\n let column = 0;\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n let numbers: number[] = [];\n let value = 0;\n let shift = 0;\n const finishSegment = (): void => {\n if (numbers.length === 0) return;\n const [dc = 0, ds, dl, dk, dn] = numbers;\n column += dc;\n if (numbers.length === 1) {\n line.push([column]);\n } else if (\n (numbers.length !== 4 && numbers.length !== 5) ||\n ds === undefined ||\n dl === undefined ||\n dk === undefined\n ) {\n throw new SyntaxError(`source map: a segment has ${numbers.length} fields.`);\n } else {\n source += ds;\n sourceLine += dl;\n sourceColumn += dk;\n if (dn === undefined) {\n line.push([column, source, sourceLine, sourceColumn]);\n } else {\n name += dn;\n line.push([column, source, sourceLine, sourceColumn, name]);\n }\n }\n numbers = [];\n };\n for (let i = 0; i < mappings.length; i += 1) {\n const char = mappings.charAt(i);\n if (char === \";\" || char === \",\") {\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n if (char === \";\") {\n lines.push(line);\n line = [];\n column = 0;\n }\n continue;\n }\n const digit = BASE64.indexOf(char);\n if (digit === -1) throw new SyntaxError(`source map: \"${char}\" is not a base 64 digit.`);\n value += (digit & VLQ_MASK) * 2 ** shift;\n if ((digit & VLQ_CONTINUE) !== 0) {\n shift += VLQ_BASE_SHIFT;\n } else {\n numbers.push(value % 2 === 1 ? -Math.floor(value / 2) : value / 2);\n value = 0;\n shift = 0;\n }\n }\n if (shift !== 0) throw new SyntaxError(\"source map: a number is cut off.\");\n finishSegment();\n lines.push(line);\n return lines;\n}\n\n/**\n * Encodes decoded mappings.\n *\n * @param lines One list of segments per generated line, each list sorted by generated column.\n * @returns The `mappings` string.\n * @internal\n */\nexport function encodeMappings(lines: readonly (readonly Segment[])[]): string {\n const out: string[] = [];\n let source = 0;\n let sourceLine = 0;\n let sourceColumn = 0;\n let name = 0;\n lines.forEach((line, index) => {\n if (index > 0) out.push(\";\");\n let column = 0;\n line.forEach((segment, position) => {\n if (position > 0) out.push(\",\");\n writeVlq(out, segment[0] - column);\n column = segment[0];\n if (segment.length === 1) return;\n writeVlq(out, segment[1] - source);\n writeVlq(out, segment[2] - sourceLine);\n writeVlq(out, segment[3] - sourceColumn);\n source = segment[1];\n sourceLine = segment[2];\n sourceColumn = segment[3];\n if (segment.length === 5) {\n writeVlq(out, segment[4] - name);\n name = segment[4];\n }\n });\n });\n return out.join(\"\");\n}\n\n/** The last segment of a line that starts at or before `column` and maps to a source position. */\nfunction segmentAt(\n line: readonly Segment[] | undefined,\n column: number,\n): Exclude<Segment, readonly [number]> | undefined {\n if (line === undefined) return undefined;\n let low = 0;\n let high = line.length - 1;\n let found: Exclude<Segment, readonly [number]> | undefined;\n while (low <= high) {\n const middle = (low + high) >> 1;\n const segment = line[middle];\n if (segment === undefined) break;\n if (segment[0] <= column) {\n if (segment.length > 1) found = segment as Exclude<Segment, readonly [number]>;\n low = middle + 1;\n } else {\n high = middle - 1;\n }\n }\n return found;\n}\n\n/**\n * Composes two maps into one that points at the first text. `outer` maps the final code to the middle\n * text (the JSX), `inner` maps the middle text to the original (the `.mdx` file). A position of the final\n * code that falls where `inner` maps nothing gets no mapping. A name recorded by `inner` wins, because it is\n * the earlier spelling.\n *\n * @param outer Final code to middle text.\n * @param inner Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @param file The name of the final file, if known.\n * @returns The map from the final code to the original file.\n * @internal\n */\nexport function composeToSource(\n outer: RawMap,\n inner: RawMap,\n source: string,\n content: string,\n file?: string,\n): ComposedMap {\n const inside = decodeMappings(inner.mappings);\n const names = [...(inner.names ?? [])];\n const known = new Map<string, number>(names.map((name, index) => [name, index]));\n const nameIndex = (name: string): number => {\n const existing = known.get(name);\n if (existing !== undefined) return existing;\n names.push(name);\n known.set(name, names.length - 1);\n return names.length - 1;\n };\n const lines = decodeMappings(outer.mappings).map((line) => {\n const out: Segment[] = [];\n for (const segment of line) {\n if (segment.length === 1) continue;\n const target = segmentAt(inside[segment[2]], segment[3]);\n if (target === undefined) continue;\n if (target.length === 5) {\n out.push([segment[0], 0, target[2], target[3], target[4]]);\n continue;\n }\n const outerName = segment.length === 5 ? outer.names?.[segment[4]] : undefined;\n out.push(\n outerName === undefined\n ? [segment[0], 0, target[2], target[3]]\n : [segment[0], 0, target[2], target[3], nameIndex(outerName)],\n );\n }\n return out;\n });\n const composed: ComposedMap = {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names,\n mappings: encodeMappings(lines),\n };\n if (file !== undefined) composed.file = file;\n return composed;\n}\n\n/**\n * The map of `@mdx-js/mdx` as a complete map of the original file: its one source named and embedded.\n *\n * @param map Middle text to original text; the original is its only source.\n * @param source The name of the original file.\n * @param content The text of the original file.\n * @returns The map.\n * @internal\n */\nexport function mapOfSource(map: RawMap, source: string, content: string): ComposedMap {\n return {\n version: 3,\n sources: [source],\n sourcesContent: [content],\n names: [...(map.names ?? [])],\n mappings: map.mappings,\n };\n}\n\n/** What `astring`, the JavaScript printer of `@mdx-js/mdx`, hands to `addMapping`. */\ninterface Mapping {\n readonly generated: { readonly line: number; readonly column: number };\n readonly original: { readonly line: number; readonly column: number } | null;\n readonly source?: string;\n readonly name?: string;\n}\n\n/**\n * The `SourceMapGenerator` the MDX plugin hands to `@mdx-js/mdx`, which uses it to record where each piece\n * of the JSX it prints came from. It has the part of the interface of the generator of the `source-map`\n * package that the printer calls (`addMapping`, `toJSON`), so the plugin needs no such package: `@mdx-js/mdx`\n * brings its own, which a package manager need not hoist to where this plugin can import it.\n *\n * @internal\n */\nexport class MappingCollector {\n readonly #file: string | undefined;\n readonly #sources: string[] = [];\n readonly #names: string[] = [];\n readonly #entries: Array<{\n line: number;\n column: number;\n source: number;\n sourceLine: number;\n sourceColumn: number;\n name: number | undefined;\n }> = [];\n\n /** @param options `file` is the name of the generated file. */\n constructor(options?: { readonly file?: string }) {\n this.#file = options?.file;\n }\n\n /** Records that the generated position came from the original one. A mapping without an original is skipped. */\n addMapping(mapping: Mapping): void {\n if (mapping.original === null) return;\n const origin = mapping.source ?? this.#file ?? \"\";\n let source = this.#sources.indexOf(origin);\n if (source === -1) source = this.#sources.push(origin) - 1;\n let name: number | undefined;\n if (mapping.name !== undefined) {\n name = this.#names.indexOf(mapping.name);\n if (name === -1) name = this.#names.push(mapping.name) - 1;\n }\n this.#entries.push({\n line: mapping.generated.line - 1,\n column: mapping.generated.column,\n source,\n sourceLine: mapping.original.line - 1,\n sourceColumn: mapping.original.column,\n name,\n });\n }\n\n /** The map as a version 3 source map object. */\n toJSON(): { version: 3; file?: string; sources: string[]; names: string[]; mappings: string } {\n const lines: Segment[][] = [];\n // The printer emits in order, but a stable sort keeps the map valid whatever the order.\n const sorted = [...this.#entries].sort((a, b) => a.line - b.line || a.column - b.column);\n for (const entry of sorted) {\n while (lines.length <= entry.line) lines.push([]);\n lines[entry.line]?.push(\n entry.name === undefined\n ? [entry.column, entry.source, entry.sourceLine, entry.sourceColumn]\n : [entry.column, entry.source, entry.sourceLine, entry.sourceColumn, entry.name],\n );\n }\n const map: {\n version: 3;\n file?: string;\n sources: string[];\n names: string[];\n mappings: string;\n } = {\n version: 3,\n sources: [...this.#sources],\n names: [...this.#names],\n mappings: encodeMappings(lines),\n };\n if (this.#file !== undefined) map.file = this.#file;\n return map;\n }\n}\n"],"mappings":"AA8BA,MAAMA,EAAS,mEAOf,SAASC,EAASC,EAAeC,EAAqB,CACpD,IAAIC,EAAOD,EAAQ,EAAK,CAACA,GAAS,EAAK,EAAIA,GAAS,EACpD,EAAG,CACD,IAAIE,EAAQD,EAAO,GACnBA,KAAU,EACNA,EAAO,IAAGC,GAAS,IACvBH,EAAI,KAAKF,EAAO,OAAOK,CAAK,CAAC,CAC/B,OAASD,EAAO,EAClB,CAUA,SAAgBE,EAAeC,EAA+B,CAC5D,IAAMC,EAAqB,CAAC,EACxBC,EAAkB,CAAC,EACnBC,EAAS,EACTC,EAAS,EACTC,EAAa,EACbC,EAAe,EACfC,EAAO,EACPC,EAAoB,CAAC,EACrBZ,EAAQ,EACRa,EAAQ,EACNC,MAA4B,CAChC,GAAIF,EAAQ,SAAW,EAAG,OAC1B,GAAM,CAACG,EAAK,EAAGC,EAAIC,EA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AAC,GAAG,KAAKG,EAAQ,EAC1B,MAAO,CAAC,GAAG,KAAKC,EAAM,EACtB,SAAU3B,EAAejB,CAAK,CAChC,EAEA,OADI,KAAK0C,KAAU,IAAA,KAAWF,EAAI,KAAO,KAAKE,IACvCF,CACT,CACF,E"}
|
package/dist/prod/mdx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx.js","names":["isNode","value","dynamicSourceOf","moduleName","LOOKUP","DYNAMIC","elementsPlugin","rewritten","pending","tree","node","child","opening","\"openingElement\"","closing","\"closingElement\"","lookupName","\"name\"","tag","mode","identifier","\"attributes\"","\"body\"","dynamicSource","name","object","\"object\"","property","\"property\"","DEFAULT_INCLUDE","DEFAULT_EXCLUDE","loadMdx","loaded","specifier","cause","compileMdx","file","options","shadowMdx","plugins","validatePlugins","include","statelessPattern","exclude","dev","env","moduleFile","id","skip","mdx","jsx","mdxMap","output","code","MappingCollector","rawMapOf","error","found","position","result","compile","transformOptions","diagnostic","composeToSource","mapOfSource","CompileError","mappings","names","pattern"],"sources":["../../src/mdx.ts"],"sourcesContent":["import { CompileError, type CompilerPlugin, compile, validatePlugins } from \"@shadow-js/compiler\";\nimport type { Plugin } from \"vite\";\nimport { moduleFile } from \"./internal/ids\";\nimport {\n composeToSource,\n MappingCollector,\n mapOfSource,\n type RawMap,\n} from \"./internal/source-maps\";\n\n/**\n * `shadowMdx()`: a Vite plugin that turns `.mdx` (and `.md`) files into ShadowJS components. MDX is compiled to JSX by\n * `@mdx-js/mdx`, an optional peer, and the JSX goes through the ShadowJS compiler in the same step, so an MDX file needs no\n * other plugin to be compiled. The default export of a module is the component; the `export`s of the file (a `frontmatter`\n * from `remark-mdx-frontmatter`, a `meta` object) are named exports.\n * @packageDocumentation\n */\n\n/** The file `@mdx-js/mdx` answers: a `VFile`, whose `value` holds the code. */\ninterface MdxOutput {\n readonly value: string | Uint8Array;\n /** The source map of `value` to the MDX file, when the options carried a `SourceMapGenerator` that records one. */\n readonly map?: unknown;\n}\n\n/** What `compile` of `@mdx-js/mdx` accepts (the options this plugin sets, and the lists it hands on). */\ninterface MdxCompileOptions {\n readonly jsx: true;\n readonly jsxImportSource: string;\n readonly development: false;\n readonly format: \"mdx\" | \"md\";\n readonly remarkPlugins?: readonly unknown[];\n readonly rehypePlugins?: readonly unknown[];\n readonly recmaPlugins?: readonly unknown[];\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n readonly providerImportSource?: string;\n /** Asks for a source map from the JSX to the MDX file (`file.map` of the answer). */\n readonly SourceMapGenerator: typeof MappingCollector;\n}\n\n/** `compile` of `@mdx-js/mdx`, or a function with its shape. @since 1.0.0 */\nexport type MdxCompile = (\n file: { readonly value: string; readonly path: string },\n options: MdxCompileOptions,\n) => Promise<MdxOutput>;\n\n/** Options of {@link shadowMdx}. @since 1.0.0 */\nexport interface ShadowMdxOptions {\n /** Files to compile, matched against the module id without its query string. Default `/\\.mdx$/`. Add `.md` to read Markdown files too. */\n readonly include?: RegExp;\n /** Files to skip; checked first. Default: any path with a `node_modules` segment. */\n readonly exclude?: RegExp;\n /** Plugins of the Markdown syntax tree (`remark-frontmatter`, `remark-mdx-frontmatter`, `remark-gfm`, ...), as `@mdx-js/mdx` takes them. */\n readonly remarkPlugins?: readonly unknown[];\n /** Plugins of the HTML syntax tree (`rehype-slug`, `rehype-autolink-headings`, ...). */\n readonly rehypePlugins?: readonly unknown[];\n /** Plugins of the JavaScript syntax tree. They run before the plugin's own pass over the elements. */\n readonly recmaPlugins?: readonly unknown[];\n /**\n * How the elements of Markdown (`h1`, `p`, `a`, `code`, ...) are rendered.\n *\n * - `\"overridable\"`: each one is looked up in the `components` prop (and the provider), so an app can replace `a` or `h1`\n * for every page. Each looked-up element is rendered by `Dynamic`.\n * - `\"static\"`: each one is a plain element in the page's template, cloned in one call. The `components` prop still\n * supplies components the file names itself (`<Chart />`) and the `wrapper`, but cannot replace `h1` or `a`.\n *\n * Choose `\"static\"` for pages that never replace a Markdown element: documentation and blog posts render faster and ship\n * less code.\n * @default \"overridable\"\n */\n readonly elements?: \"overridable\" | \"static\";\n /** Options of `remark-rehype`. */\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n /**\n * A module that exports `useMDXComponents`, whose components every MDX file may use without a `components` prop (the\n * way `@mdx-js/react` works for React). Default: none; pass `components` to the file's component instead.\n */\n readonly providerImportSource?: string;\n /** `@mdx-js/mdx`, by module name, or your own `compile`. Default `\"@mdx-js/mdx\"`. */\n readonly mdx?: string | MdxCompile;\n /** Compiler plugins that run on the JSX of every MDX file (see `ShadowPluginOptions.plugins`). */\n readonly plugins?: readonly CompilerPlugin[];\n /**\n * Module the compiled code imports its runtime helpers from. Default `\"@shadow-js/web\"` (`\"@shadow-js/web/server\"` for SSR).\n * With `elements: \"overridable\"` the file also imports `Dynamic` from it, so a custom module must export `Dynamic`;\n * `\"@shadow-js/web/server\"` has none, so `Dynamic` is then imported from `\"@shadow-js/web\"`.\n */\n readonly moduleName?: string;\n}\n\n/** A node of the JavaScript syntax tree `@mdx-js/mdx` hands to recma plugins (ESTree with JSX), read structurally. */\ninterface EsNode {\n type: string;\n [key: string]: unknown;\n}\n\nfunction isNode(value: unknown): value is EsNode {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\n/**\n * The module `Dynamic` is imported from: the one `moduleName` names, so a project that points the runtime at\n * its own module (an alias, a re-export) does not need `@shadow-js/web` resolvable as well. The one exception\n * is the SSR helpers entry `@shadow-js/web/server`: it holds the server helpers and no `Dynamic`, which the\n * main entry provides (and Vite resolves to its server build in an SSR build).\n */\nfunction dynamicSourceOf(moduleName: string | undefined): string {\n if (moduleName === undefined || moduleName === \"@shadow-js/web/server\") return \"@shadow-js/web\";\n return moduleName;\n}\n\n/** The identifier `@mdx-js/mdx` binds the element lookup table to. */\nconst LOOKUP = \"_components\";\n/** The local name of `Dynamic`: it cannot clash with a name the file exports or imports. */\nconst DYNAMIC = \"_ShadowDynamic\";\n\n/**\n * Rewrites the elements `@mdx-js/mdx` looks up in its table (`<_components.h1>`): into plain `<h1>` for `\"static\"`, into\n * `<Dynamic component={_components.h1}>` for `\"overridable\"`. The lookup yields a string for a default element and a\n * function for an override, and a ShadowJS component tag must be a function.\n */\nfunction elementsPlugin(\n mode: \"overridable\" | \"static\",\n dynamicSource: string,\n): () => (tree: EsNode) => void {\n return () => (tree) => {\n let rewritten = 0;\n const pending: unknown[] = [tree];\n while (pending.length > 0) {\n const node = pending.pop();\n if (Array.isArray(node)) {\n for (const child of node) pending.push(child);\n continue;\n }\n if (!isNode(node)) continue;\n if (node.type === \"JSXElement\") {\n const opening = node[\"openingElement\"];\n const closing = node[\"closingElement\"];\n if (isNode(opening) && lookupName(opening[\"name\"]) !== undefined) {\n const tag = lookupName(opening[\"name\"]) as string;\n if (mode === \"static\") {\n opening[\"name\"] = identifier(tag);\n } else {\n opening[\"name\"] = identifier(DYNAMIC);\n const attributes = opening[\"attributes\"] as unknown[];\n attributes.unshift({\n type: \"JSXAttribute\",\n name: identifier(\"component\"),\n value: {\n type: \"JSXExpressionContainer\",\n expression: {\n type: \"MemberExpression\",\n object: { type: \"Identifier\", name: LOOKUP },\n property: { type: \"Identifier\", name: tag },\n computed: false,\n optional: false,\n },\n },\n });\n rewritten += 1;\n }\n if (isNode(closing)) closing[\"name\"] = identifier(mode === \"static\" ? tag : DYNAMIC);\n }\n }\n for (const value of Object.values(node)) {\n if (typeof value === \"object\" && value !== null) pending.push(value);\n }\n }\n if (rewritten > 0) {\n const body = tree[\"body\"] as unknown[];\n body.unshift({\n type: \"ImportDeclaration\",\n specifiers: [\n {\n type: \"ImportSpecifier\",\n imported: { type: \"Identifier\", name: \"Dynamic\" },\n local: { type: \"Identifier\", name: DYNAMIC },\n },\n ],\n source: { type: \"Literal\", value: dynamicSource, raw: JSON.stringify(dynamicSource) },\n attributes: [],\n });\n }\n };\n}\n\n/** The element name of `_components.name` as a JSX tag name, otherwise `undefined`. */\nfunction lookupName(name: unknown): string | undefined {\n if (!isNode(name) || name.type !== \"JSXMemberExpression\") return undefined;\n const object = name[\"object\"];\n const property = name[\"property\"];\n if (!isNode(object) || object.type !== \"JSXIdentifier\" || object[\"name\"] !== LOOKUP)\n return undefined;\n return isNode(property) && typeof property[\"name\"] === \"string\" ? property[\"name\"] : undefined;\n}\n\nfunction identifier(name: string): EsNode {\n return { type: \"JSXIdentifier\", name };\n}\n\nconst DEFAULT_INCLUDE = /\\.mdx$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n\n/** `@mdx-js/mdx` warns with a position; so do the errors of its parsers. */\ninterface Positioned {\n readonly message?: string;\n readonly line?: number | null;\n readonly column?: number | null;\n readonly reason?: string;\n}\n\nasync function loadMdx(specifier: string): Promise<MdxCompile> {\n let loaded: { compile?: unknown };\n try {\n loaded = (await import(specifier)) as { compile?: unknown };\n } catch (cause) {\n throw new Error(\n `shadowMdx: cannot load \"${specifier}\". Install it with \"npm install --save-dev ${specifier}\", or pass your own function as mdx.`,\n { cause },\n );\n }\n if (typeof loaded.compile !== \"function\") {\n throw new TypeError(`shadowMdx: the module \"${specifier}\" has no compile function.`);\n }\n const compileMdx = loaded.compile;\n return (file, options) =>\n Reflect.apply(compileMdx, undefined, [file, options]) as Promise<MdxOutput>;\n}\n\n/**\n * Creates the plugin that compiles MDX to ShadowJS components. It runs before Vite's own handling (`enforce: \"pre\"`), so Vite\n * never sees MDX or JSX. A file is compiled for the browser, or for the server in an SSR build; a syntax error in the MDX is\n * reported with its file, line and column. Hot updates reload the page: an MDX file has no component state worth keeping.\n *\n * @param options Which files, the remark, rehype and recma plugins, and the MDX compiler.\n * @returns A Vite plugin named `shadowjs-mdx`.\n * @throws TypeError when `include` or `exclude` is not a `RegExp`, or `plugins` is not a list of valid compiler plugins.\n * @example\n * // vite.config.ts\n * import { shadow } from \"@shadow-js/vite\";\n * import { shadowMdx } from \"@shadow-js/vite/mdx\";\n * import remarkFrontmatter from \"remark-frontmatter\";\n * import remarkMdxFrontmatter from \"remark-mdx-frontmatter\";\n *\n * export default {\n * plugins: [\n * shadowMdx({ remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter] }),\n * shadow(),\n * ],\n * };\n * @since 1.0.0\n */\nexport function shadowMdx(options: ShadowMdxOptions = {}): Plugin {\n for (const name of [\"include\", \"exclude\"] as const) {\n const value = options[name];\n if (value !== undefined && !(value instanceof RegExp)) {\n throw new TypeError(`shadowMdx(): \"${name}\" must be a RegExp (got ${typeof value}).`);\n }\n }\n const plugins =\n options.plugins === undefined ? [] : validatePlugins(options.plugins, \"shadowMdx(): plugins\");\n const include = statelessPattern(options.include ?? DEFAULT_INCLUDE);\n const exclude = statelessPattern(options.exclude ?? DEFAULT_EXCLUDE);\n let compileMdx: Promise<MdxCompile> | undefined;\n let dev = false;\n return {\n name: \"shadowjs-mdx\",\n enforce: \"pre\",\n config(_config, env) {\n dev = env.command === \"serve\";\n },\n async transform(code, id, transformOptions) {\n const { file, skip } = moduleFile(id);\n if (skip || exclude.test(file) || !include.test(file)) return null;\n compileMdx ??=\n typeof options.mdx === \"function\"\n ? Promise.resolve(options.mdx)\n : loadMdx(options.mdx ?? \"@mdx-js/mdx\");\n const mdx = await compileMdx;\n let jsx: string;\n let mdxMap: RawMap | undefined;\n try {\n const output = await mdx(\n { value: code, path: file },\n {\n jsx: true,\n jsxImportSource: options.moduleName ?? \"@shadow-js/web\",\n development: false,\n format: file.endsWith(\".mdx\") ? \"mdx\" : \"md\",\n ...(options.remarkPlugins === undefined\n ? {}\n : { remarkPlugins: options.remarkPlugins }),\n ...(options.rehypePlugins === undefined\n ? {}\n : { rehypePlugins: options.rehypePlugins }),\n recmaPlugins: [\n ...(options.recmaPlugins ?? []),\n elementsPlugin(\n options.elements ?? \"overridable\",\n dynamicSourceOf(options.moduleName),\n ),\n ],\n ...(options.remarkRehypeOptions === undefined\n ? {}\n : { remarkRehypeOptions: options.remarkRehypeOptions }),\n ...(options.providerImportSource === undefined\n ? {}\n : { providerImportSource: options.providerImportSource }),\n SourceMapGenerator: MappingCollector,\n },\n );\n jsx =\n typeof output.value === \"string\"\n ? output.value\n : Buffer.from(output.value).toString(\"utf8\");\n mdxMap = rawMapOf(output.map);\n } catch (error) {\n const found = error as Positioned;\n const position =\n typeof found.line === \"number\" && found.line > 0\n ? { line: found.line, column: Math.max((found.column ?? 1) - 1, 0) }\n : undefined;\n return this.error(found.reason ?? found.message ?? String(error), position);\n }\n try {\n const result = compile(jsx, {\n filename: `${file}.tsx`,\n generate: transformOptions?.ssr === true ? \"ssr\" : \"dom\",\n dev,\n autoReactive: true,\n hmr: false,\n ...(options.moduleName === undefined ? {} : { moduleName: options.moduleName }),\n ...(plugins.length > 0 ? { plugins } : {}),\n });\n // The positions of the JSX pass are those of the JSX that `@mdx-js/mdx` wrote, not of the MDX file the build\n // names: passed on, they would point at lines and columns of the generated code (the message carries them).\n for (const diagnostic of result.diagnostics) {\n if (diagnostic.severity === \"warning\") this.warn(diagnostic.message);\n }\n // Without JSX to compile the code is what `@mdx-js/mdx` wrote, and its own map already points at the file.\n if (!result.transformed) {\n return { code: jsx, map: mdxMap === undefined ? null : mapOfSource(mdxMap, file, code) };\n }\n // A map from the final code to the JSX is of no use to a debugger: compose it with the one from the JSX\n // to the MDX file. When `@mdx-js/mdx` (or a replacement given as `mdx`) answered no map, it stays as it was.\n return {\n code: result.code,\n map:\n result.map === null || mdxMap === undefined\n ? result.map\n : composeToSource(result.map, mdxMap, file, code),\n };\n } catch (error) {\n if (error instanceof CompileError) return this.error(error.message);\n throw error;\n }\n },\n };\n}\n\n/** Reads the map `@mdx-js/mdx` answers with, or `undefined` when it gave none that can be used. */\nfunction rawMapOf(value: unknown): RawMap | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const { mappings, names } = value as { mappings?: unknown; names?: unknown };\n if (typeof mappings !== \"string\") return undefined;\n return {\n mappings,\n names: Array.isArray(names)\n ? names.filter((name): name is string => typeof name === \"string\")\n : [],\n };\n}\n\n/** The same pattern without the `g` and `y` flags, so `test()` does not remember where the last call ended. */\nfunction statelessPattern(pattern: RegExp): RegExp {\n return pattern.global || pattern.sticky\n ? new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, \"\"))\n : pattern;\n}\n"],"mappings":"A,uOAgGA,SAASA,EAAO,EAAiC,CAC/C,OACE,OAAOC,GAAU,YACjBA,GACA,OAAQA,EAA6B,MAAS,QAElD,CAQA,SAASC,EAAgB,EAAwC,CAE/D,OADIC,IAAe,IAAA,IAAaA,IAAe,wBAAgC,iBACxEA,CACT,CAGA,MAAMC,EAAS,cAETC,EAAU,iBAOhB,SAASC,EACP,EACA,EAC8B,CAC9B,UAAc,GAAS,CACrB,IAAIC,EAAY,EACVC,EAAqB,CAACC,CAAI,EAChC,KAAOD,EAAQ,OAAS,GAAG,CACzB,IAAME,EAAOF,EAAQ,IAAI,EACzB,GAAI,MAAM,QAAQE,CAAI,EACpB,IAAK,IAAMC,KAASD,EAAMF,EAAQ,KAAKG,CAAK,OAG9C,GAAKX,EAAOU,CAAI,EAChB,IAAIA,EAAK,OAAS,aAAc,CAC9B,IAAME,EAAUF,EAAKG,eACfC,EAAUJ,EAAKK,eACrB,GAAIf,EAAOY,CAAO,GAAKI,EAAWJ,EAAQK,IAAO,IAAM,IAAA,GAAW,CAChE,IAAMC,EAAMF,EAAWJ,EAAQK,IAAO,EAClCE,IAAS,SACX,EAAQF,KAAUG,EAAWF,CAAG,GAEhC,EAAQD,KAAUG,EAAWf,CAAO,EAEpCO,EAD2BS,WAChB,QAAQ,CACjB,KAAM,eACN,KAAMD,EAAW,WAAW,EAC5B,MAAO,CACL,KAAM,yBACN,WAAY,CACV,KAAM,mBACN,OAAQ,CAAE,KAAM,aAAc,KAAMhB,CAAO,EAC3C,SAAU,CAAE,KAAM,aAAc,KAAMc,CAAI,EAC1C,SAAU,GACV,SAAU,EACZ,CACF,CACF,CAAC,EACD,GAAa,GAEXlB,EAAOc,CAAO,IAAG,EAAQG,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AYb,EAAQf,EAAMiB,CAAI,CAAE,CAW3F,OAASG,EAAO,CACd,GAAIA,aAAiBS,EAAc,OAAO,KAAK,MAAMT,EAAM,OAAO,EAClE,MAAMA,CACR,CACF,CACF,CACF,CAGA,SAASD,EAAS,EAAoC,CACpD,GAAI,OAAOtD,GAAU,WAAYA,EAAgB,OACjD,GAAM,CAAE,WAAU,SAAUA,EAC5B,GAAI,OAAOiE,GAAa,SACxB,MAAO,CACL,WACA,MAAO,MAAM,QAAQC,CAAK,EACtBA,EAAM,OAAQ,GAAyB,OAAO3C,GAAS,QAAQ,EAC/D,CAAC,CACP,CACF,CAGA,SAASkB,EAAiB,EAAyB,CACjD,OAAO0B,EAAQ,QAAUA,EAAQ,OAC7B,IAAI,OAAOA,EAAQ,OAAQA,EAAQ,MAAM,QAAQ,QAAS,EAAE,CAAC,EAC7DA,CACN,C"}
|
|
1
|
+
{"version":3,"file":"mdx.js","names":["moduleFile","MappingCollector","composeToSource","mapOfSource","CompileError","compile","validatePlugins","isNode","value","dynamicSourceOf","moduleName","LOOKUP","DYNAMIC","elementsPlugin","mode","dynamicSource","tree","rewritten","pending","node","child","opening","\"openingElement\"","closing","\"closingElement\"","lookupName","\"name\"","tag","identifier","\"attributes\"","\"body\"","name","object","\"object\"","property","\"property\"","DEFAULT_INCLUDE","DEFAULT_EXCLUDE","loadMdx","specifier","loaded","cause","compileMdx","file","options","shadowMdx","plugins","include","statelessPattern","exclude","dev","_config","env","code","id","transformOptions","skip","mdx","jsx","mdxMap","output","rawMapOf","error","found","position","result","diagnostic","mappings","names","pattern"],"sources":["../../src/mdx.ts"],"sourcesContent":["import { CompileError, type CompilerPlugin, compile, validatePlugins } from \"@shadow-js/compiler\";\nimport type { Plugin } from \"vite\";\nimport { moduleFile } from \"./internal/ids\";\nimport {\n composeToSource,\n MappingCollector,\n mapOfSource,\n type RawMap,\n} from \"./internal/source-maps\";\n\n/**\n * `shadowMdx()`: a Vite plugin that turns `.mdx` (and `.md`) files into ShadowJS components. MDX is compiled to JSX by\n * `@mdx-js/mdx`, an optional peer, and the JSX goes through the ShadowJS compiler in the same step, so an MDX file needs no\n * other plugin to be compiled. The default export of a module is the component; the `export`s of the file (a `frontmatter`\n * from `remark-mdx-frontmatter`, a `meta` object) are named exports.\n * @packageDocumentation\n */\n\n/** The file `@mdx-js/mdx` answers: a `VFile`, whose `value` holds the code. */\ninterface MdxOutput {\n readonly value: string | Uint8Array;\n /** The source map of `value` to the MDX file, when the options carried a `SourceMapGenerator` that records one. */\n readonly map?: unknown;\n}\n\n/** What `compile` of `@mdx-js/mdx` accepts (the options this plugin sets, and the lists it hands on). */\ninterface MdxCompileOptions {\n readonly jsx: true;\n readonly jsxImportSource: string;\n readonly development: false;\n readonly format: \"mdx\" | \"md\";\n readonly remarkPlugins?: readonly unknown[];\n readonly rehypePlugins?: readonly unknown[];\n readonly recmaPlugins?: readonly unknown[];\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n readonly providerImportSource?: string;\n /** Asks for a source map from the JSX to the MDX file (`file.map` of the answer). */\n readonly SourceMapGenerator: typeof MappingCollector;\n}\n\n/** `compile` of `@mdx-js/mdx`, or a function with its shape. @since 1.0.0 */\nexport type MdxCompile = (\n file: { readonly value: string; readonly path: string },\n options: MdxCompileOptions,\n) => Promise<MdxOutput>;\n\n/** Options of {@link shadowMdx}. @since 1.0.0 */\nexport interface ShadowMdxOptions {\n /** Files to compile, matched against the module id without its query string. Default `/\\.mdx$/`. Add `.md` to read Markdown files too. */\n readonly include?: RegExp;\n /** Files to skip; checked first. Default: any path with a `node_modules` segment. */\n readonly exclude?: RegExp;\n /** Plugins of the Markdown syntax tree (`remark-frontmatter`, `remark-mdx-frontmatter`, `remark-gfm`, ...), as `@mdx-js/mdx` takes them. */\n readonly remarkPlugins?: readonly unknown[];\n /** Plugins of the HTML syntax tree (`rehype-slug`, `rehype-autolink-headings`, ...). */\n readonly rehypePlugins?: readonly unknown[];\n /** Plugins of the JavaScript syntax tree. They run before the plugin's own pass over the elements. */\n readonly recmaPlugins?: readonly unknown[];\n /**\n * How the elements of Markdown (`h1`, `p`, `a`, `code`, ...) are rendered.\n *\n * - `\"overridable\"`: each one is looked up in the `components` prop (and the provider), so an app can replace `a` or `h1`\n * for every page. Each looked-up element is rendered by `Dynamic`.\n * - `\"static\"`: each one is a plain element in the page's template, cloned in one call. The `components` prop still\n * supplies components the file names itself (`<Chart />`) and the `wrapper`, but cannot replace `h1` or `a`.\n *\n * Choose `\"static\"` for pages that never replace a Markdown element: documentation and blog posts render faster and ship\n * less code.\n * @default \"overridable\"\n */\n readonly elements?: \"overridable\" | \"static\";\n /** Options of `remark-rehype`. */\n readonly remarkRehypeOptions?: Readonly<Record<string, unknown>>;\n /**\n * A module that exports `useMDXComponents`, whose components every MDX file may use without a `components` prop (the\n * way `@mdx-js/react` works for React). Default: none; pass `components` to the file's component instead.\n */\n readonly providerImportSource?: string;\n /** `@mdx-js/mdx`, by module name, or your own `compile`. Default `\"@mdx-js/mdx\"`. */\n readonly mdx?: string | MdxCompile;\n /** Compiler plugins that run on the JSX of every MDX file (see `ShadowPluginOptions.plugins`). */\n readonly plugins?: readonly CompilerPlugin[];\n /**\n * Module the compiled code imports its runtime helpers from. Default `\"@shadow-js/web\"` (`\"@shadow-js/web/server\"` for SSR).\n * With `elements: \"overridable\"` the file also imports `Dynamic` from it, so a custom module must export `Dynamic`;\n * `\"@shadow-js/web/server\"` has none, so `Dynamic` is then imported from `\"@shadow-js/web\"`.\n */\n readonly moduleName?: string;\n}\n\n/** A node of the JavaScript syntax tree `@mdx-js/mdx` hands to recma plugins (ESTree with JSX), read structurally. */\ninterface EsNode {\n type: string;\n [key: string]: unknown;\n}\n\nfunction isNode(value: unknown): value is EsNode {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\n/**\n * The module `Dynamic` is imported from: the one `moduleName` names, so a project that points the runtime at\n * its own module (an alias, a re-export) does not need `@shadow-js/web` resolvable as well. The one exception\n * is the SSR helpers entry `@shadow-js/web/server`: it holds the server helpers and no `Dynamic`, which the\n * main entry provides (and Vite resolves to its server build in an SSR build).\n */\nfunction dynamicSourceOf(moduleName: string | undefined): string {\n if (moduleName === undefined || moduleName === \"@shadow-js/web/server\") return \"@shadow-js/web\";\n return moduleName;\n}\n\n/** The identifier `@mdx-js/mdx` binds the element lookup table to. */\nconst LOOKUP = \"_components\";\n/** The local name of `Dynamic`: it cannot clash with a name the file exports or imports. */\nconst DYNAMIC = \"_ShadowDynamic\";\n\n/**\n * Rewrites the elements `@mdx-js/mdx` looks up in its table (`<_components.h1>`): into plain `<h1>` for `\"static\"`, into\n * `<Dynamic component={_components.h1}>` for `\"overridable\"`. The lookup yields a string for a default element and a\n * function for an override, and a ShadowJS component tag must be a function.\n */\nfunction elementsPlugin(\n mode: \"overridable\" | \"static\",\n dynamicSource: string,\n): () => (tree: EsNode) => void {\n return () => (tree) => {\n let rewritten = 0;\n const pending: unknown[] = [tree];\n while (pending.length > 0) {\n const node = pending.pop();\n if (Array.isArray(node)) {\n for (const child of node) pending.push(child);\n continue;\n }\n if (!isNode(node)) continue;\n if (node.type === \"JSXElement\") {\n const opening = node[\"openingElement\"];\n const closing = node[\"closingElement\"];\n if (isNode(opening) && lookupName(opening[\"name\"]) !== undefined) {\n const tag = lookupName(opening[\"name\"]) as string;\n if (mode === \"static\") {\n opening[\"name\"] = identifier(tag);\n } else {\n opening[\"name\"] = identifier(DYNAMIC);\n const attributes = opening[\"attributes\"] as unknown[];\n attributes.unshift({\n type: \"JSXAttribute\",\n name: identifier(\"component\"),\n value: {\n type: \"JSXExpressionContainer\",\n expression: {\n type: \"MemberExpression\",\n object: { type: \"Identifier\", name: LOOKUP },\n property: { type: \"Identifier\", name: tag },\n computed: false,\n optional: false,\n },\n },\n });\n rewritten += 1;\n }\n if (isNode(closing)) closing[\"name\"] = identifier(mode === \"static\" ? tag : DYNAMIC);\n }\n }\n for (const value of Object.values(node)) {\n if (typeof value === \"object\" && value !== null) pending.push(value);\n }\n }\n if (rewritten > 0) {\n const body = tree[\"body\"] as unknown[];\n body.unshift({\n type: \"ImportDeclaration\",\n specifiers: [\n {\n type: \"ImportSpecifier\",\n imported: { type: \"Identifier\", name: \"Dynamic\" },\n local: { type: \"Identifier\", name: DYNAMIC },\n },\n ],\n source: { type: \"Literal\", value: dynamicSource, raw: JSON.stringify(dynamicSource) },\n attributes: [],\n });\n }\n };\n}\n\n/** The element name of `_components.name` as a JSX tag name, otherwise `undefined`. */\nfunction lookupName(name: unknown): string | undefined {\n if (!isNode(name) || name.type !== \"JSXMemberExpression\") return undefined;\n const object = name[\"object\"];\n const property = name[\"property\"];\n if (!isNode(object) || object.type !== \"JSXIdentifier\" || object[\"name\"] !== LOOKUP)\n return undefined;\n return isNode(property) && typeof property[\"name\"] === \"string\" ? property[\"name\"] : undefined;\n}\n\nfunction identifier(name: string): EsNode {\n return { type: \"JSXIdentifier\", name };\n}\n\nconst DEFAULT_INCLUDE = /\\.mdx$/;\nconst DEFAULT_EXCLUDE = /[\\\\/]node_modules[\\\\/]/;\n\n/** `@mdx-js/mdx` warns with a position; so do the errors of its parsers. */\ninterface Positioned {\n readonly message?: string;\n readonly line?: number | null;\n readonly column?: number | null;\n readonly reason?: string;\n}\n\nasync function loadMdx(specifier: string): Promise<MdxCompile> {\n let loaded: { compile?: unknown };\n try {\n loaded = (await import(specifier)) as { compile?: unknown };\n } catch (cause) {\n throw new Error(\n `shadowMdx: cannot load \"${specifier}\". Install it with \"npm install --save-dev ${specifier}\", or pass your own function as mdx.`,\n { cause },\n );\n }\n if (typeof loaded.compile !== \"function\") {\n throw new TypeError(`shadowMdx: the module \"${specifier}\" has no compile function.`);\n }\n const compileMdx = loaded.compile;\n return (file, options) =>\n Reflect.apply(compileMdx, undefined, [file, options]) as Promise<MdxOutput>;\n}\n\n/**\n * Creates the plugin that compiles MDX to ShadowJS components. It runs before Vite's own handling (`enforce: \"pre\"`), so Vite\n * never sees MDX or JSX. A file is compiled for the browser, or for the server in an SSR build; a syntax error in the MDX is\n * reported with its file, line and column. Hot updates reload the page: an MDX file has no component state worth keeping.\n *\n * @param options Which files, the remark, rehype and recma plugins, and the MDX compiler.\n * @returns A Vite plugin named `shadowjs-mdx`.\n * @throws TypeError when `include` or `exclude` is not a `RegExp`, or `plugins` is not a list of valid compiler plugins.\n * @example\n * // vite.config.ts\n * import { shadow } from \"@shadow-js/vite\";\n * import { shadowMdx } from \"@shadow-js/vite/mdx\";\n * import remarkFrontmatter from \"remark-frontmatter\";\n * import remarkMdxFrontmatter from \"remark-mdx-frontmatter\";\n *\n * export default {\n * plugins: [\n * shadowMdx({ remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter] }),\n * shadow(),\n * ],\n * };\n * @since 1.0.0\n */\nexport function shadowMdx(options: ShadowMdxOptions = {}): Plugin {\n for (const name of [\"include\", \"exclude\"] as const) {\n const value = options[name];\n if (value !== undefined && !(value instanceof RegExp)) {\n throw new TypeError(`shadowMdx(): \"${name}\" must be a RegExp (got ${typeof value}).`);\n }\n }\n const plugins =\n options.plugins === undefined ? [] : validatePlugins(options.plugins, \"shadowMdx(): plugins\");\n const include = statelessPattern(options.include ?? DEFAULT_INCLUDE);\n const exclude = statelessPattern(options.exclude ?? DEFAULT_EXCLUDE);\n let compileMdx: Promise<MdxCompile> | undefined;\n let dev = false;\n return {\n name: \"shadowjs-mdx\",\n enforce: \"pre\",\n config(_config, env) {\n dev = env.command === \"serve\";\n },\n async transform(code, id, transformOptions) {\n const { file, skip } = moduleFile(id);\n if (skip || exclude.test(file) || !include.test(file)) return null;\n compileMdx ??=\n typeof options.mdx === \"function\"\n ? Promise.resolve(options.mdx)\n : loadMdx(options.mdx ?? \"@mdx-js/mdx\");\n const mdx = await compileMdx;\n let jsx: string;\n let mdxMap: RawMap | undefined;\n try {\n const output = await mdx(\n { value: code, path: file },\n {\n jsx: true,\n jsxImportSource: options.moduleName ?? \"@shadow-js/web\",\n development: false,\n format: file.endsWith(\".mdx\") ? \"mdx\" : \"md\",\n ...(options.remarkPlugins === undefined\n ? {}\n : { remarkPlugins: options.remarkPlugins }),\n ...(options.rehypePlugins === undefined\n ? {}\n : { rehypePlugins: options.rehypePlugins }),\n recmaPlugins: [\n ...(options.recmaPlugins ?? []),\n elementsPlugin(\n options.elements ?? \"overridable\",\n dynamicSourceOf(options.moduleName),\n ),\n ],\n ...(options.remarkRehypeOptions === undefined\n ? {}\n : { remarkRehypeOptions: options.remarkRehypeOptions }),\n ...(options.providerImportSource === undefined\n ? {}\n : { providerImportSource: options.providerImportSource }),\n SourceMapGenerator: MappingCollector,\n },\n );\n jsx =\n typeof output.value === \"string\"\n ? output.value\n : Buffer.from(output.value).toString(\"utf8\");\n mdxMap = rawMapOf(output.map);\n } catch (error) {\n const found = error as Positioned;\n const position =\n typeof found.line === \"number\" && found.line > 0\n ? { line: found.line, column: Math.max((found.column ?? 1) - 1, 0) }\n : undefined;\n return this.error(found.reason ?? found.message ?? String(error), position);\n }\n try {\n const result = compile(jsx, {\n filename: `${file}.tsx`,\n generate: transformOptions?.ssr === true ? \"ssr\" : \"dom\",\n dev,\n autoReactive: true,\n hmr: false,\n ...(options.moduleName === undefined ? {} : { moduleName: options.moduleName }),\n ...(plugins.length > 0 ? { plugins } : {}),\n });\n // The positions of the JSX pass are those of the JSX that `@mdx-js/mdx` wrote, not of the MDX file the build\n // names: passed on, they would point at lines and columns of the generated code (the message carries them).\n for (const diagnostic of result.diagnostics) {\n if (diagnostic.severity === \"warning\") this.warn(diagnostic.message);\n }\n // Without JSX to compile the code is what `@mdx-js/mdx` wrote, and its own map already points at the file.\n if (!result.transformed) {\n return { code: jsx, map: mdxMap === undefined ? null : mapOfSource(mdxMap, file, code) };\n }\n // A map from the final code to the JSX is of no use to a debugger: compose it with the one from the JSX\n // to the MDX file. When `@mdx-js/mdx` (or a replacement given as `mdx`) answered no map, it stays as it was.\n return {\n code: result.code,\n map:\n result.map === null || mdxMap === undefined\n ? result.map\n : composeToSource(result.map, mdxMap, file, code),\n };\n } catch (error) {\n if (error instanceof CompileError) return this.error(error.message);\n throw error;\n }\n },\n };\n}\n\n/** Reads the map `@mdx-js/mdx` answers with, or `undefined` when it gave none that can be used. */\nfunction rawMapOf(value: unknown): RawMap | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const { mappings, names } = value as { mappings?: unknown; names?: unknown };\n if (typeof mappings !== \"string\") return undefined;\n return {\n mappings,\n names: Array.isArray(names)\n ? names.filter((name): name is string => typeof name === \"string\")\n : [],\n };\n}\n\n/** The same pattern without the `g` and `y` flags, so `test()` does not remember where the last call ended. */\nfunction statelessPattern(pattern: RegExp): RegExp {\n return pattern.global || pattern.sticky\n ? new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, \"\"))\n : pattern;\n}\n"],"mappings":"A,uOAgGA,SAASO,EAAOC,EAAiC,CAC/C,OACE,OAAOA,GAAU,YACjBA,GACA,OAAQA,EAA6B,MAAS,QAElD,CAQA,SAASC,EAAgBC,EAAwC,CAE/D,OADIA,IAAe,IAAA,IAAaA,IAAe,wBAAgC,iBACxEA,CACT,CAGA,MAAMC,EAAS,cAETC,EAAU,iBAOhB,SAASC,EACPC,EACAC,EAC8B,CAC9B,UAAcC,GAAS,CACrB,IAAIC,EAAY,EACVC,EAAqB,CAACF,CAAI,EAChC,KAAOE,EAAQ,OAAS,GAAG,CACzB,IAAMC,EAAOD,EAAQ,IAAI,EACzB,GAAI,MAAM,QAAQC,CAAI,EACpB,IAAK,IAAMC,KAASD,EAAMD,EAAQ,KAAKE,CAAK,OAG9C,GAAKb,EAAOY,CAAI,EAChB,IAAIA,EAAK,OAAS,aAAc,CAC9B,IAAME,EAAUF,EAAKG,eACfC,EAAUJ,EAAKK,eACrB,GAAIjB,EAAOc,CAAO,GAAKI,EAAWJ,EAAQK,IAAO,IAAM,IAAA,GAAW,CAChE,IAAMC,EAAMF,EAAWJ,EAAQK,IAAO,EAClCZ,IAAS,SACXO,EAAQK,KAAUE,EAAWD,CAAG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AAIE,EAAQ,OAAS,EAAI,CAAEA,SAAQ,EAAI,CAAC,CAC1C,CAAC,EAGD,IAAK,IAAMoB,KAAcD,EAAO,YAC1BC,EAAW,WAAa,WAAW,KAAK,KAAKA,EAAW,OAAO,EAQrE,OALKD,EAAO,YAKL,CACL,KAAMA,EAAO,KACb,IACEA,EAAO,MAAQ,MAAQN,IAAW,IAAA,GAC9BM,EAAO,IACP/D,EAAgB+D,EAAO,IAAKN,EAAQhB,EAAMU,CAAI,CACtD,EAVS,CAAE,KAAMK,EAAK,IAAKC,IAAW,IAAA,GAAY,KAAOxD,EAAYwD,EAAQhB,EAAMU,CAAI,CAAE,CAW3F,OAASS,EAAO,CACd,GAAIA,aAAiB1D,EAAc,OAAO,KAAK,MAAM0D,EAAM,OAAO,EAClE,MAAMA,CACR,CACF,CACF,CACF,CAGA,SAASD,EAASrD,EAAoC,CACpD,GAAI,OAAOA,GAAU,WAAYA,EAAgB,OACjD,GAAM,CAAE2D,WAAUC,SAAU5D,EAC5B,GAAI,OAAO2D,GAAa,SACxB,MAAO,CACLA,WACA,MAAO,MAAM,QAAQC,CAAK,EACtBA,EAAM,OAAQrC,GAAyB,OAAOA,GAAS,QAAQ,EAC/D,CAAC,CACP,CACF,CAGA,SAASiB,EAAiBqB,EAAyB,CACjD,OAAOA,EAAQ,QAAUA,EAAQ,OAC7B,IAAI,OAAOA,EAAQ,OAAQA,EAAQ,MAAM,QAAQ,QAAS,EAAE,CAAC,EAC7DA,CACN,C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shadow-js/vite",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A Vite plugin that compiles your JSX, builds for server rendering and sets up Vitest",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"typecheck": "tsc -p tsconfig.json"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@shadow-js/compiler": "1.1.
|
|
41
|
+
"@shadow-js/compiler": "1.1.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"vite": "^7.0.0 || ^8.0.0",
|
|
45
45
|
"@mdx-js/mdx": "^3.0.0",
|
|
46
|
-
"@shadow-js/web": "^1.1.
|
|
46
|
+
"@shadow-js/web": "^1.1.2"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"vite": {
|
|
@@ -57,21 +57,21 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@biomejs/biome": "2.
|
|
60
|
+
"@biomejs/biome": "2.6.6",
|
|
61
61
|
"@mdx-js/mdx": "3.1.1",
|
|
62
62
|
"@shadow-js/core": "*",
|
|
63
63
|
"@shadow-js/web": "*",
|
|
64
64
|
"@types/node": "^24.0.0",
|
|
65
|
-
"esbuild": "0.
|
|
65
|
+
"esbuild": "0.28.2",
|
|
66
66
|
"fast-check": "^4.10.2",
|
|
67
67
|
"happy-dom": "21.0.4",
|
|
68
68
|
"remark-frontmatter": "5.0.0",
|
|
69
69
|
"remark-gfm": "4.0.1",
|
|
70
70
|
"remark-mdx-frontmatter": "6.0.0",
|
|
71
|
-
"tsdown": "0.23.
|
|
71
|
+
"tsdown": "0.23.7",
|
|
72
72
|
"typescript": "7.0.2",
|
|
73
73
|
"vite": "8.3.3",
|
|
74
|
-
"vitest": "5.0
|
|
74
|
+
"vitest": "5.1.0"
|
|
75
75
|
},
|
|
76
76
|
"homepage": "https://shadowjs.net/guides/vite/",
|
|
77
77
|
"keywords": [
|