diff --git a/recipes/correct-ts-specifiers/src/get-not-found-url.ts b/recipes/correct-ts-specifiers/src/get-not-found-url.ts index bc733d5..7c8a8e6 100644 --- a/recipes/correct-ts-specifiers/src/get-not-found-url.ts +++ b/recipes/correct-ts-specifiers/src/get-not-found-url.ts @@ -1,6 +1,6 @@ import { pathToFileURL } from 'node:url'; -import type { NodeError, ResolvedSpecifier } from './index.d.ts'; +import type { FSAbsolutePath, ResolvedSpecifier } from './index.d.ts'; -export const getNotFoundUrl = (err: NodeError) => +export const getNotFoundUrl = (err: NodeJS.ErrnoException & { url?: FSAbsolutePath }) => pathToFileURL(err?.url ?? err.message.split("'")[1])?.href as ResolvedSpecifier; diff --git a/recipes/correct-ts-specifiers/src/index.d.ts b/recipes/correct-ts-specifiers/src/index.d.ts index 76059db..f1c00c3 100644 --- a/recipes/correct-ts-specifiers/src/index.d.ts +++ b/recipes/correct-ts-specifiers/src/index.d.ts @@ -20,9 +20,3 @@ export type Specifier = URL['pathname'] | ResolvedSpecifier; * @example 'foo/bar' */ export type NodeModSpecifier = string | `${string}/${string}`; - -export type NodeError = Error & - Partial<{ - code: string; - url: FSAbsolutePath; - }>; diff --git a/recipes/correct-ts-specifiers/src/is-dir.ts b/recipes/correct-ts-specifiers/src/is-dir.ts index 8b859c1..894664a 100644 --- a/recipes/correct-ts-specifiers/src/is-dir.ts +++ b/recipes/correct-ts-specifiers/src/is-dir.ts @@ -2,7 +2,6 @@ import { lstat } from 'node:fs/promises'; import type { FSAbsolutePath, - NodeError, NodeModSpecifier, ResolvedSpecifier, Specifier, @@ -14,7 +13,7 @@ export async function isDir(parentPath: FSAbsolutePath | ResolvedSpecifier, spec try { resolvedSpecifier = resolveSpecifier(parentPath, specifier); } catch (err) { - if ((err as NodeError).code === 'ERR_MODULE_NOT_FOUND') return null; + if ((err as NodeJS.ErrnoException).code === 'ERR_MODULE_NOT_FOUND') return null; } try { diff --git a/recipes/correct-ts-specifiers/src/is-ignorable-specifier.ts b/recipes/correct-ts-specifiers/src/is-ignorable-specifier.ts index a6eda4f..83135c1 100644 --- a/recipes/correct-ts-specifiers/src/is-ignorable-specifier.ts +++ b/recipes/correct-ts-specifiers/src/is-ignorable-specifier.ts @@ -3,7 +3,7 @@ import { extname, sep } from 'node:path'; import { pathToFileURL } from 'node:url'; import { tsExts } from './exts.ts'; -import type { FSAbsolutePath, NodeError, ResolvedSpecifier, Specifier } from './index.d.ts'; +import type { FSAbsolutePath, ResolvedSpecifier, Specifier } from './index.d.ts'; import { resolvesToNodeModule } from './resolves-to-node-module.ts'; import { getNotFoundUrl } from './get-not-found-url.ts'; @@ -34,7 +34,10 @@ export function isIgnorableSpecifier(parentPath: FSAbsolutePath, specifier: stri pathToFileURL(parentPath).href, ) as ResolvedSpecifier; // [1] } catch (err) { - if (!(err instanceof Error) || !IGNORABLE_RESOLVE_ERRORS.has((err as NodeError).code!)) + if ( + !(err instanceof Error) + || !IGNORABLE_RESOLVE_ERRORS.has((err as NodeJS.ErrnoException).code!) + ) throw err; resolvedSpecifier = getNotFoundUrl(err); diff --git a/recipes/correct-ts-specifiers/src/resolve-specifier.ts b/recipes/correct-ts-specifiers/src/resolve-specifier.ts index 1eb237a..03380c3 100644 --- a/recipes/correct-ts-specifiers/src/resolve-specifier.ts +++ b/recipes/correct-ts-specifiers/src/resolve-specifier.ts @@ -4,7 +4,6 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; /* node:coverage disable */ import type { FSAbsolutePath, - NodeError, NodeModSpecifier, ResolvedSpecifier, Specifier, @@ -42,7 +41,7 @@ export function resolveSpecifier( if (!(err instanceof Error)) throw err; if ( - (err as NodeError).code === 'ERR_MODULE_NOT_FOUND' && + (err as NodeJS.ErrnoException).code === 'ERR_MODULE_NOT_FOUND' && resolvesToNodeModule(getNotFoundUrl(err), parentUrl) ) { return specifier as NodeModSpecifier;