Skip to content

Remove non-production dependencies which break npm links #2880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 8, 2017
Merged
Changes from 2 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
24 changes: 24 additions & 0 deletions lib/tools/node-modules/node-modules-dest-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ export class TnsModulesCopy {

// remove platform-specific files (processed separately by plugin services)
shelljs.rm("-rf", path.join(targetPackageDir, "platforms"));

this.removeNotProductionDependencies(dependency, targetPackageDir);
}
}

private removeNotProductionDependencies(dependency: IDependencyData, targetPackageDir: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removeNonProductionDependencies? (typo?)

let packageJsonFilePath = path.join(dependency.directory, "package.json");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use constants.PACKAGE_JSON_FILE_NAME instad of package.json

if (!this.$fs.exists(packageJsonFilePath)) {
return;
}

let packageJsonContent = this.$fs.readJson(packageJsonFilePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the lets can be consts

let productionDependencies = packageJsonContent.dependencies;

let dependenciesFolder = path.join(targetPackageDir, "node_modules");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use constants.NODE_MODULES_FOLDER_NAME instead of "node_modules"

if (this.$fs.exists(dependenciesFolder)) {
let dependencies = this.$fs.readDirectory(dependenciesFolder);

for (let i = 0; i < dependencies.length; i++) {
Copy link
Contributor

@petekanev petekanev Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The for loop can be replaced with

let dependencies = this.$fs.readDirectory(dependenciesFolder);
dependencies.filter(dir => !!!productionDependencies || !productionDependencies.hasOwnProperty(dir))
             .map(dir => shelljs.rm("-rf", path.join(dependenciesFolder, dir));

for consistency with the rest of the code base.

let dir = dependencies[i];
if (productionDependencies == null || !productionDependencies.hasOwnProperty(dir)) {
shelljs.rm("-rf", path.join(dependenciesFolder, dir));
}
}
}
}
}
Expand Down