From d98792da2db55b47467bdf74652421fa5b406607 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 5 Apr 2024 11:05:00 -0500 Subject: [PATCH 1/6] fix: file casing consistent with export --- src/commands/plugins/trust/verify.ts | 4 ++-- src/hooks/verifyInstallSignature.ts | 4 ++-- src/shared/NpmName.ts | 8 ++++---- src/shared/installationVerification.ts | 6 +++--- test/shared/installationVerification.test.ts | 4 ++-- test/shared/npmName.test.ts | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) 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', () => { From a6de4840acba8d7acd3c28850c082643da444e28 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 5 Apr 2024 11:09:30 -0500 Subject: [PATCH 2/6] chore: snapshot --- command-snapshot.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command-snapshot.json b/command-snapshot.json index 3a1e777a..675434e5 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -4,7 +4,7 @@ "command": "plugins:trust:verify", "flagAliases": [], "flagChars": ["n", "r"], - "flags": ["flags-dir", "json", "loglevel", "npm", "registry"], + "flags": ["json", "loglevel", "npm", "registry"], "plugin": "@salesforce/plugin-trust" } ] From 0ca158838ed3eab04208c3864fa1dae0f287855b Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 5 Apr 2024 12:52:20 -0500 Subject: [PATCH 3/6] refactor: back to original name --- src/commands/plugins/trust/verify.ts | 4 ++-- src/hooks/verifyInstallSignature.ts | 4 ++-- src/shared/NpmName.ts | 8 ++++---- src/shared/installationVerification.ts | 6 +++--- test/shared/installationVerification.test.ts | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/commands/plugins/trust/verify.ts b/src/commands/plugins/trust/verify.ts index e1c8573d..d723020d 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 ParsedNpm, parseNpmName } from '../../../shared/npmName.js'; +import { type NpmName, 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: ParsedNpm, config: ConfigContext): InstallationVerification { + private static getVerifier(npmName: NpmName, config: ConfigContext): InstallationVerification { return new InstallationVerification().setPluginNpmName(npmName).setConfig(config); } diff --git a/src/hooks/verifyInstallSignature.ts b/src/hooks/verifyInstallSignature.ts index fdcb4238..4308d0c1 100644 --- a/src/hooks/verifyInstallSignature.ts +++ b/src/hooks/verifyInstallSignature.ts @@ -17,7 +17,7 @@ import { isAllowListed, } from '../shared/installationVerification.js'; -import { type ParsedNpm, parseNpmName } from '../shared/npmName.js'; +import { type NpmName, 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: ParsedNpm, configContext: ConfigContext): VerificationConfig => { +const buildVerificationConfig = (npmName: NpmName, 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 793c4cc3..5f33d4c3 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 ParsedNpm = { +export type NpmName = { tag: string; scope?: string; name: string; @@ -19,9 +19,9 @@ export type ParsedNpm = { * 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 {ParsedNpm} - An object with the parsed components. + * @return {NpmName} - An object with the parsed components. */ -export const parseNpmName = (npmName: string): ParsedNpm => { +export const parseNpmName = (npmName: string): NpmName => { const nameWithoutAt = validateNpmNameAndRemoveLeadingAt(npmName); const hasScope = nameWithoutAt.includes('/'); const hasTag = nameWithoutAt.includes('@'); @@ -34,7 +34,7 @@ export const parseNpmName = (npmName: string): ParsedNpm => { }; /** Produces a formatted string version of the object */ -export const npmNameToString = (npmName: ParsedNpm): string => +export const npmNameToString = (npmName: NpmName): 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 7f258e53..b4ee40f8 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 { ParsedNpm, npmNameToString } from './npmName.js'; +import { NpmName, 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?: ParsedNpm; + private pluginNpmName?: NpmName; // 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?: ParsedNpm | undefined): InstallationVerification { + public setPluginNpmName(_pluginName?: NpmName | undefined): InstallationVerification { if (_pluginName) { this.pluginNpmName = _pluginName; return this; diff --git a/test/shared/installationVerification.test.ts b/test/shared/installationVerification.test.ts index 0b01e0d4..ccc7a5a2 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 { ParsedNpm, parseNpmName } from '../../src/shared/npmName.js'; +import { type NpmName, 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: ParsedNpm; + let plugin: NpmName; let realpathSyncStub: Sinon.SinonStub; let sandbox: sinon.SinonSandbox; let shelljsExecStub: Sinon.SinonStub; From 0050bebff967e92ce8386bbbc9a7ab810a5abeac Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 5 Apr 2024 12:55:01 -0500 Subject: [PATCH 4/6] chore: add type keyword --- src/shared/installationVerification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/installationVerification.ts b/src/shared/installationVerification.ts index b4ee40f8..8f143a62 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 { type NpmName, npmNameToString } from './npmName.js'; import { setErrorName } from './errors.js'; const CRYPTO_LEVEL = 'RSA-SHA256'; From 01aaa6b312967fedb37683b28e56c396c95f3966 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 5 Apr 2024 13:08:19 -0500 Subject: [PATCH 5/6] chore: try with git mv --- src/shared/{NpmName.ts => npmName.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/shared/{NpmName.ts => npmName.ts} (100%) diff --git a/src/shared/NpmName.ts b/src/shared/npmName.ts similarity index 100% rename from src/shared/NpmName.ts rename to src/shared/npmName.ts From cbed55f503dc4d5431674f3c62f4926c75975cb5 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Fri, 5 Apr 2024 13:13:59 -0500 Subject: [PATCH 6/6] chore: snapshot --- command-snapshot.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command-snapshot.json b/command-snapshot.json index 675434e5..3a1e777a 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -4,7 +4,7 @@ "command": "plugins:trust:verify", "flagAliases": [], "flagChars": ["n", "r"], - "flags": ["json", "loglevel", "npm", "registry"], + "flags": ["flags-dir", "json", "loglevel", "npm", "registry"], "plugin": "@salesforce/plugin-trust" } ]