Skip to content

Commit e7ffb52

Browse files
authored
Fixes the resolution when a package has an invalid "main" but a valid… (#6682)
* Fixes the resolution when a package has an invalid "main" but a valid "index.js" * Update CHANGELOG.md * Fixes the resolution when a package has an invalid "main" but a valid "index.js"
1 parent 8317ddf commit e7ffb52

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa
44

55
## Master
66

7+
- Fixes a resolution issue when a package had an invalid `main` entry
8+
9+
[#6682](https://github.com/yarnpkg/yarn/pull/6682) - [**Maël Nison**](https://twitter.com/arcanis)
10+
711
## 1.12.3
812

913
**Important:** This release contains a cache bump. It will cause the very first install following the upgrade to take slightly more time, especially if you don't use the [Offline Mirror](https://yarnpkg.com/blog/2016/11/24/offline-mirror/) feature. After that everything will be back to normal.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* @flow */
2+
3+
module.exports = require(`./package.json`);
4+
5+
for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
6+
for (const dep of Object.keys(module.exports[key] || {})) {
7+
// $FlowFixMe The whole point of this file is to be dynamic
8+
module.exports[key][dep] = require(dep);
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "invalid-main",
3+
"version": "1.0.0",
4+
"main": "DoesntExists"
5+
}

packages/pkg-tests/pkg-tests-specs/sources/pnp.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,26 @@ module.exports = makeTemporaryEnv => {
591591
}),
592592
);
593593

594+
test(
595+
`it should ignore the "main" entry if it doesn't resolve`,
596+
makeTemporaryEnv(
597+
{
598+
dependencies: {
599+
[`invalid-main`]: `1.0.0`,
600+
},
601+
},
602+
{plugNPlay: true},
603+
async ({path, run, source}) => {
604+
await run(`install`);
605+
606+
await expect(source(`require("invalid-main")`)).resolves.toMatchObject({
607+
name: `invalid-main`,
608+
version: `1.0.0`,
609+
});
610+
},
611+
),
612+
);
613+
594614
test(
595615
`it should use the regular Node resolution when requiring files outside of the pnp install tree`,
596616
makeTemporaryEnv({}, {plugNPlay: true}, async ({path, run, source}) => {

src/util/generate-pnp-map-api.tpl.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ function applyNodeExtensionResolution(unqualifiedPath, {extensions}) {
176176
// If the "main" field changed the path, we start again from this new location
177177

178178
if (nextUnqualifiedPath && nextUnqualifiedPath !== unqualifiedPath) {
179-
unqualifiedPath = nextUnqualifiedPath;
180-
continue;
179+
const resolution = applyNodeExtensionResolution(nextUnqualifiedPath, {extensions});
180+
181+
if (resolution !== null) {
182+
return resolution;
183+
}
181184
}
182185
}
183186

0 commit comments

Comments
 (0)