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

refactor: use unimport built-in type gen for dirs #994

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions examples/auto-imports/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineNitroConfig } from "nitropack";

export default defineNitroConfig({});
11 changes: 11 additions & 0 deletions examples/auto-imports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "example-auto-imports",
"private": true,
"scripts": {
"dev": "nitro dev",
"build": "nitro build"
},
"devDependencies": {
"nitropack": "latest"
}
}
1 change: 1 addition & 0 deletions examples/auto-imports/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default defineEventHandler(() => `<h1>${makeGreeting('Nitro')}</h1>`);
3 changes: 3 additions & 0 deletions examples/auto-imports/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nitro/types/tsconfig.json"
}
3 changes: 3 additions & 0 deletions examples/auto-imports/utils/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function makeGreeting(name: string) {
return `Hello, ${name}!`;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"std-env": "^3.3.2",
"ufo": "^1.1.0",
"unenv": "^1.2.1",
"unimport": "^3.0.1",
"unimport": "^3.0.2",
"unstorage": "^1.1.5"
},
"devDependencies": {
Expand Down
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ export async function writeTypes(nitro: Nitro) {
let autoImportedTypes: string[] = [];

if (nitro.unimport) {
await nitro.unimport.modifyDynamicImports(async () => {
const { dirs } = nitro.options.imports as { dirs: string[] };
return (await scanDirExports(dirs)).map((i) => ({
...i,
from: i.from.replace(/\.ts$/, ""),
}));
});
await nitro.unimport.init();
autoImportedTypes = [
(
await nitro.unimport.generateTypeDeclarations({
Expand Down