From 63d1e3ee9c2e23ac87496ca78d3183f0652c531c Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 4 Jun 2019 14:51:26 -0700 Subject: [PATCH] Sort by type for compression benefits Gzip is best optimized when files containing similar contents are nearby one another in the string of bytes being compressed. Sort by extname, then basename, then alphabetically, to increase the likelihood of similar files being found nearby one another in the resulting tarball archive. Fix #30 --- index.js | 23 ++++++++------ ...test-bundled-scoped-symlink.js-TAP.test.js | 24 +++++++++++++++ .../test-bundled-scoped.js-TAP.test.js | 24 +++++++++++++++ .../test-bundled-symlink.js-TAP.test.js | 24 +++++++++++++++ tap-snapshots/test-bundled.js-TAP.test.js | 24 +++++++++++++++ tap-snapshots/test-cwd.js-TAP.test.js | 30 +++++++++++++++++++ .../test-empty-npmignore.js-TAP.test.js | 24 +++++++++++++++ tap-snapshots/test-ignores.js-TAP.test.js | 24 +++++++++++++++ .../test-include-gitignore.js-TAP.test.js | 24 +++++++++++++++ .../test-nested-lock-and-core.js-TAP.test.js | 24 +++++++++++++++ ...t-package-json-bin-multiple.js-TAP.test.js | 24 +++++++++++++++ ...est-package-json-bin-single.js-TAP.test.js | 22 ++++++++++++++ .../test-package-json-empty.js-TAP.test.js | 20 +++++++++++++ .../test-package-json-main.js-TAP.test.js | 26 ++++++++++++++++ .../test-package-json-nested.js-TAP.test.js | 22 ++++++++++++++ .../test-package-json.js-TAP.test.js | 22 ++++++++++++++ .../test-package-not-json.js-TAP.test.js | 22 ++++++++++++++ tap-snapshots/test-scoped.js-TAP.test.js | 22 ++++++++++++++ tap-snapshots/test-sorting.js-TAP.test.js | 18 +++++++++++ tap-snapshots/test-star-names.js-TAP.test.js | 22 ++++++++++++++ tap-snapshots/test-symlink.js-TAP.test.js | 22 ++++++++++++++ test/bundled-scoped-symlink.js | 9 +----- test/bundled-scoped.js | 9 +----- test/bundled-symlink.js | 9 +----- test/bundled.js | 9 +----- test/cwd.js | 8 +---- test/empty-npmignore.js | 9 +----- test/ignores.js | 9 +----- test/include-gitignore.js | 9 +----- test/nested-lock-and-core.js | 9 +----- test/package-json-bin-multiple.js | 9 +----- test/package-json-bin-single.js | 8 +---- test/package-json-empty.js | 7 +---- test/package-json-main.js | 10 +------ test/package-json-nested.js | 7 +---- test/package-json.js | 8 +---- test/package-not-json.js | 8 +---- test/scoped.js | 8 +---- test/sorting.js | 16 ++-------- test/symlink.js | 8 +---- 40 files changed, 498 insertions(+), 158 deletions(-) create mode 100644 tap-snapshots/test-bundled-scoped-symlink.js-TAP.test.js create mode 100644 tap-snapshots/test-bundled-scoped.js-TAP.test.js create mode 100644 tap-snapshots/test-bundled-symlink.js-TAP.test.js create mode 100644 tap-snapshots/test-bundled.js-TAP.test.js create mode 100644 tap-snapshots/test-cwd.js-TAP.test.js create mode 100644 tap-snapshots/test-empty-npmignore.js-TAP.test.js create mode 100644 tap-snapshots/test-ignores.js-TAP.test.js create mode 100644 tap-snapshots/test-include-gitignore.js-TAP.test.js create mode 100644 tap-snapshots/test-nested-lock-and-core.js-TAP.test.js create mode 100644 tap-snapshots/test-package-json-bin-multiple.js-TAP.test.js create mode 100644 tap-snapshots/test-package-json-bin-single.js-TAP.test.js create mode 100644 tap-snapshots/test-package-json-empty.js-TAP.test.js create mode 100644 tap-snapshots/test-package-json-main.js-TAP.test.js create mode 100644 tap-snapshots/test-package-json-nested.js-TAP.test.js create mode 100644 tap-snapshots/test-package-json.js-TAP.test.js create mode 100644 tap-snapshots/test-package-not-json.js-TAP.test.js create mode 100644 tap-snapshots/test-scoped.js-TAP.test.js create mode 100644 tap-snapshots/test-sorting.js-TAP.test.js create mode 100644 tap-snapshots/test-star-names.js-TAP.test.js create mode 100644 tap-snapshots/test-symlink.js-TAP.test.js diff --git a/index.js b/index.js index 7e55382..59a9aba 100644 --- a/index.js +++ b/index.js @@ -249,15 +249,20 @@ const walkSync = options => { return walker.result } -// package.json first, node_modules last, files before folders, alphasort -const sort = (a, b) => - a === 'package.json' ? -1 - : b === 'package.json' ? 1 - : /^node_modules/.test(a) && !/^node_modules/.test(b) ? 1 - : /^node_modules/.test(b) && !/^node_modules/.test(a) ? -1 - : path.dirname(a) === '.' && path.dirname(b) !== '.' ? -1 - : path.dirname(b) === '.' && path.dirname(a) !== '.' ? 1 - : a.localeCompare(b) +// optimize for compressibility +// extname, then basename, then locale alphabetically +// https://twitter.com/isntitvacant/status/1131094910923231232 +const sort = (a, b) => { + const exta = path.extname(a).toLowerCase() + const extb = path.extname(b).toLowerCase() + const basea = path.basename(a).toLowerCase() + const baseb = path.basename(b).toLowerCase() + + return exta.localeCompare(extb) || + basea.localeCompare(baseb) || + a.localeCompare(b) +} + module.exports = walk walk.sync = walkSync diff --git a/tap-snapshots/test-bundled-scoped-symlink.js-TAP.test.js b/tap-snapshots/test-bundled-scoped-symlink.js-TAP.test.js new file mode 100644 index 0000000..741670a --- /dev/null +++ b/tap-snapshots/test-bundled-scoped-symlink.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/bundled-scoped-symlink.js TAP includes bundled dependency async > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/@npmwombat/history/index.js", + "node_modules/@npmwombat/history/package.json", + "package.json", +] +` + +exports[`test/bundled-scoped-symlink.js TAP includes bundled dependency sync > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/@npmwombat/history/index.js", + "node_modules/@npmwombat/history/package.json", + "package.json", +] +` diff --git a/tap-snapshots/test-bundled-scoped.js-TAP.test.js b/tap-snapshots/test-bundled-scoped.js-TAP.test.js new file mode 100644 index 0000000..8d517ac --- /dev/null +++ b/tap-snapshots/test-bundled-scoped.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/bundled-scoped.js TAP includes bundled dependency async > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/@npmwombat/history/index.js", + "node_modules/@npmwombat/history/package.json", + "package.json", +] +` + +exports[`test/bundled-scoped.js TAP includes bundled dependency sync > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/@npmwombat/history/index.js", + "node_modules/@npmwombat/history/package.json", + "package.json", +] +` diff --git a/tap-snapshots/test-bundled-symlink.js-TAP.test.js b/tap-snapshots/test-bundled-symlink.js-TAP.test.js new file mode 100644 index 0000000..e7e2684 --- /dev/null +++ b/tap-snapshots/test-bundled-symlink.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/bundled-symlink.js TAP includes bundled dependency async > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/history/index.js", + "node_modules/history/package.json", + "package.json", +] +` + +exports[`test/bundled-symlink.js TAP includes bundled dependency sync > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/history/index.js", + "node_modules/history/package.json", + "package.json", +] +` diff --git a/tap-snapshots/test-bundled.js-TAP.test.js b/tap-snapshots/test-bundled.js-TAP.test.js new file mode 100644 index 0000000..c826baf --- /dev/null +++ b/tap-snapshots/test-bundled.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/bundled.js TAP includes bundled dependency async > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/history/index.js", + "node_modules/history/package.json", + "package.json", +] +` + +exports[`test/bundled.js TAP includes bundled dependency sync > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/history/index.js", + "node_modules/history/package.json", + "package.json", +] +` diff --git a/tap-snapshots/test-cwd.js-TAP.test.js b/tap-snapshots/test-cwd.js-TAP.test.js new file mode 100644 index 0000000..ba96ade --- /dev/null +++ b/tap-snapshots/test-cwd.js-TAP.test.js @@ -0,0 +1,30 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/cwd.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` + +exports[`test/cwd.js TAP follows npm package ignoring rules sync 1 > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` + +exports[`test/cwd.js TAP follows npm package ignoring rules sync 2 > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-empty-npmignore.js-TAP.test.js b/tap-snapshots/test-empty-npmignore.js-TAP.test.js new file mode 100644 index 0000000..bcde886 --- /dev/null +++ b/tap-snapshots/test-empty-npmignore.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/empty-npmignore.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "lib/node_modules/foo/package.json", + "package.json", +] +` + +exports[`test/empty-npmignore.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "lib/node_modules/foo/package.json", + "package.json", +] +` diff --git a/tap-snapshots/test-ignores.js-TAP.test.js b/tap-snapshots/test-ignores.js-TAP.test.js new file mode 100644 index 0000000..63bfa8a --- /dev/null +++ b/tap-snapshots/test-ignores.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/ignores.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", + "readme.md", +] +` + +exports[`test/ignores.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", + "readme.md", +] +` diff --git a/tap-snapshots/test-include-gitignore.js-TAP.test.js b/tap-snapshots/test-include-gitignore.js-TAP.test.js new file mode 100644 index 0000000..647d036 --- /dev/null +++ b/tap-snapshots/test-include-gitignore.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/include-gitignore.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "z/.gitignore", + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` + +exports[`test/include-gitignore.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "z/.gitignore", + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-nested-lock-and-core.js-TAP.test.js b/tap-snapshots/test-nested-lock-and-core.js-TAP.test.js new file mode 100644 index 0000000..7c0da8a --- /dev/null +++ b/tap-snapshots/test-nested-lock-and-core.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/nested-lock-and-core.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "lib/package-lock.json", + "package.json", + "lib/yarn.lock", + "core/include-me.txt", +] +` + +exports[`test/nested-lock-and-core.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "lib/package-lock.json", + "package.json", + "lib/yarn.lock", + "core/include-me.txt", +] +` diff --git a/tap-snapshots/test-package-json-bin-multiple.js-TAP.test.js b/tap-snapshots/test-package-json-bin-multiple.js-TAP.test.js new file mode 100644 index 0000000..35f20b8 --- /dev/null +++ b/tap-snapshots/test-package-json-bin-multiple.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/package-json-bin-multiple.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "__bin_bar", + "__bin_foo", + "lib/elf.js", + "package.json", +] +` + +exports[`test/package-json-bin-multiple.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "__bin_bar", + "__bin_foo", + "lib/elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-package-json-bin-single.js-TAP.test.js b/tap-snapshots/test-package-json-bin-single.js-TAP.test.js new file mode 100644 index 0000000..cf003e0 --- /dev/null +++ b/tap-snapshots/test-package-json-bin-single.js-TAP.test.js @@ -0,0 +1,22 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/package-json-bin-single.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "__bin", + "lib/elf.js", + "package.json", +] +` + +exports[`test/package-json-bin-single.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "__bin", + "lib/elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-package-json-empty.js-TAP.test.js b/tap-snapshots/test-package-json-empty.js-TAP.test.js new file mode 100644 index 0000000..2d009de --- /dev/null +++ b/tap-snapshots/test-package-json-empty.js-TAP.test.js @@ -0,0 +1,20 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/package-json-empty.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "elf.js", + "package.json", +] +` + +exports[`test/package-json-empty.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-package-json-main.js-TAP.test.js b/tap-snapshots/test-package-json-main.js-TAP.test.js new file mode 100644 index 0000000..7836cb3 --- /dev/null +++ b/tap-snapshots/test-package-json-main.js-TAP.test.js @@ -0,0 +1,26 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/package-json-main.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "__main.js", + "browser.js", + "elf.js", + "package.json", +] +` + +exports[`test/package-json-main.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "__main.js", + "browser.js", + "elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-package-json-nested.js-TAP.test.js b/tap-snapshots/test-package-json-nested.js-TAP.test.js new file mode 100644 index 0000000..0b125f1 --- /dev/null +++ b/tap-snapshots/test-package-json-nested.js-TAP.test.js @@ -0,0 +1,22 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/package-json-nested.js TAP includes nested package.json file async > must match snapshot 1`] = ` +Array [ + "nest/index.js", + "nest/package.json", + "package.json", +] +` + +exports[`test/package-json-nested.js TAP includes nested package.json file sync > must match snapshot 1`] = ` +Array [ + "nest/index.js", + "nest/package.json", + "package.json", +] +` diff --git a/tap-snapshots/test-package-json.js-TAP.test.js b/tap-snapshots/test-package-json.js-TAP.test.js new file mode 100644 index 0000000..d967800 --- /dev/null +++ b/tap-snapshots/test-package-json.js-TAP.test.js @@ -0,0 +1,22 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/package-json.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` + +exports[`test/package-json.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-package-not-json.js-TAP.test.js b/tap-snapshots/test-package-not-json.js-TAP.test.js new file mode 100644 index 0000000..4d5f28b --- /dev/null +++ b/tap-snapshots/test-package-not-json.js-TAP.test.js @@ -0,0 +1,22 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/package-not-json.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` + +exports[`test/package-not-json.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-scoped.js-TAP.test.js b/tap-snapshots/test-scoped.js-TAP.test.js new file mode 100644 index 0000000..e0e0589 --- /dev/null +++ b/tap-snapshots/test-scoped.js-TAP.test.js @@ -0,0 +1,22 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/scoped.js TAP includes bundledDependencies async > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/@npmwombat/scoped/index.js", + "package.json", +] +` + +exports[`test/scoped.js TAP includes bundledDependencies sync > must match snapshot 1`] = ` +Array [ + "elf.js", + "node_modules/@npmwombat/scoped/index.js", + "package.json", +] +` diff --git a/tap-snapshots/test-sorting.js-TAP.test.js b/tap-snapshots/test-sorting.js-TAP.test.js new file mode 100644 index 0000000..ef44b01 --- /dev/null +++ b/tap-snapshots/test-sorting.js-TAP.test.js @@ -0,0 +1,18 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/sorting.js TAP > must match snapshot 1`] = ` +Array [ + "a/b/1", + "node_modules/a/b/c", + "node_modules/b/c", + "a/b/c/d/e/f/g", + "a/b/x/y", + "asdf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-star-names.js-TAP.test.js b/tap-snapshots/test-star-names.js-TAP.test.js new file mode 100644 index 0000000..7254245 --- /dev/null +++ b/tap-snapshots/test-star-names.js-TAP.test.js @@ -0,0 +1,22 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/star-names.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` + +exports[`test/star-names.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` diff --git a/tap-snapshots/test-symlink.js-TAP.test.js b/tap-snapshots/test-symlink.js-TAP.test.js new file mode 100644 index 0000000..6154246 --- /dev/null +++ b/tap-snapshots/test-symlink.js-TAP.test.js @@ -0,0 +1,22 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/symlink.js TAP follows npm package ignoring rules async > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` + +exports[`test/symlink.js TAP follows npm package ignoring rules sync > must match snapshot 1`] = ` +Array [ + "deps/foo/config/config.gypi", + "elf.js", + "package.json", +] +` diff --git a/test/bundled-scoped-symlink.js b/test/bundled-scoped-symlink.js index 60af4ad..413112e 100644 --- a/test/bundled-scoped-symlink.js +++ b/test/bundled-scoped-symlink.js @@ -29,13 +29,6 @@ const json = { ] } -const expect = [ - 'package.json', - 'elf.js', - 'node_modules/@npmwombat/history/index.js', - 'node_modules/@npmwombat/history/package.json' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -78,7 +71,7 @@ t.test('setup', t => { t.test('includes bundled dependency', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/bundled-scoped.js b/test/bundled-scoped.js index 57958e1..622b65f 100644 --- a/test/bundled-scoped.js +++ b/test/bundled-scoped.js @@ -25,13 +25,6 @@ const json = { ] } -const expect = [ - 'package.json', - 'elf.js', - 'node_modules/@npmwombat/history/index.js', - 'node_modules/@npmwombat/history/package.json' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -71,7 +64,7 @@ t.test('setup', t => { t.test('includes bundled dependency', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/bundled-symlink.js b/test/bundled-symlink.js index 46aded1..fca3512 100644 --- a/test/bundled-symlink.js +++ b/test/bundled-symlink.js @@ -29,13 +29,6 @@ const json = { ] } -const expect = [ - 'package.json', - 'elf.js', - 'node_modules/history/index.js', - 'node_modules/history/package.json' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -78,7 +71,7 @@ t.test('setup', t => { t.test('includes bundled dependency', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/bundled.js b/test/bundled.js index ae0e230..f1a251b 100644 --- a/test/bundled.js +++ b/test/bundled.js @@ -25,13 +25,6 @@ const json = { ] } -const expect = [ - 'package.json', - 'elf.js', - 'node_modules/history/index.js', - 'node_modules/history/package.json' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -71,7 +64,7 @@ t.test('setup', t => { t.test('includes bundled dependency', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/cwd.js b/test/cwd.js index a0795b3..d26b245 100644 --- a/test/cwd.js +++ b/test/cwd.js @@ -22,12 +22,6 @@ const json = { 'main': 'elf.js' } -const expect = [ - 'package.json', - 'elf.js', - 'deps/foo/config/config.gypi' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -95,7 +89,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { process.chdir(pkg) const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/empty-npmignore.js b/test/empty-npmignore.js index e66a817..f1f13aa 100644 --- a/test/empty-npmignore.js +++ b/test/empty-npmignore.js @@ -22,13 +22,6 @@ const json = { 'main': 'elf.js' } -const expect = [ - 'package.json', - 'elf.js', - 'deps/foo/config/config.gypi', - 'lib/node_modules/foo/package.json' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -102,7 +95,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/ignores.js b/test/ignores.js index be16ec7..22c6c8b 100644 --- a/test/ignores.js +++ b/test/ignores.js @@ -22,13 +22,6 @@ const json = { 'main': 'elf.js' } -const expect = [ - 'package.json', - 'elf.js', - 'readme.md', - 'deps/foo/config/config.gypi' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -140,7 +133,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/include-gitignore.js b/test/include-gitignore.js index 5ecb702..20c9933 100644 --- a/test/include-gitignore.js +++ b/test/include-gitignore.js @@ -22,13 +22,6 @@ const json = { 'main': 'elf.js' } -const expect = [ - 'package.json', - 'elf.js', - 'deps/foo/config/config.gypi', - 'z/.gitignore' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg + '/z') @@ -106,7 +99,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/nested-lock-and-core.js b/test/nested-lock-and-core.js index f17cdba..34b5c1e 100644 --- a/test/nested-lock-and-core.js +++ b/test/nested-lock-and-core.js @@ -42,15 +42,8 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { - const expect = [ - 'package.json', - 'core/include-me.txt', - 'lib/package-lock.json', - 'lib/yarn.lock', - ] - const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/package-json-bin-multiple.js b/test/package-json-bin-multiple.js index 6d53abf..b88240c 100644 --- a/test/package-json-bin-multiple.js +++ b/test/package-json-bin-multiple.js @@ -33,13 +33,6 @@ const json = { ] } -const expect = [ - 'package.json', - '__bin_bar', - '__bin_foo', - 'lib/elf.js' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -75,7 +68,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', t => { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/package-json-bin-single.js b/test/package-json-bin-single.js index 3b3d137..5f556d0 100644 --- a/test/package-json-bin-single.js +++ b/test/package-json-bin-single.js @@ -30,12 +30,6 @@ const json = { ] } -const expect = [ - 'package.json', - '__bin', - 'lib/elf.js' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -66,7 +60,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', t => { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/package-json-empty.js b/test/package-json-empty.js index 36ebc88..c5dc372 100644 --- a/test/package-json-empty.js +++ b/test/package-json-empty.js @@ -23,11 +23,6 @@ const json = { 'files': [] } -const expect = [ - 'package.json', - 'elf.js' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -100,7 +95,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/package-json-main.js b/test/package-json-main.js index 8bd9b40..bacb2d2 100644 --- a/test/package-json-main.js +++ b/test/package-json-main.js @@ -27,14 +27,6 @@ const json = { ] } -const expect = [ - 'package.json', - '__main.js', - 'browser.js', - 'elf.js', - 'deps/foo/config/config.gypi', -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -112,7 +104,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/package-json-nested.js b/test/package-json-nested.js index dc925af..88f8df9 100644 --- a/test/package-json-nested.js +++ b/test/package-json-nested.js @@ -28,13 +28,8 @@ t.test('setup', t => { }) t.test('includes nested package.json file', function (t) { - const expect = [ - 'package.json', - 'nest/index.js', - 'nest/package.json', - ] const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/package-json.js b/test/package-json.js index 864cd70..1293139 100644 --- a/test/package-json.js +++ b/test/package-json.js @@ -25,12 +25,6 @@ const json = { ] } -const expect = [ - 'package.json', - 'elf.js', - 'deps/foo/config/config.gypi' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -98,7 +92,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/package-not-json.js b/test/package-not-json.js index 17a0aed..7fda676 100644 --- a/test/package-not-json.js +++ b/test/package-not-json.js @@ -22,12 +22,6 @@ const json = { 'main': 'elf.js' } -const expect = [ - 'package.json', - 'elf.js', - 'deps/foo/config/config.gypi' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -94,7 +88,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/scoped.js b/test/scoped.js index de9cb05..a2f14f4 100644 --- a/test/scoped.js +++ b/test/scoped.js @@ -63,15 +63,9 @@ t.test('setup', t => { t.end() }) -const expect = [ - 'package.json', - 'elf.js', - path.join('node_modules', '@npmwombat', 'scoped', 'index.js') -] - t.test('includes bundledDependencies', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() } diff --git a/test/sorting.js b/test/sorting.js index f7f04c8..cbae877 100644 --- a/test/sorting.js +++ b/test/sorting.js @@ -3,11 +3,7 @@ const t = require('tap') const Walker = require('../').Walker const sort = Walker.prototype.sort -// package.json always comes first -// then files in the root, sorted alphabetically -// then folders other than node_modules sorted alphabetically -// then the deps in the back -t.same([ +t.matchSnapshot([ 'a/b/1', 'package.json', 'node_modules/b/c', @@ -15,12 +11,4 @@ t.same([ 'node_modules/a/b/c', 'a/b/c/d/e/f/g', 'a/b/x/y' -].sort(sort), [ - 'package.json', - 'asdf.js', - 'a/b/1', - 'a/b/c/d/e/f/g', - 'a/b/x/y', - 'node_modules/a/b/c', - 'node_modules/b/c' -]) +].sort(sort)) diff --git a/test/symlink.js b/test/symlink.js index 81ce373..8c07045 100644 --- a/test/symlink.js +++ b/test/symlink.js @@ -22,12 +22,6 @@ const json = { 'main': 'elf.js' } -const expect = [ - 'package.json', - 'elf.js', - 'deps/foo/config/config.gypi' -] - t.test('setup', t => { rimraf.sync(pkg) mkdirp.sync(pkg) @@ -103,7 +97,7 @@ t.test('setup', t => { t.test('follows npm package ignoring rules', function (t) { const check = (files, t) => { - t.same(files, expect) + t.matchSnapshot(files) t.end() }