Skip to content

Commit ba33a3e

Browse files
committedOct 16, 2024··
feat(bundle): jsr mirroring support for forced types in patches
1 parent 82a9730 commit ba33a3e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
 

‎bundle/deno.lock

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bundle/ts/mirror/jsr.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function mirror(
3838
registryApi?: string
3939
cwd?: string
4040
logger?: Logger
41-
patches?: { inject?: record<string>; aliases?: { [key: string]: { [key: string]: Nullable<string> } } }
41+
patches?: { inject?: record<string>; types?: { [key: string]: boolean }; aliases?: { [key: string]: { [key: string]: Nullable<string> } } }
4242
},
4343
): Promise<{ files: record<string>; exports: record<string> }> {
4444
// List packages
@@ -103,7 +103,7 @@ export async function mirror(
103103
])
104104
} // Handle regular exports
105105
else {
106-
const symbols = await generate(jsr)
106+
const symbols = await generate(jsr, { path: paths.b, patches })
107107
output.files[path] = [...symbols.values()].map(({ content }) => content).join("\n")
108108
if (patches?.inject?.[paths.b]) {
109109
output.files[path] = `${patches.inject[paths.b]}\n${output.files[path]}`
@@ -169,13 +169,18 @@ export async function mirror(
169169
* This is computed by extracting `deno doc` information and re-attaching documentation and type information.
170170
* This is to ensure that it is properly documented once published back on the registry.
171171
*/
172-
async function generate(jsr: string) {
172+
async function generate(jsr: string, { path, patches }: { path: string; patches?: { types?: { [key: string]: boolean } } }) {
173173
const temp = await Deno.makeTempFile()
174174
const symbols = new Map<string, { type: boolean; content: string }>()
175175
try {
176176
await Deno.writeTextFile(temp, `export * from "${jsr}"\n`)
177177
const ast = await parseDoc(temp)
178-
for (const { kind, name, jsDoc, ..._ } of ast) {
178+
for (let { kind, name, jsDoc, ..._ } of ast) {
179+
let forced = false
180+
if (patches?.types?.[`${path}#${name}`]) {
181+
kind = "typeAlias"
182+
forced = true
183+
}
179184
const { stdout } = await command("deno", ["doc", "--filter", name, temp])
180185
const signature = stripAnsiCode(stdout).split("\n")[2]
181186
const type = ["interface", "typeAlias"].includes(kind)
@@ -206,7 +211,7 @@ async function generate(jsr: string) {
206211
break
207212
}
208213
}
209-
if ((!type) || (type && (!ast.some((node: { name: string; kind: string }) => node.name === name && node.kind !== kind)))) {
214+
if ((!type) || forced || (type && (!ast.some((node: { name: string; kind: string }) => node.name === name && node.kind !== kind)))) {
210215
lines.push(`export ${type ? "type " : ""}{ ${name} }`, "")
211216
}
212217
symbols.set(name, { type, content: lines.join("\n") })

0 commit comments

Comments
 (0)
Please sign in to comment.