Skip to content

Commit

Permalink
Merge pull request #76 from mcarvin8/feat/remove-git
Browse files Browse the repository at this point in the history
feat: remove dependency on git repos
  • Loading branch information
renatoliveira authored Oct 28, 2024
2 parents 020aae8 + 8e073bf commit 288c5fe
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 111 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

A plugin that generates a list of tests that your, ideally, automated process should run, so you can save time by not running all tests in your Salesforce org and also save time by not specifying them manually.

This plugin is intended to be ran in any version control repository that follows the Salesforce DX project structure (`sfdx-project.json` file).

## Install

Simply issue a install command with `sf`, as in:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"@salesforce/core": "^8.6.1",
"@salesforce/sf-plugins-core": "^11.3.12",
"async": "^3.2.6",
"isomorphic-git": "^1.27.1",
"xml2js": "^0.6.2"
},
"devDependencies": {
Expand Down Expand Up @@ -38,7 +37,8 @@
"/lib",
"/messages",
"/oclif.manifest.json",
"/oclif.lock"
"/oclif.lock",
"/CHANGELOG.md"
],
"keywords": [
"force",
Expand Down
15 changes: 5 additions & 10 deletions src/helpers/getPackageDirectories.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
'use strict';
/* eslint-disable no-await-in-loop */

import { existsSync } from 'node:fs';
import { resolve, join } from 'node:path';
import { readFile, readdir, stat } from 'node:fs/promises';

import { SFDX_PROJECT_FILE_NAME } from './constants.js';
import { getRepoRoot } from './getRepoRoot.js';
import { SfdxProject } from './types.js';

const SEARCHABLE_METADATA_FOLDERS = ['classes', 'triggers', 'testSuites'];

export async function getPackageDirectories(): Promise<string[]> {
const repoRoot = await getRepoRoot();
const { repoRoot, dxConfigFilePath } = await getRepoRoot();

process.chdir(repoRoot);

const dxConfigPath = resolve(repoRoot, SFDX_PROJECT_FILE_NAME);

if (!existsSync(dxConfigPath)) {
throw Error(`Salesforce DX Config File does not exist in this path: ${dxConfigPath}`);
if (!repoRoot || !dxConfigFilePath) {
throw new Error('Failed to retrieve repository root or sfdx-project.json path.');
}

const sfdxProjectRaw: string = await readFile(dxConfigPath, 'utf-8');
process.chdir(repoRoot);
const sfdxProjectRaw: string = await readFile(dxConfigFilePath, 'utf-8');
const sfdxProject: SfdxProject = JSON.parse(sfdxProjectRaw) as SfdxProject;
const packageDirectories = sfdxProject.packageDirectories.map((directory) => resolve(repoRoot, directory.path));
const metadataPaths: string[] = [];
Expand Down
38 changes: 28 additions & 10 deletions src/helpers/getRepoRoot.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
'use strict';
import { promises as fsPromises, readFile, stat, readdir } from 'node:fs';
import git from 'isomorphic-git';
/* eslint-disable no-await-in-loop */
import { access } from 'node:fs/promises';
import { join, dirname } from 'node:path';

export async function getRepoRoot(): Promise<string> {
const fs = { promises: fsPromises, readFile, stat, readdir };
import { SFDX_PROJECT_FILE_NAME } from './constants.js';

const repoRoot = await git.findRoot({
fs,
filepath: process.cwd(),
});

return repoRoot;
export async function getRepoRoot(): Promise<{ repoRoot: string | undefined; dxConfigFilePath: string | undefined }> {
let currentDir = process.cwd();
let found = false;
let dxConfigFilePath: string | undefined;
let repoRoot: string | undefined;
do {
const filePath = join(currentDir, SFDX_PROJECT_FILE_NAME);
try {
// Check if sfdx-project.json exists in the current directory
await access(filePath);
dxConfigFilePath = filePath;
repoRoot = currentDir;
found = true;
} catch {
// If file not found, move up one directory level
const parentDir = dirname(currentDir);
if (currentDir === parentDir) {
// Reached the root without finding the file, throw an error
throw new Error(`${SFDX_PROJECT_FILE_NAME} not found in any parent directory.`);
}
currentDir = parentDir;
}
} while (!found);
return { repoRoot, dxConfigFilePath };
}
95 changes: 6 additions & 89 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2470,10 +2470,6 @@ assertion-error@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz"

async-lock@^1.4.1:
version "1.4.1"
resolved "https://registry.npmjs.org/async-lock/-/async-lock-1.4.1.tgz"

async-retry@^1.3.3:
version "1.3.3"
resolved "https://registry.npmjs.org/async-retry/-/async-retry-1.3.3.tgz"
Expand Down Expand Up @@ -2737,10 +2733,6 @@ ci-info@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/ci-info/-/ci-info-4.0.0.tgz"

clean-git-ref@^2.0.1:
version "2.0.1"
resolved "https://registry.npmjs.org/clean-git-ref/-/clean-git-ref-2.0.1.tgz"

clean-regexp@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz"
Expand Down Expand Up @@ -2959,10 +2951,6 @@ cosmiconfig@^9.0.0:
js-yaml "^4.1.0"
parse-json "^5.2.0"

crc-32@^1.2.0:
version "1.2.2"
resolved "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz"

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz"
Expand Down Expand Up @@ -3116,10 +3104,6 @@ devlop@^1.0.0:
dependencies:
dequal "^2.0.0"

[email protected]:
version "0.0.3"
resolved "https://registry.npmjs.org/diff3/-/diff3-0.0.3.tgz"

diff@^4.0.1, diff@^4.0.2:
version "4.0.2"
resolved "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz"
Expand Down Expand Up @@ -4212,7 +4196,7 @@ ieee754@^1.2.1:
version "1.2.1"
resolved "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz"

ignore@^5.1.4, ignore@^5.2.0, ignore@^5.2.4, ignore@^5.3.0:
ignore@^5.2.0, ignore@^5.2.4, ignore@^5.3.0:
version "5.3.2"
resolved "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz"

Expand Down Expand Up @@ -4483,22 +4467,6 @@ isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz"

isomorphic-git@^1.27.1:
version "1.27.1"
resolved "https://registry.npmjs.org/isomorphic-git/-/isomorphic-git-1.27.1.tgz"
dependencies:
async-lock "^1.4.1"
clean-git-ref "^2.0.1"
crc-32 "^1.2.0"
diff3 "0.0.3"
ignore "^5.1.4"
minimisted "^2.0.0"
pako "^1.0.10"
pify "^4.0.1"
readable-stream "^3.4.0"
sha.js "^2.4.9"
simple-get "^4.0.1"

istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
version "3.2.2"
resolved "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz"
Expand Down Expand Up @@ -5106,16 +5074,10 @@ [email protected]:
is-plain-obj "^1.1.0"
kind-of "^6.0.3"

minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6, minimist@^1.2.8:
minimist@^1.2.0, minimist@^1.2.6, minimist@^1.2.8:
version "1.2.8"
resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz"

minimisted@^2.0.0:
version "2.0.1"
resolved "https://registry.npmjs.org/minimisted/-/minimisted-2.0.1.tgz"
dependencies:
minimist "^1.2.5"

"minipass@^5.0.0 || ^6.0.2 || ^7.0.0", minipass@^7.1.2:
version "7.1.2"
resolved "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz"
Expand Down Expand Up @@ -5454,7 +5416,7 @@ package-json-from-dist@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz"

pako@^1.0.10, pako@~1.0.2:
pako@~1.0.2:
version "1.0.11"
resolved "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz"

Expand Down Expand Up @@ -5562,10 +5524,6 @@ picomatch@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/picomatch/-/picomatch-3.0.1.tgz"

pify@^4.0.1:
version "4.0.1"
resolved "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz"

pino-abstract-transport@^1.0.0, pino-abstract-transport@^1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-1.2.0.tgz"
Expand Down Expand Up @@ -6011,13 +5969,6 @@ setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz"

sha.js@^2.4.9:
version "2.4.11"
resolved "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz"
dependencies:
inherits "^2.0.1"
safe-buffer "^5.0.1"

shebang-command@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz"
Expand Down Expand Up @@ -6064,18 +6015,6 @@ signal-exit@^4.0.1, signal-exit@^4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz"

simple-concat@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz"

simple-get@^4.0.1:
version "4.0.1"
resolved "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz"
dependencies:
decompress-response "^6.0.0"
once "^1.3.1"
simple-concat "^1.0.0"

[email protected]:
version "10.0.0"
resolved "https://registry.npmjs.org/sinon/-/sinon-10.0.0.tgz"
Expand Down Expand Up @@ -6220,15 +6159,7 @@ srcset@^5.0.0:
version "5.0.1"
resolved "https://registry.npmjs.org/srcset/-/srcset-5.0.1.tgz"

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
dependencies:
Expand Down Expand Up @@ -6296,13 +6227,7 @@ stringify-entities@^4.0.0:
character-entities-html4 "^2.0.0"
character-entities-legacy "^3.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
dependencies:
ansi-regex "^5.0.1"

[email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", [email protected], strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
dependencies:
Expand Down Expand Up @@ -6834,7 +6759,7 @@ workerpool@^6.5.1:
version "6.5.1"
resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
dependencies:
Expand All @@ -6850,14 +6775,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz"
Expand Down

0 comments on commit 288c5fe

Please sign in to comment.