Skip to content

fix: patch support unpublished pkg #9694

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

Merged
merged 6 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/blue-hairs-drum.md
Original file line number Diff line number Diff line change
@@ -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).
20 changes: 18 additions & 2 deletions patching/plugin-commands-patching/src/getPatchedDependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion patching/plugin-commands-patching/src/patchCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy