mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 06:43:35 +00:00 
			
		
		
		
	convert logic initial
This commit is contained in:
		
							parent
							
								
									d8923d1f9d
								
							
						
					
					
						commit
						c849fe6824
					
				
							
								
								
									
										87
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										87
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -73218,93 +73218,80 @@ const semver = __importStar(__nccwpck_require__(5911));
 | 
				
			|||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
 | 
					const fs_1 = __importDefault(__nccwpck_require__(7147));
 | 
				
			||||||
var Distributions;
 | 
					var Distributions;
 | 
				
			||||||
(function (Distributions) {
 | 
					(function (Distributions) {
 | 
				
			||||||
    Distributions["DEFAULT"] = "default";
 | 
					    Distributions["DEFAULT"] = "";
 | 
				
			||||||
    Distributions["CANARY"] = "v8-canary";
 | 
					    Distributions["CANARY"] = "-v8-canary";
 | 
				
			||||||
    Distributions["NIGHTLY"] = "nightly";
 | 
					    Distributions["NIGHTLY"] = "-nightly";
 | 
				
			||||||
    Distributions["RC"] = "rc";
 | 
					    Distributions["RC"] = "-rc";
 | 
				
			||||||
})(Distributions = exports.Distributions || (exports.Distributions = {}));
 | 
					})(Distributions = exports.Distributions || (exports.Distributions = {}));
 | 
				
			||||||
exports.distributionOf = (versionSpec) => {
 | 
					exports.distributionOf = (versionSpec) => {
 | 
				
			||||||
    if (versionSpec.includes('-v8-canary'))
 | 
					    if (versionSpec.includes(Distributions.CANARY))
 | 
				
			||||||
        return Distributions.CANARY;
 | 
					        return Distributions.CANARY;
 | 
				
			||||||
    if (versionSpec.includes('nightly'))
 | 
					    if (versionSpec.includes(Distributions.NIGHTLY))
 | 
				
			||||||
        return Distributions.NIGHTLY;
 | 
					        return Distributions.NIGHTLY;
 | 
				
			||||||
    if (semver.prerelease(versionSpec))
 | 
					    if (semver.prerelease(versionSpec))
 | 
				
			||||||
        return Distributions.RC;
 | 
					        return Distributions.RC;
 | 
				
			||||||
    return Distributions.DEFAULT;
 | 
					    return Distributions.DEFAULT;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
exports.semverVersionMatcherFactory = (range) => {
 | 
					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;
 | 
					    matcher.factory = exports.semverVersionMatcherFactory;
 | 
				
			||||||
    return matcher;
 | 
					    return matcher;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
exports.canaryRangeVersionMatcherFactory = (version) => {
 | 
					exports.canaryRangeVersionMatcherFactory = (version) => {
 | 
				
			||||||
    const range = semver.validRange(`^${version}`);
 | 
					    const { range, includePrerelease } = createRangePreRelease(version, Distributions.CANARY);
 | 
				
			||||||
    const matcher = (potential) => semver.satisfies(potential.replace('-v8-canary', '+v8-canary.'), range);
 | 
					    const matcher = (potential) => semver.satisfies(potential.replace(Distributions.CANARY, `${Distributions.CANARY}.`), range, { includePrerelease: includePrerelease });
 | 
				
			||||||
    matcher.factory = exports.canaryRangeVersionMatcherFactory;
 | 
					    matcher.factory = exports.canaryRangeVersionMatcherFactory;
 | 
				
			||||||
    return matcher;
 | 
					    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) => {
 | 
					exports.nightlyRangeVersionMatcherFactory = (version) => {
 | 
				
			||||||
    const range = semver.validRange(`^${version}`);
 | 
					    const { range, includePrerelease } = createRangePreRelease(version, Distributions.NIGHTLY);
 | 
				
			||||||
    // TODO: this makes v20.1.1-nightly to do not match v20.1.1-nightly20221103f7e2421e91
 | 
					 | 
				
			||||||
    // const range = `${semver.validRange(`^${version}-0`)}-0`;
 | 
					 | 
				
			||||||
    const matcher = (potential) => exports.distributionOf(potential) === Distributions.NIGHTLY &&
 | 
					    const matcher = (potential) => exports.distributionOf(potential) === Distributions.NIGHTLY &&
 | 
				
			||||||
        // TODO: dmitry's variant was potential.replace('-nightly', '-nightly.') that made
 | 
					        semver.satisfies(potential.replace(Distributions.NIGHTLY, `${Distributions.NIGHTLY}.`), range, { includePrerelease: includePrerelease });
 | 
				
			||||||
        //       all unit tests to fail
 | 
					 | 
				
			||||||
        semver.satisfies(potential.replace('-nightly', '+nightly.'), range /*, {
 | 
					 | 
				
			||||||
        // TODO: what is for?
 | 
					 | 
				
			||||||
        includePrerelease: true
 | 
					 | 
				
			||||||
      }*/);
 | 
					 | 
				
			||||||
    matcher.factory = exports.nightlyRangeVersionMatcherFactory;
 | 
					    matcher.factory = exports.nightlyRangeVersionMatcherFactory;
 | 
				
			||||||
    return matcher;
 | 
					    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]
 | 
					// [raw, prerelease]
 | 
				
			||||||
exports.splitVersionSpec = (versionSpec) => versionSpec.split(/-(.*)/s);
 | 
					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) {
 | 
					function versionMatcherFactory(versionSpec) {
 | 
				
			||||||
    var _a;
 | 
					    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;
 | 
					    const validVersion = semver.valid(raw) ? raw : (_a = semver.coerce(raw)) === null || _a === void 0 ? void 0 : _a.version;
 | 
				
			||||||
    if (validVersion) {
 | 
					    if (validVersion) {
 | 
				
			||||||
        switch (exports.distributionOf(versionSpec)) {
 | 
					        switch (exports.distributionOf(versionSpec)) {
 | 
				
			||||||
            case Distributions.CANARY:
 | 
					            case Distributions.CANARY:
 | 
				
			||||||
                return prerelease === 'v8-canary' // this means versionSpec does not have timestamp
 | 
					                return exports.canaryRangeVersionMatcherFactory(versionSpec);
 | 
				
			||||||
                    ? exports.canaryRangeVersionMatcherFactory(validVersion)
 | 
					 | 
				
			||||||
                    : exports.canaryExactVersionMatcherFactory(validVersion, prerelease);
 | 
					 | 
				
			||||||
            case Distributions.NIGHTLY:
 | 
					            case Distributions.NIGHTLY:
 | 
				
			||||||
                return prerelease === 'nightly' // this means versionSpec does not have prerelease tag
 | 
					                return exports.nightlyRangeVersionMatcherFactory(versionSpec);
 | 
				
			||||||
                    ? exports.nightlyRangeVersionMatcherFactory(validVersion)
 | 
					 | 
				
			||||||
                    : exports.nightlyExactVersionMatcherFactory(validVersion, prerelease);
 | 
					 | 
				
			||||||
            case Distributions.RC:
 | 
					            case Distributions.RC:
 | 
				
			||||||
            case Distributions.DEFAULT:
 | 
					            case Distributions.DEFAULT:
 | 
				
			||||||
                return exports.semverVersionMatcherFactory(versionSpec);
 | 
					                return exports.semverVersionMatcherFactory(versionSpec);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
        // TODO: i prefer to have implicit exception for the malformed input
 | 
					 | 
				
			||||||
        throw Error(`Invalid version input "${versionSpec}"`);
 | 
					        throw Error(`Invalid version input "${versionSpec}"`);
 | 
				
			||||||
        // TODO: but it is possible to silently fail
 | 
					 | 
				
			||||||
        //  return alwaysFalseVersionMatcher
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
exports.versionMatcherFactory = versionMatcherFactory;
 | 
					exports.versionMatcherFactory = versionMatcherFactory;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										126
									
								
								src/installer.ts
									
									
									
									
									
								
							
							
						
						
									
										126
									
								
								src/installer.ts
									
									
									
									
									
								
							@ -13,6 +13,7 @@ import fs from 'fs';
 | 
				
			|||||||
// see https://nodejs.org/dist/index.json
 | 
					// see https://nodejs.org/dist/index.json
 | 
				
			||||||
// for nightly https://nodejs.org/download/nightly/index.json
 | 
					// for nightly https://nodejs.org/download/nightly/index.json
 | 
				
			||||||
// for rc https://nodejs.org/download/rc/index.json
 | 
					// for rc https://nodejs.org/download/rc/index.json
 | 
				
			||||||
 | 
					// for canary https://nodejs.org/download/v8-canary/index.json
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
export interface INodeVersion {
 | 
					export interface INodeVersion {
 | 
				
			||||||
  version: string;
 | 
					  version: string;
 | 
				
			||||||
@ -31,15 +32,15 @@ interface INodeRelease extends tc.IToolRelease {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum Distributions {
 | 
					export enum Distributions {
 | 
				
			||||||
  DEFAULT = 'default',
 | 
					  DEFAULT = '',
 | 
				
			||||||
  CANARY = 'v8-canary',
 | 
					  CANARY = '-v8-canary',
 | 
				
			||||||
  NIGHTLY = 'nightly',
 | 
					  NIGHTLY = '-nightly',
 | 
				
			||||||
  RC = 'rc'
 | 
					  RC = '-rc'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const distributionOf = (versionSpec: string): Distributions => {
 | 
					export const distributionOf = (versionSpec: string): Distributions => {
 | 
				
			||||||
  if (versionSpec.includes('-v8-canary')) return Distributions.CANARY;
 | 
					  if (versionSpec.includes(Distributions.CANARY)) return Distributions.CANARY;
 | 
				
			||||||
  if (versionSpec.includes('nightly')) return Distributions.NIGHTLY;
 | 
					  if (versionSpec.includes(Distributions.NIGHTLY)) return Distributions.NIGHTLY;
 | 
				
			||||||
  if (semver.prerelease(versionSpec)) return Distributions.RC;
 | 
					  if (semver.prerelease(versionSpec)) return Distributions.RC;
 | 
				
			||||||
  return Distributions.DEFAULT;
 | 
					  return Distributions.DEFAULT;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -55,8 +56,11 @@ interface VersionMatcher {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const semverVersionMatcherFactory = (range: string): VersionMatcher => {
 | 
					export const semverVersionMatcherFactory = (range: string): VersionMatcher => {
 | 
				
			||||||
  const matcher = (potential: string): boolean =>
 | 
					  const matcher = (potential: string): boolean =>{
 | 
				
			||||||
    semver.satisfies(potential, range);
 | 
					    core.debug(`potential is ${potential}`)
 | 
				
			||||||
 | 
					    return semver.satisfies(potential, range);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  core.debug(`range is ${range}`);
 | 
				
			||||||
  matcher.factory = semverVersionMatcherFactory;
 | 
					  matcher.factory = semverVersionMatcherFactory;
 | 
				
			||||||
  return matcher;
 | 
					  return matcher;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@ -64,99 +68,85 @@ export const semverVersionMatcherFactory = (range: string): VersionMatcher => {
 | 
				
			|||||||
export const canaryRangeVersionMatcherFactory = (
 | 
					export const canaryRangeVersionMatcherFactory = (
 | 
				
			||||||
  version: string
 | 
					  version: string
 | 
				
			||||||
): VersionMatcher => {
 | 
					): VersionMatcher => {
 | 
				
			||||||
  const range = semver.validRange(`^${version}`);
 | 
					  const {range, includePrerelease} = createRangePreRelease(
 | 
				
			||||||
 | 
					    version,
 | 
				
			||||||
 | 
					    Distributions.CANARY
 | 
				
			||||||
 | 
					  )!;
 | 
				
			||||||
  const matcher = (potential: string): boolean =>
 | 
					  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;
 | 
					  matcher.factory = canaryRangeVersionMatcherFactory;
 | 
				
			||||||
  return matcher;
 | 
					  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 = (
 | 
					export const nightlyRangeVersionMatcherFactory = (
 | 
				
			||||||
  version: string
 | 
					  version: string
 | 
				
			||||||
): VersionMatcher => {
 | 
					): VersionMatcher => {
 | 
				
			||||||
  const range = semver.validRange(`^${version}`);
 | 
					  const {range, includePrerelease} = createRangePreRelease(
 | 
				
			||||||
  // TODO: this makes v20.1.1-nightly to do not match v20.1.1-nightly20221103f7e2421e91
 | 
					    version,
 | 
				
			||||||
  // const range = `${semver.validRange(`^${version}-0`)}-0`;
 | 
					    Distributions.NIGHTLY
 | 
				
			||||||
 | 
					  )!;
 | 
				
			||||||
  const matcher = (potential: string): boolean =>
 | 
					  const matcher = (potential: string): boolean =>
 | 
				
			||||||
    distributionOf(potential) === Distributions.NIGHTLY &&
 | 
					    distributionOf(potential) === Distributions.NIGHTLY &&
 | 
				
			||||||
    // TODO: dmitry's variant was potential.replace('-nightly', '-nightly.') that made
 | 
					 | 
				
			||||||
    //       all unit tests to fail
 | 
					 | 
				
			||||||
    semver.satisfies(
 | 
					    semver.satisfies(
 | 
				
			||||||
      potential.replace('-nightly', '+nightly.'),
 | 
					      potential.replace(Distributions.NIGHTLY, `${Distributions.NIGHTLY}.`),
 | 
				
			||||||
      range /*, {
 | 
					      range!,
 | 
				
			||||||
      // TODO: what is for?
 | 
					      {includePrerelease: includePrerelease}
 | 
				
			||||||
      includePrerelease: true
 | 
					 | 
				
			||||||
    }*/
 | 
					 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  matcher.factory = nightlyRangeVersionMatcherFactory;
 | 
					  matcher.factory = nightlyRangeVersionMatcherFactory;
 | 
				
			||||||
  return matcher;
 | 
					  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]
 | 
					// [raw, prerelease]
 | 
				
			||||||
export const splitVersionSpec = (versionSpec: string): string[] =>
 | 
					export const splitVersionSpec = (versionSpec: string): string[] =>
 | 
				
			||||||
  versionSpec.split(/-(.*)/s);
 | 
					  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 [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;
 | 
					  const validVersion = semver.valid(raw) ? raw : semver.coerce(raw)?.version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (validVersion) {
 | 
					  if (validVersion) {
 | 
				
			||||||
    switch (distributionOf(versionSpec)) {
 | 
					    switch (distributionOf(versionSpec)) {
 | 
				
			||||||
      case Distributions.CANARY:
 | 
					      case Distributions.CANARY:
 | 
				
			||||||
        return prerelease === 'v8-canary' // this means versionSpec does not have timestamp
 | 
					        return canaryRangeVersionMatcherFactory(versionSpec);
 | 
				
			||||||
          ? canaryRangeVersionMatcherFactory(validVersion)
 | 
					 | 
				
			||||||
          : canaryExactVersionMatcherFactory(validVersion, prerelease);
 | 
					 | 
				
			||||||
      case Distributions.NIGHTLY:
 | 
					      case Distributions.NIGHTLY:
 | 
				
			||||||
        return prerelease === 'nightly' // this means versionSpec does not have prerelease tag
 | 
					        return nightlyRangeVersionMatcherFactory(versionSpec);
 | 
				
			||||||
          ? nightlyRangeVersionMatcherFactory(validVersion)
 | 
					 | 
				
			||||||
          : nightlyExactVersionMatcherFactory(validVersion, prerelease);
 | 
					 | 
				
			||||||
      case Distributions.RC:
 | 
					      case Distributions.RC:
 | 
				
			||||||
      case Distributions.DEFAULT:
 | 
					      case Distributions.DEFAULT:
 | 
				
			||||||
        return semverVersionMatcherFactory(versionSpec);
 | 
					        return semverVersionMatcherFactory(versionSpec);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    // TODO: i prefer to have implicit exception for the malformed input
 | 
					 | 
				
			||||||
    throw Error(`Invalid version input "${versionSpec}"`);
 | 
					    throw Error(`Invalid version input "${versionSpec}"`);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // TODO: but it is possible to silently fail
 | 
					 | 
				
			||||||
    //  return alwaysFalseVersionMatcher
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user