mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-30 10:38:13 -05:00
fix: patch support unpublished pkg (#9694)
This commit is contained in:
6
.changeset/blue-hairs-drum.md
Normal file
6
.changeset/blue-hairs-drum.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-patching": patch
|
||||
pnpm: patch
|
||||
---
|
||||
|
||||
When patching dependencies installed via `pkg.pr.new`, treat them as git tarball URLs [#9694](https://github.com/pnpm/pnpm/pull/9694).
|
||||
@@ -58,14 +58,30 @@ export async function getPatchedDependency (rawDependency: string, opts: GetPatc
|
||||
}
|
||||
} else {
|
||||
const preferred = preferredVersions[0]
|
||||
if (preferred.gitTarballUrl) {
|
||||
return {
|
||||
...opts,
|
||||
applyToAll: false,
|
||||
bareSpecifier: preferred.gitTarballUrl,
|
||||
}
|
||||
}
|
||||
return {
|
||||
...dep,
|
||||
applyToAll: !dep.bareSpecifier,
|
||||
bareSpecifier: preferred.gitTarballUrl ?? preferred.version,
|
||||
bareSpecifier: preferred.version,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/stackblitz-labs/pkg.pr.new
|
||||
// With pkg.pr.new, each of your commits and pull requests will trigger an instant preview release without publishing anything to NPM.
|
||||
// This enables users to access features and bug-fixes without the need to wait for release cycles using npm or pull request merges.
|
||||
// When a package is installed via pkg.pr.new and has never been published to npm,
|
||||
// the version or name obtained is incorrect, and an error will occur when patching. We can treat it as a tarball url.
|
||||
export function isPkgPrNewUrl (url: string): boolean {
|
||||
return url.startsWith('https://pkg.pr.new/')
|
||||
}
|
||||
|
||||
export interface LockfileVersion {
|
||||
gitTarballUrl?: string
|
||||
name: string
|
||||
@@ -101,7 +117,7 @@ export async function getVersionsFromLockfile (dep: ParseWantedDependencyResult,
|
||||
const tarball = (pkgSnapshot.resolution as TarballResolution)?.tarball ?? ''
|
||||
return {
|
||||
...nameVerFromPkgSnapshot(depPath, pkgSnapshot),
|
||||
gitTarballUrl: isGitHostedPkgUrl(tarball) ? tarball : undefined,
|
||||
gitTarballUrl: (isGitHostedPkgUrl(tarball) || isPkgPrNewUrl(tarball)) ? tarball : undefined,
|
||||
}
|
||||
})
|
||||
.filter(({ name }) => name === pkgName)
|
||||
|
||||
@@ -74,7 +74,7 @@ export async function handler (opts: PatchCommitCommandOptions, params: string[]
|
||||
if (!applyToAll) {
|
||||
gitTarballUrl = await getGitTarballUrlFromLockfile({
|
||||
alias: patchedPkgManifest.name,
|
||||
bareSpecifier: patchedPkgManifest.version,
|
||||
bareSpecifier: patchedPkgManifest.version || undefined,
|
||||
}, {
|
||||
lockfileDir,
|
||||
modulesDir: opts.modulesDir,
|
||||
|
||||
Reference in New Issue
Block a user