@@ -32,6 +32,36 @@ export async function retrofit(flags: ParsedFlags) {
32
32
}
33
33
34
34
async function retrofitTypes ( flags : Map < string , string | number | boolean | null > ) {
35
+ if ( ! flags . get ( 'monorepo' ) ) {
36
+ return retrofitTypesForProject ( flags ) ;
37
+ }
38
+
39
+ // get the monorepo packages
40
+ const { getPackageList } = await import ( '../../shared/repo' ) ;
41
+ const { packages, rootDir, rootPackage, pkgManager } = await getPackageList ( ) ;
42
+ const originalDir = process . cwd ( ) ;
43
+
44
+ for ( const pkg of packages ) {
45
+ write ( `Updating ${ chalk . cyan ( pkg . packageJson . name ) } \n====================\n` ) ;
46
+ process . chdir ( pkg . dir ) ;
47
+ await retrofitTypesForProject ( flags ) ;
48
+ }
49
+
50
+ write ( `Updating ${ chalk . cyan ( rootPackage ! . packageJson . name ) } (<monoreporoot>)\n====================\n` ) ;
51
+ process . chdir ( rootDir ) ;
52
+ await retrofitTypesForProject ( flags , { isRoot : true , pkgManager } ) ;
53
+
54
+ const installCmd = `${ pkgManager } install` ;
55
+ await exec ( installCmd ) ;
56
+ write ( `\t✅ Updated lockfile` ) ;
57
+
58
+ process . chdir ( originalDir ) ;
59
+ }
60
+
61
+ async function retrofitTypesForProject (
62
+ flags : Map < string , string | number | boolean | null > ,
63
+ options ?: { isRoot : boolean ; pkgManager : string }
64
+ ) {
35
65
const version = flags . get ( 'version' ) ;
36
66
assertIsString ( version ) ;
37
67
@@ -232,7 +262,7 @@ async function retrofitTypes(flags: Map<string, string | number | boolean | null
232
262
233
263
// add the packages to the package.json
234
264
// and install them
235
- write ( chalk . grey ( `\t📦 Installing ${ toInstall . size } packages` ) ) ;
265
+ write ( chalk . grey ( `\t📦 Updating versions for ${ toInstall . size } packages` ) ) ;
236
266
if ( toInstall . size > 0 ) {
237
267
// add the packages to the package.json
238
268
for ( const [ pkgName , config ] of toInstall ) {
@@ -262,6 +292,32 @@ async function retrofitTypes(flags: Map<string, string | number | boolean | null
262
292
}
263
293
pkg . devDependencies = sortedDeps ;
264
294
}
295
+ if ( pkg . pnpm ?. overrides ) {
296
+ const keys = Object . keys ( pkg . pnpm . overrides ?? { } ) . sort ( ) ;
297
+ const sortedDeps : Record < string , string > = { } ;
298
+ for ( const key of keys ) {
299
+ sortedDeps [ key ] = pkg . pnpm . overrides [ key ] ;
300
+ }
301
+ pkg . pnpm . overrides = sortedDeps ;
302
+ }
303
+ }
304
+
305
+ const overrideChanges = new Set < string > ( ) ;
306
+ if ( pkg . pnpm ?. overrides ) {
307
+ write ( chalk . grey ( `\t🔍 Checking for pnpm overrides to update` ) ) ;
308
+ for ( const pkgName of Object . keys ( pkg . pnpm . overrides ) ) {
309
+ if ( toInstall . has ( pkgName ) ) {
310
+ const value = pkg . pnpm . overrides [ pkgName ] ;
311
+ const info = await getInfo ( `${ pkgName } @${ version } ` ) ;
312
+ const newValue = info . version ;
313
+
314
+ if ( value !== newValue ) {
315
+ overrideChanges . add ( pkgName ) ;
316
+ pkg . pnpm . overrides [ pkgName ] = newValue ;
317
+ }
318
+ }
319
+ }
320
+ write ( chalk . grey ( `\t✅ Updated ${ overrideChanges . size } pnpm overrides` ) ) ;
265
321
}
266
322
267
323
const removed = new Set ( ) ;
@@ -277,15 +333,31 @@ async function retrofitTypes(flags: Map<string, string | number | boolean | null
277
333
}
278
334
write ( chalk . grey ( `\t🗑 Removing ${ removed . size } DefinitelyTyped packages` ) ) ;
279
335
280
- if ( removed . size > 0 || toInstall . size > 0 ) {
336
+ if ( removed . size > 0 || toInstall . size > 0 || overrideChanges . size > 0 ) {
281
337
writePkgJson ( pkg ) ;
338
+ write ( `\t✅ Updated package.json` ) ;
282
339
283
340
// determine which package manager to use
284
341
// and install the packages
285
- const pkgManager = getPackageManagerFromLockfile ( ) ;
286
- const installCmd = `${ pkgManager } install` ;
287
- await exec ( installCmd ) ;
288
- write ( `\t✅ Updated package.json` ) ;
342
+ if ( ! flags . get ( 'monorepo' ) ) {
343
+ const pkgManager = getPackageManagerFromLockfile ( ) ;
344
+ const installCmd = `${ pkgManager } install` ;
345
+ await exec ( installCmd ) ;
346
+ write ( `\t✅ Updated lockfile` ) ;
347
+ } else {
348
+ write ( `\t☑️ Skipped lockfile update` ) ;
349
+ }
350
+ }
351
+
352
+ const hasAtLeastOnePackage = toInstall . size > 0 || needed . size > 0 || installed . size > 0 ;
353
+ if ( ! hasAtLeastOnePackage ) {
354
+ write ( `\tNo WarpDrive/EmberData packages detected` ) ;
355
+ return ;
356
+ }
357
+
358
+ if ( options ?. isRoot ) {
359
+ write ( chalk . grey ( `\t☑️ Skipped tsconfig.json update for monorepo root` ) ) ;
360
+ return ;
289
361
}
290
362
291
363
// ensure tsconfig for each installed and needed package
@@ -296,9 +368,9 @@ async function retrofitTypes(flags: Map<string, string | number | boolean | null
296
368
write ( chalk . yellow ( `\t⚠️ No tsconfig.json found in the current working directory` ) ) ;
297
369
const tsConfig = structuredClone ( TS_CONFIG ) as { compilerOptions : { types : string [ ] } } ;
298
370
tsConfig . compilerOptions . types = [ 'ember-source/types' ] ;
299
- for ( const [ pkgName ] of toInstall ) {
371
+ for ( const [ pkgName , details ] of toInstall ) {
300
372
if ( Types . includes ( pkgName ) ) {
301
- const typePath = getTypePathFor ( pkgName ) ;
373
+ const typePath = await getTypePathFor ( pkgName , details . version ) ;
302
374
if ( ! typePath ) {
303
375
throw new Error ( `Could not find type path for ${ pkgName } ` ) ;
304
376
}
@@ -326,9 +398,9 @@ async function retrofitTypes(flags: Map<string, string | number | boolean | null
326
398
tsConfig . compilerOptions . types . push ( 'ember-source/types' ) ;
327
399
}
328
400
329
- for ( const [ pkgName ] of toInstall ) {
401
+ for ( const [ pkgName , details ] of toInstall ) {
330
402
if ( Types . includes ( pkgName ) ) {
331
- const typePath = getTypePathFor ( pkgName ) ;
403
+ const typePath = await getTypePathFor ( pkgName , details . version ) ;
332
404
if ( ! typePath ) {
333
405
throw new Error ( `Could not find type path for ${ pkgName } ` ) ;
334
406
}
0 commit comments