1- import { execSync } from " node:child_process" ;
2- import * as fs from " node:fs" ;
3- import fg from " fast-glob" ;
1+ import { execSync } from ' node:child_process' ;
2+ import * as fs from ' node:fs' ;
3+ import fg from ' fast-glob' ;
44
55// This script is used by the `release.yml` workflow to update the version of the packages being released.
66// The standard step is only to run `changeset version` but this does not update the package-lock.json file.
77// So we also run `npm install`, which does this update.
88// This is a workaround until this is handled automatically by `changeset version`.
99// See https://github.com/changesets/changesets/issues/421.
10- execSync ( " npx changeset version" , {
11- stdio : " inherit" ,
10+ execSync ( ' npx changeset version' , {
11+ stdio : ' inherit'
1212} ) ;
13- execSync ( " npm install" , {
14- stdio : " inherit" ,
13+ execSync ( ' npm install' , {
14+ stdio : ' inherit'
1515} ) ;
1616
1717// Update all version references across the codebase after changeset updates package.json
1818try {
19- const packageJson = JSON . parse ( fs . readFileSync ( "./packages/sandbox/package.json" , "utf-8" ) ) ;
19+ const packageJson = JSON . parse (
20+ fs . readFileSync ( './packages/sandbox/package.json' , 'utf-8' )
21+ ) ;
2022 const newVersion = packageJson . version ;
2123
22- console . log ( `\n🔍 Searching for version references to update to ${ newVersion } ...\n` ) ;
24+ console . log (
25+ `\n🔍 Searching for version references to update to ${ newVersion } ...\n`
26+ ) ;
2327
2428 // Patterns to match version references in different contexts
2529 const versionPatterns = [
2630 // SDK version constant
2731 {
2832 pattern : / e x p o r t c o n s t S D K _ V E R S I O N = ' [ \d . ] + ' ; / g,
2933 replacement : `export const SDK_VERSION = '${ newVersion } ';` ,
30- description : " SDK version constant in version.ts" ,
34+ description : ' SDK version constant in version.ts'
3135 } ,
3236 // Docker image versions (production and test)
3337 {
3438 pattern : / F R O M d o c k e r \. i o \/ c l o u d f l a r e \/ s a n d b o x : [ \d . ] + / g,
3539 replacement : `FROM docker.io/cloudflare/sandbox:${ newVersion } ` ,
36- description : " Production Docker image" ,
40+ description : ' Production Docker image'
3741 } ,
3842 {
3943 pattern : / # F R O M d o c k e r \. i o \/ c l o u d f l a r e \/ s a n d b o x : [ \d . ] + / g,
4044 replacement : `# FROM docker.io/cloudflare/sandbox:${ newVersion } ` ,
41- description : " Commented production Docker image" ,
45+ description : ' Commented production Docker image'
4246 } ,
4347 {
4448 pattern : / F R O M c l o u d f l a r e \/ s a n d b o x - t e s t : [ \d . ] + / g,
4549 replacement : `FROM cloudflare/sandbox-test:${ newVersion } ` ,
46- description : " Test Docker image" ,
50+ description : ' Test Docker image'
4751 } ,
4852 {
4953 pattern : / d o c k e r \. i o \/ c l o u d f l a r e \/ s a n d b o x - t e s t : [ \d . ] + / g,
5054 replacement : `docker.io/cloudflare/sandbox-test:${ newVersion } ` ,
51- description : " Test Docker image (docker.io)" ,
55+ description : ' Test Docker image (docker.io)'
5256 } ,
5357 // Image tags in docker commands
5458 {
5559 pattern : / c l o u d f l a r e \/ s a n d b o x : [ \d . ] + / g,
5660 replacement : `cloudflare/sandbox:${ newVersion } ` ,
57- description : " Docker image reference" ,
61+ description : ' Docker image reference'
5862 } ,
5963 {
6064 pattern : / c l o u d f l a r e \/ s a n d b o x - t e s t : [ \d . ] + / g,
6165 replacement : `cloudflare/sandbox-test:${ newVersion } ` ,
62- description : " Test Docker image reference" ,
66+ description : ' Test Docker image reference'
6367 } ,
6468 // Example package.json dependencies
6569 {
6670 pattern : / " @ c l o u d f l a r e \/ s a n d b o x " : \s * " \^ [ \d . ] + " / g,
6771 replacement : `"@cloudflare/sandbox": "^${ newVersion } "` ,
68- description : " Example package.json @cloudflare/sandbox dependencies" ,
69- } ,
72+ description : ' Example package.json @cloudflare/sandbox dependencies'
73+ }
7074 ] ;
7175
7276 // Files to search and update
7377 const filePatterns = [
74- " **/*.md" , // All markdown files
75- " **/Dockerfile" , // All Dockerfiles
76- " **/Dockerfile.*" , // Dockerfile variants
77- " **/*.ts" , // TypeScript files (for documentation comments)
78- " **/*.js" , // JavaScript files
79- " **/*.json" , // JSON configs (but not package.json/package-lock.json)
80- " **/*.yaml" , // YAML configs
81- " **/*.yml" , // YML configs
82- " examples/**/package.json" , // Example package.json files (exception to ignore rule below)
78+ ' **/*.md' , // All markdown files
79+ ' **/Dockerfile' , // All Dockerfiles
80+ ' **/Dockerfile.*' , // Dockerfile variants
81+ ' **/*.ts' , // TypeScript files (for documentation comments)
82+ ' **/*.js' , // JavaScript files
83+ ' **/*.json' , // JSON configs (but not package.json/package-lock.json)
84+ ' **/*.yaml' , // YAML configs
85+ ' **/*.yml' , // YML configs
86+ ' examples/**/package.json' // Example package.json files (exception to ignore rule below)
8387 ] ;
8488
8589 // Ignore patterns
8690 const ignorePatterns = [
87- " **/node_modules/**" ,
88- " **/dist/**" ,
89- " **/build/**" ,
90- " **/.git/**" ,
91- " **/package.json" , // Don't modify package.json (changeset does this)
92- " **/package-lock.json" , // Don't modify package-lock.json (npm install does this)
93- " **/.github/changeset-version.ts" , // Don't modify this script itself
91+ ' **/node_modules/**' ,
92+ ' **/dist/**' ,
93+ ' **/build/**' ,
94+ ' **/.git/**' ,
95+ ' **/package.json' , // Don't modify package.json (changeset does this)
96+ ' **/package-lock.json' , // Don't modify package-lock.json (npm install does this)
97+ ' **/.github/changeset-version.ts' // Don't modify this script itself
9498 ] ;
9599
96100 // Find all matching files
97101 const files = await fg ( filePatterns , {
98102 ignore : ignorePatterns ,
99- onlyFiles : true ,
103+ onlyFiles : true
100104 } ) ;
101105
102106 console . log ( `📁 Found ${ files . length } files to check\n` ) ;
@@ -105,7 +109,7 @@ try {
105109 let totalReplacementsCount = 0 ;
106110
107111 for ( const file of files ) {
108- let content = fs . readFileSync ( file , " utf-8" ) ;
112+ let content = fs . readFileSync ( file , ' utf-8' ) ;
109113 let fileModified = false ;
110114 let fileReplacementsCount = 0 ;
111115
@@ -123,14 +127,21 @@ try {
123127 fs . writeFileSync ( file , content ) ;
124128 updatedFilesCount ++ ;
125129 totalReplacementsCount += fileReplacementsCount ;
126- console . log ( ` ✅ ${ file } (${ fileReplacementsCount } replacement${ fileReplacementsCount > 1 ? 's' : '' } )` ) ;
130+ console . log (
131+ ` ✅ ${ file } (${ fileReplacementsCount } replacement${
132+ fileReplacementsCount > 1 ? 's' : ''
133+ } )`
134+ ) ;
127135 }
128136 }
129137
130- console . log ( `\n✨ Updated ${ totalReplacementsCount } version reference${ totalReplacementsCount !== 1 ? 's' : '' } across ${ updatedFilesCount } file${ updatedFilesCount !== 1 ? 's' : '' } ` ) ;
138+ console . log (
139+ `\n✨ Updated ${ totalReplacementsCount } version reference${
140+ totalReplacementsCount !== 1 ? 's' : ''
141+ } across ${ updatedFilesCount } file${ updatedFilesCount !== 1 ? 's' : '' } `
142+ ) ;
131143 console . log ( ` New version: ${ newVersion } \n` ) ;
132-
133144} catch ( error ) {
134- console . error ( " ❌ Failed to update file versions:" , error ) ;
145+ console . error ( ' ❌ Failed to update file versions:' , error ) ;
135146 // Don't fail the whole release for this
136147}
0 commit comments