Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d8fe5c4
bug fix added options to get prefix
dopecodez Jul 7, 2020
84b6c94
added fix for tag coming as undefined
Jul 10, 2020
e12996c
space fix for xo
Jul 10, 2020
6008a02
Merge pull request #1 from sindresorhus/master
dopecodez Jul 11, 2020
375a2da
Merge branch 'master' of https://github.com/dopecodez/np
dopecodez Jul 13, 2020
184c068
bug fix content flag not respected
dopecodez Jul 13, 2020
a2daf26
Update readme to give more info about contents flag
dopecodez Jul 13, 2020
b120441
Update readme.md
dopecodez Jul 13, 2020
42245a9
Merge branch 'master' of https://github.com/dopecodez/np
dopecodez Jul 15, 2020
b6c8a3a
added custom test script flag
dopecodez Jul 15, 2020
b3e72f8
Finshing up test-script
dopecodez Jul 17, 2020
a11a992
Readme fixes
dopecodez Jul 17, 2020
634654b
Update readme.md
dopecodez Jul 17, 2020
5bb7bfe
cleaning up code
dopecodez Jul 17, 2020
f90ca04
cleaning code
dopecodez Jul 17, 2020
b60c475
cleaning code
dopecodez Jul 17, 2020
ab44d91
added error handling
dopecodez Jul 17, 2020
4e63eca
Update readme.md
dopecodez Jul 17, 2020
57ea657
Update source/index.js
dopecodez Jul 20, 2020
a9fc7e8
addressing PR comments
dopecodez Jul 23, 2020
e1c2ded
normalized output between cli and readme
dopecodez Jul 23, 2020
e95cbf6
Update readme.md
dopecodez Jul 25, 2020
f958505
PR comments
dopecodez Jul 25, 2020
c7b4b42
Update readme.md
dopecodez Jul 26, 2020
ebe4604
Update source/cli.js
dopecodez Jul 26, 2020
b4b335a
made output same between cli and readme
dopecodez Jul 26, 2020
fb040a3
fixing across readme
dopecodez Jul 26, 2020
bb7bea1
Update readme.md
dopecodez Jul 27, 2020
a0db7b4
Merge branch 'master' into master
dopecodez Aug 3, 2020
d3ab9f0
cli space fix
dopecodez Aug 3, 2020
deea7fa
changed bracket style for consistency
dopecodez Aug 6, 2020
3424e56
bracket fix
dopecodez Aug 6, 2020
97ab0b8
changed bracket type in cli
dopecodez Aug 9, 2020
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
21 changes: 21 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ $ np --help
--no-yarn Don't use Yarn
--contents Subdirectory to publish
--no-release-draft Skips opening a GitHub release draft
--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)

Examples
Expand Down Expand Up @@ -94,6 +95,7 @@ Currently, these are the flags you can configure:
- `yarn` - Use yarn if possible (`true` by default).
- `contents` - Subdirectory to publish (`.` by default).
- `releaseDraft` - Open a GitHub release draft after releasing (`true` by default).
- `testScript` - Name of npm run script to run tests before publishing (`test` by default).
- `2fa` - Enable 2FA on new packages (`true` by default) (it's not recommended to set this to `false`).

For example, this configures `np` to never use Yarn and to use `dist` as the subdirectory to publish:
Expand Down Expand Up @@ -160,6 +162,25 @@ You can also add `np` to a custom script in `package.json`. This can be useful i
}
```

### User-defined tests

If you want to run a user-defined test script before publishing instead of the normal `npm test` or `yarn test`, you can use `--test-script` flag or the `testScript` config. This is can be useful when your normal test script is running with a `--watch` mode or in case you want to run some specific tests (maybe on the packaged files) before publishing.

For example, `np --test-script=publish-test` would run the `publish-test` script instead of the default `test`.

```json
{
"name": "my-awesome-package",
"scripts": {
"test": "ava --watch",
"publish-test": "ava"
},
"devDependencies": {
"np": "*"
}
}
```

### Signed Git tag

Set the [`sign-git-tag`](https://docs.npmjs.com/misc/config#sign-git-tag) npm config to have the Git tag signed:
Expand Down
4 changes: 4 additions & 0 deletions source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const cli = meow(`
--no-yarn Don't use Yarn
--contents Subdirectory to publish
--no-release-draft Skips opening a GitHub release draft
--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)

Examples
Expand Down Expand Up @@ -76,6 +77,9 @@ const cli = meow(`
preview: {
type: 'boolean'
},
testScript: {
type: 'string'
},
'2fa': {
type: 'boolean'
}
Expand Down
8 changes: 5 additions & 3 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module.exports = async (input = 'patch', options) => {
const rootDir = pkgDir.sync();
const hasLockFile = fs.existsSync(path.resolve(rootDir, options.yarn ? 'yarn.lock' : 'package-lock.json')) || fs.existsSync(path.resolve(rootDir, 'npm-shrinkwrap.json'));
const isOnGitHub = options.repoUrl && (hostedGitInfo.fromUrl(options.repoUrl) || {}).type === 'github';
const testScript = options.testScript || 'test';
const testCommand = options.testScript ? ['run', testScript] : [testScript];

let publishStatus = 'UNKNOWN';

Expand Down Expand Up @@ -145,14 +147,14 @@ module.exports = async (input = 'patch', options) => {
{
title: 'Running tests using npm',
enabled: () => options.yarn === false,
task: () => exec('npm', ['test'])
task: () => exec('npm', testCommand)
},
{
title: 'Running tests using Yarn',
enabled: () => options.yarn === true,
task: () => exec('yarn', ['test']).pipe(
task: () => exec('yarn', testCommand).pipe(
catchError(error => {
if (error.message.includes('Command "test" not found')) {
if (error.message.includes(`Command “${testScript}” not found`)) {
return [];
}

Expand Down