Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generate types for #imports #1329

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ export async function writeTypes(nitro: Nitro) {
}

let autoImportedTypes: string[] = [];
let autoImportExports: string;

if (nitro.unimport) {
await nitro.unimport.init();
autoImportExports = await nitro.unimport
.toExports(typesDir)
.then((r) => r.replace(/#internal\/nitro/g, runtimeDir));
pi0 marked this conversation as resolved.
Show resolved Hide resolved
pi0 marked this conversation as resolved.
Show resolved Hide resolved
autoImportedTypes = [
(
await nitro.unimport.generateTypeDeclarations({
Expand Down Expand Up @@ -184,7 +188,9 @@ declare module 'nitropack' {

buildFiles.push({
path: join(typesDir, "nitro-imports.d.ts"),
contents: [...autoImportedTypes, "export {}"].join("\n"),
contents: [...autoImportedTypes, autoImportExports || "export {}"].join(
"\n"
),
});

buildFiles.push({
Expand All @@ -210,12 +216,15 @@ declare module 'nitropack' {
jsx: "preserve",
jsxFactory: "h",
jsxFragmentFactory: "Fragment",
paths: nitro.options.typescript.internalPaths
? {
"#internal/nitro": [join(runtimeDir, "index")],
"#internal/nitro/*": [join(runtimeDir, "*")],
}
: {},
paths: {
"#imports": [join(typesDir, "nitro-imports")],
...(nitro.options.typescript.internalPaths
? {
"#internal/nitro": [join(runtimeDir, "index")],
"#internal/nitro/*": [join(runtimeDir, "*")],
}
: {}),
},
},
include: [
relative(tsconfigDir, join(typesDir, "nitro.d.ts")).replace(
Expand Down