From 77e561971d19c3c847f85992599902ac59e2758f Mon Sep 17 00:00:00 2001 From: Dmitriy Stepanenko Date: Sun, 19 Feb 2023 13:37:35 +0200 Subject: [PATCH 1/2] feat: add "registry" option for the deploy executor --- README.md | 10 +++++++++- .../src/executors/deploy/engine/engine.ts | 2 ++ .../ngx-deploy-npm/src/executors/deploy/schema.d.ts | 4 ++++ .../ngx-deploy-npm/src/executors/deploy/schema.json | 4 ++++ .../src/executors/deploy/utils/interfaces.ts | 2 +- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5383ee45..0dacef2b 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,14 @@ Tells the registry whether to publish the package as public or restricted. It on If you have two-factor authentication enabled in auth-and-writes mode, you can provide a code from your authenticator. +#### `--registry` + +- **optional** +- Example: + - `nx deploy --registry http://localhost:4873` + +Configure npm to use any compatible registry you like, and even run your own registry. + #### `--dry-run` - **optional** @@ -302,7 +310,7 @@ configuration in the `workspace.json` file in the `options` attribute of your deploy project's executor. Just change the option to lower camel case. -A list of all available options is also available [here](https://github.com/bikecoders/ngx-deploy-npm/blob/main/src/deploy/schema.json). +A list of all available options is also available [here](https://github.com/bikecoders/ngx-deploy-npm/blob/main/packages/ngx-deploy-npm/src/executors/deploy/schema.json). Example: diff --git a/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.ts b/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.ts index 13416ee2..e0e3eb8e 100644 --- a/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.ts +++ b/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.ts @@ -57,12 +57,14 @@ function extractOnlyNPMOptions({ tag, otp, dryRun, + registry, }: DeployExecutorOptions): NpmPublishOptions { return { access, tag, otp, dryRun, + registry, }; } diff --git a/packages/ngx-deploy-npm/src/executors/deploy/schema.d.ts b/packages/ngx-deploy-npm/src/executors/deploy/schema.d.ts index dc4b0cf0..97889f9d 100644 --- a/packages/ngx-deploy-npm/src/executors/deploy/schema.d.ts +++ b/packages/ngx-deploy-npm/src/executors/deploy/schema.d.ts @@ -27,6 +27,10 @@ export interface DeployExecutorOptions { * If you have two-factor authentication enabled in auth-and-writes mode then you can provide a code from your authenticator with this. If you don’t include this and you’re running from a TTY then you’ll be prompted. */ otp?: string | number; + /** + * Configure npm to use any compatible registry you like, and even run your own registry. + */ + registry?: string; /** * For testing: Run through without making any changes. Execute with --dry-run and nothing will happen. */ diff --git a/packages/ngx-deploy-npm/src/executors/deploy/schema.json b/packages/ngx-deploy-npm/src/executors/deploy/schema.json index 6c65b721..47d055a5 100644 --- a/packages/ngx-deploy-npm/src/executors/deploy/schema.json +++ b/packages/ngx-deploy-npm/src/executors/deploy/schema.json @@ -38,6 +38,10 @@ "type": ["string", "number"], "description": "If you have two-factor authentication enabled in auth-and-writes mode then you can provide a code from your authenticator with this. If you don't include this and you're running from a TTY then you'll be prompted." }, + "registry": { + "type": "string", + "description": "Configure npm to use any compatible registry you like, and even run your own registry." + }, "dryRun": { "type": "boolean", "description": "For testing: Run through without making any changes. Execute with --dry-run and nothing will happen.", diff --git a/packages/ngx-deploy-npm/src/executors/deploy/utils/interfaces.ts b/packages/ngx-deploy-npm/src/executors/deploy/utils/interfaces.ts index b4761fe6..573d1d29 100644 --- a/packages/ngx-deploy-npm/src/executors/deploy/utils/interfaces.ts +++ b/packages/ngx-deploy-npm/src/executors/deploy/utils/interfaces.ts @@ -2,7 +2,7 @@ import { DeployExecutorOptions } from '../schema'; export type NpmPublishOptions = Pick< DeployExecutorOptions, - 'access' | 'tag' | 'otp' | 'dryRun' + 'access' | 'tag' | 'otp' | 'dryRun' | 'registry' >; export interface BuildTarget { From f735b1a7ba54d2d65d7d4e87c8673c13cde81c2d Mon Sep 17 00:00:00 2001 From: dianjuar Date: Sun, 19 Feb 2023 17:39:35 -0500 Subject: [PATCH 2/2] test: add unit test for the feature registry --- .../executors/deploy/engine/engine.spec.ts | 31 +++---------------- .../executors/deploy/utils/default-options.ts | 3 -- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.spec.ts b/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.spec.ts index 780c13c4..20464563 100644 --- a/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.spec.ts +++ b/packages/ngx-deploy-npm/src/executors/deploy/engine/engine.spec.ts @@ -28,6 +28,7 @@ describe('engine', () => { tag: 'next', otp: 'someValue', buildTarget: 'production', + registry: 'http://localhost:4873', dryRun: true, }; const optionsArray = [ @@ -39,6 +40,8 @@ describe('engine', () => { 'someValue', '--dry-run', 'true', + '--registry', + 'http://localhost:4873', ]; await engine.run(dir, options); @@ -73,32 +76,6 @@ describe('engine', () => { ]); }); - it('should overwrite the default option dry-run', async () => { - const options: DeployExecutorOptions = { - otp: 'random-text', - dryRun: true, - tag: 'random-tag', - }; - const optionsArray = [ - '--access', - 'public', - '--tag', - options.tag, - '--otp', - options.otp, - '--dry-run', - 'true', - ]; - - await engine.run(dir, options); - - expect(spawn.spawnAsync).toHaveBeenCalledWith('npm', [ - 'publish', - dir, - ...optionsArray, - ]); - }); - it('should overwrite the default option access', async () => { const options = { tag: 'random-tag', @@ -108,7 +85,7 @@ describe('engine', () => { '--access', npmAccess.restricted, '--tag', - options.tag, + 'random-tag', ]; await engine.run(dir, options); diff --git a/packages/ngx-deploy-npm/src/executors/deploy/utils/default-options.ts b/packages/ngx-deploy-npm/src/executors/deploy/utils/default-options.ts index 3f247211..2a2ee5be 100644 --- a/packages/ngx-deploy-npm/src/executors/deploy/utils/default-options.ts +++ b/packages/ngx-deploy-npm/src/executors/deploy/utils/default-options.ts @@ -2,8 +2,5 @@ import { npmAccess } from '../../../core'; import { NpmPublishOptions } from './interfaces'; export const defaults: NpmPublishOptions = { - tag: undefined, access: npmAccess.public, - otp: undefined, - dryRun: false, };