-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
264 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var Glob = require('glob').Glob | ||
|
||
/** | ||
* @param {string} cwd | ||
* @param {ProgressHandler} progressHandler | ||
*/ | ||
function findPackages (cwd, progressHandler) { | ||
return new Promise((resolve, reject) => { | ||
const matcher = new Glob( | ||
'**/node_modules/*/package.json', | ||
{cwd}, | ||
(err, results) => err ? /* istanbul ignore next */ reject(err) : resolve(results) | ||
) | ||
matcher.on('match', function (file) { | ||
progressHandler.dependencyFound(file) | ||
}) | ||
}) | ||
.then(dependencies => { | ||
// Only allow paths liks node_modules/pkg-name/node_modules/pkg-name/node_modules/pkg-name/package.json | ||
return dependencies.filter((file) => { | ||
const valid = file.match(/^(node_modules\/[^/]*\/)*package.json/) | ||
return valid | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = {findPackages} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const debug = require('debug')('analyze-module-size:progress') | ||
const ProgressBar = require('progress') | ||
|
||
class ProgressHandler { | ||
constructor (stream) { | ||
this.stream = stream | ||
this.foundDepsProgress = new ProgressBar('dependencies found: :current', {total: 1000, stream: this.stream}) | ||
this.loadedDepsProgress = null | ||
} | ||
|
||
/** | ||
* Notify the user that a dependency (package.json in node_modules) has been found | ||
* @param {string} file the path to the package.json file | ||
*/ | ||
dependencyFound (file) { | ||
this.foundDepsProgress.tick() | ||
} | ||
|
||
allDependenciesFound (dep) { | ||
this.stream.write(' ...done\n') | ||
this.loadedDepsProgress = new ProgressBar('Loading dependency details: :bar :locationxxxxxxxxxxxxxxxxxx', { | ||
total: dep, | ||
stream: this.stream | ||
}) | ||
} | ||
|
||
/** | ||
* Update the progressbar after a dependency has been loaded. | ||
* (Increase the tick-count) | ||
*/ | ||
dependencyLoaded (pkg) { | ||
this.loadedDepsProgress.tick({locationxxxxxxxxxxxxxxxxxx: pkg.location().substr(0, 'locationxxxxxxxxxxxxxxxxxx'.length)}) | ||
} | ||
|
||
connectAll () { | ||
this.stream.write('Connecting dependency graph\n') | ||
} | ||
|
||
done () { | ||
this.stream.write('done\n') | ||
} | ||
} | ||
|
||
/** | ||
* No actual output (only if DEBUG=anaylze-module-size:progress) | ||
*/ | ||
class NullProgressHandler { | ||
dependencyFound (file) { | ||
debug('dependencyFound', file) | ||
} | ||
|
||
allDependenciesFound (count) { | ||
debug('allDependenciesFound', count) | ||
} | ||
|
||
dependencyLoaded (pkg) { | ||
debug('dependencyLoaded', pkg.location()) | ||
} | ||
|
||
connectAll () { | ||
debug('connectAll') | ||
} | ||
|
||
done () { | ||
debug('done') | ||
} | ||
} | ||
|
||
module.exports = {ProgressHandler, NullProgressHandler} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.