libnpmdiff 2.0.3 → 4.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 +2 -2
- package/lib/format-diff.js +8 -6
- package/{index.js → lib/index.js} +12 -6
- package/lib/should-print-patch.js +2 -1
- package/lib/tarball.js +34 -0
- package/package.json +18 -19
- package/CHANGELOG.md +0 -30
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.
|
|
@@ -86,7 +86,7 @@ Fetches the registry tarballs and compare files between a spec `a` and spec `b`.
|
|
|
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)) {
|
|
@@ -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/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libnpmdiff",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.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,35 @@
|
|
|
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
|
-
"
|
|
50
|
-
"eslint
|
|
51
|
-
"
|
|
52
|
-
"eslint-plugin-promise": "^4.2.1",
|
|
53
|
-
"eslint-plugin-standard": "^5.0.0",
|
|
54
|
-
"tap": "^14.11.0"
|
|
46
|
+
"@npmcli/template-oss": "^2.4.2",
|
|
47
|
+
"eslint": "^8.1.0",
|
|
48
|
+
"tap": "^15.0.9"
|
|
55
49
|
},
|
|
56
50
|
"dependencies": {
|
|
57
51
|
"@npmcli/disparity-colors": "^1.0.1",
|
|
52
|
+
"@npmcli/installed-package-contents": "^1.0.7",
|
|
58
53
|
"binary-extensions": "^2.2.0",
|
|
59
54
|
"diff": "^5.0.0",
|
|
60
55
|
"minimatch": "^3.0.4",
|
|
61
|
-
"
|
|
56
|
+
"npm-package-arg": "^9.0.0",
|
|
57
|
+
"pacote": "^13.0.2",
|
|
62
58
|
"tar": "^6.1.0"
|
|
59
|
+
},
|
|
60
|
+
"templateOSS": {
|
|
61
|
+
"version": "2.4.3"
|
|
63
62
|
}
|
|
64
63
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
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
|
-
|
|
23
|
-
## 1.0.1
|
|
24
|
-
|
|
25
|
-
- fixed nameOnly option
|
|
26
|
-
|
|
27
|
-
## 1.0.0
|
|
28
|
-
|
|
29
|
-
- Initial release
|
|
30
|
-
|