From a6a826067cb46c711521772c2d0158257d54400a Mon Sep 17 00:00:00 2001 From: Gar Date: Fri, 7 May 2021 10:10:54 -0700 Subject: [PATCH] npm-packlist@2.2.2 * fix(sort): avoid locale-dependent sorting issues --- node_modules/npm-packlist/bin/index.js | 5 +-- node_modules/npm-packlist/index.js | 44 +++++++++++--------------- node_modules/npm-packlist/package.json | 17 ++++++++-- package-lock.json | 12 +++---- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/node_modules/npm-packlist/bin/index.js b/node_modules/npm-packlist/bin/index.js index f06feffd9b55a..40811db7d32e7 100755 --- a/node_modules/npm-packlist/bin/index.js +++ b/node_modules/npm-packlist/bin/index.js @@ -12,13 +12,14 @@ process.argv.slice(2).forEach(arg => { dirs.push(arg) }) -const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b)) : list +const sort = list => doSort ? list.sort((a, b) => a.localeCompare(b, 'en')) : list const packlist = require('../') if (!dirs.length) console.log(sort(packlist.sync({ path: process.cwd() })).join('\n')) -else +else { dirs.forEach(path => { console.log(`> ${path}`) console.log(sort(packlist.sync({ path })).join('\n')) }) +} diff --git a/node_modules/npm-packlist/index.js b/node_modules/npm-packlist/index.js index 12b51316c5e27..f498fa008ceca 100644 --- a/node_modules/npm-packlist/index.js +++ b/node_modules/npm-packlist/index.js @@ -29,7 +29,7 @@ const normalizePackageBin = require('npm-normalize-package-bin') const packageMustHaveFileNames = 'readme|copying|license|licence' const packageMustHaves = `@(${packageMustHaveFileNames}){,.*[^~$]}` -const packageMustHavesRE = new RegExp(`^(${packageMustHaveFileNames})(\\..*[^~\$])?$`, 'i') +const packageMustHavesRE = new RegExp(`^(${packageMustHaveFileNames})(\\..*[^~$])?$`, 'i') const fs = require('fs') const glob = require('glob') @@ -75,13 +75,11 @@ const npmWalker = Class => class Walker extends Class { 'package.json', '.npmignore', '.gitignore', - packageNecessaryRules + packageNecessaryRules, ] opt.includeEmpty = false opt.path = opt.path || process.cwd() - const dirName = path.basename(opt.path) - const parentName = path.basename(path.dirname(opt.path)) // only follow links in the root node_modules folder, because if those // folders are included, it's because they're bundled, and bundles @@ -89,7 +87,7 @@ const npmWalker = Class => class Walker extends Class { // This regexp tests to see that we're either a node_modules folder, // or a @scope within a node_modules folder, in the root's node_modules // hierarchy (ie, not in test/foo/node_modules/ or something). - const followRe = /^(?:\/node_modules\/(?:@[^\/]+\/[^\/]+|[^\/]+)\/)*\/node_modules(?:\/@[^\/]+)?$/ + const followRe = /^(?:\/node_modules\/(?:@[^/]+\/[^/]+|[^/]+)\/)*\/node_modules(?:\/@[^/]+)?$/ const rootPath = opt.parent ? opt.parent.root : opt.path const followTestPath = opt.path.replace(/\\/g, '/').substr(rootPath.length) opt.follow = followRe.test(followTestPath) @@ -103,10 +101,10 @@ const npmWalker = Class => class Walker extends Class { this.bundled = opt.bundled || [] this.bundledScopes = Array.from(new Set( this.bundled.filter(f => /^@/.test(f)) - .map(f => f.split('/')[0]))) + .map(f => f.split('/')[0]))) const rules = defaultRules.join('\n') + '\n' this.packageJsonCache = opt.packageJsonCache || new Map() - super.onReadIgnoreFile(rootBuiltinRules, rules, _=>_) + super.onReadIgnoreFile(rootBuiltinRules, rules, _ => _) } else { this.bundled = [] this.bundledScopes = [] @@ -128,9 +126,8 @@ const npmWalker = Class => class Walker extends Class { // to be in the state the user wants to include them, and // a package.json somewhere else might be a template or // test or something else entirely. - if (this.parent || !entries.includes('package.json')) { + if (this.parent || !entries.includes('package.json')) return super.onReaddir(entries) - } // when the cache has been seeded with the root manifest, // we must respect that (it may differ from the filesystem) @@ -140,9 +137,8 @@ const npmWalker = Class => class Walker extends Class { const pkg = this.packageJsonCache.get(ig) // fall back to filesystem when seeded manifest is invalid - if (!pkg || typeof pkg !== 'object') { + if (!pkg || typeof pkg !== 'object') return this.readPackageJson(entries) - } // feels wonky, but this ensures package bin is _always_ // normalized, as well as guarding against invalid JSON @@ -174,7 +170,7 @@ const npmWalker = Class => class Walker extends Class { '/package.json', '/npm-shrinkwrap.json', '!/package-lock.json', - packageMustHaves, + packageMustHaves ) return files } @@ -232,9 +228,8 @@ const npmWalker = Class => class Walker extends Class { return this.emit('error', er) results[i] = { negate, fileList } - if (--n === 0) { + if (--n === 0) processResults(results) - } } const processResults = results => { for (const {negate, fileList} of results) { @@ -272,7 +267,7 @@ const npmWalker = Class => class Walker extends Class { filterEntry (entry, partial) { // get the partial path from the root of the walk const p = this.path.substr(this.root.length + 1) - const pkgre = /^node_modules\/(@[^\/]+\/?[^\/]+|[^\/]+)(\/.*)?$/ + const pkgre = /^node_modules\/(@[^/]+\/?[^/]+|[^/]+)(\/.*)?$/ const isRoot = !this.parent const pkg = isRoot && pkgre.test(entry) ? entry.replace(pkgre, '$1') : null @@ -282,7 +277,7 @@ const npmWalker = Class => class Walker extends Class { return ( // if we're in a bundled package, check with the parent. /^node_modules($|\/)/i.test(p) ? this.parent.filterEntry( - this.basename + '/' + entry, partial) + this.basename + '/' + entry, partial) // if package is bundled, all files included // also include @scope dirs for bundled scoped deps @@ -290,8 +285,8 @@ const npmWalker = Class => class Walker extends Class { // However, this only matters if we're in the root. // node_modules folders elsewhere, like lib/node_modules, // should be included normally unless ignored. - : pkg ? -1 !== this.bundled.indexOf(pkg) || - -1 !== this.bundledScopes.indexOf(pkg) + : pkg ? this.bundled.indexOf(pkg) !== -1 || + this.bundledScopes.indexOf(pkg) !== -1 // only walk top node_modules if we want to bundle something : rootNM ? !!this.bundled.length @@ -307,10 +302,10 @@ const npmWalker = Class => class Walker extends Class { ? true // package-lock never included - : isRoot && entry === 'package-lock.json' ? false + : isRoot && entry === 'package-lock.json' ? false - // otherwise, follow ignore-walk's logic - : super.filterEntry(entry, partial) + // otherwise, follow ignore-walk's logic + : super.filterEntry(entry, partial) ) } @@ -453,12 +448,11 @@ const sort = (a, b) => { const basea = path.basename(a).toLowerCase() const baseb = path.basename(b).toLowerCase() - return exta.localeCompare(extb) || - basea.localeCompare(baseb) || - a.localeCompare(b) + return exta.localeCompare(extb, 'en') || + basea.localeCompare(baseb, 'en') || + a.localeCompare(b, 'en') } - module.exports = walk walk.sync = walkSync walk.Walker = Walker diff --git a/node_modules/npm-packlist/package.json b/node_modules/npm-packlist/package.json index e909559bdb204..49fa947547b6c 100644 --- a/node_modules/npm-packlist/package.json +++ b/node_modules/npm-packlist/package.json @@ -1,6 +1,6 @@ { "name": "npm-packlist", - "version": "2.2.0", + "version": "2.2.2", "description": "Get a list of the files to add from a folder into an npm package", "directories": { "test": "test" @@ -19,21 +19,34 @@ "index.js" ], "devDependencies": { + "eslint": "^7.25.0", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-promise": "^5.1.0", + "eslint-plugin-standard": "^5.0.0", "mutate-fs": "^2.1.1", "tap": "^15.0.6" }, "scripts": { "test": "tap", + "posttest": "npm run lint", "snap": "tap", + "postsnap": "npm run lintfix", "preversion": "npm test", "postversion": "npm publish", - "prepublishOnly": "git push origin --follow-tags" + "prepublishOnly": "git push origin --follow-tags", + "eslint": "eslint", + "lint": "npm run eslint -- index.js bin/index.js \"test/**/*.js\"", + "lintfix": "npm run lint -- --fix" }, "repository": { "type": "git", "url": "git+https://github.com/npm/npm-packlist.git" }, "tap": { + "test-env": [ + "LC_ALL=sk" + ], "check-coverage": true, "nyc-arg": [ "--include=index.js", diff --git a/package-lock.json b/package-lock.json index 2982c23c6c915..1ba3005b2bc3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5428,9 +5428,9 @@ } }, "node_modules/npm-packlist": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-2.2.0.tgz", - "integrity": "sha512-d3da2MEaYliq7h+PNOHqUhlQjRm0M6gNPi6yHsZYzsCj6bLqUTWCC+JMzW/u9Aaxu8i4F1AA0eJUPUSoFU5izA==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-2.2.2.tgz", + "integrity": "sha512-Jt01acDvJRhJGthnUJVF/w6gumWOZxO7IkpY/lsX9//zqQgnF7OJaxgQXcerd4uQOLu7W5bkb4mChL9mdfm+Zg==", "inBundle": true, "dependencies": { "glob": "^7.1.6", @@ -14293,9 +14293,9 @@ } }, "npm-packlist": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-2.2.0.tgz", - "integrity": "sha512-d3da2MEaYliq7h+PNOHqUhlQjRm0M6gNPi6yHsZYzsCj6bLqUTWCC+JMzW/u9Aaxu8i4F1AA0eJUPUSoFU5izA==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-2.2.2.tgz", + "integrity": "sha512-Jt01acDvJRhJGthnUJVF/w6gumWOZxO7IkpY/lsX9//zqQgnF7OJaxgQXcerd4uQOLu7W5bkb4mChL9mdfm+Zg==", "requires": { "glob": "^7.1.6", "ignore-walk": "^3.0.3",