@@ -29,6 +29,35 @@ function cleanupTracingSnapshot(packagePath: string, pkg: string): void {
2929 rmSync ( join ( packagePath , TRACING_INTERNAL_SUBPATH ) , { recursive : true , force : true } )
3030}
3131
32+ // JSR rejects pnpm's `workspace:*` protocol as an unpinned npm specifier. Before
33+ // publishing, swap every `workspace:<range>` entry in package.json for the
34+ // package's own version (fixed-release mode means all siblings share it), then
35+ // restore the original file in the finally block.
36+ function rewriteWorkspaceDeps ( packagePath : string , version : string ) : string {
37+ const pkgJsonPath = join ( packagePath , 'package.json' )
38+ const original = readFileSync ( pkgJsonPath , 'utf-8' )
39+ const pkgJson = JSON . parse ( original )
40+ let touched = false
41+ for ( const section of [ 'dependencies' , 'devDependencies' ] as const ) {
42+ const deps = pkgJson [ section ]
43+ if ( ! deps ) continue
44+ for ( const [ name , value ] of Object . entries ( deps ) ) {
45+ if ( typeof value === 'string' && value . startsWith ( 'workspace:' ) ) {
46+ deps [ name ] = version
47+ touched = true
48+ }
49+ }
50+ }
51+ if ( touched ) {
52+ writeFileSync ( pkgJsonPath , JSON . stringify ( pkgJson , null , 2 ) + '\n' )
53+ }
54+ return original
55+ }
56+
57+ function restorePackageJson ( packagePath : string , original : string ) : void {
58+ writeFileSync ( join ( packagePath , 'package.json' ) , original )
59+ }
60+
3261function getArg ( name : string ) : string | undefined {
3362 const idx = process . argv . findIndex ( ( a ) => a === `--${ name } ` || a . startsWith ( `--${ name } =` ) )
3463 if ( idx === - 1 ) return undefined
@@ -86,6 +115,9 @@ async function publishToJsr() {
86115 jsrConfig . version = version
87116 writeFileSync ( jsrPath , JSON . stringify ( jsrConfig , null , 2 ) + '\n' )
88117
118+ // Pin workspace:* sibling deps so JSR sees a real version constraint.
119+ const originalPackageJson = rewriteWorkspaceDeps ( packagePath , version )
120+
89121 // Snapshot any internal workspace deps that JSR would otherwise reject for
90122 // missing version constraints. See TRACING_SNAPSHOT_SOURCES for details.
91123 copyTracingSnapshot ( packagePath , pkg )
@@ -113,6 +145,8 @@ async function publishToJsr() {
113145 } finally {
114146 // Restore original jsr.json to keep working directory clean
115147 writeFileSync ( jsrPath , originalJsrContent )
148+ // Restore package.json (workspace:* sibling deps)
149+ restorePackageJson ( packagePath , originalPackageJson )
116150 // Remove any internal snapshot copies created above
117151 cleanupTracingSnapshot ( packagePath , pkg )
118152 }
0 commit comments