From b99145d5d646f4f0a0515ed9fdf6570d925dafca Mon Sep 17 00:00:00 2001 From: Emil Tabakov Date: Thu, 8 Jun 2017 16:58:09 +0300 Subject: [PATCH] #2856 Remove non-production dependencies which break npm links (#2880) --- .../node-modules/node-modules-dest-copy.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/tools/node-modules/node-modules-dest-copy.ts b/lib/tools/node-modules/node-modules-dest-copy.ts index c035f3b197..cf904d28e6 100644 --- a/lib/tools/node-modules/node-modules-dest-copy.ts +++ b/lib/tools/node-modules/node-modules-dest-copy.ts @@ -29,7 +29,7 @@ export class TnsModulesCopy { let matchPattern = this.$options.release ? "**/*.ts" : "**/*.d.ts"; allFiles.filter(file => minimatch(file, matchPattern, { nocase: true })).map(file => this.$fs.deleteFile(file)); - shelljs.rm("-rf", path.join(tnsCoreModulesResourcePath, "node_modules")); + shelljs.rm("-rf", path.join(tnsCoreModulesResourcePath, constants.NODE_MODULES_FOLDER_NAME)); } } } @@ -51,6 +51,25 @@ export class TnsModulesCopy { // remove platform-specific files (processed separately by plugin services) shelljs.rm("-rf", path.join(targetPackageDir, "platforms")); + + this.removeNonProductionDependencies(dependency, targetPackageDir); + } + } + + private removeNonProductionDependencies(dependency: IDependencyData, targetPackageDir: string): void { + const packageJsonFilePath = path.join(dependency.directory, constants.PACKAGE_JSON_FILE_NAME); + if (!this.$fs.exists(packageJsonFilePath)) { + return; + } + + const packageJsonContent = this.$fs.readJson(packageJsonFilePath); + const productionDependencies = packageJsonContent.dependencies; + + const dependenciesFolder = path.join(targetPackageDir, constants.NODE_MODULES_FOLDER_NAME); + if (this.$fs.exists(dependenciesFolder)) { + const dependencies = this.$fs.readDirectory(dependenciesFolder); + dependencies.filter(dir => !!productionDependencies || !productionDependencies.hasOwnProperty(dir)) + .forEach(dir => shelljs.rm("-rf", path.join(dependenciesFolder, dir))); } } }