From d1e261d5f4aaaab49c70f1556aef450b87f065ba Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Fri, 10 Jul 2015 11:43:07 +0300 Subject: [PATCH] Fix prepare to work correctly if you have npm module and tns plugin in same project --- lib/common | 2 +- lib/declarations.ts | 10 +++++----- lib/definitions/plugins.d.ts | 2 +- lib/node-package-manager.ts | 2 +- lib/services/platform-service.ts | 14 +++++--------- lib/services/plugins-service.ts | 14 ++++++++------ lib/tools/broccoli/builder.ts | 2 +- lib/tools/broccoli/node-modules-dest-copy.ts | 12 ++++++------ 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/lib/common b/lib/common index edf10eb9f1..9d7b712b79 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit edf10eb9f10fac608638384087ecfc7cca30b001 +Subproject commit 9d7b712b79776fb023c9514deb70f24a1d5f2fab diff --git a/lib/declarations.ts b/lib/declarations.ts index e07aa0d439..63a8cca93b 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -3,7 +3,7 @@ interface INodePackageManager { load(config?: any): IFuture; install(packageName: string, pathToSave: string, config?: any): IFuture; uninstall(packageName: string, config?: any): IFuture; - cache(packageName: string, version: string, cache?: any): IFuture; + cache(packageName: string, version: string, cache?: any): IFuture; cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture; view(packageName: string, propertyName: string): IFuture; } @@ -22,12 +22,12 @@ interface INpmInstallOptions { version?: string; } -interface ICacheData { +interface IDependencyData { name: string; version: string; - dependencies: IStringDictionary; - devDependencies: IStringDictionary; - nativescript?: any; + nativescript: any; + dependencies?: IStringDictionary; + devDependencies?: IStringDictionary; } interface IStaticConfig extends Config.IStaticConfig { } diff --git a/lib/definitions/plugins.d.ts b/lib/definitions/plugins.d.ts index c8269c74b9..76376de67e 100644 --- a/lib/definitions/plugins.d.ts +++ b/lib/definitions/plugins.d.ts @@ -1,7 +1,7 @@ interface IPluginsService { add(plugin: string): IFuture; // adds plugin by name, github url, local path and et. remove(pluginName: string): IFuture; // removes plugin only by name - prepare(pluginData: IPluginData): IFuture; + prepare(pluginData: IDependencyData): IFuture; getAllInstalledPlugins(): IFuture; ensureAllDependenciesAreInstalled(): IFuture; } diff --git a/lib/node-package-manager.ts b/lib/node-package-manager.ts index f14c11f045..762f9364fd 100644 --- a/lib/node-package-manager.ts +++ b/lib/node-package-manager.ts @@ -35,7 +35,7 @@ export class NodePackageManager implements INodePackageManager { return this.loadAndExecute("uninstall", [[packageName]], { config: config }); } - public cache(packageName: string, version: string, config?: any): IFuture { + public cache(packageName: string, version: string, config?: any): IFuture { // function cache (pkg, ver, where, scrub, cb) return this.loadAndExecute("cache", [packageName, version, undefined, false], { subCommandName: "add", config: config }); } diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 5d94d8d11d..8d0d087c53 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -88,10 +88,6 @@ export class PlatformService implements IPlatformService { this.$fs.deleteDirectory(platformPath).wait(); throw err; } - - // Prepare installed plugins - let installedPlugins = this.$pluginsService.getAllInstalledPlugins().wait(); - _.each(installedPlugins, pluginData => this.$pluginsService.prepare(pluginData).wait()); this.$logger.out("Project successfully created."); @@ -179,15 +175,15 @@ export class PlatformService implements IPlatformService { platformData.platformProjectService.prepareProject().wait(); - // Process platform specific files - let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); - let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME]; - this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs).wait(); - // Process node_modules folder this.$pluginsService.ensureAllDependenciesAreInstalled().wait(); var tnsModulesDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, PlatformService.TNS_MODULES_FOLDER_NAME); this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, this.$projectData.projectDir, platform, lastModifiedTime).wait(); + + // Process platform specific files + let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); + let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME]; + this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs).wait(); this.$logger.out("Project successfully prepared"); }).future()(); diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 29122d88e4..d0a52b0ada 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -29,11 +29,11 @@ export class PluginsService implements IPluginsService { public add(plugin: string): IFuture { return (() => { let dependencies = this.getAllInstalledModules().wait(); - let cacheData = this.$npm.cache(plugin, undefined, PluginsService.NPM_CONFIG).wait(); - if(cacheData.nativescript) { + let dependencyData = this.$npm.cache(plugin, undefined, PluginsService.NPM_CONFIG).wait(); + if(dependencyData.nativescript) { let pluginName = this.executeNpmCommand(PluginsService.INSTALL_COMMAND_NAME, plugin).wait(); - this.prepare(this.convertToPluginData(cacheData)).wait(); - this.$logger.out(`Successfully installed plugin ${cacheData.name}.`); + this.prepare(dependencyData).wait(); + this.$logger.out(`Successfully installed plugin ${dependencyData.name}.`); } else { this.$errors.failWithoutHelp(`${plugin} is not a valid NativeScript plugin. Verify that the plugin package.json file contains a nativescript key and try again.`); } @@ -68,8 +68,10 @@ export class PluginsService implements IPluginsService { }).future()(); } - public prepare(pluginData: IPluginData): IFuture { + public prepare(dependencyData: IDependencyData): IFuture { return (() => { + let pluginData = this.convertToPluginData(dependencyData); + let action = (pluginDestinationPath: string, platform: string, platformData: IPlatformData) => { return (() => { // Process .js files @@ -89,7 +91,7 @@ export class PluginsService implements IPluginsService { } this.$fs.ensureDirectoryExists(pluginDestinationPath).wait(); - shelljs.cp("-R", pluginData.fullPath, pluginDestinationPath); + shelljs.cp("-Rf", pluginData.fullPath, pluginDestinationPath); let pluginPlatformsFolderPath = path.join(pluginDestinationPath, pluginData.name, "platforms", platform); let pluginConfigurationFilePath = path.join(pluginPlatformsFolderPath, platformData.configurationFileName); diff --git a/lib/tools/broccoli/builder.ts b/lib/tools/broccoli/builder.ts index 9d8fba9437..b21ef52e32 100644 --- a/lib/tools/broccoli/builder.ts +++ b/lib/tools/broccoli/builder.ts @@ -64,7 +64,7 @@ export class Builder implements IBroccoliBuilder { } if(!lastModifiedTime || isNodeModulesModified) { - let nodeModulesDirectories = this.$fs.readDirectory(nodeModulesPath).wait(); + let nodeModulesDirectories = this.$fs.exists(nodeModulesPath).wait() ? this.$fs.readDirectory(nodeModulesPath).wait() : []; _.each(nodeModulesDirectories, nodeModuleDirectoryName => { let nodeModuleFullPath = path.join(nodeModulesPath, nodeModuleDirectoryName); this.nodeModules[nodeModuleFullPath] = nodeModuleFullPath; diff --git a/lib/tools/broccoli/node-modules-dest-copy.ts b/lib/tools/broccoli/node-modules-dest-copy.ts index 45941440ec..9dc481aefa 100644 --- a/lib/tools/broccoli/node-modules-dest-copy.ts +++ b/lib/tools/broccoli/node-modules-dest-copy.ts @@ -23,7 +23,8 @@ export class DestCopy implements IBroccoliPlugin { private projectDir: string, private platform: string, private $fs: IFileSystem, - private $projectFilesManager: IProjectFilesManager) { + private $projectFilesManager: IProjectFilesManager, + private $pluginsService: IPluginsService) { this.dependencies = Object.create(null); this.devDependencies = this.getDevDependencies(projectDir); } @@ -40,13 +41,11 @@ export class DestCopy implements IBroccoliPlugin { let fileContent = require(packageJsonFilePath); if(!this.devDependencies[fileContent.name]) { // Don't flatten dev dependencies - let isPlugin = fileContent.nativescript; - let currentDependency = { name: fileContent.name, version: fileContent.version, directory: path.dirname(packageJsonFilePath), - isPlugin: isPlugin + nativescript: fileContent.nativescript }; let addedDependency = this.dependencies[currentDependency.name]; @@ -72,8 +71,9 @@ export class DestCopy implements IBroccoliPlugin { _.each(this.dependencies, dependency => { shelljs.cp("-Rf", dependency.directory, this.outputRoot); shelljs.rm("-rf", path.join(this.outputRoot, dependency.name, "node_modules")); - if(dependency.isPlugin) { - this.$projectFilesManager.processPlatformSpecificFiles(path.join(this.outputRoot, dependency.name), platform).wait(); + let isPlugin = !!dependency.nativescript; + if(isPlugin) { + this.$pluginsService.prepare(dependency).wait(); shelljs.rm("-rf", path.join(this.outputRoot, dependency.name, "platforms")); } });