Skip to content

Commit

Permalink
fix: Support unset strictSSL setting (#76)
Browse files Browse the repository at this point in the history
* fix: Support nullable strictSSL

* Update src/utils.ts

Co-authored-by: Mike Han <56001373+mhan83@users.noreply.github.com>

* adjust npm related type

---------

Co-authored-by: Mike Han <56001373+mhan83@users.noreply.github.com>
  • Loading branch information
tianfeng92 and mhan83 authored Aug 15, 2024
1 parent 5f8d9d8 commit c0e752f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type NpmConfig = {
*/
registry?: string;
registries?: Registry[];
strictSSL?: boolean | string | null;
strictSSL?: boolean | null;
packageLock?: boolean | string | null;
packages?: { [key: string]: string | number };
legacyPeerDeps?: boolean | string | null;
Expand Down
5 changes: 2 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export async function setUpNpmConfig(
fund: false,
noproxy: 'registry.npmjs.org',
'package-lock': false,
'strict-ssl': true,
registry: getDefaultRegistry(),
'update-notifier': false,
};
Expand Down Expand Up @@ -129,9 +128,9 @@ export function getNpmConfig(runnerConfig: NpmConfigContainer) {
if (runnerConfig.npm === undefined) {
return {};
}
const cfg: { [key: string]: string | boolean | null } = {
const cfg: { [key: string]: string | boolean | null | undefined } = {
registry: runnerConfig.npm.registry || getDefaultRegistry(),
'strict-ssl': runnerConfig.npm.strictSSL !== false,
'strict-ssl': runnerConfig.npm.strictSSL,
// Setting to false to avoid dealing with the generated file.
'package-lock': runnerConfig.npm.packageLock === true,
'legacy-peer-deps':
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/src/__snapshots__/utils.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ exports[`utils .prepareNpmEnv should use default registry 1`] = `
"package-lock": false,
"registry": "https://registry.npmjs.org",
"save": false,
"strict-ssl": true,
"strict-ssl": undefined,
"update-notifier": false,
},
]
Expand All @@ -133,7 +133,7 @@ exports[`utils .prepareNpmEnv should use env var for registry 1`] = `
"package-lock": false,
"registry": "npmland.io",
"save": false,
"strict-ssl": true,
"strict-ssl": undefined,
"update-notifier": false,
},
]
Expand Down Expand Up @@ -179,7 +179,7 @@ exports[`utils .prepareNpmEnv should use true as the default value for strictSSL
"package-lock": false,
"registry": "https://registry.npmjs.org",
"save": false,
"strict-ssl": true,
"strict-ssl": undefined,
"update-notifier": false,
},
]
Expand All @@ -201,7 +201,7 @@ exports[`utils .prepareNpmEnv should use true as the default value for strictSSL
"package-lock": false,
"registry": "https://registry.npmjs.org",
"save": false,
"strict-ssl": true,
"strict-ssl": undefined,
"update-notifier": false,
},
]
Expand All @@ -223,7 +223,7 @@ exports[`utils .prepareNpmEnv should use user registry 1`] = `
"package-lock": false,
"registry": "registryland.io",
"save": false,
"strict-ssl": true,
"strict-ssl": undefined,
"update-notifier": false,
},
]
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ describe('utils', function () {
expect(npmConfig).toHaveProperty('package-lock');
});

it('should set strictSSL to true by default', function () {
it('should set strictSSL to undefined if not set', function () {
const npmConfig = getNpmConfig(emptyConfig);
expect(npmConfig).toHaveProperty('strict-ssl', true);
expect(npmConfig).toHaveProperty('strict-ssl', undefined);
});

it('should set strictSSL from runner config', function () {
Expand All @@ -74,10 +74,6 @@ describe('utils', function () {
runnerConfig.npm.strictSSL = true;
npmConfig = getNpmConfig(runnerConfig);
expect(npmConfig).toHaveProperty('strict-ssl', true);

runnerConfig.npm.strictSSL = 'truthy?';
npmConfig = getNpmConfig(runnerConfig);
expect(npmConfig).toHaveProperty('strict-ssl', true);
});

it('should set packageLock to false by default', function () {
Expand Down

0 comments on commit c0e752f

Please sign in to comment.