Skip to content

Commit

Permalink
Bumps Corepack
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Aug 18, 2021
1 parent bdfc703 commit 923a169
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 127 deletions.
8 changes: 7 additions & 1 deletion deps/corepack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ The utility commands detailed in the next section.

## Utility Commands

### `corepack <binary name>[@<version>] [... args]`

This meta-command runs the specified package manager in the local folder. You can use it to force an install to run with a given version, which can be useful when looking for regressions.

Note that those commands still check whether the local project is configured for the given package manager (ie you won't be able to run `corepack yarn install` on a project where the `packageManager` field references `pnpm`).

### `corepack enable [... name]`

| Option | Description |
Expand Down Expand Up @@ -117,7 +123,7 @@ This command will retrieve the given package manager from the specified archive

## Contributing

If you want to build corepack yourself things yourself, you can build the project like this:
If you want to build corepack yourself, you can build the project like this:

1. Clone this repository
2. Run `yarn build` (no need for `yarn install`)
Expand Down
182 changes: 114 additions & 68 deletions deps/corepack/dist/corepack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,19 @@ class Engine {
constructor(config = _config_json__WEBPACK_IMPORTED_MODULE_3__) {
this.config = config;
}
getPackageManagerFor(binaryName) {
for (const packageManager of _types__WEBPACK_IMPORTED_MODULE_7__.SupportedPackageManagerSet) {
for (const rangeDefinition of Object.values(this.config.definitions[packageManager].ranges)) {
const bins = Array.isArray(rangeDefinition.bin)
? rangeDefinition.bin
: Object.keys(rangeDefinition.bin);
if (bins.includes(binaryName)) {
return packageManager;
}
}
}
return null;
}
getBinariesFor(name) {
const binNames = new Set();
for (const rangeDefinition of Object.values(this.config.definitions[name].ranges)) {
Expand Down Expand Up @@ -14438,6 +14451,17 @@ module.exports = JSON.parse('{"definitions":{"npm":{"default":"7.20.1","transpar

/***/ }),

/***/ "./package.json":
/*!**********************!*\
!*** ./package.json ***!
\**********************/
/***/ ((module) => {

"use strict";
module.exports = JSON.parse('{"name":"corepack","version":"0.9.0","homepage":"https://github.com/nodejs/corepack#readme","bugs":{"url":"https://github.com/nodejs/corepack/issues"},"repository":{"type":"git","url":"https://github.com/nodejs/corepack.git"},"license":"MIT","bin":{"corepack":"./dist/corepack.js","pnpm":"./dist/pnpm.js","pnpx":"./dist/pnpx.js","yarn":"./dist/yarn.js","yarnpkg":"./dist/yarnpkg.js"},"packageManager":"yarn@3.0.0","devDependencies":{"@babel/core":"^7.14.3","@babel/plugin-proposal-class-properties":"^7.13.0","@babel/plugin-proposal-decorators":"^7.14.2","@babel/plugin-proposal-nullish-coalescing-operator":"^7.10.4","@babel/plugin-transform-modules-commonjs":"^7.14.0","@babel/preset-typescript":"^7.13.0","@types/debug":"^4.1.5","@types/jest":"^26.0.23","@types/node":"^13.9.2","@types/semver":"^7.1.0","@types/tar":"^4.0.3","@types/which":"^1.3.2","@typescript-eslint/eslint-plugin":"^2.0.0","@typescript-eslint/parser":"^4.2.0","@yarnpkg/eslint-config":"^0.1.0","@yarnpkg/fslib":"^2.1.0","@zkochan/cmd-shim":"^5.0.0","babel-plugin-dynamic-import-node":"^2.3.3","clipanion":"^3.0.1","debug":"^4.1.1","eslint":"^7.10.0","eslint-plugin-arca":"^0.9.5","jest":"^26.0.0","nock":"^13.0.4","semver":"^7.1.3","supports-color":"^7.1.0","tar":"^6.0.1","terser-webpack-plugin":"^5.1.2","ts-loader":"^8.0.2","ts-node":"^8.10.2","typescript":"^4.3.2","v8-compile-cache":"^2.3.0","webpack":"^5.38.1","webpack-cli":"^3.3.11","which":"^2.0.2"},"scripts":{"build":"rm -rf dist && webpack && ts-node ./mkshims.ts","corepack":"ts-node ./sources/main.ts","prepack":"node ./.yarn/releases/*.*js build","postpack":"rm -rf dist shims","test":"yarn jest"},"files":["dist","shims","LICENSE.md"],"publishConfig":{"executableFiles":["./dist/npm.js","./dist/npx.js","./dist/pnpm.js","./dist/pnpx.js","./dist/yarn.js","./dist/yarnpkg.js","./dist/corepack.js","./shims/npm","./shims/npm.ps1","./shims/npx","./shims/npx.ps1","./shims/pnpm","./shims/pnpm.ps1","./shims/pnpx","./shims/pnpx.ps1","./shims/yarn","./shims/yarn.ps1","./shims/yarnpkg","./shims/yarnpkg.ps1"]}}');

/***/ }),

/***/ "assert":
/*!*************************!*\
!*** external "assert" ***!
Expand Down Expand Up @@ -14702,7 +14726,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ "main": () => (/* binding */ main),
/* harmony export */ "runMain": () => (/* binding */ runMain)
/* harmony export */ });
/* harmony import */ var clipanion__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! clipanion */ "./.yarn/__virtual__/clipanion-virtual-119dc92083/0/cache/clipanion-npm-3.0.1-901533eeed-3a4b0c1e7d.zip/node_modules/clipanion/lib/advanced/index.js");
/* harmony import */ var clipanion__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! clipanion */ "./.yarn/__virtual__/clipanion-virtual-119dc92083/0/cache/clipanion-npm-3.0.1-901533eeed-3a4b0c1e7d.zip/node_modules/clipanion/lib/advanced/index.js");
/* harmony import */ var _Engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Engine */ "./sources/Engine.ts");
/* harmony import */ var _commands_Disable__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./commands/Disable */ "./sources/commands/Disable.ts");
/* harmony import */ var _commands_Enable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./commands/Enable */ "./sources/commands/Enable.ts");
Expand All @@ -14711,8 +14735,6 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _miscUtils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./miscUtils */ "./sources/miscUtils.ts");
/* harmony import */ var _pmmUtils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./pmmUtils */ "./sources/pmmUtils.ts");
/* harmony import */ var _specUtils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./specUtils */ "./sources/specUtils.ts");
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./types */ "./sources/types.ts");




Expand All @@ -14722,77 +14744,101 @@ __webpack_require__.r(__webpack_exports__);



async function main(argv, context) {
const firstArg = argv[0];
const [, candidatePackageManager, requestedVersion] = firstArg.match(/^([^@]*)(?:@(.*))?$/);
if ((0,_types__WEBPACK_IMPORTED_MODULE_8__.isSupportedPackageManager)(candidatePackageManager)) {
const packageManager = candidatePackageManager;
const binaryName = argv[1];
// Note: we're playing a bit with Clipanion here, since instead of letting it
// decide how to route the commands, we'll instead tweak the init settings
// based on the arguments.
const cli = new clipanion__WEBPACK_IMPORTED_MODULE_9__.Cli({ binaryName });
const defaultVersion = await context.engine.getDefaultVersion(packageManager);
class BinaryCommand extends clipanion__WEBPACK_IMPORTED_MODULE_9__.Command {
constructor() {
super(...arguments);
this.proxy = clipanion__WEBPACK_IMPORTED_MODULE_9__.Option.Proxy();
}
async execute() {
var _a;
const definition = context.engine.config.definitions[packageManager];
// If all leading segments match one of the patterns defined in the `transparent`
// key, we tolerate calling this binary even if the local project isn't explicitly
// configured for it, and we use the special default version if requested.
let isTransparentCommand = false;
for (const transparentPath of definition.transparent.commands) {
if (transparentPath[0] === binaryName && transparentPath.slice(1).every((segment, index) => segment === this.proxy[index])) {
isTransparentCommand = true;
break;
}
}
const fallbackReference = isTransparentCommand
? (_a = definition.transparent.default) !== null && _a !== void 0 ? _a : defaultVersion
: defaultVersion;
const fallbackLocator = {
name: packageManager,
reference: fallbackReference,
};
let descriptor;
try {
descriptor = await _specUtils__WEBPACK_IMPORTED_MODULE_7__.findProjectSpec(this.context.cwd, fallbackLocator, { transparent: isTransparentCommand });
}
catch (err) {
if (err instanceof _miscUtils__WEBPACK_IMPORTED_MODULE_5__.Cancellation) {
return 1;
}
else {
throw err;
}
}
if (requestedVersion)
descriptor.range = requestedVersion;
const resolved = await context.engine.resolveDescriptor(descriptor, { allowTags: true });
if (resolved === null)
throw new clipanion__WEBPACK_IMPORTED_MODULE_9__.UsageError(`Failed to successfully resolve '${descriptor.range}' to a valid ${descriptor.name} release`);
const installSpec = await context.engine.ensurePackageManager(resolved);
const exitCode = await _pmmUtils__WEBPACK_IMPORTED_MODULE_6__.runVersion(installSpec, resolved, binaryName, this.proxy, this.context);
return exitCode;
}
function getPackageManagerRequestFromCli(parameter, context) {
if (!parameter)
return null;
const match = parameter.match(/^([^@]*)(?:@(.*))?$/);
if (!match)
return null;
const [, binaryName, binaryVersion] = match;
const packageManager = context.engine.getPackageManagerFor(binaryName);
if (!packageManager)
return null;
return {
packageManager,
binaryName,
binaryVersion: binaryVersion || null,
};
}
async function executePackageManagerRequest({ packageManager, binaryName, binaryVersion }, args, context) {
var _a;
const defaultVersion = await context.engine.getDefaultVersion(packageManager);
const definition = context.engine.config.definitions[packageManager];
// If all leading segments match one of the patterns defined in the `transparent`
// key, we tolerate calling this binary even if the local project isn't explicitly
// configured for it, and we use the special default version if requested.
let isTransparentCommand = false;
for (const transparentPath of definition.transparent.commands) {
if (transparentPath[0] === binaryName && transparentPath.slice(1).every((segment, index) => segment === args[index])) {
isTransparentCommand = true;
break;
}
cli.register(BinaryCommand);
return await cli.run(argv.slice(2), Object.assign(Object.assign({}, clipanion__WEBPACK_IMPORTED_MODULE_9__.Cli.defaultContext), context));
}
else {
const binaryVersion = eval(`require`)(`corepack/package.json`).version;
const cli = new clipanion__WEBPACK_IMPORTED_MODULE_9__.Cli({ binaryName: `corepack`, binaryVersion });
cli.register(clipanion__WEBPACK_IMPORTED_MODULE_9__.Builtins.HelpCommand);
cli.register(clipanion__WEBPACK_IMPORTED_MODULE_9__.Builtins.VersionCommand);
const fallbackReference = isTransparentCommand
? (_a = definition.transparent.default) !== null && _a !== void 0 ? _a : defaultVersion
: defaultVersion;
const fallbackLocator = {
name: packageManager,
reference: fallbackReference,
};
let descriptor;
try {
descriptor = await _specUtils__WEBPACK_IMPORTED_MODULE_7__.findProjectSpec(context.cwd, fallbackLocator, { transparent: isTransparentCommand });
}
catch (err) {
if (err instanceof _miscUtils__WEBPACK_IMPORTED_MODULE_5__.Cancellation) {
return 1;
}
else {
throw err;
}
}
if (binaryVersion)
descriptor.range = binaryVersion;
const resolved = await context.engine.resolveDescriptor(descriptor, { allowTags: true });
if (resolved === null)
throw new clipanion__WEBPACK_IMPORTED_MODULE_8__.UsageError(`Failed to successfully resolve '${descriptor.range}' to a valid ${descriptor.name} release`);
const installSpec = await context.engine.ensurePackageManager(resolved);
const exitCode = await _pmmUtils__WEBPACK_IMPORTED_MODULE_6__.runVersion(installSpec, resolved, binaryName, args, context);
return exitCode;
}
async function main(argv, context) {
const corepackVersion = __webpack_require__(/*! ../package.json */ "./package.json").version;
const [firstArg, ...restArgs] = argv;
const request = getPackageManagerRequestFromCli(firstArg, context);
let cli;
if (!request) {
// If the first argument doesn't match any supported package manager, we fallback to the standard Corepack CLI
cli = new clipanion__WEBPACK_IMPORTED_MODULE_8__.Cli({
binaryLabel: `Corepack`,
binaryName: `corepack`,
binaryVersion: corepackVersion,
});
cli.register(clipanion__WEBPACK_IMPORTED_MODULE_8__.Builtins.HelpCommand);
cli.register(clipanion__WEBPACK_IMPORTED_MODULE_8__.Builtins.VersionCommand);
cli.register(_commands_Enable__WEBPACK_IMPORTED_MODULE_2__.EnableCommand);
cli.register(_commands_Disable__WEBPACK_IMPORTED_MODULE_1__.DisableCommand);
cli.register(_commands_Hydrate__WEBPACK_IMPORTED_MODULE_3__.HydrateCommand);
cli.register(_commands_Prepare__WEBPACK_IMPORTED_MODULE_4__.PrepareCommand);
return await cli.run(argv, Object.assign(Object.assign({}, clipanion__WEBPACK_IMPORTED_MODULE_9__.Cli.defaultContext), context));
return await cli.run(argv, Object.assign(Object.assign({}, clipanion__WEBPACK_IMPORTED_MODULE_8__.Cli.defaultContext), context));
}
else {
// Otherwise, we create a single-command CLI to run the specified package manager (we still use Clipanion in order to pretty-print usage errors).
const cli = new clipanion__WEBPACK_IMPORTED_MODULE_8__.Cli({
binaryLabel: `'${request.binaryName}', via Corepack`,
binaryName: request.binaryName,
binaryVersion: `corepack/${corepackVersion}`,
});
cli.register(class BinaryCommand extends clipanion__WEBPACK_IMPORTED_MODULE_8__.Command {
constructor() {
super(...arguments);
this.proxy = clipanion__WEBPACK_IMPORTED_MODULE_8__.Option.Proxy();
}
async execute() {
return executePackageManagerRequest(request, this.proxy, this.context);
}
});
return await cli.run(restArgs, Object.assign(Object.assign({}, clipanion__WEBPACK_IMPORTED_MODULE_8__.Cli.defaultContext), context));
}
}
function runMain(argv) {
Expand Down
2 changes: 1 addition & 1 deletion deps/corepack/dist/npm.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('./corepack').runMain(['npm', 'npm', ...process.argv.slice(2)]);
require('./corepack').runMain(['npm', ...process.argv.slice(2)]);
2 changes: 1 addition & 1 deletion deps/corepack/dist/npx.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('./corepack').runMain(['npm', 'npx', ...process.argv.slice(2)]);
require('./corepack').runMain(['npx', ...process.argv.slice(2)]);
2 changes: 1 addition & 1 deletion deps/corepack/dist/pnpm.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('./corepack').runMain(['pnpm', 'pnpm', ...process.argv.slice(2)]);
require('./corepack').runMain(['pnpm', ...process.argv.slice(2)]);
2 changes: 1 addition & 1 deletion deps/corepack/dist/pnpx.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('./corepack').runMain(['pnpm', 'pnpx', ...process.argv.slice(2)]);
require('./corepack').runMain(['pnpx', ...process.argv.slice(2)]);
2 changes: 1 addition & 1 deletion deps/corepack/dist/yarn.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('./corepack').runMain(['yarn', 'yarn', ...process.argv.slice(2)]);
require('./corepack').runMain(['yarn', ...process.argv.slice(2)]);
2 changes: 1 addition & 1 deletion deps/corepack/dist/yarnpkg.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('./corepack').runMain(['yarn', 'yarnpkg', ...process.argv.slice(2)]);
require('./corepack').runMain(['yarnpkg', ...process.argv.slice(2)]);
2 changes: 1 addition & 1 deletion deps/corepack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "corepack",
"version": "0.8.3",
"version": "0.9.0",
"homepage": "https://github.com/nodejs/corepack#readme",
"bugs": {
"url": "https://github.com/nodejs/corepack/issues"
Expand Down
12 changes: 0 additions & 12 deletions deps/corepack/shims/vcc

This file was deleted.

7 changes: 0 additions & 7 deletions deps/corepack/shims/vcc.cmd

This file was deleted.

28 changes: 0 additions & 28 deletions deps/corepack/shims/vcc.ps1

This file was deleted.

1 change: 0 additions & 1 deletion doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,5 @@ This field defines [subpath imports][] for the current package.
[subpath imports]: #packages_subpath_imports
[subpath patterns]: #packages_subpath_patterns
[supported package managers]: corepack.md#corepack_supported_package_managers
[the full specifier path]: esm.md#esm_mandatory_file_extensions
[the dual CommonJS/ES module packages section]: #packages_dual_commonjs_es_module_packages
[the full specifier path]: esm.md#esm_mandatory_file_extensions
3 changes: 1 addition & 2 deletions test/parallel/test-corepack-yarn-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const env = { ...process.env,
PATH: path.dirname(process.execPath),
NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'),
NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'),
HOME: homeDir,
};
HOME: homeDir };

exec(`${process.execPath} ${corepackYarnPath} install`, {
cwd: installDir,
Expand Down
2 changes: 1 addition & 1 deletion tools/license-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fi

addlicense "libuv" "deps/uv" "$(cat "${rootdir}"/deps/uv/LICENSE)"
addlicense "llhttp" "deps/llhttp" "$(cat deps/llhttp/LICENSE-MIT)"
addlicense "corepack" "deps/corepack" "$(cat ${rootdir}/deps/corepack/LICENSE.md)"
addlicense "corepack" "deps/corepack" "$(cat "${rootdir}"/deps/corepack/LICENSE.md)"
addlicense "OpenSSL" "deps/openssl" \
"$(sed -e '/^ \*\/$/,$d' -e '/^ [^*].*$/d' -e '/\/\*.*$/d' -e '/^$/d' -e 's/^[/ ]\* *//' "${rootdir}"/deps/openssl/openssl/LICENSE)"
addlicense "Punycode.js" "lib/punycode.js" \
Expand Down

0 comments on commit 923a169

Please sign in to comment.