Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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