Skip to content

chore: follow IDEs warnings, improvements, switch to promise read to … #1521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -20,9 +20,6 @@ xunit.xml
junit-custom.xml
*.received.*

# nyc test coverage
.nyc_output

# Eclipse
.project

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

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

2 changes: 1 addition & 1 deletion src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ export class MetadataApiDeploy extends MetadataTransfer<
}
const connection = await this.getConnection();
// Recasting to use the project's version of the type
return connection.metadata.checkDeployStatus(this.id, true) as unknown as MetadataApiDeployStatus;
return (await connection.metadata.checkDeployStatus(this.id, true)) as unknown as MetadataApiDeployStatus;
}

/**
2 changes: 1 addition & 1 deletion src/client/metadataTransfer.ts
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ export abstract class MetadataTransfer<
private transferId: Options['id'];
private event = new EventEmitter();
private usernameOrConnection: string | Connection;
private apiVersion?: string;
private readonly apiVersion?: string;

public constructor({ usernameOrConnection, components, apiVersion, id }: Options) {
this.usernameOrConnection = usernameOrConnection;
2 changes: 0 additions & 2 deletions src/client/types.ts
Original file line number Diff line number Diff line change
@@ -140,8 +140,6 @@ export type MetadataApiDeployStatus = {
export type DeployDetails = {
componentFailures?: DeployMessage | DeployMessage[];
componentSuccesses?: DeployMessage | DeployMessage[];
// TODO: Add types for RetrieveResult
// retrieveResult?:
runTestResult?: RunTestResult;
};

8 changes: 3 additions & 5 deletions src/collections/componentSet.ts
Original file line number Diff line number Diff line change
@@ -221,12 +221,10 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
if (resolveIncludeSet && !deletionType) {
resolveIncludeSet.add(component);
}
if (resolvePreSet && deletionType === DestructiveChangesType.PRE) {
resolvePreSet.add(component, DestructiveChangesType.PRE);
}
if (resolvePostSet && deletionType === DestructiveChangesType.POST) {
resolvePostSet.add(component, DestructiveChangesType.POST);
if (resolvePreSet && deletionType) {
resolvePreSet.add(component, deletionType);
}

const memberIsWildcard = component.fullName === ComponentSet.WILDCARD;
if (options.resolveSourcePaths === undefined || !memberIsWildcard || options.forceAddWildcards) {
result.add(component, deletionType);
13 changes: 13 additions & 0 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
@@ -319,6 +319,19 @@ const getOrgComponentFilter = (
): FromConnectionOptions['componentFilter'] =>
metadata?.metadataEntries?.length
? (component: Partial<FileProperties>): boolean => {
// {
// "createdById": "005KR000000mVHLYA2",
// "createdByName": "User User",
// "createdDate": "2025-03-05T21:15:23.000Z",
// "fileName": "classes/FileUtilitiesTest.cls",
// "fullName": "FileUtilitiesTest",
// "id": "01pKR000000FgMQYA0",
// "lastModifiedById": "005KR000000mVHLYA2",
// "lastModifiedByName": "User User",
// "lastModifiedDate": "2025-03-05T21:15:23.000Z",
// "manageableState": "unmanaged",
// "type": "ApexClass"
// }
if (component.type && component.fullName) {
const mdMapEntry = mdMap.get(component.type);
// using minimatch versus RegExp provides better (more expected) matching results
2 changes: 1 addition & 1 deletion src/convert/metadataConverter.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ export class MetadataConverter {
public static readonly DESTRUCTIVE_CHANGES_PRE_XML_FILE = 'destructiveChangesPre.xml';
public static readonly DEFAULT_PACKAGE_PREFIX = 'metadataPackage';

private registry: RegistryAccess;
private readonly registry: RegistryAccess;

public constructor(registry = new RegistryAccess()) {
this.registry = registry;
5 changes: 1 addition & 4 deletions src/convert/replacements.ts
Original file line number Diff line number Diff line change
@@ -66,10 +66,7 @@ export const replacementIterations = async (input: string, replacements: MarkedR
const lifecycleInstance = Lifecycle.getInstance();
let output = input;
for (const replacement of replacements) {
// TODO: node 16+ has String.replaceAll for non-regex scenarios
const regex =
typeof replacement.toReplace === 'string' ? new RegExp(replacement.toReplace, 'g') : replacement.toReplace;
const replaced = output.replace(regex, replacement.replaceWith ?? '');
const replaced = output.replaceAll(new RegExp(replacement.toReplace, 'g'), replacement.replaceWith ?? '');

if (replaced !== output) {
output = replaced;
2 changes: 1 addition & 1 deletion src/convert/streams.ts
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ export abstract class ComponentWriter extends Writable {
protected rootDestination?: SourcePath;
protected logger: Logger;

public constructor(rootDestination?: SourcePath) {
protected constructor(rootDestination?: SourcePath) {
super({ objectMode: true });
this.rootDestination = rootDestination;
this.logger = Logger.childFromRoot(this.constructor.name);
2 changes: 1 addition & 1 deletion src/registry/registryAccess.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');

export class RegistryAccess {
private registry: MetadataRegistry;
private readonly registry: MetadataRegistry;
private strictFolderTypes?: MetadataType[];
private folderContentTypes?: MetadataType[];
private aliasTypes?: MetadataType[];
4 changes: 2 additions & 2 deletions src/resolve/adapters/sourceAdapterFactory.ts
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');

export class SourceAdapterFactory {
private registry: RegistryAccess;
private tree: TreeContainer;
private readonly registry: RegistryAccess;
private readonly tree: TreeContainer;

public constructor(registry: RegistryAccess, tree: TreeContainer) {
this.registry = registry;
8 changes: 4 additions & 4 deletions src/resolve/connectionResolver.ts
Original file line number Diff line number Diff line change
@@ -52,14 +52,14 @@ const getLogger = (): Logger => {
* in the registry.
*/
export class ConnectionResolver {
private connection: Connection;
private registry: RegistryAccess;
private readonly connection: Connection;
private readonly registry: RegistryAccess;

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

private requestBatchSize: number;
private readonly requestBatchSize: number;

public constructor(connection: Connection, registry = new RegistryAccess(), mdTypes?: string[]) {
this.connection = connection;
2 changes: 1 addition & 1 deletion src/resolve/manifestResolver.ts
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ const getValidatedType =
(typeMembers: ParsedPackageTypeMembers): ParsedPackageTypeMembers => {
let typeName = typeMembers.name;
// protect against empty/invalid typeMember definitions in the manifest
if (typeof typeName !== 'string' || typeName.length === 0) {
if (typeName.length === 0) {
if (typeof typeName === 'object') {
typeName = JSON.stringify(typeName);
}
5 changes: 2 additions & 3 deletions src/resolve/treeContainers.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
/* eslint-disable class-methods-use-this */
import { join, dirname, basename, normalize, sep } from 'node:path';
import { Readable } from 'node:stream';
import { statSync, existsSync, readdirSync, createReadStream, readFileSync } from 'graceful-fs';
import { statSync, existsSync, readdirSync, createReadStream, promises, readFileSync } from 'graceful-fs';
import JSZip from 'jszip';
import { Messages, SfError } from '@salesforce/core';
import { isString } from '@salesforce/ts-types';
@@ -105,8 +105,7 @@ export class NodeFSTreeContainer extends TreeContainer {
}

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

public readFileSync(fsPath: SourcePath): Buffer {
7 changes: 2 additions & 5 deletions src/utils/path.ts
Original file line number Diff line number Diff line change
@@ -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 { basename, dirname, extname, sep, join } from 'node:path';
import { basename, dirname, extname, join, sep } from 'node:path';
import { Optional } from '@salesforce/ts-types';
import { SfdxFileFormat } from '../convert/types';
import { SourcePath } from '../common/types';
@@ -116,10 +116,7 @@ export function parseNestedFullName(fsPath: string, directoryName: string): stri
return;
}
const pathPrefix = pathSplits.slice(pathSplits.lastIndexOf(directoryName) + 1);
// the eslint comment should remain until strictMode is fully implemented
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const fileName = (pathSplits.pop() as string).replace('-meta.xml', '').split('.')[0];
pathPrefix[pathPrefix.length - 1] = fileName;
pathPrefix[pathPrefix.length - 1] = (pathSplits.pop() as string).replace('-meta.xml', '').split('.')[0];
return pathPrefix.join('/');
}

3 changes: 1 addition & 2 deletions test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
@@ -439,8 +439,7 @@ describe('ComponentSet', () => {
apiVersion: testApiVersionAsString,
});
$$.SANDBOX.stub(RegistryAccess.prototype, 'getTypeByName').returns(registry.types.apexclass);
const manifest = manifestFiles.ONE_FOLDER_MEMBER;
const set = await ComponentSet.fromManifest(manifest.name);
const set = await ComponentSet.fromManifest(manifestFiles.ONE_FOLDER_MEMBER.name);

const result = set.toArray();

2 changes: 1 addition & 1 deletion test/resolve/treeContainers.test.ts
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ describe('Tree Containers', () => {
});

it('should use expected Node API for readFile', async () => {
const readFileStub = env.stub(fs, 'readFileSync');
const readFileStub = env.stub(fs.promises, 'readFile');
// @ts-ignore wants Dirents but string[] works as well
readFileStub.withArgs(path).resolves(Buffer.from('test'));
const data = await tree.readFile(path);
15 changes: 2 additions & 13 deletions test/snapshot/helper/conversions.ts
Original file line number Diff line number Diff line change
@@ -128,11 +128,9 @@ const getFullPath = (file: fs.Dirent) => path.join(file.path, file.name);
/** dirEnts are sometimes folder, we don't want those. And we need the full paths */
export const dirEntsToPaths = (dirEnts: fs.Dirent[]): string[] => dirEnts.filter(isFile).map(getFullPath);

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

/**
* rather than the full path, gets the "project relative" parts based on format
@@ -151,12 +149,3 @@ const pathPartsAfter = (file: string, after: string): string => {
const parts = file.split(path.sep);
return parts.slice(parts.indexOf(after) + 1).join(path.sep);
};

/** Wrap a function with it or pass it to map, and it will log the contents */
// @ts-ignore - keep this around for use when debugging.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const logArgs = <T>(args: T): T => {
// eslint-disable-next-line no-console
typeof args === 'string' ? console.log(args) : JSON.stringify(args, null, 2);
return args;
};
5 changes: 2 additions & 3 deletions test/utils/getMissingTypes.ts
Original file line number Diff line number Diff line change
@@ -4,7 +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 { CoverageObjectType, CoverageObject } from '../../src/registry/types';
import { CoverageObject, CoverageObjectType } from '../../src/registry/types';
import { hasUnsupportedFeatures, metadataTypes } from '../../src/registry/nonSupportedTypes';
import { MetadataRegistry } from '../../src';

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