Skip to content

Commit b112335

Browse files
chore: follow IDEs warnings, improvements, switch to promise read to see perf
1 parent 3a10b04 commit b112335

19 files changed

+39
-56
lines changed

.gitignore

-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ xunit.xml
2020
junit-custom.xml
2121
*.received.*
2222

23-
# nyc test coverage
24-
.nyc_output
25-
2623
# Eclipse
2724
.project
2825

@@ -91,9 +88,6 @@ typings/
9188
# Optional REPL history
9289
.node_repl_history
9390

94-
# Output of 'npm pack'
95-
*.tgz
96-
9791
# Yarn Integrity file
9892
.yarn-integrity
9993

src/client/metadataApiDeploy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class MetadataApiDeploy extends MetadataTransfer<
152152
}
153153
const connection = await this.getConnection();
154154
// Recasting to use the project's version of the type
155-
return connection.metadata.checkDeployStatus(this.id, true) as unknown as MetadataApiDeployStatus;
155+
return (await connection.metadata.checkDeployStatus(this.id, true)) as unknown as MetadataApiDeployStatus;
156156
}
157157

158158
/**

src/client/metadataTransfer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export abstract class MetadataTransfer<
4646
private transferId: Options['id'];
4747
private event = new EventEmitter();
4848
private usernameOrConnection: string | Connection;
49-
private apiVersion?: string;
49+
private readonly apiVersion?: string;
5050

5151
public constructor({ usernameOrConnection, components, apiVersion, id }: Options) {
5252
this.usernameOrConnection = usernameOrConnection;

src/client/types.ts

-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ export type MetadataApiDeployStatus = {
140140
export type DeployDetails = {
141141
componentFailures?: DeployMessage | DeployMessage[];
142142
componentSuccesses?: DeployMessage | DeployMessage[];
143-
// TODO: Add types for RetrieveResult
144-
// retrieveResult?:
145143
runTestResult?: RunTestResult;
146144
};
147145

src/collections/componentSet.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,10 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
221221
if (resolveIncludeSet && !deletionType) {
222222
resolveIncludeSet.add(component);
223223
}
224-
if (resolvePreSet && deletionType === DestructiveChangesType.PRE) {
225-
resolvePreSet.add(component, DestructiveChangesType.PRE);
226-
}
227-
if (resolvePostSet && deletionType === DestructiveChangesType.POST) {
228-
resolvePostSet.add(component, DestructiveChangesType.POST);
224+
if (resolvePreSet && deletionType) {
225+
resolvePreSet.add(component, deletionType);
229226
}
227+
230228
const memberIsWildcard = component.fullName === ComponentSet.WILDCARD;
231229
if (options.resolveSourcePaths === undefined || !memberIsWildcard || options.forceAddWildcards) {
232230
result.add(component, deletionType);

src/collections/componentSetBuilder.ts

+13
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ const getOrgComponentFilter = (
319319
): FromConnectionOptions['componentFilter'] =>
320320
metadata?.metadataEntries?.length
321321
? (component: Partial<FileProperties>): boolean => {
322+
// {
323+
// "createdById": "005KR000000mVHLYA2",
324+
// "createdByName": "User User",
325+
// "createdDate": "2025-03-05T21:15:23.000Z",
326+
// "fileName": "classes/FileUtilitiesTest.cls",
327+
// "fullName": "FileUtilitiesTest",
328+
// "id": "01pKR000000FgMQYA0",
329+
// "lastModifiedById": "005KR000000mVHLYA2",
330+
// "lastModifiedByName": "User User",
331+
// "lastModifiedDate": "2025-03-05T21:15:23.000Z",
332+
// "manageableState": "unmanaged",
333+
// "type": "ApexClass"
334+
// }
322335
if (component.type && component.fullName) {
323336
const mdMapEntry = mdMap.get(component.type);
324337
// using minimatch versus RegExp provides better (more expected) matching results

src/convert/metadataConverter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class MetadataConverter {
2929
public static readonly DESTRUCTIVE_CHANGES_PRE_XML_FILE = 'destructiveChangesPre.xml';
3030
public static readonly DEFAULT_PACKAGE_PREFIX = 'metadataPackage';
3131

32-
private registry: RegistryAccess;
32+
private readonly registry: RegistryAccess;
3333

3434
public constructor(registry = new RegistryAccess()) {
3535
this.registry = registry;

src/convert/replacements.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ export const replacementIterations = async (input: string, replacements: MarkedR
6666
const lifecycleInstance = Lifecycle.getInstance();
6767
let output = input;
6868
for (const replacement of replacements) {
69-
// TODO: node 16+ has String.replaceAll for non-regex scenarios
70-
const regex =
71-
typeof replacement.toReplace === 'string' ? new RegExp(replacement.toReplace, 'g') : replacement.toReplace;
72-
const replaced = output.replace(regex, replacement.replaceWith ?? '');
69+
const replaced = output.replaceAll(new RegExp(replacement.toReplace, 'g'), replacement.replaceWith ?? '');
7370

7471
if (replaced !== output) {
7572
output = replaced;

src/convert/streams.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export abstract class ComponentWriter extends Writable {
118118
protected rootDestination?: SourcePath;
119119
protected logger: Logger;
120120

121-
public constructor(rootDestination?: SourcePath) {
121+
protected constructor(rootDestination?: SourcePath) {
122122
super({ objectMode: true });
123123
this.rootDestination = rootDestination;
124124
this.logger = Logger.childFromRoot(this.constructor.name);

src/registry/registryAccess.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Messages.importMessagesDirectory(__dirname);
1717
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
1818

1919
export class RegistryAccess {
20-
private registry: MetadataRegistry;
20+
private readonly registry: MetadataRegistry;
2121
private strictFolderTypes?: MetadataType[];
2222
private folderContentTypes?: MetadataType[];
2323
private aliasTypes?: MetadataType[];

src/resolve/adapters/sourceAdapterFactory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Messages.importMessagesDirectory(__dirname);
2222
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
2323

2424
export class SourceAdapterFactory {
25-
private registry: RegistryAccess;
26-
private tree: TreeContainer;
25+
private readonly registry: RegistryAccess;
26+
private readonly tree: TreeContainer;
2727

2828
public constructor(registry: RegistryAccess, tree: TreeContainer) {
2929
this.registry = registry;

src/resolve/connectionResolver.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ const getLogger = (): Logger => {
5252
* in the registry.
5353
*/
5454
export class ConnectionResolver {
55-
private connection: Connection;
56-
private registry: RegistryAccess;
55+
private readonly connection: Connection;
56+
private readonly registry: RegistryAccess;
5757

5858
// Array of metadata type names to use for listMembers. By default it includes
5959
// all types defined in the registry.
60-
private mdTypeNames: string[];
60+
private readonly mdTypeNames: string[];
6161

62-
private requestBatchSize: number;
62+
private readonly requestBatchSize: number;
6363

6464
public constructor(connection: Connection, registry = new RegistryAccess(), mdTypes?: string[]) {
6565
this.connection = connection;

src/resolve/manifestResolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const getValidatedType =
102102
(typeMembers: ParsedPackageTypeMembers): ParsedPackageTypeMembers => {
103103
let typeName = typeMembers.name;
104104
// protect against empty/invalid typeMember definitions in the manifest
105-
if (typeof typeName !== 'string' || typeName.length === 0) {
105+
if (typeName.length === 0) {
106106
if (typeof typeName === 'object') {
107107
typeName = JSON.stringify(typeName);
108108
}

src/resolve/treeContainers.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/* eslint-disable class-methods-use-this */
88
import { join, dirname, basename, normalize, sep } from 'node:path';
99
import { Readable } from 'node:stream';
10-
import { statSync, existsSync, readdirSync, createReadStream, readFileSync } from 'graceful-fs';
10+
import { statSync, existsSync, readdirSync, createReadStream, promises, readFileSync } from 'graceful-fs';
1111
import JSZip from 'jszip';
1212
import { Messages, SfError } from '@salesforce/core';
1313
import { isString } from '@salesforce/ts-types';
@@ -105,8 +105,7 @@ export class NodeFSTreeContainer extends TreeContainer {
105105
}
106106

107107
public readFile(fsPath: SourcePath): Promise<Buffer> {
108-
// significant enough performance increase using sync instead of fs.promise version
109-
return Promise.resolve(readFileSync(fsPath));
108+
return promises.readFile(fsPath);
110109
}
111110

112111
public readFileSync(fsPath: SourcePath): Buffer {

src/utils/path.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { basename, dirname, extname, sep, join } from 'node:path';
8+
import { basename, dirname, extname, join, sep } from 'node:path';
99
import { Optional } from '@salesforce/ts-types';
1010
import { SfdxFileFormat } from '../convert/types';
1111
import { SourcePath } from '../common/types';
@@ -116,10 +116,7 @@ export function parseNestedFullName(fsPath: string, directoryName: string): stri
116116
return;
117117
}
118118
const pathPrefix = pathSplits.slice(pathSplits.lastIndexOf(directoryName) + 1);
119-
// the eslint comment should remain until strictMode is fully implemented
120-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
121-
const fileName = (pathSplits.pop() as string).replace('-meta.xml', '').split('.')[0];
122-
pathPrefix[pathPrefix.length - 1] = fileName;
119+
pathPrefix[pathPrefix.length - 1] = (pathSplits.pop() as string).replace('-meta.xml', '').split('.')[0];
123120
return pathPrefix.join('/');
124121
}
125122

test/collections/componentSet.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,7 @@ describe('ComponentSet', () => {
439439
apiVersion: testApiVersionAsString,
440440
});
441441
$$.SANDBOX.stub(RegistryAccess.prototype, 'getTypeByName').returns(registry.types.apexclass);
442-
const manifest = manifestFiles.ONE_FOLDER_MEMBER;
443-
const set = await ComponentSet.fromManifest(manifest.name);
442+
const set = await ComponentSet.fromManifest(manifestFiles.ONE_FOLDER_MEMBER.name);
444443

445444
const result = set.toArray();
446445

test/resolve/treeContainers.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('Tree Containers', () => {
108108
});
109109

110110
it('should use expected Node API for readFile', async () => {
111-
const readFileStub = env.stub(fs, 'readFileSync');
111+
const readFileStub = env.stub(fs.promises, 'readFile');
112112
// @ts-ignore wants Dirents but string[] works as well
113113
readFileStub.withArgs(path).resolves(Buffer.from('test'));
114114
const data = await tree.readFile(path);

test/snapshot/helper/conversions.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ const getFullPath = (file: fs.Dirent) => path.join(file.path, file.name);
128128
/** dirEnts are sometimes folder, we don't want those. And we need the full paths */
129129
export const dirEntsToPaths = (dirEnts: fs.Dirent[]): string[] => dirEnts.filter(isFile).map(getFullPath);
130130

131-
const shouldIgnore = (file: string): boolean => {
131+
const shouldIgnore = (file: string): boolean =>
132132
// binary zip/unzip isn't exactly the same, so we "skip" that one
133-
if (file.includes('leafletjs.resource')) return true;
134-
return false;
135-
};
133+
file.includes('leafletjs.resource');
136134

137135
/**
138136
* rather than the full path, gets the "project relative" parts based on format
@@ -151,12 +149,3 @@ const pathPartsAfter = (file: string, after: string): string => {
151149
const parts = file.split(path.sep);
152150
return parts.slice(parts.indexOf(after) + 1).join(path.sep);
153151
};
154-
155-
/** Wrap a function with it or pass it to map, and it will log the contents */
156-
// @ts-ignore - keep this around for use when debugging.
157-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
158-
const logArgs = <T>(args: T): T => {
159-
// eslint-disable-next-line no-console
160-
typeof args === 'string' ? console.log(args) : JSON.stringify(args, null, 2);
161-
return args;
162-
};

test/utils/getMissingTypes.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { CoverageObjectType, CoverageObject } from '../../src/registry/types';
7+
import { CoverageObject, CoverageObjectType } from '../../src/registry/types';
88
import { hasUnsupportedFeatures, metadataTypes } from '../../src/registry/nonSupportedTypes';
99
import { MetadataRegistry } from '../../src';
1010

@@ -23,6 +23,5 @@ export const getMissingTypes = (
2323
regType.name,
2424
...(regType.children ? Object.values(regType.children.types).map((child) => child.name) : []),
2525
]);
26-
const missingTypes = metadataApiTypesFromCoverage.filter(([key]) => !registryTypeNames.includes(key));
27-
return missingTypes;
26+
return metadataApiTypesFromCoverage.filter(([key]) => !registryTypeNames.includes(key));
2827
};

0 commit comments

Comments
 (0)