@ds-sfdc/sfparty 1.3.9 → 1.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+ . "$(dirname -- "$0")/_/husky.sh"
3
+
4
+ npm test
package/README.md CHANGED
@@ -38,6 +38,10 @@ sfparty split
38
38
  sfparty combine
39
39
  ```
40
40
 
41
+ ### Update
42
+ ```bash
43
+ sfparty update
44
+ ```
41
45
  ### Options
42
46
 
43
47
  ```
@@ -48,6 +52,7 @@ sfparty combine
48
52
  -t, --target target path to directory to create yaml/json files
49
53
  -g, --git combine files based on git commits
50
54
  -h, --help Show help
55
+ -v, --version Show version
51
56
  ```
52
57
 
53
58
  ### Combine Options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ds-sfdc/sfparty",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "description": "Salesforce metadata XML splitter for CI/CD",
5
5
  "type": "module",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict'
3
- import { spawnSync } from 'child_process'
4
- import { readFileSync } from 'fs'
3
+ import { spawnSync, spawn, execSync } from 'child_process'
4
+ import fs from 'fs'
5
5
  import path from 'path'
6
6
  import yargs from 'yargs'
7
7
  import { hideBin } from 'yargs/helpers'
@@ -66,8 +66,8 @@ const typeArray = ['label', 'profile', 'permset', 'workflow']
66
66
 
67
67
  global.git = {
68
68
  enabled: false,
69
- last: undefined,
70
- latest: undefined,
69
+ lastCommit: undefined,
70
+ latestCommit: undefined,
71
71
  append: false,
72
72
  delta: false,
73
73
  }
@@ -104,20 +104,25 @@ const packageDir = getRootPath()
104
104
 
105
105
  let errorMessage = clc.red(
106
106
  'Please specify the action of ' +
107
- clc.whiteBright.bgRedBright('split') +
108
- ' or ' +
109
- clc.whiteBright.bgRedBright('combine') +
110
- '.',
107
+ clc.whiteBright.bgRedBright('split') +
108
+ ' or ' +
109
+ clc.whiteBright.bgRedBright('combine') +
110
+ '.',
111
111
  )
112
112
 
113
113
  displayHeader() // display header mast
114
114
 
115
+ let checkYargs = false
116
+
115
117
  yargs(hideBin(process.argv))
116
118
  .command({
117
119
  command: 'help',
118
120
  alias: 'h',
121
+ builder: (yargs) => {
122
+ yargs.check(yargCheck)
123
+ },
119
124
  handler: (argv) => {
120
- const data = readFileSync(
125
+ const data = fs.readFileSync(
121
126
  path.join(process.cwd(), 'README.md'),
122
127
  'utf8',
123
128
  )
@@ -126,6 +131,9 @@ yargs(hideBin(process.argv))
126
131
  })
127
132
  .command({
128
133
  command: '[test]',
134
+ builder: (yargs) => {
135
+ yargs.check(yargCheck)
136
+ },
129
137
  alias: 'test',
130
138
  handler: (argv) => {
131
139
  // THIS IS A PLACE TO TEST NEW CODE
@@ -151,13 +159,6 @@ yargs(hideBin(process.argv))
151
159
  })
152
160
  },
153
161
  })
154
- .command({
155
- command: '[version]',
156
- alias: 'version',
157
- builder: (yargs) => {
158
- yargs.check(yargCheck)
159
- },
160
- })
161
162
  .command({
162
163
  command: '[split]',
163
164
  alias: 'split',
@@ -193,12 +194,17 @@ yargs(hideBin(process.argv))
193
194
  global.git.append = argv.append || global.git.append
194
195
  global.git.delta = argv.delta || global.git.delta
195
196
  if (argv.git === '') {
196
- const commit = git.lastCommit(global.__basedir, '-1')
197
+ const commit = git.lastCommit({
198
+ dir: global.__basedir,
199
+ existsSync: fs.existsSync,
200
+ execSync,
201
+ fileUtils,
202
+ })
197
203
  commit
198
204
  .then((data, error) => {
199
- global.git.latest = data.latestCommit
200
- global.git.last = data.lastCommit
201
- if (data.last === undefined) {
205
+ global.git.latestCommit = data.latestCommit
206
+ global.git.lastCommit = data.lastCommit
207
+ if (data.lastCommit === undefined) {
202
208
  gitMode({ status: 'not active' })
203
209
  resolve(false)
204
210
  } else {
@@ -207,10 +213,12 @@ yargs(hideBin(process.argv))
207
213
  lastCommit: data.lastCommit,
208
214
  latestCommit: data.latestCommit,
209
215
  })
210
- const diff = git.diff(
211
- global.__basedir,
212
- `${data.lastCommit}..${data.latestCommit}`,
213
- )
216
+ const diff = git.diff({
217
+ dir: global.__basedir,
218
+ gitRef: `${data.lastCommit}..${data.latestCommit}`,
219
+ existsSync: fs.existsSync,
220
+ spawn,
221
+ })
214
222
  diff.then((data, error) => {
215
223
  gitFiles(data)
216
224
  resolve(true)
@@ -226,7 +234,12 @@ yargs(hideBin(process.argv))
226
234
  })
227
235
  } else {
228
236
  gitMode({ status: 'active', gitRef })
229
- const diff = git.diff(global.__basedir, gitRef)
237
+ const diff = git.diff({
238
+ dir: global.__basedir,
239
+ gitRef,
240
+ existsSync: fs.existsSync,
241
+ spawn,
242
+ })
230
243
  diff.then((data, error) => {
231
244
  gitFiles(data)
232
245
  resolve(true)
@@ -255,7 +268,16 @@ yargs(hideBin(process.argv))
255
268
  ['$0 combine --type=permset --all'],
256
269
  ['$0 combine --type=permset --name="Permission Set Name"'],
257
270
  ])
258
- .help(false).argv.parse
271
+ .help(false)
272
+ .version(false)
273
+
274
+ if (!checkYargs)
275
+ checkVersion({
276
+ axios,
277
+ spawnSync,
278
+ currentVersion: pkgObj.version,
279
+ update: false,
280
+ })
259
281
 
260
282
  function gitMode({ status, gitRef, lastCommit, latestCommit }) {
261
283
  let statusMessage
@@ -266,10 +288,11 @@ function gitMode({ status, gitRef, lastCommit, latestCommit }) {
266
288
  } else {
267
289
  statusMessage = clc.magentaBright('active:')
268
290
  if (gitRef === undefined) {
269
- displayMessage = `${clc.bgBlackBright(lastCommit) +
291
+ displayMessage = `${
292
+ clc.bgBlackBright(lastCommit) +
270
293
  '..' +
271
294
  clc.bgBlackBright(latestCommit)
272
- }`
295
+ }`
273
296
  } else {
274
297
  let delimiter = '..'
275
298
 
@@ -289,6 +312,7 @@ function gitMode({ status, gitRef, lastCommit, latestCommit }) {
289
312
  }
290
313
 
291
314
  function yargCheck(argv, options) {
315
+ checkYargs = true
292
316
  const argvKeys = Object.keys(argv)
293
317
  const invalidKeys = argvKeys.filter(
294
318
  (key) =>
@@ -331,8 +355,8 @@ function yargCheck(argv, options) {
331
355
  throw new Error(
332
356
  clc.redBright(
333
357
  'You cannot specify ' +
334
- clc.whiteBright.bgRedBright('--name') +
335
- ' when using multiple types.',
358
+ clc.whiteBright.bgRedBright('--name') +
359
+ ' when using multiple types.',
336
360
  ),
337
361
  )
338
362
  }
@@ -343,8 +367,8 @@ function yargCheck(argv, options) {
343
367
  throw new Error(
344
368
  clc.redBright(
345
369
  'You cannot specify ' +
346
- clc.whiteBright.bgRedBright('--name') +
347
- ' when using label.',
370
+ clc.whiteBright.bgRedBright('--name') +
371
+ ' when using label.',
348
372
  ),
349
373
  )
350
374
  }
@@ -361,12 +385,12 @@ function displayMessageAndDuration(startTime, message) {
361
385
  let minutes = Math.floor(
362
386
  (executionTime.seconds +
363
387
  Math.round(executionTime.milliseconds / 100000)) /
364
- 60,
388
+ 60,
365
389
  )
366
390
  let seconds = Math.round(
367
391
  (executionTime.seconds +
368
392
  Math.round(executionTime.milliseconds / 100000)) %
369
- 60,
393
+ 60,
370
394
  )
371
395
  if (minutes == 0 && seconds == 0) {
372
396
  durationMessage = message + clc.magentaBright(`<1s`)
@@ -459,17 +483,17 @@ function processSplit(typeItem, argv) {
459
483
 
460
484
  if (!all) {
461
485
  let metaFilePath = path.join(metaDirPath, name)
462
- if (!fileUtils.fileExists(metaFilePath)) {
486
+ if (!fileUtils.fileExists({ filePath: metaFilePath, fs })) {
463
487
  name += metaExtension
464
488
  metaFilePath = path.join(metaDirPath, name)
465
- if (!fileUtils.fileExists(metaFilePath)) {
489
+ if (!fileUtils.fileExists({ filePath: metaFilePath, fs })) {
466
490
  global.logger.error('File not found: ' + metaFilePath)
467
491
  process.exit(1)
468
492
  }
469
493
  }
470
494
  fileList.push(name)
471
495
  } else {
472
- if (fileUtils.directoryExists(sourceDir)) {
496
+ if (fileUtils.directoryExists({ dirPath: sourceDir, fs })) {
473
497
  fileUtils.getFiles(sourceDir, metaExtension).forEach((file) => {
474
498
  fileList.push(file)
475
499
  })
@@ -512,12 +536,13 @@ function processSplit(typeItem, argv) {
512
536
  processed.current > promList.length
513
537
  ? promList.length
514
538
  : processed.current,
515
- )} file(s) ${processed.errors > 0
539
+ )} file(s) ${
540
+ processed.errors > 0
516
541
  ? 'with ' +
517
- clc.bgBlackBright.red(processed.errors) +
518
- ' error(s) '
542
+ clc.bgBlackBright.red(processed.errors) +
543
+ ' error(s) '
519
544
  : ''
520
- }in `
545
+ }in `
521
546
  displayMessageAndDuration(startTime, message)
522
547
  resolve(true)
523
548
  })
@@ -532,8 +557,13 @@ function combineHandler(argv, startTime) {
532
557
  console.log()
533
558
  combineHandler(argv, startTime)
534
559
  } else {
535
- if (global.git.latest !== undefined) {
536
- git.updateLastCommit(global.__basedir, global.git.latest)
560
+ if (global.git.latestCommit !== undefined) {
561
+ git.updateLastCommit({
562
+ dir: global.__basedir,
563
+ latest: global.git.latestCommit,
564
+ fileUtils,
565
+ fs,
566
+ })
537
567
  }
538
568
  if (argv.type === undefined || argv.type.split(',').length > 1) {
539
569
  let message = `Split completed in `
@@ -610,7 +640,7 @@ function processCombine(typeItem, argv) {
610
640
  }
611
641
  } else if (!all) {
612
642
  let metaDirPath = path.join(sourceDir, name)
613
- if (!fileUtils.directoryExists(metaDirPath)) {
643
+ if (!fileUtils.directoryExists({ dirPath: metaDirPath, fs })) {
614
644
  global.logger.error('Directory not found: ' + metaDirPath)
615
645
  process.exit(1)
616
646
  }
@@ -675,10 +705,11 @@ function processCombine(typeItem, argv) {
675
705
  errors++
676
706
  }
677
707
  })
678
- let message = `Combined ${clc.bgBlackBright(successes)} file(s) ${errors > 0
708
+ let message = `Combined ${clc.bgBlackBright(successes)} file(s) ${
709
+ errors > 0
679
710
  ? 'with ' + clc.bgBlackBright(errors) + 'error(s) '
680
711
  : ''
681
- }in `
712
+ }in `
682
713
  displayMessageAndDuration(startTime, message)
683
714
  resolve(true)
684
715
  })
@@ -762,10 +793,11 @@ function displayHeader() {
762
793
  horizontal: '─',
763
794
  vertical: '│',
764
795
  }
765
- let versionString = `sfparty v${pkgObj.version}${process.stdout.columns > pkgObj.description.length + 15
796
+ let versionString = `sfparty v${pkgObj.version}${
797
+ process.stdout.columns > pkgObj.description.length + 15
766
798
  ? ' - ' + pkgObj.description
767
799
  : ''
768
- }`
800
+ }`
769
801
  let titleMessage = `${global.icons.party} ${clc.yellowBright(
770
802
  versionString,
771
803
  )} ${global.icons.party}`
@@ -782,16 +814,16 @@ function displayHeader() {
782
814
  console.log(
783
815
  `${clc.blackBright(
784
816
  box.topLeft +
785
- box.horizontal.repeat(process.stdout.columns - 2) +
786
- box.topRight,
817
+ box.horizontal.repeat(process.stdout.columns - 2) +
818
+ box.topRight,
787
819
  )}`,
788
820
  )
789
821
  console.log(titleMessage)
790
822
  console.log(
791
823
  `${clc.blackBright(
792
824
  box.bottomLeft +
793
- box.horizontal.repeat(process.stdout.columns - 2) +
794
- box.bottomRight,
825
+ box.horizontal.repeat(process.stdout.columns - 2) +
826
+ box.bottomRight,
795
827
  )}`,
796
828
  )
797
829
  console.log()
@@ -802,9 +834,9 @@ function getRootPath(packageDir) {
802
834
  let defaultDir
803
835
  if (rootPath) {
804
836
  global.__basedir = fileUtils.fileInfo(rootPath).dirname
805
- let packageJSON
837
+ let projectJSON
806
838
  try {
807
- packageJSON = JSON.parse(readFileSync(rootPath))
839
+ projectJSON = JSON.parse(fs.readFileSync(rootPath))
808
840
  } catch (error) {
809
841
  if (error.message.indexOf('JSON at position') > 0) {
810
842
  global.displayError('sfdx-project.json has invalid JSON', true)
@@ -812,11 +844,11 @@ function getRootPath(packageDir) {
812
844
  global.displayError(error, true)
813
845
  }
814
846
  }
815
- if (Array.isArray(packageJSON.packageDirectories)) {
816
- packageJSON.packageDirectories.every((directory) => {
847
+ if (Array.isArray(projectJSON.packageDirectories)) {
848
+ projectJSON.packageDirectories.every((directory) => {
817
849
  if (
818
850
  directory.default ||
819
- packageJSON.packageDirectories.length == 1
851
+ projectJSON.packageDirectories.length == 1
820
852
  )
821
853
  defaultDir = directory.path
822
854
  if (directory == packageDir) {
@@ -39,7 +39,7 @@ export async function checkVersion({
39
39
  )
40
40
  const latestVersion = data['dist-tags'].latest
41
41
  if (semver.gt(latestVersion, currentVersion)) {
42
- const version = clc.bgCyanBright(data['dist-tags'].latest)
42
+ const version = clc.bgMagenta(data['dist-tags'].latest)
43
43
  const icon = update ? global.icons.working : global.icons.fail
44
44
  console.log()
45
45
  console.log(`${icon} A newer version ${version} is available.`)
@@ -4,12 +4,12 @@ import * as path from 'path'
4
4
  import * as yaml from 'js-yaml'
5
5
  import { Parser } from 'xml2js'
6
6
 
7
- export function directoryExists(dirPath, fsTmp = fs) {
8
- return fsTmp.existsSync(dirPath) && fsTmp.statSync(dirPath).isDirectory()
7
+ export function directoryExists({ dirPath, fs }) {
8
+ return fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()
9
9
  }
10
10
 
11
- export function fileExists(filePath, fsTmp = fs) {
12
- return fsTmp.existsSync(filePath) && fsTmp.statSync(filePath).isFile()
11
+ export function fileExists({ filePath, fs }) {
12
+ return fs.existsSync(filePath) && fs.statSync(filePath).isFile()
13
13
  }
14
14
 
15
15
  export function createDirectory(dirPath, fsTmp = fs) {
@@ -19,7 +19,7 @@ export function createDirectory(dirPath, fsTmp = fs) {
19
19
  }
20
20
 
21
21
  export function deleteDirectory(dirPath, recursive = false, fsTmp = fs) {
22
- if (!directoryExists(dirPath, fsTmp)) {
22
+ if (!directoryExists({ dirPath, fs: fsTmp })) {
23
23
  return false
24
24
  } else {
25
25
  if (fsTmp.existsSync(dirPath)) {
@@ -40,7 +40,7 @@ export function deleteDirectory(dirPath, recursive = false, fsTmp = fs) {
40
40
 
41
41
  export function getFiles(dirPath, filter = undefined, fsTmp = fs) {
42
42
  const filesList = []
43
- if (directoryExists(dirPath, fsTmp)) {
43
+ if (directoryExists({ dirPath, fs: fsTmp })) {
44
44
  fsTmp.readdirSync(dirPath).forEach((file) => {
45
45
  if (!filter) {
46
46
  filesList.push(file)
@@ -62,7 +62,7 @@ export function getFiles(dirPath, filter = undefined, fsTmp = fs) {
62
62
  }
63
63
 
64
64
  export function getDirectories(dirPath, fsTmp = fs) {
65
- if (directoryExists(dirPath, fsTmp)) {
65
+ if (directoryExists({ dirPath, fs: fsTmp })) {
66
66
  return fsTmp
67
67
  .readdirSync(dirPath, { withFileTypes: true })
68
68
  .filter((dirent) => dirent.isDirectory())
@@ -73,7 +73,7 @@ export function getDirectories(dirPath, fsTmp = fs) {
73
73
  }
74
74
 
75
75
  export function deleteFile(filePath, fsTmp = fs) {
76
- if (!fileExists(filePath, fsTmp)) {
76
+ if (!fileExists({ filePath, fs: fsTmp })) {
77
77
  return false
78
78
  } else {
79
79
  return fsTmp.unlinkSync(filePath, { recursive: false, force: true })
@@ -117,19 +117,19 @@ export function saveFile(
117
117
  }
118
118
  }
119
119
 
120
- export function readFile(fileName, convert = true, fsTmp = fs) {
120
+ export function readFile(filePath, convert = true, fsTmp = fs) {
121
121
  try {
122
122
  let result = undefined
123
- if (fileExists(fileName, fsTmp)) {
124
- const data = fsTmp.readFileSync(fileName, {
123
+ if (fileExists({ filePath, fs: fsTmp })) {
124
+ const data = fsTmp.readFileSync(filePath, {
125
125
  encoding: 'utf8',
126
126
  flag: 'r',
127
127
  })
128
- if (convert && fileName.indexOf('.yaml') != -1) {
128
+ if (convert && filePath.indexOf('.yaml') != -1) {
129
129
  result = yaml.load(data)
130
- } else if (convert && fileName.indexOf('.json') != -1) {
130
+ } else if (convert && filePath.indexOf('.json') != -1) {
131
131
  result = JSON.parse(data)
132
- } else if (convert && fileName.indexOf('.xml') != -1) {
132
+ } else if (convert && filePath.indexOf('.xml') != -1) {
133
133
  // returns a promise
134
134
  result = convertXML(data)
135
135
  } else {
@@ -1,13 +1,9 @@
1
1
  import path from 'path'
2
- import { execSync } from 'node:child_process'
3
2
  import * as os from 'node:os'
4
- import { existsSync } from 'fs'
5
- import * as fileUtils from './fileUtils.js'
6
3
 
7
4
  const defaultDefinition = {
8
5
  git: {
9
6
  lastCommit: undefined,
10
- latestCommit: undefined,
11
7
  },
12
8
  local: {
13
9
  lastDate: undefined,
@@ -49,48 +45,90 @@ const status = {
49
45
  },
50
46
  }
51
47
 
52
- export function diff(
53
- dir,
54
- gitRef = 'HEAD',
55
- existsSyncStub = existsSync,
56
- execSyncStub = execSync,
57
- ) {
48
+ export function diff({ dir, gitRef = 'HEAD', existsSync, spawn }) {
58
49
  return new Promise((resolve, reject) => {
59
- if (!existsSyncStub(dir) || !existsSyncStub(path.join(dir, '.git'))) {
60
- reject(new Error(`The directory "${dir}" is not a git repository`))
61
- }
62
-
63
- let data = ''
64
50
  try {
65
- data = execSyncStub(
66
- `git diff --name-status --oneline --relative ${gitRef} -- *-party/*`,
67
- { cwd: dir, maxBuffer: 1024 * 1024 * 10 },
68
- ).toString()
51
+ if (!existsSync(dir)) {
52
+ throw new Error(`The directory "${dir}" does not exist`)
53
+ }
54
+ if (!existsSync(path.join(dir, '.git'))) {
55
+ throw new Error(
56
+ `The directory "${dir}" is not a git repository`,
57
+ )
58
+ }
59
+
60
+ const git = spawn('git', ['--version'])
61
+ git.on('error', (err) => {
62
+ throw new Error('Git is not installed on this machine')
63
+ })
64
+ git.on('close', (code) => {
65
+ if (code !== 0) {
66
+ reject(
67
+ new Error(
68
+ `git --version command failed with code ${code}`,
69
+ ),
70
+ )
71
+ }
72
+
73
+ const gitDiff = spawn(
74
+ 'git',
75
+ [
76
+ 'diff',
77
+ '--name-status',
78
+ '--oneline',
79
+ '--no-renames',
80
+ '--relative',
81
+ gitRef,
82
+ '--',
83
+ '*-party/*',
84
+ ],
85
+ { cwd: dir },
86
+ )
87
+ let data = ''
88
+ gitDiff.stdout.setEncoding('utf8')
89
+ gitDiff.stderr.on('data', (data) => {
90
+ if (data !== '')
91
+ reject(
92
+ new Error(
93
+ `git diff command failed with error: ${data}`,
94
+ ),
95
+ )
96
+ })
97
+ gitDiff.stdout.on('data', (chunk) => {
98
+ data += chunk
99
+ })
100
+ gitDiff.stdout.on('close', (code) => {
101
+ if (code !== 0 && code !== false) {
102
+ reject(
103
+ new Error(
104
+ `git diff command failed with code ${code}`,
105
+ ),
106
+ )
107
+ }
108
+ const gitData = data.toString().split(os.EOL)
109
+ const files = gitData.reduce((acc, gitRow) => {
110
+ if (gitRow.lastIndexOf('\t') > 0) {
111
+ const file = gitRow.split('\t')
112
+ if (file.slice(-1)[0] !== '') {
113
+ const statusType = status[file[0]]
114
+ acc.push({
115
+ type:
116
+ statusType !== undefined
117
+ ? statusType.type
118
+ : 'A',
119
+ path: file.slice(-1)[0],
120
+ action: statusType.action,
121
+ })
122
+ }
123
+ }
124
+ return acc
125
+ }, [])
126
+ resolve(files)
127
+ })
128
+ })
69
129
  } catch (error) {
70
130
  reject(error)
71
131
  }
72
-
73
- const gitData = data.toString().split(os.EOL)
74
- const files = gitData.reduce((acc, gitRow) => {
75
- if (gitRow.indexOf('\t') > 0) {
76
- const file = gitRow.split('\t')
77
- if (file.slice(-1) !== '') {
78
- const statusType =
79
- status[
80
- file[0] === file.slice(-1)
81
- ? 'A'
82
- : Array.from(file[0])[0]
83
- ]
84
- acc.push({
85
- type: statusType.type,
86
- path: file.slice(-1)[0],
87
- action: statusType.action,
88
- })
89
- }
90
- }
91
- return acc
92
- }, [])
93
- resolve(files)
94
132
  })
95
133
  }
96
134
 
@@ -110,39 +148,41 @@ export function log(dir, gitRef, execSyncStub = execSync) {
110
148
  }
111
149
  }
112
150
 
113
- export function lastCommit(
151
+ export function lastCommit({
114
152
  dir,
115
153
  fileName = 'index.yaml',
116
- existsSyncStub = existsSync,
117
- execSyncStub = execSync,
118
- fileUtilsStub = fileUtils,
119
- ) {
120
- try {
121
- const folder = path.resolve(dir, '.sfdx', 'sfparty')
122
- const filePath = path.resolve(folder, fileName)
123
- let lastCommit = undefined
154
+ existsSync,
155
+ execSync,
156
+ fileUtils,
157
+ }) {
158
+ return new Promise((resolve, reject) => {
159
+ try {
160
+ const folder = path.resolve(dir, '.sfdx', 'sfparty')
161
+ const filePath = path.resolve(folder, fileName)
162
+ let lastCommit = undefined
124
163
 
125
- fileUtilsStub.createDirectory(folder)
126
- if (existsSyncStub(filePath)) {
127
- const data = fileUtilsStub.readFile(filePath)
128
- if (data.git.lastCommit !== undefined) {
129
- lastCommit = data.git.lastCommit
164
+ fileUtils.createDirectory(folder)
165
+ if (existsSync(filePath)) {
166
+ const data = fileUtils.readFile(filePath)
167
+ if (data.git.lastCommit !== undefined) {
168
+ lastCommit = data.git.lastCommit
169
+ }
130
170
  }
171
+ const latestCommit = execSync(`git log --format=format:%H -1`, {
172
+ cwd: dir,
173
+ encoding: 'utf-8',
174
+ })
175
+ resolve({
176
+ lastCommit: lastCommit,
177
+ latestCommit: latestCommit,
178
+ })
179
+ } catch (error) {
180
+ reject(error)
131
181
  }
132
- const latestCommit = execSyncStub(`git log --format=format:%H -1`, {
133
- cwd: dir,
134
- encoding: 'utf-8',
135
- })
136
- return {
137
- lastCommit: lastCommit,
138
- latestCommit: latestCommit,
139
- }
140
- } catch (error) {
141
- throw new Error(error)
142
- }
182
+ })
143
183
  }
144
184
 
145
- export function updateLastCommit(dir, latest, fileUtilsStub = fileUtils) {
185
+ export function updateLastCommit({ dir, latest, fileUtils, fs }) {
146
186
  if (typeof latest !== 'string' && typeof latest !== 'undefined')
147
187
  throw new Error(
148
188
  `updateLastCommit received a ${typeof latest} instead of string`,
@@ -151,8 +191,8 @@ export function updateLastCommit(dir, latest, fileUtilsStub = fileUtils) {
151
191
  const folder = path.join(dir, '.sfdx', 'sfparty')
152
192
  const fileName = path.join(folder, 'index.yaml')
153
193
  let data = undefined
154
- if (fileUtilsStub.fileExists(fileName)) {
155
- data = fileUtilsStub.readFile(fileName)
194
+ if (fileUtils.fileExists({ filePath: fileName, fs })) {
195
+ data = fileUtils.readFile(fileName)
156
196
  }
157
197
 
158
198
  if (data === undefined) {
@@ -160,6 +200,6 @@ export function updateLastCommit(dir, latest, fileUtilsStub = fileUtils) {
160
200
  }
161
201
 
162
202
  data.git.lastCommit = latest
163
- fileUtilsStub.saveFile(data, fileName)
203
+ fileUtils.saveFile(data, fileName)
164
204
  }
165
205
  }