mirror of https://github.com/nodejs/corepack.git
fix: handle package managers with a bin array correctly (#20)
* test: fix tests on older versions of node * test: fix tests on Windows * fix: handle package managers with a bin array correctly
This commit is contained in:
parent
909c2e7d92
commit
1836d17b4f
|
|
@ -40,6 +40,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||
["@babel/core", "npm:7.11.0"],
|
||||
["@babel/plugin-proposal-class-properties", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4"],
|
||||
["@babel/plugin-proposal-decorators", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.5"],
|
||||
["@babel/plugin-proposal-nullish-coalescing-operator", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4"],
|
||||
["@babel/plugin-transform-modules-commonjs", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.8.3"],
|
||||
["@babel/preset-typescript", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4"],
|
||||
["@types/debug", "npm:4.1.5"],
|
||||
|
|
@ -487,6 +488,23 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||
"linkType": "HARD",
|
||||
}]
|
||||
]],
|
||||
["@babel/plugin-proposal-nullish-coalescing-operator", [
|
||||
["virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4", {
|
||||
"packageLocation": "./.yarn/$$virtual/@babel-plugin-proposal-nullish-coalescing-operator-virtual-bd98b5d760/0/cache/@babel-plugin-proposal-nullish-coalescing-operator-npm-7.10.4-dd7a5fdb9c-5a20d8bcbf.zip/node_modules/@babel/plugin-proposal-nullish-coalescing-operator/",
|
||||
"packageDependencies": [
|
||||
["@babel/plugin-proposal-nullish-coalescing-operator", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4"],
|
||||
["@babel/core", "npm:7.11.0"],
|
||||
["@babel/helper-plugin-utils", "npm:7.10.4"],
|
||||
["@babel/plugin-syntax-nullish-coalescing-operator", "virtual:bd98b5d760bf6764f08ba70bbf309191487113e76cad7ab625345d176aafe8794d4418a3d1cce882bd210ecae1f155ab0c4932e4314122ae5026a8a5bdfb6d0e#npm:7.8.3"],
|
||||
["@types/babel__core", null]
|
||||
],
|
||||
"packagePeers": [
|
||||
"@babel/core",
|
||||
"@types/babel__core"
|
||||
],
|
||||
"linkType": "HARD",
|
||||
}]
|
||||
]],
|
||||
["@babel/plugin-syntax-bigint", [
|
||||
["virtual:c35bc3215fec2d22c38f8c1112d7d34c3c55792cf1e9e148aa8755cb2680310d8e91f690f866e8073fe05de053b0487b1209bda10126d6a4d518f8f822a23126#npm:7.8.3", {
|
||||
"packageLocation": "./.yarn/$$virtual/@babel-plugin-syntax-bigint-virtual-cb6879adb0/0/cache/@babel-plugin-syntax-bigint-npm-7.8.3-b05d971e6c-8c9b610377.zip/node_modules/@babel/plugin-syntax-bigint/",
|
||||
|
|
@ -519,6 +537,22 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||
"linkType": "HARD",
|
||||
}]
|
||||
]],
|
||||
["@babel/plugin-syntax-nullish-coalescing-operator", [
|
||||
["virtual:bd98b5d760bf6764f08ba70bbf309191487113e76cad7ab625345d176aafe8794d4418a3d1cce882bd210ecae1f155ab0c4932e4314122ae5026a8a5bdfb6d0e#npm:7.8.3", {
|
||||
"packageLocation": "./.yarn/$$virtual/@babel-plugin-syntax-nullish-coalescing-operator-virtual-3353bb767f/0/cache/@babel-plugin-syntax-nullish-coalescing-operator-npm-7.8.3-8a723173b5-4ba0375375.zip/node_modules/@babel/plugin-syntax-nullish-coalescing-operator/",
|
||||
"packageDependencies": [
|
||||
["@babel/plugin-syntax-nullish-coalescing-operator", "virtual:bd98b5d760bf6764f08ba70bbf309191487113e76cad7ab625345d176aafe8794d4418a3d1cce882bd210ecae1f155ab0c4932e4314122ae5026a8a5bdfb6d0e#npm:7.8.3"],
|
||||
["@babel/core", "npm:7.11.0"],
|
||||
["@babel/helper-plugin-utils", "npm:7.8.3"],
|
||||
["@types/babel__core", null]
|
||||
],
|
||||
"packagePeers": [
|
||||
"@babel/core",
|
||||
"@types/babel__core"
|
||||
],
|
||||
"linkType": "HARD",
|
||||
}]
|
||||
]],
|
||||
["@babel/plugin-syntax-object-rest-spread", [
|
||||
["virtual:c35bc3215fec2d22c38f8c1112d7d34c3c55792cf1e9e148aa8755cb2680310d8e91f690f866e8073fe05de053b0487b1209bda10126d6a4d518f8f822a23126#npm:7.8.3", {
|
||||
"packageLocation": "./.yarn/$$virtual/@babel-plugin-syntax-object-rest-spread-virtual-229e140fb3/0/cache/@babel-plugin-syntax-object-rest-spread-npm-7.8.3-60bd05b6ae-db5dfb39fa.zip/node_modules/@babel/plugin-syntax-object-rest-spread/",
|
||||
|
|
@ -2568,6 +2602,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
|||
["@babel/core", "npm:7.11.0"],
|
||||
["@babel/plugin-proposal-class-properties", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4"],
|
||||
["@babel/plugin-proposal-decorators", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.5"],
|
||||
["@babel/plugin-proposal-nullish-coalescing-operator", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4"],
|
||||
["@babel/plugin-transform-modules-commonjs", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.8.3"],
|
||||
["@babel/preset-typescript", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:7.10.4"],
|
||||
["@types/debug", "npm:4.1.5"],
|
||||
|
|
|
|||
BIN
.yarn/cache/@babel-plugin-proposal-nullish-coalescing-operator-npm-7.10.4-dd7a5fdb9c-5a20d8bcbf.zip
vendored
Normal file
BIN
.yarn/cache/@babel-plugin-proposal-nullish-coalescing-operator-npm-7.10.4-dd7a5fdb9c-5a20d8bcbf.zip
vendored
Normal file
Binary file not shown.
BIN
.yarn/cache/@babel-plugin-syntax-nullish-coalescing-operator-npm-7.8.3-8a723173b5-4ba0375375.zip
vendored
Normal file
BIN
.yarn/cache/@babel-plugin-syntax-nullish-coalescing-operator-npm-7.8.3-8a723173b5-4ba0375375.zip
vendored
Normal file
Binary file not shown.
|
|
@ -6,5 +6,6 @@ module.exports = {
|
|||
[`@babel/plugin-proposal-decorators`, {legacy: true}],
|
||||
[`@babel/plugin-proposal-class-properties`, {loose: true}],
|
||||
[`@babel/plugin-transform-modules-commonjs`],
|
||||
[`@babel/plugin-proposal-nullish-coalescing-operator`],
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
"@babel/core": "^7.11.0",
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"@babel/plugin-proposal-decorators": "^7.10.5",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4",
|
||||
"@babel/plugin-transform-modules-commonjs": "^7.8.3",
|
||||
"@babel/preset-typescript": "^7.10.4",
|
||||
"@types/debug": "^4.1.5",
|
||||
|
|
|
|||
|
|
@ -130,7 +130,13 @@ export async function installVersion(installTarget: string, locator: Locator, {s
|
|||
export async function runVersion(installSpec: { location: string, spec: PackageManagerSpec }, locator: Locator, binName: string, args: Array<string>, context: Context) {
|
||||
let binPath: string | null = null;
|
||||
if (Array.isArray(installSpec.spec.bin)) {
|
||||
binPath = path.join(installSpec.location, `${binName}.js`);
|
||||
if (installSpec.spec.bin.some(bin => bin === binName)) {
|
||||
const parsedUrl = new URL(installSpec.spec.url);
|
||||
const ext = path.posix.extname(parsedUrl.pathname);
|
||||
if (ext === `.js`) {
|
||||
binPath = path.join(installSpec.location, path.posix.basename(parsedUrl.pathname));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const [name, dest] of Object.entries(installSpec.spec.bin)) {
|
||||
if (name === binName) {
|
||||
|
|
@ -141,7 +147,7 @@ export async function runVersion(installSpec: { location: string, spec: PackageM
|
|||
}
|
||||
|
||||
if (!binPath)
|
||||
throw new Error(`Assertion failed: Unable to locate bin path`);
|
||||
throw new Error(`Assertion failed: Unable to locate path for bin '${binName}'`);
|
||||
|
||||
return new Promise<number>((resolve, reject) => {
|
||||
process.on(`SIGINT`, () => {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {runCli} from './_runCli';
|
|||
const engine = new Engine();
|
||||
|
||||
beforeEach(async () => {
|
||||
process.env.COREPACK_HOME = await xfs.mktempPromise();
|
||||
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
|
||||
});
|
||||
|
||||
async function makeBin(cwd: PortablePath, name: Filename) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {runCli} from './_runCli';
|
|||
const engine = new Engine();
|
||||
|
||||
beforeEach(async () => {
|
||||
process.env.COREPACK_HOME = await xfs.mktempPromise();
|
||||
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
|
||||
});
|
||||
|
||||
async function makeBin(cwd: PortablePath, name: Filename) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import {Filename, ppath, xfs} from '@yarnpkg/fslib';
|
||||
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
|
||||
|
||||
import config from '../config.json';
|
||||
|
||||
import {runCli} from './_runCli';
|
||||
|
||||
beforeEach(async () => {
|
||||
process.env.COREPACK_HOME = await xfs.mktempPromise();
|
||||
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
|
||||
});
|
||||
|
||||
for (const [name, version] of [[`yarn`, `1.22.4`], [`yarn`, `2.0.0-rc.30`], [`pnpm`, `4.11.6`], [`npm`, `6.14.2`]]) {
|
||||
|
|
@ -169,7 +169,7 @@ it(`should support hydrating package managers from cached archives`, async () =>
|
|||
});
|
||||
|
||||
// Use a new cache
|
||||
process.env.COREPACK_HOME = await xfs.mktempPromise();
|
||||
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
|
||||
|
||||
// Disable the network to make sure we don't succeed by accident
|
||||
process.env.COREPACK_ENABLE_NETWORK = `0`;
|
||||
|
|
@ -193,3 +193,21 @@ it(`should support hydrating package managers from cached archives`, async () =>
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
it(`should support running package managers with bin array`, async () => {
|
||||
await xfs.mktempPromise(async cwd => {
|
||||
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
|
||||
packageManager: `yarn@2.2.2`,
|
||||
});
|
||||
|
||||
await expect(runCli(cwd, [`yarn`, `yarnpkg`, `--version`])).resolves.toMatchObject({
|
||||
stdout: `2.2.2\n`,
|
||||
exitCode: 0,
|
||||
});
|
||||
|
||||
await expect(runCli(cwd, [`yarn`, `yarn`, `--version`])).resolves.toMatchObject({
|
||||
stdout: `2.2.2\n`,
|
||||
exitCode: 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
24
yarn.lock
24
yarn.lock
|
|
@ -403,6 +403,18 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator@npm:^7.10.4":
|
||||
version: 7.10.4
|
||||
resolution: "@babel/plugin-proposal-nullish-coalescing-operator@npm:7.10.4"
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils": ^7.10.4
|
||||
"@babel/plugin-syntax-nullish-coalescing-operator": ^7.8.0
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.0.0-0
|
||||
checksum: 5a20d8bcbf2926dde3e9edcf847eaa5485d0d0fea76d0683ef1cafb11e0c35e46620391916283e1a9c0f76351e8c5ecccebf0d3a6bdf24559c5ad381433a0e3a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-syntax-bigint@npm:^7.0.0":
|
||||
version: 7.8.3
|
||||
resolution: "@babel/plugin-syntax-bigint@npm:7.8.3"
|
||||
|
|
@ -425,6 +437,17 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-syntax-nullish-coalescing-operator@npm:^7.8.0":
|
||||
version: 7.8.3
|
||||
resolution: "@babel/plugin-syntax-nullish-coalescing-operator@npm:7.8.3"
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils": ^7.8.0
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.0.0-0
|
||||
checksum: 4ba03753759a2d9783b792c060147a20f474f76c42edf77cbf89c6669f9f22ffb3cbba4facdd8ce651129db6089a81feca1f7e42da75244eabedecba37bd20be
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/plugin-syntax-object-rest-spread@npm:^7.0.0":
|
||||
version: 7.8.3
|
||||
resolution: "@babel/plugin-syntax-object-rest-spread@npm:7.8.3"
|
||||
|
|
@ -2212,6 +2235,7 @@ __metadata:
|
|||
"@babel/core": ^7.11.0
|
||||
"@babel/plugin-proposal-class-properties": ^7.10.4
|
||||
"@babel/plugin-proposal-decorators": ^7.10.5
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator": ^7.10.4
|
||||
"@babel/plugin-transform-modules-commonjs": ^7.8.3
|
||||
"@babel/preset-typescript": ^7.10.4
|
||||
"@types/debug": ^4.1.5
|
||||
|
|
|
|||
Loading…
Reference in New Issue