Skip to content

Commit

Permalink
fix: avoid fallback if starting point cannot be resolved (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Mar 2, 2025
1 parent 9bfa19d commit 8a0e515
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
22 changes: 15 additions & 7 deletions src/resolve/internal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { isAbsolute, normalize } from "pathe";
import type { ResolveOptions } from "./types";
import { resolveModulePath } from "exsolve";
import { fileURLToPath } from "node:url";

export function _resolvePath(id: string, opts: ResolveOptions = {}) {
return (
resolveModulePath(id, {
try: true,
from: opts.parent || opts.url /* default is cwd */,
}) || id
);
export function _resolvePath(id: URL | string, opts: ResolveOptions = {}) {
if (id instanceof URL || id.startsWith("file://")) {
return normalize(fileURLToPath(id));
}

if (isAbsolute(id)) {
return normalize(id);
}

return resolveModulePath(id, {
...opts,
from: opts.from || opts.parent || opts.url /* default is cwd */,
});
}
14 changes: 10 additions & 4 deletions src/resolve/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { ResolveOptions as ExsolveResolveOptions } from "exsolve";

/**
* Represents the options for resolving paths with additional file finding capabilities.
*/
export type ResolveOptions = Omit<FindFileOptions, "startingFrom"> & {
/** @deprecated: use parent */ url?: string;
parent?: string;
};
export type ResolveOptions = Omit<FindFileOptions, "startingFrom"> &
ExsolveResolveOptions & {
/** @deprecated: use `from` */
url?: string;

/** @deprecated: use `from` */
parent?: string;
};

/**
* Options for reading files with optional caching.
Expand Down

0 comments on commit 8a0e515

Please sign in to comment.