diff --git a/electron-builder-scripts/linux_after_install.sh b/electron-builder-scripts/linux_after_install.sh index fe1727b9..84e1aaf7 100644 --- a/electron-builder-scripts/linux_after_install.sh +++ b/electron-builder-scripts/linux_after_install.sh @@ -1 +1 @@ -./opt/JupyterLab/resources/env_installer/JupyterLabAppServer-3.1.12-Linux-x86_64.sh -b -p "/opt/JupyterLab/resources/jlab_server" +./opt/JupyterLab/resources/env_installer/JupyterLabAppServer-3.1.12-1-Linux-x86_64.sh -b -p "/opt/JupyterLab/resources/jlab_server" diff --git a/electron-builder-scripts/postinstall b/electron-builder-scripts/postinstall index 32e22fe8..857e7452 100755 --- a/electron-builder-scripts/postinstall +++ b/electron-builder-scripts/postinstall @@ -1,5 +1,5 @@ #!/bin/bash -"$2/JupyterLab.app/Contents/Resources/env_installer/JupyterLabAppServer-3.1.12-MacOSX-x86_64.sh" -b -p "$2/JupyterLab.app/Contents/Resources/jlab_server" +"$2/JupyterLab.app/Contents/Resources/env_installer/JupyterLabAppServer-3.1.12-1-MacOSX-x86_64.sh" -b -p "$2/JupyterLab.app/Contents/Resources/jlab_server" exit 0 diff --git a/electron-builder-scripts/wininstall.nsh b/electron-builder-scripts/wininstall.nsh index 1f9576ef..171e5615 100644 --- a/electron-builder-scripts/wininstall.nsh +++ b/electron-builder-scripts/wininstall.nsh @@ -5,5 +5,5 @@ !macroend !macro customInstall - ExecWait "$INSTDIR\resources\env_installer\JupyterLabAppServer-3.1.12-Windows-x86_64.exe" + ExecWait "$INSTDIR\resources\env_installer\JupyterLabAppServer-3.1.12-1-Windows-x86_64.exe" !macroend diff --git a/env_installer/construct.yaml b/env_installer/construct.yaml index 978a3ea0..7fdb09f1 100644 --- a/env_installer/construct.yaml +++ b/env_installer/construct.yaml @@ -1,5 +1,5 @@ name: JupyterLabAppServer -version: 3.1.12 +version: 3.1.12-1 company: "Project Jupyter" welcome_image_text: "JupyterLab" diff --git a/package.json b/package.json index 55653bd8..f5191678 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jupyterlab_app", - "version": "3.1.12", + "version": "3.1.12-1", "description": "A native app for JupyterLab, based on electron.", "main": "./build/out/main/main.js", "scripts": { @@ -27,7 +27,8 @@ "dockerdist:win": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/builder:wine /bin/bash -c \"yarn && yarn dist:win\"", "create_env_installer:linux": "rimraf ./env_installer/JupyterLab*.sh && constructor ./env_installer --platform=linux-64 --output-dir ./env_installer", "create_env_installer:mac": "rimraf ./env_installer/JupyterLab*.sh && constructor ./env_installer --platform=osx-64 --output-dir ./env_installer", - "create_env_installer:win": "rimraf ./env_installer/JupyterLab*.exe && constructor ./env_installer --platform=win-64 --output-dir ./env_installer" + "create_env_installer:win": "rimraf ./env_installer/JupyterLab*.exe && constructor ./env_installer --platform=win-64 --output-dir ./env_installer", + "check_version_match": "node scripts/buildutil.js --check-version-match" }, "build": { "productName": "JupyterLab", @@ -43,9 +44,7 @@ "!env_installer/JupyterLab*.*" ], "extraResources": [ - "env_installer/JupyterLabAppServer-3.1.12-MacOSX-x86_64.sh", - "env_installer/JupyterLabAppServer-3.1.12-Linux-x86_64.sh", - "env_installer/JupyterLabAppServer-3.1.12-Windows-x86_64.exe" + "env_installer/JupyterLabAppServer-*[.sh,.exe]" ], "linux": { "target": [ @@ -114,11 +113,14 @@ "repository": "github:jupyterlab/jupyterlab", "license": "BSD-3-Clause", "devDependencies": { + "@yarnpkg/lockfile": "~1.1.0", "css-loader": "~5.1.1", "electron": "^10.1.3", "electron-builder": "^22.10.5", "file-loader": "~6.2.0", "fs-extra": "~9.1.0", + "js-yaml": "^4.1.0", + "meow": "^6.0.1", "mini-css-extract-plugin": "^1.3.9", "node-watch": "^0.7.1", "raw-loader": "^4.0.2", diff --git a/scripts/buildutil.js b/scripts/buildutil.js new file mode 100644 index 00000000..d43c3a68 --- /dev/null +++ b/scripts/buildutil.js @@ -0,0 +1,160 @@ +const meow = require("meow"); +const fs = require("fs-extra"); +const path = require("path"); +const semver = require("semver"); +const lockfile = require("@yarnpkg/lockfile"); +const yaml = require("js-yaml"); + +const platform = process.platform; + +const cli = meow( + ` + Usage + $ node buildutil + + Options + --check-version-match check for JupyterLab version match + + Other options: + --help show usage information + --version show version information + + Examples + $ node buildutil --check-version-match +`, + { + flags: { + checkVersionMatch: { + type: "boolean", + default: false, + }, + }, + } +); + +const searchTextInFile = (filePath, text) => { + try { + const fileContent = fs.readFileSync(filePath, "utf8"); + return fileContent.includes(text); + } catch (e) { + console.error('Error searching for file content', e); + } + + return false; +}; + +if (cli.flags.checkVersionMatch) { + // parse App version + const pkgjsonFilePath = path.resolve(__dirname, "../package.json"); + const pkgjsonFileData = fs.existsSync(pkgjsonFilePath) + ? fs.readJSONSync(pkgjsonFilePath) + : undefined; + if (!pkgjsonFileData) { + console.error("package.json not found!"); + process.exit(1); + } + + const appVersion = pkgjsonFileData["version"]; + console.log(`JupyterLab App version: ${appVersion}`); + + // parse JupyterLab version bundled to App UI + const yarnlockFilePath = path.resolve(__dirname, "../yarn.lock"); + if (!fs.existsSync(yarnlockFilePath)) { + console.error("yarn.lock not found!"); + process.exit(1); + } + + const yarnLockFileContent = fs.readFileSync(yarnlockFilePath, "utf8"); + const yarnLockData = lockfile.parse(yarnLockFileContent).object; + const yarnPackages = Object.keys(yarnLockData); + const metapackage = yarnPackages.find((pkg) => + pkg.startsWith("@jupyterlab/metapackage") + ); + if (!metapackage) { + console.error("@jupyterlab/metapackage not found!"); + process.exit(1); + } + + const jlabVersion = yarnLockData[metapackage].version; + console.log(`JupyterLab version: ${jlabVersion}`); + + if ( + !semver.valid(appVersion) || + !semver.valid(jlabVersion) || + semver.major(appVersion) !== semver.major(jlabVersion) || + semver.minor(appVersion) !== semver.minor(jlabVersion) || + semver.patch(appVersion) !== semver.patch(jlabVersion) + ) { + console.error( + `App package version ${appVersion} doesn't match bundled JupyterLab version ${jlabVersion}` + ); + process.exit(1); + } + + // check JupyterLab version bundled to App Server + const constructorData = yaml.load( + fs.readFileSync( + path.resolve(__dirname, "../env_installer/construct.yaml"), + "utf8" + ) + ); + const appServerVersion = constructorData["version"]; + console.log(`App Server version: ${appServerVersion}`); + + if (appServerVersion !== appVersion) { + console.error( + `App Server version ${appServerVersion} doesn't match App version ${appVersion}` + ); + process.exit(1); + } + + const jlabCondaPkg = constructorData["specs"].find((pkg) => pkg.startsWith("jupyterlab")); + if (!jlabCondaPkg) { + console.error("jupyterlab conda package not found in environment specs!"); + process.exit(1); + } + const specParts = jlabCondaPkg.split(" "); + const appServerJLabVersion = specParts[1]; + console.log(`App Server JupyterLab version: ${appServerJLabVersion}`); + + if (appServerJLabVersion !== jlabVersion) { + console.error( + `App Server package version ${appServerJLabVersion} doesn't match bundled JupyterLab version ${jlabVersion}` + ); + process.exit(1); + } + + // check JupyterLab versions in scripts + const envInstallerScriptName = + platform === "darwin" + ? "postinstall" + : platform === "win32" + ? "electron-builder-scripts/wininstall.nsh" + : "electron-builder-scripts/linux_after_install.sh"; + const envInstallScriptPath = path.resolve( + __dirname, + `../electron-builder-scripts/${envInstallerScriptName}` + ); + let searchString = `JupyterLabAppServer-${appVersion}-`; + if (!searchTextInFile(envInstallScriptPath, searchString)) { + console.error( + `Script file ${envInstallScriptPath} doesn't contain correct App version ${appVersion}` + ); + process.exit(1); + } + + searchString = `"appVersion": "${appVersion}",`; + if ( + !searchTextInFile( + path.resolve(__dirname, `../src/browser/index.html`), + searchString + ) + ) { + console.error( + `src/index.html doesn't contain correct App version ${appVersion}` + ); + process.exit(1); + } + + process.exit(0); +} diff --git a/src/browser/index.html b/src/browser/index.html index 0be3f9e3..3e64cef1 100644 --- a/src/browser/index.html +++ b/src/browser/index.html @@ -11,7 +11,7 @@ JupyterLab