Skip to content

Commit

Permalink
fix: interfaces to types, no-param-reassign for windows normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 5, 2024
1 parent 4852617 commit a4be02c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/shared/localComponentSetArray.ts
Expand Up @@ -17,16 +17,16 @@ import {
import { sourceComponentGuard } from './guards';
import { supportsPartialDelete, pathIsInFolder } from './functions';

interface GroupedFileInput {
type GroupedFileInput = {
packageDirs: NamedPackageDir[];
nonDeletes: string[];
deletes: string[];
}
interface GroupedFile {
};
type GroupedFile = {
path: string;
nonDeletes: string[];
deletes: string[];
}
};

export const getGroupedFiles = (input: GroupedFileInput, byPackageDir = false): GroupedFile[] =>
(byPackageDir ? getSequential(input) : getNonSequential(input)).filter(
Expand Down
23 changes: 10 additions & 13 deletions src/shared/localShadowRepo.ts
Expand Up @@ -34,11 +34,11 @@ const redirectToCliRepoError = (e: unknown): never => {
throw e;
};

interface ShadowRepoOptions {
type ShadowRepoOptions = {
orgId: string;
projectPath: string;
packageDirs: NamedPackageDir[];
}
};

// https://isomorphic-git.org/docs/en/statusMatrix#docsNav
type StatusRow = [file: string, head: number, workdir: number, stage: number];
Expand All @@ -48,12 +48,12 @@ const FILE = 0;
const HEAD = 1;
const WORKDIR = 2;

interface CommitRequest {
type CommitRequest = {
deployedFiles?: string[];
deletedFiles?: string[];
message?: string;
needsUpdatedStatus?: boolean;
}
};

export class ShadowRepo {
private static instanceMap = new Map<string, ShadowRepo>();
Expand Down Expand Up @@ -256,16 +256,13 @@ export class ShadowRepo {
deployedFiles: deployedFiles.length,
deletedFiles: deletedFiles.length,
});
// these are stored in posix/style/path format. We have to convert inbound stuff from windows
if (this.isWindows) {
this.logger.trace('start: transforming windows paths to posix');
deployedFiles = deployedFiles.map(normalize).map(ensurePosix);
deletedFiles = deletedFiles.map(normalize).map(ensurePosix);
this.logger.trace('done: transforming windows paths to posix');
}

if (deployedFiles.length) {
const chunks = chunkArray([...new Set(deployedFiles)], this.maxFileAdd);
const chunks = chunkArray(
// these are stored in posix/style/path format. We have to convert inbound stuff from windows
[...new Set(this.isWindows ? deployedFiles.map(normalize).map(ensurePosix) : deployedFiles)],
this.maxFileAdd
);
for (const chunk of chunks) {
try {
this.logger.debug(`adding ${chunk.length} files of ${deployedFiles.length} deployedFiles to git`);
Expand Down Expand Up @@ -297,7 +294,7 @@ export class ShadowRepo {
}
}

for (const filepath of [...new Set(deletedFiles)]) {
for (const filepath of [...new Set(this.isWindows ? deletedFiles.map(normalize).map(ensurePosix) : deletedFiles)]) {
try {
// these need to be done sequentially because isogit manages file locking. Isogit remove does not support multiple files at once
// eslint-disable-next-line no-await-in-loop
Expand Down
4 changes: 2 additions & 2 deletions src/shared/remoteSourceTrackingService.ts
Expand Up @@ -42,10 +42,10 @@ const CONSECUTIVE_EMPTY_POLLING_RESULT_LIMIT =
(env.getNumber('SFDX_SOURCE_MEMBER_POLLING_TIMEOUT') ?? 120) / Duration.milliseconds(POLLING_DELAY_MS).seconds;

/** Options for RemoteSourceTrackingService.getInstance */
export interface RemoteSourceTrackingServiceOptions {
export type RemoteSourceTrackingServiceOptions = {
org: Org;
projectPath: string;
}
};

/**
* This service handles source tracking of metadata between a local project and an org.
Expand Down
12 changes: 6 additions & 6 deletions src/shared/types.ts
Expand Up @@ -8,11 +8,11 @@
import { FileResponse, SourceComponent } from '@salesforce/source-deploy-retrieve';
import { SfError } from '@salesforce/core';

export interface ChangeOptions {
export type ChangeOptions = {
origin: 'local' | 'remote';
state: 'add' | 'delete' | 'modify' | 'nondelete';
format: 'ChangeResult' | 'SourceComponent' | 'string' | 'ChangeResultWithPaths';
}
};

export type RemoteSyncInput = Pick<FileResponse, 'fullName' | 'filePath' | 'type' | 'state'>;

Expand All @@ -21,10 +21,10 @@ export type StatusOutputRow = Pick<FileResponse, 'fullName' | 'filePath' | 'type
ignored?: boolean;
} & Pick<ChangeOptions, 'origin' | 'state'>;

export interface LocalUpdateOptions {
export type LocalUpdateOptions = {
files?: string[];
deletedFiles?: string[];
}
};

export type RemoteChangeElement = {
name: string;
Expand Down Expand Up @@ -57,12 +57,12 @@ export type SourceMember = {
ignored?: boolean;
};

export interface ConflictResponse {
export type ConflictResponse = {
state: 'Conflict';
fullName: string;
type: string;
filePath: string;
}
};

// this and the related class are not enforced but a convention of this library.
// This helps the consumers get correct typing--if the error name matches SourceConflictError,
Expand Down
4 changes: 2 additions & 2 deletions src/sourceTracking.ts
Expand Up @@ -68,7 +68,7 @@ import { populateFilePaths } from './shared/populateFilePaths';
import { populateTypesAndNames } from './shared/populateTypesAndNames';
import { getComponentSets, getGroupedFiles } from './shared/localComponentSetArray';
import { sourceComponentIsCustomLabel } from './shared/functions';
export interface SourceTrackingOptions {
export type SourceTrackingOptions = {
org: Org;
project: SfProject;

Expand All @@ -87,7 +87,7 @@ export interface SourceTrackingOptions {
* If you're using STL as part of a long running process (ex: vscode extensions), set this to false
*/
ignoreLocalCache?: boolean;
}
};

type RemoteChangesResults = {
componentSetFromNonDeletes: ComponentSet;
Expand Down
1 change: 1 addition & 0 deletions test/unit/remoteSourceTracking.test.ts
Expand Up @@ -12,6 +12,7 @@ import { existsSync } from 'node:fs';
import { sep, dirname } from 'node:path';
import { MockTestOrgData, instantiateContext, stubContext, restoreContext } from '@salesforce/core/lib/testSetup';
import { Logger, Messages, Org } from '@salesforce/core';
// eslint-disable-next-line no-restricted-imports
import * as kit from '@salesforce/kit';
import { expect } from 'chai';
import { ComponentStatus } from '@salesforce/source-deploy-retrieve';
Expand Down

0 comments on commit a4be02c

Please sign in to comment.