Permalink
Browse files

feat(non-npm): add support for running non-npm commands

BREAKING CHANGE: this removes the --npm-bin option in favor of --command
  • Loading branch information...
zkat committed Dec 3, 2017
1 parent 72dcd14 commit aee4e7081e520c6c5a8371a7e0081bc38b9952f3
Showing with 47 additions and 17 deletions.
  1. +29 −5 README.md
  2. +18 −12 index.js
@@ -47,6 +47,14 @@ have specific needs.
`--driver-name` - string to use as the merge driver name in your configuration
`--files` - list of files that will trigger this driver
#### Merge Options
`npm-merge-driver merge` can also be configured:
`-c, --command` - command to execute when a lockfile is conflicted
#### Install as Dependency
To avoid regular `npx` installs, consider installing the driver:
@@ -55,10 +63,10 @@ To avoid regular `npx` installs, consider installing the driver:
#### Manual Setup (advanced):
`npm-merge-driver` requires two git configurations to work:
a git configuration to add the driver to git, which is by default your local
`.git/config` file, and a `gitattributes` configuration, which is by default
your local `.git/info/attributes`.
`npm-merge-driver` requires two git configurations to work: a git configuration
to add the driver to git, which is by default your local `.git/config` file, and
a `gitattributes(5)` configuration, which is by default your local
`.git/info/attributes`.
If you **do not** want `npm-merge-driver` to install itself for you:
@@ -67,7 +75,7 @@ Add the driver to `.git/config`:
$ git config merge."npm-merge-driver".name \
"Automatically merge npm lockfiles"
$ git config merge."npm-merge-driver".driver \
"npx npm-merge-driver merge npm %A %O %B %P"
"npx npm-merge-driver merge %A %O %B %P"
```
Add the relevant attributes to `.gitattributes` or `.git/info/attributes`:
@@ -76,6 +84,22 @@ package-lock.json merge=npm-merge-driver
npm-shrinkwrap.json merge=npm-merge-driver
```
#### Using with other package managers
`npm-merge-driver` can be used with package managers other than npm! It's a bit
more verbose, but works just as well, assuming the package manager has a command
that can automatically resolve merge conflicts in its lockfile:
```
$ npx npm-merge-driver install \
--driver-name yarn-merge-driver \
--driver "npx npm-merge-driver merge %A %O %B %P -c yarn"
--files yarn.lock
```
...and now, any time `yarn.lock` has a conflict, it will be automatically
resolved without you having to manually run `yarn`.
## AUTHOR
Written by [Kat Marchan](https://github.com/zkat)
@@ -18,23 +18,35 @@ function parseArgs () {
{
driver: {
type: 'string',
default: 'npx npm-merge-driver merge npm %A %O %B %P',
default: 'npx npm-merge-driver merge %A %O %B %P',
description:
'string to install as the driver in the git configuration'
},
'driver-name': {
type: 'string',
default: 'npm-merge-driver',
description:
'string to use as the merge driver name in your configuration'
'String to use as the merge driver name in your configuration.'
},
files: {
description: 'Filenames that will trigger this driver.',
type: 'array',
default: ['npm-shrinkwrap.json', 'package-lock.json']
}
},
configureGit
)
.command(
'merge <npm-bin> <%A> <%O> <%B> <%P>',
'merge <%A> <%O> <%B> <%P>',
'Check for lockfile conflicts and correct them if necessary.',
{},
{
command: {
alias: 'c',
description: 'Command to execute to resolve conflicts.',
type: 'string',
default: 'npm install --package-lock-only'
}
},
mergeFiles
)
.version(require('./package.json').version)
@@ -57,11 +69,7 @@ function configureGit (argv) {
.trim()
fs.appendFileSync(
path.join(gitDir, 'info', 'attributes'),
[
'',
`npm-shrinkwrap.json merge=${argv.driverName}`,
`package-lock.json merge=${argv.driverName}`
].join('\n')
'\n' + argv.files.map(f => `${f} merge=${argv.driverName}`).join('\n')
)
}
@@ -74,8 +82,6 @@ function mergeFiles (argv) {
}
)
fs.writeFileSync(argv['%P'], ret.stdout)
cp.spawnSync(argv.npmBin, ['install', '--package-lock-only'], {
stdio: 'inherit'
})
cp.execSync(argv.command, { stdio: 'inherit' })
fs.writeFileSync(argv['%A'], fs.readFileSync(argv['%P']))
}

0 comments on commit aee4e70

Please sign in to comment.