Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the resolution when a package has an invalid "main" but a valid… #6682

Merged
merged 4 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Fixes a resolution issue when a package had an invalid `main` entry

[#6682](https://github.com/yarnpkg/yarn/pull/6682) - [**Maël Nison**](https://twitter.com/arcanis)

## 1.12.3

**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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow */

module.exports = require(`./package.json`);

for (const key of [`dependencies`, `devDependencies`, `peerDependencies`]) {
for (const dep of Object.keys(module.exports[key] || {})) {
// $FlowFixMe The whole point of this file is to be dynamic
module.exports[key][dep] = require(dep);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "invalid-main",
"version": "1.0.0",
"main": "DoesntExists"
}
20 changes: 20 additions & 0 deletions packages/pkg-tests/pkg-tests-specs/sources/pnp.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,26 @@ module.exports = makeTemporaryEnv => {
}),
);

test(
`it should ignore the "main" entry if it doesn't resolve`,
makeTemporaryEnv(
{
dependencies: {
[`invalid-main`]: `1.0.0`,
},
},
{plugNPlay: true},
async ({path, run, source}) => {
await run(`install`);

await expect(source(`require("invalid-main")`)).resolves.toMatchObject({
name: `invalid-main`,
version: `1.0.0`,
});
},
),
);

test(
`it should use the regular Node resolution when requiring files outside of the pnp install tree`,
makeTemporaryEnv({}, {plugNPlay: true}, async ({path, run, source}) => {
Expand Down
7 changes: 5 additions & 2 deletions src/util/generate-pnp-map-api.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ function applyNodeExtensionResolution(unqualifiedPath, {extensions}) {
// If the "main" field changed the path, we start again from this new location

if (nextUnqualifiedPath && nextUnqualifiedPath !== unqualifiedPath) {
unqualifiedPath = nextUnqualifiedPath;
continue;
const resolution = applyNodeExtensionResolution(nextUnqualifiedPath, {extensions});

if (resolution !== null) {
return resolution;
}
}
}

Expand Down