Skip to content
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

Removes npm from the possible options #670

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@

Corepack is a zero-runtime-dependency Node.js script that acts as a bridge
between Node.js projects and the package managers they are intended to be used
with during development. In practical terms, **Corepack lets you use Yarn, npm,
and pnpm without having to install them**.
with during development. In practical terms, **Corepack lets you use Yarn and pnpm without having to install them**.

## How to Install

@@ -71,7 +70,7 @@ See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
### When Building Packages

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
projects and `pnpm install` in pnpm projects. Corepack
will catch these calls, and depending on the situation:

- **If the local project is configured for the package manager you're using**,
@@ -100,7 +99,7 @@ Here, `yarn` is the name of the package manager, specified at version `3.2.3`,
along with the SHA-224 hash of this version for validation.
`[email protected]` is required. The hash is optional but strongly
recommended as a security practice. Permitted values for the package manager are
`yarn`, `npm`, and `pnpm`.
`yarn` and `pnpm`.

You can also provide a URL to a `.js` file (which will be interpreted as a
CommonJS module) or a `.tgz` file (which will be interpreted as a package, and
@@ -198,9 +197,8 @@ Clears the local `COREPACK_HOME` cache directory.

This command will detect where Corepack 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.js
through other means.
is called without parameters). Note that the npm shims will not be installed,
as npm is directly installed with Node.js.

If the file system where the `corepack` binary is located is read-only, this
command will fail. A workaround is to add the binaries as alias in your
@@ -211,8 +209,6 @@ alias yarn="corepack yarn"
alias yarnpkg="corepack yarnpkg"
alias pnpm="corepack pnpm"
alias pnpx="corepack pnpx"
alias npm="corepack npm"
alias npx="corepack npx"
```

On Windows PowerShell, you can add functions using the `$PROFILE` automatic
@@ -223,8 +219,6 @@ echo "function yarn { corepack yarn `$args }" >> $PROFILE
echo "function yarnpkg { corepack yarnpkg `$args }" >> $PROFILE
echo "function pnpm { corepack pnpm `$args }" >> $PROFILE
echo "function pnpx { corepack pnpx `$args }" >> $PROFILE
echo "function npm { corepack npm `$args }" >> $PROFILE
echo "function npx { corepack npx `$args }" >> $PROFILE
```

### `corepack disable [... name]`
@@ -302,7 +296,7 @@ same major line. Should you need to upgrade to a new major, use an explicit
ask for user input before starting the download.

- `COREPACK_ENABLE_UNSAFE_CUSTOM_URLS` can be set to `1` to allow use of
custom URLs to load a package manager known by Corepack (`yarn`, `npm`, and
custom URLs to load a package manager known by Corepack (`yarn` and
`pnpm`).

- `COREPACK_ENABLE_NETWORK` can be set to `0` to prevent Corepack from accessing
37 changes: 0 additions & 37 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
{
"definitions": {
"npm": {
"default": "11.1.0+sha1.dba08f7d0f5301ebedaf968b4f74b2282f97a750",
"fetchLatestFrom": {
"type": "npm",
"package": "npm"
},
"transparent": {
"commands": [
[
"npm",
"init"
],
[
"npx"
]
]
},
"ranges": {
"*": {
"url": "https://registry.npmjs.org/npm/-/npm-{}.tgz",
"bin": {
"npm": "./bin/npm-cli.js",
"npx": "./bin/npx-cli.js"
},
"registry": {
"type": "npm",
"package": "npm"
},
"commands": {
"use": [
"npm",
"install"
]
}
}
}
},
"pnpm": {
"default": "10.5.2+sha1.ca68c0441df195b7e2992f1d1cb12fb731f82d78",
"fetchLatestFrom": {
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -71,17 +71,11 @@
"yarnpkg": "./dist/yarnpkg.js"
},
"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",
16 changes: 8 additions & 8 deletions sources/commands/Disable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Command, Option, UsageError} from 'clipanion';
import fs from 'fs';
import path from 'path';
import which from 'which';
import {Command, Option, UsageError} from 'clipanion';
import fs from 'fs';
import path from 'path';
import which from 'which';

import {Context} from '../main';
import type {NodeError} from '../nodeUtils';
import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types';
import {Context} from '../main';
import type {NodeError} from '../nodeUtils';
import {isSupportedPackageManager, SupportedPackageManagerSet} from '../types';

export class DisableCommand extends Command<Context> {
static paths = [
@@ -47,7 +47,7 @@ export class DisableCommand extends Command<Context> {
installDirectory = path.dirname(await which(`corepack`));

const names = this.names.length === 0
? SupportedPackageManagerSetWithoutNpm
? SupportedPackageManagerSet
: this.names;

const allBinNames: Array<string> = [];
16 changes: 8 additions & 8 deletions sources/commands/Enable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import cmdShim from '@zkochan/cmd-shim';
import {Command, Option, UsageError} from 'clipanion';
import fs from 'fs';
import path from 'path';
import which from 'which';
import cmdShim from '@zkochan/cmd-shim';
import {Command, Option, UsageError} from 'clipanion';
import fs from 'fs';
import path from 'path';
import which from 'which';

import {Context} from '../main';
import {isSupportedPackageManager, SupportedPackageManagerSetWithoutNpm} from '../types';
import {Context} from '../main';
import {isSupportedPackageManager, SupportedPackageManagerSet} from '../types';

export class EnableCommand extends Command<Context> {
static paths = [
@@ -57,7 +57,7 @@ export class EnableCommand extends Command<Context> {
throw new Error(`Assertion failed: The stub folder doesn't exist`);

const names = this.names.length === 0
? SupportedPackageManagerSetWithoutNpm
? SupportedPackageManagerSet
: this.names;

const allBinNames: Array<string> = [];
12 changes: 3 additions & 9 deletions sources/corepackUtils.ts
Original file line number Diff line number Diff line change
@@ -401,15 +401,9 @@ export async function runVersion(locator: Locator, installSpec: InstallSpec & {s
throw new Error(`Assertion failed: Unable to locate path for bin '${binName}'`);

// @ts-expect-error - Missing types
if (!Module.enableCompileCache) {
// Node.js segfaults when using npm@>=9.7.0 and v8-compile-cache
// $ docker run -it node:20.3.0-slim corepack [email protected] --version
// [SIGSEGV]
if (locator.name !== `npm` || semverLt(locator.reference, `9.7.0`)) {
// @ts-expect-error - No types
await import(`v8-compile-cache`);
}
}
if (!Module.enableCompileCache)
// @ts-expect-error - No types
await import(`v8-compile-cache`);

// We load the binary into the current process,
// while making it think it was spawned.
8 changes: 0 additions & 8 deletions sources/types.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ export type BinSpec = {[key: string]: string};
export type BinList = Array<string>;

export enum SupportedPackageManagers {
Npm = `npm`,
Pnpm = `pnpm`,
Yarn = `yarn`,
}
@@ -11,13 +10,6 @@ export const SupportedPackageManagerSet = new Set<SupportedPackageManagers>(
Object.values(SupportedPackageManagers),
);

export const SupportedPackageManagerSetWithoutNpm = new Set<SupportedPackageManagers>(
Object.values(SupportedPackageManagers),
);

// npm is distributed with Node as a builtin; we don't want Corepack to override it unless the npm team is on board
SupportedPackageManagerSetWithoutNpm.delete(SupportedPackageManagers.Npm);

export function isSupportedPackageManager(value: string): value is SupportedPackageManagers {
return SupportedPackageManagerSet.has(value as SupportedPackageManagers);
}
22 changes: 11 additions & 11 deletions tests/Disable.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it, expect} from 'vitest';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it, expect} from 'vitest';

import {Engine} from '../sources/Engine';
import {SupportedPackageManagerSetWithoutNpm} from '../sources/types';
import {Engine} from '../sources/Engine';
import {SupportedPackageManagerSet} from '../sources/types';

import {makeBin, getBinaryNames} from './_binHelpers';
import {runCli} from './_runCli';
import {makeBin, getBinaryNames} from './_binHelpers';
import {runCli} from './_runCli';

const engine = new Engine();

@@ -22,7 +22,7 @@ describe(`DisableCommand`, () => {
const corepackBin = await makeBin(cwd, `corepack` as Filename);
const dontRemoveBin = await makeBin(cwd, `dont-remove` as Filename);

for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const packageManager of SupportedPackageManagerSet)
for (const binName of engine.getBinariesFor(packageManager))
for (const variant of getBinaryNames(binName))
await makeBin(cwd, variant as Filename, {ignorePlatform: true});
@@ -47,7 +47,7 @@ describe(`DisableCommand`, () => {
await xfs.mktempPromise(async cwd => {
const dontRemoveBin = await makeBin(cwd, `dont-remove` as Filename);

for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const packageManager of SupportedPackageManagerSet)
for (const binName of engine.getBinariesFor(packageManager))
for (const variant of getBinaryNames(binName))
await makeBin(cwd, variant as Filename, {ignorePlatform: true});
@@ -66,7 +66,7 @@ describe(`DisableCommand`, () => {
await xfs.mktempPromise(async cwd => {
const binNames = new Set<string>();

for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const packageManager of SupportedPackageManagerSet)
for (const binName of engine.getBinariesFor(packageManager))
for (const variant of getBinaryNames(binName))
binNames.add(variant);
20 changes: 10 additions & 10 deletions tests/Enable.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it, expect} from 'vitest';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it, expect} from 'vitest';

import {Engine} from '../sources/Engine';
import {SupportedPackageManagers, SupportedPackageManagerSetWithoutNpm} from '../sources/types';
import {Engine} from '../sources/Engine';
import {SupportedPackageManagers, SupportedPackageManagerSet} from '../sources/types';

import {makeBin, getBinaryNames} from './_binHelpers';
import {runCli} from './_runCli';
import {makeBin, getBinaryNames} from './_binHelpers';
import {runCli} from './_runCli';

const engine = new Engine();

@@ -34,7 +34,7 @@ describe(`EnableCommand`, () => {
});

const expectedEntries: Array<string> = [ppath.basename(corepackBin)];
for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const packageManager of SupportedPackageManagerSet)
for (const binName of engine.getBinariesFor(packageManager))
expectedEntries.push(...getBinaryNames(binName));

@@ -57,7 +57,7 @@ describe(`EnableCommand`, () => {
});

const expectedEntries: Array<string> = [ppath.basename(corepackBin)];
for (const packageManager of SupportedPackageManagerSetWithoutNpm)
for (const packageManager of SupportedPackageManagerSet)
for (const binName of engine.getBinariesFor(packageManager))
expectedEntries.push(...getBinaryNames(binName));

Loading