Skip to content

Commit 58fee14

Browse files
committed
CLI: Reduce size of the dependencies tree
Package 'findup-sync': * Tree: (96 packages) |- [email protected] |- [email protected] \ ... |- [email protected] \ ... |[email protected] \ ... * Summary: We used it in one place only, for finding a 'package.json' file. The findup-async library seems to only offer features we don't need. For example: - 'detect-file' provides a case-insensitive version of `fs.stat`. - 'is-glob' and 'micromatch' helps provide a pattern-based search. - 'resolve-dir' allows the start directory to contain tilde (~) for `$HOME` and `@` for package-bound traversal. For our use case, we only needed a loop that calls the built-in `require('fs').stat()` and `require('path').dirname()`. On second thought, I realised that we can avoid this entire problem by simply using `require('<module>/package.json')`. Which allows us to directly include a file from the module directory. Package 'exists-stat' * (1 package, no sub-dependencies.) * Summary: We used it in one place only. Added the function to cli/utils directly. Package 'walk-sync' * Tree: (7 packages) |- [email protected] |- [email protected] |- [email protected] |- [email protected] |- [email protected] |- [email protected] * Summary: We used in two places. I created a simplified version (directly based on Minimatch) in cli/utils and updated callers. Ref #1342.
1 parent d5d357b commit 58fee14

File tree

6 files changed

+55
-112
lines changed

6 files changed

+55
-112
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@
3232
],
3333
"dependencies": {
3434
"commander": "2.12.2",
35-
"exists-stat": "1.0.0",
36-
"findup-sync": "2.0.0",
3735
"js-reporters": "1.2.1",
3836
"resolve": "1.5.0",
3937
"sane": "^4.0.0",
40-
"walk-sync": "0.3.2"
38+
"minimatch": "3.0.4"
4139
},
4240
"devDependencies": {
4341
"async": "2.6.0",

src/cli/find-reporter.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use strict";
22

33
const JSReporters = require( "js-reporters" );
4-
const path = require( "path" );
5-
const findup = require( "findup-sync" );
64
const utils = require( "./utils" );
75
const pkg = require( "../../package.json" );
86

@@ -69,9 +67,7 @@ function getReportersFromDependencies() {
6967
);
7068
return dependencies.filter( dep => {
7169
try {
72-
const depPath = path.dirname( require.resolve( dep ) );
73-
const pkgPath = findup( "package.json", { cwd: depPath } );
74-
const pkg = require( pkgPath );
70+
const pkg = require( dep + "/package.json" );
7571

7672
return !!pkg.keywords && pkg.keywords.indexOf( "js-reporter" ) !== -1;
7773
} catch ( e ) {

src/cli/require-from-cwd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const resolve = require( "resolve" );
22

33
module.exports = function requireFromCWD( mod ) {
4+
5+
// TODO: Once Node 8+ is required, consider using native require.resolve().
46
const resolvedPath = resolve.sync( mod, { basedir: process.cwd() } );
57
return require( resolvedPath );
68
};

src/cli/run.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
const path = require( "path" );
4-
const walkSync = require( "walk-sync" );
54

65
const requireFromCWD = require( "./require-from-cwd" );
76
const requireQUnit = require( "./require-qunit" );
@@ -107,9 +106,8 @@ run.restart = function( args ) {
107106

108107
this._restartDebounceTimer = setTimeout( () => {
109108

110-
const watchedFiles = walkSync( process.cwd(), {
111-
globs: [ "**/*.js" ],
112-
directories: false,
109+
const watchedFiles = utils.findFiles( process.cwd(), {
110+
match: [ "**/*.js" ],
113111
ignore: IGNORED_GLOBS
114112
} );
115113

src/cli/utils.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,47 @@
11
"use strict";
22

3-
const walkSync = require( "walk-sync" );
4-
const existsStat = require( "exists-stat" );
3+
const fs = require( "fs" );
4+
const path = require( "path" );
5+
const { Minimatch } = require( "minimatch" );
6+
7+
function existsStat() {
8+
try {
9+
return fs.statSync.apply( fs, arguments );
10+
} catch ( e ) {
11+
return null;
12+
}
13+
}
14+
15+
function findFilesInternal( dir, options, result = [], prefix = "" ) {
16+
fs.readdirSync( dir ).forEach( ( name ) => {
17+
const fullName = path.join( dir, name );
18+
const stat = existsStat( fullName );
19+
if ( !stat ) {
20+
return;
21+
}
22+
const prefixedName = prefix + name;
23+
const isIgnore = options.ignores.some( ( mm ) => mm.match( prefixedName ) );
24+
if ( isIgnore ) {
25+
return;
26+
}
27+
if ( stat.isDirectory() ) {
28+
findFilesInternal( fullName, options, result, prefixedName + "/" );
29+
} else {
30+
const isMatch = options.matchers.some( ( mm ) => mm.match( prefixedName ) );
31+
if ( isMatch ) {
32+
result.push( prefixedName );
33+
}
34+
}
35+
} );
36+
return result;
37+
}
38+
39+
function findFiles( baseDir, options ) {
40+
return findFilesInternal( baseDir, {
41+
matchers: ( options.match || [] ).map( ( pattern ) => new Minimatch( pattern ) ),
42+
ignores: ( options.ignore || [] ).map( ( pattern ) => new Minimatch( pattern ) )
43+
} );
44+
}
545

646
function getFilesFromArgs( args ) {
747
let globs = args.slice();
@@ -23,7 +63,7 @@ function getFilesFromArgs( args ) {
2363
}
2464
} );
2565

26-
const files = walkSync( process.cwd(), { globs } );
66+
const files = findFiles( process.cwd(), { match: globs } );
2767

2868
if ( !files.length ) {
2969
error( "No files were found matching: " + args.join( ", " ) );
@@ -42,6 +82,7 @@ function capitalize( string ) {
4282
}
4383

4484
module.exports = {
85+
findFiles,
4586
capitalize,
4687
error,
4788
getFilesFromArgs

yarn.lock

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,11 +1246,6 @@ destroy@~1.0.4:
12461246
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
12471247
integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=
12481248

1249-
detect-file@^1.0.0:
1250-
version "1.0.0"
1251-
resolved "https://registry.yarnpkg.com/detect-file/-/detect-file-1.0.0.tgz#f0d66d03672a825cb1b73bdb3fe62310c8e552b7"
1252-
integrity sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=
1253-
12541249
detect-indent@^4.0.0:
12551250
version "4.0.0"
12561251
resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-4.0.0.tgz#f76d064352cdf43a1cb6ce619c4ee3a9475de208"
@@ -1338,11 +1333,6 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0:
13381333
dependencies:
13391334
once "^1.4.0"
13401335

1341-
ensure-posix-path@^1.0.0:
1342-
version "1.0.2"
1343-
resolved "https://registry.yarnpkg.com/ensure-posix-path/-/ensure-posix-path-1.0.2.tgz#a65b3e42d0b71cfc585eb774f9943c8d9b91b0c2"
1344-
integrity sha1-pls+QtC3HPxYXrd0+ZQ8jZuRsMI=
1345-
13461336
entities@^1.1.1, entities@~1.1.1:
13471337
version "1.1.1"
13481338
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
@@ -1571,11 +1561,6 @@ execa@^1.0.0:
15711561
signal-exit "^3.0.0"
15721562
strip-eof "^1.0.0"
15731563

1574-
1575-
version "1.0.0"
1576-
resolved "https://registry.yarnpkg.com/exists-stat/-/exists-stat-1.0.0.tgz#0660e3525a2e89d9e446129440c272edfa24b529"
1577-
integrity sha1-BmDjUlouidnkRhKUQMJy7foktSk=
1578-
15791564
exit@~0.1.1:
15801565
version "0.1.2"
15811566
resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"
@@ -1594,13 +1579,6 @@ expand-brackets@^2.1.4:
15941579
snapdragon "^0.8.1"
15951580
to-regex "^3.0.1"
15961581

1597-
expand-tilde@^2.0.0, expand-tilde@^2.0.2:
1598-
version "2.0.2"
1599-
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
1600-
integrity sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=
1601-
dependencies:
1602-
homedir-polyfill "^1.0.1"
1603-
16041582
extend-shallow@^2.0.1:
16051583
version "2.0.1"
16061584
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f"
@@ -1759,16 +1737,6 @@ find-up@^1.0.0:
17591737
path-exists "^2.0.0"
17601738
pinkie-promise "^2.0.0"
17611739

1762-
1763-
version "2.0.0"
1764-
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-2.0.0.tgz#9326b1488c22d1a6088650a86901b2d9a90a2cbc"
1765-
integrity sha1-kyaxSIwi0aYIhlCoaQGy2akKLLw=
1766-
dependencies:
1767-
detect-file "^1.0.0"
1768-
is-glob "^3.1.0"
1769-
micromatch "^3.0.4"
1770-
resolve-dir "^1.0.1"
1771-
17721740
findup-sync@~0.3.0:
17731741
version "0.3.0"
17741742
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-0.3.0.tgz#37930aa5d816b777c03445e1966cc6790a4c0b16"
@@ -1937,26 +1905,6 @@ glob@~7.0.0:
19371905
once "^1.3.0"
19381906
path-is-absolute "^1.0.0"
19391907

1940-
global-modules@^1.0.0:
1941-
version "1.0.0"
1942-
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea"
1943-
integrity sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==
1944-
dependencies:
1945-
global-prefix "^1.0.1"
1946-
is-windows "^1.0.1"
1947-
resolve-dir "^1.0.0"
1948-
1949-
global-prefix@^1.0.1:
1950-
version "1.0.2"
1951-
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-1.0.2.tgz#dbf743c6c14992593c655568cb66ed32c0122ebe"
1952-
integrity sha1-2/dDxsFJklk8ZVVoy2btMsASLr4=
1953-
dependencies:
1954-
expand-tilde "^2.0.2"
1955-
homedir-polyfill "^1.0.1"
1956-
ini "^1.3.4"
1957-
is-windows "^1.0.1"
1958-
which "^1.2.14"
1959-
19601908
globals@^11.0.1:
19611909
version "11.7.0"
19621910
resolved "https://registry.yarnpkg.com/globals/-/globals-11.7.0.tgz#a583faa43055b1aca771914bf68258e2fc125673"
@@ -2242,13 +2190,6 @@ home-or-tmp@^2.0.0:
22422190
os-homedir "^1.0.0"
22432191
os-tmpdir "^1.0.1"
22442192

2245-
homedir-polyfill@^1.0.1:
2246-
version "1.0.1"
2247-
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc"
2248-
integrity sha1-TCu8inWJmP7r9e1oWA921GdotLw=
2249-
dependencies:
2250-
parse-passwd "^1.0.0"
2251-
22522193
hooker@~0.2.3:
22532194
version "0.2.3"
22542195
resolved "https://registry.yarnpkg.com/hooker/-/hooker-0.2.3.tgz#b834f723cc4a242aa65963459df6d984c5d3d959"
@@ -2452,11 +2393,6 @@ is-extendable@^1.0.1:
24522393
dependencies:
24532394
is-plain-object "^2.0.4"
24542395

2455-
is-extglob@^2.1.0:
2456-
version "2.1.1"
2457-
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
2458-
integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=
2459-
24602396
is-finite@^1.0.0:
24612397
version "1.0.2"
24622398
resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa"
@@ -2469,13 +2405,6 @@ is-fullwidth-code-point@^2.0.0:
24692405
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
24702406
integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=
24712407

2472-
is-glob@^3.1.0:
2473-
version "3.1.0"
2474-
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a"
2475-
integrity sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=
2476-
dependencies:
2477-
is-extglob "^2.1.0"
2478-
24792408
is-module@^1.0.0:
24802409
version "1.0.0"
24812410
resolved "https://registry.yarnpkg.com/is-module/-/is-module-1.0.0.tgz#3258fb69f78c14d5b815d664336b4cffb6441591"
@@ -2544,7 +2473,7 @@ is-utf8@^0.2.0:
25442473
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
25452474
integrity sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=
25462475

2547-
is-windows@^1.0.1, is-windows@^1.0.2:
2476+
is-windows@^1.0.2:
25482477
version "1.0.2"
25492478
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
25502479
integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==
@@ -2818,7 +2747,7 @@ map-visit@^1.0.0:
28182747
dependencies:
28192748
object-visit "^1.0.0"
28202749

2821-
matcher-collection@^1.0.0, matcher-collection@^1.0.4:
2750+
matcher-collection@^1.0.4:
28222751
version "1.0.5"
28232752
resolved "https://registry.yarnpkg.com/matcher-collection/-/matcher-collection-1.0.5.tgz#2ee095438372cb8884f058234138c05c644ec339"
28242753
integrity sha512-nUCmzKipcJEwYsBVAFh5P+d7JBuhJaW1xs85Hara9xuMLqtCVUrW6DSC0JVIkluxEH2W45nPBM/wjHtBXa/tYA==
@@ -2851,7 +2780,7 @@ merge@^1.2.0:
28512780
resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.0.tgz#7531e39d4949c281a66b8c5a6e0265e8b05894da"
28522781
integrity sha1-dTHjnUlJwoGma4xabgJl6LBYlNo=
28532782

2854-
micromatch@^3.0.4, micromatch@^3.1.4:
2783+
micromatch@^3.1.4:
28552784
version "3.1.10"
28562785
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"
28572786
integrity sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg==
@@ -2897,7 +2826,7 @@ mimic-fn@^1.0.0:
28972826
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
28982827
integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==
28992828

2900-
"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.4, minimatch@~3.0.2:
2829+
"minimatch@2 || 3", minimatch@3.0.4, minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.4, minimatch@~3.0.2:
29012830
version "3.0.4"
29022831
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
29032832
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
@@ -3186,11 +3115,6 @@ parse-json@^2.2.0:
31863115
dependencies:
31873116
error-ex "^1.2.0"
31883117

3189-
parse-passwd@^1.0.0:
3190-
version "1.0.0"
3191-
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
3192-
integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=
3193-
31943118
parseurl@~1.3.2:
31953119
version "1.3.2"
31963120
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
@@ -3545,14 +3469,6 @@ [email protected]:
35453469
resolved "https://registry.yarnpkg.com/requirejs/-/requirejs-2.3.5.tgz#617b9acbbcb336540ef4914d790323a8d4b861b0"
35463470
integrity sha512-svnO+aNcR/an9Dpi44C7KSAy5fFGLtmPbaaCeQaklUz8BQhS64tWWIIlvEA5jrWICzlO/X9KSzSeXFnZdBu8nw==
35473471

3548-
resolve-dir@^1.0.0, resolve-dir@^1.0.1:
3549-
version "1.0.1"
3550-
resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43"
3551-
integrity sha1-eaQGRMNivoLybv/nOcm7U4IEb0M=
3552-
dependencies:
3553-
expand-tilde "^2.0.0"
3554-
global-modules "^1.0.0"
3555-
35563472
resolve-from@^1.0.0:
35573473
version "1.0.1"
35583474
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
@@ -4272,14 +4188,6 @@ [email protected]:
42724188
core-util-is "1.0.2"
42734189
extsprintf "^1.2.0"
42744190

4275-
4276-
version "0.3.2"
4277-
resolved "https://registry.yarnpkg.com/walk-sync/-/walk-sync-0.3.2.tgz#4827280afc42d0e035367c4a4e31eeac0d136f75"
4278-
integrity sha512-FMB5VqpLqOCcqrzA9okZFc0wq0Qbmdm396qJxvQZhDpyu0W95G9JCmp74tx7iyYnyOcBtUuKJsgIKAqjozvmmQ==
4279-
dependencies:
4280-
ensure-posix-path "^1.0.0"
4281-
matcher-collection "^1.0.0"
4282-
42834191
walker@~1.0.5:
42844192
version "1.0.7"
42854193
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"
@@ -4308,7 +4216,7 @@ websocket-extensions@>=0.1.1:
43084216
resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29"
43094217
integrity sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==
43104218

4311-
which@^1.1.1, which@^1.2.14, which@^1.2.9, which@~1.3.0:
4219+
which@^1.1.1, which@^1.2.9, which@~1.3.0:
43124220
version "1.3.1"
43134221
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
43144222
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==

0 commit comments

Comments
 (0)