libnpmdiff 2.0.0 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.3
4
+
5
+ - fix name of options sent by the npm cli
6
+
7
+ ## 2.0.2
8
+
9
+ - fix matching basename file filter
10
+
11
+ ## 2.0.1
12
+
13
+ - fix for tarballs not listing folder names
14
+
15
+ ## 2.0.0
16
+
17
+ - API rewrite:
18
+ - normalized all options
19
+ - specs to compare are now an array
20
+ - fix context=0
21
+ - added support to filtering by folder names
22
+
3
23
  ## 1.0.1
4
24
 
5
25
  - fixed nameOnly option
package/README.md CHANGED
@@ -78,15 +78,15 @@ Fetches the registry tarballs and compare files between a spec `a` and spec `b`.
78
78
 
79
79
  - `color <Boolean>`: Should add ANSI colors to string output? Defaults to `false`.
80
80
  - `tagVersionPrefix <Sring>`: What prefix should be used to define version numbers. Defaults to `v`
81
- - `diffContext <Number>`: How many lines of code to print before/after each diff. Defaults to `3`.
81
+ - `diffUnified <Number>`: How many lines of code to print before/after each diff. Defaults to `3`.
82
82
  - `diffFiles <Array<String>>`: If set only prints patches for the files listed in this array (also accepts globs). Defaults to `undefined`.
83
- - `diffIgnoreWhitespace <Boolean>`: Whether or not should ignore changes in whitespace (very useful to avoid indentation changes extra diff lines). Defaults to `false`.
83
+ - `diffIgnoreAllSpace <Boolean>`: Whether or not should ignore changes in whitespace (very useful to avoid indentation changes extra diff lines). Defaults to `false`.
84
84
  - `diffNameOnly <Boolean>`: Prints only file names and no patch diffs. Defaults to `false`.
85
85
  - `diffNoPrefix <Boolean>`: If true then skips printing any prefixes in filenames. Defaults to `false`.
86
86
  - `diffSrcPrefix <String>`: Prefix to be used in the filenames from `a`. Defaults to `a/`.
87
87
  - `diffDstPrefix <String>`: Prefix to be used in the filenames from `b`. Defaults to `b/`.
88
88
  - `diffText <Boolean>`: Should treat all files as text and try to print diff for binary files. Defaults to `false`.
89
- - ...`cache`, `registry` and other common options accepted by [pacote](https://github.com/npm/pacote#options)
89
+ - ...`cache`, `registry`, `where` and other common options accepted by [pacote](https://github.com/npm/pacote#options)
90
90
 
91
91
  Returns a `Promise` that fullfils with a `String` containing the resulting patch diffs.
92
92
 
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const pacote = require('pacote')
2
2
 
3
3
  const formatDiff = require('./lib/format-diff.js')
4
+ const getTarball = require('./lib/tarball.js')
4
5
  const untar = require('./lib/untar.js')
5
6
 
6
7
  const argsError = () =>
@@ -25,8 +26,8 @@ const diff = async (specs, opts = {}) => {
25
26
 
26
27
  // fetches tarball using pacote
27
28
  const [a, b] = await Promise.all([
28
- pacote.tarball(aManifest._resolved, opts),
29
- pacote.tarball(bManifest._resolved, opts),
29
+ getTarball(aManifest, opts),
30
+ getTarball(bManifest, opts),
30
31
  ])
31
32
 
32
33
  // read all files
@@ -70,8 +70,8 @@ const formatDiff = ({ files, opts = {}, refs, versions }) => {
70
70
  '',
71
71
  '',
72
72
  {
73
- context: opts.diffContext === 0 ? 0 : opts.diffContext || 3,
74
- ignoreWhitespace: opts.diffIgnoreWhitespace,
73
+ context: opts.diffUnified === 0 ? 0 : opts.diffUnified || 3,
74
+ ignoreWhitespace: opts.diffIgnoreAllSpace,
75
75
  }
76
76
  ).replace(
77
77
  '===================================================================\n',
package/lib/tarball.js ADDED
@@ -0,0 +1,33 @@
1
+ const { relative } = require('path')
2
+
3
+ const npa = require('npm-package-arg')
4
+ const pkgContents = require('@npmcli/installed-package-contents')
5
+ const pacote = require('pacote')
6
+ const { tarCreateOptions } = pacote.DirFetcher
7
+ const tar = require('tar')
8
+
9
+ // returns a simplified tarball when reading files from node_modules folder,
10
+ // thus avoiding running the prepare scripts and the extra logic from packlist
11
+ const nodeModulesTarball = (manifest, opts) =>
12
+ pkgContents({ path: manifest._resolved, depth: 1 })
13
+ .then(files =>
14
+ files.map(file => relative(manifest._resolved, file))
15
+ )
16
+ .then(files =>
17
+ tar.c(tarCreateOptions(manifest), files).concat()
18
+ )
19
+
20
+ const tarball = (manifest, opts) => {
21
+ const resolved = manifest._resolved
22
+ const where = opts.where || process.cwd()
23
+
24
+ const fromNodeModules = npa(resolved).type === 'directory'
25
+ && /node_modules[\\/](@[^\\/]+\/)?[^\\/]+[\\/]?$/.test(relative(where, resolved))
26
+
27
+ if (fromNodeModules)
28
+ return nodeModulesTarball(manifest, opts)
29
+
30
+ return pacote.tarball(manifest._resolved, opts)
31
+ }
32
+
33
+ module.exports = tarball
package/lib/untar.js CHANGED
@@ -12,12 +12,14 @@ const untar = ({ files, refs }, { filterFiles, item, prefix }) => {
12
12
  filter: (path, entry) => {
13
13
  const fileMatch = () =>
14
14
  (!filterFiles.length ||
15
- filterFiles.some(f =>
16
- minimatch(
15
+ filterFiles.some(f => {
16
+ const pattern = normalizeMatch(f)
17
+ return minimatch(
17
18
  normalizeMatch(path),
18
- `{package/,}${normalizeMatch(f)}`,
19
- { matchBase: true }
20
- )))
19
+ `{package/,}${pattern}`,
20
+ { matchBase: pattern.startsWith('*') }
21
+ )
22
+ }))
21
23
 
22
24
  // expands usage of simple path filters, e.g: lib or src/
23
25
  const folderMatch = () =>
@@ -25,19 +27,9 @@ const untar = ({ files, refs }, { filterFiles, item, prefix }) => {
25
27
  normalizeMatch(path).startsWith(normalizeMatch(f)) ||
26
28
  normalizeMatch(path).startsWith(`package/${normalizeMatch(f)}`))
27
29
 
28
- if (
29
- filterFiles.length &&
30
- entry.type === 'Directory' &&
31
- folderMatch()
32
- ) {
33
- // if simple folder was found, add that as a glob to list of filters
34
- filterFiles.push(`${path}**`)
35
- return false
36
- }
37
-
38
30
  if (
39
31
  entry.type === 'File' &&
40
- fileMatch()
32
+ (fileMatch() || folderMatch())
41
33
  ) {
42
34
  const key = path.replace(/^[^/]+\/?/, '')
43
35
  files.add(key)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libnpmdiff",
3
- "version": "2.0.0",
3
+ "version": "2.0.4",
4
4
  "description": "The registry diff",
5
5
  "repository": "https://github.com/npm/libnpmdiff",
6
6
  "files": [
@@ -55,10 +55,12 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@npmcli/disparity-colors": "^1.0.1",
58
+ "@npmcli/installed-package-contents": "^1.0.7",
58
59
  "binary-extensions": "^2.2.0",
59
60
  "diff": "^5.0.0",
60
61
  "minimatch": "^3.0.4",
61
- "pacote": "^11.2.3",
62
+ "npm-package-arg": "^8.1.1",
63
+ "pacote": "^11.3.0",
62
64
  "tar": "^6.1.0"
63
65
  }
64
66
  }