Skip to content

Commit 1fd1755

Browse files
committed
fix(esbuild-plugin-pnp): return resolveDir from esbuild pnp plugin onLoad callback
1 parent 354dde2 commit 1fd1755

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

.yarn/versions/d54e2225.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
releases:
2+
"@yarnpkg/builder": patch
3+
"@yarnpkg/esbuild-plugin-pnp": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-constraints"
7+
- "@yarnpkg/plugin-exec"
8+
- "@yarnpkg/plugin-interactive-tools"
9+
- "@yarnpkg/plugin-stage"
10+
- "@yarnpkg/plugin-typescript"
11+
- "@yarnpkg/plugin-version"
12+
- "@yarnpkg/plugin-workspace-tools"
13+
- "@yarnpkg/cli"

packages/esbuild-plugin-pnp/sources/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {PnpApi} from '@yarnpkg/pnp';
22
import type {OnLoadArgs, OnLoadResult, OnResolveArgs, OnResolveResult, Plugin, PluginBuild} from 'esbuild';
33
import * as fs from 'fs';
4+
import path from 'path';
45

56
const matchAll = /()/;
67
const defaultExtensions = [`.tsx`, `.ts`, `.jsx`, `.mjs`, `.cjs`, `.js`, `.css`, `.json`];
@@ -54,6 +55,12 @@ async function defaultOnLoad(args: OnLoadArgs): Promise<OnLoadResult> {
5455
return {
5556
contents: await fs.promises.readFile(args.path),
5657
loader: `default`,
58+
// For regular imports in the `file` namespace, resolveDir is the directory the
59+
// file being resolved lives in. For all other virtual modules, this defaults to
60+
// empty string: ""
61+
// A sensible value for pnp imports is the same as the `file` namespace, as pnp
62+
// still resolves to files on disk (in the cache).
63+
resolveDir: path.dirname(args.path),
5764
};
5865
}
5966

0 commit comments

Comments
 (0)