Skip to content

Commit

Permalink
feat!: remove --all flag
Browse files Browse the repository at this point in the history
Force users to opt-in into the package managers they want to support.
As more and more package managers are added to Corepack, it's more and
more unlikely that our users will be interested in _all_ the package
managers Corepack supports, and it is unreasonable to expect Corepack
maintainers would be able to perform security audits.
  • Loading branch information
aduh95 committed Jan 8, 2024
1 parent 9bdd296 commit 59d0b61
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 97 deletions.
19 changes: 4 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ The utility commands detailed in the next section.
case you'll simply run `corepack pack` 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 pack -o`) before storing
Expand All @@ -124,17 +121,14 @@ 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]`
### `corepack enable name [...names]`

| Option | Description |
| --------------------- | --------------------------------------- |
| `--install-directory` | Add the shims to the specified location |

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.
to it for each of the specified package managers.

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 Down Expand Up @@ -177,23 +171,18 @@ This command doesn't change the global version used when running the package
manager from outside the project (use the \`-g,--global\` flag if you wish
to do this).

### `corepack install <-g,--global> [--all] [... name[@<version>]]`

| Option | Description |
| --------------------- | ------------------------------------------ |
| `--all` | Install all Last Known Good releases |
### `corepack install <-g,--global> [... name[@<version>]]`

Install the selected package managers and install them on the system.

Package managers thus installed will be configured as the new default when
calling their respective binaries outside of projects defining the
`packageManager` field.

### `corepack pack [--all] [... name[@<version>]]`
### `corepack pack [... name[@<version>]]`

| Option | Description |
| --------------------- | ------------------------------------------ |
| `--all` | Pack all Last Known Good releases |
| `--json ` | Print the output folder rather than logs |
| `-o,--output ` | Path where to generate the archive |

Expand Down
9 changes: 2 additions & 7 deletions sources/commands/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import * as nodeUtils from '../nodeUtils';
import * as specUtils from '../specUtils';

export abstract class BaseCommand extends Command<Context> {
async resolvePatternsToDescriptors({all, patterns}: {all: boolean, patterns: Array<string>}) {
if (all && patterns.length > 0)
throw new UsageError(`The --all option cannot be used along with an explicit package manager specification`);

const resolvedSpecs = all
? await this.context.engine.getDefaultDescriptors()
: patterns.map(pattern => specUtils.parseSpec(pattern, `CLI arguments`, {enforceExactVersion: false}));
async resolvePatternsToDescriptors({patterns}: {patterns: Array<string>}) {
const resolvedSpecs = patterns.map(pattern => specUtils.parseSpec(pattern, `CLI arguments`, {enforceExactVersion: false}));

if (resolvedSpecs.length === 0) {
const lookup = await specUtils.loadSpec(this.context.cwd);
Expand Down
30 changes: 10 additions & 20 deletions sources/commands/InstallGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,30 @@ export class InstallGlobalCommand extends BaseCommand {
`Install the latest version of Yarn 1.x and make it globally available`,
`corepack install -g yarn@^1`,
], [
`Install the latest version of all available package managers, and make them globally available`,
`corepack install -g --all`,
`Install the latest version of pnpm, and make them globally available`,
`corepack install -g pnpm`,
]],
});

global = Option.Boolean(`-g,--global`, {
required: true,
});

all = Option.Boolean(`--all`, false, {
description: `If true, all available default package managers will be installed`,
});

cacheOnly = Option.Boolean(`--cache-only`, false, {
description: `If true, the package managers will only be cached, not set as new defaults`,
});

args = Option.Rest();

async execute() {
if (this.args.length === 0 && !this.all)
throw new UsageError(`No package managers specified; use --all to install all available package managers, or specify one or more package managers to proceed`);

if (!this.all) {
for (const arg of this.args) {
if (arg.endsWith(`.tgz`)) {
await this.installFromTarball(path.resolve(this.context.cwd, arg));
} else {
await this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`, {enforceExactVersion: false}));
}
}
} else {
for (const descriptor of await this.context.engine.getDefaultDescriptors()) {
await this.installFromDescriptor(descriptor);
if (this.args.length === 0)
throw new UsageError(`No package managers specified`);

for (const arg of this.args) {
if (arg.endsWith(`.tgz`)) {
await this.installFromTarball(path.resolve(this.context.cwd, arg));
} else {
await this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`, {enforceExactVersion: false}));
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions sources/commands/Pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@ export class PackCommand extends BaseCommand {
], [
`Pack the latest version of Yarn 1.x inside a file named corepack.tgz`,
`corepack pack yarn@^1`,
], [
`Pack the latest versions of all supported package managers inside a file named everything.tgz`,
`corepack pack --all -o everything.tgz`,
]],
});

all = Option.Boolean(`--all`, false, {
description: `If true, all available default package managers will be installed`,
});

json = Option.Boolean(`--json`, false, {
description: `If true, the path to the generated tarball will be printed on stdout`,
});
Expand All @@ -44,7 +37,6 @@ export class PackCommand extends BaseCommand {

async execute() {
const descriptors = await this.resolvePatternsToDescriptors({
all: this.all,
patterns: this.patterns,
});

Expand Down
11 changes: 1 addition & 10 deletions sources/commands/deprecated/Prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export class PrepareCommand extends Command<Context> {
description: `If true, this release will become the default one for this package manager`,
});

all = Option.Boolean(`--all`, false, {
description: `If true, all available default package managers will be installed`,
});

json = Option.Boolean(`--json`, false, {
description: `If true, the output will be the path of the generated tarball`,
});
Expand All @@ -32,12 +28,7 @@ export class PrepareCommand extends Command<Context> {
specs = Option.Rest();

async execute() {
if (this.all && this.specs.length > 0)
throw new UsageError(`The --all option cannot be used along with an explicit package manager specification`);

const specs: Array<string | Descriptor> = this.all
? await this.context.engine.getDefaultDescriptors()
: this.specs;
const specs: Array<string | Descriptor> = this.specs;

const installLocations: Array<string> = [];

Expand Down
37 changes: 0 additions & 37 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,43 +371,6 @@ it(`should always use fallback version when project spec env is disabled`, async
});
});

it(`should allow to call "corepack install -g --all" to prepare all package managers`, async () => {
await xfs.mktempPromise(async cwd => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
// empty package.json file
});

await expect(runCli(cwd, [`install`, `-g`, `--all`])).resolves.toMatchObject({
exitCode: 0,
stderr: ``,
});

process.env.COREPACK_ENABLE_NETWORK = `0`;

try {
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.yarn.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});

await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.pnpm.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});

await expect(runCli(cwd, [`npm`, `--version`])).resolves.toMatchObject({
stdout: `${config.definitions.npm.default.split(`+`, 1)[0]}\n`,
stderr: ``,
exitCode: 0,
});
} finally {
delete process.env.COREPACK_ENABLE_NETWORK;
}
});
});

it(`should support disabling the network accesses from the environment`, async () => {
process.env.COREPACK_ENABLE_NETWORK = `0`;

Expand Down

0 comments on commit 59d0b61

Please sign in to comment.