Skip to content

Commit

Permalink
Move to ESM, update dependencies (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell authored Apr 3, 2023
1 parent 6867fb9 commit 72879e0
Show file tree
Hide file tree
Showing 42 changed files with 1,362 additions and 1,173 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 10
- 19
- 18
- 16
steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: git config --global user.name "Github Actions"
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion integration-test
Submodule integration-test deleted from b2492e
File renamed without changes
File renamed without changes
File renamed without changes
102 changes: 50 additions & 52 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"license": "MIT",
"repository": "sindresorhus/np",
"funding": "https://github.com/sindresorhus/np?sponsor=1",
"type": "module",
"bin": "source/cli.js",
"engines": {
"node": ">=10",
"npm": ">=6.8.0",
"node": ">=16.6.0",
"npm": ">=7.19.0",
"git": ">=2.11.0",
"yarn": ">=1.7.0"
},
"scripts": {
"test": "xo && FORCE_HYPERLINK=1 ava"
"test": "xo && ava && ava test/integration.js --no-worker-threads"
},
"files": [
"source"
Expand All @@ -30,63 +31,60 @@
"commit"
],
"dependencies": {
"@samverschueren/stream-to-observable": "^0.3.1",
"any-observable": "^0.5.1",
"async-exit-hook": "^2.0.1",
"chalk": "^4.1.0",
"cosmiconfig": "^7.0.0",
"del": "^6.0.0",
"escape-goat": "^3.0.0",
"escape-string-regexp": "^4.0.0",
"execa": "^5.0.0",
"chalk": "^5.2.0",
"cosmiconfig": "^8.1.3",
"del": "^7.0.0",
"escape-goat": "^4.0.0",
"escape-string-regexp": "^5.0.0",
"execa": "^7.1.1",
"exit-hook": "^3.2.0",
"github-url-from-git": "^1.5.0",
"has-yarn": "^2.1.0",
"hosted-git-info": "^3.0.7",
"ignore-walk": "^3.0.3",
"import-local": "^3.0.2",
"inquirer": "^7.3.3",
"is-installed-globally": "^0.3.2",
"is-interactive": "^1.0.0",
"is-scoped": "^2.1.0",
"issue-regex": "^3.1.0",
"has-yarn": "^3.0.0",
"hosted-git-info": "^6.1.1",
"ignore-walk": "^6.0.2",
"import-local": "^3.1.0",
"inquirer": "^9.1.5",
"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": "^4.0.0",
"meow": "^8.1.0",
"minimatch": "^3.0.4",
"new-github-release-url": "^1.0.0",
"npm-name": "^6.0.1",
"onetime": "^5.1.2",
"open": "^7.3.0",
"ow": "^0.21.0",
"p-memoize": "^4.0.1",
"p-timeout": "^4.1.0",
"pkg-dir": "^5.0.0",
"read-pkg-up": "^7.0.1",
"rxjs": "^6.6.3",
"semver": "^7.3.4",
"split": "^1.0.1",
"symbol-observable": "^3.0.0",
"terminal-link": "^2.1.1",
"update-notifier": "^5.0.1"
"log-symbols": "^5.1.0",
"meow": "^11.0.0",
"minimatch": "^8.0.2",
"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",
"pkg-dir": "^7.0.0",
"read-pkg-up": "^9.1.0",
"rxjs": "^7.8.0",
"semver": "^7.3.8",
"symbol-observable": "^4.0.0",
"terminal-link": "^3.0.0",
"update-notifier": "^6.0.2"
},
"devDependencies": {
"ava": "^2.3.0",
"execa_test_double": "^4.0.1",
"mockery": "^2.1.0",
"proxyquire": "^2.1.3",
"sinon": "^9.2.2",
"xo": "^0.36.1"
"ava": "^5.2.0",
"common-tags": "^1.8.2",
"esmock": "^2.2.0",
"fs-extra": "^11.1.1",
"sinon": "^15.0.3",
"xo": "^0.53.1"
},
"ava": {
"environmentVariables": {
"FORCE_HYPERLINK": "1"
},
"files": [
"!test/fixtures",
"!integration-test"
]
},
"xo": {
"ignores": [
"integration-test"
"!test/integration.js"
],
"nodeArguments": [
"--loader=esmock"
]
}
}
20 changes: 14 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

---

<img src="screenshot.gif" width="688">
<img src="media/screenshot.gif" width="688">

## Why

Expand Down Expand Up @@ -54,8 +54,8 @@

## Prerequisite

- Node.js 10 or later
- npm 6.8.0 or later
- Node.js 16 or later
- npm 7.19.0 or later
- Git 2.11 or later

## Install
Expand Down Expand Up @@ -104,11 +104,11 @@ $ np --help

Run `np` without arguments to launch the interactive UI that guides you through publishing a new version.

<img src="screenshot-ui.png" width="1290">
<img src="media/screenshot-ui.png" width="1290">

## Config

`np` can be configured both locally and globally. When using the global `np` binary, you can configure any of the CLI flags in either a `.np-config.js`, `.np-config.cjs` or `.np-config.json` file in the home directory. When using the local `np` binary, for example, in a `npm run` script, you can configure `np` by setting the flags in either a top-level `np` field in `package.json` or in a `.np-config.js`, `.np-config.cjs` or `.np-config.json` file in the project directory. If it exists, the local installation will always take precedence. This ensures any local config matches the version of `np` it was designed for.
`np` can be configured both globally and locally. When using the global `np` binary, you can configure any of the CLI flags in either a `.np-config.js` (as CJS), `.np-config.cjs`, `.np-config.mjs`, or `.np-config.json` file in the home directory. When using the local `np` binary, for example, in a `npm run` script, you can configure `np` by setting the flags in either a top-level `np` field in `package.json` or in one of the aforementioned file types in the project directory. If it exists, the local installation will always take precedence. This ensures any local config matches the version of `np` it was designed for.

Currently, these are the flags you can configure:

Expand Down Expand Up @@ -156,6 +156,14 @@ module.exports = {
};
```

`.np-config.mjs`
```js
export default {
yarn: false,
contents: 'dist'
};
```

_**Note:** The global config only applies when using the global `np` binary, and is never inherited when using a local binary._

## Tips
Expand Down Expand Up @@ -226,7 +234,7 @@ $ yarn config set version-sign-git-tag true

### Private packages

<img src="private-packages.png" width="260" align="right">
<img src="media/private-packages.png" width="260" align="right">

You can use `np` for packages that aren't publicly published to npm (perhaps installed from a private git repo).

Expand Down
85 changes: 43 additions & 42 deletions source/cli-implementation.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/env node
'use strict';
// eslint-disable-next-line import/no-unassigned-import
require('symbol-observable'); // Important: This needs to be first to prevent weird Observable incompatibilities
const logSymbols = require('log-symbols');
const meow = require('meow');
const updateNotifier = require('update-notifier');
const hasYarn = require('has-yarn');
const config = require('./config');
const git = require('./git-util');
const {isPackageNameAvailable} = require('./npm/util');
const version = require('./version');
const util = require('./util');
const ui = require('./ui');
const np = require('.');
import 'symbol-observable'; // Important: This needs to be first to prevent weird Observable incompatibilities
import logSymbols from 'log-symbols';
import meow from 'meow';
import updateNotifier from 'update-notifier';
import hasYarn from 'has-yarn';
import {gracefulExit} from 'exit-hook';
import config from './config.js';
import * as git from './git-util.js';
import {isPackageNameAvailable} from './npm/util.js';
import Version from './version.js';
import * as util from './util.js';
import ui from './ui.js';
import np from './index.js';

const cli = meow(`
Usage
$ np <version>
Version can be:
${version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
${Version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3
Options
--any-branch Allow publishing from any branch
Expand All @@ -45,76 +45,77 @@ const cli = meow(`
$ np 1.0.2-beta.3 --tag=beta
$ np 1.0.2-beta.3 --tag=beta --contents=dist
`, {
importMeta: import.meta,
booleanDefault: undefined,
flags: {
anyBranch: {
type: 'boolean'
type: 'boolean',
},
branch: {
type: 'string'
type: 'string',
},
cleanup: {
type: 'boolean'
type: 'boolean',
},
tests: {
type: 'boolean'
type: 'boolean',
},
yolo: {
type: 'boolean'
type: 'boolean',
},
publish: {
type: 'boolean'
type: 'boolean',
},
releaseDraft: {
type: 'boolean'
type: 'boolean',
},
releaseDraftOnly: {
type: 'boolean'
type: 'boolean',
},
tag: {
type: 'string'
type: 'string',
},
yarn: {
type: 'boolean'
type: 'boolean',
},
contents: {
type: 'string'
type: 'string',
},
preview: {
type: 'boolean'
type: 'boolean',
},
testScript: {
type: 'string'
type: 'string',
},
'2fa': {
type: 'boolean'
type: 'boolean',
},
message: {
type: 'string'
}
}
type: 'string',
},
},
});

updateNotifier({pkg: cli.pkg}).notify();

(async () => {
const {pkg, pkgPath} = util.readPkg();
try {
const {pkg, pkgPath} = await util.readPkg();

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

const localConfig = await config();

const flags = {
...defaultFlags,
...localConfig,
...cli.flags
...cli.flags,
};

// Workaround for unintended auto-casing behavior from `meow`.
Expand All @@ -126,7 +127,7 @@ updateNotifier({pkg: cli.pkg}).notify();

const availability = flags.publish ? await isPackageNameAvailable(pkg) : {
isAvailable: false,
isUnknown: false
isUnknown: false,
};

// Use current (latest) version when 'releaseDraftOnly', otherwise use the first argument.
Expand All @@ -138,22 +139,22 @@ updateNotifier({pkg: cli.pkg}).notify();
availability,
version,
runPublish,
branch
branch,
}, {pkg, pkgPath});

if (!options.confirm) {
process.exit(0);
gracefulExit();
}

console.log(); // Prints a newline for readability
const newPkg = await np(options.version, options);

if (options.preview || options.releaseDraftOnly) {
return;
gracefulExit();
}

console.log(`\n ${newPkg.name} ${newPkg.version} published 🎉`);
})().catch(error => {
} catch (error) {
console.error(`\n${logSymbols.error} ${error.message}`);
process.exit(1);
});
gracefulExit(1);
}
Loading

0 comments on commit 72879e0

Please sign in to comment.