|
|
|
|
@ -1,18 +1,46 @@
|
|
|
|
|
import * as fs from 'fs-extra';
|
|
|
|
|
import * as semver from 'semver';
|
|
|
|
|
|
|
|
|
|
function convertPythonVersion(version: string): string {
|
|
|
|
|
return version
|
|
|
|
|
.replace('a', '-alpha')
|
|
|
|
|
.replace('b', '-beta')
|
|
|
|
|
.replace('rc', '-rc');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function extractVersionFromReleases(
|
|
|
|
|
releases: any,
|
|
|
|
|
versionTag: string
|
|
|
|
|
versionTag: string,
|
|
|
|
|
currentVersion: string
|
|
|
|
|
): string | null {
|
|
|
|
|
for (const release of releases) {
|
|
|
|
|
const tagName: string = release['tag_name'];
|
|
|
|
|
if (versionTag === 'latest') {
|
|
|
|
|
if (!release['prerelease'] && !release['draft']) {
|
|
|
|
|
return tagName;
|
|
|
|
|
}
|
|
|
|
|
} else if (versionTag === tagName) {
|
|
|
|
|
return tagName;
|
|
|
|
|
}
|
|
|
|
|
const npmCurrentVersion = convertPythonVersion(currentVersion);
|
|
|
|
|
const isCurrentPreRelease = semver.prerelease(npmCurrentVersion) !== null;
|
|
|
|
|
|
|
|
|
|
if (versionTag === 'latest') {
|
|
|
|
|
// Find first version that is newer than current and matches pre-release criteria
|
|
|
|
|
const release = releases.find((r: any) => {
|
|
|
|
|
const version = r['tag_name'].substring(1); // Remove 'v' prefix for semver
|
|
|
|
|
const npmVersion = convertPythonVersion(version);
|
|
|
|
|
return (
|
|
|
|
|
(isCurrentPreRelease || !r['prerelease']) &&
|
|
|
|
|
semver.gte(npmVersion, npmCurrentVersion)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
return release ? release['tag_name'] : null;
|
|
|
|
|
} else {
|
|
|
|
|
// Find exact version match
|
|
|
|
|
const release = releases.find((r: any) => r['tag_name'] === versionTag);
|
|
|
|
|
return release ? release['tag_name'] : null;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function extractCurrentJupyterLabVersion(): string {
|
|
|
|
|
const toml = fs.readFileSync('pyproject.toml', 'utf8');
|
|
|
|
|
const match = toml.match(/jupyterlab>=([^,]+)/);
|
|
|
|
|
if (!match) {
|
|
|
|
|
throw new Error('Could not find JupyterLab version in pyproject.toml');
|
|
|
|
|
}
|
|
|
|
|
return match[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function findVersion(versionTag: string): Promise<string> {
|
|
|
|
|
@ -22,10 +50,14 @@ async function findVersion(versionTag: string): Promise<string> {
|
|
|
|
|
const error_message = `Failed to fetch package.json from ${url}. HTTP status code: ${response.status}`;
|
|
|
|
|
throw new Error(error_message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const currentVersion = extractCurrentJupyterLabVersion();
|
|
|
|
|
|
|
|
|
|
const releases: any = await response.json();
|
|
|
|
|
const version: string | null = extractVersionFromReleases(
|
|
|
|
|
releases,
|
|
|
|
|
versionTag
|
|
|
|
|
versionTag,
|
|
|
|
|
currentVersion
|
|
|
|
|
);
|
|
|
|
|
if (version === null) {
|
|
|
|
|
const error_message = 'Invalid release tag';
|
|
|
|
|
|