From 74f29065f85903a2181c8450adcd2d41d239194b Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Fri, 13 Nov 2015 11:32:35 +0200 Subject: [PATCH 1/6] Don't try to execute fast livesync if the project has framework version lower than 1.5.0 --- lib/services/usb-livesync-service.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/services/usb-livesync-service.ts b/lib/services/usb-livesync-service.ts index 88ed619ea5..321eab9f0f 100644 --- a/lib/services/usb-livesync-service.ts +++ b/lib/services/usb-livesync-service.ts @@ -49,9 +49,10 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer let platformData = this.$platformsData.getPlatformData(platformLowerCase); + this.$projectDataService.initialize(this.$projectData.projectDir); + let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait().version; + if (platformLowerCase === this.$devicePlatformsConstants.Android.toLowerCase()) { - this.$projectDataService.initialize(this.$projectData.projectDir); - let frameworkVersion = this.$projectDataService.getValue(platformData.frameworkPackageName).wait().version; if (semver.lt(frameworkVersion, "1.2.1")) { let shouldUpdate = this.$prompter.confirm( "You need Android Runtime 1.2.1 or later for LiveSync to work properly. Do you want to update your runtime now?" @@ -139,6 +140,8 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer return platformSpecificUsbLiveSyncService.sendPageReloadMessageToDevice(deviceAppData).wait(); }); } + + this.$logger.info(`Successfully synced application ${this.$projectData.projectId}.`); }).future()(); }); }; @@ -156,7 +159,7 @@ export class UsbLiveSyncService extends usbLivesyncServiceBaseLib.UsbLiveSyncSer beforeLiveSyncAction: beforeLiveSyncAction, beforeBatchLiveSyncAction: beforeBatchLiveSyncAction, iOSSimulatorRelativeToProjectBasePathAction: iOSSimulatorRelativeToProjectBasePathAction, - canExecuteFastLiveSync: (filePath: string) => _.contains(fastLivesyncFileExtensions, path.extname(filePath)), + canExecuteFastLiveSync: (filePath: string) => _.contains(fastLivesyncFileExtensions, path.extname(filePath)) && semver.gte(frameworkVersion, "1.5.0"), fastLiveSync: fastLiveSync }; From 806662701e2de5389071c4bba75cc5b6a17df9d3 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 13 Nov 2015 12:02:12 +0200 Subject: [PATCH 2/6] Install devDependencies before prepare As our hooks (like typescript) are called before executing prepare method, we must be sure we have all devDependencies installed in order to be able to execute before-prepare hooks. This is mandatory for projects where typescript is enabled, but you do not have node_modules directory yet. --- lib/definitions/plugins.d.ts | 8 ++++++++ lib/services/platform-service.ts | 11 ++++++++++- lib/services/plugins-service.ts | 16 ++++++++++++++++ test/platform-service.ts | 3 ++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/definitions/plugins.d.ts b/lib/definitions/plugins.d.ts index 2935878a59..06e5e4f7b6 100644 --- a/lib/definitions/plugins.d.ts +++ b/lib/definitions/plugins.d.ts @@ -5,6 +5,13 @@ interface IPluginsService { getAllInstalledPlugins(): IFuture; ensureAllDependenciesAreInstalled(): IFuture; afterPrepareAllPlugins(): IFuture; + /** + * Installs all devDependencies of the project. + * In case all of them are already installed, no operation will be executed. + * In case any of them is missing, all of them will be installed. + * @return {IFuture} + */ + installDevDependencies(): IFuture; } interface IPluginData extends INodeModuleData { @@ -53,6 +60,7 @@ interface IPluginVariablesService { * @return {IFuture} returns the changed plugin configuration file content. */ getPluginVariablePropertyName(pluginData: IPluginData): string; + } interface IPluginVariableData { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index daf7447617..9ef7395a04 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -154,11 +154,20 @@ export class PlatformService implements IPlatformService { }).future()(); } - @helpers.hook('prepare') public preparePlatform(platform: string): IFuture { return (() => { this.validatePlatform(platform); + //Install dev-dependencies here, so before-prepare hooks will be executed correctly. + this.$pluginsService.installDevDependencies().wait(); + + this.preparePlatformCore(platform).wait(); + }).future()(); + } + + @helpers.hook('prepare') + private preparePlatformCore(platform: string): IFuture { + return (() => { platform = platform.toLowerCase(); this.ensurePlatformInstalled(platform).wait(); diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index ed85813b5b..4b497b6b51 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -185,6 +185,22 @@ export class PluginsService implements IPluginsService { return this.executeForAllInstalledPlatforms(action); } + public installDevDependencies(): IFuture { + return (() => { + let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : []; + let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait(); + let devDependencies = _.keys(packageJsonContent.devDependencies); + if(devDependencies.length && (this.$options.force || _.difference(devDependencies, installedDependencies).length)) { + let command = `npm install ${devDependencies.join(" ")}`; + if(this.$options.ignoreScripts) { + command += "--ignore-scripts"; + } + this.$logger.trace(`Command for installing devDependencies is: '${command}'.`); + this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait(); + } + }).future()(); + } + private get nodeModulesPath(): string { return path.join(this.$projectData.projectDir, "node_modules"); } diff --git a/test/platform-service.ts b/test/platform-service.ts index a4a766ecb5..2bf7b3c0b7 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -49,7 +49,8 @@ function createTestInjector() { }, ensureAllDependenciesAreInstalled: () => { return Future.fromResult(); - } + }, + installDevDependencies: () => Future.fromResult() }); testInjector.register("projectFilesManager", ProjectFilesManagerLib.ProjectFilesManager); testInjector.register("hooksService", stubs.HooksServiceStub); From 8c726cf5087fb02a209461fb78e190baf2c08ae5 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 13 Nov 2015 13:52:21 +0200 Subject: [PATCH 3/6] Install ALL dependencies and devDependencies before prepare The old fix for installing only devDependencies before preparing the project has a problem: `npm install ` does not respect the versions from the devDependencies section and always installs the latest versions. We cannot use `npm install @` as we do not know if they are real versions or paths or even "frog legs". There's a magical flag `--dev` which should allow you to do: `npm install --dev` and it will respect the versions from devDependencies. Unfortunately this flag forces recursive installation of devDependencies all down the tree of packages. Of course npm has another rabbit in the hat - `--only=dev`. However I couldn't get it work at all. So the only solution I could think about is to install all dependencies before preparing the project. --- lib/definitions/plugins.d.ts | 7 ------- lib/services/platform-service.ts | 10 +++++++--- lib/services/plugins-service.ts | 19 ++----------------- test/platform-service.ts | 3 +-- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/lib/definitions/plugins.d.ts b/lib/definitions/plugins.d.ts index 06e5e4f7b6..35e38b63ab 100644 --- a/lib/definitions/plugins.d.ts +++ b/lib/definitions/plugins.d.ts @@ -5,13 +5,6 @@ interface IPluginsService { getAllInstalledPlugins(): IFuture; ensureAllDependenciesAreInstalled(): IFuture; afterPrepareAllPlugins(): IFuture; - /** - * Installs all devDependencies of the project. - * In case all of them are already installed, no operation will be executed. - * In case any of them is missing, all of them will be installed. - * @return {IFuture} - */ - installDevDependencies(): IFuture; } interface IPluginData extends INodeModuleData { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 9ef7395a04..948c169c1c 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -158,8 +158,13 @@ export class PlatformService implements IPlatformService { return (() => { this.validatePlatform(platform); - //Install dev-dependencies here, so before-prepare hooks will be executed correctly. - this.$pluginsService.installDevDependencies().wait(); + //We need dev-dependencies here, so before-prepare hooks will be executed correctly. + try { + this.$pluginsService.ensureAllDependenciesAreInstalled().wait(); + } catch(err) { + this.$logger.trace(err); + this.$errors.failWithoutHelp(`Unable to install dependencies. Make sure your package.json is valid and all dependencies are correct. Error is: ${err.message}`); + } this.preparePlatformCore(platform).wait(); }).future()(); @@ -223,7 +228,6 @@ export class PlatformService implements IPlatformService { // Process node_modules folder let appDir = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); try { - this.$pluginsService.ensureAllDependenciesAreInstalled().wait(); let tnsModulesDestinationPath = path.join(appDir, PlatformService.TNS_MODULES_FOLDER_NAME); this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime).wait(); } catch(error) { diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 4b497b6b51..0951f4de4e 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -160,7 +160,8 @@ export class PluginsService implements IPluginsService { return (() => { let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : []; let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait(); - if(this.$options.force || (packageJsonContent.dependencies && _.difference(_.keys(packageJsonContent.dependencies), installedDependencies).length)) { + let allDependencies = _.keys(packageJsonContent.dependencies).concat(_.keys(packageJsonContent.devDependencies)); + if(this.$options.force || _.difference(allDependencies, installedDependencies).length) { let command = "npm install "; if(this.$options.ignoreScripts) { command += "--ignore-scripts"; @@ -185,22 +186,6 @@ export class PluginsService implements IPluginsService { return this.executeForAllInstalledPlatforms(action); } - public installDevDependencies(): IFuture { - return (() => { - let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : []; - let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait(); - let devDependencies = _.keys(packageJsonContent.devDependencies); - if(devDependencies.length && (this.$options.force || _.difference(devDependencies, installedDependencies).length)) { - let command = `npm install ${devDependencies.join(" ")}`; - if(this.$options.ignoreScripts) { - command += "--ignore-scripts"; - } - this.$logger.trace(`Command for installing devDependencies is: '${command}'.`); - this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait(); - } - }).future()(); - } - private get nodeModulesPath(): string { return path.join(this.$projectData.projectDir, "node_modules"); } diff --git a/test/platform-service.ts b/test/platform-service.ts index 2bf7b3c0b7..a4a766ecb5 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -49,8 +49,7 @@ function createTestInjector() { }, ensureAllDependenciesAreInstalled: () => { return Future.fromResult(); - }, - installDevDependencies: () => Future.fromResult() + } }); testInjector.register("projectFilesManager", ProjectFilesManagerLib.ProjectFilesManager); testInjector.register("hooksService", stubs.HooksServiceStub); From e3efe84f897af33dd4e6aae53f70f076f661f611 Mon Sep 17 00:00:00 2001 From: Rosen Vladimirov Date: Fri, 13 Nov 2015 15:03:57 +0200 Subject: [PATCH 4/6] Collect all warnings upon pod installing --- lib/services/ios-project-service.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index ff8a20a8fd..271c9ebf77 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -516,15 +516,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ let podTool = this.$config.USE_POD_SANDBOX ? "sandbox-pod" : "pod"; let childProcess = this.$childProcess.spawnFromEvent(podTool, ["install"], "close", { cwd: this.platformData.projectRoot, stdio: ['pipe', process.stdout, 'pipe'] }).wait(); if (childProcess.stderr) { - let warnings = childProcess.stderr.match(/(\u001b\[(?:\d*;){0,5}\d*m[\s\S]+?\u001b\[(?:\d*;){0,5}\d*m)|(\[!\].*?\n)/g); + let warnings = childProcess.stderr.match(/(\u001b\[(?:\d*;){0,5}\d*m[\s\S]+?\u001b\[(?:\d*;){0,5}\d*m)|(\[!\].*?\n)|(.*?warning.*)/gi); _.each(warnings, (warning: string) => { this.$logger.warnWithLabel(warning.replace("\n", "")); }); - // HACK for silencing irrelevant linking warnings when pod installing on - // El Capitan with cocoa pods version 0.38.2 - // Reference https://github.com/CocoaPods/CocoaPods/issues/4302 - let errors = childProcess.stderr.replace(/dyld: warning, LC_RPATH @executable_path.*?@executable_path/g, ""); + let errors = childProcess.stderr; _.each(warnings, warning => { errors = errors.replace(warning, ""); }); From 55603126744dc9780a52c04039aad4d4bae6524e Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Mon, 16 Nov 2015 09:40:13 +0200 Subject: [PATCH 5/6] Show message after successful deploy Get back the message that reports successful deploy on android device. We've deleted it a couple of commits ago. --- lib/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common b/lib/common index 46e271fc22..7ee22324d2 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 46e271fc2280d9b45bd027f78f0f411e9b8d474f +Subproject commit 7ee22324d20cc83ea44f58f85d0118c8b9f511b2 From 5b2bc76f500166543b3ea94882c749628f193797 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Mon, 16 Nov 2015 10:59:12 +0200 Subject: [PATCH 6/6] Set version to 1.6.0 Set version to 1.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b4a7f45813..1bcc36f325 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nativescript", "preferGlobal": true, - "version": "1.5.0", + "version": "1.6.0", "author": "Telerik ", "description": "Command-line interface for building NativeScript projects", "bin": {