libnpmdiff 2.0.1 → 3.0.0
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/README.md +4 -4
- package/lib/format-diff.js +10 -8
- package/{index.js → lib/index.js} +12 -6
- package/lib/should-print-patch.js +2 -1
- package/lib/tarball.js +34 -0
- package/lib/untar.js +7 -5
- package/package.json +17 -19
- package/CHANGELOG.md +0 -22
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ hesitate to jump in if you'd like to, or even ask us questions if something
|
|
|
61
61
|
isn't clear.
|
|
62
62
|
|
|
63
63
|
All participants and maintainers in this project are expected to follow the
|
|
64
|
-
[npm Code of Conduct](https://
|
|
64
|
+
[npm Code of Conduct](https://docs.npmjs.com/policies/conduct), and just
|
|
65
65
|
generally be excellent to each other.
|
|
66
66
|
|
|
67
67
|
Please refer to the [Changelog](CHANGELOG.md) for project history details, too.
|
|
@@ -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
|
-
- `
|
|
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
|
-
- `
|
|
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/lib/format-diff.js
CHANGED
|
@@ -30,8 +30,9 @@ const formatDiff = ({ files, opts = {}, refs, versions }) => {
|
|
|
30
30
|
b: filenames.b && filenames.b.mode,
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
if (contents.a === contents.b && modes.a === modes.b)
|
|
33
|
+
if (contents.a === contents.b && modes.a === modes.b) {
|
|
34
34
|
continue
|
|
35
|
+
}
|
|
35
36
|
|
|
36
37
|
if (opts.diffNameOnly) {
|
|
37
38
|
res += `${filename}${EOL}`
|
|
@@ -47,18 +48,19 @@ const formatDiff = ({ files, opts = {}, refs, versions }) => {
|
|
|
47
48
|
|
|
48
49
|
// manually build a git diff-compatible header
|
|
49
50
|
header(`diff --git ${names.a} ${names.b}`)
|
|
50
|
-
if (modes.a === modes.b)
|
|
51
|
+
if (modes.a === modes.b) {
|
|
51
52
|
fileMode = filenames.a.mode
|
|
52
|
-
else {
|
|
53
|
-
if (modes.a && !modes.b)
|
|
53
|
+
} else {
|
|
54
|
+
if (modes.a && !modes.b) {
|
|
54
55
|
header(`deleted file mode ${modes.a}`)
|
|
55
|
-
else if (!modes.a && modes.b)
|
|
56
|
+
} else if (!modes.a && modes.b) {
|
|
56
57
|
header(`new file mode ${modes.b}`)
|
|
57
|
-
else {
|
|
58
|
+
} else {
|
|
58
59
|
header(`old mode ${modes.a}`)
|
|
59
60
|
header(`new mode ${modes.b}`)
|
|
60
61
|
}
|
|
61
62
|
}
|
|
63
|
+
/* eslint-disable-next-line max-len */
|
|
62
64
|
header(`index ${opts.tagVersionPrefix || 'v'}${versions.a}..${opts.tagVersionPrefix || 'v'}${versions.b} ${fileMode}`)
|
|
63
65
|
|
|
64
66
|
if (shouldPrintPatch(filename)) {
|
|
@@ -70,8 +72,8 @@ const formatDiff = ({ files, opts = {}, refs, versions }) => {
|
|
|
70
72
|
'',
|
|
71
73
|
'',
|
|
72
74
|
{
|
|
73
|
-
context: opts.
|
|
74
|
-
ignoreWhitespace: opts.
|
|
75
|
+
context: opts.diffUnified === 0 ? 0 : opts.diffUnified || 3,
|
|
76
|
+
ignoreWhitespace: opts.diffIgnoreAllSpace,
|
|
75
77
|
}
|
|
76
78
|
).replace(
|
|
77
79
|
'===================================================================\n',
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
const pacote = require('pacote')
|
|
2
2
|
|
|
3
|
-
const formatDiff = require('./
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
const formatDiff = require('./format-diff.js')
|
|
4
|
+
const getTarball = require('./tarball.js')
|
|
5
|
+
const untar = require('./untar.js')
|
|
6
|
+
|
|
7
|
+
// TODO: we test this condition in the diff command
|
|
8
|
+
// so this error probably doesnt need to be here. Or
|
|
9
|
+
// if it does we should figure out a standard code
|
|
10
|
+
// so we can catch it in the cli and display it consistently
|
|
6
11
|
const argsError = () =>
|
|
7
12
|
Object.assign(
|
|
8
13
|
new TypeError('libnpmdiff needs two arguments to compare'),
|
|
9
14
|
{ code: 'EDIFFARGS' }
|
|
10
15
|
)
|
|
11
16
|
const diff = async (specs, opts = {}) => {
|
|
12
|
-
if (specs.length !== 2)
|
|
17
|
+
if (specs.length !== 2) {
|
|
13
18
|
throw argsError()
|
|
19
|
+
}
|
|
14
20
|
|
|
15
21
|
const [
|
|
16
22
|
aManifest,
|
|
@@ -25,8 +31,8 @@ const diff = async (specs, opts = {}) => {
|
|
|
25
31
|
|
|
26
32
|
// fetches tarball using pacote
|
|
27
33
|
const [a, b] = await Promise.all([
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
getTarball(aManifest, opts),
|
|
35
|
+
getTarball(bManifest, opts),
|
|
30
36
|
])
|
|
31
37
|
|
|
32
38
|
// read all files
|
|
@@ -5,8 +5,9 @@ const binaryExtensions = require('binary-extensions')
|
|
|
5
5
|
// we should try to print patches as long as the
|
|
6
6
|
// extension is not identified as binary files
|
|
7
7
|
const shouldPrintPatch = (path, opts = {}) => {
|
|
8
|
-
if (opts.diffText)
|
|
8
|
+
if (opts.diffText) {
|
|
9
9
|
return true
|
|
10
|
+
}
|
|
10
11
|
|
|
11
12
|
const filename = basename(path)
|
|
12
13
|
const extension = (
|
package/lib/tarball.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
|
|
31
|
+
return pacote.tarball(manifest._resolved, opts)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
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
|
-
|
|
15
|
+
filterFiles.some(f => {
|
|
16
|
+
const pattern = normalizeMatch(f)
|
|
17
|
+
return minimatch(
|
|
17
18
|
normalizeMatch(path),
|
|
18
|
-
`{package/,}${
|
|
19
|
-
{ matchBase:
|
|
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 = () =>
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libnpmdiff",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "The registry diff",
|
|
5
5
|
"repository": "https://github.com/npm/libnpmdiff",
|
|
6
|
+
"main": "lib/index.js",
|
|
6
7
|
"files": [
|
|
7
|
-
"
|
|
8
|
+
"bin",
|
|
8
9
|
"lib"
|
|
9
10
|
],
|
|
10
11
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
12
|
+
"node": "^12.13.0 || ^14.15.0 || >=16"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [
|
|
14
15
|
"npm",
|
|
@@ -28,37 +29,34 @@
|
|
|
28
29
|
"license": "ISC",
|
|
29
30
|
"scripts": {
|
|
30
31
|
"eslint": "eslint",
|
|
31
|
-
"lint": "
|
|
32
|
+
"lint": "eslint '**/*.js'",
|
|
32
33
|
"lintfix": "npm run lint -- --fix",
|
|
33
|
-
"test": "tap
|
|
34
|
+
"test": "tap",
|
|
34
35
|
"posttest": "npm run lint",
|
|
35
|
-
"snap": "tap
|
|
36
|
+
"snap": "tap",
|
|
36
37
|
"preversion": "npm test",
|
|
37
38
|
"postversion": "npm publish",
|
|
38
|
-
"prepublishOnly": "git push origin --follow-tags"
|
|
39
|
+
"prepublishOnly": "git push origin --follow-tags",
|
|
40
|
+
"postlint": "npm-template-check"
|
|
39
41
|
},
|
|
40
42
|
"tap": {
|
|
41
43
|
"check-coverage": true
|
|
42
44
|
},
|
|
43
|
-
"standard": {
|
|
44
|
-
"ignore": [
|
|
45
|
-
"/tap-snapshots/"
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
45
|
"devDependencies": {
|
|
49
|
-
"eslint": "^
|
|
50
|
-
"
|
|
51
|
-
"eslint-plugin-node": "^11.1.0",
|
|
52
|
-
"eslint-plugin-promise": "^4.2.1",
|
|
53
|
-
"eslint-plugin-standard": "^5.0.0",
|
|
54
|
-
"tap": "^14.11.0"
|
|
46
|
+
"eslint": "^8.1.0",
|
|
47
|
+
"tap": "^15.0.9"
|
|
55
48
|
},
|
|
56
49
|
"dependencies": {
|
|
57
50
|
"@npmcli/disparity-colors": "^1.0.1",
|
|
51
|
+
"@npmcli/installed-package-contents": "^1.0.7",
|
|
58
52
|
"binary-extensions": "^2.2.0",
|
|
59
53
|
"diff": "^5.0.0",
|
|
60
54
|
"minimatch": "^3.0.4",
|
|
61
|
-
"
|
|
55
|
+
"npm-package-arg": "^8.1.4",
|
|
56
|
+
"pacote": "^12.0.0",
|
|
62
57
|
"tar": "^6.1.0"
|
|
58
|
+
},
|
|
59
|
+
"templateOSS": {
|
|
60
|
+
"version": "2.4.1"
|
|
63
61
|
}
|
|
64
62
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 2.0.1
|
|
4
|
-
|
|
5
|
-
- fix for tarballs not listing folder names
|
|
6
|
-
|
|
7
|
-
## 2.0.0
|
|
8
|
-
|
|
9
|
-
- API rewrite:
|
|
10
|
-
- normalized all options
|
|
11
|
-
- specs to compare are now an array
|
|
12
|
-
- fix context=0
|
|
13
|
-
- added support to filtering by folder names
|
|
14
|
-
|
|
15
|
-
## 1.0.1
|
|
16
|
-
|
|
17
|
-
- fixed nameOnly option
|
|
18
|
-
|
|
19
|
-
## 1.0.0
|
|
20
|
-
|
|
21
|
-
- Initial release
|
|
22
|
-
|