Skip to content

Commit

Permalink
Internal improvements, add more tests (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Sep 2, 2023
1 parent 885cc94 commit 1cb22e0
Show file tree
Hide file tree
Showing 93 changed files with 3,446 additions and 1,056 deletions.
46 changes: 28 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,60 +31,70 @@
"commit"
],
"dependencies": {
"chalk": "^5.2.0",
"chalk": "^5.3.0",
"chalk-template": "^1.1.0",
"cosmiconfig": "^8.1.3",
"del": "^7.0.0",
"del": "^7.1.0",
"escape-goat": "^4.0.0",
"escape-string-regexp": "^5.0.0",
"execa": "^7.1.1",
"exit-hook": "^3.2.0",
"execa": "^8.0.1",
"exit-hook": "^4.0.0",
"github-url-from-git": "^1.5.0",
"has-yarn": "^3.0.0",
"hosted-git-info": "^6.1.1",
"hosted-git-info": "^7.0.0",
"ignore-walk": "^6.0.3",
"import-local": "^3.1.0",
"inquirer": "^9.2.6",
"inquirer": "^9.2.10",
"is-installed-globally": "^0.4.0",
"is-interactive": "^2.0.0",
"is-scoped": "^3.0.0",
"issue-regex": "^4.1.0",
"listr": "^0.14.3",
"listr-input": "^0.2.1",
"log-symbols": "^5.1.0",
"meow": "^12.0.1",
"meow": "^12.1.1",
"new-github-release-url": "^2.0.0",
"npm-name": "^7.1.0",
"onetime": "^6.0.0",
"open": "^9.1.0",
"ow": "^1.1.1",
"p-memoize": "^7.1.1",
"p-timeout": "^6.1.1",
"p-timeout": "^6.1.2",
"path-exists": "^5.0.0",
"pkg-dir": "^7.0.0",
"read-pkg-up": "^9.1.0",
"read-pkg": "^8.1.0",
"read-pkg-up": "^10.1.0",
"rxjs": "^7.8.1",
"semver": "^7.5.1",
"semver": "^7.5.4",
"symbol-observable": "^4.0.0",
"terminal-link": "^3.0.0",
"update-notifier": "^6.0.2"
},
"devDependencies": {
"ava": "^5.3.0",
"@sindresorhus/is": "^6.0.0",
"@types/semver": "^7.5.1",
"ava": "^5.3.1",
"common-tags": "^1.8.2",
"esmock": "^2.2.3",
"esmock": "^2.3.8",
"fs-extra": "^11.1.1",
"move-file": "^3.1.0",
"sinon": "^15.1.0",
"tempy": "^3.0.0",
"write-pkg": "^5.1.0",
"xo": "^0.54.2"
"map-obj": "^5.0.2",
"sinon": "^15.2.0",
"strip-ansi": "^7.1.0",
"tempy": "^3.1.0",
"write-pkg": "^6.0.0",
"xo": "^0.56.0"
},
"ava": {
"files": [
"!test/fixtures",
"!test/_helpers"
],
"environmentVariables": {
"FORCE_HYPERLINK": "1"
},
"nodeArguments": [
"--loader=esmock"
"--loader=esmock",
"--no-warnings=ExperimentalWarning"
]
}
}
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ $ np --help
$ np <version>
Version can be:
patch | minor | major | prepatch | preminor | premajor | prerelease | 1.2.3
major | minor | patch | premajor | preminor | prepatch | prerelease | 1.2.3
Options
--any-branch Allow publishing from any branch
Expand All @@ -87,7 +87,7 @@ $ np --help
--no-yarn Don't use Yarn
--contents Subdirectory to publish
--no-release-draft Skips opening a GitHub release draft
--release-draft-only Only opens a GitHub release draft
--release-draft-only Only opens a GitHub release draft for the latest published version
--test-script Name of npm run script to run tests before publishing (default: test)
--no-2fa Don't enable 2FA on new packages (not recommended)
--message Version bump commit message. `%s` will be replaced with version. (default: '%s' with npm and 'v%s' with yarn)
Expand All @@ -113,7 +113,7 @@ Run `np` without arguments to launch the interactive UI that guides you through
Currently, these are the flags you can configure:

- `anyBranch` - Allow publishing from any branch (`false` by default).
- `branch` - Name of the release branch (`master` by default).
- `branch` - Name of the release branch (`main` or `master` by default).
- `cleanup` - Cleanup `node_modules` (`true` by default).
- `tests` - Run `npm test` (`true` by default).
- `yolo` - Skip cleanup and testing (`false` by default).
Expand Down Expand Up @@ -346,6 +346,8 @@ npm ERR! 403 Forbidden - GET https://registry.yarnpkg.com/-/package/my-awesome-p
"publishConfig": {
"registry": "https://registry.npmjs.org"
}

Note: On `npm` v9+, the command has been changed to `npm access list collaborators my-awesome-package`.
```

## Maintainers
Expand Down
33 changes: 15 additions & 18 deletions source/cli-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import config from './config.js';
import * as util from './util.js';
import * as git from './git-util.js';
import * as npm from './npm/util.js';
import Version from './version.js';
import {SEMVER_INCREMENTS} from './version.js';
import ui from './ui.js';
import np from './index.js';

Expand All @@ -19,7 +19,7 @@ const cli = meow(`
$ np <version>
Version can be:
${Version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
${SEMVER_INCREMENTS.join(' | ')} | 1.2.3
Options
--any-branch Allow publishing from any branch
Expand Down Expand Up @@ -56,18 +56,22 @@ const cli = meow(`
},
cleanup: {
type: 'boolean',
default: true,
},
tests: {
type: 'boolean',
default: true,
},
yolo: {
type: 'boolean',
},
publish: {
type: 'boolean',
default: true,
},
releaseDraft: {
type: 'boolean',
default: true,
},
releaseDraftOnly: {
type: 'boolean',
Expand All @@ -77,6 +81,7 @@ const cli = meow(`
},
yarn: {
type: 'boolean',
default: hasYarn(),
},
contents: {
type: 'string',
Expand All @@ -89,6 +94,7 @@ const cli = meow(`
},
'2fa': {
type: 'boolean',
default: true,
},
message: {
type: 'string',
Expand All @@ -101,19 +107,8 @@ updateNotifier({pkg: cli.pkg}).notify();
try {
const {pkg, rootDir} = await util.readPkg(cli.flags.contents);

const defaultFlags = {
cleanup: true,
tests: true,
publish: true,
releaseDraft: true,
yarn: hasYarn(),
'2fa': true,
};

const localConfig = await config(rootDir);

const flags = {
...defaultFlags,
...localConfig,
...cli.flags,
};
Expand All @@ -125,20 +120,22 @@ try {

const runPublish = !flags.releaseDraftOnly && flags.publish && !pkg.private;

const availability = flags.publish ? await npm.isPackageNameAvailable(pkg) : {
// TODO: does this need to run if `runPublish` is false?
const availability = runPublish ? await npm.isPackageNameAvailable(pkg) : {
isAvailable: false,
isUnknown: false,
};

// Use current (latest) version when 'releaseDraftOnly', otherwise use the first argument.
const version = flags.releaseDraftOnly ? pkg.version : (cli.input.length > 0 ? cli.input[0] : false);
// Use current (latest) version when 'releaseDraftOnly', otherwise try to use the first argument.
const version = flags.releaseDraftOnly ? pkg.version : cli.input.at(0);

const branch = flags.branch ?? await git.defaultBranch();

const branch = flags.branch || await git.defaultBranch();
const options = await ui({
...flags,
runPublish,
availability,
version,
runPublish,
branch,
}, {pkg, rootDir});

Expand Down
4 changes: 1 addition & 3 deletions source/cli.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env node
import {fileURLToPath} from 'node:url';
import {debuglog} from 'node:util';
import importLocal from 'import-local';
import isInstalledGlobally from 'is-installed-globally';

const __filename = fileURLToPath(import.meta.url);
const log = debuglog('np');

// Prefer the local installation
if (!importLocal(__filename)) {
if (!importLocal(import.meta.url)) {
if (isInstalledGlobally) {
log('Using global install of np.');
}
Expand Down
2 changes: 1 addition & 1 deletion source/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import os from 'node:os';
import isInstalledGlobally from 'is-installed-globally';
import {cosmiconfig} from 'cosmiconfig';

// TODO: remove when cosmiconfig/cosmiconfig#283 lands
// TODO: Remove when cosmiconfig/cosmiconfig#283 lands
const loadESM = async filepath => {
const module = await import(filepath);
return module.default ?? module;
Expand Down

0 comments on commit 1cb22e0

Please sign in to comment.