@modernpoacher/deps 2.2.18 → 2.2.20

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.
@@ -1,50 +1,18 @@
1
1
  /**
2
- * Package or configuration dependencies
3
- *
4
- * @typedef {Record<string, string>} Dependencies
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
2
+ * @typedef {DepsTypes.Dependencies} Dependencies
3
+ * @typedef {DepsTypes.DependencyDescriptor} DependencyDescriptor
4
+ * @typedef {DepsTypes.Package} Package
5
+ * @typedef {DepsTypes.Configuration} Configuration
25
6
  */
26
7
 
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
38
- */
39
-
40
- import debug from 'debug'
41
-
42
- import PATH from '#where-am-i'
43
-
44
8
  import {
45
9
  join
46
10
  } from 'node:path'
47
11
 
12
+ import PATH from '#where-am-i'
13
+
14
+ import debug from '#deps/src/common/debug'
15
+
48
16
  import {
49
17
  VERSION,
50
18
  PLATFORM
@@ -62,35 +30,49 @@ const log = debug('@modernpoacher/deps')
62
30
 
63
31
  log(`\`common\` (${VERSION} - ${PLATFORM}) is awake`)
64
32
 
65
- export const tidy = (v) => v.replace(/\n{2,}}/gm, String.fromCharCode(10)).trim()
33
+ const LF = String.fromCharCode(10)
34
+ const SP = String.fromCharCode(32)
66
35
 
67
- export const trim = (v) => v.split(String.fromCharCode(10)).map((v) => v.trimEnd()).join(String.fromCharCode(10)).trim()
36
+ /**
37
+ * @param {string} v
38
+ * @returns {string}
39
+ */
40
+ export const tidy = (v) => v.replace(/\n{2,}}/gm, LF).trim()
41
+
42
+ /**
43
+ * @param {string} v
44
+ * @returns {string}
45
+ */
46
+ export const trimEnd = (v) => v.trimEnd()
47
+
48
+ /**
49
+ * @param {string} v
50
+ * @returns {string}
51
+ */
52
+ export const trim = (v) => v.split(LF).map(trimEnd).join(LF).trim()
68
53
 
69
54
  /**
70
55
  * @function getSaveProdParameter
71
- *
56
+ * @description
72
57
  * Get the `--save-prod` parameter
73
- *
74
- * @param {string} current commands string
58
+ * @param {string} commands commands string
75
59
  * @returns {string}
76
60
  */
77
61
  export const getSaveProdParameter = (commands) => commands.concat(' --save-prod')
78
62
 
79
63
  /**
80
64
  * @function getSaveDevParameter
81
- *
65
+ * @description
82
66
  * Get the `--save-dev` parameter
83
- *
84
- * @param {string} current commands string
67
+ * @param {string} commands commands string
85
68
  * @returns {string}
86
69
  */
87
70
  export const getSaveDevParameter = (commands) => commands.concat(' --save-dev')
88
71
 
89
72
  /**
90
73
  * @function getSaveBundleParameter
91
- *
74
+ * @description
92
75
  * Get the "save bundle" parameter
93
- *
94
76
  * @param {string} commands - Current commands string
95
77
  * @returns {string}
96
78
  */
@@ -98,9 +80,8 @@ export const getSaveBundleParameter = (commands) => commands.concat(' --save-bun
98
80
 
99
81
  /**
100
82
  * @function getSaveOptionalParameter
101
- *
83
+ * @description
102
84
  * Get the `--save-optional` parameter
103
- *
104
85
  * @param {string} commands - Current commands string
105
86
  * @returns {string}
106
87
  */
@@ -108,9 +89,8 @@ export const getSaveOptionalParameter = (commands) => commands.concat(' --save-o
108
89
 
109
90
  /**
110
91
  * @function getRegistryParameter
111
- *
92
+ * @description
112
93
  * Get the "registry" parameter and argument
113
- *
114
94
  * @param {string} r - Registry
115
95
  * @param {string} commands - Current commands string
116
96
  * @returns {string}
@@ -119,9 +99,8 @@ export const getRegistryParameter = (r, commands) => r ? commands.concat(` --reg
119
99
 
120
100
  /**
121
101
  * @function getForceParameter
122
- *
102
+ * @description
123
103
  * Get the "force" parameter and argument
124
- *
125
104
  * @param {boolean} f - Force
126
105
  * @param {string} commands - Current commands string
127
106
  * @returns {string}
@@ -130,9 +109,8 @@ export const getForceParameter = (f, commands) => f ? commands.concat(' --force'
130
109
 
131
110
  /**
132
111
  * @function getNoSaveParameter
133
- *
112
+ * @description
134
113
  * Get the `--no-save` parameter
135
- *
136
114
  * @param {boolean} s - Save
137
115
  * @param {string} commands - Current commands string
138
116
  * @returns {string}
@@ -141,9 +119,8 @@ export const getNoSaveParameter = (s, commands) => s ? commands : commands.conca
141
119
 
142
120
  /**
143
121
  * @function getSaveExactParameter
144
- *
122
+ * @description
145
123
  * Get the `--save-exact` parameter
146
- *
147
124
  * @param {string} commands - Current commands string
148
125
  * @returns {string}
149
126
  */
@@ -151,9 +128,8 @@ export const getSaveExactParameter = (commands) => commands.concat(' --save-exac
151
128
 
152
129
  /**
153
130
  * @function getExportPath
154
- *
131
+ * @description
155
132
  * Get the export PATH shell script
156
- *
157
133
  * @param {string} commands - Current commands string
158
134
  * @returns {string}
159
135
  */
@@ -164,9 +140,8 @@ ${commands}
164
140
 
165
141
  /**
166
142
  * @function getNvm
167
- *
143
+ * @description
168
144
  * Get the NVM shell script
169
- *
170
145
  * @param {string} commands - Current commands string
171
146
  * @returns {string}
172
147
  */
@@ -177,9 +152,8 @@ ${commands}
177
152
 
178
153
  /**
179
154
  * @function getCommands
180
- *
155
+ * @description
181
156
  * Get the installation shell script
182
- *
183
157
  * @param {string} commands - Current commands string
184
158
  * @returns {string}
185
159
  */
@@ -189,74 +163,68 @@ export const getCommands = PLATFORM === 'win32'
189
163
 
190
164
  /**
191
165
  * @function getProdDependencies
192
- *
166
+ * @description
193
167
  * Get the production dependencies by destructuring the package or configuration
194
- *
195
- * @param {Package|Configuration}
168
+ * @param {Package | Configuration} deps
196
169
  * @returns {Dependencies}
197
170
  */
198
171
  export const getProdDependencies = ({ dependencies = {} } = {}) => dependencies
199
172
 
200
173
  /**
201
174
  * @function getDevDependencies
202
- *
175
+ * @description
203
176
  * Get the development dependencies by destructuring the package or configuration
204
- *
205
- * @param {Package|Configuration}
177
+ * @param {Package | Configuration} deps
206
178
  * @returns {Dependencies}
207
179
  */
208
180
  export const getDevDependencies = ({ devDependencies = {} } = {}) => devDependencies
209
181
 
210
182
  /**
211
183
  * @function getOptionalDependencies
212
- *
184
+ * @description
213
185
  * Get the optional dependencies by destructuring the package or configuration
214
- *
215
- * @param {Package|Configuration}
186
+ * @param {Package | Configuration} deps
216
187
  * @returns {Dependencies}
217
188
  */
218
189
  export const getOptionalDependencies = ({ optionalDependencies = {} } = {}) => optionalDependencies
219
190
 
220
191
  /**
221
192
  * @function getBundleDependencies
222
- *
193
+ * @description
223
194
  * Get the bundle dependencies by destructuring the package or configuration
224
- *
225
- * @param {Package|Configuration}
195
+ * @param {Package | Configuration} deps
226
196
  * @returns {Dependencies}
227
197
  */
228
198
  export const getBundleDependencies = ({ bundleDependencies = {} } = {}) => bundleDependencies
229
199
 
230
200
  /**
231
201
  * @function getPeerDependencies
232
- *
202
+ * @description
233
203
  * Get the peer dependencies by destructuring the package or configuration
234
- *
235
- * @param {Package|Configuration}
204
+ * @param {Package | Configuration} deps
236
205
  * @returns {Dependencies}
237
206
  */
238
- export const getPeerDependencies = ({ peerDependencies } = {}) => peerDependencies
207
+ export const getPeerDependencies = ({ peerDependencies = {} } = {}) => peerDependencies
239
208
 
240
209
  /**
241
210
  * @function getIgnore
242
- *
211
+ * @description
243
212
  * Get the ignore flag by destructuring the configuration
244
- *
245
- * @param {Configuration}
213
+ * @param {Configuration} deps
246
214
  * @returns {boolean}
247
215
  */
248
216
  export const getIgnore = ({ ignore = false } = {}) => ignore === true
249
217
 
250
218
  /**
251
219
  * @function getAuthor
252
- *
220
+ * @description
253
221
  * Get the author by destructuring the package or configuration
254
- *
255
- * @param {Package|Configuration}
256
- * @returns {string|null}
222
+ * @param {Package | Configuration} deps
223
+ * @returns {string | null}
257
224
  */
258
225
  export const getAuthor = ({ author = '' } = {}) => {
259
- if ((author || false) instanceof Object) {
226
+ if (typeof author === 'string') return author
227
+ if (typeof (author || false) === 'object') {
260
228
  const {
261
229
  name: NAME = '',
262
230
  email: EMAIL = ''
@@ -272,24 +240,22 @@ export const getAuthor = ({ author = '' } = {}) => {
272
240
  )
273
241
  }
274
242
 
275
- return author || null
243
+ return null
276
244
  }
277
245
 
278
246
  /**
279
247
  * @function getMessage
280
- *
248
+ * @description
281
249
  * Get the message by destructuring the configuration
282
- *
283
- * @param {Configuration}
284
- * @returns {string|null}
250
+ * @param {Configuration} deps
251
+ * @returns {string | null}
285
252
  */
286
253
  export const getMessage = ({ message = '' } = {}) => message || null
287
254
 
288
255
  /**
289
256
  * @function isPreRelease
290
- *
257
+ * @description
291
258
  * Determine whether the dependency is a pre-release with a Regular Expression
292
- *
293
259
  * @param {string} v
294
260
  * @returns {boolean}
295
261
  */
@@ -297,9 +263,8 @@ export const isPreRelease = (v) => /-/.test(v)
297
263
 
298
264
  /**
299
265
  * @function isExact
300
- *
266
+ * @description
301
267
  * Determine whether the dependency is exact with a Regular Expression
302
- *
303
268
  * @param {string} v
304
269
  * @returns {boolean}
305
270
  */
@@ -323,7 +288,7 @@ function excludeVersionIsExact ([name, version]) {
323
288
 
324
289
  /**
325
290
  * @function getMapToDepsExactVersionFromConfiguration
326
- *
291
+ * @description
327
292
  * Produces an array of objects from the entries of `packageDependencies` which have
328
293
  * exact versions
329
294
  *
@@ -331,7 +296,6 @@ function excludeVersionIsExact ([name, version]) {
331
296
  *
332
297
  * Each entry is mapped to the same package name in `configurationDependencies` if it
333
298
  * appears there. Otherwise, the `packageDependencies` version is used
334
- *
335
299
  * @param {Record<string, string>} configurationDependencies
336
300
  * @returns {(entry: [name: string, version: string]) => {
337
301
  * name: string,
@@ -365,13 +329,12 @@ function getMapToDepsExactVersionFromConfiguration (configurationDependencies) {
365
329
 
366
330
  /**
367
331
  * @function mapToDepsVersion
368
- *
332
+ * @description
369
333
  * Produces an array of objects from the entries of `packageDependencies` which do not have
370
334
  * exact versions
371
335
  *
372
336
  * Where the version is a pre-release, that version is used. Otherwise the version is
373
337
  * set to `latest` to ensure that package is updated
374
- *
375
338
  * @param {[name: string, version: string]} entry
376
339
  * @returns {{
377
340
  * name: string,
@@ -399,9 +362,8 @@ function mapToDepsVersion (entry) {
399
362
 
400
363
  /**
401
364
  * @function getDepsExact
402
- *
365
+ * @description
403
366
  * Get an array of dependencies to be installed with the `--save-exact` parameter
404
- *
405
367
  * @param {Dependencies} packageDependencies - Package dependencies
406
368
  * @param {Dependencies} configurationDependencies - Configuration dependencies
407
369
  * @returns {DependencyDescriptor[]}
@@ -418,9 +380,8 @@ export function getDepsExact (packageDependencies, configurationDependencies) {
418
380
 
419
381
  /**
420
382
  * @function getDeps
421
- *
383
+ * @description
422
384
  * Get an array of dependencies to be installed
423
- *
424
385
  * @param {Dependencies} packageDependencies - Package dependencies
425
386
  * @returns {DependencyDescriptor[]}
426
387
  */
@@ -436,40 +397,37 @@ export function getDeps (packageDependencies) {
436
397
 
437
398
  /**
438
399
  * @function normalizeCommands
439
- *
400
+ * @description
440
401
  * Normalise the commands string
441
- *
442
- * @param {string} value
402
+ * @param {string} commands
443
403
  * @returns {string}
444
404
  */
445
405
  export function normalizeCommands (commands) {
446
- const s = String.fromCharCode(32)
406
+ let c = commands
447
407
 
448
- while (/\s{2,}|\n+/.test(commands)) {
449
- commands = commands.replace(/\s{2,}/gm, s).replace(/\n+/gm, s)
408
+ while (/\s{2,} | \n+/.test(c)) {
409
+ c = c.replace(/\s{2,}/gm, SP).replace(/\n+/gm, SP)
450
410
  }
451
411
 
452
412
  return (
453
- commands.trim()
413
+ c.trim()
454
414
  )
455
415
  }
456
416
 
457
417
  /**
458
418
  * @function transformDependency
459
- *
419
+ * @description
460
420
  * Transform by destructuring the value
461
- *
462
- * @param {DependencyDescriptor}
421
+ * @param {DependencyDescriptor | { name?: string, version?: string }} dependencyDescriptor
463
422
  * @returns {string}
464
423
  */
465
424
  export const transformDependency = ({ name = '@modernpoacher/deps', version = 'latest' } = {}) => `${name}@${version}`
466
425
 
467
426
  /**
468
427
  * @function transform
469
- *
428
+ * @description
470
429
  * Transform the parameter to a string
471
- *
472
- * @param {DependencyDescriptor|DependencyDescriptor[]} value
430
+ * @param {DependencyDescriptor | DependencyDescriptor[]} value
473
431
  * @returns {string}
474
432
  */
475
433
  export function transform (value) {
@@ -477,7 +435,7 @@ export function transform (value) {
477
435
 
478
436
  return (
479
437
  Array.isArray(value)
480
- ? value.map(transformDependency).join(String.fromCharCode(32)).trim()
438
+ ? value.map(transformDependency).join(SP).trim()
481
439
  : transformDependency(value)
482
440
  )
483
441
  }
@@ -1,4 +1,8 @@
1
- import debug from 'debug'
1
+ /**
2
+ * @typedef {DepsTypes.Options} Options
3
+ */
4
+
5
+ import debug from '#deps/src/common/debug'
2
6
 
3
7
  import {
4
8
  VERSION,
@@ -14,14 +18,17 @@ const {
14
18
  }
15
19
  } = process
16
20
 
21
+ /**
22
+ * @type {Options}
23
+ */
17
24
  export const OPTIONS = {
18
25
  maxBuffer: 1024 * 2000,
19
26
  stdio: 'inherit',
20
27
  env: {
21
28
  DEBUG_COLORS: 'yes',
22
29
  FORCE_COLOR: PLATFORM === 'win32'
23
- ? 3
24
- : 2,
30
+ ? '3'
31
+ : '2',
25
32
  NODE_OPTIONS,
26
33
  SSH_AUTH_SOCK,
27
34
  HOME,
@@ -35,23 +42,10 @@ log(`\`common/options\` (${VERSION} - ${PLATFORM}) is awake`)
35
42
 
36
43
  /**
37
44
  * @function getOptions
38
- *
39
- * Get the installation `exec` child process options
40
- *
41
- * @param {string} cwd normalized directory
42
- * @returns {{
43
- * maxBuffer: number,
44
- * stdio: string
45
- * env: {
46
- * DEBUG_COLORS: string,
47
- * FORCE_COLOR: number,
48
- * NODE_OPTIONS: string,
49
- * SSH_AUTH_SOCK?: string,
50
- * HOME?: string,
51
- * PATH?: string
52
- * }
53
- * cwd: string
54
- * }}
45
+ * @description
46
+ * `exec` shell options
47
+ * @param {string} [cwd] normalized directory
48
+ * @returns {Options & { cwd?: string }}
55
49
  */
56
50
  export function getOptions (cwd) {
57
51
  log('getOptions')