From c849fe68249ef8cad2991ad052e78d20edbbf79c Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 29 Nov 2022 16:06:13 +0100 Subject: [PATCH 1/5] convert logic initial --- dist/setup/index.js | 87 +++++++++++++----------------- src/installer.ts | 126 ++++++++++++++++++++------------------------ 2 files changed, 95 insertions(+), 118 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 2d4f882fb..80f0f8f0e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73218,93 +73218,80 @@ const semver = __importStar(__nccwpck_require__(5911)); const fs_1 = __importDefault(__nccwpck_require__(7147)); var Distributions; (function (Distributions) { - Distributions["DEFAULT"] = "default"; - Distributions["CANARY"] = "v8-canary"; - Distributions["NIGHTLY"] = "nightly"; - Distributions["RC"] = "rc"; + Distributions["DEFAULT"] = ""; + Distributions["CANARY"] = "-v8-canary"; + Distributions["NIGHTLY"] = "-nightly"; + Distributions["RC"] = "-rc"; })(Distributions = exports.Distributions || (exports.Distributions = {})); exports.distributionOf = (versionSpec) => { - if (versionSpec.includes('-v8-canary')) + if (versionSpec.includes(Distributions.CANARY)) return Distributions.CANARY; - if (versionSpec.includes('nightly')) + if (versionSpec.includes(Distributions.NIGHTLY)) return Distributions.NIGHTLY; if (semver.prerelease(versionSpec)) return Distributions.RC; return Distributions.DEFAULT; }; exports.semverVersionMatcherFactory = (range) => { - const matcher = (potential) => semver.satisfies(potential, range); + const matcher = (potential) => { + core.debug(`potential is ${potential}`); + return semver.satisfies(potential, range); + }; + core.debug(`range is ${range}`); matcher.factory = exports.semverVersionMatcherFactory; return matcher; }; exports.canaryRangeVersionMatcherFactory = (version) => { - const range = semver.validRange(`^${version}`); - const matcher = (potential) => semver.satisfies(potential.replace('-v8-canary', '+v8-canary.'), range); + const { range, includePrerelease } = createRangePreRelease(version, Distributions.CANARY); + const matcher = (potential) => semver.satisfies(potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), range, { includePrerelease: includePrerelease }); matcher.factory = exports.canaryRangeVersionMatcherFactory; return matcher; }; -exports.canaryExactVersionMatcherFactory = (version, timestamp) => { - const range = `${version}-${timestamp}`; - const matcher = (potential) => semver.satisfies(potential, range); - matcher.factory = exports.canaryExactVersionMatcherFactory; - return matcher; -}; exports.nightlyRangeVersionMatcherFactory = (version) => { - const range = semver.validRange(`^${version}`); - // TODO: this makes v20.1.1-nightly to do not match v20.1.1-nightly20221103f7e2421e91 - // const range = `${semver.validRange(`^${version}-0`)}-0`; + const { range, includePrerelease } = createRangePreRelease(version, Distributions.NIGHTLY); const matcher = (potential) => exports.distributionOf(potential) === Distributions.NIGHTLY && - // TODO: dmitry's variant was potential.replace('-nightly', '-nightly.') that made - // all unit tests to fail - semver.satisfies(potential.replace('-nightly', '+nightly.'), range /*, { - // TODO: what is for? - includePrerelease: true - }*/); + semver.satisfies(potential.replace(Distributions.NIGHTLY, `${Distributions.NIGHTLY}.`), range, { includePrerelease: includePrerelease }); matcher.factory = exports.nightlyRangeVersionMatcherFactory; return matcher; }; -exports.nightlyExactVersionMatcherFactory = (version, timestamp) => { - const range = `${version}-${timestamp.replace('nightly', 'nightly.')}`; - const matcher = (potential) => exports.distributionOf(potential) === Distributions.NIGHTLY && - semver.satisfies(potential.replace('-nightly', '-nightly.'), range /*, { - // TODO: what is for? - includePrerelease: true - }*/); - matcher.factory = exports.nightlyExactVersionMatcherFactory; - return matcher; -}; -const alwaysFalseVersionMatcherFactory = () => { - const matcher = () => false; - matcher.factory = alwaysFalseVersionMatcherFactory; - return matcher; -}; -const alwaysFalseVersionMatcher = alwaysFalseVersionMatcherFactory(); // [raw, prerelease] exports.splitVersionSpec = (versionSpec) => versionSpec.split(/-(.*)/s); +const createRangePreRelease = (versionSpec, preRelease = '') => { + let range; + const [raw, prerelease] = exports.splitVersionSpec(versionSpec); + const isValidVersion = semver.valid(raw); + const rawVersion = isValidVersion ? raw : semver.coerce(raw); + if (rawVersion) { + if (`-${prerelease}` !== preRelease) { + core.debug(`came to full version ${preRelease}`); + range = `${rawVersion}${`-${prerelease}`.replace(preRelease, `${preRelease}.`)}`; + } + else { + core.debug('came to range version'); + range = `${semver.validRange(`^${rawVersion}${preRelease}`)}-0`; + } + } + core.debug(`prerelease is ${prerelease}, preRelease is ${preRelease}`); + core.debug(`Version Range for ${versionSpec} is ${range}`); + return { range, includePrerelease: !isValidVersion }; +}; function versionMatcherFactory(versionSpec) { var _a; - const [raw, prerelease] = exports.splitVersionSpec(versionSpec); + const raw = exports.splitVersionSpec(versionSpec)[0]; const validVersion = semver.valid(raw) ? raw : (_a = semver.coerce(raw)) === null || _a === void 0 ? void 0 : _a.version; if (validVersion) { switch (exports.distributionOf(versionSpec)) { case Distributions.CANARY: - return prerelease === 'v8-canary' // this means versionSpec does not have timestamp - ? exports.canaryRangeVersionMatcherFactory(validVersion) - : exports.canaryExactVersionMatcherFactory(validVersion, prerelease); + return exports.canaryRangeVersionMatcherFactory(versionSpec); case Distributions.NIGHTLY: - return prerelease === 'nightly' // this means versionSpec does not have prerelease tag - ? exports.nightlyRangeVersionMatcherFactory(validVersion) - : exports.nightlyExactVersionMatcherFactory(validVersion, prerelease); + return exports.nightlyRangeVersionMatcherFactory(versionSpec); case Distributions.RC: case Distributions.DEFAULT: return exports.semverVersionMatcherFactory(versionSpec); } } else { - // TODO: i prefer to have implicit exception for the malformed input throw Error(`Invalid version input "${versionSpec}"`); - // TODO: but it is possible to silently fail - // return alwaysFalseVersionMatcher } } exports.versionMatcherFactory = versionMatcherFactory; diff --git a/src/installer.ts b/src/installer.ts index c3dc349ff..5e1fc2cc3 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -13,6 +13,7 @@ import fs from 'fs'; // see https://nodejs.org/dist/index.json // for nightly https://nodejs.org/download/nightly/index.json // for rc https://nodejs.org/download/rc/index.json +// for canary https://nodejs.org/download/v8-canary/index.json // export interface INodeVersion { version: string; @@ -31,15 +32,15 @@ interface INodeRelease extends tc.IToolRelease { } export enum Distributions { - DEFAULT = 'default', - CANARY = 'v8-canary', - NIGHTLY = 'nightly', - RC = 'rc' + DEFAULT = '', + CANARY = '-v8-canary', + NIGHTLY = '-nightly', + RC = '-rc' } export const distributionOf = (versionSpec: string): Distributions => { - if (versionSpec.includes('-v8-canary')) return Distributions.CANARY; - if (versionSpec.includes('nightly')) return Distributions.NIGHTLY; + if (versionSpec.includes(Distributions.CANARY)) return Distributions.CANARY; + if (versionSpec.includes(Distributions.NIGHTLY)) return Distributions.NIGHTLY; if (semver.prerelease(versionSpec)) return Distributions.RC; return Distributions.DEFAULT; }; @@ -55,8 +56,11 @@ interface VersionMatcher { } export const semverVersionMatcherFactory = (range: string): VersionMatcher => { - const matcher = (potential: string): boolean => - semver.satisfies(potential, range); + const matcher = (potential: string): boolean =>{ + core.debug(`potential is ${potential}`) + return semver.satisfies(potential, range); + } + core.debug(`range is ${range}`); matcher.factory = semverVersionMatcherFactory; return matcher; }; @@ -64,99 +68,85 @@ export const semverVersionMatcherFactory = (range: string): VersionMatcher => { export const canaryRangeVersionMatcherFactory = ( version: string ): VersionMatcher => { - const range = semver.validRange(`^${version}`); + const {range, includePrerelease} = createRangePreRelease( + version, + Distributions.CANARY + )!; const matcher = (potential: string): boolean => - semver.satisfies(potential.replace('-v8-canary', '+v8-canary.'), range); + semver.satisfies( + potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), + range!, + {includePrerelease: includePrerelease} + ); matcher.factory = canaryRangeVersionMatcherFactory; return matcher; }; -export const canaryExactVersionMatcherFactory = ( - version: string, - timestamp: string -): VersionMatcher => { - const range = `${version}-${timestamp}`; - const matcher = (potential: string): boolean => - semver.satisfies(potential, range); - matcher.factory = canaryExactVersionMatcherFactory; - return matcher; -}; - export const nightlyRangeVersionMatcherFactory = ( version: string ): VersionMatcher => { - const range = semver.validRange(`^${version}`); - // TODO: this makes v20.1.1-nightly to do not match v20.1.1-nightly20221103f7e2421e91 - // const range = `${semver.validRange(`^${version}-0`)}-0`; + const {range, includePrerelease} = createRangePreRelease( + version, + Distributions.NIGHTLY + )!; const matcher = (potential: string): boolean => distributionOf(potential) === Distributions.NIGHTLY && - // TODO: dmitry's variant was potential.replace('-nightly', '-nightly.') that made - // all unit tests to fail semver.satisfies( - potential.replace('-nightly', '+nightly.'), - range /*, { - // TODO: what is for? - includePrerelease: true - }*/ + potential.replace(Distributions.NIGHTLY, `${Distributions.NIGHTLY}.`), + range!, + {includePrerelease: includePrerelease} ); matcher.factory = nightlyRangeVersionMatcherFactory; return matcher; }; -export const nightlyExactVersionMatcherFactory = ( - version: string, - timestamp: string -): VersionMatcher => { - const range = `${version}-${timestamp.replace('nightly', 'nightly.')}`; - const matcher = (potential: string): boolean => - distributionOf(potential) === Distributions.NIGHTLY && - semver.satisfies( - potential.replace('-nightly', '-nightly.'), - range /*, { - // TODO: what is for? - includePrerelease: true - }*/ - ); - matcher.factory = nightlyExactVersionMatcherFactory; - return matcher; -}; - -const alwaysFalseVersionMatcherFactory = (): VersionMatcher => { - const matcher = () => false; - matcher.factory = alwaysFalseVersionMatcherFactory; - return matcher; -}; - -const alwaysFalseVersionMatcher = alwaysFalseVersionMatcherFactory(); - // [raw, prerelease] export const splitVersionSpec = (versionSpec: string): string[] => versionSpec.split(/-(.*)/s); -export function versionMatcherFactory(versionSpec: string): VersionMatcher { +const createRangePreRelease = ( + versionSpec: string, + preRelease: string = '' +) => { + let range: string | undefined; const [raw, prerelease] = splitVersionSpec(versionSpec); + const isValidVersion = semver.valid(raw); + const rawVersion = isValidVersion ? raw : semver.coerce(raw); + + if (rawVersion) { + if (`-${prerelease}` !== preRelease) { + core.debug(`came to full version ${preRelease}`); + range = `${rawVersion}${`-${prerelease}`.replace( + preRelease, + `${preRelease}.` + )}`; + } else { + core.debug('came to range version'); + range = `${semver.validRange(`^${rawVersion}${preRelease}`)}-0`; + } + } + core.debug(`prerelease is ${prerelease}, preRelease is ${preRelease}`); + core.debug(`Version Range for ${versionSpec} is ${range}`); + + return {range, includePrerelease: !isValidVersion}; +}; + +export function versionMatcherFactory(versionSpec: string): VersionMatcher { + const raw = splitVersionSpec(versionSpec)[0]; const validVersion = semver.valid(raw) ? raw : semver.coerce(raw)?.version; if (validVersion) { switch (distributionOf(versionSpec)) { case Distributions.CANARY: - return prerelease === 'v8-canary' // this means versionSpec does not have timestamp - ? canaryRangeVersionMatcherFactory(validVersion) - : canaryExactVersionMatcherFactory(validVersion, prerelease); + return canaryRangeVersionMatcherFactory(versionSpec); case Distributions.NIGHTLY: - return prerelease === 'nightly' // this means versionSpec does not have prerelease tag - ? nightlyRangeVersionMatcherFactory(validVersion) - : nightlyExactVersionMatcherFactory(validVersion, prerelease); + return nightlyRangeVersionMatcherFactory(versionSpec); case Distributions.RC: case Distributions.DEFAULT: return semverVersionMatcherFactory(versionSpec); } } else { - // TODO: i prefer to have implicit exception for the malformed input throw Error(`Invalid version input "${versionSpec}"`); - - // TODO: but it is possible to silently fail - // return alwaysFalseVersionMatcher } } From e25fd13757c25a111a5eea56327baa391dc9b925 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 29 Nov 2022 16:14:33 +0100 Subject: [PATCH 2/5] comment code --- dist/setup/index.js | 46 +++++++++++++++++--------------- src/installer.ts | 65 +++++++++++++++++++++++---------------------- 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 80f0f8f0e..d2061e7d1 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73233,28 +73233,33 @@ exports.distributionOf = (versionSpec) => { return Distributions.DEFAULT; }; exports.semverVersionMatcherFactory = (range) => { - const matcher = (potential) => { - core.debug(`potential is ${potential}`); - return semver.satisfies(potential, range); - }; - core.debug(`range is ${range}`); + const matcher = (potential) => semver.satisfies(potential, range); matcher.factory = exports.semverVersionMatcherFactory; return matcher; }; -exports.canaryRangeVersionMatcherFactory = (version) => { - const { range, includePrerelease } = createRangePreRelease(version, Distributions.CANARY); - const matcher = (potential) => semver.satisfies(potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), range, { includePrerelease: includePrerelease }); - matcher.factory = exports.canaryRangeVersionMatcherFactory; - return matcher; -}; -exports.nightlyRangeVersionMatcherFactory = (version) => { - const { range, includePrerelease } = createRangePreRelease(version, Distributions.NIGHTLY); - const matcher = (potential) => exports.distributionOf(potential) === Distributions.NIGHTLY && - semver.satisfies(potential.replace(Distributions.NIGHTLY, `${Distributions.NIGHTLY}.`), range, { includePrerelease: includePrerelease }); +// export const canaryRangeVersionMatcherFactory = ( +// version: string +// ): VersionMatcher => { +// const {range, includePrerelease} = createRangePreRelease( +// version, +// Distributions.CANARY +// )!; +// const matcher = (potential: string): boolean => +// semver.satisfies( +// potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), +// range!, +// {includePrerelease: includePrerelease} +// ); +// matcher.factory = canaryRangeVersionMatcherFactory; +// return matcher; +// }; +exports.nightlyRangeVersionMatcherFactory = (version, distribution) => { + const { range, includePrerelease } = createRangePreRelease(version, distribution); + const matcher = (potential) => exports.distributionOf(potential) === distribution && + semver.satisfies(potential.replace(distribution, `${distribution}.`), range, { includePrerelease: includePrerelease }); matcher.factory = exports.nightlyRangeVersionMatcherFactory; return matcher; }; -// [raw, prerelease] exports.splitVersionSpec = (versionSpec) => versionSpec.split(/-(.*)/s); const createRangePreRelease = (versionSpec, preRelease = '') => { let range; @@ -73263,16 +73268,12 @@ const createRangePreRelease = (versionSpec, preRelease = '') => { const rawVersion = isValidVersion ? raw : semver.coerce(raw); if (rawVersion) { if (`-${prerelease}` !== preRelease) { - core.debug(`came to full version ${preRelease}`); range = `${rawVersion}${`-${prerelease}`.replace(preRelease, `${preRelease}.`)}`; } else { - core.debug('came to range version'); range = `${semver.validRange(`^${rawVersion}${preRelease}`)}-0`; } } - core.debug(`prerelease is ${prerelease}, preRelease is ${preRelease}`); - core.debug(`Version Range for ${versionSpec} is ${range}`); return { range, includePrerelease: !isValidVersion }; }; function versionMatcherFactory(versionSpec) { @@ -73282,9 +73283,10 @@ function versionMatcherFactory(versionSpec) { if (validVersion) { switch (exports.distributionOf(versionSpec)) { case Distributions.CANARY: - return exports.canaryRangeVersionMatcherFactory(versionSpec); case Distributions.NIGHTLY: - return exports.nightlyRangeVersionMatcherFactory(versionSpec); + return exports.nightlyRangeVersionMatcherFactory(versionSpec, Distributions.CANARY); + case Distributions.NIGHTLY: + return exports.nightlyRangeVersionMatcherFactory(versionSpec, Distributions.NIGHTLY); case Distributions.RC: case Distributions.DEFAULT: return exports.semverVersionMatcherFactory(versionSpec); diff --git a/src/installer.ts b/src/installer.ts index 5e1fc2cc3..7049b538d 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -56,43 +56,42 @@ interface VersionMatcher { } export const semverVersionMatcherFactory = (range: string): VersionMatcher => { - const matcher = (potential: string): boolean =>{ - core.debug(`potential is ${potential}`) - return semver.satisfies(potential, range); - } - core.debug(`range is ${range}`); + const matcher = (potential: string): boolean => + semver.satisfies(potential, range); + matcher.factory = semverVersionMatcherFactory; return matcher; }; -export const canaryRangeVersionMatcherFactory = ( - version: string -): VersionMatcher => { - const {range, includePrerelease} = createRangePreRelease( - version, - Distributions.CANARY - )!; - const matcher = (potential: string): boolean => - semver.satisfies( - potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), - range!, - {includePrerelease: includePrerelease} - ); - matcher.factory = canaryRangeVersionMatcherFactory; - return matcher; -}; +// export const canaryRangeVersionMatcherFactory = ( +// version: string +// ): VersionMatcher => { +// const {range, includePrerelease} = createRangePreRelease( +// version, +// Distributions.CANARY +// )!; +// const matcher = (potential: string): boolean => +// semver.satisfies( +// potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), +// range!, +// {includePrerelease: includePrerelease} +// ); +// matcher.factory = canaryRangeVersionMatcherFactory; +// return matcher; +// }; export const nightlyRangeVersionMatcherFactory = ( - version: string + version: string, + distribution: string ): VersionMatcher => { const {range, includePrerelease} = createRangePreRelease( version, - Distributions.NIGHTLY + distribution )!; const matcher = (potential: string): boolean => - distributionOf(potential) === Distributions.NIGHTLY && + distributionOf(potential) === distribution && semver.satisfies( - potential.replace(Distributions.NIGHTLY, `${Distributions.NIGHTLY}.`), + potential.replace(distribution, `${distribution}.`), range!, {includePrerelease: includePrerelease} ); @@ -100,7 +99,6 @@ export const nightlyRangeVersionMatcherFactory = ( return matcher; }; -// [raw, prerelease] export const splitVersionSpec = (versionSpec: string): string[] => versionSpec.split(/-(.*)/s); @@ -115,18 +113,14 @@ const createRangePreRelease = ( if (rawVersion) { if (`-${prerelease}` !== preRelease) { - core.debug(`came to full version ${preRelease}`); range = `${rawVersion}${`-${prerelease}`.replace( preRelease, `${preRelease}.` )}`; } else { - core.debug('came to range version'); range = `${semver.validRange(`^${rawVersion}${preRelease}`)}-0`; } } - core.debug(`prerelease is ${prerelease}, preRelease is ${preRelease}`); - core.debug(`Version Range for ${versionSpec} is ${range}`); return {range, includePrerelease: !isValidVersion}; }; @@ -138,9 +132,16 @@ export function versionMatcherFactory(versionSpec: string): VersionMatcher { if (validVersion) { switch (distributionOf(versionSpec)) { case Distributions.CANARY: - return canaryRangeVersionMatcherFactory(versionSpec); case Distributions.NIGHTLY: - return nightlyRangeVersionMatcherFactory(versionSpec); + return nightlyRangeVersionMatcherFactory( + versionSpec, + Distributions.CANARY + ); + case Distributions.NIGHTLY: + return nightlyRangeVersionMatcherFactory( + versionSpec, + Distributions.NIGHTLY + ); case Distributions.RC: case Distributions.DEFAULT: return semverVersionMatcherFactory(versionSpec); From 3533caf801cfa60263878fc6ad3b17ce6d3c8647 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 29 Nov 2022 16:25:39 +0100 Subject: [PATCH 3/5] remove case for Nightly --- dist/setup/index.js | 1 - src/installer.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index d2061e7d1..b0c6cbcd9 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73283,7 +73283,6 @@ function versionMatcherFactory(versionSpec) { if (validVersion) { switch (exports.distributionOf(versionSpec)) { case Distributions.CANARY: - case Distributions.NIGHTLY: return exports.nightlyRangeVersionMatcherFactory(versionSpec, Distributions.CANARY); case Distributions.NIGHTLY: return exports.nightlyRangeVersionMatcherFactory(versionSpec, Distributions.NIGHTLY); diff --git a/src/installer.ts b/src/installer.ts index 7049b538d..238337a55 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -132,7 +132,6 @@ export function versionMatcherFactory(versionSpec: string): VersionMatcher { if (validVersion) { switch (distributionOf(versionSpec)) { case Distributions.CANARY: - case Distributions.NIGHTLY: return nightlyRangeVersionMatcherFactory( versionSpec, Distributions.CANARY From b3720569394241a2be1c3e05fb25874bdfe561ce Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 29 Nov 2022 16:31:20 +0100 Subject: [PATCH 4/5] remove unused code --- dist/setup/index.js | 24 ++++-------------------- src/installer.ts | 25 ++++--------------------- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b0c6cbcd9..912c7c584 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73237,27 +73237,11 @@ exports.semverVersionMatcherFactory = (range) => { matcher.factory = exports.semverVersionMatcherFactory; return matcher; }; -// export const canaryRangeVersionMatcherFactory = ( -// version: string -// ): VersionMatcher => { -// const {range, includePrerelease} = createRangePreRelease( -// version, -// Distributions.CANARY -// )!; -// const matcher = (potential: string): boolean => -// semver.satisfies( -// potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), -// range!, -// {includePrerelease: includePrerelease} -// ); -// matcher.factory = canaryRangeVersionMatcherFactory; -// return matcher; -// }; -exports.nightlyRangeVersionMatcherFactory = (version, distribution) => { +exports.nightlyV8MatcherFactory = (version, distribution) => { const { range, includePrerelease } = createRangePreRelease(version, distribution); const matcher = (potential) => exports.distributionOf(potential) === distribution && semver.satisfies(potential.replace(distribution, `${distribution}.`), range, { includePrerelease: includePrerelease }); - matcher.factory = exports.nightlyRangeVersionMatcherFactory; + matcher.factory = exports.nightlyV8MatcherFactory; return matcher; }; exports.splitVersionSpec = (versionSpec) => versionSpec.split(/-(.*)/s); @@ -73283,9 +73267,9 @@ function versionMatcherFactory(versionSpec) { if (validVersion) { switch (exports.distributionOf(versionSpec)) { case Distributions.CANARY: - return exports.nightlyRangeVersionMatcherFactory(versionSpec, Distributions.CANARY); + return exports.nightlyV8MatcherFactory(versionSpec, Distributions.CANARY); case Distributions.NIGHTLY: - return exports.nightlyRangeVersionMatcherFactory(versionSpec, Distributions.NIGHTLY); + return exports.nightlyV8MatcherFactory(versionSpec, Distributions.NIGHTLY); case Distributions.RC: case Distributions.DEFAULT: return exports.semverVersionMatcherFactory(versionSpec); diff --git a/src/installer.ts b/src/installer.ts index 238337a55..50d89921b 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -63,24 +63,7 @@ export const semverVersionMatcherFactory = (range: string): VersionMatcher => { return matcher; }; -// export const canaryRangeVersionMatcherFactory = ( -// version: string -// ): VersionMatcher => { -// const {range, includePrerelease} = createRangePreRelease( -// version, -// Distributions.CANARY -// )!; -// const matcher = (potential: string): boolean => -// semver.satisfies( -// potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), -// range!, -// {includePrerelease: includePrerelease} -// ); -// matcher.factory = canaryRangeVersionMatcherFactory; -// return matcher; -// }; - -export const nightlyRangeVersionMatcherFactory = ( +export const nightlyV8MatcherFactory = ( version: string, distribution: string ): VersionMatcher => { @@ -95,7 +78,7 @@ export const nightlyRangeVersionMatcherFactory = ( range!, {includePrerelease: includePrerelease} ); - matcher.factory = nightlyRangeVersionMatcherFactory; + matcher.factory = nightlyV8MatcherFactory; return matcher; }; @@ -132,12 +115,12 @@ export function versionMatcherFactory(versionSpec: string): VersionMatcher { if (validVersion) { switch (distributionOf(versionSpec)) { case Distributions.CANARY: - return nightlyRangeVersionMatcherFactory( + return nightlyV8MatcherFactory( versionSpec, Distributions.CANARY ); case Distributions.NIGHTLY: - return nightlyRangeVersionMatcherFactory( + return nightlyV8MatcherFactory( versionSpec, Distributions.NIGHTLY ); From b717bf1b71931ecfc9fcd85912c79bc8c546b2a2 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Wed, 30 Nov 2022 11:48:41 +0100 Subject: [PATCH 5/5] remove if --- dist/setup/index.js | 22 ++++++++++------------ src/installer.ts | 34 +++++++++++++--------------------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 912c7c584..522ca2a32 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73245,18 +73245,16 @@ exports.nightlyV8MatcherFactory = (version, distribution) => { return matcher; }; exports.splitVersionSpec = (versionSpec) => versionSpec.split(/-(.*)/s); -const createRangePreRelease = (versionSpec, preRelease = '') => { +const createRangePreRelease = (versionSpec, distribution = '') => { let range; const [raw, prerelease] = exports.splitVersionSpec(versionSpec); const isValidVersion = semver.valid(raw); - const rawVersion = isValidVersion ? raw : semver.coerce(raw); - if (rawVersion) { - if (`-${prerelease}` !== preRelease) { - range = `${rawVersion}${`-${prerelease}`.replace(preRelease, `${preRelease}.`)}`; - } - else { - range = `${semver.validRange(`^${rawVersion}${preRelease}`)}-0`; - } + const rawVersion = (isValidVersion ? raw : semver.coerce(raw)); + if (`-${prerelease}` !== distribution) { + range = `${rawVersion}${`-${prerelease}`.replace(distribution, `${distribution}.`)}`; + } + else { + range = `${semver.validRange(`^${rawVersion}${distribution}`)}-0`; } return { range, includePrerelease: !isValidVersion }; }; @@ -73264,12 +73262,12 @@ function versionMatcherFactory(versionSpec) { var _a; const raw = exports.splitVersionSpec(versionSpec)[0]; const validVersion = semver.valid(raw) ? raw : (_a = semver.coerce(raw)) === null || _a === void 0 ? void 0 : _a.version; + const distribution = exports.distributionOf(versionSpec); if (validVersion) { - switch (exports.distributionOf(versionSpec)) { + switch (distribution) { case Distributions.CANARY: - return exports.nightlyV8MatcherFactory(versionSpec, Distributions.CANARY); case Distributions.NIGHTLY: - return exports.nightlyV8MatcherFactory(versionSpec, Distributions.NIGHTLY); + return exports.nightlyV8MatcherFactory(versionSpec, distribution); case Distributions.RC: case Distributions.DEFAULT: return exports.semverVersionMatcherFactory(versionSpec); diff --git a/src/installer.ts b/src/installer.ts index 50d89921b..ffee7dd5e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -87,22 +87,20 @@ export const splitVersionSpec = (versionSpec: string): string[] => const createRangePreRelease = ( versionSpec: string, - preRelease: string = '' + distribution: string = '' ) => { let range: string | undefined; const [raw, prerelease] = splitVersionSpec(versionSpec); const isValidVersion = semver.valid(raw); - const rawVersion = isValidVersion ? raw : semver.coerce(raw); - - if (rawVersion) { - if (`-${prerelease}` !== preRelease) { - range = `${rawVersion}${`-${prerelease}`.replace( - preRelease, - `${preRelease}.` - )}`; - } else { - range = `${semver.validRange(`^${rawVersion}${preRelease}`)}-0`; - } + const rawVersion = (isValidVersion ? raw : semver.coerce(raw))!; + + if (`-${prerelease}` !== distribution) { + range = `${rawVersion}${`-${prerelease}`.replace( + distribution, + `${distribution}.` + )}`; + } else { + range = `${semver.validRange(`^${rawVersion}${distribution}`)}-0`; } return {range, includePrerelease: !isValidVersion}; @@ -111,19 +109,13 @@ const createRangePreRelease = ( export function versionMatcherFactory(versionSpec: string): VersionMatcher { const raw = splitVersionSpec(versionSpec)[0]; const validVersion = semver.valid(raw) ? raw : semver.coerce(raw)?.version; + const distribution = distributionOf(versionSpec); if (validVersion) { - switch (distributionOf(versionSpec)) { + switch (distribution) { case Distributions.CANARY: - return nightlyV8MatcherFactory( - versionSpec, - Distributions.CANARY - ); case Distributions.NIGHTLY: - return nightlyV8MatcherFactory( - versionSpec, - Distributions.NIGHTLY - ); + return nightlyV8MatcherFactory(versionSpec, distribution); case Distributions.RC: case Distributions.DEFAULT: return semverVersionMatcherFactory(versionSpec);