Fixes symlink creation when install path has symlinks (#41)

This commit is contained in:
Maël Nison 2021-07-27 13:55:30 +02:00 committed by GitHub
parent 545f90f2b9
commit 7a034df587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 25 deletions

16
.pnp.cjs generated
View File

@ -53,7 +53,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@yarnpkg/fslib", "npm:2.1.0"],
["@zkochan/cmd-shim", "npm:5.0.0"],
["babel-plugin-dynamic-import-node", "npm:2.3.3"],
["clipanion", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.0-rc.12"],
["clipanion", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.1"],
["debug", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:4.1.1"],
["eslint", "npm:7.10.0"],
["eslint-plugin-arca", "npm:0.9.5"],
@ -2849,17 +2849,17 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
}]
]],
["clipanion", [
["npm:3.0.0-rc.12", {
"packageLocation": "./.yarn/cache/clipanion-npm-3.0.0-rc.12-95ffbe8b7e-a3824cbd11.zip/node_modules/clipanion/",
["npm:3.0.1", {
"packageLocation": "./.yarn/cache/clipanion-npm-3.0.1-901533eeed-3a4b0c1e7d.zip/node_modules/clipanion/",
"packageDependencies": [
["clipanion", "npm:3.0.0-rc.12"]
["clipanion", "npm:3.0.1"]
],
"linkType": "SOFT",
}],
["virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.0-rc.12", {
"packageLocation": "./.yarn/__virtual__/clipanion-virtual-5fe719a4f0/0/cache/clipanion-npm-3.0.0-rc.12-95ffbe8b7e-a3824cbd11.zip/node_modules/clipanion/",
["virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.1", {
"packageLocation": "./.yarn/__virtual__/clipanion-virtual-119dc92083/0/cache/clipanion-npm-3.0.1-901533eeed-3a4b0c1e7d.zip/node_modules/clipanion/",
"packageDependencies": [
["clipanion", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.0-rc.12"],
["clipanion", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.1"],
["@types/typanion", null],
["typanion", "npm:3.3.1"]
],
@ -3069,7 +3069,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@yarnpkg/fslib", "npm:2.1.0"],
["@zkochan/cmd-shim", "npm:5.0.0"],
["babel-plugin-dynamic-import-node", "npm:2.3.3"],
["clipanion", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.0-rc.12"],
["clipanion", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:3.0.1"],
["debug", "virtual:0bda696f47fa4339976f909c007f0dc954386da51b8923bf264010d9929618071aa538c29b76d4b6c53f7388a7d83508f2a5027eb81cfc74b39b9d4a0b1a8c5a#npm:4.1.1"],
["eslint", "npm:7.10.0"],
["eslint-plugin-arca", "npm:0.9.5"],

View File

@ -1,6 +1,6 @@
{
"name": "corepack",
"version": "0.8.1",
"version": "0.8.2",
"homepage": "https://github.com/nodejs/corepack#readme",
"bugs": {
"url": "https://github.com/nodejs/corepack/issues"
@ -37,7 +37,7 @@
"@yarnpkg/fslib": "^2.1.0",
"@zkochan/cmd-shim": "^5.0.0",
"babel-plugin-dynamic-import-node": "^2.3.3",
"clipanion": "^3.0.0-rc.12",
"clipanion": "^3.0.1",
"debug": "^4.1.1",
"eslint": "^7.10.0",
"eslint-plugin-arca": "^0.9.5",

View File

@ -46,6 +46,10 @@ export class EnableCommand extends Command<Context> {
if (typeof installDirectory === `undefined`)
installDirectory = path.dirname(await which(`corepack`));
// Otherwise the relative symlink we'll compute will be incorrect, if the
// install directory is within a symlink
installDirectory = fs.realpathSync(installDirectory);
// We use `eval` so that Webpack doesn't statically transform it.
const manifestPath = eval(`require`).resolve(`corepack/package.json`);

View File

@ -87,7 +87,8 @@ export async function main(argv: Array<string>, context: CustomContext & Partial
} else {
const cli = new Cli<Context>({binaryName: `corepack`});
cli.register(Builtins.HelpCommand as any);
cli.register(Builtins.HelpCommand);
cli.register(Builtins.VersionCommand);
cli.register(EnableCommand);
cli.register(DisableCommand);

View File

@ -1,4 +1,4 @@
import {StdioOptions, spawn} from 'child_process';
import {StdioOptions, spawn, ChildProcess} from 'child_process';
import fs from 'fs';
import path from 'path';
import semver from 'semver';
@ -164,7 +164,7 @@ export async function runVersion(installSpec: { location: string, spec: PackageM
? eval(`require`).resolve(`./vcc.js`)
: eval(`require`).resolve(`corepack/dist/vcc.js`);
const sub = spawn(process.execPath, [`--require`, v8CompileCache, binPath!, ...args], {
const child = spawn(process.execPath, [`--require`, v8CompileCache, binPath!, ...args], {
cwd: context.cwd,
stdio,
env: {
@ -173,16 +173,53 @@ export async function runVersion(installSpec: { location: string, spec: PackageM
},
});
if (context.stdin !== process.stdin)
context.stdin.pipe(sub.stdin!);
if (context.stdout !== process.stdout)
sub.stdout!.pipe(context.stdout);
if (context.stderr !== process.stderr)
sub.stderr!.pipe(context.stderr);
activeChildren.add(child);
if (activeChildren.size === 1) {
process.on(`SIGINT`, sigintHandler);
process.on(`SIGTERM`, sigtermHandler);
}
if (context.stdin !== process.stdin)
context.stdin.pipe(child.stdin!);
if (context.stdout !== process.stdout)
child.stdout!.pipe(context.stdout);
if (context.stderr !== process.stderr)
child.stderr!.pipe(context.stderr);
child.on(`error`, error => {
activeChildren.delete(child);
if (activeChildren.size === 0) {
process.off(`SIGINT`, sigintHandler);
process.off(`SIGTERM`, sigtermHandler);
}
reject(error);
});
child.on(`exit`, exitCode => {
activeChildren.delete(child);
if (activeChildren.size === 0) {
process.off(`SIGINT`, sigintHandler);
process.off(`SIGTERM`, sigtermHandler);
}
sub.on(`exit`, exitCode => {
resolve(exitCode !== null ? exitCode : 1);
});
});
}
const activeChildren = new Set<ChildProcess>();
function sigintHandler() {
// We don't want SIGINT to kill our process; we want it to kill the
// innermost process, whose end will cause our own to exit.
}
function sigtermHandler() {
for (const child of activeChildren) {
child.kill();
}
}

View File

@ -2190,14 +2190,14 @@ __metadata:
languageName: node
linkType: hard
"clipanion@npm:^3.0.0-rc.12":
version: 3.0.0-rc.12
resolution: "clipanion@npm:3.0.0-rc.12"
"clipanion@npm:^3.0.1":
version: 3.0.1
resolution: "clipanion@npm:3.0.1"
dependencies:
typanion: ^3.3.1
peerDependencies:
typanion: "*"
checksum: a3824cbd11df862b52b72bf69fe63b6fecc5f63c3cc48fc54af2ef6145eac78e021246bd5b0f5c10c4af0ddfc0503b169283142cd2f643f528109cc24548773f
checksum: 3a4b0c1e7d29a0f3c41860323494114a3533298134761e564b9057fe26ceef929a06da73cc3dfc0000e02c89ad7222984109a60213a212c10ea71ac6cacabc89
languageName: node
linkType: hard
@ -2375,7 +2375,7 @@ __metadata:
"@yarnpkg/fslib": ^2.1.0
"@zkochan/cmd-shim": ^5.0.0
babel-plugin-dynamic-import-node: ^2.3.3
clipanion: ^3.0.0-rc.12
clipanion: ^3.0.1
debug: ^4.1.1
eslint: ^7.10.0
eslint-plugin-arca: ^0.9.5