Skip to content

Commit

Permalink
fix(deps): remove dep (#464)
Browse files Browse the repository at this point in the history
* chore: don't use ts-types

* refactor: new message import style

* docs: correct CLI install
  • Loading branch information
mshanemc authored Dec 15, 2023
1 parent 3fe87f1 commit 968f6df
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 125 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Config and alias commands for the `sf` Salesforce CLI
>
> If you are looking for the `sfdx` command repos, they can be found here: [plugin-config](https://github.com/salesforcecli/plugin-config) and [plugin-alias](https://github.com/salesforcecli/plugin-alias)
This plugin is bundled with the [Salesforce CLI](https://developer.salesforce.com/tools/sfdxcli). For more information on the CLI, read the [getting started guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm).
This plugin is bundled with the [Salesforce CLI](https://developer.salesforce.com/tools/salesforcecli). For more information on the CLI, read the [getting started guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm).

We always recommend using the latest version of these commands bundled with the CLI, however, you can install a specific version or tag if needed.

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
"@salesforce/plugin-command-reference": "^3.0.51",
"@salesforce/plugin-deploy-retrieve": "^1.20.3",
"@salesforce/ts-sinon": "^1.4.17",
"@salesforce/ts-types": "^2.0.9",
"@types/fast-levenshtein": "^0.0.3",
"eslint-plugin-sf-plugin": "^1.16.15",
"eslint-plugin-sf-plugin": "^1.17.0",
"oclif": "^4.0.4",
"shx": "0.3.4",
"ts-node": "^10.9.2",
Expand Down
4 changes: 1 addition & 3 deletions src/commands/alias/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { StateAggregator, Messages } from '@salesforce/core';
import { loglevel } from '@salesforce/sf-plugins-core';
import { AliasCommand, AliasResults } from '../../alias.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'alias.list');
export default class AliasList extends AliasCommand<AliasResults> {
public static summary = messages.getMessage('summary');
Expand Down
4 changes: 1 addition & 3 deletions src/commands/alias/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { loglevel, parseVarArgs } from '@salesforce/sf-plugins-core';
import { StateAggregator, Messages } from '@salesforce/core';
import { AliasCommand, AliasResults } from '../../alias.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'alias.set');

export default class AliasSet extends AliasCommand<AliasResults> {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/alias/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { Flags, loglevel } from '@salesforce/sf-plugins-core';
import { StateAggregator, Messages } from '@salesforce/core';
import { AliasCommand, AliasResults } from '../../alias.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'alias.unset');

export default class AliasUnset extends AliasCommand<AliasResults> {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/config/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';

import { Flags, loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ConfigAggregator, Messages } from '@salesforce/core';
import {
Expand All @@ -17,7 +16,7 @@ import {
ConfigResponses,
} from '../../config.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'config.get');

export class Get extends SfCommand<ConfigResponses> {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/config/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';

import { ConfigAggregator, Messages } from '@salesforce/core';
import { loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ConfigResponses, buildSuccessMsg, output } from '../../config.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'config.list');

export default class List extends SfCommand<ConfigResponses> {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { parseVarArgs, Flags, loglevel, Ux, SfCommand } from '@salesforce/sf-plugins-core';
import { Config, Messages, Org, SfError, OrgConfigProperties } from '@salesforce/core';
import { CONFIG_HELP_SECTION, Msg, buildFailureMsg, calculateSuggestion, output } from '../../config.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'config.set');

export type SetOrUnsetConfigCommandResult = { successes: Msg[]; failures: Msg[] };
Expand Down
4 changes: 1 addition & 3 deletions src/commands/config/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { Flags, loglevel, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { Config, Messages } from '@salesforce/core';
import { CONFIG_HELP_SECTION, buildFailureMsg, calculateSuggestion, output } from '../../config.js';
import { SetOrUnsetConfigCommandResult } from './set.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'config.unset');

export class UnSet extends SfCommand<SetOrUnsetConfigCommandResult> {
Expand Down
3 changes: 1 addition & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Ux } from '@salesforce/sf-plugins-core';
import { ConfigInfo, SfError, Config } from '@salesforce/core';
import { toHelpSection } from '@salesforce/sf-plugins-core';
import Levenshtein from 'fast-levenshtein';
import { isJsonMap } from '@salesforce/ts-types';
import { HelpSection } from '@oclif/core';

export type Msg = {
Expand Down Expand Up @@ -59,7 +58,7 @@ export const buildSuccessMsg = (configInfo: ConfigInfo): Msg => {
if (Array.isArray(configInfo.value)) {
throw new SfError(`Config ${configInfo.key} is an Array. It should be a primitive.`);
}
if (isJsonMap(configInfo.value)) {
if (typeof configInfo.value === 'object') {
throw new SfError(`Config ${configInfo.key} is an Object. It should be a primitive.`);
}
return {
Expand Down
15 changes: 6 additions & 9 deletions test/commands/alias/set.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { getNumber, getString } from '@salesforce/ts-types';
import { expect } from 'chai';
import { Messages } from '@salesforce/core';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'alias.set');

function unsetAll() {
Expand Down Expand Up @@ -157,11 +154,11 @@ describe('alias set NUTs', () => {
it('alias set --json', () => {
// access each member individually because the stack trace will be different
const res = execCmd('alias set --json');
expect(getNumber(res.jsonOutput, 'status')).to.equal(1);
expect(getString(res.jsonOutput, 'name')).to.equal('ArgumentsRequiredError');
expect(getString(res.jsonOutput, 'stack')).to.contain('ArgumentsRequiredError');
expect(getString(res.jsonOutput, 'message')).to.include(messages.getMessages('error.ArgumentsRequired'));
expect(getNumber(res.jsonOutput, 'exitCode')).to.equal(1);
expect(res.jsonOutput?.status).to.equal(1);
expect(res.jsonOutput?.name).to.equal('ArgumentsRequiredError');
expect(res.jsonOutput?.stack).to.contain('ArgumentsRequiredError');
expect(res.jsonOutput?.message).to.include(messages.getMessages('error.ArgumentsRequired'));
expect(res.jsonOutput?.exitCode).to.equal(1);
});

it('alias set without varargs stdout', () => {
Expand Down
4 changes: 1 addition & 3 deletions test/commands/alias/unset.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';
import { Messages } from '@salesforce/core';
import { AliasResults } from '../../../src/alias.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'alias.unset');

describe('alias unset NUTs', () => {
Expand Down
4 changes: 1 addition & 3 deletions test/commands/config/set.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { assert, expect } from 'chai';
import { Messages } from '@salesforce/core';
import { SetOrUnsetConfigCommandResult } from '../../../src/commands/config/set.js';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-settings', 'config.set');

let testSession: TestSession;
Expand Down
12 changes: 5 additions & 7 deletions test/commands/sfdx/alias/set.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { getNumber, getString } from '@salesforce/ts-types';
import { expect } from 'chai';
let testSession: TestSession;

Expand Down Expand Up @@ -101,14 +100,13 @@ describe('alias:set NUTs', async () => {
it('alias:set --json', () => {
// access each member individually because the stack trace will be different
const res = execCmd('alias:set --json');
expect(getNumber(res.jsonOutput, 'status')).to.equal(1);
expect(getString(res.jsonOutput, 'name')).to.equal('ArgumentsRequiredError');
expect(getString(res.jsonOutput, 'stack')).to.contain('ArgumentsRequiredError');
expect(getString(res.jsonOutput, 'message')).to.contain(
expect(res.jsonOutput?.status).to.equal(1);
expect(res.jsonOutput?.name).to.equal('ArgumentsRequiredError');
expect(res.jsonOutput?.stack).to.contain('ArgumentsRequiredError');
expect(res.jsonOutput?.message).to.contain(
'You must provide one or more aliases to set. Use the --help flag to see examples.'
);
expect(getNumber(res.jsonOutput, 'exitCode')).to.equal(1);
expect(getNumber(res.jsonOutput, 'status')).to.equal(1);
expect(res.jsonOutput?.exitCode).to.equal(1);
});

it('alias:set without varargs stdout', () => {
Expand Down
Loading

0 comments on commit 968f6df

Please sign in to comment.