From db489e64b87c9633f138886edf6396f677b1594e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 25 Apr 2022 15:17:15 +0100 Subject: [PATCH 1/2] fix(nuxi): don't strip file extensions from dirs --- packages/nuxi/src/utils/prepare.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/nuxi/src/utils/prepare.ts b/packages/nuxi/src/utils/prepare.ts index 6bae37feff2..e4a4a8061df 100644 --- a/packages/nuxi/src/utils/prepare.ts +++ b/packages/nuxi/src/utils/prepare.ts @@ -1,4 +1,4 @@ -import { promises as fsp } from 'node:fs' +import { promises as fsp, statSync } from 'node:fs' import { isAbsolute, join, relative, resolve } from 'pathe' import { Nuxt, TSReference } from '@nuxt/schema' import defu from 'defu' @@ -43,18 +43,17 @@ export const writeTypes = async (nuxt: Nuxt) => { if (excludedAlias.some(re => re.test(alias))) { continue } - const path = aliases[alias].replace(/(?<=\w)\.\w+$/g, '') /* remove extension */ - const relativePath = isAbsolute(path) - ? relative(nuxt.options.rootDir, path) || '.' - : path - tsConfig.compilerOptions.paths[alias] = [relativePath] - - try { - const { isDirectory } = await fsp.stat(resolve(nuxt.options.rootDir, relativePath)) - if (isDirectory) { - tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`] - } - } catch { } + const relativePath = isAbsolute(aliases[alias]) + ? relative(nuxt.options.rootDir, aliases[alias]) || '.' + : aliases[alias] + + const stats = await fsp.stat(resolve(nuxt.options.rootDir, relativePath)).catch(() => null /* file does not exist */) + if (stats?.isDirectory()) { + tsConfig.compilerOptions.paths[alias] = [relativePath] + tsConfig.compilerOptions.paths[`${alias}/*`] = [`${relativePath}/*`] + } else { + tsConfig.compilerOptions.paths[alias] = [relativePath.replace(/(?<=\w)\.\w+$/g, '')] /* remove extension */ + } } const references: TSReference[] = [ From ae7ed09bd8faf6233bb2b0d86e94ee2ecf23eb0e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 25 Apr 2022 15:57:54 +0100 Subject: [PATCH 2/2] style: remove unused import --- packages/nuxi/src/utils/prepare.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/utils/prepare.ts b/packages/nuxi/src/utils/prepare.ts index e4a4a8061df..0710d9961f4 100644 --- a/packages/nuxi/src/utils/prepare.ts +++ b/packages/nuxi/src/utils/prepare.ts @@ -1,4 +1,4 @@ -import { promises as fsp, statSync } from 'node:fs' +import { promises as fsp } from 'node:fs' import { isAbsolute, join, relative, resolve } from 'pathe' import { Nuxt, TSReference } from '@nuxt/schema' import defu from 'defu'