From 9607fb765720cdb7e21be16a3ffa27f9fca0c8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 2 Oct 2018 11:32:54 +0100 Subject: [PATCH 1/2] Injects a "process.versions.pnp" variable --- CHANGELOG.md | 4 ++++ src/util/generate-pnp-map-api.tpl.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d82605fdce..39fa89e394 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa [#6449](https://github.com/yarnpkg/yarn/pull/6449) - [**Maël Nison**](https://twitter.com/arcanis) +- Makes the PnP hook inject a `process.versions.pnp` variable when setup (equals to `VERSIONS.std`) + + [#6464](https://github.com/yarnpkg/yarn/pull/6464) - [**Maël Nison**](https://twitter.com/arcanis) + - Fixes the display name of the faulty package when the NPM registry returns corrupted data [#6455](https://github.com/yarnpkg/yarn/pull/6455) - [**Grey Baker**](https://github.com/greysteil) diff --git a/src/util/generate-pnp-map-api.tpl.js b/src/util/generate-pnp-map-api.tpl.js index 1eeeab5cfa..d8f5152100 100644 --- a/src/util/generate-pnp-map-api.tpl.js +++ b/src/util/generate-pnp-map-api.tpl.js @@ -677,6 +677,8 @@ exports.setup = function setup() { return false; }; + + process.versions.pnp = String(exports.VERSIONS.std); }; exports.setupCompatibilityLayer = () => { From c59869998c3c2d0ca0d81b59a6e0654218dfd517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 2 Oct 2018 11:38:32 +0100 Subject: [PATCH 2/2] Adds a test --- packages/pkg-tests/pkg-tests-specs/sources/pnp.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/pkg-tests/pkg-tests-specs/sources/pnp.js b/packages/pkg-tests/pkg-tests-specs/sources/pnp.js index 7ef06f1c84..3c70197991 100644 --- a/packages/pkg-tests/pkg-tests-specs/sources/pnp.js +++ b/packages/pkg-tests/pkg-tests-specs/sources/pnp.js @@ -523,7 +523,7 @@ module.exports = makeTemporaryEnv => { test( `it should export the PnP API through the 'pnpapi' name`, makeTemporaryEnv( - {dependencies: {[`no-deps`]: `1.0.0`}}, + {}, { plugNPlay: true, }, @@ -535,6 +535,19 @@ module.exports = makeTemporaryEnv => { ), ); + test( + `it should expose the PnP version through 'process.versions.pnp'`, + makeTemporaryEnv({}, {plugNPlay: true}, async ({path, run, source}) => { + await run(`install`); + + const pnpapiVersionsStd = await source(`require('pnpapi').VERSIONS.std`); + const processVersionsPnp = await source(`process.versions.pnp`); + + await expect(typeof processVersionsPnp).toEqual(`string`); + await expect(processVersionsPnp).toEqual(String(pnpapiVersionsStd)); + }), + ); + test( `it should not update the installConfig.pnp field of the package.json when installing with an environment override`, makeTemporaryEnv(