@@ -21,6 +21,55 @@ const PACKAGE_JSON_PATHS: string[] = [
21
21
22
22
const DEPENDENCY_GROUP = '@jupyterlab' ;
23
23
24
+ interface IVersion {
25
+ major : number ;
26
+ minor : number ;
27
+ patch : number ;
28
+ preRelease ?: string ;
29
+ }
30
+
31
+ function parseVersion ( version : string ) : IVersion {
32
+ const match = version . match ( / ^ ( \d + ) \. ( \d + ) \. ( \d + ) (?: ( a | b | r c ) ( \d + ) ) ? $ / ) ;
33
+ if ( ! match ) {
34
+ throw new Error ( `Invalid version format: ${ version } ` ) ;
35
+ }
36
+
37
+ const [ , major , minor , patch , type , preVersion ] = match ;
38
+ const baseVersion = {
39
+ major : parseInt ( major , 10 ) ,
40
+ minor : parseInt ( minor , 10 ) ,
41
+ patch : parseInt ( patch , 10 ) ,
42
+ } ;
43
+
44
+ if ( type && preVersion ) {
45
+ return {
46
+ ...baseVersion ,
47
+ preRelease : `${ type } ${ preVersion } ` ,
48
+ } ;
49
+ }
50
+
51
+ return baseVersion ;
52
+ }
53
+
54
+ function getVersionRange ( version : IVersion ) : string {
55
+ const baseVersion = `${ version . major } .${ version . minor } .${ version . patch } ${
56
+ version . preRelease ?? ''
57
+ } `;
58
+ return `>=${ baseVersion } ,<${ version . major } .${ version . minor + 1 } ` ;
59
+ }
60
+
61
+ function updateVersionInFile (
62
+ filePath : string ,
63
+ pattern : RegExp ,
64
+ version : IVersion ,
65
+ isGlobal = false
66
+ ) : void {
67
+ const content = fs . readFileSync ( filePath , 'utf-8' ) ;
68
+ const versionRange = getVersionRange ( version ) ;
69
+ const updatedContent = content . replace ( pattern , `$1${ versionRange } ` ) ;
70
+ fs . writeFileSync ( filePath , updatedContent ) ;
71
+ }
72
+
24
73
async function updatePackageJson ( newVersion : string ) : Promise < void > {
25
74
const url = `https://raw.githubusercontent.com/jupyterlab/jupyterlab/v${ newVersion } /jupyterlab/staging/package.json` ;
26
75
const response = await fetch ( url ) ;
@@ -89,6 +138,33 @@ function absoluteVersion(version: string): string {
89
138
return version ;
90
139
}
91
140
141
+ async function updatePyprojectToml ( version : IVersion ) : Promise < void > {
142
+ const filePath = path . resolve ( 'pyproject.toml' ) ;
143
+ const pattern = / ( j u p y t e r l a b > = ) [ \d . ] + (?: a | b | r c \d + ) ? , < [ \d . ] + / g;
144
+ updateVersionInFile ( filePath , pattern , version , true ) ;
145
+ }
146
+
147
+ async function updatePreCommitConfig ( version : IVersion ) : Promise < void > {
148
+ const filePath = path . resolve ( '.pre-commit-config.yaml' ) ;
149
+ const pattern = / ( j u p y t e r l a b ) (?: > = | = = ) [ \d . ] + (?: , < [ \d . ] + ) ? (? = " | , | \s | $ ) / ;
150
+ updateVersionInFile ( filePath , pattern , version ) ;
151
+ }
152
+
153
+ // async function updateWorkflowFiles(version: IVersion): Promise<void> {
154
+ // const workflowDir = path.resolve('.github', 'workflows');
155
+ // const files = fs.readdirSync(workflowDir);
156
+ // const pattern = /(jupyterlab)(?:>=|==)[\d.]+(?:,<[\d.]+)?(?="|,|\s|$)/g;
157
+
158
+ // for (const file of files) {
159
+ // const filePath = path.join(workflowDir, file);
160
+ // const content = fs.readFileSync(filePath, 'utf-8');
161
+
162
+ // if (content.includes('jupyterlab>=')) {
163
+ // updateVersionInFile(filePath, pattern, version, true);
164
+ // }
165
+ // }
166
+ // }
167
+
92
168
async function upgradeLabDependencies ( ) : Promise < void > {
93
169
const args : string [ ] = process . argv . slice ( 2 ) ;
94
170
@@ -97,8 +173,11 @@ async function upgradeLabDependencies(): Promise<void> {
97
173
process . exit ( 1 ) ;
98
174
}
99
175
100
- const newVersion : string = args [ 1 ] ;
101
- await updatePackageJson ( newVersion ) ;
176
+ const version = parseVersion ( args [ 1 ] ) ;
177
+ await updatePackageJson ( args [ 1 ] ) ; // Keep original string version for package.json
178
+ await updatePyprojectToml ( version ) ;
179
+ await updatePreCommitConfig ( version ) ;
180
+ // await updateWorkflowFiles(version);
102
181
}
103
182
104
183
upgradeLabDependencies ( ) ;
0 commit comments