From 0c7bdcf0047c986f019e754bcf208b1af3436a63 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 8 Nov 2023 22:58:51 +0900 Subject: [PATCH 1/9] fix import bug enable2fa.getEnable2faArgs is not a function probably from rewriting to esm --- source/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/index.js b/source/index.js index c4aa6c30..249b69cd 100644 --- a/source/index.js +++ b/source/index.js @@ -12,7 +12,7 @@ import logSymbols from 'log-symbols'; import prerequisiteTasks from './prerequisite-tasks.js'; import gitTasks from './git-tasks.js'; import publish, {getPackagePublishArguments} from './npm/publish.js'; -import enable2fa from './npm/enable-2fa.js'; +import enable2fa, { getEnable2faArgs } from './npm/enable-2fa.js'; import releaseTaskHelper from './release-task-helper.js'; import * as util from './util.js'; import * as git from './git-util.js'; @@ -227,9 +227,9 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => { }, ...shouldEnable2FA ? [{ title: 'Enabling two-factor authentication', - skip() { + async skip() { if (options.preview) { - const args = enable2fa.getEnable2faArgs(pkg.name, options); + const args = await getEnable2faArgs(pkg.name, options); return `[Preview] Command not executed: npm ${args.join(' ')}.`; } }, From 846a0b39d5a4eb240d1ea41c8e0d6ce6766b4a60 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 8 Nov 2023 23:00:51 +0900 Subject: [PATCH 2/9] don't exit with 0 even though it failed can be reproduced by running `np` without an internet connection thereby it thinks that options.availability.isUnknown but the package is not scoped, so it just exits with success (exit code 0) --- source/ui.js | 1 + 1 file changed, 1 insertion(+) diff --git a/source/ui.js b/source/ui.js index 44931301..4f240ae4 100644 --- a/source/ui.js +++ b/source/ui.js @@ -198,6 +198,7 @@ const ui = async (options, {pkg, rootDir}) => { } if (options.availability.isUnknown) { + if (!isScoped(pkg.name)) throw new Error('Unknown availability, but package is not scoped. This shouldn\'t happen'); const answers = await inquirer.prompt({ confirm: { type: 'confirm', From 4bf6ae0f51bac5d99e38196f72c2802a0710e00b Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 8 Nov 2023 23:01:24 +0900 Subject: [PATCH 3/9] fix bug where it was trying to call setFrom with the first argument as a Version instance instead of a string causing code to fail --- source/release-task-helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/release-task-helper.js b/source/release-task-helper.js index 51f62058..ebaf2269 100644 --- a/source/release-task-helper.js +++ b/source/release-task-helper.js @@ -6,7 +6,7 @@ import Version from './version.js'; const releaseTaskHelper = async (options, pkg) => { const newVersion = options.releaseDraftOnly ? new Version(pkg.version) - : new Version(pkg.version).setFrom(options.version, {prereleasePrefix: await getPreReleasePrefix(options)}); + : new Version(pkg.version).setFrom(options.version.toString(), {prereleasePrefix: await getPreReleasePrefix(options)}); const tag = await getTagVersionPrefix(options) + newVersion.toString(); From 0bd4e93ecb31f2566ce8ba99721b9992e94a5846 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 8 Nov 2023 23:15:43 +0900 Subject: [PATCH 4/9] allow publishing scoped packages otherwise it fails with: Response Code: 402 (Payment Required) You must sign up for private packages --- source/cli-implementation.js | 1 + source/ui.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/cli-implementation.js b/source/cli-implementation.js index e706f2ad..94b13de7 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -37,6 +37,7 @@ const cli = meow(` --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) + --publish-scoped When publishing a scoped package, you need to provide this option to force publish it publically Examples $ np diff --git a/source/ui.js b/source/ui.js index 4f240ae4..45520b0a 100644 --- a/source/ui.js +++ b/source/ui.js @@ -309,7 +309,7 @@ const ui = async (options, {pkg, rootDir}) => { ...options, version: answers.version || answers.customVersion || options.version, tag: answers.tag || answers.customTag || options.tag, - publishScoped: answers.publishScoped, + publishScoped: answers.publishScoped || options.publishScoped, confirm: true, repoUrl, releaseNotes, From 773bd1d04f3515a6b1784deb51c456d8ef358b7b Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 8 Nov 2023 23:25:23 +0900 Subject: [PATCH 5/9] fix lint and test --- source/index.js | 2 +- source/ui.js | 5 ++++- test/cli.js | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/index.js b/source/index.js index 249b69cd..93a9407d 100644 --- a/source/index.js +++ b/source/index.js @@ -12,7 +12,7 @@ import logSymbols from 'log-symbols'; import prerequisiteTasks from './prerequisite-tasks.js'; import gitTasks from './git-tasks.js'; import publish, {getPackagePublishArguments} from './npm/publish.js'; -import enable2fa, { getEnable2faArgs } from './npm/enable-2fa.js'; +import enable2fa, {getEnable2faArgs} from './npm/enable-2fa.js'; import releaseTaskHelper from './release-task-helper.js'; import * as util from './util.js'; import * as git from './git-util.js'; diff --git a/source/ui.js b/source/ui.js index 45520b0a..6ec862ac 100644 --- a/source/ui.js +++ b/source/ui.js @@ -198,7 +198,10 @@ const ui = async (options, {pkg, rootDir}) => { } if (options.availability.isUnknown) { - if (!isScoped(pkg.name)) throw new Error('Unknown availability, but package is not scoped. This shouldn\'t happen'); + if (!isScoped(pkg.name)) { + throw new Error('Unknown availability, but package is not scoped. This shouldn\'t happen'); + } + const answers = await inquirer.prompt({ confirm: { type: 'confirm', diff --git a/test/cli.js b/test/cli.js index c898fd67..313dad6f 100644 --- a/test/cli.js +++ b/test/cli.js @@ -31,6 +31,7 @@ test('flags: --help', cliPasses, cli, '--help', [ '--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)', + '--publish-scoped When publishing a scoped package, you need to provide this option to force publish it publically', '', 'Examples', '$ np', From 7566a3f02ed0d4ac991113d9038bec886e2b5c07 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 8 Nov 2023 23:43:54 +0900 Subject: [PATCH 6/9] add bool specification for cli option --- source/cli-implementation.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/cli-implementation.js b/source/cli-implementation.js index 94b13de7..e90a3dad 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -100,6 +100,10 @@ const cli = meow(` message: { type: 'string', }, + publishScoped: { + type: 'boolean', + default: false, + }, }, }); From 11c02b7dab8d814a83435ed1cb1a8beddcbe5612 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Mon, 27 Nov 2023 14:07:34 +0800 Subject: [PATCH 7/9] add note about scoped packages --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 3455b0cb..cdab1c4b 100644 --- a/readme.md +++ b/readme.md @@ -254,6 +254,8 @@ To publish [scoped packages](https://docs.npmjs.com/misc/scope#publishing-public If publishing a scoped package for the first time, `np` will prompt you to ask if you want to publish it publicly. +**Note:** When publishing a scoped package, the first ever version you publish has to be done interactively using `np`. If not, you cannot use `np` to publish future versions of the package. + ### Private Org-scoped packages To publish a [private Org-scoped package](https://docs.npmjs.com/creating-and-publishing-an-org-scoped-package#publishing-a-private-org-scoped-package), you need to set the access level to `restricted`. You can do that by adding the following to your `package.json`: From 0901b9b06cb1823558288bd4f4f5624382fb4f4f Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Mon, 27 Nov 2023 14:07:40 +0800 Subject: [PATCH 8/9] add note about pnpm too --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cdab1c4b..e9ae7eff 100644 --- a/readme.md +++ b/readme.md @@ -49,7 +49,7 @@ ### Why not - Monorepos are not supported. -- Yarn >= 2 is not supported. +- Yarn >= 2 and pnpm are not supported. - Custom registries are not supported ([but could be with your help](https://github.com/sindresorhus/np/issues/420)). - CI is [not an ideal environment](https://github.com/sindresorhus/np/issues/619#issuecomment-994493179) for `np`. It's meant to be used locally as an interactive tool. From e999583e41ffc40a084f7e0fa5436299c60cfabd Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Mon, 27 Nov 2023 15:35:40 +0800 Subject: [PATCH 9/9] reverse publishScoped arg --- source/cli-implementation.js | 5 ----- source/ui.js | 2 +- test/cli.js | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/source/cli-implementation.js b/source/cli-implementation.js index e90a3dad..e706f2ad 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -37,7 +37,6 @@ const cli = meow(` --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) - --publish-scoped When publishing a scoped package, you need to provide this option to force publish it publically Examples $ np @@ -100,10 +99,6 @@ const cli = meow(` message: { type: 'string', }, - publishScoped: { - type: 'boolean', - default: false, - }, }, }); diff --git a/source/ui.js b/source/ui.js index 6ec862ac..66e7984a 100644 --- a/source/ui.js +++ b/source/ui.js @@ -312,7 +312,7 @@ const ui = async (options, {pkg, rootDir}) => { ...options, version: answers.version || answers.customVersion || options.version, tag: answers.tag || answers.customTag || options.tag, - publishScoped: answers.publishScoped || options.publishScoped, + publishScoped: answers.publishScoped, confirm: true, repoUrl, releaseNotes, diff --git a/test/cli.js b/test/cli.js index 313dad6f..c898fd67 100644 --- a/test/cli.js +++ b/test/cli.js @@ -31,7 +31,6 @@ test('flags: --help', cliPasses, cli, '--help', [ '--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)', - '--publish-scoped When publishing a scoped package, you need to provide this option to force publish it publically', '', 'Examples', '$ np',