From c8cba01a6730dbc0fad9529b449e214d84ab46be Mon Sep 17 00:00:00 2001 From: Misha Kaletsky Date: Fri, 23 Feb 2024 16:02:49 -0500 Subject: [PATCH] @tommy-mitchell feedback --- source/.npmignore | 1 + source/cli-implementation.js | 4 +++- source/index.js | 10 +++++----- source/package-manager/index.js | 22 +++++++++++----------- source/ui.js | 4 ++-- source/util.js | 2 +- test/tasks/prerequisite-tasks.js | 2 +- test/ui/prompts/tags.js | 2 +- 8 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 source/.npmignore diff --git a/source/.npmignore b/source/.npmignore new file mode 100644 index 00000000..cd4efd8e --- /dev/null +++ b/source/.npmignore @@ -0,0 +1 @@ +*.d.ts diff --git a/source/cli-implementation.js b/source/cli-implementation.js index 57b03886..c13fa608 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -13,7 +13,9 @@ import {SEMVER_INCREMENTS} from './version.js'; import ui from './ui.js'; import np from './index.js'; -export const cli = meow(` +/** @typedef {typeof cli} CLI */ + +const cli = meow(` Usage $ np diff --git a/source/index.js b/source/index.js index 07a2d7e0..f5484dba 100644 --- a/source/index.js +++ b/source/index.js @@ -8,14 +8,14 @@ import {asyncExitHook} from 'exit-hook'; import logSymbols from 'log-symbols'; import prerequisiteTasks from './prerequisite-tasks.js'; import gitTasks from './git-tasks.js'; -import {getPackagePublishArguments as getAdditionalPackagePublishArguments} from './npm/publish.js'; +import {getPackagePublishArguments} from './npm/publish.js'; import enable2fa, {getEnable2faArgs} from './npm/enable-2fa.js'; +import handleNpmError from './npm/handle-npm-error.js'; import releaseTaskHelper from './release-task-helper.js'; +import {findLockfile, getPackageManagerConfig, printCommand} from './package-manager/index.js'; import * as util from './util.js'; import * as git from './git-util.js'; import * as npm from './npm/util.js'; -import {findLockFile, getPackageManagerConfig, printCommand} from './package-manager/index.js'; -import handleNpmError from './npm/handle-npm-error.js'; /** @type {(cmd: string, args: string[], options?: import('execa').Options) => any} */ const exec = (cmd, args, options) => { @@ -40,7 +40,7 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => { const runTests = options.tests && !options.yolo; const runCleanup = options.cleanup && !options.yolo; - const lockfile = findLockFile(rootDir, pkgManager); + const lockfile = findLockfile(rootDir, pkgManager); const isOnGitHub = options.repoUrl && hostedGitInfo.fromUrl(options.repoUrl)?.type === 'github'; const testScript = options.testScript || 'test'; @@ -98,7 +98,7 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => { /** @param {typeof options} _options */ function getPublishCommand(_options) { const publishCommand = pkgManager.publishCommand || (args => [pkgManager.cli, args]); - const args = getAdditionalPackagePublishArguments(_options); + const args = getPackagePublishArguments(_options); return publishCommand(args); } diff --git a/source/package-manager/index.js b/source/package-manager/index.js index 252014f4..93252f72 100644 --- a/source/package-manager/index.js +++ b/source/package-manager/index.js @@ -1,16 +1,16 @@ import fs from 'node:fs'; import path from 'node:path'; import semver from 'semver'; -import {npmConfig, yarnBerryConfig, pnpmConfig, yarnConfig} from './configs.js'; +import * as configs from './configs.js'; /** @param {string} rootDir @param {import('./types.d.ts').PackageManagerConfig} config */ -export function findLockFile(rootDir, config) { +export function findLockfile(rootDir, config) { return config.lockfiles - .map(filename => ({filename, filepath: path.resolve(rootDir || '.', filename)})) - .find(({filepath}) => fs.existsSync(filepath)); + .map(filename => path.resolve(rootDir || '.', filename)) + .find(filepath => fs.existsSync(filepath)); } /** @@ -19,7 +19,7 @@ export function findLockFile(rootDir, config) { */ export function getPackageManagerConfig(rootDir, pkg) { const config = configFromPackageManagerField(pkg); - return config || configFromLockfile(rootDir) || npmConfig; + return config || configFromLockfile(rootDir) || configs.npmConfig; } /** @param {import('read-pkg').NormalizedPackageJson} pkg */ @@ -31,27 +31,27 @@ function configFromPackageManagerField(pkg) { const [packageManager, version] = pkg.packageManager.split('@'); if (packageManager === 'yarn' && version && semver.gte(version, '2.0.0')) { - return yarnBerryConfig; + return configs.yarnBerryConfig; } if (packageManager === 'npm') { - return npmConfig; + return configs.npmConfig; } if (packageManager === 'pnpm') { - return pnpmConfig; + return configs.pnpmConfig; } if (packageManager === 'yarn') { - return yarnConfig; + return configs.yarnConfig; } throw new Error(`Invalid package manager: ${pkg.packageManager}`); } /** @param {string} rootDir */ -function configFromLockfile(rootDir, options = [npmConfig, pnpmConfig, yarnConfig]) { - return options.find(config => findLockFile(rootDir, config)); +function configFromLockfile(rootDir, options = [configs.npmConfig, configs.pnpmConfig, configs.yarnConfig]) { + return options.find(config => findLockfile(rootDir, config)); } /** @param {import('./types.d.ts').Command} command */ diff --git a/source/ui.js b/source/ui.js index e4ea2f25..115c08a8 100644 --- a/source/ui.js +++ b/source/ui.js @@ -5,11 +5,11 @@ import {htmlEscape} from 'escape-goat'; import isScoped from 'is-scoped'; import isInteractive from 'is-interactive'; import {execa} from 'execa'; +import {getPackageManagerConfig} from './package-manager/index.js'; import Version, {SEMVER_INCREMENTS} from './version.js'; import * as util from './util.js'; import * as git from './git-util.js'; import * as npm from './npm/util.js'; -import {getPackageManagerConfig} from './package-manager/index.js'; const printCommitLog = async (repoUrl, registryUrl, fromLatestTag, releaseBranch) => { const revision = fromLatestTag ? await git.latestTagOrFirstCommit() : await git.previousTagOrFirstCommit(); @@ -122,7 +122,7 @@ const checkNewFilesAndDependencies = async (pkg, rootDir) => { }; /** -@param {typeof import('./cli-implementation.js').cli['flags']} options +@param {import('./cli-implementation.js').CLI['flags']} options @param {{pkg: import('read-pkg').NormalizedPackageJson; rootDir: string}} context */ const ui = async (options, {pkg, rootDir}) => { diff --git a/source/util.js b/source/util.js index 9cd366cb..e0ea3e66 100644 --- a/source/util.js +++ b/source/util.js @@ -1,13 +1,13 @@ import process from 'node:process'; import {fileURLToPath} from 'node:url'; import path from 'node:path'; -import ow from 'ow'; import {readPackageUp} from 'read-package-up'; import {parsePackage} from 'read-pkg'; import issueRegex from 'issue-regex'; import terminalLink from 'terminal-link'; import {execa} from 'execa'; import pMemoize from 'p-memoize'; +import ow from 'ow'; import chalk from 'chalk'; import Version from './version.js'; import * as git from './git-util.js'; diff --git a/test/tasks/prerequisite-tasks.js b/test/tasks/prerequisite-tasks.js index 4937a2e0..b7480912 100644 --- a/test/tasks/prerequisite-tasks.js +++ b/test/tasks/prerequisite-tasks.js @@ -1,11 +1,11 @@ import process from 'node:process'; import test from 'ava'; +import {npmConfig, yarnConfig} from '../../source/package-manager/configs.js'; import actualPrerequisiteTasks from '../../source/prerequisite-tasks.js'; import {npPkg} from '../../source/util.js'; import {SilentRenderer} from '../_helpers/listr-renderer.js'; import {_createFixture} from '../_helpers/stub-execa.js'; import {run, assertTaskFailed, assertTaskDisabled} from '../_helpers/listr.js'; -import {npmConfig, yarnConfig} from '../../source/package-manager/configs.js'; /** @type {ReturnType>} */ const createFixture = _createFixture('../../source/prerequisite-tasks.js', import.meta.url); diff --git a/test/ui/prompts/tags.js b/test/ui/prompts/tags.js index e95b4899..1cf6acdc 100644 --- a/test/ui/prompts/tags.js +++ b/test/ui/prompts/tags.js @@ -18,7 +18,7 @@ const testUi = test.macro(async (t, {version, tags, answers}, assertions) => { commitLogFromRevision: sinon.stub().resolves(''), }, './package-manager/index.js': { - findLockFile: sinon.stub().resolves(undefined), + findLockfile: sinon.stub().resolves(undefined), }, }});