update-browserslist-db 1.0.8 → 1.0.9
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.
- package/index.js +9 -3
- package/package.json +1 -1
- package/utils.js +18 -5
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ let pico = require('picocolors')
|
|
|
4
4
|
let path = require('path')
|
|
5
5
|
let fs = require('fs')
|
|
6
6
|
|
|
7
|
-
const { detectIndent } = require('./utils')
|
|
7
|
+
const { detectIndent, detectEOL } = require('./utils')
|
|
8
8
|
|
|
9
9
|
function BrowserslistUpdateError(message) {
|
|
10
10
|
this.name = 'BrowserslistUpdateError'
|
|
@@ -162,11 +162,17 @@ function updateYarnLockfile(lock, latest) {
|
|
|
162
162
|
function updateLockfile(lock, latest) {
|
|
163
163
|
if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()
|
|
164
164
|
|
|
165
|
+
let updatedLockFile
|
|
165
166
|
if (lock.mode === 'yarn') {
|
|
166
|
-
|
|
167
|
+
updatedLockFile = updateYarnLockfile(lock, latest)
|
|
167
168
|
} else {
|
|
168
|
-
|
|
169
|
+
updatedLockFile = updateNpmLockfile(lock, latest)
|
|
169
170
|
}
|
|
171
|
+
updatedLockFile.content = updatedLockFile.content.replace(
|
|
172
|
+
/\n/g,
|
|
173
|
+
detectEOL(lock.content)
|
|
174
|
+
)
|
|
175
|
+
return updatedLockFile
|
|
170
176
|
}
|
|
171
177
|
|
|
172
178
|
function updatePackageManually(print, lock, latest) {
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
const
|
|
2
|
-
const INDENT_REGEXP = /^([ \t]+)[^\s]/m
|
|
1
|
+
const { EOL } = require('os')
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const getFirstRegexpMatchOrDefault = (text, regexp, defaultValue) => {
|
|
4
|
+
regexp.lastIndex = 0 // https://stackoverflow.com/a/11477448/4536543
|
|
5
|
+
let match = regexp.exec(text)
|
|
6
6
|
if (match !== null) return match[1]
|
|
7
|
-
return
|
|
7
|
+
return defaultValue
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
const DEFAULT_INDENT = ' '
|
|
11
|
+
const INDENT_REGEXP = /^([ \t]+)[^\s]/m
|
|
12
|
+
|
|
13
|
+
module.exports.detectIndent = text =>
|
|
14
|
+
getFirstRegexpMatchOrDefault(text, INDENT_REGEXP, DEFAULT_INDENT)
|
|
9
15
|
module.exports.DEFAULT_INDENT = DEFAULT_INDENT
|
|
16
|
+
|
|
17
|
+
const DEFAULT_EOL = EOL
|
|
18
|
+
const EOL_REGEXP = /(\r\n|\n|\r)/g
|
|
19
|
+
|
|
20
|
+
module.exports.detectEOL = text =>
|
|
21
|
+
getFirstRegexpMatchOrDefault(text, EOL_REGEXP, DEFAULT_EOL)
|
|
22
|
+
module.exports.DEFAULT_EOL = DEFAULT_EOL
|