libnpmpack 2.0.0 → 3.1.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.
@@ -3,6 +3,9 @@
3
3
  const pacote = require('pacote')
4
4
  const npa = require('npm-package-arg')
5
5
  const runScript = require('@npmcli/run-script')
6
+ const path = require('path')
7
+ const util = require('util')
8
+ const writeFile = util.promisify(require('fs').writeFile)
6
9
 
7
10
  module.exports = pack
8
11
  async function pack (spec = 'file:.', opts = {}) {
@@ -11,6 +14,10 @@ async function pack (spec = 'file:.', opts = {}) {
11
14
 
12
15
  const manifest = await pacote.manifest(spec, opts)
13
16
 
17
+ // Default to true if no log options passed, set to false if we're in silent
18
+ // mode
19
+ const banner = !opts.log || (opts.log.level !== 'silent')
20
+
14
21
  if (spec.type === 'directory') {
15
22
  // prepack
16
23
  await runScript({
@@ -18,16 +25,25 @@ async function pack (spec = 'file:.', opts = {}) {
18
25
  event: 'prepack',
19
26
  path: spec.fetchSpec,
20
27
  stdio: 'inherit',
21
- pkg: manifest
28
+ pkg: manifest,
29
+ banner,
22
30
  })
23
31
  }
24
32
 
25
33
  // packs tarball
26
34
  const tarball = await pacote.tarball(manifest._resolved, {
27
35
  ...opts,
28
- integrity: manifest._integrity
36
+ integrity: manifest._integrity,
29
37
  })
30
38
 
39
+ // check for explicit `false` so the default behavior is to skip writing to disk
40
+ if (opts.dryRun === false) {
41
+ const filename = `${manifest.name}-${manifest.version}.tgz`
42
+ .replace(/^@/, '').replace(/\//, '-')
43
+ const destination = path.resolve(opts.packDestination, filename)
44
+ await writeFile(destination, tarball)
45
+ }
46
+
31
47
  if (spec.type === 'directory') {
32
48
  // postpack
33
49
  await runScript({
@@ -36,11 +52,12 @@ async function pack (spec = 'file:.', opts = {}) {
36
52
  path: spec.fetchSpec,
37
53
  stdio: 'inherit',
38
54
  pkg: manifest,
55
+ banner,
39
56
  env: {
40
57
  npm_package_from: tarball.from,
41
58
  npm_package_resolved: tarball.resolved,
42
- npm_package_integrity: tarball.integrity
43
- }
59
+ npm_package_integrity: tarball.integrity,
60
+ },
44
61
  })
45
62
  }
46
63
 
package/package.json CHANGED
@@ -1,31 +1,35 @@
1
1
  {
2
2
  "name": "libnpmpack",
3
- "version": "2.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Programmatic API for the bits behind npm pack",
5
- "author": "npm Inc. <support@npmjs.com>",
5
+ "author": "GitHub Inc.",
6
+ "main": "lib/index.js",
6
7
  "contributors": [
7
8
  "Claudia Hernández <claudia@npmjs.com>"
8
9
  ],
9
- "main": "index.js",
10
10
  "files": [
11
- "*.js"
11
+ "bin",
12
+ "lib"
12
13
  ],
13
14
  "license": "ISC",
14
15
  "scripts": {
15
16
  "preversion": "npm test",
16
17
  "postversion": "npm publish",
17
18
  "prepublishOnly": "git push origin --follow-tags",
18
- "lint": "standard",
19
+ "lint": "eslint '**/*.js'",
19
20
  "test": "tap",
20
- "posttest": "npm run lint"
21
+ "posttest": "npm run lint",
22
+ "postlint": "npm-template-check",
23
+ "lintfix": "npm run lint -- --fix",
24
+ "snap": "tap"
21
25
  },
22
26
  "tap": {
23
27
  "check-coverage": true
24
28
  },
25
29
  "devDependencies": {
26
- "nock": "^12.0.2",
27
- "standard": "^14.3.1",
28
- "tap": "^14.10.6"
30
+ "@npmcli/template-oss": "^2.4.2",
31
+ "nock": "^13.0.7",
32
+ "tap": "^15.0.0"
29
33
  },
30
34
  "repository": {
31
35
  "type": "git",
@@ -34,11 +38,14 @@
34
38
  "bugs": "https://github.com/npm/libnpmpack/issues",
35
39
  "homepage": "https://npmjs.com/package/libnpmpack",
36
40
  "dependencies": {
37
- "@npmcli/run-script": "^1.3.0",
38
- "npm-package-arg": "^8.0.0",
39
- "pacote": "^11.1.4"
41
+ "@npmcli/run-script": "^2.0.0",
42
+ "npm-package-arg": "^8.1.0",
43
+ "pacote": "^12.0.0"
40
44
  },
41
45
  "engines": {
42
- "node": ">=10"
46
+ "node": "^12.13.0 || ^14.15.0 || >=16"
47
+ },
48
+ "templateOSS": {
49
+ "version": "2.4.3"
43
50
  }
44
51
  }
package/CHANGELOG.md DELETED
@@ -1,17 +0,0 @@
1
- # Change Log
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
-
10
- <a name="1.0.0"></a>
11
- # 1.0.0 (2020-03-26)
12
-
13
- ### Features
14
-
15
- * [`a35c590`](https://github.com/npm/libnpmpack/commit/a35c590) feat: pack tarballs from local dir or registry spec ([@claudiahdz](https://github.com/claudiahdz))
16
-
17
- * [`6d72149`](https://github.com/npm/libnpmpack/commit/6d72149) feat: sorted tarball contents ([@eridal](https://github.com/eridal))