Skip to content

Commit 216a0cb

Browse files
Merge pull request #5198 from NativeScript/vladimirov/fix-tns-info-scoped-package
fix: `tns info` should work with scoped modules
2 parents 8288193 + e94fa81 commit 216a0cb

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

lib/declarations.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,10 @@ interface IVersionsService {
798798
getNativescriptCliVersion(): Promise<IVersionInformation>;
799799

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

806806
/**
807807
* Gets versions information about nativescript runtimes.

lib/services/versions-service.ts

+32-7
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,51 @@ class VersionsService implements IVersionsService {
3737
};
3838
}
3939

40-
public async getTnsCoreModulesVersion(): Promise<IVersionInformation> {
40+
public async getTnsCoreModulesVersion(): Promise<IVersionInformation[]> {
4141
const latestTnsCoreModulesVersion = await this.$packageInstallationManager.getLatestVersion(constants.TNS_CORE_MODULES_NAME);
4242
const nativescriptCoreModulesInfo: IVersionInformation = {
4343
componentName: constants.TNS_CORE_MODULES_NAME,
4444
latestVersion: latestTnsCoreModulesVersion
4545
};
4646

47+
const versionInformations: IVersionInformation[] = [];
48+
4749
if (this.projectData) {
4850
const nodeModulesPath = path.join(this.projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME);
51+
const scopedPackagePath = path.join(nodeModulesPath, constants.SCOPED_TNS_CORE_MODULES);
4952
const tnsCoreModulesPath = path.join(nodeModulesPath, constants.TNS_CORE_MODULES_NAME);
53+
54+
const dependsOnNonScopedPackage = !!this.projectData.dependencies[constants.TNS_CORE_MODULES_NAME];
55+
const dependsOnScopedPackage = !!this.projectData.dependencies[constants.SCOPED_TNS_CORE_MODULES];
56+
57+
// ensure the dependencies are installed, so we can get their actual versions from node_modules
5058
if (!this.$fs.exists(nodeModulesPath) ||
51-
!this.$fs.exists(tnsCoreModulesPath)) {
59+
(dependsOnNonScopedPackage && !this.$fs.exists(tnsCoreModulesPath)) ||
60+
(dependsOnScopedPackage && !this.$fs.exists(scopedPackagePath))) {
5261
await this.$pluginsService.ensureAllDependenciesAreInstalled(this.projectData);
5362
}
5463

55-
const currentTnsCoreModulesVersion = this.$fs.readJson(path.join(tnsCoreModulesPath, constants.PACKAGE_JSON_FILE_NAME)).version;
56-
nativescriptCoreModulesInfo.currentVersion = currentTnsCoreModulesVersion;
64+
if (dependsOnNonScopedPackage && this.$fs.exists(tnsCoreModulesPath)) {
65+
const currentTnsCoreModulesVersion = this.$fs.readJson(path.join(tnsCoreModulesPath, constants.PACKAGE_JSON_FILE_NAME)).version;
66+
nativescriptCoreModulesInfo.currentVersion = currentTnsCoreModulesVersion;
67+
versionInformations.push(nativescriptCoreModulesInfo);
68+
}
69+
70+
if (dependsOnScopedPackage && this.$fs.exists(scopedPackagePath)) {
71+
const scopedModulesInformation: IVersionInformation = {
72+
componentName: constants.SCOPED_TNS_CORE_MODULES,
73+
latestVersion: await this.$packageInstallationManager.getLatestVersion(constants.SCOPED_TNS_CORE_MODULES)
74+
};
75+
76+
const currentScopedPackageVersion = this.$fs.readJson(path.join(scopedPackagePath, constants.PACKAGE_JSON_FILE_NAME)).version;
77+
scopedModulesInformation.currentVersion = currentScopedPackageVersion;
78+
versionInformations.push(scopedModulesInformation);
79+
}
80+
} else {
81+
versionInformations.push(nativescriptCoreModulesInfo);
5782
}
5883

59-
return nativescriptCoreModulesInfo;
84+
return versionInformations;
6085
}
6186

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

103128
if (this.projectData) {
104-
const nativescriptCoreModulesInformation: IVersionInformation = await this.getTnsCoreModulesVersion();
129+
const nativescriptCoreModulesInformation: IVersionInformation[] = await this.getTnsCoreModulesVersion();
105130
if (nativescriptCoreModulesInformation) {
106-
allComponents.push(nativescriptCoreModulesInformation);
131+
allComponents.push(...nativescriptCoreModulesInformation);
107132
}
108133

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

0 commit comments

Comments
 (0)