@@ -13,7 +13,6 @@ const cli = meow(
13
13
14
14
Options
15
15
--check-version-match check for JupyterLab version match
16
- --set-jupyterlab-version set JupyterLab version
17
16
18
17
Other options:
19
18
--help show usage information
@@ -27,61 +26,11 @@ const cli = meow(
27
26
checkVersionMatch : {
28
27
type : 'boolean' ,
29
28
default : false
30
- } ,
31
- setJupyterlabVersion : {
32
- type : 'string' ,
33
- default : ''
34
29
}
35
30
}
36
31
}
37
32
) ;
38
33
39
- // remove ~ or ^ prefix from semver version
40
- function makeVersionAbsolute ( version ) {
41
- if ( version . length > 0 && ( version [ 0 ] === '^' || version [ 0 ] === '~' ) ) {
42
- return version . substring ( 1 ) ;
43
- }
44
-
45
- return version ;
46
- }
47
-
48
- /*
49
- * Checks if JupyterLab extensions listed in package.json
50
- * are properly included into the bundle in "extensions/index.ts"
51
- */
52
- function checkExtensionImports ( ) {
53
- console . log ( 'Checking for missing extension imports...' ) ;
54
-
55
- const pkgjsonFileData = fs . existsSync ( pkgjsonFilePath )
56
- ? fs . readJSONSync ( pkgjsonFilePath )
57
- : undefined ;
58
- if ( ! pkgjsonFileData ) {
59
- console . error ( 'package.json not found!' ) ;
60
- process . exit ( 1 ) ;
61
- }
62
-
63
- const extensions = pkgjsonFileData . jupyterlab . extensions ;
64
- const mimeExtensions = pkgjsonFileData . jupyterlab . mimeExtensions ;
65
- const extensionsFilePath = path . resolve (
66
- __dirname ,
67
- `../src/browser/extensions/index.ts`
68
- ) ;
69
- let extensionsFileContent = '' ;
70
- try {
71
- extensionsFileContent = fs . readFileSync ( extensionsFilePath , 'utf8' ) ;
72
- } catch ( e ) {
73
- console . error ( 'Error loading "extensions/index.ts"' , e ) ;
74
- }
75
- for ( const extension of [ ...extensions , ...mimeExtensions ] ) {
76
- if ( ! extensionsFileContent . includes ( `require('${ extension } ')` ) ) {
77
- console . error ( `${ extension } is not imported in "extensions/index.ts"` ) ;
78
- process . exit ( 1 ) ;
79
- }
80
- }
81
-
82
- console . log ( 'All extensions are bundled correctly.' ) ;
83
- }
84
-
85
34
if ( cli . flags . checkVersionMatch ) {
86
35
// parse application version
87
36
const pkgjsonFileData = fs . existsSync ( pkgjsonFilePath )
@@ -139,115 +88,3 @@ if (cli.flags.checkVersionMatch) {
139
88
console . log ( 'JupyterLab version match satisfied!' ) ;
140
89
process . exit ( 0 ) ;
141
90
}
142
-
143
- if ( cli . flags . setJupyterlabVersion !== '' ) {
144
- const https = require ( 'https' ) ;
145
- const newVersion = cli . flags . setJupyterlabVersion ;
146
- console . log ( `Downloading JupyterLab v${ newVersion } package.json` ) ;
147
-
148
- const url = `https://raw.githubusercontent.com/jupyterlab/jupyterlab/v${ newVersion } /jupyterlab/staging/package.json` ;
149
-
150
- https
151
- . get ( url , res => {
152
- let body = '' ;
153
-
154
- res . on ( 'data' , chunk => {
155
- body += chunk ;
156
- } ) ;
157
-
158
- res . on ( 'end' , ( ) => {
159
- try {
160
- let newPkgData = JSON . parse ( body ) ;
161
- if ( ! ( newPkgData . devDependencies && newPkgData . resolutions ) ) {
162
- console . error ( `Invalid package.json format for v${ newVersion } !` ) ;
163
- process . exit ( 1 ) ;
164
- }
165
-
166
- const newResolutions = { ...newPkgData . resolutions } ;
167
- const newDependencies = {
168
- ...newPkgData . devDependencies ,
169
- ...newResolutions
170
- } ;
171
-
172
- const pkgjsonFileData = fs . existsSync ( pkgjsonFilePath )
173
- ? fs . readJSONSync ( pkgjsonFilePath )
174
- : undefined ;
175
- if ( ! pkgjsonFileData ) {
176
- console . error ( 'package.json not found!' ) ;
177
- process . exit ( 1 ) ;
178
- }
179
-
180
- const oldDependencies = pkgjsonFileData . dependencies ;
181
-
182
- for ( const packageName in oldDependencies ) {
183
- if (
184
- packageName . startsWith ( '@jupyterlab' ) &&
185
- packageName in newDependencies
186
- ) {
187
- oldDependencies [ packageName ] = makeVersionAbsolute (
188
- newDependencies [ packageName ]
189
- ) ;
190
- }
191
- }
192
-
193
- // copy resolutions and singleton packages as-is
194
- pkgjsonFileData . resolutions = newResolutions ;
195
- pkgjsonFileData . singletonPackages = newPkgData . singletonPackages ;
196
-
197
- fs . writeFileSync (
198
- pkgjsonFilePath ,
199
- JSON . stringify ( pkgjsonFileData , null , 2 )
200
- ) ;
201
-
202
- console . log ( `JupyterLab dependencies updated to v${ newVersion } ` ) ;
203
-
204
- checkExtensionImports ( ) ;
205
-
206
- // Check if all extensions of the new JupyterLab version are
207
- // bundled into the application
208
- console . log ( 'Checking for extension list match...' ) ;
209
- const extensions = pkgjsonFileData . jupyterlab . extensions ;
210
- const mimeExtensions = pkgjsonFileData . jupyterlab . mimeExtensions ;
211
- const excludedExtensions =
212
- pkgjsonFileData . jupyterlab . excludedExtensions ;
213
-
214
- const extensionSet = new Set ( [ ...extensions , ...excludedExtensions ] ) ;
215
- const mimeExtensionSet = new Set ( [
216
- ...mimeExtensions ,
217
- ...excludedExtensions
218
- ] ) ;
219
-
220
- for ( const extension in newPkgData . jupyterlab . extensions ) {
221
- if ( ! extensionSet . has ( extension ) ) {
222
- console . error (
223
- `JupyterLab v${ newVersion } ${ extension } is not bundled into the application!`
224
- ) ;
225
- process . exit ( 1 ) ;
226
- }
227
- }
228
-
229
- for ( const extension in newPkgData . jupyterlab . mimeExtensions ) {
230
- if ( ! mimeExtensionSet . has ( extension ) ) {
231
- console . error (
232
- `JupyterLab v${ newVersion } ${ extension } is not bundled into the application!`
233
- ) ;
234
- process . exit ( 1 ) ;
235
- }
236
- }
237
-
238
- console . log (
239
- 'All extensions in the new version are bundled correctly.'
240
- ) ;
241
-
242
- process . exit ( 0 ) ;
243
- } catch ( error ) {
244
- console . error ( error . message ) ;
245
- process . exit ( 1 ) ;
246
- }
247
- } ) ;
248
- } )
249
- . on ( 'error' , error => {
250
- console . error ( error . message ) ;
251
- process . exit ( 1 ) ;
252
- } ) ;
253
- }
0 commit comments