Skip to content

Commit

Permalink
feat: no shelljs
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 6, 2023
1 parent ad2cb25 commit 95828cf
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@salesforce/source-deploy-retrieve": "^9.8.1",
"@salesforce/source-tracking": "^4.2.20",
"chalk": "^4.1.2",
"shelljs": "^0.8.5",
"tslib": "^2"
},
"devDependencies": {
Expand All @@ -29,7 +28,6 @@
"@salesforce/ts-sinon": "1.4.15",
"@salesforce/ts-types": "^2.0.8",
"@swc/core": "1.3.39",
"@types/shelljs": "^0.8.14",
"cross-env": "^7.0.3",
"eslint-plugin-sf-plugin": "^1.16.13",
"jsforce": "^2.0.0-beta.28",
Expand Down
7 changes: 3 additions & 4 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { EOL } from 'node:os';
import { writeFile, readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { exec } from 'node:child_process';
import { Hook } from '@oclif/core';
import { Messages } from '@salesforce/core';
import { Env, parseJsonMap } from '@salesforce/kit';
Expand All @@ -21,9 +22,7 @@ import {
SfHook,
Flags,
} from '@salesforce/sf-plugins-core';
import { exec } from 'shelljs';
import { DeployerResult } from '@salesforce/sf-plugins-core/lib/deployer';

Messages.importMessagesDirectory(__dirname);

const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy');
Expand Down Expand Up @@ -144,8 +143,8 @@ export default class Deploy extends SfCommand<void> {
const addition = `${EOL}${EOL}# Deploy Options${EOL}${DEPLOY_OPTIONS_FILE}${EOL}`;
await writeFile('.gitignore', `${gitignore}${addition}`);
}
exec('git add .gitignore', { silent: true });
exec(`git commit -am "Add ${DEPLOY_OPTIONS_FILE} to .gitignore"`, { silent: true });
exec('git add .gitignore');
exec(`git commit -am "Add ${DEPLOY_OPTIONS_FILE} to .gitignore"`);
}

// this used to be async when it was using fs-extra. Presered public api
Expand Down
21 changes: 9 additions & 12 deletions test/nuts/delete/source.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as path from 'node:path';
import { expect } from 'chai';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { SourceTestkit } from '@salesforce/source-testkit';
import { exec } from 'shelljs';
import { FileResponse } from '@salesforce/source-deploy-retrieve';
import { AuthInfo, Connection } from '@salesforce/core';
import { ensureArray } from '@salesforce/ts-types';
Expand Down Expand Up @@ -184,16 +183,14 @@ describe('project delete source NUTs', () => {
it('should source:delete a remote-only ApexClass from the org', async () => {
const { apexName, pathToClass } = createApexClass();
const query = () =>
JSON.parse(
exec(
`sf data:query -q "SELECT IsNameObsolete FROM SourceMember WHERE MemberType='ApexClass' AND MemberName='${apexName}' LIMIT 1" -t --json`,
{ silent: true }
)
) as { result: { records: Array<{ IsNameObsolete: boolean }> } };

let soql = query();
execCmd<{ records: Array<{ IsNameObsolete: boolean }> }>(
`sf data:query -q "SELECT IsNameObsolete FROM SourceMember WHERE MemberType='ApexClass' AND MemberName='${apexName}' LIMIT 1" -t --json`,
{ silent: true, cli: 'sf' }
);

let soql = query().jsonOutput?.result;
// the ApexClass is present in the org
expect(soql.result.records[0].IsNameObsolete).to.be.false;
expect(soql?.records[0].IsNameObsolete).to.be.false;
await testkit.deleteGlobs(['force-app/main/default/classes/myApexClass.*']);
const response = execCmd<DeleteSourceJson>(
`project:delete:source --json --no-prompt --metadata ApexClass:${apexName}`,
Expand All @@ -204,9 +201,9 @@ describe('project delete source NUTs', () => {
// remote only delete won't have an associated filepath
expect(response?.deletedSource).to.have.length(0);
expect(fs.existsSync(pathToClass)).to.be.false;
soql = query();
soql = query().jsonOutput?.result;
// the apex class has been deleted in the org
expect(soql.result.records[0].IsNameObsolete).to.be.true;
expect(soql?.records[0].IsNameObsolete).to.be.true;
});

it('should NOT delete local files with --checkonly', () => {
Expand Down
3 changes: 1 addition & 2 deletions test/nuts/generateNuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import * as path from 'node:path';
import * as fs from 'node:fs';
import * as shelljs from 'shelljs';
import { RepoConfig, TEST_REPOS_MAP } from './testMatrix';

const SEED_FILTER = process.env.PLUGIN_DEPLOY_RETRIEVE_SEED_FILTER ?? '';
Expand Down Expand Up @@ -41,7 +40,7 @@ function generateNut(generatedDir: string, seedName: string, seedContents: strin

function generateNuts(): void {
const generatedDir = path.resolve(__dirname, 'generated');
shelljs.rm('-rf', generatedDir);
fs.rmSync(generatedDir, { recursive: true, force: true });
fs.mkdirSync(generatedDir, { recursive: true });
const seeds = getSeedFiles();
for (const seed of seeds) {
Expand Down
4 changes: 2 additions & 2 deletions test/nuts/retrieve/metadata.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import * as path from 'node:path';
import * as fs from 'node:fs';
import { execCmd } from '@salesforce/cli-plugins-testkit';
import { SourceTestkit } from '@salesforce/source-testkit';
import { exec } from 'shelljs';
import { expect } from 'chai';

const ELECTRON = { id: '04t6A000002zgKSQAY', name: 'ElectronBranding' };
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('retrieve metadata NUTs', () => {

describe('--package-name flag', () => {
it('should retrieve an installed package', async () => {
exec(`sf force:package:install --noprompt --package ${ELECTRON.id} --wait 5 --json`, { silent: true });
execCmd(`force:package:install --noprompt --package ${ELECTRON.id} --wait 5 --json`, { silent: true, cli: 'sf' });

await testkit.retrieve({ args: `--package-name "${ELECTRON.name}"` });
await testkit.expect.packagesToBeRetrieved([ELECTRON.name]);
Expand Down
4 changes: 2 additions & 2 deletions test/nuts/tracking/forceIgnore.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import * as path from 'node:path';
import * as fs from 'node:fs';
import { expect } from 'chai';
import * as shell from 'shelljs';

import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { AuthInfo, Connection } from '@salesforce/core';
Expand Down Expand Up @@ -107,9 +106,10 @@ describe('forceignore changes', () => {
await fs.promises.writeFile(path.join(session.project.dir, '.forceignore'), newForceIgnore);

// add a file in the local source
shell.exec(`sfdx force:apex:class:create -n UnIgnoreTest --outputdir ${classdir} --api-version 58.0`, {
execCmd(`sfdx force:apex:class:create -n UnIgnoreTest --outputdir ${classdir} --api-version 58.0`, {
cwd: session.project.dir,
silent: true,
cli: 'sf',
});
// another error when there's nothing to push
const output = execCmd<DeployResultJson>('deploy:metadata --json', {
Expand Down

0 comments on commit 95828cf

Please sign in to comment.