Skip to content

Commit

Permalink
fix: issue with path separator conversion in xml file and path portab…
Browse files Browse the repository at this point in the history
…ility (#153)

Co-authored-by: Mehdi Cherfaoui <>
  • Loading branch information
scolladon authored Jun 24, 2021
1 parent be1470b commit 549addf
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 8 deletions.
10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,12 @@ The repo contains a script to increment the Salesforce API version supported by
To upgrade the API version, run the following command:
```
yarn && yarn increment:apiversion
```
```
## Testing the plugin from a pull request

To test SGD as a Salesforce CLI plugin from a pending pull request:
1. uninstall the previous version you may have `sfdx plugins:uninstall sfdx-git-delta`
2. clone the repository
3. checkout the branch to test
3. run `sfdx plugins:link` from that local repository
4. test the plugin!
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ OPTIONS
this command invocation
```

_See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-git-delta/blob/v4.5.0/src/commands/sgd/source/delta.ts)_
_See code: [src/commands/sgd/source/delta.ts](https://github.com/scolladon/sfdx-git-delta/blob/v4.6.0/src/commands/sgd/source/delta.ts)_
<!-- commandsstop -->

### Important note for Windows users:
Expand Down
39 changes: 39 additions & 0 deletions __tests__/integration/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,45 @@ describe(`test if the appli`, () => {
).toHaveProperty('warnings', [])
})

test('can execute with posix path', () => {
expect(
app({ output: './output', repo: '', to: 'test', apiVersion: '46' })
).toHaveProperty('warnings', [])
})

test('can execute with posix relative path', () => {
expect(
app({
output: './output/../output',
repo: '',
to: 'test',
apiVersion: '46',
})
).toHaveProperty('warnings', [])
})

test('can execute with windows path', () => {
expect(
app({
output: '.\\output',
repo: '',
to: 'test',
apiVersion: '46',
})
).toHaveProperty('warnings', [])
})

test('can execute with windows relative path', () => {
expect(
app({
output: '.\\output\\..\\output',
repo: '',
to: 'test',
apiVersion: '46',
})
).toHaveProperty('warnings', [])
})

test('catch and reject big issues', () => {
fsMocked.errorMode = true
fseMocked.errorMode = true
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"postrelease": "npm run release:tags && npm run release:github",
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
"prepare": "husky install",
"release": "standard-version --no-verify",
"release": "standard-version --no-verify --commit-all",
"release:github": "conventional-github-releaser -p angular",
"release:tags": "git push --follow-tags origin master -f --no-verify",
"increment:apiversion": "jq '.sfdc.latestApiVersion = (.sfdc.latestApiVersion|tonumber + 1 |tostring)' package.json | sponge package.json && filename=`ls src/metadata/v*.json | tail -1` && version=${filename//[!0-9]/} && ((version++)) && targetname=\"src/metadata/v${version}.json\" && \\cp $filename $targetname && yarn pack"
Expand Down Expand Up @@ -106,6 +106,11 @@
"publishConfig": {
"access": "public"
},
"standard-version": {
"scripts": {
"postbump": "yarn pack && git add README.md"
}
},
"sfdc": {
"latestApiVersion": "52"
}
Expand Down
15 changes: 13 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
const PackageConstructor = require('./utils/packageConstructor')
const TypeHandlerFactory = require('./service/typeHandlerFactory')
const { sanitizePath } = require('./utils/childProcessUtils')
const metadataManager = require('./metadata/metadataManager')
const repoSetup = require('./utils/repoSetup')
const repoGitDiff = require('./utils/repoGitDiff')
Expand Down Expand Up @@ -36,13 +37,23 @@ const checkConfig = config => {
return errors
}

const sanitizeConfig = config => {
config.apiVersion = parseInt(config.apiVersion)
repoSetup(config)
config.repo = config.repo ? sanitizePath(config.repo) : config.repo
config.output = config.output ? sanitizePath(config.output) : config.output
config.ignore = config.ignore ? sanitizePath(config.ignore) : config.ignore
config.ignoreDestructive = config.ignoreDestructive
? sanitizePath(config.ignoreDestructive)
: config.ignoreDestructive
}

module.exports = config => {
sanitizeConfig(config)
const inputError = checkConfig(config)
if (inputError.length > 0) {
throw new Error(inputError)
}
config.apiVersion = parseInt(config.apiVersion)
repoSetup(config)

const metadata = metadataManager.getDefinition(
'directoryName',
Expand Down
9 changes: 7 additions & 2 deletions src/utils/childProcessUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
const os = require('os')
const path = require('path')

module.exports.treatDataFromSpawn = data =>
data.replace(/[/\\]+/g, path.sep).replace(/\r?\n/g, os.EOL)
const treatEOL = data => data.replace(/\r?\n/g, os.EOL)
const treatPathSep = data => data.replace(/[/\\]+/g, path.sep)
const sanitizePath = data => path.normalize(treatPathSep(data))

module.exports.treatDataFromSpawn = data => treatEOL(treatPathSep(data))
module.exports.treatEOL = treatEOL
module.exports.sanitizePath = sanitizePath
2 changes: 1 addition & 1 deletion src/utils/fileGitDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ module.exports = (filePath, config) => {
{ cwd: config.repo, encoding: gc.UTF8_ENCODING }
)

return cpUtils.treatDataFromSpawn(diff)
return cpUtils.treatEOL(diff)
}

0 comments on commit 549addf

Please sign in to comment.