Skip to content

Commit

Permalink
fix(esbuild-plugin-pnp): return resolveDir from esbuild pnp plugin on…
Browse files Browse the repository at this point in the history
…Load callback
  • Loading branch information
alisd23 committed Jul 1, 2022
1 parent 354dde2 commit 1fd1755
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .yarn/versions/d54e2225.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
releases:
"@yarnpkg/builder": patch
"@yarnpkg/esbuild-plugin-pnp": patch

declined:
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/cli"
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 1fd1755

Please sign in to comment.