Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal improvements, add more tests #689

Merged
merged 66 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
d3df4f8
chore: start separating tests
tommy-mitchell Apr 6, 2023
636eb0b
tests(`git`): add tests for `git-util.js`
tommy-mitchell Apr 7, 2023
e822ae9
further separate tests, add `npm` tests, style
tommy-mitchell Apr 8, 2023
22cac30
fix(`git`): move tests to integration, fix `defaultBranch` tests
tommy-mitchell Apr 8, 2023
796595d
tests(`util`): add more tests
tommy-mitchell Apr 8, 2023
af48c4e
feat(`pretty-version-diff`): simplify and add tests
tommy-mitchell Apr 9, 2023
dce03f5
update `Version` API, remove `pretty-version-diff.js`, consolidate ta…
tommy-mitchell Apr 11, 2023
49378f4
fix(`test/index`): incorrect message expectation
tommy-mitchell Apr 11, 2023
993a53e
fix(`version`): passing test marked as failing
tommy-mitchell Apr 11, 2023
f6b988e
chore(`version`): rename `setNewVersionFrom` to `setFrom`
tommy-mitchell Apr 11, 2023
76dd173
chore: bump `semver`
tommy-mitchell Apr 11, 2023
75a2156
fix(`version`): get correct diff
tommy-mitchell Apr 11, 2023
722370b
chore(`version`): use new `semver.RELEASE_TYPES`
tommy-mitchell Apr 11, 2023
9097485
fix(`packed-files`): don't rename `.gitignore`
tommy-mitchell Apr 11, 2023
68997f1
feat(`version`): improved prerelease diffs, more docs
tommy-mitchell Apr 12, 2023
280c66e
feat(`version`): update/document API
tommy-mitchell Apr 13, 2023
21eeab1
tests(`prerequisite-tasks`): test is passing now?
tommy-mitchell Apr 13, 2023
d234532
tests: add more `git` and `npm` tests
tommy-mitchell Apr 14, 2023
d258504
fix: comment out unused imports
tommy-mitchell Apr 14, 2023
7a39e51
docs: update old info on readme
tommy-mitchell Apr 14, 2023
12a3650
add `ui`/`cli` tests, improve `customVersion` validation, style impro…
tommy-mitchell Apr 18, 2023
ef1d2e9
update CI to Node.js 20
tommy-mitchell Apr 18, 2023
b854b81
tests(`cli`): try to fix failure on CI
tommy-mitchell Apr 19, 2023
d675d1f
Merge branch 'main' into improve-tests
tommy-mitchell Apr 19, 2023
9d810a1
feat: add changes from #932, add tests
tommy-mitchell Apr 19, 2023
f2bc525
undo Node.js 20 on CI, issues with `esmock`
tommy-mitchell Apr 19, 2023
2b502c3
Merge branch 'main' into improve-tests
tommy-mitchell Jul 2, 2023
e403bf9
update deps
tommy-mitchell Jul 2, 2023
26accf9
fix(`npm`): incorrect version handling, missing async, style fix
tommy-mitchell Jul 4, 2023
366c8c3
suppress ESM warnings on tests
tommy-mitchell Jul 4, 2023
f5331c4
tests(`npm`): finish adding tests, seperate into own files
tommy-mitchell Jul 4, 2023
bab7bb2
mark tests as failing
tommy-mitchell Jul 4, 2023
438db1e
fix(`npm.collaborators`): revert version change
tommy-mitchell Jul 4, 2023
1ed67ac
remove reminders (added to #684)
tommy-mitchell Jul 4, 2023
da36e87
refactor(`cli`): move defaults into `meow` configuration
tommy-mitchell Jul 4, 2023
7534032
remove todos, update `chalk` usage, grammar tweak
tommy-mitchell Jul 4, 2023
649f7ef
update `esmock` to fix `ui` tests
tommy-mitchell Jul 30, 2023
f3c09b2
fix lint
tommy-mitchell Jul 30, 2023
0d262ea
fix lint
tommy-mitchell Jul 30, 2023
0413d1f
move `util` tests to separate files, fix failing tests, add test for…
tommy-mitchell Jul 31, 2023
676bdfd
move `git-util` tests to separate files
tommy-mitchell Jul 31, 2023
2eefd96
use `git add .` in tests
tommy-mitchell Jul 31, 2023
80cfc9d
fix: await create file
tommy-mitchell Jul 31, 2023
86c3ffd
tests(`hyperlink`): use `esmock`
tommy-mitchell Jul 31, 2023
213d374
fix(`hyperlinks`): mark tests as serial
tommy-mitchell Jul 31, 2023
f869534
tests(`hyperlinks`): properly mock `terminal-link`
tommy-mitchell Jul 31, 2023
a1618c1
rename `test/git` to `test/git-util`
tommy-mitchell Jul 31, 2023
784b2cd
tests(`git-util`): finish testing
tommy-mitchell Jul 31, 2023
53657bf
tests(`inquirer`): log debug messages with AVA
tommy-mitchell Jul 31, 2023
44a045a
handle todos, style tweaks
tommy-mitchell Jul 31, 2023
1cdf40b
fix lint
tommy-mitchell Jul 31, 2023
57c9df4
fix: correct config name
tommy-mitchell Jul 31, 2023
8d5ede5
document test helpers
tommy-mitchell Jul 31, 2023
bdc92fb
Merge branch 'improve-tests' of https://github.com/tommy-mitchell/np …
tommy-mitchell Jul 31, 2023
b286a28
remove todos
tommy-mitchell Jul 31, 2023
4aa52f8
fix: move `chalk-template` to regular deps
tommy-mitchell Jul 31, 2023
f140762
try resolving `util.readPkg` error
tommy-mitchell Aug 2, 2023
b06fc98
better resolution of issue
tommy-mitchell Aug 2, 2023
6ba3b4b
fixes
tommy-mitchell Aug 31, 2023
cd16b94
update deps
tommy-mitchell Aug 31, 2023
c92873c
fix: lint
tommy-mitchell Aug 31, 2023
361b609
fix: missing option in test
tommy-mitchell Aug 31, 2023
e3c5e5c
fix: ignore some checks when `--release-draft-only`
tommy-mitchell Aug 31, 2023
f98b85d
fix(`prerequisite-tasks`): don't double parse version
tommy-mitchell Sep 1, 2023
c6249a2
version style tweaks
tommy-mitchell Sep 1, 2023
a682b51
semver order
tommy-mitchell Sep 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading