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

feat: Initial pnpm support #1273

Merged
merged 21 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"editor.formatOnSave": true
}
}
11 changes: 11 additions & 0 deletions crates/volta-core/fixtures/hooks/bins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"bin": "/some/bin/for/node/index"
}
},
"pnpm": {
"distro": {
"bin": "/bin/to/pnpm/distro"
},
"latest": {
"bin": "/bin/to/pnpm/latest"
},
"index": {
"bin": "/bin/to/pnpm/index"
}
},
"yarn": {
"distro": {
"bin": "/bin/to/yarn/distro"
Expand Down
6 changes: 6 additions & 0 deletions crates/volta-core/fixtures/hooks/format_github.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"format": "github"
}
},
"pnpm": {
"index": {
"prefix": "http://localhost/pnpm/index/",
"format": "github"
}
},
"yarn": {
"index": {
"prefix": "http://localhost/yarn/index/",
Expand Down
6 changes: 6 additions & 0 deletions crates/volta-core/fixtures/hooks/format_npm.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"format": "npm"
}
},
"pnpm": {
"index": {
"prefix": "http://localhost/pnpm/index/",
"format": "npm"
}
},
"yarn": {
"index": {
"prefix": "http://localhost/yarn/index/",
Expand Down
11 changes: 11 additions & 0 deletions crates/volta-core/fixtures/hooks/prefixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"prefix": "http://localhost/node/index/"
}
},
"pnpm": {
"distro": {
"prefix": "http://localhost/pnpm/distro/"
},
"latest": {
"prefix": "http://localhost/pnpm/latest/"
},
"index": {
"prefix": "http://localhost/pnpm/index/"
}
},
"yarn": {
"distro": {
"prefix": "http://localhost/yarn/distro/"
Expand Down
11 changes: 11 additions & 0 deletions crates/volta-core/fixtures/hooks/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"template": "http://localhost/node/index/{{version}}/"
}
},
"pnpm": {
"distro": {
"template": "http://localhost/pnpm/distro/{{version}}/"
},
"latest": {
"template": "http://localhost/pnpm/latest/{{version}}/"
},
"index": {
"template": "http://localhost/pnpm/index/{{version}}/"
}
},
"yarn": {
"distro": {
"template": "http://localhost/yarn/distro/{{version}}/"
Expand Down
47 changes: 46 additions & 1 deletion crates/volta-core/src/error/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ pub enum ErrorKind {
command: String,
},

/// Thrown when pnpm is not set at the command-line
NoCommandLinePnpm,

/// Thrown when Yarn is not set at the command-line
NoCommandLineYarn,

Expand All @@ -209,7 +212,7 @@ pub enum ErrorKind {

NoLocalDataDir,

/// Thrown when a user tries to pin a Yarn or npm version before pinning a Node version.
/// Thrown when a user tries to pin a npm, pnpm, or Yarn version before pinning a Node version.
NoPinnedNodeVersion {
tool: String,
},
Expand All @@ -223,6 +226,9 @@ pub enum ErrorKind {
/// Thrown when Yarn is not set in a project
NoProjectYarn,

/// Thrown when pnpm is not set in a project
NoProjectPnpm,

/// Thrown when no shell profiles could be found
NoShellProfile {
env_profile: String,
Expand All @@ -235,6 +241,9 @@ pub enum ErrorKind {
/// Thrown when default Yarn is not set
NoDefaultYarn,

/// Thrown when default pnpm is not set
NoDefaultPnpm,

/// Thrown when `npm link` is called with a package that isn't available
NpmLinkMissingPackage {
package: String,
Expand Down Expand Up @@ -330,6 +339,11 @@ pub enum ErrorKind {
tool: String,
},

/// Thrown when there is no pnpm version matching a requested semver specifier.
PnpmVersionNotFound {
matching: String,
},

/// Thrown when executing a project-local binary fails
ProjectLocalBinaryExecError {
command: String,
Expand Down Expand Up @@ -856,6 +870,12 @@ format
Please ensure you have a Node version selected with `volta {} node` (see `volta help {0}` for more info).",
command
),
ErrorKind::NoCommandLinePnpm => write!(
f,
"No pnpm version specified.

Use `volta run --pnpm` to select a version (see `volta help run` for more info)."
),
ErrorKind::NoCommandLineYarn => write!(
f,
"No Yarn version specified.
Expand Down Expand Up @@ -912,6 +932,12 @@ To run any Node command, first set a default version using `volta install node`"
"No Node version found in this project.

Use `volta pin node` to select a version (see `volta help pin` for more info)."
),
ErrorKind::NoProjectPnpm => write!(
f,
"No pnpm version found in this project.

Use `volta pin pnpm` to select a version (see `volta help pin` for more info)."
),
ErrorKind::NoProjectYarn => write!(
f,
Expand All @@ -932,6 +958,12 @@ Please create one of these and try again; or you can edit your profile manually
"Not in a node package.

Use `volta install` to select a default version of a tool."
),
ErrorKind::NoDefaultPnpm => write!(
f,
"pnpm is not available.

Use `volta install pnpm` to select a default version (see `volta help install` for more info)."
),
ErrorKind::NoDefaultYarn => write!(
f,
Expand Down Expand Up @@ -1096,6 +1128,13 @@ Please supply a spec in the format `<tool name>[@<version>]`.",
{}",
tool, PERMISSIONS_CTA
),
ErrorKind::PnpmVersionNotFound { matching } => write!(
f,
r#"Could not find pnpm version matching "{}" in the version registry.

Please verify that the version is correct."#,
matching
),
ErrorKind::ProjectLocalBinaryExecError { command } => write!(
f,
"Could not execute `{}`
Expand Down Expand Up @@ -1299,12 +1338,14 @@ Please ensure it is installed with `{} {0}`"#,
package,
match manager {
PackageManager::Npm => "npm i -g",
PackageManager::Pnpm => "pnpm add -g",
PackageManager::Yarn => "yarn global add",
}
),
ErrorKind::UpgradePackageWrongManager { package, manager } => {
let (name, command) = match manager {
PackageManager::Npm => ("npm", "npm update -g"),
PackageManager::Pnpm => ("pnpm", "pnpm update -g"),
PackageManager::Yarn => ("Yarn", "yarn global upgrade"),
};
write!(
Expand Down Expand Up @@ -1455,6 +1496,7 @@ impl ErrorKind {
ErrorKind::InvalidToolName { .. } => ExitCode::InvalidArguments,
ErrorKind::LockAcquireError => ExitCode::FileSystemError,
ErrorKind::NoBundledNpm { .. } => ExitCode::ConfigurationError,
ErrorKind::NoCommandLinePnpm => ExitCode::ConfigurationError,
ErrorKind::NoCommandLineYarn => ExitCode::ConfigurationError,
ErrorKind::NoDefaultNodeVersion { .. } => ExitCode::ConfigurationError,
ErrorKind::NodeVersionNotFound { .. } => ExitCode::NoVersionMatch,
Expand All @@ -1464,9 +1506,11 @@ impl ErrorKind {
ErrorKind::NoPinnedNodeVersion { .. } => ExitCode::ConfigurationError,
ErrorKind::NoPlatform => ExitCode::ConfigurationError,
ErrorKind::NoProjectNodeInManifest => ExitCode::ConfigurationError,
ErrorKind::NoProjectPnpm => ExitCode::ConfigurationError,
ErrorKind::NoProjectYarn => ExitCode::ConfigurationError,
ErrorKind::NoShellProfile { .. } => ExitCode::EnvironmentError,
ErrorKind::NotInPackage => ExitCode::ConfigurationError,
ErrorKind::NoDefaultPnpm => ExitCode::ConfigurationError,
ErrorKind::NoDefaultYarn => ExitCode::ConfigurationError,
ErrorKind::NpmLinkMissingPackage { .. } => ExitCode::ConfigurationError,
ErrorKind::NpmLinkWrongManager { .. } => ExitCode::ConfigurationError,
Expand All @@ -1490,6 +1534,7 @@ impl ErrorKind {
ErrorKind::ParsePackageConfigError => ExitCode::UnknownError,
ErrorKind::ParsePlatformError => ExitCode::ConfigurationError,
ErrorKind::PersistInventoryError { .. } => ExitCode::FileSystemError,
ErrorKind::PnpmVersionNotFound { .. } => ExitCode::NoVersionMatch,
ErrorKind::ProjectLocalBinaryExecError { .. } => ExitCode::ExecutionFailure,
ErrorKind::ProjectLocalBinaryNotFound { .. } => ExitCode::FileSystemError,
ErrorKind::PublishHookBothUrlAndBin => ExitCode::ConfigurationError,
Expand Down
Loading