@modernpoacher/deps 2.2.18 → 2.2.19
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/bin/common/index.mjs +161 -47
- package/bin/deps.mjs +6 -6
- package/bin/node/deps.mjs +5 -21
- package/bin/node/execute.mjs +137 -25
- package/bin/node/head.mjs +5 -21
- package/bin/node/install.mjs +5 -5
- package/bin/node/push.mjs +5 -21
- package/bin/node/wipe.mjs +5 -21
- package/eslint.config.mjs +86 -0
- package/index.d.mts +50 -0
- package/package.json +11 -9
- package/src/common/env/index.mjs +1 -1
- package/src/common/git/index.mjs +98 -62
- package/src/common/index.mjs +32 -55
- package/src/common/options/index.mjs +11 -18
- package/src/index.mjs +56 -44
- package/src/install/index.mjs +15 -19
- package/tsconfig.json +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modernpoacher/deps",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.19",
|
|
4
4
|
"description": "Update NPM package dependencies from the command line",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deps",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"main": "./index.mjs",
|
|
14
14
|
"type": "module",
|
|
15
|
+
"types": "./index.d.mts",
|
|
15
16
|
"author": {
|
|
16
17
|
"name": "Jonathan Perry for Modern Poacher Limited",
|
|
17
18
|
"email": "modernpoacher@modernpoacher.com",
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"deps-install": "cross-env NODE_OPTIONS=--disable-warning=ExperimentalWarning DEBUG_COLORS=yes NODE_ENV=production node bin/deps/install.mjs",
|
|
38
39
|
"deps-push": "cross-env NODE_OPTIONS=--disable-warning=ExperimentalWarning DEBUG_COLORS=yes NODE_ENV=production node bin/deps/push.mjs",
|
|
39
40
|
"deps-wipe": "cross-env NODE_OPTIONS=--disable-warning=ExperimentalWarning DEBUG_COLORS=yes NODE_ENV=production node bin/deps/wipe.mjs",
|
|
40
|
-
"lint": "
|
|
41
|
+
"lint": "eslint .",
|
|
41
42
|
"lint:fix": "npm run lint -- --fix",
|
|
42
43
|
"prepare": "husky",
|
|
43
44
|
"start": "npm run deps",
|
|
@@ -60,15 +61,16 @@
|
|
|
60
61
|
"supports-color": "^10.0.0"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
64
|
+
"@sequencemedia/eslint-config-standard": "^0.2.47",
|
|
65
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.69",
|
|
66
|
+
"@types/chai": "^5.2.1",
|
|
67
|
+
"@types/debug": "^4.1.12",
|
|
68
|
+
"@types/mocha": "^10.0.10",
|
|
69
|
+
"@typescript-eslint/parser": "^8.28.0",
|
|
67
70
|
"chai": "^5.2.0",
|
|
68
|
-
"core-js": "^3.41.0",
|
|
69
71
|
"cross-env": "^7.0.3",
|
|
70
|
-
"eslint": "
|
|
71
|
-
"
|
|
72
|
+
"eslint": "^9.23.0",
|
|
73
|
+
"globals": "^16.0.0",
|
|
72
74
|
"husky": "^9.1.7",
|
|
73
75
|
"mocha": "^11.1.0"
|
|
74
76
|
},
|
package/src/common/env/index.mjs
CHANGED
package/src/common/git/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ const ADD = 'package.json package-lock.json'
|
|
|
28
28
|
|
|
29
29
|
export const MESSAGE = PLATFORM === 'win32'
|
|
30
30
|
? 'Updated `package.json` &/ `package-lock.json`'
|
|
31
|
-
: 'Updated \\`package.json\\` &/ \\`package-lock.json\\`'
|
|
31
|
+
: 'Updated \\`package.json\\` &/ \\`package-lock.json\\`'
|
|
32
32
|
|
|
33
33
|
export const AUTHOR = 'Modern Poacher Limited <modernpoacher@modernpoacher.com>'
|
|
34
34
|
|
|
@@ -40,25 +40,19 @@ echo "\${BASH_REMATCH[0]}"
|
|
|
40
40
|
|
|
41
41
|
const GIT_PULL = `
|
|
42
42
|
source "${BIN}/common.sh"
|
|
43
|
-
|
|
44
43
|
source_home "${BIN}"
|
|
45
|
-
|
|
46
44
|
git pull
|
|
47
45
|
`
|
|
48
46
|
|
|
49
47
|
const GIT_PUSH = `
|
|
50
48
|
source "${BIN}/common.sh"
|
|
51
|
-
|
|
52
49
|
source_home "${BIN}"
|
|
53
|
-
|
|
54
50
|
git push
|
|
55
51
|
`
|
|
56
52
|
|
|
57
53
|
const GIT_PUSH_TAGS = `
|
|
58
54
|
source "${BIN}/common.sh"
|
|
59
|
-
|
|
60
55
|
source_home "${BIN}"
|
|
61
|
-
|
|
62
56
|
git push --tags
|
|
63
57
|
`
|
|
64
58
|
|
|
@@ -66,25 +60,49 @@ const log = debug('@modernpoacher/deps')
|
|
|
66
60
|
|
|
67
61
|
log(`\`common/git\` (${VERSION} - ${PLATFORM}) is awake`)
|
|
68
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} v
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
69
67
|
const trim = (v) => v.split(String.fromCharCode(10)).map((v) => v.trimEnd()).join(String.fromCharCode(10)).trim()
|
|
70
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @param {string} v
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
71
73
|
function filter (v) {
|
|
72
74
|
return Boolean(stripAnsi(v).trim())
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
/**
|
|
78
|
+
* @param {string} directory
|
|
79
|
+
* @returns {(s: string) => boolean}
|
|
80
|
+
*/
|
|
75
81
|
function getIsDirectory (directory) {
|
|
76
82
|
return function isDirectory (s) {
|
|
77
83
|
return directory === s
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
/**
|
|
88
|
+
* @param {string} v
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*/
|
|
91
|
+
function isFatal (v) {
|
|
92
|
+
return v.toLowerCase().startsWith('fatal: not a git repository')
|
|
83
93
|
}
|
|
84
94
|
|
|
95
|
+
/**
|
|
96
|
+
* @param {string} key
|
|
97
|
+
* @returns {(value: string) => void}
|
|
98
|
+
*/
|
|
85
99
|
export function use (key) {
|
|
86
100
|
const log = debug(`@modernpoacher/deps:${key}`)
|
|
87
101
|
|
|
102
|
+
/**
|
|
103
|
+
* @param {string} v
|
|
104
|
+
* @returns {void}
|
|
105
|
+
*/
|
|
88
106
|
function write (v) {
|
|
89
107
|
log(v.trimEnd())
|
|
90
108
|
}
|
|
@@ -96,11 +114,20 @@ export function use (key) {
|
|
|
96
114
|
}
|
|
97
115
|
}
|
|
98
116
|
|
|
117
|
+
/**
|
|
118
|
+
* @param {string} key
|
|
119
|
+
* @param {string} directory
|
|
120
|
+
* @returns {(value: string) => void}
|
|
121
|
+
*/
|
|
99
122
|
export function out (key, directory) {
|
|
100
123
|
const log = debug(`@modernpoacher/deps:${key}`)
|
|
101
124
|
|
|
102
125
|
const isDirectory = getIsDirectory(directory)
|
|
103
126
|
|
|
127
|
+
/**
|
|
128
|
+
* @param {string} v
|
|
129
|
+
* @returns {boolean}
|
|
130
|
+
*/
|
|
104
131
|
function filterOut (v) {
|
|
105
132
|
const s = v.trim()
|
|
106
133
|
|
|
@@ -109,6 +136,10 @@ export function out (key, directory) {
|
|
|
109
136
|
)
|
|
110
137
|
}
|
|
111
138
|
|
|
139
|
+
/**
|
|
140
|
+
* @param {string} v
|
|
141
|
+
* @returns {void}
|
|
142
|
+
*/
|
|
112
143
|
function write (v) {
|
|
113
144
|
if (v.trim()) log(v.trimEnd())
|
|
114
145
|
}
|
|
@@ -120,11 +151,20 @@ export function out (key, directory) {
|
|
|
120
151
|
}
|
|
121
152
|
}
|
|
122
153
|
|
|
154
|
+
/**
|
|
155
|
+
* @param {string} key
|
|
156
|
+
* @param {string} directory
|
|
157
|
+
* @returns {(value: string) => void}
|
|
158
|
+
*/
|
|
123
159
|
export function err (key, directory) {
|
|
124
160
|
const log = debug(`@modernpoacher/deps:${key}`)
|
|
125
161
|
|
|
126
162
|
const isDirectory = getIsDirectory(directory)
|
|
127
163
|
|
|
164
|
+
/**
|
|
165
|
+
* @param {string} v
|
|
166
|
+
* @returns {boolean}
|
|
167
|
+
*/
|
|
128
168
|
function filterErr (v) {
|
|
129
169
|
const s = v.trim()
|
|
130
170
|
|
|
@@ -133,6 +173,10 @@ export function err (key, directory) {
|
|
|
133
173
|
)
|
|
134
174
|
}
|
|
135
175
|
|
|
176
|
+
/**
|
|
177
|
+
* @param {string} v
|
|
178
|
+
* @returns {void}
|
|
179
|
+
*/
|
|
136
180
|
function write (v) {
|
|
137
181
|
if (v.trim()) log(v.trimEnd())
|
|
138
182
|
}
|
|
@@ -149,7 +193,7 @@ export function err (key, directory) {
|
|
|
149
193
|
*
|
|
150
194
|
* Get an error code from an error
|
|
151
195
|
*
|
|
152
|
-
* @param {
|
|
196
|
+
* @param {{code?: number, message?: string}} e
|
|
153
197
|
* @returns {number}
|
|
154
198
|
*/
|
|
155
199
|
const getErrorCode = ({ code = 0 } = {}) => code
|
|
@@ -159,7 +203,7 @@ const getErrorCode = ({ code = 0 } = {}) => code
|
|
|
159
203
|
*
|
|
160
204
|
* Get an error message from an error
|
|
161
205
|
*
|
|
162
|
-
* @param {
|
|
206
|
+
* @param {{code?: number, message?: string}} e
|
|
163
207
|
* @returns {string}
|
|
164
208
|
*/
|
|
165
209
|
const getErrorMessage = ({ message = '' } = {}) => message
|
|
@@ -169,7 +213,7 @@ const getErrorMessage = ({ message = '' } = {}) => message
|
|
|
169
213
|
*
|
|
170
214
|
* Determine whether an error is a safe non-zero exit from a Git command
|
|
171
215
|
*
|
|
172
|
-
* @param {
|
|
216
|
+
* @param {{code?: number, message?: string}} e
|
|
173
217
|
* @returns {boolean}
|
|
174
218
|
*/
|
|
175
219
|
function isCommandError (e) {
|
|
@@ -202,14 +246,12 @@ export function catGitRefsRemotesOriginHead (d = DIRECTORY) {
|
|
|
202
246
|
const {
|
|
203
247
|
stdout,
|
|
204
248
|
stderr
|
|
205
|
-
} = exec(commands, options, (e, v = '') => {
|
|
206
|
-
(!e)
|
|
207
|
-
? resolve(trim(v))
|
|
208
|
-
: reject(e)
|
|
249
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
250
|
+
return (!e) ? resolve(trim(v)) : reject(e)
|
|
209
251
|
})
|
|
210
252
|
|
|
211
|
-
stdout.on('data', out('cat-git-refs-remotes-origin-head', directory))
|
|
212
|
-
stderr.on('data', err('cat-git-refs-remotes-origin-head', directory))
|
|
253
|
+
if (stdout) stdout.on('data', out('cat-git-refs-remotes-origin-head', directory))
|
|
254
|
+
if (stderr) stderr.on('data', err('cat-git-refs-remotes-origin-head', directory))
|
|
213
255
|
})
|
|
214
256
|
)
|
|
215
257
|
}
|
|
@@ -235,14 +277,12 @@ export function awkGitRemoteShowOriginHead (d = DIRECTORY) {
|
|
|
235
277
|
const {
|
|
236
278
|
stdout,
|
|
237
279
|
stderr
|
|
238
|
-
} = exec(commands, options, (e, v = '') => {
|
|
239
|
-
(!e)
|
|
240
|
-
? resolve(trim(v))
|
|
241
|
-
: reject(e)
|
|
280
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
281
|
+
return (!e) ? resolve(trim(v)) : reject(e)
|
|
242
282
|
})
|
|
243
283
|
|
|
244
|
-
stdout.on('data', out('git-remote-show-origin-head', directory))
|
|
245
|
-
stderr.on('data', err('git-remote-show-origin-head', directory))
|
|
284
|
+
if (stdout) stdout.on('data', out('git-remote-show-origin-head', directory))
|
|
285
|
+
if (stderr) stderr.on('data', err('git-remote-show-origin-head', directory))
|
|
246
286
|
})
|
|
247
287
|
)
|
|
248
288
|
}
|
|
@@ -268,14 +308,12 @@ export function gitRevParseShowTopLevel (d = DIRECTORY) {
|
|
|
268
308
|
const {
|
|
269
309
|
stdout,
|
|
270
310
|
stderr
|
|
271
|
-
} = exec(commands, options, (e, v = '') => {
|
|
272
|
-
(!e)
|
|
273
|
-
? resolve(trim(v))
|
|
274
|
-
: reject(e)
|
|
311
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
312
|
+
return (!e) ? resolve(trim(v)) : reject(e)
|
|
275
313
|
})
|
|
276
314
|
|
|
277
|
-
stdout.on('data', out('git-rev-parse-show-toplevel', directory))
|
|
278
|
-
stderr.on('data', err('git-rev-parse-show-toplevel', directory))
|
|
315
|
+
if (stdout) stdout.on('data', out('git-rev-parse-show-toplevel', directory))
|
|
316
|
+
if (stderr) stderr.on('data', err('git-rev-parse-show-toplevel', directory))
|
|
279
317
|
})
|
|
280
318
|
)
|
|
281
319
|
}
|
|
@@ -301,14 +339,12 @@ export function gitRevParseAbbrevRefHead (d = DIRECTORY) {
|
|
|
301
339
|
const {
|
|
302
340
|
stdout,
|
|
303
341
|
stderr
|
|
304
|
-
} = exec(commands, options, (e, v = '') => {
|
|
305
|
-
(!e)
|
|
306
|
-
? resolve(trim(v))
|
|
307
|
-
: reject(e)
|
|
342
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
343
|
+
return (!e) ? resolve(trim(v)) : reject(e)
|
|
308
344
|
})
|
|
309
345
|
|
|
310
|
-
stdout.on('data', out('git-rev-parse-abbrev-ref-head', directory))
|
|
311
|
-
stderr.on('data', err('git-rev-parse-abbrev-ref-head', directory))
|
|
346
|
+
if (stdout) stdout.on('data', out('git-rev-parse-abbrev-ref-head', directory))
|
|
347
|
+
if (stderr) stderr.on('data', err('git-rev-parse-abbrev-ref-head', directory))
|
|
312
348
|
})
|
|
313
349
|
)
|
|
314
350
|
}
|
|
@@ -335,8 +371,8 @@ export function gitCheckout (d = DIRECTORY, branch = BRANCH) {
|
|
|
335
371
|
const {
|
|
336
372
|
stdout,
|
|
337
373
|
stderr
|
|
338
|
-
} = exec(commands, options, (e, v) => {
|
|
339
|
-
(!e)
|
|
374
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
375
|
+
return (!e)
|
|
340
376
|
? resolve(v)
|
|
341
377
|
: isCommandError(e)
|
|
342
378
|
? resolve(v)
|
|
@@ -345,8 +381,8 @@ export function gitCheckout (d = DIRECTORY, branch = BRANCH) {
|
|
|
345
381
|
|
|
346
382
|
const log = use('git-checkout')
|
|
347
383
|
|
|
348
|
-
stdout.on('data', log)
|
|
349
|
-
stderr.on('data', log)
|
|
384
|
+
if (stdout) stdout.on('data', log)
|
|
385
|
+
if (stderr) stderr.on('data', log)
|
|
350
386
|
})
|
|
351
387
|
)
|
|
352
388
|
}
|
|
@@ -372,8 +408,8 @@ export function gitPull (d = DIRECTORY) {
|
|
|
372
408
|
const {
|
|
373
409
|
stdout,
|
|
374
410
|
stderr
|
|
375
|
-
} = exec(commands, options, (e, v) => {
|
|
376
|
-
(!e)
|
|
411
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
412
|
+
return (!e)
|
|
377
413
|
? resolve(v)
|
|
378
414
|
: isCommandError(e)
|
|
379
415
|
? resolve(v)
|
|
@@ -382,8 +418,8 @@ export function gitPull (d = DIRECTORY) {
|
|
|
382
418
|
|
|
383
419
|
const log = use('git-pull')
|
|
384
420
|
|
|
385
|
-
stdout.on('data', log)
|
|
386
|
-
stderr.on('data', log)
|
|
421
|
+
if (stdout) stdout.on('data', log)
|
|
422
|
+
if (stderr) stderr.on('data', log)
|
|
387
423
|
})
|
|
388
424
|
)
|
|
389
425
|
}
|
|
@@ -409,8 +445,8 @@ export function gitPush (d = DIRECTORY) {
|
|
|
409
445
|
const {
|
|
410
446
|
stdout,
|
|
411
447
|
stderr
|
|
412
|
-
} = exec(commands, options, (e, v) => {
|
|
413
|
-
(!e)
|
|
448
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
449
|
+
return (!e)
|
|
414
450
|
? resolve(v)
|
|
415
451
|
: isCommandError(e)
|
|
416
452
|
? resolve(v)
|
|
@@ -419,8 +455,8 @@ export function gitPush (d = DIRECTORY) {
|
|
|
419
455
|
|
|
420
456
|
const log = use('git-push')
|
|
421
457
|
|
|
422
|
-
stdout.on('data', log)
|
|
423
|
-
stderr.on('data', log)
|
|
458
|
+
if (stdout) stdout.on('data', log)
|
|
459
|
+
if (stderr) stderr.on('data', log)
|
|
424
460
|
})
|
|
425
461
|
)
|
|
426
462
|
}
|
|
@@ -446,8 +482,8 @@ export function gitPushTags (d = DIRECTORY) {
|
|
|
446
482
|
const {
|
|
447
483
|
stdout,
|
|
448
484
|
stderr
|
|
449
|
-
} = exec(commands, options, (e, v) => {
|
|
450
|
-
(!e)
|
|
485
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
486
|
+
return (!e)
|
|
451
487
|
? resolve(v)
|
|
452
488
|
: isCommandError(e)
|
|
453
489
|
? resolve(v)
|
|
@@ -456,8 +492,8 @@ export function gitPushTags (d = DIRECTORY) {
|
|
|
456
492
|
|
|
457
493
|
const log = use('git-push-tags')
|
|
458
494
|
|
|
459
|
-
stdout.on('data', log)
|
|
460
|
-
stderr.on('data', log)
|
|
495
|
+
if (stdout) stdout.on('data', log)
|
|
496
|
+
if (stderr) stderr.on('data', log)
|
|
461
497
|
})
|
|
462
498
|
)
|
|
463
499
|
}
|
|
@@ -484,8 +520,8 @@ export function gitAdd (d = DIRECTORY, add = ADD) {
|
|
|
484
520
|
const {
|
|
485
521
|
stdout,
|
|
486
522
|
stderr
|
|
487
|
-
} = exec(commands, options, (e, v) => {
|
|
488
|
-
(!e)
|
|
523
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
524
|
+
return (!e)
|
|
489
525
|
? resolve(v)
|
|
490
526
|
: isCommandError(e)
|
|
491
527
|
? resolve(v)
|
|
@@ -494,8 +530,8 @@ export function gitAdd (d = DIRECTORY, add = ADD) {
|
|
|
494
530
|
|
|
495
531
|
const log = use('git-add')
|
|
496
532
|
|
|
497
|
-
stdout.on('data', log)
|
|
498
|
-
stderr.on('data', log)
|
|
533
|
+
if (stdout) stdout.on('data', log)
|
|
534
|
+
if (stderr) stderr.on('data', log)
|
|
499
535
|
})
|
|
500
536
|
)
|
|
501
537
|
}
|
|
@@ -505,9 +541,9 @@ export function gitAdd (d = DIRECTORY, add = ADD) {
|
|
|
505
541
|
*
|
|
506
542
|
* Commit changes to Git with a default value if none is supplied
|
|
507
543
|
*
|
|
508
|
-
* @param {string}
|
|
544
|
+
* @param {string} d - A directory configured for Git
|
|
509
545
|
* @param {string} message - A commit message
|
|
510
|
-
* @param {string} author - The commit author
|
|
546
|
+
* @param {string | { name: string; email: string }} author - The commit author
|
|
511
547
|
* @returns {Promise<string>}
|
|
512
548
|
*/
|
|
513
549
|
export function gitCommit (d = DIRECTORY, message = MESSAGE, author = AUTHOR) {
|
|
@@ -523,8 +559,8 @@ export function gitCommit (d = DIRECTORY, message = MESSAGE, author = AUTHOR) {
|
|
|
523
559
|
const {
|
|
524
560
|
stdout,
|
|
525
561
|
stderr
|
|
526
|
-
} = exec(commands, options, (e, v) => {
|
|
527
|
-
(!e)
|
|
562
|
+
} = exec(commands, options, (e = null, v = '') => {
|
|
563
|
+
return (!e)
|
|
528
564
|
? resolve(v)
|
|
529
565
|
: isCommandError(e)
|
|
530
566
|
? resolve(v)
|
|
@@ -533,8 +569,8 @@ export function gitCommit (d = DIRECTORY, message = MESSAGE, author = AUTHOR) {
|
|
|
533
569
|
|
|
534
570
|
const log = use('git-commit')
|
|
535
571
|
|
|
536
|
-
stdout.on('data', log)
|
|
537
|
-
stderr.on('data', log)
|
|
572
|
+
if (stdout) stdout.on('data', log)
|
|
573
|
+
if (stderr) stderr.on('data', log)
|
|
538
574
|
})
|
|
539
575
|
)
|
|
540
576
|
}
|
package/src/common/index.mjs
CHANGED
|
@@ -1,40 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @typedef {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A dependency descriptor
|
|
9
|
-
*
|
|
10
|
-
* @typedef {Object} DependencyDescriptor
|
|
11
|
-
* @property {string} name - Dependency name in NPM.
|
|
12
|
-
* @property {string} version - Dependency version or "latest".
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A package
|
|
17
|
-
*
|
|
18
|
-
* @typedef {Object} Package
|
|
19
|
-
* @property {string|{name: string, email: string}} author
|
|
20
|
-
* @property {Dependencies} dependencies - Production dependencies.
|
|
21
|
-
* @property {Dependencies} devDependencies - Development dependencies.
|
|
22
|
-
* @property {Dependencies} optionalDependencies - Optional dependencies.
|
|
23
|
-
* @property {Dependencies} bundleDependencies - Bundle dependencies.
|
|
24
|
-
* @property {Dependencies} peerDependencies - Peer dependencies
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A configuration
|
|
29
|
-
*
|
|
30
|
-
* @typedef {Object} Configuration
|
|
31
|
-
* @property {string|{name: string, email: string}} author
|
|
32
|
-
* @property {boolean} ignore
|
|
33
|
-
* @property {Dependencies} dependencies - Production dependencies.
|
|
34
|
-
* @property {Dependencies} devDependencies - Development dependencies.
|
|
35
|
-
* @property {Dependencies} optionalDependencies - Optional dependencies.
|
|
36
|
-
* @property {Dependencies} bundleDependencies - Bundle dependencies.
|
|
37
|
-
* @property {Dependencies} peerDependencies - Peer dependencies
|
|
2
|
+
* @typedef {DepsTypes.Dependencies} Dependencies
|
|
3
|
+
* @typedef {DepsTypes.DependencyDescriptor} DependencyDescriptor
|
|
4
|
+
* @typedef {DepsTypes.Package} Package
|
|
5
|
+
* @typedef {DepsTypes.Configuration} Configuration
|
|
38
6
|
*/
|
|
39
7
|
|
|
40
8
|
import debug from 'debug'
|
|
@@ -62,8 +30,16 @@ const log = debug('@modernpoacher/deps')
|
|
|
62
30
|
|
|
63
31
|
log(`\`common\` (${VERSION} - ${PLATFORM}) is awake`)
|
|
64
32
|
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} v
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
65
37
|
export const tidy = (v) => v.replace(/\n{2,}}/gm, String.fromCharCode(10)).trim()
|
|
66
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} v
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
67
43
|
export const trim = (v) => v.split(String.fromCharCode(10)).map((v) => v.trimEnd()).join(String.fromCharCode(10)).trim()
|
|
68
44
|
|
|
69
45
|
/**
|
|
@@ -71,7 +47,7 @@ export const trim = (v) => v.split(String.fromCharCode(10)).map((v) => v.trimEnd
|
|
|
71
47
|
*
|
|
72
48
|
* Get the `--save-prod` parameter
|
|
73
49
|
*
|
|
74
|
-
* @param {string}
|
|
50
|
+
* @param {string} commands commands string
|
|
75
51
|
* @returns {string}
|
|
76
52
|
*/
|
|
77
53
|
export const getSaveProdParameter = (commands) => commands.concat(' --save-prod')
|
|
@@ -81,7 +57,7 @@ export const getSaveProdParameter = (commands) => commands.concat(' --save-prod'
|
|
|
81
57
|
*
|
|
82
58
|
* Get the `--save-dev` parameter
|
|
83
59
|
*
|
|
84
|
-
* @param {string}
|
|
60
|
+
* @param {string} commands commands string
|
|
85
61
|
* @returns {string}
|
|
86
62
|
*/
|
|
87
63
|
export const getSaveDevParameter = (commands) => commands.concat(' --save-dev')
|
|
@@ -192,7 +168,7 @@ export const getCommands = PLATFORM === 'win32'
|
|
|
192
168
|
*
|
|
193
169
|
* Get the production dependencies by destructuring the package or configuration
|
|
194
170
|
*
|
|
195
|
-
* @param {Package|Configuration}
|
|
171
|
+
* @param {Package | Configuration} deps
|
|
196
172
|
* @returns {Dependencies}
|
|
197
173
|
*/
|
|
198
174
|
export const getProdDependencies = ({ dependencies = {} } = {}) => dependencies
|
|
@@ -202,7 +178,7 @@ export const getProdDependencies = ({ dependencies = {} } = {}) => dependencies
|
|
|
202
178
|
*
|
|
203
179
|
* Get the development dependencies by destructuring the package or configuration
|
|
204
180
|
*
|
|
205
|
-
* @param {Package|Configuration}
|
|
181
|
+
* @param {Package | Configuration} deps
|
|
206
182
|
* @returns {Dependencies}
|
|
207
183
|
*/
|
|
208
184
|
export const getDevDependencies = ({ devDependencies = {} } = {}) => devDependencies
|
|
@@ -212,7 +188,7 @@ export const getDevDependencies = ({ devDependencies = {} } = {}) => devDependen
|
|
|
212
188
|
*
|
|
213
189
|
* Get the optional dependencies by destructuring the package or configuration
|
|
214
190
|
*
|
|
215
|
-
* @param {Package|Configuration}
|
|
191
|
+
* @param {Package | Configuration} deps
|
|
216
192
|
* @returns {Dependencies}
|
|
217
193
|
*/
|
|
218
194
|
export const getOptionalDependencies = ({ optionalDependencies = {} } = {}) => optionalDependencies
|
|
@@ -222,7 +198,7 @@ export const getOptionalDependencies = ({ optionalDependencies = {} } = {}) => o
|
|
|
222
198
|
*
|
|
223
199
|
* Get the bundle dependencies by destructuring the package or configuration
|
|
224
200
|
*
|
|
225
|
-
* @param {Package|Configuration}
|
|
201
|
+
* @param {Package | Configuration} deps
|
|
226
202
|
* @returns {Dependencies}
|
|
227
203
|
*/
|
|
228
204
|
export const getBundleDependencies = ({ bundleDependencies = {} } = {}) => bundleDependencies
|
|
@@ -232,17 +208,17 @@ export const getBundleDependencies = ({ bundleDependencies = {} } = {}) => bundl
|
|
|
232
208
|
*
|
|
233
209
|
* Get the peer dependencies by destructuring the package or configuration
|
|
234
210
|
*
|
|
235
|
-
* @param {Package|Configuration}
|
|
211
|
+
* @param {Package | Configuration} deps
|
|
236
212
|
* @returns {Dependencies}
|
|
237
213
|
*/
|
|
238
|
-
export const getPeerDependencies = ({ peerDependencies } = {}) => peerDependencies
|
|
214
|
+
export const getPeerDependencies = ({ peerDependencies = {} } = {}) => peerDependencies
|
|
239
215
|
|
|
240
216
|
/**
|
|
241
217
|
* @function getIgnore
|
|
242
218
|
*
|
|
243
219
|
* Get the ignore flag by destructuring the configuration
|
|
244
220
|
*
|
|
245
|
-
* @param {Configuration}
|
|
221
|
+
* @param {Configuration} deps
|
|
246
222
|
* @returns {boolean}
|
|
247
223
|
*/
|
|
248
224
|
export const getIgnore = ({ ignore = false } = {}) => ignore === true
|
|
@@ -252,11 +228,12 @@ export const getIgnore = ({ ignore = false } = {}) => ignore === true
|
|
|
252
228
|
*
|
|
253
229
|
* Get the author by destructuring the package or configuration
|
|
254
230
|
*
|
|
255
|
-
* @param {Package|Configuration}
|
|
256
|
-
* @returns {string|null}
|
|
231
|
+
* @param {Package | Configuration} deps
|
|
232
|
+
* @returns {string | null}
|
|
257
233
|
*/
|
|
258
234
|
export const getAuthor = ({ author = '' } = {}) => {
|
|
259
|
-
if (
|
|
235
|
+
if (typeof author === 'string') return author
|
|
236
|
+
if (typeof (author || false) === 'object') {
|
|
260
237
|
const {
|
|
261
238
|
name: NAME = '',
|
|
262
239
|
email: EMAIL = ''
|
|
@@ -272,7 +249,7 @@ export const getAuthor = ({ author = '' } = {}) => {
|
|
|
272
249
|
)
|
|
273
250
|
}
|
|
274
251
|
|
|
275
|
-
return
|
|
252
|
+
return null
|
|
276
253
|
}
|
|
277
254
|
|
|
278
255
|
/**
|
|
@@ -280,8 +257,8 @@ export const getAuthor = ({ author = '' } = {}) => {
|
|
|
280
257
|
*
|
|
281
258
|
* Get the message by destructuring the configuration
|
|
282
259
|
*
|
|
283
|
-
* @param {Configuration}
|
|
284
|
-
* @returns {string|null}
|
|
260
|
+
* @param {Configuration} deps
|
|
261
|
+
* @returns {string | null}
|
|
285
262
|
*/
|
|
286
263
|
export const getMessage = ({ message = '' } = {}) => message || null
|
|
287
264
|
|
|
@@ -439,13 +416,13 @@ export function getDeps (packageDependencies) {
|
|
|
439
416
|
*
|
|
440
417
|
* Normalise the commands string
|
|
441
418
|
*
|
|
442
|
-
* @param {string}
|
|
419
|
+
* @param {string} commands
|
|
443
420
|
* @returns {string}
|
|
444
421
|
*/
|
|
445
422
|
export function normalizeCommands (commands) {
|
|
446
423
|
const s = String.fromCharCode(32)
|
|
447
424
|
|
|
448
|
-
while (/\s{2,}
|
|
425
|
+
while (/\s{2,} | \n+/.test(commands)) {
|
|
449
426
|
commands = commands.replace(/\s{2,}/gm, s).replace(/\n+/gm, s)
|
|
450
427
|
}
|
|
451
428
|
|
|
@@ -459,7 +436,7 @@ export function normalizeCommands (commands) {
|
|
|
459
436
|
*
|
|
460
437
|
* Transform by destructuring the value
|
|
461
438
|
*
|
|
462
|
-
* @param {DependencyDescriptor}
|
|
439
|
+
* @param {DependencyDescriptor | { name?: string, version?: string }} dependencyDescriptor
|
|
463
440
|
* @returns {string}
|
|
464
441
|
*/
|
|
465
442
|
export const transformDependency = ({ name = '@modernpoacher/deps', version = 'latest' } = {}) => `${name}@${version}`
|
|
@@ -469,7 +446,7 @@ export const transformDependency = ({ name = '@modernpoacher/deps', version = 'l
|
|
|
469
446
|
*
|
|
470
447
|
* Transform the parameter to a string
|
|
471
448
|
*
|
|
472
|
-
* @param {DependencyDescriptor|DependencyDescriptor[]} value
|
|
449
|
+
* @param {DependencyDescriptor | DependencyDescriptor[]} value
|
|
473
450
|
* @returns {string}
|
|
474
451
|
*/
|
|
475
452
|
export function transform (value) {
|