Skip to content

Commit

Permalink
@tommy-mitchell feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Feb 23, 2024
1 parent 3163835 commit c8cba01
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions source/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.d.ts
4 changes: 3 additions & 1 deletion source/cli-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version>
Expand Down
10 changes: 5 additions & 5 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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';

Expand Down Expand Up @@ -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);
}

Expand Down
22 changes: 11 additions & 11 deletions source/package-manager/index.js
Original file line number Diff line number Diff line change
@@ -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));
}

/**
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions source/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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}) => {
Expand Down
2 changes: 1 addition & 1 deletion source/util.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/tasks/prerequisite-tasks.js
Original file line number Diff line number Diff line change
@@ -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<typeof _createFixture<import('../../source/prerequisite-tasks.js')>>} */
const createFixture = _createFixture('../../source/prerequisite-tasks.js', import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion test/ui/prompts/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}});

Expand Down

0 comments on commit c8cba01

Please sign in to comment.