From 54696148f25986bcdf39e1acb5aca4bf09e7d1a0 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 2 Apr 2024 07:09:27 -0700 Subject: [PATCH] deps: read@3.0.1 (#7327) deps: init-package-json@6.0.2 deps: promzard@1.0.1 --- DEPENDENCIES.md | 8 +- lib/utils/read-user-info.js | 2 +- .../lib/init-package-json.js | 115 +++++++++--------- node_modules/init-package-json/package.json | 26 ++-- node_modules/promzard/lib/index.js | 2 +- node_modules/promzard/package.json | 11 +- node_modules/read/dist/commonjs/package.json | 3 + node_modules/read/dist/commonjs/read.js | 95 +++++++++++++++ node_modules/read/dist/esm/package.json | 3 + node_modules/read/dist/esm/read.js | 88 ++++++++++++++ node_modules/read/lib/read.js | 82 ------------- node_modules/read/package.json | 77 ++++++++---- package-lock.json | 32 ++--- package.json | 4 +- scripts/publish.js | 2 +- .../tap-snapshots/test/index.js.test.cjs | 6 +- test/lib/utils/read-user-info.js | 4 +- workspaces/libnpmexec/lib/index.js | 2 +- workspaces/libnpmexec/package.json | 2 +- workspaces/libnpmexec/test/prompt.js | 8 +- 20 files changed, 352 insertions(+), 220 deletions(-) create mode 100644 node_modules/read/dist/commonjs/package.json create mode 100644 node_modules/read/dist/commonjs/read.js create mode 100644 node_modules/read/dist/esm/package.json create mode 100644 node_modules/read/dist/esm/read.js delete mode 100644 node_modules/read/lib/read.js diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index e13d24bbfd4f5..0178b70d104c2 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -12,8 +12,8 @@ graph LR; cacache-->ssri; cacache-->unique-filename; init-package-json-->npm-package-arg; + init-package-json-->npmcli-package-json["@npmcli/package-json"]; init-package-json-->promzard; - init-package-json-->read-package-json; init-package-json-->read; init-package-json-->semver; init-package-json-->validate-npm-package-name; @@ -322,8 +322,8 @@ graph LR; iconv-lite-->safer-buffer; ignore-walk-->minimatch; init-package-json-->npm-package-arg; + init-package-json-->npmcli-package-json["@npmcli/package-json"]; init-package-json-->promzard; - init-package-json-->read-package-json; init-package-json-->read; init-package-json-->semver; init-package-json-->validate-npm-package-license; @@ -826,9 +826,9 @@ packages higher up the chain. - @npmcli/arborist - @npmcli/metavuln-calculator - pacote, libnpmversion - - @npmcli/run-script, libnpmhook, libnpmorg, libnpmsearch, libnpmteam, npm-profile + - @npmcli/run-script, libnpmhook, libnpmorg, libnpmsearch, libnpmteam, init-package-json, npm-profile - @npmcli/package-json, npm-registry-fetch - - @npmcli/git, make-fetch-happen, @npmcli/config, init-package-json + - @npmcli/git, make-fetch-happen, @npmcli/config - @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, read-package-json, promzard - @npmcli/docs, @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, npm-install-checks, npm-package-arg, normalize-package-data, npm-packlist, bin-links, nopt, npmlog, parse-conflict-json, @npmcli/mock-globals, 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, @npmcli/agent, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, minify-registry-metadata, ini, @npmcli/disparity-colors, mute-stream, npm-audit-report, npm-user-validate diff --git a/lib/utils/read-user-info.js b/lib/utils/read-user-info.js index 1cac8ee6d2668..fa1cea158e897 100644 --- a/lib/utils/read-user-info.js +++ b/lib/utils/read-user-info.js @@ -1,4 +1,4 @@ -const read = require('read') +const { read } = require('read') const userValidate = require('npm-user-validate') const log = require('./log-shim.js') diff --git a/node_modules/init-package-json/lib/init-package-json.js b/node_modules/init-package-json/lib/init-package-json.js index 077ebd96ffc52..23fd3dc94dbe4 100644 --- a/node_modules/init-package-json/lib/init-package-json.js +++ b/node_modules/init-package-json/lib/init-package-json.js @@ -1,29 +1,28 @@ const promzard = require('promzard') const path = require('path') -const fs = require('fs/promises') const semver = require('semver') -const read = require('read') +const { read } = require('read') const util = require('util') -const rpj = require('read-package-json') +const PackageJson = require('@npmcli/package-json') const def = require.resolve('./default-input.js') -// to validate the data object at the end as a worthwhile package -// and assign default values for things. -const _extraSet = rpj.extraSet -const _rpj = util.promisify(rpj) -const _rpjExtras = util.promisify(rpj.extras) -const readPkgJson = async (file, pkg) => { - // only do a few of these. no need for mans or contributors if they're in the files - rpj.extraSet = _extraSet.filter(f => f.name !== 'authors' && f.name !== 'mans') - const p = pkg ? _rpjExtras(file, pkg) : _rpj(file) - return p.catch(() => ({})).finally(() => rpj.extraSet = _extraSet) -} +const extras = [ + 'bundleDependencies', + 'gypfile', + 'serverjs', + 'scriptpath', + 'readme', + 'bin', + 'githead', + 'fillTypes', + 'normalizeData', +] const isYes = (c) => !!(c.get('yes') || c.get('y') || c.get('force') || c.get('f')) -const getConfig = (c = {}) => { +const getConfig = (c) => { // accept either a plain-jane object, or a config object with a "get" method. if (typeof c.get !== 'function') { const data = c @@ -35,25 +34,31 @@ const getConfig = (c = {}) => { return c } +// Coverage disabled because this is just walking back the fixPeople +// normalization from the normalizeData step and we don't need to re-test all +// of those paths. +/* istanbul ignore next */ const stringifyPerson = (p) => { - if (typeof p === 'string') { - return p - } - const { name = '', url, web, email, mail } = p + const { name, url, web, email, mail } = p const u = url || web const e = email || mail return `${name}${e ? ` <${e}>` : ''}${u ? ` (${u})` : ''}` } - -async function init (dir, input = def, c = {}) { +async function init (dir, + // TODO test for non-default definitions + /* istanbul ignore next */ + input = def, + c = {}) { const config = getConfig(c) const yes = isYes(config) const packageFile = path.resolve(dir, 'package.json') - const pkg = await readPkgJson(packageFile) + // read what's already there to inform our prompts + const pkg = await PackageJson.load(dir, { create: true }) + await pkg.normalize() - if (!semver.valid(pkg.version)) { - delete pkg.version + if (!semver.valid(pkg.content.version)) { + delete pkg.content.version } // make sure that the input is valid. if not, use the default @@ -61,73 +66,67 @@ async function init (dir, input = def, c = {}) { yes, config, filename: packageFile, - dirname: path.dirname(packageFile), - basename: path.basename(path.dirname(packageFile)), - package: pkg, + dirname: dir, + basename: path.basename(dir), + package: pkg.content, }, { backupFile: def }) for (const [k, v] of Object.entries(pzData)) { if (v != null) { - pkg[k] = v + pkg.content[k] = v } } - const pkgExtras = await readPkgJson(packageFile, pkg) + await pkg.normalize({ steps: extras }) - // turn the objects into somewhat more humane strings. - if (pkgExtras.author) { - pkgExtras.author = stringifyPerson(pkgExtras.author) - } - - for (const set of ['maintainers', 'contributors']) { - if (Array.isArray(pkgExtras[set])) { - pkgExtras[set] = pkgExtras[set].map(stringifyPerson) - } + // turn the objects back into somewhat more humane strings. + // "normalizeData" does this and there isn't a way to choose which of those steps happen + if (pkg.content.author) { + pkg.content.author = stringifyPerson(pkg.content.author) } // no need for the readme now. - delete pkgExtras.readme - delete pkgExtras.readmeFilename + delete pkg.content.readme + delete pkg.content.readmeFilename // really don't want to have this lying around in the file - delete pkgExtras._id + delete pkg.content._id // ditto - delete pkgExtras.gitHead + delete pkg.content.gitHead // if the repo is empty, remove it. - if (!pkgExtras.repository) { - delete pkgExtras.repository + if (!pkg.content.repository) { + delete pkg.content.repository } // readJson filters out empty descriptions, but init-package-json // traditionally leaves them alone - if (!pkgExtras.description) { - pkgExtras.description = pzData.description + if (!pkg.content.description) { + pkg.content.description = pzData.description } // optionalDependencies don't need to be repeated in two places - if (pkgExtras.dependencies) { - if (pkgExtras.optionalDependencies) { - for (const name of Object.keys(pkgExtras.optionalDependencies)) { - delete pkgExtras.dependencies[name] + if (pkg.content.dependencies) { + if (pkg.content.optionalDependencies) { + for (const name of Object.keys(pkg.content.optionalDependencies)) { + delete pkg.content.dependencies[name] } } - if (Object.keys(pkgExtras.dependencies).length === 0) { - delete pkgExtras.dependencies + if (Object.keys(pkg.content.dependencies).length === 0) { + delete pkg.content.dependencies } } - const stringified = JSON.stringify(pkgExtras, null, 2) + '\n' + const stringified = JSON.stringify(pkg.content, null, 2) + '\n' const msg = util.format('%s:\n\n%s\n', packageFile, stringified) - const write = () => fs.writeFile(packageFile, stringified, 'utf8') if (yes) { - await write() + await pkg.save() if (!config.get('silent')) { console.log(`Wrote to ${msg}`) } - return pkgExtras + return pkg.content } console.log(`About to write to ${msg}`) @@ -137,8 +136,8 @@ async function init (dir, input = def, c = {}) { return } - await write() - return pkgExtras + await pkg.save() + return pkg.content } module.exports = init diff --git a/node_modules/init-package-json/package.json b/node_modules/init-package-json/package.json index a164169a74df3..e867964e10156 100644 --- a/node_modules/init-package-json/package.json +++ b/node_modules/init-package-json/package.json @@ -1,10 +1,10 @@ { "name": "init-package-json", - "version": "6.0.0", + "version": "6.0.2", "main": "lib/init-package-json.js", "scripts": { "test": "tap", - "lint": "eslint \"**/*.js\"", + "lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"", "postlint": "template-oss-check", "lintfix": "npm run lint -- --fix", "snap": "tap", @@ -19,28 +19,24 @@ "license": "ISC", "description": "A node module to get your node module started", "dependencies": { + "@npmcli/package-json": "^5.0.0", "npm-package-arg": "^11.0.0", "promzard": "^1.0.0", - "read": "^2.0.0", - "read-package-json": "^7.0.0", + "read": "^3.0.1", "semver": "^7.3.5", "validate-npm-package-license": "^3.0.4", "validate-npm-package-name": "^5.0.0" }, "devDependencies": { - "@npmcli/config": "^7.0.0", + "@npmcli/config": "^8.2.0", "@npmcli/eslint-config": "^4.0.0", - "@npmcli/template-oss": "4.18.0", + "@npmcli/template-oss": "4.21.3", "tap": "^16.0.1" }, "engines": { "node": "^16.14.0 || >=18.0.0" }, "tap": { - "statements": 95, - "branches": 78, - "lines": 94, - "jobs": 1, "test-ignore": "fixtures/", "nyc-arg": [ "--exclude", @@ -63,13 +59,7 @@ ], "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "version": "4.18.0", - "publish": true, - "ciVersions": [ - "16.14.0", - "16.x", - "18.0.0", - "18.x" - ] + "version": "4.21.3", + "publish": true } } diff --git a/node_modules/promzard/lib/index.js b/node_modules/promzard/lib/index.js index 2244cbbbacdb0..52c8a3c828313 100644 --- a/node_modules/promzard/lib/index.js +++ b/node_modules/promzard/lib/index.js @@ -4,7 +4,7 @@ const { promisify } = require('util') const { randomBytes } = require('crypto') const { Module } = require('module') const { dirname, basename } = require('path') -const read = require('read') +const { read } = require('read') const files = {} diff --git a/node_modules/promzard/package.json b/node_modules/promzard/package.json index a48764dd5441b..a4253193232b8 100644 --- a/node_modules/promzard/package.json +++ b/node_modules/promzard/package.json @@ -2,23 +2,23 @@ "author": "GitHub Inc.", "name": "promzard", "description": "prompting wizardly", - "version": "1.0.0", + "version": "1.0.1", "repository": { "url": "https://github.com/npm/promzard.git", "type": "git" }, "dependencies": { - "read": "^2.0.0" + "read": "^3.0.1" }, "devDependencies": { "@npmcli/eslint-config": "^4.0.0", - "@npmcli/template-oss": "4.11.0", + "@npmcli/template-oss": "4.21.3", "tap": "^16.3.0" }, "main": "lib/index.js", "scripts": { "test": "tap", - "lint": "eslint \"**/*.js\"", + "lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "lintfix": "npm run lint -- --fix", @@ -35,7 +35,8 @@ }, "templateOSS": { "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", - "version": "4.11.0" + "version": "4.21.3", + "publish": true }, "tap": { "jobs": 1, diff --git a/node_modules/read/dist/commonjs/package.json b/node_modules/read/dist/commonjs/package.json new file mode 100644 index 0000000000000..5bbefffbabee3 --- /dev/null +++ b/node_modules/read/dist/commonjs/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/node_modules/read/dist/commonjs/read.js b/node_modules/read/dist/commonjs/read.js new file mode 100644 index 0000000000000..bab433d8a1155 --- /dev/null +++ b/node_modules/read/dist/commonjs/read.js @@ -0,0 +1,95 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.read = void 0; +const mute_stream_1 = __importDefault(require("mute-stream")); +const readline_1 = require("readline"); +async function read({ default: def, input = process.stdin, output = process.stdout, completer, prompt = '', silent, timeout, edit, terminal, replace, }) { + if (typeof def !== 'undefined' && + typeof def !== 'string' && + typeof def !== 'number') { + throw new Error('default value must be string or number'); + } + let editDef = false; + const defString = def?.toString(); + prompt = prompt.trim() + ' '; + terminal = !!(terminal || output.isTTY); + if (defString) { + if (silent) { + prompt += '(