Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
deps: Experiments with Corepack#35398
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
69911bbd6d71504f5ffbbf4293593b05d19143637b5241ce4869317d6c0fc66b23c9458cd84653d1303d6be2f5fcefcd66750c1683113b588014bdf2fc67bb7b785605d74b57b913333cb89ac6b33b13bd7d5d85ae3d05b704ea8cd23d9d9d8d6204f9c9389File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| **Copyright © Corepack contributors** | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # <img src="./icon.svg" height="25" /> corepack | ||
| Corepack is a zero-runtime-dependency Node script that acts as a bridge between Node projects and the package managers they are intended to be used with during development. In practical terms, **Corepack will let you use Yarn and pnpm without having to install them** - just like what currently happens with npm, which is shipped by Node by default. | ||
| **Important:** At the moment, Corepack only covers Yarn and pnpm. Given that we have little control on the npm project, we prefer to focus on the Yarn and pnpm use cases. As a result, Corepack doesn't have any effect at all on the way you use npm. | ||
| ## How to Install | ||
| ### Default Installs | ||
| Corepack isn't intended to be installed manually. While it's certainly possible, we're working with the Node TSC to provide Corepack by default starting from Node 15, thus ensuring that all package managers can be used with little to no friction. | ||
| ### Manual Installs | ||
| <details> | ||
| <summary>Click here to see how to install Corepack using npm</summary> | ||
| First uninstall your global Yarn and pnpm binaries (just leave npm). In general, you'd do this by running the following command: | ||
| ```shell | ||
| npm uninstall -g yarn pnpm | ||
| # That should be enough, but if you installed Yarn without going through npm it might | ||
| # be more tedious - for example, you might need to run `brew uninstall yarn` as well. | ||
| ``` | ||
| Then install Corepack: | ||
| ```shell | ||
| npm install -g corepack | ||
| ``` | ||
| We do acknowledge the irony and overhead of using npm to install Corepack, which is at least part of why the preferred option is to use the Corepack version that will be distributed along with Node itself. | ||
| </details> | ||
| ### Prebuilt Binaries | ||
| <details> | ||
| <summary>Click here to see how to download prebuilt Corepack Node distributions</summary> | ||
| We have a few prebuilt Node binaries (based on the [following branch](https://github.com/arcanis/node/tree/mael/pmm)) that you can just download, unpack somewhere, and add to your `PATH` environment variable. | ||
| 1. Go to [this page](https://github.com/arcanis/pmm/actions?query=workflow%3ABuild) | ||
| 2. Open the latest build (the one at the top) | ||
| 3. Download the right artifact (Linux or Darwin) | ||
| 4. Unzip the artifact, then untar it | ||
| 5. Add the `node-v15.0.0-nightlyYYYY-MM-DDXXXX-linux-x64/bin` directory to your `$PATH` | ||
| </details> | ||
| ## Usage | ||
| Just use your package managers as you usually would. Run `yarn install` in Yarn projects, `pnpm install` in pnpm projects, and `npm` in npm projects. Corepack will catch these calls, and depending on the situation: | ||
| - **If the local project is configured for the package manager you're using**, Corepack will silently download and cache the latest compatible version. | ||
| - **If the local project is configured for a different package manager**, Corepack will request you to run the command again using the right package manager - thus avoiding corruptions of your install artifacts. | ||
| - **If the local project isn't configured for any package manager**, Corepack will assume that you know what you're doing, and will use whatever package manager version has been pinned as "known good release". Check the relevant section for more details. | ||
| ## Known Good Releases | ||
| When running Yarn or pnpm within projects that don't list a supported package manager, Corepack will default to a set of Known Good Releases. In a way, you can compare this to Node, where each version ships with a specific version of npm. | ||
| The Known Good Releases can be updated system-wide using the `--activate` flag from the `corepack prepare` and `corepack hydrate` commands. | ||
| ## Offline Workflow | ||
| The utility commands detailed in the next section. | ||
| - Either you can use the network while building your container image, in which case you'll simply run `corepack prepare` to make sure that your image includes the Last Known Good release for the specified package manager. | ||
| - If you want to have *all* Last Known Good releases for all package managers, just use the `--all` flag which will do just that. | ||
| - Or you're publishing your project to a system where the network is unavailable, in which case you'll preemptively generate a package manager archive from your local computer (using `corepack prepare -o`) before storing it somewhere your container will be able to access (for example within your repository). After that it'll just be a matter of running `corepack hydrate <path/to/corepack.tgz>` to setup the cache. | ||
| ## Utility Commands | ||
| ### `corepack enable [... name]` | ||
| | Option | Description | | ||
| | --- | --- | | ||
| | `--install-directory` | Add the shims to the specified location | | ||
| This command will detect where Node is installed and will create shims next to it for each of the specified package managers (or all of them if the command is called without parameters). Note that the npm shims will not be installed unless explicitly requested, as npm is currently distributed with Node through other means. | ||
| ### `corepack disable [... name]` | ||
| | Option | Description | | ||
| | --- | --- | | ||
| | `--install-directory` | Remove the shims to the specified location | | ||
| This command will detect where Node is installed and will remove the shims from there. | ||
| ### `corepack prepare [... name@version]` | ||
| | Option | Description | | ||
| | --- | --- | | ||
| | `--all` | Prepare the "Last Known Good" version of all supported package managers | | ||
| | `-o,--output` | Also generate an archive containing the package managers | | ||
| | `--activate` | Also update the "Last Known Good" release | | ||
| This command will download the given package managers (or the one configured for the local project if no argument is passed in parameter) and store it within the Corepack cache. If the `-o,--output` flag is set (optionally with a path as parameter), an archive will also be generated that can be used by the `corepack hydrate` command. | ||
| ### `corepack hydrate <path/to/corepack.tgz>` | ||
| | Option | Description | | ||
| | --- | --- | | ||
| | `--activate` | Also update the "Last Known Good" release | | ||
| This command will retrieve the given package manager from the specified archive and will install it within the Corepack cache, ready to be used without further network interaction. | ||
| ## Contributing | ||
| If you want to build corepack yourself things yourself, you can build the project like this: | ||
| 1. Clone this repository | ||
| 2. Run `yarn build` (no need for `yarn install`) | ||
| 3. The `dist/` directory now contains the pmm build and the shims | ||
| 4. Call `node ./dist/pmm --version` and behold | ||
| You can also run the tests with `yarn jest` (still no install needed). | ||
| ## Design | ||
| Various tidbits about Corepack's design are explained in more details in [DESIGN.md](/DESIGN.md). | ||
| ## License (MIT) | ||
| > **Copyright © Corepack contributors** | ||
| > | ||
| > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
| > | ||
| > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
| > | ||
| > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| require('./corepack').runMain(['npm', 'npm', ...process.argv.slice(2)]); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| require('./corepack').runMain(['npm', 'npx', ...process.argv.slice(2)]); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| require('./corepack').runMain(['pnpm', 'pnpm', ...process.argv.slice(2)]); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| require('./corepack').runMain(['pnpm', 'pnpx', ...process.argv.slice(2)]); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| require('./corepack').runMain(['yarn', 'yarn', ...process.argv.slice(2)]); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| require('./corepack').runMain(['yarn', 'yarnpkg', ...process.argv.slice(2)]); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| { | ||
| "name": "corepack", | ||
| "version": "0.5.0", | ||
| "bin": { | ||
| "corepack": "./dist/corepack.js", | ||
| "pnpm": "./dist/pnpm.js", | ||
| "pnpx": "./dist/pnpx.js", | ||
| "yarn": "./dist/yarn.js", | ||
| "yarnpkg": "./dist/yarnpkg.js" | ||
| }, | ||
| "packageManager": "yarn@2.0.0-rc.29", | ||
| "devDependencies": { | ||
| "@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", | ||
| "@types/jest": "^25.1.4", | ||
| "@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", | ||
| "clipanion": "^2.6.2", | ||
| "debug": "^4.1.1", | ||
| "eslint": "^7.10.0", | ||
| "eslint-plugin-arca": "^0.9.5", | ||
| "jest": "^25.1.0", | ||
| "nock": "^13.0.4", | ||
| "semver": "^7.1.3", | ||
| "supports-color": "^7.1.0", | ||
| "tar": "^6.0.1", | ||
| "terser-webpack-plugin": "^3.1.0", | ||
| "ts-loader": "^8.0.2", | ||
| "ts-node": "^8.10.2", | ||
| "typescript": "^3.9.7", | ||
| "webpack": "next", | ||
| "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" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/sh | ||
| basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | ||
| case `uname` in | ||
| *CYGWIN*) basedir=`cygpath -w "$basedir"`;; | ||
| esac | ||
| if [ -x "$basedir/node" ]; then | ||
| exec "$basedir/node" "$basedir/../dist/corepack.js" "$@" | ||
| else | ||
| exec node "$basedir/../dist/corepack.js" "$@" | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| @IF EXIST "%~dp0\node.exe" ( | ||
| "%~dp0\node.exe" "%~dp0\..\dist\corepack.js" %* | ||
| ) ELSE ( | ||
| @SETLOCAL | ||
| @SET PATHEXT=%PATHEXT:;.JS;=;% | ||
| node "%~dp0\..\dist\corepack.js" %* | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env pwsh | ||
| $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | ||
| $exe="" | ||
| if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | ||
| # Fix case when both the Windows and Linux builds of Node | ||
| # are installed in the same directory | ||
| $exe=".exe" | ||
| } | ||
| $ret=0 | ||
| if (Test-Path "$basedir/node$exe") { | ||
| # Support pipeline input | ||
| if ($MyInvocation.ExpectingInput) { | ||
| $input | & "$basedir/node$exe" "$basedir/../dist/corepack.js" $args | ||
| } else { | ||
| & "$basedir/node$exe" "$basedir/../dist/corepack.js" $args | ||
| } | ||
| $ret=$LASTEXITCODE | ||
| } else { | ||
| # Support pipeline input | ||
| if ($MyInvocation.ExpectingInput) { | ||
| $input | & "node$exe" "$basedir/../dist/corepack.js" $args | ||
| } else { | ||
| & "node$exe" "$basedir/../dist/corepack.js" $args | ||
| } | ||
| $ret=$LASTEXITCODE | ||
| } | ||
| exit $ret |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/sh | ||
| basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | ||
| case `uname` in | ||
| *CYGWIN*) basedir=`cygpath -w "$basedir"`;; | ||
| esac | ||
| if [ -x "$basedir/node" ]; then | ||
| exec "$basedir/node" "$basedir/node_modules/corepack/dist/corepack.js" "$@" | ||
| else | ||
| exec node "$basedir/node_modules/corepack/dist/corepack.js" "$@" | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| @IF EXIST "%~dp0\node.exe" ( | ||
| "%~dp0\node.exe" "%~dp0\node_modules\corepack\dist\corepack.js" %* | ||
| ) ELSE ( | ||
| @SETLOCAL | ||
| @SET PATHEXT=%PATHEXT:;.JS;=;% | ||
| node "%~dp0\node_modules\corepack\dist\corepack.js" %* | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #!/usr/bin/env pwsh | ||
| $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent | ||
| $exe="" | ||
| if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | ||
| # Fix case when both the Windows and Linux builds of Node | ||
| # are installed in the same directory | ||
| $exe=".exe" | ||
| } | ||
| $ret=0 | ||
| if (Test-Path "$basedir/node$exe") { | ||
| # Support pipeline input | ||
| if ($MyInvocation.ExpectingInput) { | ||
| $input | & "$basedir/node$exe" "$basedir/node_modules/corepack/dist/corepack.js" $args | ||
| } else { | ||
| & "$basedir/node$exe" "$basedir/node_modules/corepack/dist/corepack.js" $args | ||
| } | ||
| $ret=$LASTEXITCODE | ||
| } else { | ||
| # Support pipeline input | ||
| if ($MyInvocation.ExpectingInput) { | ||
| $input | & "node$exe" "$basedir/node_modules/corepack/dist/corepack.js" $args | ||
| } else { | ||
| & "node$exe" "$basedir/node_modules/corepack/dist/corepack.js" $args | ||
| } | ||
| $ret=$LASTEXITCODE | ||
| } | ||
| exit $ret |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these files could be symlinks to a helper that reads process.execName or whatever it's called. it's a common pattern in gnu core utils so it shouldn't break anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it also occurs to me that if someone does not want a specific package manager on their system (for example, i do not wish to have yarn on my system), this could be considered somewhat invasive. Are we planning to ship tars with and without corepack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devsnek ... this would not install the binaries by default. It installs jumpers that would download the binaries on demand if needed and it would be possible to block it via configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize it doesn't come with the binaries, but it puts things in my path that installs them. Let's say I'd rather not have any of that. Would I have to bundle my own releases of node?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it will ask you before downloading Yarn or pnpm?
Like "Do you want Yarn v2 be downloaded to your system? Y/n"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's implemented yet or not, but there was also discussion around being able to set configuration options to disable the download. It would likely be possible to have the tool remove the jumpers from the path when requested to do so. For interactive installers, it should be possible to make that configurable (e.g. by default install all jumpers but give the user the option to select them during the install)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Downloads can be disabled by setting
COREPACK_ENABLE_NETWORK=0in the environment (nodejs/corepack#4). Removing the jumpers isn't possible yet as I wasn't sure of the use case, although it would be possible if needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@merceyz many tools are invoked directly, and not as part of a package manager - how would these tools detect it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be up to these projects to make decisions on a per-case basis, as the semantic compatible path isn't clear. For instance, that CRA "will use Yarn to install dependencies (when available)" could be interpreted as CRA preferring installs to be made via Yarn as much as possible - in which case using npm when Yarn is available wouldn't be the behavior that the project would prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that these tools are typically called via
npx,pnpx, oryarn create/yarn dlx. In all of these cases, the tool got an implicit insight as to the preferred package manager (ie undernpxthe$npm_config_user_agentvalue will reference npm, withyarn dlxit'll reference Yarn, etc).