Skip to content

Commit b99145d

Browse files
authored
#2856 Remove non-production dependencies which break npm links (#2880)
1 parent 55b170a commit b99145d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/tools/node-modules/node-modules-dest-copy.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class TnsModulesCopy {
2929
let matchPattern = this.$options.release ? "**/*.ts" : "**/*.d.ts";
3030
allFiles.filter(file => minimatch(file, matchPattern, { nocase: true })).map(file => this.$fs.deleteFile(file));
3131

32-
shelljs.rm("-rf", path.join(tnsCoreModulesResourcePath, "node_modules"));
32+
shelljs.rm("-rf", path.join(tnsCoreModulesResourcePath, constants.NODE_MODULES_FOLDER_NAME));
3333
}
3434
}
3535
}
@@ -51,6 +51,25 @@ export class TnsModulesCopy {
5151

5252
// remove platform-specific files (processed separately by plugin services)
5353
shelljs.rm("-rf", path.join(targetPackageDir, "platforms"));
54+
55+
this.removeNonProductionDependencies(dependency, targetPackageDir);
56+
}
57+
}
58+
59+
private removeNonProductionDependencies(dependency: IDependencyData, targetPackageDir: string): void {
60+
const packageJsonFilePath = path.join(dependency.directory, constants.PACKAGE_JSON_FILE_NAME);
61+
if (!this.$fs.exists(packageJsonFilePath)) {
62+
return;
63+
}
64+
65+
const packageJsonContent = this.$fs.readJson(packageJsonFilePath);
66+
const productionDependencies = packageJsonContent.dependencies;
67+
68+
const dependenciesFolder = path.join(targetPackageDir, constants.NODE_MODULES_FOLDER_NAME);
69+
if (this.$fs.exists(dependenciesFolder)) {
70+
const dependencies = this.$fs.readDirectory(dependenciesFolder);
71+
dependencies.filter(dir => !!productionDependencies || !productionDependencies.hasOwnProperty(dir))
72+
.forEach(dir => shelljs.rm("-rf", path.join(dependenciesFolder, dir)));
5473
}
5574
}
5675
}

0 commit comments

Comments
 (0)