Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@github.com>2021-12-16 21:01:56 +0300
committerNathan Fritz <fritzy@github.com>2021-12-16 21:05:19 +0300
commitd7265045730555c03b3142c004c7438e9577028c (patch)
tree035d81b3124bdaa09c21854934bf2b2b50e52e44 /workspaces/libnpmpack
parentd8aac8448e983692cacb427e03f4688cd1b62e30 (diff)
Bring in all libnpm modules + arborist as workspaces (#4166)
Added libnpm workspaces and arborist
Diffstat (limited to 'workspaces/libnpmpack')
-rw-r--r--workspaces/libnpmpack/.eslintrc.js14
-rw-r--r--workspaces/libnpmpack/.gitignore23
-rw-r--r--workspaces/libnpmpack/.npmrc3
-rw-r--r--workspaces/libnpmpack/CHANGELOG.md17
-rw-r--r--workspaces/libnpmpack/LICENSE13
-rw-r--r--workspaces/libnpmpack/README.md56
-rw-r--r--workspaces/libnpmpack/SECURITY.md3
-rw-r--r--workspaces/libnpmpack/lib/index.js54
-rw-r--r--workspaces/libnpmpack/package.json50
-rw-r--r--workspaces/libnpmpack/test/fixtures/tnock.js12
-rw-r--r--workspaces/libnpmpack/test/index.js91
11 files changed, 336 insertions, 0 deletions
diff --git a/workspaces/libnpmpack/.eslintrc.js b/workspaces/libnpmpack/.eslintrc.js
new file mode 100644
index 000000000..022767bc3
--- /dev/null
+++ b/workspaces/libnpmpack/.eslintrc.js
@@ -0,0 +1,14 @@
+// This file is automatically added by @npmcli/template-oss. Do not edit.
+
+const { readdirSync: readdir } = require('fs')
+
+const localConfigs = readdir(__dirname)
+ .filter((file) => file.startsWith('.eslintrc.local.'))
+ .map((file) => `./${file}`)
+
+module.exports = {
+ extends: [
+ '@npmcli',
+ ...localConfigs,
+ ],
+}
diff --git a/workspaces/libnpmpack/.gitignore b/workspaces/libnpmpack/.gitignore
new file mode 100644
index 000000000..6ed44c72b
--- /dev/null
+++ b/workspaces/libnpmpack/.gitignore
@@ -0,0 +1,23 @@
+# This file is automatically added by @npmcli/template-oss. Do not edit.
+
+# ignore everything in the root
+/*
+
+# keep these
+!/.commitlintrc.js
+!/.npmrc
+!/.eslintrc*
+!/.github
+!**/.gitignore
+!/package.json
+!/docs
+!/bin
+!/lib
+!/map.js
+!/tap-snapshots
+!/test
+!/scripts
+!/README*
+!/LICENSE*
+!/SECURITY*
+!/CHANGELOG*
diff --git a/workspaces/libnpmpack/.npmrc b/workspaces/libnpmpack/.npmrc
new file mode 100644
index 000000000..878b7ddef
--- /dev/null
+++ b/workspaces/libnpmpack/.npmrc
@@ -0,0 +1,3 @@
+;This file is automatically added by @npmcli/template-oss. Do not edit.
+
+package-lock=false
diff --git a/workspaces/libnpmpack/CHANGELOG.md b/workspaces/libnpmpack/CHANGELOG.md
new file mode 100644
index 000000000..2310ac7f8
--- /dev/null
+++ b/workspaces/libnpmpack/CHANGELOG.md
@@ -0,0 +1,17 @@
+# Change Log
+
+<a name="2.0.0"></a>
+# [2.0.0](https://github.com/npm/libnpmpack/compare/v1.0.0...v2.0.0) (2020-03-27)
+
+### Breaking Changes
+
+* [`cb2ecf2`](https://github.com/npm/libnpmpack/commit/cb2ecf2) feat: resolve to tarball data Buffer ([@claudiahdz](https://github.com/claudiahdz))
+
+<a name="1.0.0"></a>
+# 1.0.0 (2020-03-26)
+
+### Features
+
+* [`a35c590`](https://github.com/npm/libnpmpack/commit/a35c590) feat: pack tarballs from local dir or registry spec ([@claudiahdz](https://github.com/claudiahdz))
+
+* [`6d72149`](https://github.com/npm/libnpmpack/commit/6d72149) feat: sorted tarball contents ([@eridal](https://github.com/eridal))
diff --git a/workspaces/libnpmpack/LICENSE b/workspaces/libnpmpack/LICENSE
new file mode 100644
index 000000000..209e4477f
--- /dev/null
+++ b/workspaces/libnpmpack/LICENSE
@@ -0,0 +1,13 @@
+Copyright npm, Inc
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/workspaces/libnpmpack/README.md b/workspaces/libnpmpack/README.md
new file mode 100644
index 000000000..74b4934b0
--- /dev/null
+++ b/workspaces/libnpmpack/README.md
@@ -0,0 +1,56 @@
+# libnpmpack
+
+[![npm version](https://img.shields.io/npm/v/libnpmpack.svg)](https://npm.im/libnpmpack)
+[![license](https://img.shields.io/npm/l/libnpmpack.svg)](https://npm.im/libnpmpack)
+[![GitHub Actions](https://github.com/npm/libnpmpack/workflows/Node%20CI/badge.svg)](https://github.com/npm/libnpmpack/actions?query=workflow%3A%22Node+CI%22)
+[![Coverage Status](https://coveralls.io/repos/github/npm/libnpmpack/badge.svg?branch=latest)](https://coveralls.io/github/npm/libnpmpack?branch=latest)
+
+[`libnpmpack`](https://github.com/npm/libnpmpack) is a Node.js library for
+programmatically packing tarballs from a local directory or from a registry or github spec. If packing from a local source, `libnpmpack` will also run the `prepack` and `postpack` lifecycles.
+
+## Table of Contents
+
+* [Example](#example)
+* [Install](#install)
+* [API](#api)
+ * [`pack()`](#pack)
+
+## Example
+
+```js
+const pack = require('libnpmpack')
+```
+
+## Install
+
+`$ npm install libnpmpack`
+
+### API
+
+#### <a name="pack"></a> `> pack(spec, [opts]) -> Promise`
+
+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.
+
+If no options are passed, the tarball file will be saved on the same directory from which `pack` was called in.
+
+`libnpmpack` uses [`pacote`](https://npm.im/pacote).
+Most options are passed through directly to that library, so please refer to
+[its own `opts`
+documentation](https://www.npmjs.com/package/pacote#options)
+for options that can be passed in.
+
+##### Examples
+
+```javascript
+// packs from cwd
+const tarball = await pack()
+
+// packs from a local directory
+const localTar = await pack('/Users/claudiahdz/projects/my-cool-pkg')
+
+// packs from a registry spec
+const registryTar = await pack('abbrev@1.0.3')
+
+// packs from a github spec
+const githubTar = await pack('isaacs/rimraf#PR-192')
+```
diff --git a/workspaces/libnpmpack/SECURITY.md b/workspaces/libnpmpack/SECURITY.md
new file mode 100644
index 000000000..a93106d0c
--- /dev/null
+++ b/workspaces/libnpmpack/SECURITY.md
@@ -0,0 +1,3 @@
+<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
+
+Please send vulnerability reports through [hackerone](https://hackerone.com/github).
diff --git a/workspaces/libnpmpack/lib/index.js b/workspaces/libnpmpack/lib/index.js
new file mode 100644
index 000000000..23bb9df4b
--- /dev/null
+++ b/workspaces/libnpmpack/lib/index.js
@@ -0,0 +1,54 @@
+'use strict'
+
+const pacote = require('pacote')
+const npa = require('npm-package-arg')
+const runScript = require('@npmcli/run-script')
+
+module.exports = pack
+async function pack (spec = 'file:.', opts = {}) {
+ // gets spec
+ spec = npa(spec)
+
+ const manifest = await pacote.manifest(spec, opts)
+
+ // Default to true if no log options passed, set to false if we're in silent
+ // mode
+ const banner = !opts.log || (opts.log.level !== 'silent')
+
+ if (spec.type === 'directory') {
+ // prepack
+ await runScript({
+ ...opts,
+ event: 'prepack',
+ path: spec.fetchSpec,
+ stdio: 'inherit',
+ pkg: manifest,
+ banner,
+ })
+ }
+
+ // packs tarball
+ const tarball = await pacote.tarball(manifest._resolved, {
+ ...opts,
+ integrity: manifest._integrity,
+ })
+
+ if (spec.type === 'directory') {
+ // postpack
+ await runScript({
+ ...opts,
+ event: 'postpack',
+ path: spec.fetchSpec,
+ stdio: 'inherit',
+ pkg: manifest,
+ banner,
+ env: {
+ npm_package_from: tarball.from,
+ npm_package_resolved: tarball.resolved,
+ npm_package_integrity: tarball.integrity,
+ },
+ })
+ }
+
+ return tarball
+}
diff --git a/workspaces/libnpmpack/package.json b/workspaces/libnpmpack/package.json
new file mode 100644
index 000000000..4a1ebc24f
--- /dev/null
+++ b/workspaces/libnpmpack/package.json
@@ -0,0 +1,50 @@
+{
+ "name": "libnpmpack",
+ "version": "3.0.1",
+ "description": "Programmatic API for the bits behind npm pack",
+ "author": "GitHub Inc.",
+ "main": "lib/index.js",
+ "contributors": [
+ "Claudia Hernández <claudia@npmjs.com>"
+ ],
+ "files": [
+ "bin",
+ "lib"
+ ],
+ "license": "ISC",
+ "scripts": {
+ "preversion": "npm test",
+ "postversion": "npm publish",
+ "prepublishOnly": "git push origin --follow-tags",
+ "lint": "eslint '**/*.js'",
+ "test": "tap",
+ "posttest": "npm run lint",
+ "postlint": "npm-template-check",
+ "lintfix": "npm run lint -- --fix",
+ "snap": "tap"
+ },
+ "tap": {
+ "check-coverage": true
+ },
+ "devDependencies": {
+ "nock": "^13.0.7",
+ "tap": "^15.0.0"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/npm/libnpmpack.git"
+ },
+ "bugs": "https://github.com/npm/libnpmpack/issues",
+ "homepage": "https://npmjs.com/package/libnpmpack",
+ "dependencies": {
+ "@npmcli/run-script": "^2.0.0",
+ "npm-package-arg": "^8.1.0",
+ "pacote": "^12.0.0"
+ },
+ "engines": {
+ "node": "^12.13.0 || ^14.15.0 || >=16"
+ },
+ "templateOSS": {
+ "version": "2.4.1"
+ }
+}
diff --git a/workspaces/libnpmpack/test/fixtures/tnock.js b/workspaces/libnpmpack/test/fixtures/tnock.js
new file mode 100644
index 000000000..048639a50
--- /dev/null
+++ b/workspaces/libnpmpack/test/fixtures/tnock.js
@@ -0,0 +1,12 @@
+'use strict'
+
+const nock = require('nock')
+
+module.exports = tnock
+function tnock (t, host) {
+ const server = nock(host)
+ t.teardown(function () {
+ server.done()
+ })
+ return server
+}
diff --git a/workspaces/libnpmpack/test/index.js b/workspaces/libnpmpack/test/index.js
new file mode 100644
index 000000000..dcc5e41f4
--- /dev/null
+++ b/workspaces/libnpmpack/test/index.js
@@ -0,0 +1,91 @@
+'use strict'
+
+const t = require('tap')
+const pack = require('../lib/index.js')
+const tnock = require('./fixtures/tnock.js')
+
+const OPTS = {
+ registry: 'https://mock.reg/',
+}
+
+const REG = OPTS.registry
+
+t.test('packs from local directory', async t => {
+ const testDir = t.testdir({
+ 'package.json': JSON.stringify({
+ name: 'my-cool-pkg',
+ version: '1.0.0',
+ }, null, 2),
+ })
+
+ const cwd = process.cwd()
+ process.chdir(testDir)
+
+ const tarball = await pack()
+ t.ok(tarball)
+
+ t.teardown(async () => {
+ process.chdir(cwd)
+ })
+})
+
+t.test('packs from local directory with silent loglevel', async t => {
+ const testDir = t.testdir({
+ 'package.json': JSON.stringify({
+ name: 'my-cool-pkg',
+ version: '1.0.0',
+ }, null, 2),
+ })
+
+ const cwd = process.cwd()
+ process.chdir(testDir)
+
+ const tarball = await pack('file:', { log: { level: 'silent' } })
+ t.ok(tarball)
+
+ t.teardown(async () => {
+ process.chdir(cwd)
+ })
+})
+
+t.test('packs from registry spec', async t => {
+ const spec = 'my-cool-pkg'
+ const packument = {
+ _id: 'my-cool-pkg',
+ name: 'my-cool-pkg',
+ description: 'some stuff',
+ 'dist-tags': {
+ latest: '1.0.0',
+ },
+ versions: {
+ '1.0.0': {
+ _id: 'my-cool-pkg@1.0.0',
+ _nodeVersion: process.versions.node,
+ name: 'my-cool-pkg',
+ version: '1.0.0',
+ description: 'some stuff',
+ dist: {
+ shasum: 'some-shasum',
+ integrity: '123',
+ tarball: 'https://mock.reg/my-cool-pkg/-/my-cool-pkg-1.0.0.tgz',
+ },
+ },
+ },
+ readme: '',
+ access: 'public',
+ _attachments: {
+ 'my-cool-pkg-1.0.0.tgz': {
+ content_type: 'application/octet-stream',
+ data: '',
+ length: '0',
+ },
+ },
+ }
+
+ const srv = tnock(t, REG)
+ srv.get('/my-cool-pkg').reply(200, packument)
+ srv.get('/my-cool-pkg/-/my-cool-pkg-1.0.0.tgz').reply(200, '')
+
+ const tarball = await pack(spec, { ...OPTS })
+ t.ok(tarball)
+})