Skip to content

Commit

Permalink
fix: remove npm references
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyclarke committed Mar 7, 2024
1 parent 3958d26 commit 9bfded8
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 177 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/sync.yml
Expand Up @@ -22,16 +22,12 @@ jobs:
run: |
LATEST_BERRY_VERSION=$(curl https://repo.yarnpkg.com/tags | jq -r '.latest.stable')
LATEST_NPM=$(curl https://registry.npmjs.org/npm | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_PNPM=$(curl https://registry.npmjs.org/pnpm | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_YARN=$(curl https://registry.npmjs.org/yarn | jq '.["dist-tags"].latest + "+sha1." + .versions[.["dist-tags"].latest].dist.shasum')
LATEST_BERRY=$(jq -n '$version + "+sha224." + $checksum' --arg version "$LATEST_BERRY_VERSION" --arg checksum "$(curl https://repo.yarnpkg.com/"$LATEST_BERRY_VERSION"/packages/yarnpkg-cli/bin/yarn.js | openssl dgst -sha224 | cut -d' ' -f2)")
git --no-pager show HEAD:config.json | jq '. * '"{
definitions: {
npm: {
default: $LATEST_NPM,
},
pnpm: {
default: $LATEST_PNPM,
},
Expand Down
20 changes: 7 additions & 13 deletions README.md
Expand Up @@ -2,8 +2,8 @@

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

Expand Down Expand Up @@ -50,8 +50,8 @@ 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
will catch these calls, and depending on the situation:
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**,
Corepack will silently download and cache the latest compatible version.
Expand Down Expand Up @@ -79,7 +79,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.
`packageManager@x.y.z` 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
Expand Down Expand Up @@ -148,9 +148,7 @@ 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).

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
Expand All @@ -161,8 +159,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
Expand All @@ -173,8 +169,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]`
Expand Down Expand Up @@ -250,7 +244,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
Expand Down
37 changes: 0 additions & 37 deletions config.json
@@ -1,42 +1,5 @@
{
"definitions": {
"npm": {
"default": "10.4.0+sha1.904025b4d932cfaed8799e644a1c5ae7f02729fc",
"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": "8.15.3+sha1.64838798f519c18029c1e8a1310e16101fc2eda0",
"fetchLatestFrom": {
Expand Down
4 changes: 0 additions & 4 deletions package.json
Expand Up @@ -83,10 +83,6 @@
"./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",
Expand Down
2 changes: 0 additions & 2 deletions sources/commands/Base.ts
@@ -1,10 +1,8 @@
import {Command, UsageError} from 'clipanion';
import fs from 'fs';

import {PreparedPackageManagerInfo} from '../Engine';
import * as corepackUtils from '../corepackUtils';
import {Context} from '../main';
import * as nodeUtils from '../nodeUtils';
import * as specUtils from '../specUtils';

export abstract class BaseCommand extends Command<Context> {
Expand Down
16 changes: 8 additions & 8 deletions sources/commands/Disable.ts
@@ -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 {SupportedPackageManagerSet, isSupportedPackageManager} from '../types';

export class DisableCommand extends Command<Context> {
static paths = [
Expand Down Expand Up @@ -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;

for (const name of new Set(names)) {
Expand Down
16 changes: 8 additions & 8 deletions sources/commands/Enable.ts
@@ -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 = [
Expand Down Expand Up @@ -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;

for (const name of new Set(names)) {
Expand Down
7 changes: 0 additions & 7 deletions sources/corepackUtils.ts
Expand Up @@ -350,13 +350,6 @@ export async function runVersion(locator: Locator, installSpec: InstallSpec & {s
if (!binPath)
throw new Error(`Assertion failed: Unable to locate path for bin '${binName}'`);

// Node.js segfaults when using npm@>=9.7.0 and v8-compile-cache
// $ docker run -it node:20.3.0-slim corepack npm@9.7.1 --version
// [SIGSEGV]
if (locator.name !== `npm` || semver.lt(locator.reference, `9.7.0`))
// @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.

Expand Down
8 changes: 0 additions & 8 deletions sources/types.ts
Expand Up @@ -2,7 +2,6 @@ export type BinSpec = {[key: string]: string};
export type BinList = Array<string>;

export enum SupportedPackageManagers {
Npm = `npm`,
Pnpm = `pnpm`,
Yarn = `yarn`,
}
Expand All @@ -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);
}
Expand Down
22 changes: 11 additions & 11 deletions tests/Disable.test.ts
@@ -1,13 +1,13 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it, expect} from '@jest/globals';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';

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();

Expand All @@ -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});
Expand All @@ -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});
Expand All @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions tests/Enable.test.ts
@@ -1,13 +1,13 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it, expect} from '@jest/globals';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';

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();

Expand All @@ -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));

Expand All @@ -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));

Expand Down

0 comments on commit 9bfded8

Please sign in to comment.