1+ #!/usr/bin/env node
2+
3+ const fs = require ( 'fs' ) ;
4+ const path = require ( 'path' ) ;
5+ const { execSync } = require ( 'child_process' ) ;
6+
7+ // Package dependency map - defines which packages depend on which
8+ const DEPENDENCY_MAP = {
9+ 'supabase' : [
10+ 'functions_client' ,
11+ 'gotrue' ,
12+ 'postgrest' ,
13+ 'realtime_client' ,
14+ 'storage_client' ,
15+ 'yet_another_json_isolate'
16+ ] ,
17+ 'supabase_flutter' : [
18+ 'supabase'
19+ ]
20+ } ;
21+
22+ // Read package version from pubspec.yaml
23+ function getPackageVersion ( packagePath ) {
24+ const pubspecPath = path . join ( packagePath , 'pubspec.yaml' ) ;
25+ const pubspec = fs . readFileSync ( pubspecPath , 'utf8' ) ;
26+ const match = pubspec . match ( / ^ v e r s i o n : \s + ( .+ ) $ / m) ;
27+ return match ? match [ 1 ] . trim ( ) : null ;
28+ }
29+
30+ // Update dependency version in pubspec.yaml
31+ function updateDependencyVersion ( packagePath , depName , newVersion ) {
32+ const pubspecPath = path . join ( packagePath , 'pubspec.yaml' ) ;
33+ let pubspec = fs . readFileSync ( pubspecPath , 'utf8' ) ;
34+
35+ // Update dependency version (exact match)
36+ const regex = new RegExp ( `(\\s+${ depName } :\\s+)([\\d\\.]+)` , 'g' ) ;
37+ const updated = pubspec . replace ( regex , `$1${ newVersion } ` ) ;
38+
39+ if ( updated !== pubspec ) {
40+ fs . writeFileSync ( pubspecPath , updated ) ;
41+ console . log ( `Updated ${ depName } to ${ newVersion } in ${ packagePath } ` ) ;
42+ return true ;
43+ }
44+
45+ return false ;
46+ }
47+
48+ // Check if any package has been updated by looking at git diff
49+ function getUpdatedPackages ( ) {
50+ try {
51+ const diff = execSync ( 'git diff --name-only HEAD~1' , { encoding : 'utf8' } ) ;
52+ const updatedPackages = new Set ( ) ;
53+
54+ diff . split ( '\\n' ) . forEach ( file => {
55+ const match = file . match ( / ^ p a c k a g e s \/ ( [ ^ \/ ] + ) \/ / ) ;
56+ if ( match ) {
57+ updatedPackages . add ( match [ 1 ] ) ;
58+ }
59+ } ) ;
60+
61+ return Array . from ( updatedPackages ) ;
62+ } catch ( error ) {
63+ console . log ( 'Could not determine updated packages, assuming all may need updates' ) ;
64+ return Object . keys ( DEPENDENCY_MAP ) . concat ( [ 'functions_client' , 'gotrue' , 'postgrest' , 'realtime_client' , 'storage_client' , 'yet_another_json_isolate' ] ) ;
65+ }
66+ }
67+
68+ function main ( ) {
69+ console . log ( 'Updating package dependencies...' ) ;
70+
71+ const packagesDir = 'packages' ;
72+ const updatedPackages = getUpdatedPackages ( ) ;
73+ let hasChanges = false ;
74+
75+ // For each package that depends on others
76+ Object . entries ( DEPENDENCY_MAP ) . forEach ( ( [ packageName , dependencies ] ) => {
77+ const packagePath = path . join ( packagesDir , packageName ) ;
78+
79+ if ( ! fs . existsSync ( packagePath ) ) {
80+ console . log ( `Package ${ packageName } not found, skipping` ) ;
81+ return ;
82+ }
83+
84+ // Check if any of its dependencies were updated
85+ const updatedDeps = dependencies . filter ( dep => updatedPackages . includes ( dep ) ) ;
86+
87+ if ( updatedDeps . length === 0 ) {
88+ console . log ( `No dependency updates needed for ${ packageName } ` ) ;
89+ return ;
90+ }
91+
92+ console . log ( `Updating dependencies for ${ packageName } : ${ updatedDeps . join ( ', ' ) } ` ) ;
93+
94+ // Update each dependency to its new version
95+ updatedDeps . forEach ( depName => {
96+ const depPath = path . join ( packagesDir , depName ) ;
97+ const newVersion = getPackageVersion ( depPath ) ;
98+
99+ if ( newVersion ) {
100+ const updated = updateDependencyVersion ( packagePath , depName , newVersion ) ;
101+ if ( updated ) {
102+ hasChanges = true ;
103+ }
104+ }
105+ } ) ;
106+ } ) ;
107+
108+ if ( hasChanges ) {
109+ console . log ( 'Dependencies updated, changes will be committed automatically' ) ;
110+ } else {
111+ console . log ( 'No dependency updates were needed' ) ;
112+ }
113+ }
114+
115+ if ( require . main === module ) {
116+ main ( ) ;
117+ }
0 commit comments