@@ -105,6 +105,35 @@ export async function capsule({
105105 await writeFile ( packageJsonPath , updatedContent , 'utf-8' )
106106 console . log ( chalk . green ( ` ✓ Updated workspace dependencies in ${ packageJsonPath } \n` ) )
107107 }
108+
109+ // Follow workspaces declarations to update sub-workspace package.json files
110+ const workspaces : string [ ] = packageJson . workspaces || [ ]
111+ if ( workspaces . length > 0 ) {
112+ const workspacePatterns = workspaces . map ( ws => join ( ws , 'package.json' ) )
113+ const subPackageJsonPaths = await glob ( workspacePatterns , {
114+ cwd : repoSourceDir as string ,
115+ absolute : true ,
116+ onlyFiles : true ,
117+ } )
118+
119+ for ( const subPkgPath of subPackageJsonPaths ) {
120+ try {
121+ const subContent = await readFile ( subPkgPath , 'utf-8' )
122+ const subIndent = detectIndent ( subContent )
123+ const subPkg = JSON . parse ( subContent )
124+
125+ await updateWorkspaceDependencies ( subPkg , workspaceNpmPackageNames , workspacePackageSourceDirs , publicNpmPackageNames )
126+
127+ const subUpdated = JSON . stringify ( subPkg , null , subIndent ) + '\n'
128+ if ( subUpdated !== subContent ) {
129+ await writeFile ( subPkgPath , subUpdated , 'utf-8' )
130+ console . log ( chalk . green ( ` ✓ Updated workspace dependencies in ${ subPkgPath } \n` ) )
131+ }
132+ } catch ( e ) {
133+ // Skip sub-workspaces with unreadable package.json
134+ }
135+ }
136+ }
108137 }
109138 }
110139 }
@@ -228,13 +257,13 @@ async function buildWorkspacePackageMaps(repositoriesConfig: any, npmRenames: Re
228257 workspaceNpmPackageNames [ renamedName ] = workspacePackageName
229258 }
230259 } catch ( error ) {
231- // Skip repos without a readable package.json
260+ console . log ( chalk . gray ( ` [debug] Could not read ${ packageJsonPath } : ${ error } ` ) )
232261 }
233262
234263 const providers = ( repoConfig as any ) . providers || ( ( repoConfig as any ) . provider ? [ ( repoConfig as any ) . provider ] : [ ] )
235264
236265 for ( const provider of providers ) {
237- if ( provider . capsule === 't44/caps/patterns/ npmjs.com/ProjectPublishing' ) {
266+ if ( provider . capsule === '@stream44.studio/t44- npmjs.com/caps /ProjectPublishing' ) {
238267 try {
239268 const packageJsonContent = await readFile ( packageJsonPath , 'utf-8' )
240269 const packageJson = JSON . parse ( packageJsonContent )
@@ -278,10 +307,14 @@ async function updateWorkspaceDependencies(
278307 if ( typeof depVersion === 'string' && depVersion . startsWith ( 'workspace:' ) ) {
279308 try {
280309 const workspaceDepName = workspaceNpmPackageNames [ depName ] || depName
281- const depSourceDir = workspacePackageSourceDirs [ workspaceDepName ]
310+ const depSourceDir = workspacePackageSourceDirs [ workspaceDepName ] || workspacePackageSourceDirs [ depName ]
282311
283312 if ( ! depSourceDir ) {
284- throw new Error ( `Could not find source directory for workspace dependency ${ depName } (${ workspaceDepName } )` )
313+ throw new Error (
314+ `Could not find source directory for workspace dependency ${ depName } (resolved to: ${ workspaceDepName } )\n` +
315+ ` workspaceNpmPackageNames keys: ${ Object . keys ( workspaceNpmPackageNames ) . join ( ', ' ) } \n` +
316+ ` workspacePackageSourceDirs keys: ${ Object . keys ( workspacePackageSourceDirs ) . join ( ', ' ) } `
317+ )
285318 }
286319
287320 const depPackageJsonPath = join ( depSourceDir , 'package.json' )
0 commit comments