Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly parse browser as config as string #6020

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
'smoke-tests/**',
'mock-registry/**',
'workspaces/**',
'mock-globals/**',
],
extends: [
'@npmcli',
Expand Down
30 changes: 30 additions & 0 deletions .eslintrc.local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { resolve, relative } = require('path')

// Create an override to lockdown a file to es6 syntax only
// and only allow it to require an allowlist of files
const res = (p) => resolve(__dirname, p)
const rel = (p) => relative(__dirname, res(p))
const braces = (a) => a.length > 1 ? `{${a.map(rel).join(',')}}` : a[0]

const es6Files = (e) => Object.entries(e).map(([file, allow]) => ({
files: `./${rel(file)}`,
parserOptions: {
ecmaVersion: 6,
},
rules: {
'node/no-restricted-require': ['error', [{
name: ['/**', `!${__dirname}/${braces(allow)}`],
message: `This file can only require: ${allow.join(',')}`,
}]],
},
}))

module.exports = {
rules: {
'no-console': 'error',
},
overrides: es6Files({
'index.js': ['lib/cli/validate-engines.js'],
'lib/cli/validate-engines.js': ['package.json', 'lib/cli/index.js'],
}),
}
5 changes: 0 additions & 5 deletions .eslintrc.local.json

This file was deleted.

94 changes: 94 additions & 0 deletions .github/workflows/ci-npmcli-mock-globals.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# This file is automatically added by @npmcli/template-oss. Do not edit.

name: CI - @npmcli/mock-globals

on:
workflow_dispatch:
pull_request:
paths:
- mock-globals/**
push:
branches:
- main
- latest
paths:
- mock-globals/**
schedule:
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
- cron: "0 9 * * 1"

jobs:
lint:
name: Lint
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm
- name: Reset Deps
run: node . run resetdeps
- name: Lint
run: node . run lint --ignore-scripts -w @npmcli/mock-globals
- name: Post Lint
run: node . run postlint --ignore-scripts -w @npmcli/mock-globals

test:
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
if: github.repository_owner == 'npm'
strategy:
fail-fast: false
matrix:
platform:
- name: Linux
os: ubuntu-latest
shell: bash
- name: macOS
os: macos-latest
shell: bash
- name: Windows
os: windows-latest
shell: cmd
node-version:
- 14.17.0
- 14.x
- 16.13.0
- 16.x
- 18.0.0
- 18.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Reset Deps
run: node . run resetdeps
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
run: node . test --ignore-scripts -w @npmcli/mock-globals
- name: Check Git Status
if: matrix && matrix.platform.os != 'windows-latest'
run: node scripts/git-dirty.js
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- smoke-tests/**
- mock-registry/**
- workspaces/**
- mock-globals/**
push:
branches:
- main
Expand All @@ -19,6 +20,7 @@ on:
- smoke-tests/**
- mock-registry/**
- workspaces/**
- mock-globals/**
schedule:
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
- cron: "0 9 * * 1"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@
!/workspaces/libnpmsearch/
!/workspaces/libnpmteam/
!/workspaces/libnpmversion/
!/mock-globals/
30 changes: 25 additions & 5 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ graph LR;
npm-->npmcli-fs["@npmcli/fs"];
npm-->npmcli-git["@npmcli/git"];
npm-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npm-->npmcli-mock-globals["@npmcli/mock-globals"];
npm-->npmcli-mock-registry["@npmcli/mock-registry"];
npm-->npmcli-package-json["@npmcli/package-json"];
npm-->npmcli-promise-spawn["@npmcli/promise-spawn"];
Expand Down Expand Up @@ -186,13 +187,18 @@ graph LR;
npmcli-arborist-->treeverse;
npmcli-config-->ini;
npmcli-config-->nopt;
npmcli-config-->npm-registry-fetch;
npmcli-config-->npmcli-arborist["@npmcli/arborist"];
npmcli-config-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npmcli-config-->npmcli-mock-globals["@npmcli/mock-globals"];
npmcli-config-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npmcli-config-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-config-->proc-log;
npmcli-config-->read-package-json-fast;
npmcli-config-->semver;
npmcli-docs-->ignore-walk;
npmcli-docs-->npmcli-config["@npmcli/config"];
npmcli-docs-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-docs-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-fs-->semver;
Expand All @@ -208,6 +214,8 @@ graph LR;
npmcli-metavuln-calculator-->json-parse-even-better-errors;
npmcli-metavuln-calculator-->pacote;
npmcli-metavuln-calculator-->semver;
npmcli-mock-globals-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-mock-globals-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-mock-registry-->npm-package-arg;
npmcli-mock-registry-->npmcli-arborist["@npmcli/arborist"];
npmcli-mock-registry-->npmcli-eslint-config["@npmcli/eslint-config"];
Expand Down Expand Up @@ -530,6 +538,7 @@ graph LR;
npm-->npmcli-fs["@npmcli/fs"];
npm-->npmcli-git["@npmcli/git"];
npm-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npm-->npmcli-mock-globals["@npmcli/mock-globals"];
npm-->npmcli-mock-registry["@npmcli/mock-registry"];
npm-->npmcli-package-json["@npmcli/package-json"];
npm-->npmcli-promise-spawn["@npmcli/promise-spawn"];
Expand Down Expand Up @@ -621,22 +630,30 @@ graph LR;
npmcli-arborist-->tcompare;
npmcli-arborist-->treeverse;
npmcli-arborist-->walk-up-path;
npmcli-config-->ci-info;
npmcli-config-->ini;
npmcli-config-->isaacs-string-locale-compare["@isaacs/string-locale-compare"];
npmcli-config-->nopt;
npmcli-config-->npm-registry-fetch;
npmcli-config-->npmcli-arborist["@npmcli/arborist"];
npmcli-config-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npmcli-config-->npmcli-mock-globals["@npmcli/mock-globals"];
npmcli-config-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npmcli-config-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-config-->proc-log;
npmcli-config-->read-package-json-fast;
npmcli-config-->semver;
npmcli-config-->tap;
npmcli-config-->walk-up-path;
npmcli-config-->which;
npmcli-disparity-colors-->ansi-styles;
npmcli-docs-->front-matter;
npmcli-docs-->ignore-walk;
npmcli-docs-->isaacs-string-locale-compare["@isaacs/string-locale-compare"];
npmcli-docs-->jsdom;
npmcli-docs-->mkdirp;
npmcli-docs-->npmcli-config["@npmcli/config"];
npmcli-docs-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-docs-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-docs-->rehype-stringify;
Expand Down Expand Up @@ -667,6 +684,9 @@ graph LR;
npmcli-metavuln-calculator-->json-parse-even-better-errors;
npmcli-metavuln-calculator-->pacote;
npmcli-metavuln-calculator-->semver;
npmcli-mock-globals-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-mock-globals-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-mock-globals-->tap;
npmcli-mock-registry-->nock;
npmcli-mock-registry-->npm-package-arg;
npmcli-mock-registry-->npmcli-arborist["@npmcli/arborist"];
Expand Down Expand Up @@ -777,13 +797,13 @@ Each group depends on packages lower down the chain, nothing depends on
packages higher up the chain.

- npm
- @npmcli/smoke-tests, libnpmaccess, libnpmexec, libnpmpublish
- @npmcli/mock-registry, libnpmdiff, libnpmfund, libnpmpack
- @npmcli/docs, @npmcli/smoke-tests, libnpmaccess, libnpmexec, libnpmpublish
- @npmcli/config, @npmcli/mock-registry, libnpmdiff, libnpmfund, libnpmpack
- @npmcli/arborist
- @npmcli/metavuln-calculator
- pacote, libnpmhook, libnpmorg, libnpmsearch, libnpmteam, npm-profile
- npm-registry-fetch, libnpmversion
- @npmcli/git, make-fetch-happen, @npmcli/config, init-package-json
- @npmcli/git, make-fetch-happen, init-package-json
- @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, @npmcli/run-script, read-package-json, promzard
- @npmcli/docs, @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, npm-packlist, normalize-package-data, @npmcli/package-json, bin-links, nopt, npmlog, parse-conflict-json, read
- @npmcli/eslint-config, @npmcli/template-oss, ignore-walk, semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, treeverse, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate
- @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, npm-packlist, normalize-package-data, @npmcli/package-json, bin-links, nopt, npmlog, parse-conflict-json, @npmcli/mock-globals, read
- semver, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, fs-minipass, ssri, unique-slug, @npmcli/promise-spawn, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, ignore-walk, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, treeverse, @npmcli/eslint-config, @npmcli/template-oss, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate
7 changes: 2 additions & 5 deletions bin/npx-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ const removed = new Set([
...removedOpts,
])

const { definitions, shorthands } = require('../lib/utils/config/index.js')
const npmSwitches = Object.entries(definitions)
.filter(([key, { type }]) => type === Boolean ||
(Array.isArray(type) && type.includes(Boolean)))
.map(([key]) => key)
const { definitions, shorthands, definitionKeys } = require('@npmcli/config')
const npmSwitches = definitionKeys.filter(k => definitions[k].hasNonBoolean)

// things that don't take a value
const switches = new Set([
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { join, basename, resolve } = require('path')
const transformHTML = require('./transform-html.js')
const { version } = require('../../lib/npm.js')
const { aliases } = require('../../lib/utils/cmd-list')
const { shorthands, definitions } = require('../../lib/utils/config/index.js')
const { shorthands, definitions } = require('@npmcli/config')

const DOC_EXT = '.md'

Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"@isaacs/string-locale-compare": "^1.1.0",
"@npmcli/config": "^6.1.0",
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.11.0",
"front-matter": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (require.main === module) {
require('./lib/cli.js')(process)
require('./lib/cli/validate-engines.js')(process)
} else {
throw new Error('The programmatic API was removed in npm v8.0.0')
}
Loading