1+ #!/usr/bin/env node
2+
3+ const fs = require ( 'fs' ) ;
4+ const path = require ( 'path' ) ;
5+ const { execSync } = require ( 'child_process' ) ;
6+
7+ console . log ( '🔄 Updating @pgsql/types versions in versions/* packages...\n' ) ;
8+
9+ // Fetch dist-tags for @pgsql/types from npm
10+ console . log ( '📡 Fetching latest @pgsql/types versions from npm dist-tags...' ) ;
11+ let distTags ;
12+ try {
13+ const npmOutput = execSync ( 'npm view @pgsql/types dist-tags --json' , { encoding : 'utf8' } ) ;
14+ distTags = JSON . parse ( npmOutput ) ;
15+ } catch ( error ) {
16+ console . error ( '❌ Failed to fetch npm data:' , error . message ) ;
17+ process . exit ( 1 ) ;
18+ }
19+
20+ // Extract versions for PostgreSQL 13-17
21+ const typeVersions = { } ;
22+ for ( let pgVersion = 13 ; pgVersion <= 17 ; pgVersion ++ ) {
23+ const tag = `pg${ pgVersion } ` ;
24+ if ( distTags [ tag ] ) {
25+ typeVersions [ pgVersion . toString ( ) ] = distTags [ tag ] ;
26+ }
27+ }
28+
29+ console . log ( '\n📦 Found latest versions from npm:' ) ;
30+ Object . entries ( typeVersions ) . sort ( ( [ a ] , [ b ] ) => parseInt ( a ) - parseInt ( b ) ) . forEach ( ( [ major , version ] ) => {
31+ console . log ( ` PostgreSQL ${ major } → @pgsql/types@${ version } ` ) ;
32+ } ) ;
33+ console . log ( ) ;
34+
35+ // Get all version directories
36+ const versionsDir = path . join ( __dirname , '..' , 'versions' ) ;
37+ const versionDirs = fs . readdirSync ( versionsDir )
38+ . filter ( dir => / ^ \d + $ / . test ( dir ) )
39+ . sort ( ( a , b ) => parseInt ( a ) - parseInt ( b ) ) ;
40+
41+ let updatedCount = 0 ;
42+
43+ versionDirs . forEach ( version => {
44+ const packageJsonPath = path . join ( versionsDir , version , 'package.json' ) ;
45+
46+ if ( ! fs . existsSync ( packageJsonPath ) ) {
47+ console . log ( `⚠️ No package.json found for version ${ version } ` ) ;
48+ return ;
49+ }
50+
51+ const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ;
52+ const targetTypeVersion = typeVersions [ version ] ;
53+
54+ if ( ! targetTypeVersion ) {
55+ console . log ( `⚠️ No type version mapping found for PostgreSQL ${ version } ` ) ;
56+ return ;
57+ }
58+
59+ const currentTypeVersion = packageJson . dependencies ?. [ '@pgsql/types' ] ;
60+ const expectedTypeVersion = `^${ targetTypeVersion } ` ;
61+
62+ if ( currentTypeVersion === expectedTypeVersion ) {
63+ console . log ( `✅ Version ${ version } : @pgsql/types already up to date (${ currentTypeVersion } )` ) ;
64+ return ;
65+ }
66+
67+ // Update the dependency
68+ if ( ! packageJson . dependencies ) {
69+ packageJson . dependencies = { } ;
70+ }
71+
72+ packageJson . dependencies [ '@pgsql/types' ] = expectedTypeVersion ;
73+
74+ // Write back the updated package.json
75+ fs . writeFileSync (
76+ packageJsonPath ,
77+ JSON . stringify ( packageJson , null , 2 ) + '\n' ,
78+ 'utf8'
79+ ) ;
80+
81+ console . log ( `📦 Version ${ version } : Updated @pgsql/types from ${ currentTypeVersion || 'none' } to ${ expectedTypeVersion } ` ) ;
82+ updatedCount ++ ;
83+ } ) ;
84+
85+ console . log ( `\n✨ Updated ${ updatedCount } package(s)` ) ;
86+
87+ if ( updatedCount > 0 ) {
88+ console . log ( '\n💡 Next steps:' ) ;
89+ console . log ( ' 1. Run "pnpm install" to update lockfile' ) ;
90+ console . log ( ' 2. Test the changes' ) ;
91+ console . log ( ' 3. Commit the updates' ) ;
92+ }
0 commit comments