@modernpoacher/deps 2.0.16 → 2.0.18
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/execute/app.mjs +47 -5
- package/package.json +7 -7
- package/src/common/git/index.mjs +50 -55
- package/src/common/index.mjs +111 -80
- package/src/index.mjs +210 -176
- package/src/install/index.mjs +56 -39
package/src/common/index.mjs
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package or configuration dependencies
|
|
3
|
+
* @typedef {Object.<string, string>} Dependencies
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A dependency descriptor
|
|
8
|
+
* @typedef {Object} DependencyDescriptor
|
|
9
|
+
* @property {string} name - Dependency name in NPM.
|
|
10
|
+
* @property {string} version - Dependency version or "latest".
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A package
|
|
15
|
+
* @typedef {Object} Package
|
|
16
|
+
* @property {string|{name: string, email: string}} author
|
|
17
|
+
* @property {Dependencies} dependencies - Production dependencies.
|
|
18
|
+
* @property {Dependencies} devDependencies - Development dependencies.
|
|
19
|
+
* @property {Dependencies} optionalDependencies - Optional dependencies.
|
|
20
|
+
* @property {Dependencies} bundleDependencies - Bundle dependencies.
|
|
21
|
+
* @property {Dependencies} peerDependencies - Peer dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A configuration
|
|
26
|
+
* @typedef {Object} Configuration
|
|
27
|
+
* @property {string|{name: string, email: string}} author
|
|
28
|
+
* @property {boolean} ignore
|
|
29
|
+
* @property {Dependencies} dependencies - Production dependencies.
|
|
30
|
+
* @property {Dependencies} devDependencies - Development dependencies.
|
|
31
|
+
* @property {Dependencies} optionalDependencies - Optional dependencies.
|
|
32
|
+
* @property {Dependencies} bundleDependencies - Bundle dependencies.
|
|
33
|
+
* @property {Dependencies} peerDependencies - Peer dependencies
|
|
34
|
+
*/
|
|
35
|
+
|
|
1
36
|
import debug from 'debug'
|
|
2
37
|
|
|
3
38
|
import PATH from '#where-am-i'
|
|
@@ -23,16 +58,16 @@ const log = debug('@modernpoacher/deps')
|
|
|
23
58
|
|
|
24
59
|
log(`\`common\` (${VERSION} - ${PLATFORM}) is awake at "${PATH}"`)
|
|
25
60
|
|
|
26
|
-
const tidy = (v) => v.replace(/\n
|
|
61
|
+
const tidy = (v) => v.replace(/\n{2,}}/gm, String.fromCharCode(10)).trim()
|
|
27
62
|
|
|
28
63
|
/**
|
|
29
64
|
* @function getSaveProdParameter
|
|
30
65
|
*
|
|
31
66
|
* Get the `--save-prod` parameter
|
|
32
67
|
*
|
|
33
|
-
* @param {
|
|
68
|
+
* @param {string} current commands string
|
|
34
69
|
*
|
|
35
|
-
* @return {
|
|
70
|
+
* @return {string}
|
|
36
71
|
*/
|
|
37
72
|
export const getSaveProdParameter = (commands) => commands.concat(' --save-prod')
|
|
38
73
|
|
|
@@ -41,9 +76,9 @@ export const getSaveProdParameter = (commands) => commands.concat(' --save-prod'
|
|
|
41
76
|
*
|
|
42
77
|
* Get the `--save-dev` parameter
|
|
43
78
|
*
|
|
44
|
-
* @param {
|
|
79
|
+
* @param {string} current commands string
|
|
45
80
|
*
|
|
46
|
-
* @return {
|
|
81
|
+
* @return {string}
|
|
47
82
|
*/
|
|
48
83
|
export const getSaveDevParameter = (commands) => commands.concat(' --save-dev')
|
|
49
84
|
|
|
@@ -52,9 +87,9 @@ export const getSaveDevParameter = (commands) => commands.concat(' --save-dev')
|
|
|
52
87
|
*
|
|
53
88
|
* Get the "save bundle" parameter
|
|
54
89
|
*
|
|
55
|
-
* @param {
|
|
90
|
+
* @param {string} commands - Current commands string
|
|
56
91
|
*
|
|
57
|
-
* @return {
|
|
92
|
+
* @return {string}
|
|
58
93
|
*/
|
|
59
94
|
export const getSaveBundleParameter = (commands) => commands.concat(' --save-bundle')
|
|
60
95
|
|
|
@@ -63,9 +98,9 @@ export const getSaveBundleParameter = (commands) => commands.concat(' --save-bun
|
|
|
63
98
|
*
|
|
64
99
|
* Get the `--save-optional` parameter
|
|
65
100
|
*
|
|
66
|
-
* @param {
|
|
101
|
+
* @param {string} commands - Current commands string
|
|
67
102
|
*
|
|
68
|
-
* @return {
|
|
103
|
+
* @return {string}
|
|
69
104
|
*/
|
|
70
105
|
export const getSaveOptionalParameter = (commands) => commands.concat(' --save-optional')
|
|
71
106
|
|
|
@@ -74,10 +109,10 @@ export const getSaveOptionalParameter = (commands) => commands.concat(' --save-o
|
|
|
74
109
|
*
|
|
75
110
|
* Get the "registry" parameter and argument
|
|
76
111
|
*
|
|
77
|
-
* @param {
|
|
78
|
-
* @param {
|
|
112
|
+
* @param {string} r - Registry
|
|
113
|
+
* @param {string} commands - Current commands string
|
|
79
114
|
*
|
|
80
|
-
* @return {
|
|
115
|
+
* @return {string}
|
|
81
116
|
*/
|
|
82
117
|
export const getRegistryParameter = (r, commands) => r ? commands.concat(` --registry ${r}`) : commands
|
|
83
118
|
|
|
@@ -86,10 +121,10 @@ export const getRegistryParameter = (r, commands) => r ? commands.concat(` --reg
|
|
|
86
121
|
*
|
|
87
122
|
* Get the "force" parameter and argument
|
|
88
123
|
*
|
|
89
|
-
* @param {
|
|
90
|
-
* @param {
|
|
124
|
+
* @param {boolean} f - Force
|
|
125
|
+
* @param {string} commands - Current commands string
|
|
91
126
|
*
|
|
92
|
-
* @return {
|
|
127
|
+
* @return {string}
|
|
93
128
|
*/
|
|
94
129
|
export const getForceParameter = (f, commands) => f ? commands.concat(' --force') : commands
|
|
95
130
|
|
|
@@ -98,10 +133,10 @@ export const getForceParameter = (f, commands) => f ? commands.concat(' --force'
|
|
|
98
133
|
*
|
|
99
134
|
* Get the `--no-save` parameter
|
|
100
135
|
*
|
|
101
|
-
* @param {
|
|
102
|
-
* @param {
|
|
136
|
+
* @param {boolean} s - Save
|
|
137
|
+
* @param {string} commands - Current commands string
|
|
103
138
|
*
|
|
104
|
-
* @return {
|
|
139
|
+
* @return {string}
|
|
105
140
|
*/
|
|
106
141
|
export const getNoSaveParameter = (s, commands) => s ? commands : commands.concat(' --no-save')
|
|
107
142
|
|
|
@@ -110,10 +145,9 @@ export const getNoSaveParameter = (s, commands) => s ? commands : commands.conca
|
|
|
110
145
|
*
|
|
111
146
|
* Get the `--save-exact` parameter
|
|
112
147
|
*
|
|
113
|
-
* @param {
|
|
114
|
-
* @param {String} current commands string
|
|
148
|
+
* @param {string} commands - Current commands string
|
|
115
149
|
*
|
|
116
|
-
* @return {
|
|
150
|
+
* @return {string}
|
|
117
151
|
*/
|
|
118
152
|
export const getSaveExactParameter = (commands) => commands.concat(' --save-exact')
|
|
119
153
|
|
|
@@ -122,9 +156,9 @@ export const getSaveExactParameter = (commands) => commands.concat(' --save-exac
|
|
|
122
156
|
*
|
|
123
157
|
* Get the export PATH shell script
|
|
124
158
|
*
|
|
125
|
-
* @param {
|
|
159
|
+
* @param {string} commands - Current commands string
|
|
126
160
|
*
|
|
127
|
-
* @return {
|
|
161
|
+
* @return {string}
|
|
128
162
|
*/
|
|
129
163
|
export const getExportPath = (commands) => `
|
|
130
164
|
export PATH=/usr/local/bin:$PATH &> /dev/null
|
|
@@ -136,9 +170,9 @@ ${commands}
|
|
|
136
170
|
*
|
|
137
171
|
* Get the NVM shell script
|
|
138
172
|
*
|
|
139
|
-
* @param {
|
|
173
|
+
* @param {string} commands - Current commands string
|
|
140
174
|
*
|
|
141
|
-
* @return {
|
|
175
|
+
* @return {string}
|
|
142
176
|
*/
|
|
143
177
|
export const getNvm = (commands) => `
|
|
144
178
|
. "${NVM}" 2> /dev/null
|
|
@@ -150,30 +184,22 @@ ${commands}
|
|
|
150
184
|
*
|
|
151
185
|
* Get the installation shell script
|
|
152
186
|
*
|
|
153
|
-
* @param {
|
|
154
|
-
* @param {String} commands
|
|
187
|
+
* @param {string} commands - Current commands string
|
|
155
188
|
*
|
|
156
|
-
* @return {
|
|
189
|
+
* @return {string}
|
|
157
190
|
*/
|
|
158
|
-
|
|
159
191
|
export const getCommands = PLATFORM === 'win32'
|
|
160
|
-
? (
|
|
161
|
-
|
|
162
|
-
${commands}
|
|
163
|
-
`)
|
|
164
|
-
: (directory = DIRECTORY, commands = 'npm i') => tidy(`
|
|
165
|
-
echo Directory is \\"${directory}\\"
|
|
166
|
-
${getExportPath(getNvm(commands))}
|
|
167
|
-
`)
|
|
192
|
+
? (commands = 'npm i') => tidy(commands)
|
|
193
|
+
: (commands = 'npm i') => tidy(getExportPath(getNvm(commands)))
|
|
168
194
|
|
|
169
195
|
/**
|
|
170
196
|
* @function getProdDependencies
|
|
171
197
|
*
|
|
172
198
|
* Get the production dependencies by destructuring the package or configuration
|
|
173
199
|
*
|
|
174
|
-
* @param {
|
|
200
|
+
* @param {Package|Configuration}
|
|
175
201
|
*
|
|
176
|
-
* @return {
|
|
202
|
+
* @return {Dependencies}
|
|
177
203
|
*/
|
|
178
204
|
export const getProdDependencies = ({ dependencies = {} } = {}) => dependencies
|
|
179
205
|
|
|
@@ -182,9 +208,9 @@ export const getProdDependencies = ({ dependencies = {} } = {}) => dependencies
|
|
|
182
208
|
*
|
|
183
209
|
* Get the development dependencies by destructuring the package or configuration
|
|
184
210
|
*
|
|
185
|
-
* @param {
|
|
211
|
+
* @param {Package|Configuration}
|
|
186
212
|
*
|
|
187
|
-
* @return {
|
|
213
|
+
* @return {Dependencies}
|
|
188
214
|
*/
|
|
189
215
|
export const getDevDependencies = ({ devDependencies = {} } = {}) => devDependencies
|
|
190
216
|
|
|
@@ -193,9 +219,9 @@ export const getDevDependencies = ({ devDependencies = {} } = {}) => devDependen
|
|
|
193
219
|
*
|
|
194
220
|
* Get the optional dependencies by destructuring the package or configuration
|
|
195
221
|
*
|
|
196
|
-
* @param {
|
|
222
|
+
* @param {Package|Configuration}
|
|
197
223
|
*
|
|
198
|
-
* @return {
|
|
224
|
+
* @return {Dependencies}
|
|
199
225
|
*/
|
|
200
226
|
export const getOptionalDependencies = ({ optionalDependencies = {} } = {}) => optionalDependencies
|
|
201
227
|
|
|
@@ -204,20 +230,20 @@ export const getOptionalDependencies = ({ optionalDependencies = {} } = {}) => o
|
|
|
204
230
|
*
|
|
205
231
|
* Get the bundle dependencies by destructuring the package or configuration
|
|
206
232
|
*
|
|
207
|
-
* @param {
|
|
233
|
+
* @param {Package|Configuration}
|
|
208
234
|
*
|
|
209
|
-
* @return {
|
|
235
|
+
* @return {Dependencies}
|
|
210
236
|
*/
|
|
211
|
-
export const getBundleDependencies = ({ bundleDependencies =
|
|
237
|
+
export const getBundleDependencies = ({ bundleDependencies = {} } = {}) => bundleDependencies
|
|
212
238
|
|
|
213
239
|
/**
|
|
214
240
|
* @function getPeerDependencies
|
|
215
241
|
*
|
|
216
242
|
* Get the peer dependencies by destructuring the package or configuration
|
|
217
243
|
*
|
|
218
|
-
* @param {
|
|
244
|
+
* @param {Package|Configuration}
|
|
219
245
|
*
|
|
220
|
-
* @return {
|
|
246
|
+
* @return {Dependencies}
|
|
221
247
|
*/
|
|
222
248
|
export const getPeerDependencies = ({ peerDependencies } = {}) => peerDependencies
|
|
223
249
|
|
|
@@ -226,9 +252,9 @@ export const getPeerDependencies = ({ peerDependencies } = {}) => peerDependenci
|
|
|
226
252
|
*
|
|
227
253
|
* Get the ignore flag by destructuring the package or configuration
|
|
228
254
|
*
|
|
229
|
-
* @param {
|
|
255
|
+
* @param {Package|Configuration}
|
|
230
256
|
*
|
|
231
|
-
* @return {
|
|
257
|
+
* @return {boolean}
|
|
232
258
|
*/
|
|
233
259
|
export const getIgnore = ({ ignore = false } = {}) => ignore === true
|
|
234
260
|
|
|
@@ -237,20 +263,23 @@ export const getIgnore = ({ ignore = false } = {}) => ignore === true
|
|
|
237
263
|
*
|
|
238
264
|
* Get the author by destructuring the package or configuration
|
|
239
265
|
*
|
|
240
|
-
* @param {
|
|
266
|
+
* @param {Package|Configuration}
|
|
241
267
|
*
|
|
242
|
-
* @return {
|
|
268
|
+
* @return {string|null}
|
|
243
269
|
*/
|
|
244
|
-
export const getAuthor = ({ author } = {}) => {
|
|
270
|
+
export const getAuthor = ({ author = '' } = {}) => {
|
|
245
271
|
if ((author || false) instanceof Object) {
|
|
246
272
|
const {
|
|
247
|
-
name = '',
|
|
248
|
-
email = ''
|
|
273
|
+
name: NAME = '',
|
|
274
|
+
email: EMAIL = ''
|
|
249
275
|
} = author
|
|
250
276
|
|
|
277
|
+
const name = String(NAME).trim()
|
|
278
|
+
const email = String(EMAIL).trim()
|
|
279
|
+
|
|
251
280
|
return (
|
|
252
281
|
name && email
|
|
253
|
-
? `${name} <${email}
|
|
282
|
+
? `${name} <${email}>`
|
|
254
283
|
: null
|
|
255
284
|
)
|
|
256
285
|
}
|
|
@@ -263,9 +292,9 @@ export const getAuthor = ({ author } = {}) => {
|
|
|
263
292
|
*
|
|
264
293
|
* Determine whether the dependency is a pre-release with a Regular Expression
|
|
265
294
|
*
|
|
266
|
-
* @param {
|
|
295
|
+
* @param {string} v
|
|
267
296
|
*
|
|
268
|
-
* @return {
|
|
297
|
+
* @return {boolean}
|
|
269
298
|
*/
|
|
270
299
|
export const isPreRelease = (v) => /-/.test(v)
|
|
271
300
|
|
|
@@ -274,9 +303,9 @@ export const isPreRelease = (v) => /-/.test(v)
|
|
|
274
303
|
*
|
|
275
304
|
* Determine whether the dependency is exact with a Regular Expression
|
|
276
305
|
*
|
|
277
|
-
* @param {
|
|
306
|
+
* @param {string} v
|
|
278
307
|
*
|
|
279
|
-
* @return {
|
|
308
|
+
* @return {boolean}
|
|
280
309
|
*/
|
|
281
310
|
export const isExact = (v) => /^\d/.test(v)
|
|
282
311
|
|
|
@@ -285,19 +314,19 @@ export const isExact = (v) => /^\d/.test(v)
|
|
|
285
314
|
*
|
|
286
315
|
* Get an array of dependencies to be installed with the `--save-exact` parameter
|
|
287
316
|
*
|
|
288
|
-
* @param {
|
|
289
|
-
* @param {
|
|
317
|
+
* @param {Dependencies} packageDependencies - Package dependencies
|
|
318
|
+
* @param {Dependencies} configurationDependencies - Configuration dependencies
|
|
290
319
|
*
|
|
291
|
-
* @return {
|
|
320
|
+
* @return {DependencyDescriptor[]}
|
|
292
321
|
*/
|
|
293
|
-
export function getDepsExact (
|
|
322
|
+
export function getDepsExact (packageDependencies, configurationDependencies) {
|
|
294
323
|
log('getDepsExact')
|
|
295
324
|
|
|
296
325
|
return (
|
|
297
|
-
Object.entries(
|
|
326
|
+
Object.entries(packageDependencies)
|
|
298
327
|
.reduce((accumulator, [name, version]) => (
|
|
299
328
|
isExact(version)
|
|
300
|
-
? accumulator.concat({ name, version: Reflect.has(
|
|
329
|
+
? accumulator.concat({ name, version: Reflect.has(configurationDependencies, name) ? Reflect.get(configurationDependencies, name) : version })
|
|
301
330
|
: accumulator
|
|
302
331
|
), [])
|
|
303
332
|
)
|
|
@@ -308,15 +337,15 @@ export function getDepsExact (values, configuration) {
|
|
|
308
337
|
*
|
|
309
338
|
* Get an array of dependencies to be installed
|
|
310
339
|
*
|
|
311
|
-
* @param {
|
|
340
|
+
* @param {Dependencies} packageDependencies - Package dependencies
|
|
312
341
|
*
|
|
313
|
-
* @return {
|
|
342
|
+
* @return {DependencyDescriptor[]}
|
|
314
343
|
*/
|
|
315
|
-
export function getDeps (
|
|
344
|
+
export function getDeps (packageDependencies) {
|
|
316
345
|
log('getDeps')
|
|
317
346
|
|
|
318
347
|
return (
|
|
319
|
-
Object.entries(
|
|
348
|
+
Object.entries(packageDependencies)
|
|
320
349
|
.reduce((accumulator, [name, version]) => (
|
|
321
350
|
isExact(version)
|
|
322
351
|
? accumulator
|
|
@@ -332,17 +361,19 @@ export function getDeps (values) {
|
|
|
332
361
|
*
|
|
333
362
|
* Normalise the commands string
|
|
334
363
|
*
|
|
335
|
-
* @param {
|
|
364
|
+
* @param {string} value
|
|
336
365
|
*
|
|
337
|
-
* @return {
|
|
366
|
+
* @return {string}
|
|
338
367
|
*/
|
|
339
|
-
export function normalizeCommands (
|
|
340
|
-
|
|
341
|
-
|
|
368
|
+
export function normalizeCommands (commands) {
|
|
369
|
+
const s = String.fromCharCode(32)
|
|
370
|
+
|
|
371
|
+
while (/\s{2,}|\n+/.test(commands)) {
|
|
372
|
+
commands = commands.replace(/\s{2,}/gm, s).replace(/\n+/gm, s)
|
|
342
373
|
}
|
|
343
374
|
|
|
344
375
|
return (
|
|
345
|
-
|
|
376
|
+
commands.trim()
|
|
346
377
|
)
|
|
347
378
|
}
|
|
348
379
|
|
|
@@ -351,9 +382,9 @@ export function normalizeCommands (value) {
|
|
|
351
382
|
*
|
|
352
383
|
* Transform by destructuring the value
|
|
353
384
|
*
|
|
354
|
-
* @param {
|
|
385
|
+
* @param {DependencyDescriptor}
|
|
355
386
|
*
|
|
356
|
-
* @return {
|
|
387
|
+
* @return {string}
|
|
357
388
|
*/
|
|
358
389
|
export const transformDependency = ({ name = '@modernpoacher/deps', version = 'latest' } = {}) => `${name}@${version}`
|
|
359
390
|
|
|
@@ -362,9 +393,9 @@ export const transformDependency = ({ name = '@modernpoacher/deps', version = 'l
|
|
|
362
393
|
*
|
|
363
394
|
* Transform the parameter to a string
|
|
364
395
|
*
|
|
365
|
-
* @param {
|
|
396
|
+
* @param {DependencyDescriptor|DependencyDescriptor[]} value
|
|
366
397
|
*
|
|
367
|
-
* @return {
|
|
398
|
+
* @return {string}
|
|
368
399
|
*/
|
|
369
400
|
export function transform (value) {
|
|
370
401
|
log('transform')
|