本文整理汇总了TypeScript中semver.coerce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript coerce函数的具体用法?TypeScript coerce怎么用?TypeScript coerce使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coerce函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: preparePlatformCore
/* Hooks are expected to use "filesToSync" parameter, as to give plugin authors additional information about the sync process.*/
@performanceLog()
@helpers.hook('prepare')
private async preparePlatformCore(platform: string,
appFilesUpdaterOptions: IAppFilesUpdaterOptions,
projectData: IProjectData,
platformSpecificData: IPlatformSpecificData,
env: Object,
changesInfo?: IProjectChangesInfo,
filesToSync?: string[],
filesToRemove?: string[],
nativePrepare?: INativePrepare): Promise<void> {
this.$logger.info("Preparing project...");
const platformData = this.$platformsData.getPlatformData(platform, projectData);
const frameworkVersion = this.getCurrentPlatformVersion(platform, projectData);
if (semver.lt(semver.coerce(frameworkVersion), semver.coerce('5.1.0'))) {
this.$logger.warn(`Runtime versions lower than 5.1.0 have been deprecated and will not be supported as of v6.0.0 of NativeScript CLI. More info can be found in this issue https://github.com/NativeScript/nativescript-cli/issues/4518.`);
}
const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: appFilesUpdaterOptions.release });
await this.$preparePlatformJSService.preparePlatform({
platform,
platformData,
projectFilesConfig,
appFilesUpdaterOptions,
projectData,
platformSpecificData,
changesInfo,
filesToSync,
filesToRemove,
env
});
if (!nativePrepare || !nativePrepare.skipNativePrepare) {
await this.$preparePlatformNativeService.preparePlatform({
platform,
platformData,
appFilesUpdaterOptions,
projectData,
platformSpecificData,
changesInfo,
filesToSync,
filesToRemove,
projectFilesConfig,
env
});
}
const directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
const excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME];
if (!changesInfo || !changesInfo.modulesChanged) {
excludedDirs.push(constants.TNS_MODULES_FOLDER_NAME);
}
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, projectFilesConfig, excludedDirs);
this.$logger.info(`Project successfully prepared (${platform})`);
}
示例2: validateInstall
public async validateInstall(device: Mobile.IDevice, projectData: IProjectData, release: IRelease, outputPath?: string): Promise<void> {
const platform = device.deviceInfo.platform;
const platformData = this.$platformsData.getPlatformData(platform, projectData);
const localBuildInfo = this.getBuildInfo(device.deviceInfo.platform, platformData, { buildForDevice: !device.isEmulator, release: release.release }, outputPath);
if (localBuildInfo.deploymentTarget) {
if (semver.lt(semver.coerce(device.deviceInfo.version), semver.coerce(localBuildInfo.deploymentTarget))) {
this.$errors.fail(`Unable to install on device with version ${device.deviceInfo.version} as deployment target is ${localBuildInfo.deploymentTarget}`);
}
}
}
示例3: parseCurrentVersion
function parseCurrentVersion(uiMetadata: UIMetadata): semver.SemVer | null {
const coercedPackageVersion = semver.coerce(uiMetadata.packageVersion || "");
if (coercedPackageVersion !== null) {
return coercedPackageVersion;
}
const coercedServerBuild = semver.coerce(uiMetadata.serverBuild || "");
if (coercedServerBuild !== null) {
return coercedServerBuild;
}
return null;
}
示例4: computeElectronVersion
export async function computeElectronVersion(projectDir: string, projectMetadata: MetadataValue): Promise<string> {
const result = await getElectronVersionFromInstalled(projectDir)
if (result != null) {
return result
}
const electronPrebuiltDep = findFromElectronPrebuilt(await projectMetadata!!.value)
if (electronPrebuiltDep == null || electronPrebuiltDep === "latest") {
try {
const releaseInfo = JSON.parse((await httpExecutor.request({
hostname: "github.com",
path: "/electron/electron/releases/latest",
headers: {
accept: "application/json",
},
}))!!)
return (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name
}
catch (e) {
log.warn(e)
}
throw new Error(`Cannot find electron dependency to get electron version in the '${path.join(projectDir, "package.json")}'`)
}
const version = semver.coerce(electronPrebuiltDep)
if (version == null) {
throw new Error("cannot compute electron version")
}
return version.toString()
}
示例5: isVersionCompatible
/**
* Checks whether plugin expected Kibana version is compatible with the used Kibana version.
* @param expectedKibanaVersion Kibana version expected by the plugin.
* @param actualKibanaVersion Used Kibana version.
*/
function isVersionCompatible(expectedKibanaVersion: string, actualKibanaVersion: string) {
if (expectedKibanaVersion === ALWAYS_COMPATIBLE_VERSION) {
return true;
}
const coercedActualKibanaVersion = coerce(actualKibanaVersion);
if (coercedActualKibanaVersion == null) {
return false;
}
const coercedExpectedKibanaVersion = coerce(expectedKibanaVersion);
if (coercedExpectedKibanaVersion == null) {
return false;
}
// Compare coerced versions, e.g. `1.2.3` ---> `1.2.3` and `7.0.0-alpha1` ---> `7.0.0`.
return coercedActualKibanaVersion.compare(coercedExpectedKibanaVersion) === 0;
}
示例6: satisfies
export function satisfies(nodeVersion: string, semverRange: string) {
// Coercing the version is needed to handle nightly builds correctly.
// In particular,
// semver.satisfies('v10.0.0-nightly201804132a6ab9b37b', '>=10')
// returns `false`.
//
// `semver.coerce` can be used to coerce that nightly version to v10.0.0.
const coercedVersion = semver.coerce(nodeVersion);
const finalVersion = coercedVersion ? coercedVersion.version : nodeVersion;
return semver.satisfies(finalVersion, semverRange);
}
示例7: versionSatisfies
function versionSatisfies(version: string | semver.SemVer | null, range: string | semver.Range, loose?: boolean): boolean {
if (version == null) {
return false
}
const coerced = semver.coerce(version)
if (coerced == null) {
return false
}
return semver.satisfies(coerced, range, loose)
}
示例8: getLogcatStream
private async getLogcatStream(deviceIdentifier: string, pid?: string) {
const device = await this.$devicesService.getDevice(deviceIdentifier);
const minAndroidWithLogcatPidSupport = "7.0.0";
const isLogcatPidSupported = !!device.deviceInfo.version && semver.gte(semver.coerce(device.deviceInfo.version), minAndroidWithLogcatPidSupport);
const adb: Mobile.IDeviceAndroidDebugBridge = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: deviceIdentifier });
const logcatCommand = ["logcat"];
if (pid && isLogcatPidSupported) {
logcatCommand.push(`--pid=${pid}`);
}
const logcatStream = await adb.executeCommand(logcatCommand, { returnChildProcess: true });
return logcatStream;
}
示例9: getWarningForPluginCore
private getWarningForPluginCore(localPlugin: string, localPluginVersion: string, devicePluginVersion: string, deviceId: string): string {
this.$logger.trace(`Comparing plugin ${localPlugin} with localPluginVersion ${localPluginVersion} and devicePluginVersion ${devicePluginVersion}`);
if (!devicePluginVersion) {
return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
}
const shouldSkipCheck = !semver.valid(localPluginVersion) && !semver.validRange(localPluginVersion);
if (shouldSkipCheck) {
return null;
}
const localPluginVersionData = semver.coerce(localPluginVersion);
const devicePluginVersionData = semver.coerce(devicePluginVersion);
if (localPluginVersionData.major !== devicePluginVersionData.major) {
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
} else if (localPluginVersionData.minor > devicePluginVersionData.minor) {
return util.format(PluginComparisonMessages.LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION, localPlugin, localPluginVersion, devicePluginVersion);
}
return null;
}
示例10:
_.each(allPodfiles, podfileContent => {
const platformMatch = platformRowRegExp.exec(podfileContent);
const podfilePathMatch: any[] = podfilePathRegExp.exec(podfileContent) || [];
// platform without version -> select it with highest priority
if (platformMatch && platformMatch[0] && !platformMatch[2]) {
selectedPlatformData = {
version: null,
content: platformMatch[1],
path: podfilePathMatch[1]
};
return false;
}
// platform with version
if (platformMatch && platformMatch[0] && platformMatch[2]) {
if (!selectedPlatformData || semver.gt(semver.coerce(platformMatch[2]), semver.coerce(selectedPlatformData.version))) {
selectedPlatformData = {
version: platformMatch[2],
content: platformMatch[1],
path: podfilePathMatch[1]
};
}
}
});