Skip to content

Commit 667f1ee

Browse files
CHANGE: @W-20005455@: Upgrade oclif and core salesforce dependencies to latest (#1913)
1 parent a01b84b commit 667f1ee

File tree

8 files changed

+1692
-2137
lines changed

8 files changed

+1692
-2137
lines changed

package-lock.json

Lines changed: 1598 additions & 2094 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"bugs": "https://github.com/forcedotcom/code-analyzer/issues",
77
"type": "module",
88
"dependencies": {
9-
"@oclif/core": "3.27.0",
9+
"@oclif/core": "^4.6.0",
10+
"@oclif/table": "^0.4.14",
1011
"@salesforce/code-analyzer-core": "0.39.0",
1112
"@salesforce/code-analyzer-engine-api": "0.31.0",
1213
"@salesforce/code-analyzer-eslint-engine": "0.36.0",
@@ -15,8 +16,8 @@
1516
"@salesforce/code-analyzer-regex-engine": "0.29.0",
1617
"@salesforce/code-analyzer-retirejs-engine": "0.28.0",
1718
"@salesforce/code-analyzer-sfge-engine": "0.14.0",
18-
"@salesforce/core": "6.7.6",
19-
"@salesforce/sf-plugins-core": "5.0.13",
19+
"@salesforce/core": "^8.23.3",
20+
"@salesforce/sf-plugins-core": "^12.2.4",
2021
"@salesforce/ts-types": "^2.0.12",
2122
"@types/js-yaml": "^4.0.9",
2223
"@types/node": "^20.0.0",

src/lib/Display.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {Ux, Spinner} from '@salesforce/sf-plugins-core';
1+
import {TableOptions} from '@oclif/table';
2+
import {Spinner} from '@salesforce/sf-plugins-core';
23

34
/**
45
* Interface for objects that display output information to users. E.g., a class that prints to the CLI would implement
@@ -31,7 +32,7 @@ export interface Display {
3132
/**
3233
* Output table to stdout only if the "--json" flag is not present.
3334
*/
34-
displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void;
35+
displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void;
3536

3637
/**
3738
* Prompt the user to confirm that the described action should be carried out, and block until they respond (or a timeout
@@ -73,12 +74,28 @@ export class UxDisplay implements Display {
7374
this.displayable.log(message);
7475
}
7576

76-
public displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void {
77-
this.displayable.table(data, columns);
77+
public displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void {
78+
// Currently oclif's table options do not allow us to set the width of the table larger than the user's current
79+
// terminal width. This means if the user's terminal width is small then we will table cells with "truncate" by
80+
// default or "wrap" depending on the passed in 'overflow' value in the table options. To work around this
81+
// limitation, we temporarily set the OCLIF_TABLE_COLUMN_OVERRIDE environment variable so that the user's
82+
// terminal width is ignored so that no truncating or wrapping occurs in order to maintain our original table
83+
// view behavior (prior to when we upgraded oclif).
84+
const oldTableColumnOverrideValue = process.env.OCLIF_TABLE_COLUMN_OVERRIDE;
85+
86+
// If we use too large a number (like 99999), then we can get out of memory issues. Using 3000 seems to the best
87+
// number that fits everything without causing memory issues. And if there is more than 3000 characters then at
88+
// that point we are fine wrapping or truncating
89+
process.env.OCLIF_TABLE_COLUMN_OVERRIDE = '3000';
90+
try {
91+
this.displayable.table(options);
92+
} finally {
93+
process.env.OCLIF_TABLE_COLUMN_OVERRIDE = oldTableColumnOverrideValue;
94+
}
7895
}
7996

8097
public confirm(message: string): Promise<boolean> {
81-
return this.displayable.confirm(message);
98+
return this.displayable.confirm({message});
8299
}
83100

84101
public spinnerStart(msg: string, status?: string): void {
@@ -111,8 +128,8 @@ export interface Displayable {
111128
log(message?: string): void;
112129

113130
// Prompt the user to confirm that the described action should be performed. [Implemented by SfCommand]
114-
confirm(message: string): Promise<boolean>;
131+
confirm(promptInputs: {message: string}): Promise<boolean>;
115132

116133
// Output table to stdout only when "--json" flag is not present. [Implemented by SfCommand]
117-
table<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>, options?: Ux.Table.Options): void;
134+
table<R extends Record<string, unknown>>(options: TableOptions<R>): void;
118135
}

src/lib/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Messages} from '@salesforce/core';
2-
import {Tokens} from '@salesforce/core/lib/messages.js';
2+
import {Tokens} from '@salesforce/core/messages';
33

44
// Initialize Messages with the current plugin directory
55
Messages.importMessagesDirectory(import.meta.dirname);

src/lib/viewers/ResultsViewer.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as path from 'node:path';
2-
import {Ux} from '@salesforce/sf-plugins-core';
32
import {CodeLocation, RunResults, SeverityLevel, Violation} from '@salesforce/code-analyzer-core';
43
import {Display} from '../Display.js';
54
import {toStyledHeaderAndBody} from '../utils/StylingUtil.js';
@@ -119,23 +118,28 @@ type ResultRow = {
119118
message: string;
120119
}
121120

122-
const TABLE_COLUMNS: Ux.Table.Columns<ResultRow> = {
123-
num: {
124-
header: getMessage(BundleName.ResultsViewer, 'summary.table.num-column'),
121+
const TABLE_COLUMNS = [
122+
{
123+
key: 'num' as keyof ResultRow,
124+
name: getMessage(BundleName.ResultsViewer, 'summary.table.num-column'),
125125
},
126-
severity: {
127-
header: getMessage(BundleName.ResultsViewer, 'summary.table.severity-column')
126+
{
127+
key: 'severity' as keyof ResultRow,
128+
name: getMessage(BundleName.ResultsViewer, 'summary.table.severity-column')
128129
},
129-
rule: {
130-
header: getMessage(BundleName.ResultsViewer, 'summary.table.rule-column')
130+
{
131+
key: 'rule' as keyof ResultRow,
132+
name: getMessage(BundleName.ResultsViewer, 'summary.table.rule-column')
131133
},
132-
location: {
133-
header: getMessage(BundleName.ResultsViewer, 'summary.table.location-column')
134+
{
135+
key: 'location' as keyof ResultRow,
136+
name: getMessage(BundleName.ResultsViewer, 'summary.table.location-column')
134137
},
135-
message: {
136-
header: getMessage(BundleName.ResultsViewer, 'summary.table.message-column')
138+
{
139+
key: 'message' as keyof ResultRow,
140+
name: getMessage(BundleName.ResultsViewer, 'summary.table.message-column')
137141
}
138-
};
142+
];
139143

140144
export class ResultsTableDisplayer extends AbstractResultsDisplayer {
141145
protected _view(results: RunResults) {
@@ -158,7 +162,11 @@ export class ResultsTableDisplayer extends AbstractResultsDisplayer {
158162
});
159163

160164
this.display.displayLog(getMessage(BundleName.ResultsViewer, 'summary.shared.results-relative-to', [parentFolder]));
161-
this.display.displayTable(resultRows, TABLE_COLUMNS);
165+
this.display.displayTable({
166+
data: resultRows,
167+
columns: TABLE_COLUMNS,
168+
overflow: 'wrap' // We do not want to use truncate because it is lossy
169+
});
162170
}
163171
}
164172

src/lib/viewers/RuleViewer.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {Ux} from '@salesforce/sf-plugins-core';
21
import {Rule, SeverityLevel} from '@salesforce/code-analyzer-core';
32
import {Display} from '../Display.js';
43
import {toStyledHeaderAndBody} from '../utils/StylingUtil.js';
@@ -76,23 +75,28 @@ type RuleRow = {
7675
tag: string;
7776
};
7877

79-
const TABLE_COLUMNS: Ux.Table.Columns<RuleRow> = {
80-
num: {
81-
header: getMessage(BundleName.RuleViewer, 'summary.table.num-column')
78+
const TABLE_COLUMNS = [
79+
{
80+
key: 'num' as keyof RuleRow,
81+
name: getMessage(BundleName.RuleViewer, 'summary.table.num-column')
8282
},
83-
name: {
84-
header: getMessage(BundleName.RuleViewer, 'summary.table.name-column')
83+
{
84+
key: 'name' as keyof RuleRow,
85+
name: getMessage(BundleName.RuleViewer, 'summary.table.name-column')
8586
},
86-
engine: {
87-
header: getMessage(BundleName.RuleViewer, 'summary.table.engine-column')
87+
{
88+
key: 'engine' as keyof RuleRow,
89+
name: getMessage(BundleName.RuleViewer, 'summary.table.engine-column')
8890
},
89-
severity: {
90-
header: getMessage(BundleName.RuleViewer, 'summary.table.severity-column')
91+
{
92+
key: 'severity' as keyof RuleRow,
93+
name: getMessage(BundleName.RuleViewer, 'summary.table.severity-column')
9194
},
92-
tag: {
93-
header: getMessage(BundleName.RuleViewer, 'summary.table.tag-column')
95+
{
96+
key: 'tag' as keyof RuleRow,
97+
name: getMessage(BundleName.RuleViewer, 'summary.table.tag-column')
9498
}
95-
};
99+
];
96100

97101
export class RuleTableDisplayer extends AbstractRuleDisplayer {
98102
protected _view(rules: Rule[]): void {
@@ -106,7 +110,11 @@ export class RuleTableDisplayer extends AbstractRuleDisplayer {
106110
tag: rule.getTags().join(', ')
107111
};
108112
});
109-
this.display.displayTable(ruleJsons, TABLE_COLUMNS);
113+
this.display.displayTable({
114+
data: ruleJsons,
115+
columns: TABLE_COLUMNS,
116+
overflow: 'wrap' // We do not want to use truncate because it is lossy
117+
});
110118
}
111119
}
112120

test/stubs/SpyDisplay.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Ux} from '@salesforce/sf-plugins-core';
1+
import { TableOptions } from '@oclif/table';
22
import {Display} from '../../src/lib/Display.js';
33

44
/**
@@ -53,13 +53,14 @@ export class SpyDisplay implements Display {
5353
/**
5454
* Track that the provided table data was displayed.
5555
*/
56-
public displayTable<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>): void {
57-
const columnNames: string[] = Object.values(columns).map(column => column.header || '');
56+
public displayTable<R extends Record<string, unknown>>(options: TableOptions<R>): void {
57+
const columnNames: string[] = options.columns!.map(
58+
column => typeof(column) === 'string' ? column : (column as object)['name'] ?? (column as object)['key']);
5859
this.displayEvents.push({
5960
type: DisplayEventType.TABLE,
6061
data: JSON.stringify({
6162
columns: columnNames,
62-
rows: data
63+
rows: options.data
6364
})
6465
});
6566
}

test/test-utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
export class ConsoleOuputInterceptor {
22
private origStdOutWrite: typeof process.stdout.write;
33
private origStdErrWrite: typeof process.stderr.write;
4+
private origConsoleLog: typeof console.log;
5+
private origConsoleError: typeof console.error;
46
public stdOut: string = '';
57
public stdErr: string = '';
68
public out: string = '';
79

810
constructor() {
911
this.origStdOutWrite = process.stdout.write;
1012
this.origStdErrWrite = process.stderr.write;
13+
this.origConsoleLog = console.log;
14+
this.origConsoleError = console.error;
1115
}
1216

1317
start() {
@@ -21,10 +25,22 @@ export class ConsoleOuputInterceptor {
2125
this.out += chunk;
2226
return true;
2327
}
28+
console.log = (...args) => {
29+
const output = args.join(' ') + '\n';
30+
this.stdOut += output;
31+
this.out += output;
32+
};
33+
console.error = (...args) => {
34+
const output = args.join(' ') + '\n';
35+
this.stdErr += output;
36+
this.out += output;
37+
}
2438
}
2539

2640
stop() {
2741
process.stdout.write = this.origStdOutWrite;
2842
process.stderr.write = this.origStdErrWrite;
43+
console.log = this.origConsoleLog;
44+
console.error = this.origConsoleError;
2945
}
3046
}

0 commit comments

Comments
 (0)