Skip to content

Commit

Permalink
fix(esbuild-plugin-pnp): return resolveDir from onLoad (#4597)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisd23 authored and merceyz committed Jul 1, 2022
1 parent 1be8591 commit 94e1233
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .yarn/versions/d54e2225.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releases:
"@yarnpkg/esbuild-plugin-pnp": patch

declined:
- "@yarnpkg/builder"
7 changes: 7 additions & 0 deletions packages/esbuild-plugin-pnp/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {PnpApi} from '@yarnpkg/pnp';
import type {OnLoadArgs, OnLoadResult, OnResolveArgs, OnResolveResult, Plugin, PluginBuild} from 'esbuild';
import * as fs from 'fs';
import path from 'path';

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

Expand Down

0 comments on commit 94e1233

Please sign in to comment.