Skip to content

Commit

Permalink
refactor: devScripts update (#895)
Browse files Browse the repository at this point in the history
* chore: updates from devScripts

* fix: don't rely on optional command.pluginName

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
svc-cli-bot and mshanemc authored Jul 30, 2024
1 parent fb8b2a9 commit c50b622
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 233 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.2.9",
"@salesforce/cli-plugins-testkit": "^5.3.20",
"@salesforce/dev-scripts": "^10.2.8",
"@salesforce/dev-scripts": "^10.2.9",
"@salesforce/plugin-command-reference": "^3.1.11",
"@salesforce/plugin-telemetry": "^3.6.2",
"@salesforce/ts-sinon": "^1.4.22",
Expand Down
10 changes: 5 additions & 5 deletions src/commands/plugins/trust/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const messages = Messages.loadMessages('@salesforce/plugin-trust', 'verify');
export type VerifyResponse = {
message: string;
verified: boolean;
}
};

export class Verify extends SfCommand<VerifyResponse> {
public static readonly summary = messages.getMessage('summary');
Expand Down Expand Up @@ -63,9 +63,9 @@ export class Verify extends SfCommand<VerifyResponse> {
cliRoot: this.config.root,
};

logger.debug(`cacheDir: ${configContext.cacheDir}`);
logger.debug(`configDir: ${configContext.configDir}`);
logger.debug(`dataDir: ${configContext.dataDir}`);
(['cacheDir', 'configDir', 'dataDir'] as const)
.map((dir) => `${dir}: ${configContext[dir] ?? '<not present on configContext>'}`)
.map((s) => logger.debug(s));

vConfig.verifier = Verify.getVerifier(npmName, configContext);

Expand All @@ -84,7 +84,7 @@ export class Verify extends SfCommand<VerifyResponse> {

try {
const meta = await vConfig.verifier.verify();
logger.debug(`meta.verified: ${meta.verified}`);
logger.debug(`meta.verified: ${meta.verified ?? '<not present>'}`);

if (!meta.verified) {
const e = messages.createError('FailedDigitalSignatureVerification');
Expand Down
13 changes: 8 additions & 5 deletions src/hooks/jitPluginInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const hook: Hook<'jit_plugin_not_installed'> = async function (opts) {
eventName: 'JIT_INSTALL_STARTED',
type: 'EVENT',
version: opts.pluginVersion,
plugin: opts.command.pluginName,
plugin: opts.pluginName,
command: opts.command.id,
});

const jitInstallArgv = [`${opts.command.pluginName}@${opts.pluginVersion}`];
const jitInstallArgv = [`${opts.pluginName}@${opts.pluginVersion}`];
if (opts.argv.includes('--json')) {
// pass along --json arg to plugins:install
jitInstallArgv.push('--json');
Expand All @@ -32,7 +32,7 @@ const hook: Hook<'jit_plugin_not_installed'> = async function (opts) {
eventName: 'JIT_INSTALL_SUCCESS',
type: 'EVENT',
version: opts.pluginVersion,
plugin: opts.command.pluginName,
plugin: opts.pluginName,
command: opts.command.id,
});
} catch (error) {
Expand All @@ -43,11 +43,14 @@ const hook: Hook<'jit_plugin_not_installed'> = async function (opts) {
stackTrace:
error instanceof Error ? error?.stack?.replace(new RegExp(homedir(), 'g'), '<GDPR_HIDDEN>') : undefined,
version: opts.pluginVersion,
plugin: opts.command.pluginName,
plugin: opts.pluginName,
command: opts.command.id,
});

throw new SfError(`Could not install ${opts.command.pluginName}`, 'JitPluginInstallError');
throw new SfError(
`Could not install ${opts.pluginName ?? '<opts.command.pluginName not defined>'}`,
'JitPluginInstallError'
);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/shared/installationVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class InstallationVerification implements Verifier {
}
logger.debug(`retrieveNpmMeta | npmRegistry: ${npmRegistry.href}`);
logger.debug(`retrieveNpmMeta | this.pluginNpmName.name: ${this.pluginNpmName.name}`);
logger.debug(`retrieveNpmMeta | this.pluginNpmName.scope: ${this.pluginNpmName.scope}`);
logger.debug(`retrieveNpmMeta | this.pluginNpmName.scope: ${this.pluginNpmName.scope ?? '<not defined>'}`);
logger.debug(`retrieveNpmMeta | this.pluginNpmName.tag: ${this.pluginNpmName.tag}`);

const npmShowModule = this.pluginNpmName.scope
Expand Down Expand Up @@ -382,7 +382,7 @@ export class InstallationVerification implements Verifier {
versionNumber =
maxSatisfying(npmMetadata.versions, tagVersionStr) ??
npmMetadata.versions.find((version) => version === tagVersionStr);
logger.debug(`retrieveNpmMeta | versionObject: ${versionNumber}`);
logger.debug(`retrieveNpmMeta | versionObject: ${versionNumber ?? '<not defined>'}`);
} else {
const err = new SfError(
`The dist tag ${this.pluginNpmName.tag} was not found for plugin: ${this.pluginNpmName.name}`,
Expand Down Expand Up @@ -427,7 +427,7 @@ export class InstallationVerification implements Verifier {

npmModule.npmMeta.tarballUrl = npmMetadata.dist?.tarball;

logger.debug(`retrieveNpmMeta | meta.tarballUrl: ${npmModule.npmMeta.tarballUrl}`);
logger.debug(`retrieveNpmMeta | meta.tarballUrl: ${npmModule.npmMeta.tarballUrl ?? '<not defined>'}`);

return npmModule.npmMeta;
}
Expand Down
4 changes: 2 additions & 2 deletions src/shared/npmCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class NpmCommand {
public static runNpmCmd(cmd: string, options = {} as NpmCommandOptions): NpmCommandResult {
const nodeExecutable = NpmCommand.findNode(options.cliRoot);
const npmCli = NpmCommand.npmCli();
const command = `"${nodeExecutable}" "${npmCli}" ${cmd} --registry=${options.registry}`;
const command = `"${nodeExecutable}" "${npmCli}" ${cmd} --registry=${options.registry ?? ''}`;
const npmCmdResult = shelljs.exec(command, {
...options,
silent: true,
Expand Down Expand Up @@ -158,7 +158,7 @@ export class NpmModule {
}

public ping(registry?: string): { registry: string; time: number; details: Record<string, unknown> } {
return JSON.parse(NpmCommand.runNpmCmd(`ping ${registry} --json`, { json: true, cliRoot: this.cliRoot })) as {
return JSON.parse(NpmCommand.runNpmCmd(`ping ${registry ?? ''} --json`, { json: true, cliRoot: this.cliRoot })) as {
registry: string;
time: number;
details: Record<string, unknown>;
Expand Down
Loading

0 comments on commit c50b622

Please sign in to comment.