Skip to content

Commit

Permalink
Removes the node_modules by default (#691)
Browse files Browse the repository at this point in the history
* Removes the node_modules by default

* Adds release definition
  • Loading branch information
arcanis committed Jan 14, 2020
1 parent 16f76d4 commit 97703c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
19 changes: 19 additions & 0 deletions .yarn/versions/c60c2dbe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
releases:
"@yarnpkg/cli@2.0.0-rc.22": prerelease
"@yarnpkg/plugin-pnp@2.0.0-rc.13": prerelease

declined:
- "@yarnpkg/plugin-constraints@2.0.0-rc.9"
- "@yarnpkg/plugin-dlx@2.0.0-rc.10"
- "@yarnpkg/plugin-essentials@2.0.0-rc.18"
- "@yarnpkg/plugin-init@2.0.0-rc.10"
- "@yarnpkg/plugin-interactive-tools@2.0.0-rc.11"
- "@yarnpkg/plugin-npm-cli@2.0.0-rc.10"
- "@yarnpkg/plugin-pack@2.0.0-rc.13"
- "@yarnpkg/plugin-patch@2.0.0-rc.2"
- "@yarnpkg/plugin-stage@2.0.0-rc.13"
- "@yarnpkg/plugin-typescript@2.0.0-rc.11"
- "@yarnpkg/plugin-version@2.0.0-rc.17"
- "@yarnpkg/plugin-workspace-tools@2.0.0-rc.12"
- "@yarnpkg/check@2.0.0-rc.9"
- "@yarnpkg/core@2.0.0-rc.17"
17 changes: 12 additions & 5 deletions packages/plugin-pnp/sources/PnpLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ class PnpInstaller implements Installer {
}

async finalizeInstall() {
if (await this.shouldWarnNodeModules())
this.opts.report.reportWarning(MessageName.DANGEROUS_NODE_MODULES, `One or more node_modules have been detected; they risk hiding legitimate problems until your application reaches production.`);
const nodeModules = await this.locateNodeModules();
if (nodeModules.length > 0) {
this.opts.report.reportWarning(MessageName.DANGEROUS_NODE_MODULES, `One or more node_modules have been detected and will be removed. This operation may take some time.`);
for (const nodeModulesPath of nodeModules) {
await xfs.removePromise(nodeModulesPath);
}
}

this.trimBlacklistedPackages();

Expand Down Expand Up @@ -281,7 +286,9 @@ class PnpInstaller implements Installer {
}
}

private async shouldWarnNodeModules() {
private async locateNodeModules() {
const nodeModules: Array<PortablePath> = [];

for (const workspace of this.opts.project.workspaces) {
const nodeModulesPath = ppath.join(workspace.cwd, toFilename(`node_modules`));
if (!xfs.existsSync(nodeModulesPath))
Expand All @@ -291,10 +298,10 @@ class PnpInstaller implements Installer {
if (directoryListing.every(entry => entry.startsWith(`.`)))
continue;

return true;
nodeModules.push(nodeModulesPath);
}

return false;
return nodeModules;
}

private normalizeDirectoryPath(folder: PortablePath) {
Expand Down

0 comments on commit 97703c9

Please sign in to comment.