Skip to content

Commit

Permalink
feat!: remove --all flag (#351)
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 authored Feb 17, 2024
1 parent 9066ea7 commit d9c70b9
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 92 deletions.
12 changes: 2 additions & 10 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 Down Expand Up @@ -185,23 +182,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 it 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
1 change: 0 additions & 1 deletion sources/commands/InstallLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class InstallLocalCommand extends BaseCommand {

async execute() {
const [descriptor] = await this.resolvePatternsToDescriptors({
all: false,
patterns: [],
});

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
1 change: 0 additions & 1 deletion sources/commands/Up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class UpCommand extends BaseCommand {

async execute() {
const [descriptor] = await this.resolvePatternsToDescriptors({
all: false,
patterns: [],
});

Expand Down
1 change: 0 additions & 1 deletion sources/commands/Use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class UseCommand extends BaseCommand {

async execute() {
const [descriptor] = await this.resolvePatternsToDescriptors({
all: false,
patterns: [this.pattern],
});

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
33 changes: 0 additions & 33 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,39 +403,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`;

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,
});
});
});

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

Expand Down
1 change: 0 additions & 1 deletion tests/nock/VurwVdvlR5Rs7xQVs9UCVw-1.dat

This file was deleted.

0 comments on commit d9c70b9

Please sign in to comment.