Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored Apr 2, 2024
1 parent 9ccff72 commit 5469614
Show file tree
Hide file tree
Showing 20 changed files with 352 additions and 220 deletions.
8 changes: 4 additions & 4 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/utils/read-user-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const read = require('read')
const { read } = require('read')
const userValidate = require('npm-user-validate')
const log = require('./log-shim.js')

Expand Down
115 changes: 57 additions & 58 deletions node_modules/init-package-json/lib/init-package-json.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -35,99 +34,99 @@ 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
const pzData = await promzard(path.resolve(input), {
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}`)
Expand All @@ -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
Expand Down
26 changes: 8 additions & 18 deletions node_modules/init-package-json/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion node_modules/promzard/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
11 changes: 6 additions & 5 deletions node_modules/promzard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions node_modules/read/dist/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
Loading

0 comments on commit 5469614

Please sign in to comment.