Skip to content

Commit

Permalink
fix(npm-publish): Allows disabling of strict SSL checks (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Oct 10, 2022
1 parent ff5e99a commit a26d849
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/publish/src/__tests__/npm-publish.spec.ts
Expand Up @@ -19,6 +19,7 @@ import path from 'path';

// file under test
import { npmPublish } from '../lib/npm-publish';
import { LibNpmPublishOptions } from '../models';

describe('npm-publish', () => {
const mockTarData = Buffer.from('MOCK');
Expand Down Expand Up @@ -183,6 +184,20 @@ describe('npm-publish', () => {
expect(runLifecycle).toHaveBeenCalledTimes(2);
});

it.each([['true'], [true], ['false'], [false]])('aliases strict-ssl to strictSSL', async (strictSSLValue) => {
const opts = { 'strict-ssl': strictSSLValue } as Partial<LibNpmPublishOptions>;

await npmPublish(pkg, tarFilePath, opts);

expect(publish).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
expect.objectContaining({
strictSSL: strictSSLValue,
})
);
});

it('calls publish lifecycles', async () => {
const options = expect.objectContaining({
projectScope: '@scope',
Expand Down
2 changes: 2 additions & 0 deletions packages/publish/src/lib/npm-publish.ts
Expand Up @@ -21,6 +21,8 @@ function flattenOptions(obj: Omit<LibNpmPublishOptions, 'defaultTag'>): LibNpmPu
// eslint-disable-next-line dot-notation -- (npm v7 compat)
defaultTag: obj['tag'] || 'latest',
dryRun: obj['dry-run'] || obj['git-dry-run'],
// libnpmpublish / npm-registry-fetch check strictSSL rather than strict-ssl
strictSSL: obj['strict-ssl'],
...obj,
};
}
Expand Down
14 changes: 13 additions & 1 deletion packages/publish/src/models/index.ts
Expand Up @@ -6,11 +6,23 @@ export interface DistTagOptions extends fetch.FetchOptions {
tag: string;
}

export type KebabCase<S> = S extends `${infer C}${infer T}`
? KebabCase<T> extends infer U
? U extends string
? T extends Uncapitalize<T>
? `${Uncapitalize<C>}${U}`
: `${Uncapitalize<C>}-${U}`
: never
: never
: S;

/** LibNpmPublishOptions - https://github.com/npm/libnpmpublish#opts */
export interface LibNpmPublishOptions extends fetch.FetchOptions {
export interface LibNpmPublishOptions extends KebabCase<fetch.FetchOptions> {
access?: 'public' | 'restricted';
defaultTag: string;
dryRun?: boolean;
// libnpmpublish / npm-registry-fetch check strictSSL rather than strict-ssl
strictSSL?: boolean | 'true' | 'false';
/* Passed to libnpmpublish as `opts.defaultTag` to preserve npm v6 back-compat */
tag?: string;
}
Expand Down

0 comments on commit a26d849

Please sign in to comment.