Skip to content

fix: tns info should work with scoped modules #5198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ interface IVersionsService {
getNativescriptCliVersion(): Promise<IVersionInformation>;

/**
* Gets version information about tns-core-modules.
* @return {Promise<IVersionInformation>} The version information.
* Gets version information about tns-core-modules and @nativescript/core packages.
* @return {Promise<IVersionInformation[]>} The version information.
*/
getTnsCoreModulesVersion(): Promise<IVersionInformation>;
getTnsCoreModulesVersion(): Promise<IVersionInformation[]>;

/**
* Gets versions information about nativescript runtimes.
Expand Down
39 changes: 32 additions & 7 deletions lib/services/versions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,51 @@ class VersionsService implements IVersionsService {
};
}

public async getTnsCoreModulesVersion(): Promise<IVersionInformation> {
public async getTnsCoreModulesVersion(): Promise<IVersionInformation[]> {
const latestTnsCoreModulesVersion = await this.$packageInstallationManager.getLatestVersion(constants.TNS_CORE_MODULES_NAME);
const nativescriptCoreModulesInfo: IVersionInformation = {
componentName: constants.TNS_CORE_MODULES_NAME,
latestVersion: latestTnsCoreModulesVersion
};

const versionInformations: IVersionInformation[] = [];

if (this.projectData) {
const nodeModulesPath = path.join(this.projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME);
const scopedPackagePath = path.join(nodeModulesPath, constants.SCOPED_TNS_CORE_MODULES);
const tnsCoreModulesPath = path.join(nodeModulesPath, constants.TNS_CORE_MODULES_NAME);

const dependsOnNonScopedPackage = !!this.projectData.dependencies[constants.TNS_CORE_MODULES_NAME];
const dependsOnScopedPackage = !!this.projectData.dependencies[constants.SCOPED_TNS_CORE_MODULES];

// ensure the dependencies are installed, so we can get their actual versions from node_modules
if (!this.$fs.exists(nodeModulesPath) ||
!this.$fs.exists(tnsCoreModulesPath)) {
(dependsOnNonScopedPackage && !this.$fs.exists(tnsCoreModulesPath)) ||
(dependsOnScopedPackage && !this.$fs.exists(scopedPackagePath))) {
await this.$pluginsService.ensureAllDependenciesAreInstalled(this.projectData);
}

const currentTnsCoreModulesVersion = this.$fs.readJson(path.join(tnsCoreModulesPath, constants.PACKAGE_JSON_FILE_NAME)).version;
nativescriptCoreModulesInfo.currentVersion = currentTnsCoreModulesVersion;
if (dependsOnNonScopedPackage && this.$fs.exists(tnsCoreModulesPath)) {
const currentTnsCoreModulesVersion = this.$fs.readJson(path.join(tnsCoreModulesPath, constants.PACKAGE_JSON_FILE_NAME)).version;
nativescriptCoreModulesInfo.currentVersion = currentTnsCoreModulesVersion;
versionInformations.push(nativescriptCoreModulesInfo);
}

if (dependsOnScopedPackage && this.$fs.exists(scopedPackagePath)) {
const scopedModulesInformation: IVersionInformation = {
componentName: constants.SCOPED_TNS_CORE_MODULES,
latestVersion: await this.$packageInstallationManager.getLatestVersion(constants.SCOPED_TNS_CORE_MODULES)
};

const currentScopedPackageVersion = this.$fs.readJson(path.join(scopedPackagePath, constants.PACKAGE_JSON_FILE_NAME)).version;
scopedModulesInformation.currentVersion = currentScopedPackageVersion;
versionInformations.push(scopedModulesInformation);
}
} else {
versionInformations.push(nativescriptCoreModulesInfo);
}

return nativescriptCoreModulesInfo;
return versionInformations;
}

public async getRuntimesVersions(): Promise<IVersionInformation[]> {
Expand Down Expand Up @@ -101,9 +126,9 @@ class VersionsService implements IVersionsService {
}

if (this.projectData) {
const nativescriptCoreModulesInformation: IVersionInformation = await this.getTnsCoreModulesVersion();
const nativescriptCoreModulesInformation: IVersionInformation[] = await this.getTnsCoreModulesVersion();
if (nativescriptCoreModulesInformation) {
allComponents.push(nativescriptCoreModulesInformation);
allComponents.push(...nativescriptCoreModulesInformation);
}

const runtimesVersions: IVersionInformation[] = await this.getRuntimesVersions();
Expand Down