-
-
Notifications
You must be signed in to change notification settings - Fork 202
add corepack project install
command
#551
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
Open
mmkal
wants to merge
11
commits into
nodejs:main
Choose a base branch
from
mmkal:project-install
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−1
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
afcca3d
add `corepack project install` command
mmkal 4b92973
if
mmkal 793bbb1
fix descirptions
mmkal e2d6567
add tests
mmkal 2f790c8
Update Project.ts
mmkal 1510e37
docs
mmkal a5d870d
use same binaries as other tests
mmkal ca88ec3
fix tests + make em easier to debug on failure
mmkal 6a0aed2
fix npm casing
mmkal 6ccc639
lint --fix
mmkal 3e938cf
Merge branch 'main' into project-install
mmkal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {Command, UsageError} from 'clipanion'; | ||
import semverValid from 'semver/functions/valid'; | ||
import semverValidRange from 'semver/ranges/valid'; | ||
|
||
import {BaseCommand} from './Base'; | ||
|
||
// modified from ./Enable.ts | ||
// https://github.com/nodejs/corepack/issues/505 | ||
export class ProjectInstallCommand extends BaseCommand { | ||
static paths = [ | ||
[`project`, `install`], | ||
]; | ||
|
||
static usage = Command.Usage({ | ||
description: `Add the Corepack shims to the install directories, and run the install command of the specified package manager`, | ||
details: ` | ||
When run, this command will check whether the shims for the specified package managers can be found with the correct values inside the install directory. If not, or if they don't exist, they will be created. | ||
|
||
Then, it will run the install command of the specified package manager. If no package manager is specified, it will default to NPM. | ||
mmkal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
By default it will locate the install directory by running the equivalent of \`which corepack\`, but this can be tweaked by explicitly passing the install directory via the \`--install-directory\` flag. | ||
`, | ||
examples: [[ | ||
`Enable all shims and install, putting shims next to the \`corepack\` binary`, | ||
`$0 project install`, | ||
]], | ||
}); | ||
|
||
async execute() { | ||
const [descriptor] = await this.resolvePatternsToDescriptors({ | ||
patterns: [], | ||
}); | ||
|
||
if (!semverValid(descriptor.range) && !semverValidRange(descriptor.range)) | ||
throw new UsageError(`The 'corepack project install' command can only be used when your project's packageManager field is set to a semver version or semver range`); | ||
|
||
const resolved = await this.context.engine.resolveDescriptor(descriptor, {useCache: true}); | ||
if (!resolved) | ||
throw new UsageError(`Failed to successfully resolve '${descriptor.range}' to a valid ${descriptor.name} release`); | ||
|
||
this.context.stdout.write(`Installing ${resolved.name}@${resolved.reference} in the project...\n`); | ||
|
||
const packageManagerInfo = await this.context.engine.ensurePackageManager(resolved); | ||
await this.installLocalPackageManager(packageManagerInfo); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {describe, it} from 'vitest'; | ||
|
||
describe(`ProjectCommand`, () => { | ||
describe(`InstallSubcommand`, () => { | ||
it(`should add the binaries in the folder found in the PATH`, async () => { | ||
// todo | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.