Skip to content

Commit

Permalink
#2856 Remove non-production dependencies which break npm links (#2880)
Browse files Browse the repository at this point in the history
  • Loading branch information
etabakov authored Jun 8, 2017
1 parent 55b170a commit b99145d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/tools/node-modules/node-modules-dest-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand All @@ -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)));
}
}
}
Expand Down

0 comments on commit b99145d

Please sign in to comment.