semver#coerce TypeScript Examples
The following examples show how to use
semver#coerce.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: configErrors.ts From cli with Apache License 2.0 | 6 votes |
private computeMessageForString(version: string) {
const coercedSemver = coerce(version);
if (coercedSemver === null) {
return `Version found in config '${version}' is not parsable to a valid semantic version.`;
}
if (gt(coercedSemver, CurrentSchemaVersion)) {
return `Version found in config '${version}' is greater than the one accepted by this version of the CLI.`;
}
if (lt(coercedSemver, CurrentSchemaVersion)) {
return `Version found in config '${version}' is less than the one accepted by this version of the CLI.`;
}
return dedent`
Unknown config version error:
- configVersion: ${version}
- compatibleVersion: ${CurrentSchemaVersion}
Please report this issue to Coveo.`;
}
Example #2
Source File: misc.ts From cli with Apache License 2.0 | 6 votes |
export function getPackageVersion(packageName: string) {
const pathToPackageJson = resolve(
__dirname,
...new Array(3).fill('..'),
'package.json'
);
const pkg = require(pathToPackageJson);
const dep =
pkg.dependencies[packageName] ||
pkg.devDependencies[packageName] ||
pkg.peerDependencies[packageName];
const defaultVersion = coerce(dep?.toString())?.version;
return defaultVersion;
}
Example #3
Source File: pool.ts From lightning-terminal with MIT License | 6 votes |
/**
* Determines which order version to use based on the provided version string
* @param version the version of pool
* (ex: 0.5.4-alpha commit=v0.5.4-alpha.0.20220114202858-525fe156d240)
*/
getOrderVersion(version: string): number {
// try to convert the pool version string to a SemVer object (ex: 0.5.4)
const verNum = coerce(version);
if (!verNum) return DEFAULT_ORDER_VERSION;
// find the first key which the pool version satisfies
const matchedKey = Object.keys(ORDER_VERSION_COMPAT).find(condition =>
satisfies(verNum, condition),
);
if (!matchedKey) return DEFAULT_ORDER_VERSION;
// return the order version that was matched
return ORDER_VERSION_COMPAT[matchedKey];
}
Example #4
Source File: platform.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 6 votes |
isAboveIOS14 = () => {
if (Platform.OS === 'ios') {
const platformVer = valid(coerce(Platform.Version.toString()));
if (platformVer) {
return gte(platformVer, '14.0.0');
}
}
return false;
}
Example #5
Source File: get-local-mods.ts From ow-mod-manager with MIT License | 5 votes |
function pushModsFromDirectory(
localMods: Mod[],
directory: string,
isAlpha?: boolean
) {
const manifestPaths = globby.sync(`**/manifest.json`, {
cwd: directory,
absolute: true,
});
manifestPaths.forEach((manifestPath) => {
const modPath = path.dirname(manifestPath);
try {
const { manifest, missingAttributes } = manifestPartialToFull(
fs.readJsonSync(manifestPath)
);
const modWithSameId = localMods.find(
(localMod) => localMod.uniqueName === manifest.uniqueName
);
if (modWithSameId) {
modWithSameId.errors.push(
modsText.duplicateModError(manifest.uniqueName)
);
return;
}
const mod: Mod = {
name: manifest.name,
author: manifest.author,
uniqueName: manifest.uniqueName,
localVersion: coerce(manifest.version)?.version ?? manifest.version,
modPath,
errors: [],
dependencies: manifest.dependencies ?? [],
warning: manifest.warning,
patcher: manifest.patcher,
conflicts: manifest.conflicts,
pathsToPreserve: manifest.pathsToPreserve,
addons: [],
isAlpha,
};
if (missingAttributes.length > 0) {
mod.errors.push(
modsText.missingManifestAttributesError(
manifestPath,
missingAttributes
)
);
}
try {
mod.isEnabled = isEnabled(mod);
} catch (error) {
mod.isEnabled = true;
debugConsole.error(error);
}
localMods.push(mod);
} catch (error) {
const modDirectoryName = path.basename(modPath);
localMods.push({
author: modDirectoryName,
dependencies: [],
errors: [modsText.brokenManifestError(modDirectoryName, `${error}`)],
modPath,
name: modDirectoryName,
uniqueName: modDirectoryName,
localVersion: '-',
addons: [],
isAlpha,
});
}
});
}
Example #6
Source File: get-mod-database.ts From ow-mod-manager with MIT License | 5 votes |
export async function getModDatabase(
url: string,
owmlPath: string,
alphaPath: string
): Promise<ModDatabase> {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`${response.statusText} (${response.status})`);
}
const {
releases,
alphaReleases,
modManager,
} = (await response.json()) as RemoteModDatabase;
const allReleases = [...releases, ...alphaReleases];
const mods = allReleases.map(
({
downloadCount,
downloadUrl,
required,
repo,
version,
prerelease,
author,
name,
uniqueName,
description,
parent,
alpha,
}: RemoteMod) => {
// TODO doesnt make sense for this to be here in remote mods
const modPath = alpha
? `${alphaPath}/BepInEx/plugins/${uniqueName}`
: `${owmlPath}/Mods/${uniqueName}`;
const mod: Mod = {
name,
author,
uniqueName,
parent,
remoteVersion: coerce(version)?.version ?? version,
modPath,
errors: [],
downloadUrl,
downloadCount,
repo,
dependencies: [],
isRequired: required,
description,
prerelease,
addons: allReleases
.filter((release) => release.parent === uniqueName)
.map((addon) => addon.uniqueName),
isAlpha: alpha,
};
return mod;
}
);
return {
mods,
modManager,
};
}
Example #7
Source File: configErrors.spec.ts From cli with Apache License 2.0 | 5 votes |
mockedCoerce = jest.mocked(coerce)
Example #8
Source File: index.ts From design-systems-cli with MIT License | 5 votes |
async run(options: UpdatePluginOptions) {
const rawVersion = await getCliVersion();
const { version } = coerce(rawVersion) || { version: '' };
const notes = await getReleaseNotes(version);
const latest = execSync('npm view @design-systems/cli version', {
encoding: 'utf8',
}).trim();
if (eq(latest, rawVersion)) {
logger.info(
`You're already on the latest version! "@design-systems/cli@${latest}"`
);
return;
}
if (options.releaseNotes) {
logger.info('Updates to be installed:\n');
// eslint-disable-next-line no-console
console.log(notes);
return;
}
process.chdir(getMonorepoRoot());
if (fs.existsSync('./packages/babel-preset')) {
logger.info('Updating babel-plugin in preset...');
// --no-bootstrap because we let the last yarn handle it so
// we only run the install once
try {
execSync(
`yarn lerna add @design-systems/babel-plugin-include-styles --exact --no-bootstrap --scope @${monorepoName()}/babel-preset`,
execOptions
);
} catch (error) {
logger.trace(error);
logger.note(
'No update found for @design-systems/babel-plugin-include-styles'
);
}
}
logger.info('Updating CLI version in root...');
execSync(`yarn add -DW @design-systems/cli`, {
...execOptions,
stdio: 'inherit',
});
logger.success('Updated to latest version of `@design-systems/cli`!');
logger.success('Updates include:\n');
// eslint-disable-next-line no-console
console.log(notes);
}
Example #9
Source File: nodeVersionChecker.ts From grafana-chinese with Apache License 2.0 | 5 votes |
nodeVersionCheckerRunner: TaskRunner<NodeVersionCheckerOptions> = async () => {
// Read version from package json and treat that as the expected version in all other locations
const packageJson = require(`${process.cwd()}/${packageJsonFile}`);
const expectedVersion = packageJson.engines.node;
console.log(chalk.yellow(`Specified node version in package.json is: ${expectedVersion}`));
for (const file of nodeVersionFiles) {
const fileContent = readFileSync(`${process.cwd()}/${file}`);
const matches = fileContent.toString('utf8').match(pattern);
if (!matches) {
continue;
}
for (const match of matches) {
const actualVersion = coerce(match);
if (!actualVersion) {
failures.push({
file,
line: match,
});
continue;
}
const satisfied = satisfies(actualVersion, expectedVersion);
if (!satisfied) {
failures.push({
file,
line: match,
});
}
}
}
if (failures.length > 0) {
console.log(chalk.red('--------------------------------------------------------------------'));
console.log(chalk.red(`These entries don't satisfy the engine version in ${packageJsonFile}`));
console.log(chalk.red('--------------------------------------------------------------------'));
for (let index = 0; index < failures.length; index++) {
const failure = failures[index];
console.log(chalk.green(`\tIn ${failure.file} the line ${failure.line} does not satisfy ${expectedVersion}.`));
}
throw new Error('Node versions not in sync');
}
console.log(chalk.yellow('--------------------------------------------------------------------'));
console.log(chalk.yellow('All node versions seem ok.'));
console.log(chalk.yellow("Don't forget to sync https://github.com/grafana/grafana-build-container"));
console.log(chalk.yellow(`also if you changed the engine version in ${packageJsonFile}`));
console.log(chalk.yellow('--------------------------------------------------------------------'));
}
Example #10
Source File: dbmss.local.ts From relate with GNU General Public License v3.0 | 4 votes |
async install(
name: string,
version: string,
edition: NEO4J_EDITION = NEO4J_EDITION.ENTERPRISE,
credentials = '',
overrideCache = false,
limited = false,
installPath?: string,
): Promise<IDbmsInfo> {
if (!version) {
throw new InvalidArgumentError('Version must be specified');
}
let dbmsExists;
try {
await this.get(name);
dbmsExists = true;
} catch {
dbmsExists = false;
}
if (dbmsExists) {
throw new DbmsExistsError(`DBMS with name "${name}" already exists`);
}
// version as a file path.
if ((await fse.pathExists(version)) && (await fse.stat(version)).isFile()) {
const tmpPath = path.join(this.environment.dirPaths.tmp, uuidv4());
const {extractedDistPath} = await extractNeo4j(version, tmpPath);
const dbms = await this.installNeo4j(
name,
this.getDbmsRootPath(),
extractedDistPath,
credentials,
installPath,
);
await fse.remove(tmpPath);
return dbms;
}
// @todo: version as a URL.
if (isValidUrl(version)) {
throw new NotSupportedError(`fetch and install ${version}`);
}
const coercedVersion = coerce(version)?.version;
if (coercedVersion) {
if (!satisfies(coercedVersion, NEO4J_SUPPORTED_VERSION_RANGE)) {
throw new NotSupportedError(`version not in range ${NEO4J_SUPPORTED_VERSION_RANGE}`);
}
const beforeDownload = await discoverNeo4jDistributions(this.environment.dirPaths.dbmssCache);
const requestedDistribution = beforeDownload.find(
(dist) => dist.version === coercedVersion && dist.edition === edition,
);
const found = await requestedDistribution.flatMap(async (dist) => {
const shouldDownload = overrideCache || None.isNone(dist);
if (shouldDownload && !None.isNone(dist)) {
await fse.remove(dist.dist);
}
if (shouldDownload) {
await downloadNeo4j(coercedVersion, edition, this.environment.dirPaths.dbmssCache, limited);
const afterDownload = await discoverNeo4jDistributions(this.environment.dirPaths.dbmssCache);
return afterDownload.find((down) => down.version === coercedVersion && down.edition === edition);
}
return Maybe.of(dist);
});
return found.flatMap((dist) => {
if (None.isNone(dist)) {
throw new NotFoundError(`Unable to find the requested version: ${version}-${edition} online`);
}
return this.installNeo4j(name, this.getDbmsRootPath(), dist.dist, credentials, installPath);
});
}
throw new InvalidArgumentError('Provided version argument is not valid semver, url or path.');
}