Skip to content

Commit 65ddfc0

Browse files
authored
feat: template-oss (#60)
BREAKING CHANGE: this will drop support for node10 and non-LTS versions of node12 and node14 - chore: rebuild package-lock - fix: move files to lib, fix otpPrompt error catching - feat: move to template-oss - chore: fix linting - chore: remove @npmcli/lint
1 parent 9cd7257 commit 65ddfc0

22 files changed

+2673
-4928
lines changed

.eslintrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
const { readdirSync: readdir } = require('fs')
4+
5+
const localConfigs = readdir(__dirname)
6+
.filter((file) => file.startsWith('.eslintrc.local.'))
7+
.map((file) => `./${file}`)
8+
9+
module.exports = {
10+
extends: [
11+
'@npmcli',
12+
...localConfigs,
13+
],
14+
}

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @npm/cli-team

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
name: Bug
4+
description: File a bug/issue
5+
title: "[BUG] <title>"
6+
labels: [Bug, Needs Triage]
7+
body:
8+
- type: checkboxes
9+
attributes:
10+
label: Is there an existing issue for this?
11+
description: Please [search here](./issues) to see if an issue already exists for your problem.
12+
options:
13+
- label: I have searched the existing issues
14+
required: true
15+
- type: textarea
16+
attributes:
17+
label: Current Behavior
18+
description: A clear & concise description of what you're experiencing.
19+
validations:
20+
required: false
21+
- type: textarea
22+
attributes:
23+
label: Expected Behavior
24+
description: A clear & concise description of what you expected to happen.
25+
validations:
26+
required: false
27+
- type: textarea
28+
attributes:
29+
label: Steps To Reproduce
30+
description: Steps to reproduce the behavior.
31+
value: |
32+
1. In this environment...
33+
2. With this config...
34+
3. Run '...'
35+
4. See error...
36+
validations:
37+
required: false
38+
- type: textarea
39+
attributes:
40+
label: Environment
41+
description: |
42+
examples:
43+
- **npm**: 7.6.3
44+
- **Node**: 13.14.0
45+
- **OS**: Ubuntu 20.04
46+
- **platform**: Macbook Pro
47+
value: |
48+
- npm:
49+
- Node:
50+
- OS:
51+
- platform:
52+
validations:
53+
required: false
54+

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
blank_issues_enabled: true

.github/workflows/ci.yml

Lines changed: 43 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,53 @@
1-
---
2-
################################################################################
3-
# Template - Node CI
4-
#
5-
# Description:
6-
# This contains the basic information to: install dependencies, run tests,
7-
# get coverage, and run linting on a nodejs project. This template will run
8-
# over the MxN matrix of all operating systems, and all current LTS versions
9-
# of NodeJS.
10-
#
11-
# Dependencies:
12-
# This template assumes that your project is using the `tap` module for
13-
# testing. If you're not using this module, then the step that runs your
14-
# coverage will need to be adjusted.
15-
#
16-
################################################################################
17-
name: Node CI
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
182

19-
on: [push, pull_request]
3+
name: CI
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- main
10+
- latest
2011

2112
jobs:
22-
build:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-node@v2
18+
with:
19+
node-version: '16'
20+
cache: npm
21+
- run: npm i --prefer-online -g npm@latest
22+
- run: npm ci
23+
- run: npm run lint
24+
25+
test:
2326
strategy:
2427
fail-fast: false
2528
matrix:
26-
node-version: [10.x, 12.x, 14.x, 16.x]
27-
os: [ubuntu-latest, windows-latest, macOS-latest]
28-
29-
runs-on: ${{ matrix.os }}
30-
29+
node-version: [12.13.0, 12.x, 14.15.0, 14.x, 16.13.0, 16.x]
30+
platform:
31+
- os: ubuntu-latest
32+
shell: bash
33+
- os: macos-latest
34+
shell: bash
35+
- os: windows-latest
36+
shell: bash
37+
- os: windows-latest
38+
shell: cmd
39+
- os: windows-latest
40+
shell: powershell
41+
runs-on: ${{ matrix.platform.os }}
42+
defaults:
43+
run:
44+
shell: ${{ matrix.platform.shell }}
3145
steps:
32-
# Checkout the repository
3346
- uses: actions/checkout@v2
34-
# Installs the specific version of Node.js
35-
- name: Use Node.js ${{ matrix.node-version }}
36-
uses: actions/setup-node@v1
47+
- uses: actions/setup-node@v2
3748
with:
3849
node-version: ${{ matrix.node-version }}
39-
40-
- name: update npm
41-
run: npm i -g npm@latest
42-
43-
################################################################################
44-
# Install Dependencies
45-
#
46-
# ASSUMPTIONS:
47-
# - The project has a package-lock.json file
48-
#
49-
# Simply run the tests for the project.
50-
################################################################################
51-
- name: Install dependencies
52-
run: npm ci
53-
54-
################################################################################
55-
# Run Testing
56-
#
57-
# ASSUMPTIONS:
58-
# - The project has `tap` as a devDependency
59-
# - There is a script called "test" in the package.json
60-
#
61-
# Simply run the tests for the project.
62-
################################################################################
63-
- name: Run tests
64-
run: npm test -- --no-coverage
65-
66-
################################################################################
67-
# Run coverage check
68-
#
69-
# ASSUMPTIONS:
70-
# - The project has `tap` as a devDependency
71-
# - There is a script called "coverage" in the package.json
72-
#
73-
# Coverage should only be posted once, we are choosing the latest LTS of
74-
# node, and ubuntu as the matrix point to post coverage from. We limit
75-
# to the 'push' event so that coverage ins't posted twice from the
76-
# pull-request event, and push event (line 3).
77-
################################################################################
78-
- name: Run coverage report
79-
if: github.event_name == 'push' && matrix.node-version == '12.x' && matrix.os == 'ubuntu-latest'
80-
run: npm test
81-
env:
82-
# The environment variable name is leveraged by `tap`
83-
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
84-
85-
################################################################################
86-
# Run linting
87-
#
88-
# ASSUMPTIONS:
89-
# - There is a script called "lint" in the package.json
90-
#
91-
# We run linting AFTER we run testing and coverage checks, because if a step
92-
# fails in an GitHub Action, all other steps are not run. We don't want to
93-
# fail to run tests or coverage because of linting. It should be the lowest
94-
# priority of all the steps.
95-
################################################################################
96-
- name: Run linter
97-
run: npm run lint
50+
cache: npm
51+
- run: npm i --prefer-online -g npm@latest
52+
- run: npm ci
53+
- run: npm test --ignore-scripts

.gitignore

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
/node_modules
2-
/.nyc_output
3-
/test/cache
4-
/coverage
1+
# This file is automatically added by @npmcli/template-oss. Do not edit.
2+
3+
# ignore everything in the root
4+
/*
5+
6+
# keep these
7+
!/.eslintrc*
8+
!/.github
9+
!**/.gitignore
10+
!/package.json
11+
!/package-lock.json
12+
!/docs
13+
!/bin
14+
!/lib
15+
!/map.js
16+
!/tap-snapshots
17+
!/test
18+
!/scripts
19+
!/README*
20+
!/LICENSE*
21+
!/SECURITY*
22+
!/CHANGELOG*

LICENSE.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
2+
13
ISC License
24

3-
Copyright (c) npm, Inc.
5+
Copyright npm, Inc.
46

5-
Permission to use, copy, modify, and/or distribute this software for
6-
any purpose with or without fee is hereby granted, provided that the
7-
above copyright notice and this permission notice appear in all copies.
7+
Permission to use, copy, modify, and/or distribute this
8+
software for any purpose with or without fee is hereby
9+
granted, provided that the above copyright notice and this
10+
permission notice appear in all copies.
811

9-
THE SOFTWARE IS PROVIDED "AS IS" AND THE COPYRIGHT HOLDER DISCLAIMS
10-
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11-
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12-
COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13-
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14-
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15-
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
12+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
13+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
14+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
15+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
16+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
1620
USE OR PERFORMANCE OF THIS SOFTWARE.

SECURITY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
2+
3+
Please send vulnerability reports through [hackerone](https://hackerone.com/github).

auth.js renamed to lib/auth.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const regKeyFromURI = (uri, opts) => {
1212
let regKey = `//${parsed.host}${parsed.pathname}`
1313
while (regKey.length > '//'.length) {
1414
// got some auth for this URI
15-
if (hasAuth(regKey, opts))
15+
if (hasAuth(regKey, opts)) {
1616
return regKey
17+
}
1718

1819
// can be either //host/some/path/:_auth or //host/some/path:_auth
1920
// walk up by removing EITHER what's after the slash OR the slash itself
@@ -44,8 +45,9 @@ const getRegistry = opts => {
4445

4546
const getAuth = (uri, opts = {}) => {
4647
const { forceAuth } = opts
47-
if (!uri)
48+
if (!uri) {
4849
throw new Error('URI is required')
50+
}
4951
const regKey = regKeyFromURI(uri, forceAuth || opts)
5052

5153
// we are only allowed to use what's in forceAuth if specified
@@ -62,9 +64,9 @@ const getAuth = (uri, opts = {}) => {
6264
// no auth for this URI, but might have it for the registry
6365
if (!regKey) {
6466
const registry = getRegistry(opts)
65-
if (registry && uri !== registry && sameHost(uri, registry))
67+
if (registry && uri !== registry && sameHost(uri, registry)) {
6668
return getAuth(registry, opts)
67-
else if (registry !== opts.registry) {
69+
} else if (registry !== opts.registry) {
6870
// If making a tarball request to a different base URI than the
6971
// registry where we logged in, but the same auth SHOULD be sent
7072
// to that artifact host, then we track where it was coming in from,
@@ -96,11 +98,11 @@ class Auth {
9698
this.token = null
9799
this.auth = null
98100
this.isBasicAuth = false
99-
if (token)
101+
if (token) {
100102
this.token = token
101-
else if (auth)
103+
} else if (auth) {
102104
this.auth = auth
103-
else if (username && password) {
105+
} else if (username && password) {
104106
const p = Buffer.from(password, 'base64').toString('utf8')
105107
this.auth = Buffer.from(`${username}:${p}`, 'utf8').toString('base64')
106108
this.isBasicAuth = true

check-response.js renamed to lib/check-response.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ const errors = require('./errors.js')
44
const { Response } = require('minipass-fetch')
55
const defaultOpts = require('./default-opts.js')
66

7+
/* eslint-disable-next-line max-len */
8+
const moreInfoUrl = 'https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-present-for-scoped-registry'
79
const checkResponse =
810
async ({ method, uri, res, registry, startTime, auth, opts }) => {
911
opts = { ...defaultOpts, ...opts }
10-
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache'))
12+
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) {
1113
opts.log.notice('', res.headers.get('npm-notice'))
14+
}
1215

1316
if (res.status >= 400) {
1417
logRequest(method, res, startTime, opts)
@@ -21,7 +24,7 @@ const checkResponse =
2124
URI: ${uri}
2225
Scoped Registry Key: ${auth.scopeAuthKey}
2326
24-
More info here: https://github.com/npm/cli/wiki/No-auth-for-URI,-but-auth-present-for-scoped-registry`)
27+
More info here: ${moreInfoUrl}`)
2528
}
2629
return checkErrors(method, res, startTime, opts)
2730
} else {
@@ -46,8 +49,9 @@ function logRequest (method, res, startTime, opts) {
4649
try {
4750
const { URL } = require('url')
4851
const url = new URL(res.url)
49-
if (url.password)
52+
if (url.password) {
5053
url.password = '***'
54+
}
5155

5256
urlStr = url.toString()
5357
} catch (er) {
@@ -85,7 +89,11 @@ function checkErrors (method, res, startTime, opts) {
8589
method, res, parsed, opts.spec
8690
)
8791
}
88-
} else if (res.status === 401 && body != null && /one-time pass/.test(body.toString('utf8'))) {
92+
} else if (
93+
res.status === 401 &&
94+
body != null &&
95+
/one-time pass/.test(body.toString('utf8'))
96+
) {
8997
// Heuristic for malformed OTP responses that don't include the
9098
// www-authenticate header.
9199
throw new errors.HttpErrorAuthOTP(

default-opts.js renamed to lib/default-opts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const pkg = require('./package.json')
1+
const pkg = require('../package.json')
22
module.exports = {
33
log: require('./silentlog.js'),
44
maxSockets: 12,

errors.js renamed to lib/errors.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ function packageName (href) {
88
if (!basePath.match(/^-/)) {
99
basePath = basePath.split('/')
1010
var index = basePath.indexOf('_rewrite')
11-
if (index === -1)
11+
if (index === -1) {
1212
index = basePath.length - 1
13-
else
13+
} else {
1414
index++
15+
}
1516
return decodeURIComponent(basePath[index])
1617
}
1718
} catch (_) {

0 commit comments

Comments
 (0)