Skip to content

Commit b49772d

Browse files
committed
tns-android/ios are installed as dev dependencies
previously tns-android and tns-ios have been installed in nativescript key in the root package.json now both platforms are installed as a dev-dependencies
1 parent 3596891 commit b49772d

11 files changed

+30
-22
lines changed

lib/commands/install.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EOL } from "os";
2+
import * as constants from "../constants";
23

34
export class InstallCommand implements ICommand {
45
public enableHooks = false;
@@ -26,7 +27,7 @@ export class InstallCommand implements ICommand {
2627
this.$projectDataService.initialize(this.$projectData.projectDir);
2728
for (let platform of this.$platformsData.platformsNames) {
2829
let platformData = this.$platformsData.getPlatformData(platform);
29-
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName);
30+
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
3031
if (frameworkPackageData && frameworkPackageData.version) {
3132
try {
3233
await this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`]);

lib/commands/update.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from "path";
22
import * as shelljs from "shelljs";
3+
import * as constants from "../constants";
34

45
export class UpdateCommand implements ICommand {
56
public allowedParameters: ICommandParameter[] = [];
@@ -63,7 +64,7 @@ export class UpdateCommand implements ICommand {
6364
this.$projectDataService.initialize(this.$projectData.projectDir);
6465
for (let platform of availablePlatforms) {
6566
let platformData = this.$platformsData.getPlatformData(platform);
66-
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName);
67+
let platformVersion = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
6768
if (platformVersion) {
6869
packagePlatforms.push(platform);
6970
this.$projectDataService.removeProperty(platformData.frameworkPackageName);

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const TESTING_FRAMEWORKS = ['jasmine', 'mocha', 'qunit'];
1515
export const TEST_RUNNER_NAME = "nativescript-unit-test-runner";
1616
export const LIVESYNC_EXCLUDED_FILE_PATTERNS = ["**/*.js.map", "**/*.ts"];
1717
export const XML_FILE_EXTENSION = ".xml";
18+
export const DEV_DEPENDENCIES = "devDependencies";
1819

1920
export class PackageVersion {
2021
static NEXT = "next";

lib/definitions/project.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ interface IProjectDataService {
6767
* @param {string} propertyName The name of the property to be checked in `nativescript` key.
6868
* @returns {any} The value of the property.
6969
*/
70-
getValue(propertyName: string): any;
70+
getValue(propertyName: string, key?: string): any;
7171

7272
/**
7373
* Sets a value in the `nativescript` key in a project's package.json.

lib/services/android-project-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
417417
if (!this._canUseGradle) {
418418
if (!frameworkVersion) {
419419
this.$projectDataService.initialize(this.$projectData.projectDir);
420-
let frameworkInfoInProjectFile = this.$projectDataService.getValue(this.platformData.frameworkPackageName);
420+
let frameworkInfoInProjectFile = this.$projectDataService.getValue(this.platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
421421
frameworkVersion = frameworkInfoInProjectFile && frameworkInfoInProjectFile.version;
422422
}
423423

lib/services/livesync/livesync-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LiveSyncService implements ILiveSyncService {
2727

2828
private async ensureAndroidFrameworkVersion(platformData: IPlatformData): Promise<void> { // TODO: this can be moved inside command or canExecute function
2929
this.$projectDataService.initialize(this.$projectData.projectDir);
30-
let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).version;
30+
let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES).version;
3131

3232
if (platformData.normalizedPlatformName.toLowerCase() === this.$devicePlatformsConstants.Android.toLowerCase()) {
3333
if (semver.lt(frameworkVersion, "1.2.1")) {
@@ -46,9 +46,9 @@ class LiveSyncService implements ILiveSyncService {
4646
}
4747

4848
public async liveSync(platform: string, applicationReloadAction?: (deviceAppData: Mobile.IDeviceAppData) => Promise<void>): Promise<void> {
49-
if (this.$options.justlaunch) {
50-
this.$options.watch = false;
51-
}
49+
if (this.$options.justlaunch) {
50+
this.$options.watch = false;
51+
}
5252
let liveSyncData: ILiveSyncData[] = [];
5353

5454
if (platform) {

lib/services/platform-project-service-base.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as constants from "../constants";
2+
13
export class PlatformProjectServiceBase implements IPlatformProjectServiceBase {
24
constructor(protected $fs: IFileSystem,
35
protected $projectData: IProjectData,
@@ -24,7 +26,7 @@ export class PlatformProjectServiceBase implements IPlatformProjectServiceBase {
2426

2527
protected getFrameworkVersion(runtimePackageName: string): string {
2628
this.$projectDataService.initialize(this.$projectData.projectDir);
27-
let frameworkVersion = this.$projectDataService.getValue(runtimePackageName).version;
29+
let frameworkVersion = this.$projectDataService.getValue(runtimePackageName, constants.DEV_DEPENDENCIES).version;
2830
return frameworkVersion;
2931
}
3032
}

lib/services/platform-service.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class PlatformService implements IPlatformService {
8282
let packageToInstall = "";
8383
let npmOptions: IStringDictionary = {
8484
pathToSave: path.join(this.$projectData.platformsDir, platform),
85-
dependencyType: "save"
85+
dependencyType: "save-dev"
8686
};
8787

8888
if (!this.$options.frameworkPath) {
@@ -98,7 +98,7 @@ export class PlatformService implements IPlatformService {
9898
frameworkDir = path.resolve(frameworkDir);
9999

100100
let coreModuleName = await this.addPlatformCore(platformData, frameworkDir);
101-
await this.$npm.uninstall(coreModuleName, { save: true }, this.$projectData.projectDir);
101+
await this.$npm.uninstall(coreModuleName, {}, this.$projectData.projectDir);
102102
} catch (err) {
103103
this.$fs.deleteDirectory(platformPath);
104104
throw err;
@@ -129,17 +129,15 @@ export class PlatformService implements IPlatformService {
129129
if (customTemplateOptions) {
130130
frameworkPackageNameData.template = customTemplateOptions.selectedTemplate;
131131
}
132-
this.$projectDataService.setValue(platformData.frameworkPackageName, frameworkPackageNameData);
133132

134133
return coreModuleName;
135-
136134
}
137135

138136
private async getPathToPlatformTemplate(selectedTemplate: string, frameworkPackageName: string): Promise<any> {
139137
if (!selectedTemplate) {
140138
// read data from package.json's nativescript key
141139
// check the nativescript.tns-<platform>.template value
142-
let nativescriptPlatformData = this.$projectDataService.getValue(frameworkPackageName);
140+
let nativescriptPlatformData = this.$projectDataService.getValue(frameworkPackageName, constants.DEV_DEPENDENCIES);
143141
selectedTemplate = nativescriptPlatformData && nativescriptPlatformData.template;
144142
}
145143

@@ -577,6 +575,7 @@ export class PlatformService implements IPlatformService {
577575
let platformDir = path.join(this.$projectData.platformsDir, platform);
578576
this.$fs.deleteDirectory(platformDir);
579577
this.$projectDataService.removeProperty(platformData.frameworkPackageName);
578+
this.$npm.uninstall(platformData.frameworkPackageName, {"save-dev": true})
580579

581580
this.$logger.out(`Platform ${platform} successfully removed.`);
582581
});
@@ -709,7 +708,7 @@ export class PlatformService implements IPlatformService {
709708
let platformData = this.$platformsData.getPlatformData(platform);
710709

711710
this.$projectDataService.initialize(this.$projectData.projectDir);
712-
let data = this.$projectDataService.getValue(platformData.frameworkPackageName);
711+
let data = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
713712
let currentVersion = data && data.version ? data.version : "0.2.0";
714713

715714
let newVersion = version === constants.PackageVersion.NEXT ?

lib/services/plugins-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ export class PluginsService implements IPluginsService {
276276
private getInstalledFrameworkVersion(platform: string): string {
277277
let platformData = this.$platformsData.getPlatformData(platform);
278278
this.$projectDataService.initialize(this.$projectData.projectDir);
279-
let frameworkData = this.$projectDataService.getValue(platformData.frameworkPackageName);
280-
return frameworkData.version;
279+
let version = this.$projectDataService.getValue(platformData.frameworkPackageName, constants.DEV_DEPENDENCIES);
280+
return version
281281
}
282282

283283
private isPluginDataValidForPlatform(pluginData: IPluginData, platform: string): boolean {

lib/services/project-data-service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ export class ProjectDataService implements IProjectDataService {
1818
}
1919
}
2020

21-
public getValue(propertyName: string): any {
21+
public getValue(propertyName: string, key?: string): any {
2222
this.loadProjectFile();
23-
return this.projectData ? this.projectData[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE][propertyName] : null;
23+
let rootKey: string = this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE;
24+
if(key) {
25+
rootKey = key;
26+
}
27+
return this.projectData ? this.projectData[rootKey][propertyName] : null;
2428
}
2529

2630
public setValue(key: string, value: any): void {

test/plugins-service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ function createProjectFile(testInjector: IInjector): string {
112112
"version": "0.1.0",
113113
"nativescript": {
114114
"id": "org.nativescript.Test",
115-
"tns-android": {
116-
"version": "1.4.0"
117-
}
115+
},
116+
"devDependencies": {
117+
"tns-android": "1.4.0"
118118
}
119119
};
120120

0 commit comments

Comments
 (0)