Skip to content

Commit

Permalink
Better detection of node modules when pruning
Browse files Browse the repository at this point in the history
Fixes #845.
  • Loading branch information
malept committed May 18, 2018
1 parent b3c610c commit 69ad04b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions prune.js
Expand Up @@ -59,6 +59,7 @@ class Pruner {
module.exports = {
isModule: function isModule (pathToCheck) {
return fs.pathExists(path.join(pathToCheck, 'package.json'))
.then(exists => exists && path.basename(path.dirname(pathToCheck)) === 'node_modules')
},
Pruner: Pruner
}
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions test/prune.js
Expand Up @@ -2,6 +2,8 @@

const fs = require('fs-extra')
const path = require('path')
const prune = require('../prune')
const test = require('ava')
const util = require('./_util')

function checkDependency (t, resourcesPath, moduleName, moduleExists) {
Expand Down Expand Up @@ -53,3 +55,11 @@ util.testSinglePlatform('prune electron in dependencies', (t, baseOpts) => {

util.testSinglePlatform('prune: false test', createPruneOptionTest, false,
'package.json devDependency should exist under app/node_modules')

test('isModule only detects modules inside a node_modules parent folder', t =>
prune.isModule(util.fixtureSubdir(path.join('prune-is-module', 'node_modules', 'module')))
.then(isModule => {
t.true(isModule, 'module folder should be detected as module')
return prune.isModule(util.fixtureSubdir(path.join('prune-is-module', 'node_modules', 'module', 'not-module')))
}).then(isModule => t.false(isModule, 'not-module folder should not be detected as module'))
)

0 comments on commit 69ad04b

Please sign in to comment.