Skip to content

Commit

Permalink
feat: merge npmrc files
Browse files Browse the repository at this point in the history
Closes #258
  • Loading branch information
lukekarrys committed Nov 10, 2022
1 parent dfbdadc commit e4465dd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; This file is automatically added by @npmcli/template-oss. Do not edit.

package-lock=false
install-links=false
30 changes: 28 additions & 2 deletions lib/util/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const NpmPackageJson = require('@npmcli/package-json')
const jsonParse = require('json-parse-even-better-errors')
const Diff = require('diff')
const { unset } = require('lodash')
const ini = require('ini')
const template = require('./template.js')
const jsonDiff = require('./json-diff')
const merge = require('./merge.js')
Expand Down Expand Up @@ -176,9 +177,33 @@ class Js extends Base {
}

class Ini extends Base {
// XXX: add merge mode for updating ini files
static types = ['npmrc']
static types = ['ini']
comment = (c) => `; ${c}`

toString (s) {
return typeof s === 'string' ? s : ini.stringify(s)
}

parse (s) {
return typeof s === 'string' ? ini.parse(s) : s
}

prepare (s, t) {
let source = s
if (typeof this.merge === 'function' && t) {
source = this.merge(t, s)
}
return super.prepare(this.toString(source))
}

diff (t, s) {
return jsonDiff(this.parse(t), this.parse(s), this.DELETE)
}
}

class IniMerge extends Ini {
static types = ['npmrc']
merge = (t, s) => merge(t, s)
}

class Markdown extends Base {
Expand Down Expand Up @@ -314,6 +339,7 @@ const Parsers = {
Gitignore,
Js,
Ini,
IniMerge,
Markdown,
Yml,
YmlMerge,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"glob": "^8.0.1",
"handlebars": "^4.7.7",
"hosted-git-info": "^6.0.0",
"ini": "^3.0.1",
"json-parse-even-better-errors": "^3.0.0",
"just-deep-map-values": "^1.1.1",
"just-diff": "^5.0.1",
Expand Down

0 comments on commit e4465dd

Please sign in to comment.