Skip to content

Commit

Permalink
fix: remove dead code (#598)
Browse files Browse the repository at this point in the history
* fix: remove dead code

* style: deprecation message

* chore: bump oclif/core for tests

* chore: sfdx-core top-level imports

* chore: bump oclif/core for fix

* chore: bump lots of things

---------

Co-authored-by: mshanemc <shane.mclaughlin@salesforce.com>
  • Loading branch information
mdonnalley and mshanemc committed Jul 29, 2024
1 parent 0474c89 commit cfd04e8
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 1,190 deletions.
1,317 changes: 302 additions & 1,015 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions messages/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ Set varargs with this format: key=value or key="value with spaces"

Found duplicate argument %s.

# warning.arrayInputFormat

The input format for array arguments has changed. Use this format: --array-flag value1 --array-flag value2 --array-flag value3

# flags.flags-dir.summary

Import flag values from a directory.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
},
"dependencies": {
"@inquirer/confirm": "^3.1.17",
"@inquirer/password": "^2.1.14",
"@oclif/core": "^4.0.12",
"@salesforce/core": "^8.1.1",
"@inquirer/password": "^2.1.18",
"@oclif/core": "^4.0.15",
"@salesforce/core": "^8.2.7",
"@salesforce/kit": "^3.1.6",
"@salesforce/ts-types": "^2.0.10",
"@salesforce/ts-types": "^2.0.11",
"ansis": "^3.3.2",
"cli-progress": "^3.12.0",
"natural-orderby": "^3.0.2",
Expand All @@ -59,11 +59,11 @@
},
"devDependencies": {
"@inquirer/type": "^1.3.3",
"@salesforce/dev-scripts": "^10.2.4",
"@salesforce/dev-scripts": "^10.2.5",
"@types/cli-progress": "^3.11.6",
"eslint-plugin-sf-plugin": "^1.18.8",
"eslint-plugin-sf-plugin": "^1.20.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.2"
"typescript": "^5.5.4"
},
"publishConfig": {
"access": "public"
Expand Down
17 changes: 2 additions & 15 deletions src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Flags } from '@oclif/core';
import { Lifecycle, Messages } from '@salesforce/core';
import { Messages } from '@salesforce/core/messages';
import { orgApiVersionFlag } from './flags/orgApiVersion.js';
import { optionalHubFlag, optionalOrgFlag, requiredHubFlag, requiredOrgFlag } from './flags/orgFlags.js';

Expand Down Expand Up @@ -93,22 +93,9 @@ export type ArrayWithDeprecationOptions = {
parse?: undefined;
};
/**
* @deprecated
* @deprecated. Use `multiple: true` with `delimiter: ','` instead
*/
export const arrayWithDeprecation = Flags.custom<string[], ArrayWithDeprecationOptions>({
multiple: true,
delimiter: ',',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error parse expects to return string[] but we need to return string.
// This is a weird consequence of implementing an array flag. The oclif parser splits the input (e.g. "thing1,thing2")
// on the delimiter and passes each value individually to the parse function. However, the return type needs to be
// string[] so that upstream consumers have the correct flag typings.
parse: async (input, ctx) => {
const inputParts = ctx.token.input.split(',').map((i) => i.trim());
if (inputParts.length > 1) {
await Lifecycle.getInstance().emitWarning(messages.getMessage('warning.arrayInputFormat'));
}

return input;
},
});
2 changes: 1 addition & 1 deletion src/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { SfError } from '@salesforce/core';
import { SfError } from '@salesforce/core/sfError';
import { Errors } from '@oclif/core';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/flags/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Flags } from '@oclif/core';
import { Messages } from '@salesforce/core';
import { Messages } from '@salesforce/core/messages';
import { Duration } from '@salesforce/kit';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
Expand Down
2 changes: 1 addition & 1 deletion src/ux/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { setTimeout } from 'node:timers/promises';
import { SfError } from '@salesforce/core';
import { SfError } from '@salesforce/core/sfError';
import type { CancelablePromise } from '@inquirer/type';

export type PromptInputs<T> = {
Expand Down
45 changes: 45 additions & 0 deletions test/unit/compatibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* 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 { expect } from 'chai';
import { Command, Interfaces } from '@oclif/core';
import { arrayWithDeprecation } from '../../src/compatibility.js';

describe('arrayWithDeprecation', () => {
class TestCommand extends Command {
public static flags = {
things: arrayWithDeprecation({
char: 'a',
description: 'api version for the org',
}),
};

public async run(): Promise<Interfaces.InferredFlags<typeof TestCommand.flags>> {
const { flags } = await this.parse(TestCommand);
return flags;
}
}

it('should split the flags on comma', async () => {
const result = await TestCommand.run(['--things', 'a,b,c']);
expect(result.things).to.deep.equal(['a', 'b', 'c']);
});

it('should split the flags on comma and ignore spaces', async () => {
const result = await TestCommand.run(['--things', 'a, b, c']);
expect(result.things).to.deep.equal(['a', 'b', 'c']);
});

it('should not split on escaped commas', async () => {
const result = await TestCommand.run(['--things', 'a\\,b,c']);
expect(result.things).to.deep.equal(['a,b', 'c']);
});

it('should allow multiple flag inputs', async () => {
const result = await TestCommand.run(['--things', 'a', '--things', 'b', '--things', 'c']);
expect(result.things).to.deep.equal(['a', 'b', 'c']);
});
});
2 changes: 1 addition & 1 deletion test/unit/errorHandling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { expect } from 'chai';
import { SfError } from '@salesforce/core';
import { SfError } from '@salesforce/core/sfError';
import { computeErrorCode, errorIsGack, errorIsTypeError } from '../../src/errorHandling.js';
import { SfCommandError } from '../../src/SfCommandError.js';

Expand Down
2 changes: 1 addition & 1 deletion test/unit/flags/duration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Parser } from '@oclif/core';
import { Messages } from '@salesforce/core';
import { Messages } from '@salesforce/core/messages';
import { expect } from 'chai';
import { Duration } from '@salesforce/kit';
import { durationFlag } from '../../../src/flags/duration.js';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/flags/id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { expect } from 'chai';
import { Parser } from '@oclif/core';
import { Messages } from '@salesforce/core';
import { Messages } from '@salesforce/core/messages';
import { salesforceIdFlag } from '../../../src/flags/salesforceId.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sfCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
import { Flags } from '@oclif/core';
import { Errors } from '@oclif/core';
import { Lifecycle } from '@salesforce/core';
import { Lifecycle } from '@salesforce/core/lifecycle';
import { TestContext } from '@salesforce/core/testSetup';
import { assert, expect } from 'chai';
import { SfError } from '@salesforce/core';
import { SfError } from '@salesforce/core/sfError';
import { Config } from '@oclif/core/interfaces';
import { SfCommand } from '../../src/sfCommand.js';
import { SfCommandError } from '../../src/SfCommandError.js';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/stubUx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Interfaces } from '@oclif/core';
import { expect } from 'chai';
import { TestContext } from '@salesforce/core/testSetup';
import { Lifecycle } from '@salesforce/core';
import { Lifecycle } from '@salesforce/core/lifecycle';
import { stubUx, stubSfCommandUx, SfCommand, Ux, stubSpinner, Flags } from '../../src/exported.js';

const TABLE_DATA = Array.from({ length: 10 }).fill({ id: '123', name: 'foo', value: 'bar' }) as Array<
Expand Down
Loading

0 comments on commit cfd04e8

Please sign in to comment.