Skip to content

Commit

Permalink
[FEATURE] Resolvers: Use npm tags for determining 'latest'
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte authored and matz3 committed Sep 5, 2023
1 parent 98672ae commit 5cde95a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/ui5Framework/AbstractResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ class AbstractResolver {
}

static async resolveVersion(version, {ui5HomeDir, cwd} = {}) {
if (version === "latest") {
const tagVersion = this.fetchTag("latest", {ui5HomeDir, cwd});
if (tagVersion) {
return tagVersion;
}
}

let spec;
const isSnapshotVersion = version.toLowerCase().endsWith("-snapshot");
if (version === "latest" || version === "latest-snapshot") {
Expand All @@ -238,6 +245,7 @@ class AbstractResolver {
throw new Error(`Framework version specifier "${version}" is incorrect or not supported`);
}
}

const versions = await this.fetchAllVersions({ui5HomeDir, cwd});
const resolvedVersion = semver.maxSatisfying(versions, spec, {
includePrerelease: isSnapshotVersion
Expand Down Expand Up @@ -271,6 +279,9 @@ class AbstractResolver {
static fetchAllVersions(options) {
throw new Error("AbstractResolver: static fetchAllVersions must be implemented!");
}
static fetchTag(tagName, options) {
throw new Error("AbstractResolver: static fetchDistTag must be implemented!");
}
}

/* istanbul ignore else */
Expand Down
11 changes: 11 additions & 0 deletions lib/ui5Framework/Openui5Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ class Openui5Resolver extends AbstractResolver {
});
return await installer.fetchPackageVersions({pkgName: OPENUI5_CORE_PACKAGE});
}

static async fetchTag(tagName, {ui5HomeDir, cwd} = {}) {
const installer = new Installer({
cwd: cwd ? path.resolve(cwd) : process.cwd(),
ui5HomeDir:
ui5HomeDir ? path.resolve(ui5HomeDir) :
path.join(os.homedir(), ".ui5")
});
const distTags = await installer.fetchPackageDistTags({pkgName: OPENUI5_CORE_PACKAGE});
return distTags[tagName];
}
}

export default Openui5Resolver;
11 changes: 11 additions & 0 deletions lib/ui5Framework/Sapui5Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ class Sapui5Resolver extends AbstractResolver {
});
return await installer.fetchPackageVersions({pkgName: DIST_PKG_NAME});
}

static async fetchTag(tagName, {ui5HomeDir, cwd} = {}) {
const installer = new Installer({
cwd: cwd ? path.resolve(cwd) : process.cwd(),
ui5HomeDir:
ui5HomeDir ? path.resolve(ui5HomeDir) :
path.join(os.homedir(), ".ui5")
});
const distTags = await installer.fetchPackageDistTags({pkgName: DIST_PKG_NAME});
return distTags[tagName];
}
}

export default Sapui5Resolver;
5 changes: 5 additions & 0 deletions lib/ui5Framework/npm/Installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Installer extends AbstractInstaller {
return Object.keys(packument.versions);
}

async fetchPackageDistTags({pkgName}) {
const packument = await this.getRegistry().requestPackagePackument(pkgName);
return packument["dist-tags"];
}

async fetchPackageManifest({pkgName, version}) {
const targetDir = this._getTargetDirForPackage({pkgName, version});
try {
Expand Down

0 comments on commit 5cde95a

Please sign in to comment.