From aecefd5d84c8ab8a53ded3f7a0041bd4e4e9b489 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 24 Feb 2023 14:44:09 +0100 Subject: [PATCH 1/2] refactor: use unimport built-in type gen for dirs --- examples/auto-imports/nitro.config.ts | 3 +++ examples/auto-imports/package.json | 11 +++++++++++ examples/auto-imports/routes/index.ts | 1 + examples/auto-imports/tsconfig.json | 3 +++ examples/auto-imports/utils/hello.ts | 3 +++ package.json | 2 +- pnpm-lock.yaml | 14 ++++++++++---- src/build.ts | 8 +------- 8 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 examples/auto-imports/nitro.config.ts create mode 100644 examples/auto-imports/package.json create mode 100644 examples/auto-imports/routes/index.ts create mode 100644 examples/auto-imports/tsconfig.json create mode 100644 examples/auto-imports/utils/hello.ts diff --git a/examples/auto-imports/nitro.config.ts b/examples/auto-imports/nitro.config.ts new file mode 100644 index 0000000000..0d2ca51b59 --- /dev/null +++ b/examples/auto-imports/nitro.config.ts @@ -0,0 +1,3 @@ +import { defineNitroConfig } from "nitropack"; + +export default defineNitroConfig({}); diff --git a/examples/auto-imports/package.json b/examples/auto-imports/package.json new file mode 100644 index 0000000000..9629263db6 --- /dev/null +++ b/examples/auto-imports/package.json @@ -0,0 +1,11 @@ +{ + "name": "example-auto-imports", + "private": true, + "scripts": { + "dev": "nitro dev", + "build": "nitro build" + }, + "devDependencies": { + "nitropack": "latest" + } +} diff --git a/examples/auto-imports/routes/index.ts b/examples/auto-imports/routes/index.ts new file mode 100644 index 0000000000..3f7c12620d --- /dev/null +++ b/examples/auto-imports/routes/index.ts @@ -0,0 +1 @@ +export default defineEventHandler(() => `

${makeGreeting('Nitro')}

`); diff --git a/examples/auto-imports/tsconfig.json b/examples/auto-imports/tsconfig.json new file mode 100644 index 0000000000..43008af1c7 --- /dev/null +++ b/examples/auto-imports/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "./.nitro/types/tsconfig.json" +} diff --git a/examples/auto-imports/utils/hello.ts b/examples/auto-imports/utils/hello.ts new file mode 100644 index 0000000000..5998a38077 --- /dev/null +++ b/examples/auto-imports/utils/hello.ts @@ -0,0 +1,3 @@ +export function makeGreeting(name: string) { + return `Hello, ${name}!`; +} diff --git a/package.json b/package.json index 6f76550b2a..5309c18670 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7deb52326f..a0eac4fb33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,7 +81,7 @@ importers: ufo: ^1.1.0 unbuild: ^1.1.2 unenv: ^1.2.1 - unimport: ^3.0.1 + unimport: ^3.0.2 unstorage: ^1.1.5 vitest: ^0.28.5 dependencies: @@ -141,7 +141,7 @@ importers: std-env: 3.3.2 ufo: 1.1.0 unenv: 1.2.1 - unimport: 3.0.1_rollup@3.17.2 + unimport: 3.0.2_rollup@3.17.2 unstorage: 1.1.5 devDependencies: '@types/aws-lambda': 8.10.110 @@ -170,6 +170,12 @@ importers: devDependencies: nitropack: link:../.. + examples/auto-imports: + specifiers: + nitropack: link:../.. + devDependencies: + nitropack: link:../.. + examples/cached-handler: specifiers: nitropack: link:../.. @@ -5167,8 +5173,8 @@ packages: pathe: 1.1.0 dev: false - /unimport/3.0.1_rollup@3.17.2: - resolution: {integrity: sha512-agdjfSLRp0Yi7qyRm3bwTdQR3NTN1JmuQmTj2b8hNZWTnphq5k4NugOad12t21ukD1uXvnYu1Tji7aNmzmCZGQ==} + /unimport/3.0.2_rollup@3.17.2: + resolution: {integrity: sha512-OQ0hShpcerS1PSsISsyn/NV2dGe5xfdUn4p5nwOodq0iqq5xxYQrTidHqlFGjxIliPDtDJp80OeySzyPTjYHmA==} dependencies: '@rollup/pluginutils': 5.0.2_rollup@3.17.2 escape-string-regexp: 5.0.0 diff --git a/src/build.ts b/src/build.ts index 096514f3c6..1091b3a746 100644 --- a/src/build.ts +++ b/src/build.ts @@ -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({ From 713410e5b14dfafdb1e89772ae27e9b61671737c Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 24 Feb 2023 14:46:20 +0100 Subject: [PATCH 2/2] chore: format --- src/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build.ts b/src/build.ts index 1091b3a746..edcefbb047 100644 --- a/src/build.ts +++ b/src/build.ts @@ -95,7 +95,7 @@ export async function writeTypes(nitro: Nitro) { let autoImportedTypes: string[] = []; if (nitro.unimport) { - await nitro.unimport.init() + await nitro.unimport.init(); autoImportedTypes = [ ( await nitro.unimport.generateTypeDeclarations({