Skip to content

Commit

Permalink
fix: refactor interface=>type, no-param-reassign (#965)
Browse files Browse the repository at this point in the history
* refactor: types to interfaces

* chore: bump stl for interfaces => types

* refactor: no-param-reassign
  • Loading branch information
mshanemc authored Apr 8, 2024
1 parent 50135b9 commit b10a4f2
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 126 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"@salesforce/plugin-info": "^3.1.0",
"@salesforce/sf-plugins-core": "^8.0.2",
"@salesforce/source-deploy-retrieve": "^10.7.0",
"@salesforce/source-tracking": "^5.2.1",
"@salesforce/source-tracking": "^5.2.4",
"@salesforce/ts-types": "^2.0.9",
"chalk": "^5.3.0"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.1.4",
"@salesforce/cli-plugins-testkit": "^5.1.13",
"@salesforce/dev-scripts": "^8.4.3",
"@salesforce/dev-scripts": "^8.5.0",
"@salesforce/plugin-command-reference": "^3.0.73",
"@salesforce/source-testkit": "^2.1.108",
"@salesforce/ts-sinon": "^1.4.19",
Expand Down
5 changes: 3 additions & 2 deletions src/commands/project/convert/mdapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ import { MetadataConvertResultFormatter } from '../../../formatters/metadataConv
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'convert.mdapi');

export interface EnsureFsFlagOptions {
export type EnsureFsFlagOptions = {
flagName: string;
path: string;
type: 'dir' | 'file' | 'any';
throwOnENOENT?: boolean;
}
};

export class Mdapi extends SfCommand<ConvertMdapiJson> {
public static readonly aliases = ['force:mdapi:convert'];
public static readonly deprecateAliases = true;
Expand Down
5 changes: 2 additions & 3 deletions src/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,12 @@ export async function executeDeploy(
await deploy.start();
}
} else {
// mdapi format deploys don't require a project, but at this point we need one
project ??= await SfProject.resolve();
// instantiate source tracking
// stl will decide, based on the org's properties, what needs to be done
const stl = await SourceTracking.create({
org,
project,
// mdapi format deploys don't require a project, but at this point we need one
project: project ?? (await SfProject.resolve()),
subscribeSDREvents: true,
ignoreConflicts: opts['ignore-conflicts'],
});
Expand Down
6 changes: 3 additions & 3 deletions src/utils/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ async function ensureDirectoryPath(path: string): Promise<string> {
return resolvedPath;
}

function resolveZipFileName(zipFileName?: string): string {
const resolveZipFileName = (zipFileName?: string): string => {
if (!zipFileName) {
return DEFAULT_ZIP_FILE_NAME;
}
// If no file extension was provided append, '.zip'
return !extname(zipFileName) ? (zipFileName += '.zip') : zipFileName;
}
return !extname(zipFileName) ? `${zipFileName}.zip` : zipFileName;
};

export const DEFAULT_ZIP_FILE_NAME = 'unpackaged.zip';

Expand Down
4 changes: 2 additions & 2 deletions src/utils/previewOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export type PreviewFile = {
operation?: BaseOperation | 'deletePost' | 'deletePre';
};

export interface PreviewResult {
export type PreviewResult = {
ignored: PreviewFile[];
conflicts: PreviewFile[];
toDeploy: PreviewFile[];
toDelete: PreviewFile[];
toRetrieve: PreviewFile[];
}
};

const ensureAbsolutePath = (f: string): string => (isAbsolute(f) ? f : resolve(f));

Expand Down
4 changes: 2 additions & 2 deletions test/nuts/convert/mdapi.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { ConvertMdapiJson } from '../../../src/utils/types.js';
let session: TestSession;

const writeManifest = (manifestPath: string, contents?: string) => {
contents ??= `<?xml version="1.0" encoding="UTF-8"?>
const defaultContents = `<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<version>53.0</version>
</Package>`;
fs.writeFileSync(manifestPath, contents);
fs.writeFileSync(manifestPath, contents ?? defaultContents);
};

describe('project convert mdapi NUTs', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/nuts/convert/source.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { ConvertResultJson } from '../../../src/utils/types.js';
let session: TestSession;

const writeManifest = (manifestPath: string, contents?: string) => {
contents ??= `<?xml version="1.0" encoding="UTF-8"?>
const defaultContents = `<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>*</members>
<name>ApexClass</name>
</types>
<version>53.0</version>
</Package>`;
fs.writeFileSync(manifestPath, contents);
fs.writeFileSync(manifestPath, contents ?? defaultContents);
};

describe('project convert source NUTs', () => {
Expand Down
3 changes: 3 additions & 0 deletions test/nuts/digitalExperienceBundle/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* 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
*/
// existing tests do a lot mutation. I decided to leave rather than refactor
/* eslint-disable no-param-reassign */

import { join, relative } from 'node:path';
import * as fs from 'node:fs';
import { FileResponse } from '@salesforce/source-deploy-retrieve';
Expand Down
9 changes: 4 additions & 5 deletions test/nuts/specialTypes/folderTypes.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ describe('metadata types that go in folders', () => {
];

const getRelativeFileResponses = (resp: FileResponse[]) =>
resp.map((s) => {
// grab the last 2 directories with the file only
s.filePath = s.filePath?.split(path.sep).slice(-3).join(path.sep);
return s;
});
resp.map((fr) => ({
...fr,
filePath: fr.filePath?.split(path.sep).slice(-3).join(path.sep),
}));

it('can generate manifest for just the emailTemplates', () => {
const pathToEmails = path.join('force-app', 'main', 'default', 'email');
Expand Down
Loading

0 comments on commit b10a4f2

Please sign in to comment.