diff --git a/node_modules/libnpmdiff/README.md b/node_modules/libnpmdiff/README.md index d1cf53fc6c5c7..bc260ad15ce12 100644 --- a/node_modules/libnpmdiff/README.md +++ b/node_modules/libnpmdiff/README.md @@ -86,7 +86,7 @@ Fetches the registry tarballs and compare files between a spec `a` and spec `b`. - `diffSrcPrefix `: Prefix to be used in the filenames from `a`. Defaults to `a/`. - `diffDstPrefix `: Prefix to be used in the filenames from `b`. Defaults to `b/`. - `diffText `: Should treat all files as text and try to print diff for binary files. Defaults to `false`. -- ...`cache`, `registry` and other common options accepted by [pacote](https://github.com/npm/pacote#options) +- ...`cache`, `registry`, `where` and other common options accepted by [pacote](https://github.com/npm/pacote#options) Returns a `Promise` that fullfils with a `String` containing the resulting patch diffs. diff --git a/node_modules/libnpmdiff/index.js b/node_modules/libnpmdiff/index.js index 0bfc8734ef639..73dc3ee64e3ce 100644 --- a/node_modules/libnpmdiff/index.js +++ b/node_modules/libnpmdiff/index.js @@ -1,6 +1,7 @@ const pacote = require('pacote') const formatDiff = require('./lib/format-diff.js') +const getTarball = require('./lib/tarball.js') const untar = require('./lib/untar.js') const argsError = () => @@ -25,8 +26,8 @@ const diff = async (specs, opts = {}) => { // fetches tarball using pacote const [a, b] = await Promise.all([ - pacote.tarball(aManifest._resolved, opts), - pacote.tarball(bManifest._resolved, opts), + getTarball(aManifest, opts), + getTarball(bManifest, opts), ]) // read all files diff --git a/node_modules/libnpmdiff/lib/tarball.js b/node_modules/libnpmdiff/lib/tarball.js new file mode 100644 index 0000000000000..0c8fb177a3885 --- /dev/null +++ b/node_modules/libnpmdiff/lib/tarball.js @@ -0,0 +1,33 @@ +const { relative } = require('path') + +const npa = require('npm-package-arg') +const pkgContents = require('@npmcli/installed-package-contents') +const pacote = require('pacote') +const { tarCreateOptions } = pacote.DirFetcher +const tar = require('tar') + +// returns a simplified tarball when reading files from node_modules folder, +// thus avoiding running the prepare scripts and the extra logic from packlist +const nodeModulesTarball = (manifest, opts) => + pkgContents({ path: manifest._resolved, depth: 1 }) + .then(files => + files.map(file => relative(manifest._resolved, file)) + ) + .then(files => + tar.c(tarCreateOptions(manifest), files).concat() + ) + +const tarball = (manifest, opts) => { + const resolved = manifest._resolved + const where = opts.where || process.cwd() + + const fromNodeModules = npa(resolved).type === 'directory' + && /node_modules[\\/](@[^\\/]+\/)?[^\\/]+[\\/]?$/.test(relative(where, resolved)) + + if (fromNodeModules) + return nodeModulesTarball(manifest, opts) + + return pacote.tarball(manifest._resolved, opts) +} + +module.exports = tarball diff --git a/node_modules/libnpmdiff/package.json b/node_modules/libnpmdiff/package.json index fab4293e9374e..aa13954c63010 100644 --- a/node_modules/libnpmdiff/package.json +++ b/node_modules/libnpmdiff/package.json @@ -1,6 +1,6 @@ { "name": "libnpmdiff", - "version": "2.0.3", + "version": "2.0.4", "description": "The registry diff", "repository": "https://github.com/npm/libnpmdiff", "files": [ @@ -55,10 +55,12 @@ }, "dependencies": { "@npmcli/disparity-colors": "^1.0.1", + "@npmcli/installed-package-contents": "^1.0.7", "binary-extensions": "^2.2.0", "diff": "^5.0.0", "minimatch": "^3.0.4", - "pacote": "^11.2.3", + "npm-package-arg": "^8.1.1", + "pacote": "^11.3.0", "tar": "^6.1.0" } } diff --git a/node_modules/pacote/README.md b/node_modules/pacote/README.md index 619e0ec44e8f6..2328c0a4a55dc 100644 --- a/node_modules/pacote/README.md +++ b/node_modules/pacote/README.md @@ -168,6 +168,18 @@ resolved, and other properties, as they are determined. times (even just to validate the cache) for a given packument, since it is unlikely to change in the span of a single command. + +### Advanced API + +Each different type of fetcher is exposed for more advanced usage such as +using helper methods from this classes: + +* `DirFetcher` +* `FileFetcher` +* `GitFetcher` +* `RegistryFetcher` +* `RemoteFetcher` + ## Extracted File Modes Files are extracted with a mode matching the following formula: diff --git a/node_modules/pacote/lib/dir.js b/node_modules/pacote/lib/dir.js index 4a89348b9290c..0d3a00d95ae7c 100644 --- a/node_modules/pacote/lib/dir.js +++ b/node_modules/pacote/lib/dir.js @@ -4,11 +4,10 @@ const cacache = require('cacache') const Minipass = require('minipass') const { promisify } = require('util') const readPackageJson = require('read-package-json-fast') -const isPackageBin = require('./util/is-package-bin.js') +const tarCreateOptions = require('./util/tar-create-options.js') const packlist = require('npm-packlist') const tar = require('tar') const _prepareDir = Symbol('_prepareDir') -const _tarcOpts = Symbol('_tarcOpts') const { resolve } = require('path') const runScript = require('@npmcli/run-script') @@ -21,6 +20,11 @@ class DirFetcher extends Fetcher { this.resolved = this.spec.fetchSpec } + // exposes tarCreateOptions as public API + static tarCreateOptions (manifest) { + return tarCreateOptions(manifest) + } + get types () { return ['directory'] } @@ -65,35 +69,12 @@ class DirFetcher extends Fetcher { // pipe to the stream, and proxy errors the chain. this[_prepareDir]() .then(() => packlist({ path: this.resolved })) - .then(files => tar.c(this[_tarcOpts](), files) + .then(files => tar.c(tarCreateOptions(this.package), files) .on('error', er => stream.emit('error', er)).pipe(stream)) .catch(er => stream.emit('error', er)) return stream } - [_tarcOpts] () { - return { - cwd: this.resolved, - prefix: 'package/', - portable: true, - gzip: true, - - // ensure that package bins are always executable - // Note that npm-packlist is already filtering out - // anything that is not a regular file, ignored by - // .npmignore or package.json "files", etc. - filter: (path, stat) => { - if (isPackageBin(this.package, path)) - stat.mode |= 0o111 - return true - }, - - // Provide a specific date in the 1980s for the benefit of zip, - // which is confounded by files dated at the Unix epoch 0. - mtime: new Date('1985-10-26T08:15:00.000Z'), - } - } - manifest () { if (this.package) return Promise.resolve(this.package) diff --git a/node_modules/pacote/lib/index.js b/node_modules/pacote/lib/index.js index 546ba960baa2e..cbcbd7c92d15f 100644 --- a/node_modules/pacote/lib/index.js +++ b/node_modules/pacote/lib/index.js @@ -1,5 +1,16 @@ const { get } = require('./fetcher.js') +const GitFetcher = require('./git.js') +const RegistryFetcher = require('./registry.js') +const FileFetcher = require('./file.js') +const DirFetcher = require('./dir.js') +const RemoteFetcher = require('./remote.js') + module.exports = { + GitFetcher, + RegistryFetcher, + FileFetcher, + DirFetcher, + RemoteFetcher, resolve: (spec, opts) => get(spec, opts).resolve(), extract: (spec, dest, opts) => get(spec, opts).extract(dest), manifest: (spec, opts) => get(spec, opts).manifest(), diff --git a/node_modules/pacote/lib/util/tar-create-options.js b/node_modules/pacote/lib/util/tar-create-options.js new file mode 100644 index 0000000000000..e8abbe175b262 --- /dev/null +++ b/node_modules/pacote/lib/util/tar-create-options.js @@ -0,0 +1,24 @@ +const isPackageBin = require('./is-package-bin.js') + +const tarCreateOptions = manifest => ({ + cwd: manifest._resolved, + prefix: 'package/', + portable: true, + gzip: true, + + // ensure that package bins are always executable + // Note that npm-packlist is already filtering out + // anything that is not a regular file, ignored by + // .npmignore or package.json "files", etc. + filter: (path, stat) => { + if (isPackageBin(manifest, path)) + stat.mode |= 0o111 + return true + }, + + // Provide a specific date in the 1980s for the benefit of zip, + // which is confounded by files dated at the Unix epoch 0. + mtime: new Date('1985-10-26T08:15:00.000Z'), +}) + +module.exports = tarCreateOptions diff --git a/node_modules/pacote/package.json b/node_modules/pacote/package.json index a1668056f9794..dca67f3e8876a 100644 --- a/node_modules/pacote/package.json +++ b/node_modules/pacote/package.json @@ -1,6 +1,6 @@ { "name": "pacote", - "version": "11.2.7", + "version": "11.3.0", "description": "JavaScript package downloader", "author": "Isaac Z. Schlueter (https://izs.me)", "bin": { diff --git a/package-lock.json b/package-lock.json index 5c5793bf8f0df..bcd020f250643 100644 --- a/package-lock.json +++ b/package-lock.json @@ -275,7 +275,7 @@ "json-parse-even-better-errors": "^2.3.1", "leven": "^3.1.0", "libnpmaccess": "^4.0.1", - "libnpmdiff": "^2.0.3", + "libnpmdiff": "^2.0.4", "libnpmfund": "^1.0.2", "libnpmhook": "^6.0.1", "libnpmorg": "^2.0.1", @@ -4767,16 +4767,18 @@ } }, "node_modules/libnpmdiff": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/libnpmdiff/-/libnpmdiff-2.0.3.tgz", - "integrity": "sha512-BgVvJCjd+EGY3Ifb3+gWkZwMjn6kYMtruT88XXOrJCWyjnG5aRdFv3lKuJx5JdU5ku08G5LlY8tOZdfRn72m7w==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/libnpmdiff/-/libnpmdiff-2.0.4.tgz", + "integrity": "sha512-q3zWePOJLHwsLEUjZw3Kyu/MJMYfl4tWCg78Vl6QGSfm4aXBUSVzMzjJ6jGiyarsT4d+1NH4B1gxfs62/+y9iQ==", "inBundle": true, "dependencies": { "@npmcli/disparity-colors": "^1.0.1", + "@npmcli/installed-package-contents": "^1.0.7", "binary-extensions": "^2.2.0", "diff": "^5.0.0", "minimatch": "^3.0.4", - "pacote": "^11.2.3", + "npm-package-arg": "^8.1.1", + "pacote": "^11.3.0", "tar": "^6.1.0" }, "engines": { @@ -5971,9 +5973,9 @@ } }, "node_modules/pacote": { - "version": "11.2.7", - "resolved": "https://registry.npmjs.org/pacote/-/pacote-11.2.7.tgz", - "integrity": "sha512-ogxPor11v/rnU9ukwLlI2dPx22q9iob1+yZyqSwerKsOvBMhU9e+SJHtxY4y2N0MRH4/5jGsGiRLsZeJWyM4dQ==", + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/pacote/-/pacote-11.3.0.tgz", + "integrity": "sha512-cygprcGpEVqvDzpuPMkGVXW/ooc2ibpoosuJ4YHcUXozDs9VJP7Vha+41pYppG2MVNis4t1BB8IygIBh7vVr2Q==", "inBundle": true, "dependencies": { "@npmcli/git": "^2.0.1", @@ -13898,15 +13900,17 @@ } }, "libnpmdiff": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/libnpmdiff/-/libnpmdiff-2.0.3.tgz", - "integrity": "sha512-BgVvJCjd+EGY3Ifb3+gWkZwMjn6kYMtruT88XXOrJCWyjnG5aRdFv3lKuJx5JdU5ku08G5LlY8tOZdfRn72m7w==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/libnpmdiff/-/libnpmdiff-2.0.4.tgz", + "integrity": "sha512-q3zWePOJLHwsLEUjZw3Kyu/MJMYfl4tWCg78Vl6QGSfm4aXBUSVzMzjJ6jGiyarsT4d+1NH4B1gxfs62/+y9iQ==", "requires": { "@npmcli/disparity-colors": "^1.0.1", + "@npmcli/installed-package-contents": "^1.0.7", "binary-extensions": "^2.2.0", "diff": "^5.0.0", "minimatch": "^3.0.4", - "pacote": "^11.2.3", + "npm-package-arg": "^8.1.1", + "pacote": "^11.3.0", "tar": "^6.1.0" } }, @@ -14801,9 +14805,9 @@ } }, "pacote": { - "version": "11.2.7", - "resolved": "https://registry.npmjs.org/pacote/-/pacote-11.2.7.tgz", - "integrity": "sha512-ogxPor11v/rnU9ukwLlI2dPx22q9iob1+yZyqSwerKsOvBMhU9e+SJHtxY4y2N0MRH4/5jGsGiRLsZeJWyM4dQ==", + "version": "11.3.0", + "resolved": "https://registry.npmjs.org/pacote/-/pacote-11.3.0.tgz", + "integrity": "sha512-cygprcGpEVqvDzpuPMkGVXW/ooc2ibpoosuJ4YHcUXozDs9VJP7Vha+41pYppG2MVNis4t1BB8IygIBh7vVr2Q==", "requires": { "@npmcli/git": "^2.0.1", "@npmcli/installed-package-contents": "^1.0.6", diff --git a/package.json b/package.json index 024405fee6e1c..9c8fac16ad22a 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "json-parse-even-better-errors": "^2.3.1", "leven": "^3.1.0", "libnpmaccess": "^4.0.1", - "libnpmdiff": "^2.0.3", + "libnpmdiff": "^2.0.4", "libnpmfund": "^1.0.2", "libnpmhook": "^6.0.1", "libnpmorg": "^2.0.1",