Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sfdx-git-delta

Package Overview
Dependencies
Maintainers
1
Versions
360
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sfdx-git-delta - npm Package Compare versions

Comparing version 3.1.1 to 3.1.2

.vscode/launch.json

9

__mocks__/fs-extra.js

@@ -5,9 +5,14 @@ 'use strict'

fse.errorMode = false
fse.outputFileSyncError = false
fse.copySync = () => {}
fse.pathExistsSync = () => true
fse.outputFileSync = () => {
fse.copySync = () => {
if (fse.errorMode) throw new Error()
}
fse.outputFileSync = () => {
if (fse.outputFileSyncError) throw new Error()
}
module.exports = fse

@@ -9,2 +9,5 @@ 'use strict'

const fsMocked = require('fs')
const fseMocked = require('fs-extra')
const lines = [

@@ -42,4 +45,21 @@ 'D force-app/main/default/objects/Account/fields/deleted.field-meta.xml',

})
).toBeUndefined()
).toHaveProperty('warnings', [])
})
test('catch internal warnings', () => {
fsMocked.errorMode = true
fseMocked.errorMode = true
child_process.spawnSync.mockImplementation(() => ({
stdout: lines.join(os.EOL),
}))
expect(
app({
output: 'output',
repo: '',
to: 'test',
apiVersion: '46',
generateDelta: true,
}).warnings
).not.toHaveLength(0)
})
})

@@ -16,2 +16,3 @@ 'use strict'

fseMocked.errorMode = false
fseMocked.outputFileSyncError = false
fsMocked.__setMockFiles({

@@ -25,3 +26,3 @@ output: '',

app({ output: 'output', repo: '', to: 'test', apiVersion: '46' })
).toBeUndefined()
).toHaveProperty('warnings', [])
})

@@ -32,3 +33,3 @@

app({ output: 'output', repo: '', to: 'test', apiVersion: '46' })
).toBeUndefined()
).toHaveProperty('warnings', [])
})

@@ -39,3 +40,3 @@

app({ output: 'output', repo: '', to: 'test', apiVersion: '46' })
).toBeUndefined()
).toHaveProperty('warnings', [])
})

@@ -46,3 +47,3 @@

app({ output: 'output', repo: '', to: 'test', apiVersion: '46' })
).toBeUndefined()
).toHaveProperty('warnings', [])
})

@@ -53,2 +54,3 @@

fseMocked.errorMode = true
fseMocked.outputFileSyncError = true
expect(() => {

@@ -59,8 +61,2 @@ app({ output: 'output', repo: '', to: 'test', apiVersion: '46' })

test('catch internal qwaks', () => {
expect(() => {
app({ output: 'output', repo: '', to: 'test', apiVersion: '46' })
}).toThrow()
})
test('throw errors when to parameter is not filled', () => {

@@ -67,0 +63,0 @@ expect(() => {

@@ -55,2 +55,3 @@ 'use strict'

treatPackages(work.diffs, config)
return work
}

@@ -62,2 +63,3 @@

diffs: { package: {}, destructiveChanges: {} },
warnings: [],
}

@@ -64,0 +66,0 @@

'use strict'
const StandardHandler = require('./standardHandler')
const SubCustomObjectHandler = require('./subCustomObjectHandler')
const gc = require('../utils/gitConstants')
const mc = require('../utils/metadataConstants')
const path = require('path')
const fse = require('fs-extra')
const fs = require('fs')

@@ -15,3 +14,3 @@

path.parse(this.line).dir,
CustomObjectHandler.FIELD_DIRECTORY_NAME
mc.FIELD_DIRECTORY_NAME
)

@@ -27,6 +26,6 @@ fs.readdirSync(path.resolve(this.config.repo, fieldsFolder))

)
.includes(SubCustomObjectHandler.MASTER_DETAIL_TAG)
.includes(mc.MASTER_DETAIL_TAG)
)
.forEach(field =>
fse.copySync(
this._copyFiles(
path.resolve(this.config.repo, fieldsFolder, field),

@@ -39,4 +38,2 @@ path.resolve(this.config.output, fieldsFolder, field)

CustomObjectHandler.OBJECT_META_XML_SUFFIX = `object${StandardHandler.METAFILE_SUFFIX}`
CustomObjectHandler.FIELD_DIRECTORY_NAME = 'fields'
module.exports = CustomObjectHandler
'use strict'
const StandardHandler = require('./standardHandler')
const mc = require('../utils/metadataConstants')
const path = require('path')
const fse = require('fs-extra')
class InFolderHandler extends StandardHandler {

@@ -28,5 +28,5 @@ handleDeletion() {

this.type
].xmlName.toLowerCase() + InFolderHandler.INFOLDER_METAFILE_SUFFIX}`
].xmlName.toLowerCase() + mc.INFOLDER_METAFILE_SUFFIX}`
fse.copySync(
this._copyFiles(
path.normalize(path.join(this.config.repo, folderPath, folderName)),

@@ -44,3 +44,3 @@ path.normalize(path.join(this.config.output, folderPath, folderName))

.join(path.sep)
.replace(StandardHandler.METAFILE_SUFFIX, '')
.replace(mc.METAFILE_SUFFIX, '')
.replace(`.${this.metadata[this.type].suffix}`, '')

@@ -51,5 +51,4 @@ )

InFolderHandler.INFOLDER_METAFILE_SUFFIX = `Folder${StandardHandler.METAFILE_SUFFIX}`
module.exports = InFolderHandler
RegExp.escape = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

@@ -5,3 +5,2 @@ 'use strict'

const fs = require('fs')
const fse = require('fs-extra')

@@ -38,3 +37,3 @@ const elementSrc = {}

.forEach(src =>
fse.copySync(
this._copyFiles(
path.normalize(path.join(srcPath, src)),

@@ -41,0 +40,0 @@ path.normalize(path.join(targetPath, src))

'use strict'
const StandardHandler = require('./standardHandler')
const path = require('path')
const fse = require('fs-extra')

@@ -13,3 +12,3 @@ class LightningHandler extends StandardHandler {

fse.copySync(
this._copyFiles(
path.join(this.config.repo, fileName),

@@ -16,0 +15,0 @@ path.join(this.config.output, fileName)

'use strict'
const path = require('path')
const fse = require('fs-extra')
const mc = require('../utils/metadataConstants')
const FSE_COPYSYNC_OPTION = {
overwrite: true,
errorOnExist: false,
dereference: true,
preserveTimestamps: false,
}
class StandardHandler {

@@ -14,5 +22,6 @@ constructor(line, type, work, metadata) {

this.metadata = metadata
this.warnings = work.warnings
if (this.metadata[this.type].metaFile === true) {
this.line = this.line.replace(StandardHandler.METAFILE_SUFFIX, '')
this.line = this.line.replace(mc.METAFILE_SUFFIX, '')
}

@@ -29,3 +38,7 @@

if (this.handlerMap[this.changeType]) {
this.handlerMap[this.changeType].apply(this)
try {
this.handlerMap[this.changeType].apply(this)
} catch (error) {
this.warnings.push(error)
}
}

@@ -41,8 +54,5 @@ }

fse.copySync(source, target)
this._copyFiles(source, target)
if (this.metadata[this.type].metaFile === true) {
fse.copySync(
source + StandardHandler.METAFILE_SUFFIX,
target + StandardHandler.METAFILE_SUFFIX
)
this._copyFiles(source + mc.METAFILE_SUFFIX, target + mc.METAFILE_SUFFIX)
}

@@ -62,3 +72,3 @@ }

this.splittedLine[this.splittedLine.indexOf(this.type) + 1]
.replace(StandardHandler.METAFILE_SUFFIX, '')
.replace(mc.METAFILE_SUFFIX, '')
.replace(`.${this.metadata[this.type].suffix}`, '')

@@ -78,5 +88,10 @@ )

}
_copyFiles(src, dst) {
if (fse.pathExistsSync(src)) {
fse.copySync(src, dst, FSE_COPYSYNC_OPTION)
}
}
}
StandardHandler.METAFILE_SUFFIX = '-meta.xml'
module.exports = StandardHandler
'use strict'
const StandardHandler = require('./standardHandler')
const CustomObjectHandler = require('./customObjectHandler')
const gc = require('../utils/gitConstants')
const mc = require('../utils/metadataConstants')
const path = require('path')
const fse = require('fs-extra')
const fs = require('fs')

@@ -21,3 +20,3 @@

})
if (!!data && data.includes(SubCustomObjectHandler.MASTER_DETAIL_TAG)) {
if (!!data && data.includes(mc.MASTER_DETAIL_TAG)) {
const customObjectDirPath = this.splittedLine

@@ -32,6 +31,6 @@ .slice(0, [this.splittedLine.indexOf(this.type)])

customObjectDirPath,
`${customObjectName}.${CustomObjectHandler.OBJECT_META_XML_SUFFIX}`
`${customObjectName}.${mc.OBJECT_META_XML_SUFFIX}`
)
fse.copySync(
this._copyFiles(
path.join(this.config.repo, customObjectPath),

@@ -53,3 +52,2 @@ path.join(this.config.output, customObjectPath)

SubCustomObjectHandler.MASTER_DETAIL_TAG = '<type>MasterDetail</type>'
module.exports = SubCustomObjectHandler

@@ -18,2 +18,3 @@ 'use strict'

documents: InFolder,
email: InFolder,
experiences: InResource,

@@ -20,0 +21,0 @@ fieldSets: SubCustomObject,

{
"name": "sfdx-git-delta",
"version": "3.1.1",
"version": "3.1.2",
"description": "Generate the sfdx content in source format and destructive change from two git commits",

@@ -53,2 +53,3 @@ "keyword": [

"test": "jest --runInBand",
"test:debug": "node --inspect node_modules/.bin/jest --runInBand",
"test:coverage": "jest --coverage --runInBand",

@@ -55,0 +56,0 @@ "lint:fix": "eslint --fix .",

@@ -9,3 +9,3 @@ [![NPM](https://nodei.co/npm/sfdx-git-delta.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/sfdx-git-delta/) [![NPM](https://nodei.co/npm-dl/sfdx-git-delta.png)](https://nodei.co/npm/sfdx-git-delta/) [![HitCount](http://hits.dwyl.com/scolladon/sfdx-git-delta.svg)](http://hits.dwyl.com/scolladon/sfdx-git-delta)

**SFDX-Git-Delta** (*a.k.a. **sgd***) helps Technical Architects accomplish 2 things with their CI deployments:
**SFDX-Git-Delta** (\*a.k.a. **sgd\***) helps Technical Architects accomplish 2 things with their CI deployments:

@@ -15,13 +15,13 @@ 1. **Make deployments faster,** by identifying the metadata that has been changed since a reference commit.

## Is it for me?
## Is it for you?
If you are not a Salesforce Architect, probably not, _sorry_.
If you are not a Salesforce Architect or Developer, probably not, _sorry_.
If you are a Technical Architect, then it’s a very useful tool for you, _when the 3 conditions below are met:_
If you are a Technical Architect or Developer, then it’s a very useful tool for you, when the 3 conditions below are met:
Your Salesforce project uses a git repo as the source of truth.
You use the new Source (DX) format in the repo.
You use the Source (DX) format in the repo.
You have a CI/CD pipeline (Jenkins, Bitbucket Pipelines, GitLab CI...) that handles the deployment of the sources to the salesforce org(s).
You have a CI/CD pipeline (Jenkins, Bitbucket Pipelines, GitLab CI, GitHub Actions, Azure DevOps...) that handles the deployment of the sources to the Salesforce org(s).

@@ -32,3 +32,3 @@ **DISCLAIMER:**

👷 Use it at your own risk, wear a helmet, and do not let non-technical people play with it 🔥
👷 Use it at your own risk, wear a helmet, and test it first before adding it to your pipeline 🔥

@@ -91,11 +91,11 @@ ## How to install it?

> ***The CI pipelines deploys the sources to Production anytime there is a new commit in the master branch.***
> **_The CI pipelines deploys the sources to Production anytime there is a new commit in the master branch._**
In our example, the latest commit to master is composed of:
+ _Apex Class added:_ TriggerHandler
+ _Apex Class added:_ TriggerHandler_Test
+ _Apex Class modified:_ TestDataFactory
+ _Apex Class deleted:_ AnotherTriggerFramework
- _Apex Class added:_ TriggerHandler
- _Apex Class added:_ TriggerHandler_Test
- _Apex Class modified:_ TestDataFactory
- _Apex Class deleted:_ AnotherTriggerFramework
![commit](/img/example_commit.png)

@@ -122,3 +122,3 @@

The `sgd` command will produces 2 usefull artefacts:
The `sgd` command produces 2 usefull artefacts:

@@ -130,3 +130,3 @@ **1) A `package.xml` file, inside a `package` folder.** This package.xml file contains only the metadata that has been added and changed, and that needs to be deployed in the target org.

**2) A `destructivePackage.xml` file, inside a `destructivePackage` folder.** This destructivePackage.xml file contains only the metadata that has been removed or renamed, and that needs to be deleted from the target org.
**2) A `destructivePackage.xml` file, inside a `destructivePackage` folder.** This destructivePackage.xml file contains only the metadata that has been removed or renamed, and that needs to be deleted from the target org. Note: the `destructivePackage` folder also contains a minimal package.xml file because deploying destructive changes requires a package.xml (even an empty one) in the payload.

@@ -136,4 +136,5 @@ _Content of the `destructivePackage.xml` file in our scenario:_

In addition, we could also have generated a copy of the **force-app** folder with only the added and changed metadata, by using the `--generate-delta` option.
In addition, we could also have generated a copy of the **force-app** folder with only the added and changed metadata, by using the `--generate-delta (-d)` option (more on that later).
### Deploy only the added/modified metadata:

@@ -165,2 +166,24 @@

### Advanced use-case: Generating a folder containing only the added/modified sources
Using a package.xml file to deploy a subset of the metadata is propably the simpliest approach to delta deployments. But there are some situations where you may want to have the actual source files related to all the components that have been changed recently.
One example is to speed up object deployments: the package.xml approach will result on the entire sub-folder for a given object to be deployed. On the opposite, having a copy of the actual sources added/modified allows you to chirchugically deploy only the modified components.
This is where the `--generate-delta (-d)` option comes handy!
Let's use this option with our previous example:
```
mkdir changed-sources
sgd --to HEAD --from HEAD^ --repo . --output changed-sources/ --generate-delta
```
In addition to the `package` and `destructiveChanges` folders, the `sgd` command will also produce a copy of the added/changed files in the ouput folder.
_Content of the output folder when using the --generate-delta option, with the same scenario as above:_
![delta-source](/img/example_generateDelta.png)
## Javascript Module

@@ -171,3 +194,3 @@

sgd({
const work = sgd({
'to':'', // commit sha to where the diff is done. Default : HEAD

@@ -178,3 +201,11 @@ 'from':'', // commit sha from where the diff is done. Default : git rev-list --max-parents=0 HEAD

'repo':'' // git repository location. Default : ./repo
}, console.log);
});
console.log(JSON.stringify(work));
/* {
* config: config,
* diffs: { package: {...}, destructiveChanges: {...} },
* warnings: []
* }
*/
```

@@ -181,0 +212,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc