mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-18 05:42:27 -04: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 {
|
} else {
|
||||||
const preferred = preferredVersions[0]
|
const preferred = preferredVersions[0]
|
||||||
|
if (preferred.gitTarballUrl) {
|
||||||
|
return {
|
||||||
|
...opts,
|
||||||
|
applyToAll: false,
|
||||||
|
bareSpecifier: preferred.gitTarballUrl,
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...dep,
|
...dep,
|
||||||
applyToAll: !dep.bareSpecifier,
|
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 {
|
export interface LockfileVersion {
|
||||||
gitTarballUrl?: string
|
gitTarballUrl?: string
|
||||||
name: string
|
name: string
|
||||||
@@ -101,7 +117,7 @@ export async function getVersionsFromLockfile (dep: ParseWantedDependencyResult,
|
|||||||
const tarball = (pkgSnapshot.resolution as TarballResolution)?.tarball ?? ''
|
const tarball = (pkgSnapshot.resolution as TarballResolution)?.tarball ?? ''
|
||||||
return {
|
return {
|
||||||
...nameVerFromPkgSnapshot(depPath, pkgSnapshot),
|
...nameVerFromPkgSnapshot(depPath, pkgSnapshot),
|
||||||
gitTarballUrl: isGitHostedPkgUrl(tarball) ? tarball : undefined,
|
gitTarballUrl: (isGitHostedPkgUrl(tarball) || isPkgPrNewUrl(tarball)) ? tarball : undefined,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(({ name }) => name === pkgName)
|
.filter(({ name }) => name === pkgName)
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export async function handler (opts: PatchCommitCommandOptions, params: string[]
|
|||||||
if (!applyToAll) {
|
if (!applyToAll) {
|
||||||
gitTarballUrl = await getGitTarballUrlFromLockfile({
|
gitTarballUrl = await getGitTarballUrlFromLockfile({
|
||||||
alias: patchedPkgManifest.name,
|
alias: patchedPkgManifest.name,
|
||||||
bareSpecifier: patchedPkgManifest.version,
|
bareSpecifier: patchedPkgManifest.version || undefined,
|
||||||
}, {
|
}, {
|
||||||
lockfileDir,
|
lockfileDir,
|
||||||
modulesDir: opts.modulesDir,
|
modulesDir: opts.modulesDir,
|
||||||
|
|||||||
Reference in New Issue
Block a user