libnpmpack 1.0.0 → 2.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/CHANGELOG.md +7 -0
- package/README.md +6 -68
- package/index.js +5 -32
- package/package.json +3 -10
- package/utils/tar.js +0 -121
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
<a name="2.0.0"></a>
|
|
4
|
+
# [2.0.0](https://github.com/npm/libnpmpublish/compare/v1.0.0...v2.0.0) (2020-03-27)
|
|
5
|
+
|
|
6
|
+
### Breaking Changes
|
|
7
|
+
|
|
8
|
+
* [`cb2ecf2`](https://github.com/npm/libnpmpack/commit/cb2ecf2) feat: resolve to tarball data Buffer ([@claudiahdz](https://github.com/claudiahdz))
|
|
9
|
+
|
|
3
10
|
<a name="1.0.0"></a>
|
|
4
11
|
# 1.0.0 (2020-03-26)
|
|
5
12
|
|
package/README.md
CHANGED
|
@@ -27,15 +27,12 @@ const pack = require('libnpmpack')
|
|
|
27
27
|
|
|
28
28
|
### API
|
|
29
29
|
|
|
30
|
-
|
|
31
30
|
#### <a name="pack"></a> `> pack(spec, [opts]) -> Promise`
|
|
32
31
|
|
|
33
|
-
Packs a tarball from a local directory or from a registry or github spec and
|
|
32
|
+
Packs a tarball from a local directory or from a registry or github spec and returns a Promise that resolves to the tarball data Buffer, with from, resolved, and integrity fields attached.
|
|
34
33
|
|
|
35
34
|
If no options are passed, the tarball file will be saved on the same directory from which `pack` was called in.
|
|
36
35
|
|
|
37
|
-
If `opts.target` is passed in, it will save the tarball file on the location entered.
|
|
38
|
-
|
|
39
36
|
`libnpmpack` uses [`pacote`](https://npm.im/pacote).
|
|
40
37
|
Most options are passed through directly to that library, so please refer to
|
|
41
38
|
[its own `opts`
|
|
@@ -45,74 +42,15 @@ for options that can be passed in.
|
|
|
45
42
|
##### Examples
|
|
46
43
|
|
|
47
44
|
```javascript
|
|
48
|
-
// packs from
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
id: 'my-cool-pkg@1.0.0',
|
|
54
|
-
name: 'my-cool-pkg',
|
|
55
|
-
version: '1.0.0',
|
|
56
|
-
size: 260,
|
|
57
|
-
unpackedSize: 133,
|
|
58
|
-
shasum: '535bdcc05fd4a1b7f2603c5527a7c63ba5b88cff',
|
|
59
|
-
integrity: ssri.parse(integrity.sha512[0]),
|
|
60
|
-
filename: 'my-cool-pkg-1.0.0.tgz',
|
|
61
|
-
files: [
|
|
62
|
-
{ path: 'index.js', size: 5, mode: 420 },
|
|
63
|
-
{ path: 'node_modules/a/package.json', size: 39, mode: 420 },
|
|
64
|
-
{ path: 'package.json', size: 89, mode: 420 }
|
|
65
|
-
],
|
|
66
|
-
entryCount: 3,
|
|
67
|
-
bundled: ['a']
|
|
68
|
-
}
|
|
69
|
-
*/
|
|
45
|
+
// packs from cwd
|
|
46
|
+
const tarball = await pack()
|
|
47
|
+
|
|
48
|
+
// packs from a local directory
|
|
49
|
+
const localTar = await pack('/Users/claudiahdz/projects/my-cool-pkg')
|
|
70
50
|
|
|
71
51
|
// packs from a registry spec
|
|
72
52
|
const registryTar = await pack('abbrev@1.0.3')
|
|
73
|
-
console.log(registryTar)
|
|
74
|
-
/*
|
|
75
|
-
{
|
|
76
|
-
id: abbrev@1.0.3,
|
|
77
|
-
name: 'abbrev',
|
|
78
|
-
version: '1.0.3',
|
|
79
|
-
size: 1526,
|
|
80
|
-
unpackedSize: 3358,
|
|
81
|
-
shasum: 'aa049c967f999222aa42e14434f0c562ef468241',
|
|
82
|
-
integrity: Integrity { sha512: [ [Hash] ] },
|
|
83
|
-
filename: 'abbrev-1.0.3.tgz',
|
|
84
|
-
files: [
|
|
85
|
-
{ path: 'package.json', size: 277, mode: 420 },
|
|
86
|
-
{ path: 'README.md', size: 499, mode: 420 },
|
|
87
|
-
{ path: 'lib/abbrev.js', size: 2582, mode: 420 }
|
|
88
|
-
],
|
|
89
|
-
entryCount: 3,
|
|
90
|
-
bundled: []
|
|
91
|
-
}
|
|
92
|
-
*/
|
|
93
53
|
|
|
94
54
|
// packs from a github spec
|
|
95
55
|
const githubTar = await pack('isaacs/rimraf#PR-192')
|
|
96
|
-
/*
|
|
97
|
-
{
|
|
98
|
-
id: 'rimraf@2.6.3',
|
|
99
|
-
name: 'rimraf',
|
|
100
|
-
version: '2.6.3',
|
|
101
|
-
size: 5664,
|
|
102
|
-
unpackedSize: 15463,
|
|
103
|
-
shasum: '9f5edf99046b4096d610532f0ec279135a624b15',
|
|
104
|
-
integrity: Integrity { sha512: [ [Hash] ] },
|
|
105
|
-
filename: 'rimraf-2.6.3.tgz',
|
|
106
|
-
files: [
|
|
107
|
-
{ path: 'LICENSE', size: 765, mode: 420 },
|
|
108
|
-
{ path: 'bin.js', size: 1196, mode: 493 },
|
|
109
|
-
{ path: 'rimraf.js', size: 9225, mode: 420 },
|
|
110
|
-
{ path: 'package.json', size: 677, mode: 420 },
|
|
111
|
-
{ path: 'README.md', size: 3600, mode: 420 }
|
|
112
|
-
],
|
|
113
|
-
entryCount: 5,
|
|
114
|
-
bundled: []
|
|
115
|
-
}
|
|
116
|
-
*/
|
|
117
56
|
```
|
|
118
|
-
|
package/index.js
CHANGED
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const os = require('os')
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const util = require('util')
|
|
7
3
|
const pacote = require('pacote')
|
|
8
4
|
const npa = require('npm-package-arg')
|
|
9
|
-
const mv = require('move-concurrently')
|
|
10
5
|
const runScript = require('@npmcli/run-script')
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
const mkdtemp = util.promisify(fs.mkdtemp)
|
|
14
|
-
|
|
15
|
-
const { getContents, logTar } = require('./utils/tar')
|
|
16
|
-
|
|
7
|
+
module.exports = pack
|
|
17
8
|
async function pack (spec = 'file:.', opts = {}) {
|
|
18
|
-
const { target = null } = opts
|
|
19
9
|
// gets spec
|
|
20
10
|
spec = npa(spec)
|
|
21
11
|
|
|
22
12
|
const manifest = await pacote.manifest(spec, opts)
|
|
23
|
-
const filename = path.basename(`${manifest.name}-${manifest.version}.tgz`)
|
|
24
|
-
const dest = target || `${process.cwd()}/${filename}`
|
|
25
13
|
|
|
26
14
|
if (spec.type === 'directory') {
|
|
27
15
|
// prepack
|
|
@@ -30,26 +18,16 @@ async function pack (spec = 'file:.', opts = {}) {
|
|
|
30
18
|
event: 'prepack',
|
|
31
19
|
path: spec.fetchSpec,
|
|
32
20
|
stdio: 'inherit',
|
|
33
|
-
pkg: manifest
|
|
34
|
-
env: {
|
|
35
|
-
npm_package_target: dest
|
|
36
|
-
}
|
|
21
|
+
pkg: manifest
|
|
37
22
|
})
|
|
38
23
|
}
|
|
39
24
|
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
// packs tarball on tmp location
|
|
44
|
-
const tarball = await pacote.tarball.file(manifest._resolved, tmpTarget, {
|
|
25
|
+
// packs tarball
|
|
26
|
+
const tarball = await pacote.tarball(manifest._resolved, {
|
|
45
27
|
...opts,
|
|
46
28
|
integrity: manifest._integrity
|
|
47
29
|
})
|
|
48
30
|
|
|
49
|
-
// moves tarball to dest
|
|
50
|
-
await mv(tmpTarget, dest)
|
|
51
|
-
await rimraf(tmpDir)
|
|
52
|
-
|
|
53
31
|
if (spec.type === 'directory') {
|
|
54
32
|
// postpack
|
|
55
33
|
await runScript({
|
|
@@ -59,7 +37,6 @@ async function pack (spec = 'file:.', opts = {}) {
|
|
|
59
37
|
stdio: 'inherit',
|
|
60
38
|
pkg: manifest,
|
|
61
39
|
env: {
|
|
62
|
-
npm_package_target: dest,
|
|
63
40
|
npm_package_from: tarball.from,
|
|
64
41
|
npm_package_resolved: tarball.resolved,
|
|
65
42
|
npm_package_integrity: tarball.integrity
|
|
@@ -67,9 +44,5 @@ async function pack (spec = 'file:.', opts = {}) {
|
|
|
67
44
|
})
|
|
68
45
|
}
|
|
69
46
|
|
|
70
|
-
|
|
71
|
-
return contents
|
|
47
|
+
return tarball
|
|
72
48
|
}
|
|
73
|
-
|
|
74
|
-
pack.logTar = logTar
|
|
75
|
-
module.exports = pack
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libnpmpack",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Programmatic API for the bits behind npm pack",
|
|
5
5
|
"author": "npm Inc. <support@npmjs.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
],
|
|
9
9
|
"main": "index.js",
|
|
10
10
|
"files": [
|
|
11
|
-
"*.js"
|
|
12
|
-
"utils"
|
|
11
|
+
"*.js"
|
|
13
12
|
],
|
|
14
13
|
"license": "ISC",
|
|
15
14
|
"scripts": {
|
|
@@ -36,14 +35,8 @@
|
|
|
36
35
|
"homepage": "https://npmjs.com/package/libnpmpack",
|
|
37
36
|
"dependencies": {
|
|
38
37
|
"@npmcli/run-script": "^1.3.0",
|
|
39
|
-
"byte-size": "^6.2.0",
|
|
40
|
-
"columnify": "^1.5.4",
|
|
41
|
-
"move-concurrently": "^1.0.1",
|
|
42
38
|
"npm-package-arg": "^8.0.0",
|
|
43
|
-
"pacote": "^11.1.
|
|
44
|
-
"rimraf": "^3.0.2",
|
|
45
|
-
"ssri": "^8.0.0",
|
|
46
|
-
"tar": "^6.0.1"
|
|
39
|
+
"pacote": "^11.1.4"
|
|
47
40
|
},
|
|
48
41
|
"engines": {
|
|
49
42
|
"node": ">=10"
|
package/utils/tar.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const tar = require('tar')
|
|
5
|
-
const util = require('util')
|
|
6
|
-
const ssri = require('ssri')
|
|
7
|
-
const byteSize = require('byte-size')
|
|
8
|
-
const columnify = require('columnify')
|
|
9
|
-
|
|
10
|
-
const statAsync = util.promisify(require('fs').stat)
|
|
11
|
-
|
|
12
|
-
module.exports.logTar = logTar
|
|
13
|
-
/* istanbul ignore next */
|
|
14
|
-
function logTar (tarball, opts = {}) {
|
|
15
|
-
const { unicode, log = console.log } = opts
|
|
16
|
-
log('')
|
|
17
|
-
log('', `${unicode ? '📦 ' : 'package:'} ${tarball.name}@${tarball.version}`)
|
|
18
|
-
log('=== Tarball Contents ===')
|
|
19
|
-
if (tarball.files.length) {
|
|
20
|
-
log('', columnify(tarball.files.map((f) => {
|
|
21
|
-
const bytes = byteSize(f.size)
|
|
22
|
-
return { path: f.path, size: `${bytes.value}${bytes.unit}` }
|
|
23
|
-
}), {
|
|
24
|
-
include: ['size', 'path'],
|
|
25
|
-
showHeaders: false
|
|
26
|
-
}))
|
|
27
|
-
}
|
|
28
|
-
if (tarball.bundled.length) {
|
|
29
|
-
log('=== Bundled Dependencies ===')
|
|
30
|
-
tarball.bundled.forEach((name) => log.notice('', name))
|
|
31
|
-
}
|
|
32
|
-
log('=== Tarball Details ===')
|
|
33
|
-
log('', columnify([
|
|
34
|
-
{ name: 'name:', value: tarball.name },
|
|
35
|
-
{ name: 'version:', value: tarball.version },
|
|
36
|
-
tarball.filename && { name: 'filename:', value: tarball.filename },
|
|
37
|
-
{ name: 'package size:', value: byteSize(tarball.size) },
|
|
38
|
-
{ name: 'unpacked size:', value: byteSize(tarball.unpackedSize) },
|
|
39
|
-
{ name: 'shasum:', value: tarball.shasum },
|
|
40
|
-
{
|
|
41
|
-
name: 'integrity:',
|
|
42
|
-
value: tarball.integrity.toString().substr(0, 20) + '[...]' + tarball.integrity.toString().substr(80)
|
|
43
|
-
},
|
|
44
|
-
tarball.bundled.length && { name: 'bundled deps:', value: tarball.bundled.length },
|
|
45
|
-
tarball.bundled.length && { name: 'bundled files:', value: tarball.entryCount - tarball.files.length },
|
|
46
|
-
tarball.bundled.length && { name: 'own files:', value: tarball.files.length },
|
|
47
|
-
{ name: 'total files:', value: tarball.entryCount }
|
|
48
|
-
].filter((x) => x), {
|
|
49
|
-
include: ['name', 'value'],
|
|
50
|
-
showHeaders: false
|
|
51
|
-
}))
|
|
52
|
-
log('', '')
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports.getContents = getContents
|
|
56
|
-
async function getContents (manifest, target) {
|
|
57
|
-
const files = []
|
|
58
|
-
const bundled = new Set()
|
|
59
|
-
let totalEntries = 0
|
|
60
|
-
let totalEntrySize = 0
|
|
61
|
-
|
|
62
|
-
// reads contents of tarball
|
|
63
|
-
await tar.t({
|
|
64
|
-
file: target,
|
|
65
|
-
onentry (entry) {
|
|
66
|
-
totalEntries++
|
|
67
|
-
totalEntrySize += entry.size
|
|
68
|
-
const p = entry.path
|
|
69
|
-
if (p.startsWith('package/node_modules/')) {
|
|
70
|
-
const name = p.match(/^package\/node_modules\/((?:@[^/]+\/)?[^/]+)/)[1]
|
|
71
|
-
bundled.add(name)
|
|
72
|
-
}
|
|
73
|
-
files.push({
|
|
74
|
-
path: entry.path.replace(/^package\//, ''),
|
|
75
|
-
size: entry.size,
|
|
76
|
-
mode: entry.mode
|
|
77
|
-
})
|
|
78
|
-
},
|
|
79
|
-
strip: 1
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
const [stat, integrity] = await Promise.all([
|
|
83
|
-
statAsync(target),
|
|
84
|
-
ssri.fromStream(fs.createReadStream(target), {
|
|
85
|
-
algorithms: ['sha1', 'sha512']
|
|
86
|
-
})
|
|
87
|
-
])
|
|
88
|
-
|
|
89
|
-
const comparator = (a, b) => {
|
|
90
|
-
return a.path.localeCompare(b.path, undefined, {
|
|
91
|
-
sensitivity: 'case',
|
|
92
|
-
numeric: true
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const isUpper = (str) => {
|
|
97
|
-
const ch = str.charAt(0)
|
|
98
|
-
return ch >= 'A' && ch <= 'Z'
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const uppers = files.filter(file => isUpper(file.path))
|
|
102
|
-
const others = files.filter(file => !isUpper(file.path))
|
|
103
|
-
|
|
104
|
-
uppers.sort(comparator)
|
|
105
|
-
others.sort(comparator)
|
|
106
|
-
|
|
107
|
-
const shasum = integrity.sha1[0].hexDigest()
|
|
108
|
-
return {
|
|
109
|
-
id: manifest._id || `${manifest.name}@${manifest.version}`,
|
|
110
|
-
name: manifest.name,
|
|
111
|
-
version: manifest.version,
|
|
112
|
-
size: stat.size,
|
|
113
|
-
unpackedSize: totalEntrySize,
|
|
114
|
-
shasum,
|
|
115
|
-
integrity: ssri.parse(integrity.sha512[0]),
|
|
116
|
-
filename: `${manifest.name}-${manifest.version}.tgz`,
|
|
117
|
-
files: uppers.concat(others),
|
|
118
|
-
entryCount: totalEntries,
|
|
119
|
-
bundled: Array.from(bundled)
|
|
120
|
-
}
|
|
121
|
-
}
|