diff --git a/src/commands/plugins/trust/verify.ts b/src/commands/plugins/trust/verify.ts index 5379ea30..e1c8573d 100644 --- a/src/commands/plugins/trust/verify.ts +++ b/src/commands/plugins/trust/verify.ts @@ -12,7 +12,7 @@ import { InstallationVerification, VerificationConfig, } from '../../../shared/installationVerification.js'; -import { type NpmName, parseNpmName } from '../../../shared/NpmName.js'; +import { type ParsedNpm, parseNpmName } from '../../../shared/npmName.js'; import { setErrorName } from '../../../shared/errors.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); @@ -41,7 +41,7 @@ export class Verify extends SfCommand { loglevel, }; - private static getVerifier(npmName: NpmName, config: ConfigContext): InstallationVerification { + private static getVerifier(npmName: ParsedNpm, config: ConfigContext): InstallationVerification { return new InstallationVerification().setPluginNpmName(npmName).setConfig(config); } diff --git a/src/hooks/verifyInstallSignature.ts b/src/hooks/verifyInstallSignature.ts index dfbd0a5b..fdcb4238 100644 --- a/src/hooks/verifyInstallSignature.ts +++ b/src/hooks/verifyInstallSignature.ts @@ -17,7 +17,7 @@ import { isAllowListed, } from '../shared/installationVerification.js'; -import { type NpmName, parseNpmName } from '../shared/NpmName.js'; +import { type ParsedNpm, parseNpmName } from '../shared/npmName.js'; export const hook: Hook.PluginsPreinstall = async function (options) { if (options.plugin && options.plugin.type === 'npm') { @@ -87,7 +87,7 @@ export default hook; /** * Build a VerificationConfig. Useful for testing. */ -const buildVerificationConfig = (npmName: NpmName, configContext: ConfigContext): VerificationConfig => { +const buildVerificationConfig = (npmName: ParsedNpm, configContext: ConfigContext): VerificationConfig => { const vConfig = new VerificationConfig(); vConfig.verifier = new InstallationVerification().setPluginNpmName(npmName).setConfig(configContext); return vConfig; diff --git a/src/shared/NpmName.ts b/src/shared/NpmName.ts index 5f33d4c3..793c4cc3 100644 --- a/src/shared/NpmName.ts +++ b/src/shared/NpmName.ts @@ -9,7 +9,7 @@ import { setErrorName } from './errors.js'; const DEFAULT_TAG = 'latest'; -export type NpmName = { +export type ParsedNpm = { tag: string; scope?: string; name: string; @@ -19,9 +19,9 @@ export type NpmName = { * Parse an NPM package name into {scope, name, tag}. The tag is 'latest' by default and can be any semver string. * * @param {string} npmName - The npm name to parse. - * @return {NpmName} - An object with the parsed components. + * @return {ParsedNpm} - An object with the parsed components. */ -export const parseNpmName = (npmName: string): NpmName => { +export const parseNpmName = (npmName: string): ParsedNpm => { const nameWithoutAt = validateNpmNameAndRemoveLeadingAt(npmName); const hasScope = nameWithoutAt.includes('/'); const hasTag = nameWithoutAt.includes('@'); @@ -34,7 +34,7 @@ export const parseNpmName = (npmName: string): NpmName => { }; /** Produces a formatted string version of the object */ -export const npmNameToString = (npmName: NpmName): string => +export const npmNameToString = (npmName: ParsedNpm): string => `${npmName.scope ? `@${npmName.scope}/` : ''}${npmName.name}`; const validateNpmNameAndRemoveLeadingAt = (input: string): string => { diff --git a/src/shared/installationVerification.ts b/src/shared/installationVerification.ts index bf41de36..7f258e53 100644 --- a/src/shared/installationVerification.ts +++ b/src/shared/installationVerification.ts @@ -19,7 +19,7 @@ import { ux } from '@oclif/core'; import { prompts } from '@salesforce/sf-plugins-core'; import { maxSatisfying } from 'semver'; import { NpmModule, NpmMeta } from './npmCommand.js'; -import { NpmName, npmNameToString } from './NpmName.js'; +import { ParsedNpm, npmNameToString } from './npmName.js'; import { setErrorName } from './errors.js'; const CRYPTO_LEVEL = 'RSA-SHA256'; @@ -187,7 +187,7 @@ export async function isAllowListed({ */ export class InstallationVerification implements Verifier { // The name of the published plugin - private pluginNpmName?: NpmName; + private pluginNpmName?: ParsedNpm; // config derived from the cli environment private config?: ConfigContext; @@ -211,7 +211,7 @@ export class InstallationVerification implements Verifier { * * @param _pluginName the published plugin name */ - public setPluginNpmName(_pluginName?: NpmName | undefined): InstallationVerification { + public setPluginNpmName(_pluginName?: ParsedNpm | undefined): InstallationVerification { if (_pluginName) { this.pluginNpmName = _pluginName; return this; diff --git a/test/shared/installationVerification.test.ts b/test/shared/installationVerification.test.ts index d6586dd5..0b01e0d4 100644 --- a/test/shared/installationVerification.test.ts +++ b/test/shared/installationVerification.test.ts @@ -26,7 +26,7 @@ import { Verifier, } from '../../src/shared/installationVerification.js'; import { NpmMeta, NpmModule, NpmShowResults } from '../../src/shared/npmCommand.js'; -import { NpmName, parseNpmName } from '../../src/shared/NpmName.js'; +import { ParsedNpm, parseNpmName } from '../../src/shared/npmName.js'; import { CERTIFICATE, TEST_DATA, TEST_DATA_SIGNATURE } from '../testCert.js'; const BLANK_PLUGIN = { plugin: '', tag: '' }; @@ -137,7 +137,7 @@ describe('InstallationVerification Tests', () => { }; const currentRegistry = process.env.SFDX_NPM_REGISTRY; let fsReaddirSyncStub: Sinon.SinonStub; - let plugin: NpmName; + let plugin: ParsedNpm; let realpathSyncStub: Sinon.SinonStub; let sandbox: sinon.SinonSandbox; let shelljsExecStub: Sinon.SinonStub; diff --git a/test/shared/npmName.test.ts b/test/shared/npmName.test.ts index 1bc65a93..e68f37fe 100644 --- a/test/shared/npmName.test.ts +++ b/test/shared/npmName.test.ts @@ -6,7 +6,7 @@ */ import { expect } from 'chai'; -import { npmNameToString, parseNpmName } from '../../src/shared/NpmName.js'; +import { npmNameToString, parseNpmName } from '../../src/shared/npmName.js'; describe('npmName', () => { describe('parse', () => {