update-browserslist-db 1.0.8 → 1.0.10
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 +14 -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'
|
|
@@ -68,6 +68,11 @@ function getLatestInfo(lock) {
|
|
|
68
68
|
)
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
if (lock.mode === 'pnpm') {
|
|
72
|
+
return JSON.parse(
|
|
73
|
+
childProcess.execSync('pnpm info caniuse-lite --json').toString()
|
|
74
|
+
)
|
|
75
|
+
}
|
|
71
76
|
return JSON.parse(
|
|
72
77
|
childProcess.execSync('npm show caniuse-lite --json').toString()
|
|
73
78
|
)
|
|
@@ -162,11 +167,17 @@ function updateYarnLockfile(lock, latest) {
|
|
|
162
167
|
function updateLockfile(lock, latest) {
|
|
163
168
|
if (!lock.content) lock.content = fs.readFileSync(lock.file).toString()
|
|
164
169
|
|
|
170
|
+
let updatedLockFile
|
|
165
171
|
if (lock.mode === 'yarn') {
|
|
166
|
-
|
|
172
|
+
updatedLockFile = updateYarnLockfile(lock, latest)
|
|
167
173
|
} else {
|
|
168
|
-
|
|
174
|
+
updatedLockFile = updateNpmLockfile(lock, latest)
|
|
169
175
|
}
|
|
176
|
+
updatedLockFile.content = updatedLockFile.content.replace(
|
|
177
|
+
/\n/g,
|
|
178
|
+
detectEOL(lock.content)
|
|
179
|
+
)
|
|
180
|
+
return updatedLockFile
|
|
170
181
|
}
|
|
171
182
|
|
|
172
183
|
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
|