Skip to content
Draft
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
405 changes: 350 additions & 55 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"memoize-one": "^6.0.0",
"minimatch": "^9.0.4",
"os-name": "^6.0.0",
"oxc-resolver": "^11.16.3",
"p-event": "^6.0.0",
"p-filter": "^4.0.0",
"p-locate": "^6.0.0",
Expand All @@ -104,7 +105,6 @@
"ps-list": "^8.0.0",
"read-package-up": "^11.0.0",
"readdirp": "^4.0.0",
"resolve": "^2.0.0-next.5",
"rfdc": "^1.3.0",
"safe-json-stringify": "^1.2.0",
"semver": "^7.3.8",
Expand Down
45 changes: 0 additions & 45 deletions packages/build/src/utils/resolve.js

This file was deleted.

42 changes: 42 additions & 0 deletions packages/build/src/utils/resolve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* This module provides functions to resolve module paths using Node.js resolution.
*
* TODO(serhalp): Replace all this with `import.meta.resolve()` when all Node.js versions we support
* support it without a flag: https://nodejs.org/api/esm.html#importmetaresolvespecifier.
* This is 20.6.0+, so some time after April 2026.
*/
import { ResolverFactory } from 'oxc-resolver'

// Create a resolver instance with default Node.js resolution settings
const resolver = new ResolverFactory({
// Use standard Node.js module resolution
mainFields: ['main'],
conditionNames: ['node', 'require'],
extensions: ['.js', '.json', '.node'],
})

type ResolveSuccess = { path: string; error?: never }
type ResolveFailure = { path?: never; error: string }
type ResolveResult = ResolveSuccess | ResolveFailure

// Resolves a module path. Returns an error if the package cannot be found.
export const tryResolvePath = async function (path: string, basedir: string): Promise<ResolveResult> {
const result = await resolver.async(basedir, path)

if (result.error || !result.path) {
return { error: result.error ?? `Cannot resolve '${path}' from '${basedir}'` }
}

return { path: result.path }
}

// Resolves a module path. Throws if the package cannot be found.
export const resolvePath = async function (path: string, basedir: string): Promise<string> {
const result = await resolver.async(basedir, path)

if (result.error || !result.path) {
throw new Error(result.error ?? `Cannot resolve '${path}' from '${basedir}'`)
}

return result.path
}
8 changes: 5 additions & 3 deletions packages/build/tests/plugins/snapshots/tests.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,14 @@ Generated by [AVA](https://avajs.dev).
> Context␊
production␊
Configuration error ␊
Core internal error ␊
────────────────────────────────────────────────────────────────␊
Error message␊
Plugin could not be found using local path: ./plugin␊
Cannot find module './plugin'␊
TypeError: Cannot create property 'message' on string 'Cannot find module './plugin''␊
Error location␊
STACK TRACE␊
Resolved config␊
build:␊
Expand Down
Binary file modified packages/build/tests/plugins/snapshots/tests.js.snap
Binary file not shown.
Loading