From c1c3ac429e3005cf0f286a8baacbb1bacc5e3845 Mon Sep 17 00:00:00 2001 From: Peter Kanev Date: Tue, 6 Jun 2017 15:20:36 +0300 Subject: [PATCH] Flatten scoped module when copying into android/src (#2837) * fix path when removing dir in a scoped dependency during prepare * flatten android plugins with native code when copying into main/src --- lib/services/android-project-service.ts | 5 ++++- lib/tools/node-modules/node-modules-dest-copy.ts | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index e2804185e2..b4e3d63f02 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -361,8 +361,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject if (this.$fs.exists(pluginPlatformsFolderPath)) { this.$fs.ensureDirectoryExists(pluginConfigurationDirectoryPath); + let isScoped = pluginData.name.indexOf("@") === 0; + let flattenedDependencyName = isScoped ? pluginData.name.replace("/", "_") : pluginData.name; + // Copy all resources from plugin - let resourcesDestinationDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, "src", pluginData.name); + let resourcesDestinationDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, "src", flattenedDependencyName); this.$fs.ensureDirectoryExists(resourcesDestinationDirectoryPath); shell.cp("-Rf", path.join(pluginPlatformsFolderPath, "*"), resourcesDestinationDirectoryPath); diff --git a/lib/tools/node-modules/node-modules-dest-copy.ts b/lib/tools/node-modules/node-modules-dest-copy.ts index c5cb4f4864..c035f3b197 100644 --- a/lib/tools/node-modules/node-modules-dest-copy.ts +++ b/lib/tools/node-modules/node-modules-dest-copy.ts @@ -36,18 +36,20 @@ export class TnsModulesCopy { private copyDependencyDir(dependency: IDependencyData): void { if (dependency.depth === 0) { + const targetPackageDir = path.join(this.outputRoot, dependency.name); + + shelljs.mkdir("-p", targetPackageDir); + let isScoped = dependency.name.indexOf("@") === 0; - let targetDir = this.outputRoot; if (isScoped) { - targetDir = path.join(this.outputRoot, dependency.name.substring(0, dependency.name.indexOf("/"))); + // copy module into tns_modules/@scope/module instead of tns_modules/module + shelljs.cp("-Rf", dependency.directory, path.join(this.outputRoot, dependency.name.substring(0, dependency.name.indexOf("/")))); + } else { + shelljs.cp("-Rf", dependency.directory, this.outputRoot); } - shelljs.mkdir("-p", targetDir); - shelljs.cp("-Rf", dependency.directory, targetDir); - - //remove platform-specific files (processed separately by plugin services) - const targetPackageDir = path.join(targetDir, dependency.name); + // remove platform-specific files (processed separately by plugin services) shelljs.rm("-rf", path.join(targetPackageDir, "platforms")); } }