Skip to content

Commit 6c007bb

Browse files
committed
Fixes importing the PnP API from ESM modules
1 parent 028eff9 commit 6c007bb

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

.pnp.loader.mjs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/fb5469c7.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-pnp": patch
4+
"@yarnpkg/pnp": patch
5+
6+
declined:
7+
- "@yarnpkg/plugin-compat"
8+
- "@yarnpkg/plugin-constraints"
9+
- "@yarnpkg/plugin-dlx"
10+
- "@yarnpkg/plugin-essentials"
11+
- "@yarnpkg/plugin-init"
12+
- "@yarnpkg/plugin-interactive-tools"
13+
- "@yarnpkg/plugin-nm"
14+
- "@yarnpkg/plugin-npm-cli"
15+
- "@yarnpkg/plugin-pack"
16+
- "@yarnpkg/plugin-patch"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"
25+
- "@yarnpkg/nm"
26+
- "@yarnpkg/pnpify"
27+
- "@yarnpkg/sdks"

packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ describe(`Plug'n'Play - ESM`, () => {
4646
),
4747
);
4848

49+
test(
50+
`it should be able to import the PnP API`,
51+
makeTemporaryEnv(
52+
{
53+
type: `module`,
54+
},
55+
async ({path, run, source}) => {
56+
await expect(run(`install`)).resolves.toMatchObject({code: 0});
57+
58+
await xfs.writeFilePromise(
59+
ppath.join(path, `index.js` as Filename),
60+
`import pnp from 'pnpapi';\nconsole.log(typeof pnp.resolveRequest)`,
61+
);
62+
63+
await expect(run(`node`, `./index.js`)).resolves.toMatchObject({
64+
code: 0,
65+
stdout: `function\n`,
66+
});
67+
},
68+
),
69+
);
70+
4971
test(
5072
`it should be able to import a dependency`,
5173
makeTemporaryEnv(

packages/yarnpkg-pnp/sources/esm-loader/built-loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-pnp/sources/esm-loader/hooks/resolve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function resolve(
8888

8989
// If the package.json doesn't list an `exports` field, Node will tolerate omitting the extension
9090
// https://github.com/nodejs/node/blob/0996eb71edbd47d9f9ec6153331255993fd6f0d1/lib/internal/modules/esm/resolve.js#L686-L691
91-
if (subPath === ``) {
91+
if (subPath === `` && dependencyName !== `pnpapi`) {
9292
const resolved = pnpapi.resolveToUnqualified(`${dependencyName}/package.json`, issuer);
9393
if (resolved) {
9494
const content = await loaderUtils.tryReadFile(resolved);

0 commit comments

Comments
 (0)