@@ -2,94 +2,100 @@ import fs from 'fs';
2
2
import path from 'path' ;
3
3
4
4
const PACKAGE_JSON_PATHS : string [ ] = [
5
- " app/package.json" ,
6
- " buildutils/package.json" ,
7
- " package.json" ,
8
- " packages/application-extension/package.json" ,
9
- " packages/application/package.json" ,
10
- " packages/console-extension/package.json" ,
11
- " packages/docmanager-extension/package.json" ,
12
- " packages/documentsearch-extension/package.json" ,
13
- " packages/help-extension/package.json" ,
14
- " packages/lab-extension/package.json" ,
15
- " packages/notebook-extension/package.json" ,
16
- " packages/terminal-extension/package.json" ,
17
- " packages/tree-extension/package.json" ,
18
- " packages/tree/package.json" ,
19
- " packages/ui-components/package.json" ,
5
+ ' app/package.json' ,
6
+ ' buildutils/package.json' ,
7
+ ' package.json' ,
8
+ ' packages/application-extension/package.json' ,
9
+ ' packages/application/package.json' ,
10
+ ' packages/console-extension/package.json' ,
11
+ ' packages/docmanager-extension/package.json' ,
12
+ ' packages/documentsearch-extension/package.json' ,
13
+ ' packages/help-extension/package.json' ,
14
+ ' packages/lab-extension/package.json' ,
15
+ ' packages/notebook-extension/package.json' ,
16
+ ' packages/terminal-extension/package.json' ,
17
+ ' packages/tree-extension/package.json' ,
18
+ ' packages/tree/package.json' ,
19
+ ' packages/ui-components/package.json' ,
20
20
] ;
21
21
22
- const DEPENDENCY_GROUP : string = " @jupyterlab" ;
22
+ const DEPENDENCY_GROUP = ' @jupyterlab' ;
23
23
24
24
async function updatePackageJson ( newVersion : string ) : Promise < void > {
25
- const url : string = `https://raw.githubusercontent.com/jupyterlab/jupyterlab/v${ newVersion } /jupyterlab/staging/package.json` ;
26
- const response = await fetch ( url ) ;
25
+ const url = `https://raw.githubusercontent.com/jupyterlab/jupyterlab/v${ newVersion } /jupyterlab/staging/package.json` ;
26
+ const response = await fetch ( url ) ;
27
27
28
- if ( ! response . ok ) {
29
- const errorMessage : string = `Failed to fetch package.json from ${ url } . HTTP status code: ${ response . status } ` ;
30
- throw new Error ( errorMessage ) ;
31
- }
28
+ if ( ! response . ok ) {
29
+ const errorMessage = `Failed to fetch package.json from ${ url } . HTTP status code: ${ response . status } ` ;
30
+ throw new Error ( errorMessage ) ;
31
+ }
32
32
33
- const newPackageJson = await response . json ( ) ;
33
+ const newPackageJson = await response . json ( ) ;
34
34
35
- for ( const packageJsonPath of PACKAGE_JSON_PATHS ) {
36
- const filePath : string = path . resolve ( packageJsonPath ) ;
37
- const existingPackageJson = JSON . parse ( fs . readFileSync ( filePath , 'utf-8' ) ) ;
35
+ for ( const packageJsonPath of PACKAGE_JSON_PATHS ) {
36
+ const filePath : string = path . resolve ( packageJsonPath ) ;
37
+ const existingPackageJson = JSON . parse ( fs . readFileSync ( filePath , 'utf-8' ) ) ;
38
38
39
- const newDependencies = {
40
- ...newPackageJson . devDependencies ,
41
- ...newPackageJson . resolutions
42
- } ;
39
+ const newDependencies = {
40
+ ...newPackageJson . devDependencies ,
41
+ ...newPackageJson . resolutions ,
42
+ } ;
43
43
44
- updateDependencyVersion ( existingPackageJson , newDependencies ) ;
44
+ updateDependencyVersion ( existingPackageJson , newDependencies ) ;
45
45
46
- fs . writeFileSync ( filePath , JSON . stringify ( existingPackageJson , null , 2 ) ) ;
47
- }
46
+ fs . writeFileSync ( filePath , JSON . stringify ( existingPackageJson , null , 2 ) ) ;
47
+ }
48
48
}
49
49
50
50
function updateDependencyVersion ( existingJson : any , newJson : any ) : void {
51
- if ( ! existingJson ) {
52
- return ;
51
+ if ( ! existingJson ) {
52
+ return ;
53
+ }
54
+
55
+ const sectionPaths : string [ ] = [
56
+ 'resolutions' ,
57
+ 'dependencies' ,
58
+ 'devDependencies' ,
59
+ ] ;
60
+
61
+ for ( const section of sectionPaths ) {
62
+ if ( ! existingJson [ section ] ) {
63
+ continue ;
53
64
}
54
65
55
- const sectionPaths : string [ ] = [ "resolutions" , "dependencies" , "devDependencies" ] ;
66
+ const updated = existingJson [ section ] ;
56
67
57
- for ( const section of sectionPaths ) {
58
- if ( ! existingJson [ section ] ) {
59
- continue ;
60
- }
61
-
62
- const updated = existingJson [ section ] ;
63
-
64
- for ( const [ pkg , version ] of Object . entries < string > ( existingJson [ section ] ) ) {
65
- if ( pkg . startsWith ( DEPENDENCY_GROUP ) && pkg in newJson ) {
66
- if ( version [ 0 ] === '^' || version [ 0 ] === '~' ) {
67
- updated [ pkg ] = version [ 0 ] + absoluteVersion ( newJson [ pkg ] ) ;
68
- } else {
69
- updated [ pkg ] = absoluteVersion ( newJson [ pkg ] ) ;
70
- }
71
- }
68
+ for ( const [ pkg , version ] of Object . entries < string > (
69
+ existingJson [ section ]
70
+ ) ) {
71
+ if ( pkg . startsWith ( DEPENDENCY_GROUP ) && pkg in newJson ) {
72
+ if ( version [ 0 ] === '^' || version [ 0 ] === '~' ) {
73
+ updated [ pkg ] = version [ 0 ] + absoluteVersion ( newJson [ pkg ] ) ;
74
+ } else {
75
+ updated [ pkg ] = absoluteVersion ( newJson [ pkg ] ) ;
72
76
}
77
+ }
73
78
}
79
+ }
74
80
}
75
81
76
82
function absoluteVersion ( version : string ) : string {
77
- if ( version . length > 0 && ( version [ 0 ] === '^' || version [ 0 ] === '~' ) ) {
78
- return version . substring ( 1 ) ;
79
- }
80
- return version ;
83
+ if ( version . length > 0 && ( version [ 0 ] === '^' || version [ 0 ] === '~' ) ) {
84
+ return version . substring ( 1 ) ;
85
+ }
86
+ return version ;
81
87
}
82
88
83
89
async function upgradeLabDependencies ( ) : Promise < void > {
84
- const args : string [ ] = process . argv . slice ( 2 ) ;
90
+ const args : string [ ] = process . argv . slice ( 2 ) ;
85
91
86
- if ( args . length !== 2 || args [ 0 ] !== '--set-version' ) {
87
- console . error ( 'Usage: node script.js --set-version <version>' ) ;
88
- process . exit ( 1 ) ;
89
- }
92
+ if ( args . length !== 2 || args [ 0 ] !== '--set-version' ) {
93
+ console . error ( 'Usage: node script.js --set-version <version>' ) ;
94
+ process . exit ( 1 ) ;
95
+ }
90
96
91
- const newVersion : string = args [ 1 ] ;
92
- await updatePackageJson ( newVersion ) ;
97
+ const newVersion : string = args [ 1 ] ;
98
+ await updatePackageJson ( newVersion ) ;
93
99
}
94
100
95
101
upgradeLabDependencies ( ) ;
0 commit comments