@modernpoacher/deps 2.2.17 → 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.
@@ -56,10 +56,14 @@ import {
56
56
  } from '#deps/bin/common'
57
57
 
58
58
  const log = debug('@modernpoacher/deps')
59
+ const info = debug('@modernpoacher/deps:info')
59
60
 
60
61
  log(`\`execute\` (${VERSION} - ${PLATFORM}) is awake`)
61
62
 
62
- function handleCommandError (e) {
63
+ /**
64
+ * @param {{ code?: number, message?: string }} [e]
65
+ */
66
+ function handleCommandError (e = {}) {
63
67
  const {
64
68
  code = 0
65
69
  } = e
@@ -67,6 +71,10 @@ function handleCommandError (e) {
67
71
  if (code !== 128) handleError(e)
68
72
  }
69
73
 
74
+ /**
75
+ * @param {string} directory
76
+ * @returns {Promise<string>}
77
+ */
70
78
  async function getDefaultBranch (directory) {
71
79
  const branch = await catGitRefsRemotesOriginHead(directory)
72
80
  if (branch) return branch
@@ -75,12 +83,20 @@ async function getDefaultBranch (directory) {
75
83
  )
76
84
  }
77
85
 
86
+ /**
87
+ * @param {string} directory
88
+ * @returns {Promise<string>}
89
+ */
78
90
  async function getCurrentBranch (directory) {
79
91
  return (
80
92
  await gitRevParseAbbrevRefHead(directory)
81
93
  )
82
94
  }
83
95
 
96
+ /**
97
+ * @param {string} directory
98
+ * @returns {Promise<boolean>}
99
+ */
84
100
  async function isHeadDefaultBranch (directory) {
85
101
  const defaultBranch = await getDefaultBranch(directory)
86
102
  const currentBranch = await getCurrentBranch(directory)
@@ -117,7 +133,7 @@ async function getIgnoreFromConfiguration (directory) {
117
133
  * Interrogates `.depsrc` or `.depsrc.json` for an `author` value
118
134
  *
119
135
  * @param {string} directory
120
- * @returns {Promise<string|null>}
136
+ * @returns {Promise<string | null>}
121
137
  */
122
138
  async function getAuthorFromConfiguration (directory) {
123
139
  log('getAuthorFromConfiguration')
@@ -139,7 +155,7 @@ async function getAuthorFromConfiguration (directory) {
139
155
  * Interrogates `package.json` for an `author` value
140
156
  *
141
157
  * @param {string} directory
142
- * @returns {Promise<string|null>}
158
+ * @returns {Promise<string | null>}
143
159
  */
144
160
  async function getAuthorFromPackage (directory) {
145
161
  log('getAuthorFromPackage')
@@ -161,7 +177,7 @@ async function getAuthorFromPackage (directory) {
161
177
  * Interrogates `.depsrc` or `.depsrc.json` for a `message` value
162
178
  *
163
179
  * @param {string} directory
164
- * @returns {Promise<string|null>}
180
+ * @returns {Promise<string | null>}
165
181
  */
166
182
  async function getMessageFromConfiguration (directory) {
167
183
  log('getMessageFromConfiguration')
@@ -185,9 +201,9 @@ async function getMessageFromConfiguration (directory) {
185
201
  *
186
202
  * Since it can be null `author` may not default in function arguments
187
203
  *
188
- * @param {string|null} author
204
+ * @param {string | { name: string; email: string }} author
189
205
  * @param {string} directory
190
- * @returns {Promise<string>}
206
+ * @returns {Promise<string | { name: string; email: string }>}
191
207
  */
192
208
  async function toAuthor (author, directory) {
193
209
  return author || await getAuthorFromConfiguration(directory) || await getAuthorFromPackage(directory) || AUTHOR
@@ -201,7 +217,7 @@ async function toAuthor (author, directory) {
201
217
  *
202
218
  * Since it can be null `message` may not default in function arguments
203
219
  *
204
- * @param {string|null} message
220
+ * @param {string | null} message
205
221
  * @param {string} directory
206
222
  * @returns {Promise<string>}
207
223
  */
@@ -209,14 +225,30 @@ async function toMessage (message, directory) {
209
225
  return message || await getMessageFromConfiguration(directory) || MESSAGE
210
226
  }
211
227
 
212
- const filterDeps = (v) => !!v // de-falsy
228
+ /**
229
+ * @param {string | undefined} v
230
+ * @returns {boolean}
231
+ */
232
+ const filterDeps = (v) => Boolean(v) // de-falsy
213
233
 
214
- const reduceDeps = (a, v) => a.includes(v) ? a : a.concat(v) // de-dupe
234
+ /**
235
+ * @param {string[]} a
236
+ * @param {string} v
237
+ * @returns {string[]}
238
+ */
239
+ const reduceDeps = (a, v = '') => a.includes(v) ? a : a.concat(v) // de-dupe
215
240
 
241
+ /**
242
+ * @param {string[]} directories
243
+ */
216
244
  function * genDirsList (directories = []) {
217
245
  while (directories.length) yield directories.shift()
218
246
  }
219
247
 
248
+ /**
249
+ * @param {string} directory
250
+ * @returns {Promise<string[]>}
251
+ */
220
252
  async function getPathList (directory) {
221
253
  log('getPathList')
222
254
 
@@ -229,9 +261,16 @@ async function getPathList (directory) {
229
261
  )
230
262
  }
231
263
 
264
+ /**
265
+ * @param {Array<string | undefined>} [directories]
266
+ * @returns {Promise<string[]>}
267
+ */
232
268
  async function getDepsList (directories = []) {
233
269
  log('getDepsList')
234
270
 
271
+ /**
272
+ * Transform `directories` to create `alpha`
273
+ */
235
274
  const alpha = (
236
275
  directories
237
276
  .filter(filterDeps)
@@ -240,19 +279,40 @@ async function getDepsList (directories = []) {
240
279
  )
241
280
 
242
281
  try {
243
- const omega = await Promise.all(alpha.map(mapRevParseShowTopLevel))
282
+ /**
283
+ * Recreate `directories` from `alpha`
284
+ *
285
+ * @type {Array<string | undefined>}
286
+ */
287
+ const directories = (
288
+ await Promise.all(
289
+ alpha
290
+ .map(mapRevParseShowTopLevel)
291
+ )
292
+ )
244
293
 
245
- return (
246
- omega
294
+ /**
295
+ * Transform `directories` to create `omega`
296
+ */
297
+ const omega = (
298
+ directories
247
299
  .filter(filterDeps)
248
300
  .reduce(reduceDeps, [])
249
301
  .sort()
250
302
  )
303
+
304
+ return omega
251
305
  } catch (e) {
252
- handleError(e)
306
+ if (e instanceof Error) handleError(e)
253
307
  }
308
+
309
+ return []
254
310
  }
255
311
 
312
+ /**
313
+ * @param {string} directory
314
+ * @returns {Promise<string | undefined>}
315
+ */
256
316
  async function mapRevParseShowTopLevel (directory) {
257
317
  log('mapRevParseShowTopLevel')
258
318
 
@@ -261,10 +321,17 @@ async function mapRevParseShowTopLevel (directory) {
261
321
  await gitRevParseShowTopLevel(directory)
262
322
  )
263
323
  } catch (e) {
264
- handleCommandError(e)
324
+ if (e instanceof Error) handleCommandError(e)
265
325
  }
266
326
  }
267
327
 
328
+ /**
329
+ * @param {string} directory
330
+ * @param {string} registry
331
+ * @param {boolean} force
332
+ * @param {string} message
333
+ * @param {string | { name: string; email: string }} author
334
+ */
268
335
  async function iterate (directory, registry, force, message, author) {
269
336
  log('iterate')
270
337
 
@@ -282,11 +349,18 @@ async function iterate (directory, registry, force, message, author) {
282
349
  }
283
350
  }
284
351
  } catch (e) {
285
- handleCommandError(e)
352
+ if (e instanceof Error) handleCommandError(e)
286
353
  }
287
354
  }
288
355
  }
289
356
 
357
+ /**
358
+ * @param {string} directory
359
+ * @param {string} registry
360
+ * @param {boolean} force
361
+ * @param {string} message
362
+ * @param {string | { name: string; email: string }} author
363
+ */
290
364
  async function iteratePath (directory, registry, force, message, author) {
291
365
  log('iteratePath')
292
366
 
@@ -299,17 +373,28 @@ async function iteratePath (directory, registry, force, message, author) {
299
373
  const depsList = await getDepsList(pathList)
300
374
 
301
375
  if (depsList.length) {
302
- for (const d of genDirsList(depsList)) await iterate(d, registry, force, message, author)
376
+ for (const d of genDirsList(depsList)) if (d) await iterate(d, registry, force, message, author)
303
377
  }
304
378
  }
305
379
  }
306
380
  }
307
381
 
382
+ /**
383
+ * @param {string} directory
384
+ * @param {string} registry
385
+ * @param {boolean} force
386
+ * @param {string} message
387
+ * @param {string | { name: string; email: string }} author
388
+ */
308
389
  async function execute (directory = DIRECTORY, registry = REGISTRY, force = false, message = MESSAGE, author = AUTHOR) {
309
390
  log('execute')
310
391
 
311
392
  try {
312
- log({ directory, registry, force, message, author })
393
+ info(`Directory is "${directory}"`)
394
+ info(`Registry is "${registry}"`)
395
+ info(`Force is "${force}"`)
396
+ info(`Message is "${message}"`)
397
+ info(`Author is "${author}"`)
313
398
 
314
399
  await gitPull(directory)
315
400
  await rmrf(directory)
@@ -320,10 +405,17 @@ async function execute (directory = DIRECTORY, registry = REGISTRY, force = fals
320
405
  await gitPush(directory)
321
406
  await gitPushTags(directory)
322
407
  } catch (e) {
323
- handleError(e)
408
+ if (e instanceof Error) handleError(e)
324
409
  }
325
410
  }
326
411
 
412
+ /**
413
+ * @param {string} directory
414
+ * @param {string} registry
415
+ * @param {boolean} force
416
+ * @param {string} message
417
+ * @param {string | { name: string; email: string }} author
418
+ */
327
419
  async function executeFrom (directory, registry, force, message, author) {
328
420
  log('executeFrom')
329
421
 
@@ -333,19 +425,28 @@ async function executeFrom (directory, registry, force, message, author) {
333
425
  try {
334
426
  if (D === await gitRevParseShowTopLevel(D)) {
335
427
  const B = await isHeadDefaultBranch(D)
428
+
336
429
  if (B) {
337
430
  const ignore = await getIgnoreFromConfiguration(D)
431
+
338
432
  if (!ignore) {
339
433
  await execute(D, registry, force, await toMessage(message, D), await toAuthor(author, D))
340
434
  }
341
435
  }
342
436
  }
343
437
  } catch (e) {
344
- handleCommandError(e)
438
+ if (e instanceof Error) handleCommandError(e)
345
439
  }
346
440
  }
347
441
  }
348
442
 
443
+ /**
444
+ * @param {string} directory
445
+ * @param {string} registry
446
+ * @param {boolean} force
447
+ * @param {string} message
448
+ * @param {string | { name: string; email: string }} author
449
+ */
349
450
  async function executeOnly (directory, registry, force, message, author) {
350
451
  log('executeOnly')
351
452
 
@@ -355,19 +456,28 @@ async function executeOnly (directory, registry, force, message, author) {
355
456
  try {
356
457
  if (D === await gitRevParseShowTopLevel(D)) {
357
458
  const B = await isHeadDefaultBranch(D)
459
+
358
460
  if (B) {
359
461
  const ignore = await getIgnoreFromConfiguration(D)
462
+
360
463
  if (!ignore) {
361
464
  await execute(D, registry, force, await toMessage(message, D), await toAuthor(author, D))
362
465
  }
363
466
  }
364
467
  }
365
468
  } catch (e) {
366
- handleCommandError(e)
469
+ if (e instanceof Error) handleCommandError(e)
367
470
  }
368
471
  }
369
472
  }
370
473
 
474
+ /**
475
+ * @param {string} directory
476
+ * @param {string} registry
477
+ * @param {boolean} force
478
+ * @param {string} message
479
+ * @param {string | { name: string; email: string }} author
480
+ */
371
481
  async function executePath (directory, registry, force, message, author) {
372
482
  log('executePath')
373
483
 
@@ -377,15 +487,17 @@ async function executePath (directory, registry, force, message, author) {
377
487
  try {
378
488
  if (D === await gitRevParseShowTopLevel(D)) {
379
489
  const B = await isHeadDefaultBranch(D)
490
+
380
491
  if (B) {
381
492
  const ignore = await getIgnoreFromConfiguration(D)
493
+
382
494
  if (!ignore) {
383
495
  await execute(D, registry, force, await toMessage(message, D), await toAuthor(author, D))
384
496
  }
385
497
  }
386
498
  }
387
499
  } catch (e) {
388
- const {
500
+ const { // @ts-expect-error
389
501
  code
390
502
  } = e
391
503
 
@@ -395,7 +507,7 @@ async function executePath (directory, registry, force, message, author) {
395
507
  )
396
508
  }
397
509
 
398
- handleCommandError(e)
510
+ if (e instanceof Error) handleCommandError(e)
399
511
  }
400
512
  }
401
513
  }
@@ -449,7 +561,7 @@ async function app () {
449
561
  try {
450
562
  await executePath(P, registry, force, message, author)
451
563
  } catch (e) {
452
- handleError(e)
564
+ if (e instanceof Error) handleError(e)
453
565
  }
454
566
  } else {
455
567
  if (F) {
@@ -458,7 +570,7 @@ async function app () {
458
570
  try {
459
571
  await executeFrom(P, registry, force, message, author)
460
572
  } catch (e) {
461
- handleError(e)
573
+ if (e instanceof Error) handleError(e)
462
574
  }
463
575
  } else {
464
576
  if (O) {
@@ -467,7 +579,7 @@ async function app () {
467
579
  try {
468
580
  await executeOnly(P, registry, force, message, author)
469
581
  } catch (e) {
470
- handleError(e)
582
+ if (e instanceof Error) handleError(e)
471
583
  }
472
584
  }
473
585
  }
package/bin/node/head.mjs CHANGED
@@ -4,39 +4,23 @@ import {
4
4
  exec
5
5
  } from 'node:child_process'
6
6
 
7
- import {
8
- join
9
- } from 'node:path'
10
-
11
7
  import '#deps/src/common/debug'
12
8
 
13
- import {
14
- PLATFORM,
15
- BIN
16
- } from '#deps/src/common/env'
17
-
18
9
  import {
19
10
  getOptions
20
11
  } from '#deps/src/common/options'
21
12
 
22
13
  import {
23
- getArgs,
14
+ HEAD,
15
+ ARGS,
24
16
  use,
25
17
  handleComplete
26
18
  } from '#deps/bin/common'
27
19
 
28
- const command = (
29
- PLATFORM === 'win32'
30
- ? `bash "${join(BIN, '.\\bash\\head.sh')}"`
31
- : `bash '${join(BIN, './bash/head.sh')}'`
32
- )
33
-
34
- const args = getArgs()
35
-
36
20
  const {
37
21
  stdout,
38
22
  stderr
39
- } = exec(`${command} ${args}`, getOptions(), handleComplete)
23
+ } = exec(`${HEAD} ${ARGS}`, getOptions(), handleComplete)
40
24
 
41
- stdout.on('data', use('deps-head'))
42
- stderr.on('data', use('deps-head:error'))
25
+ if (stdout) stdout.on('data', use('deps-head'))
26
+ if (stderr) stderr.on('data', use('deps-head:error'))
@@ -115,7 +115,7 @@ async function app () {
115
115
  try {
116
116
  await execute(DEPS_PATH, getProdDependencies(PACKAGE), getProdDependencies(CONFIGURATION), save, registry, force)
117
117
  } catch (e) {
118
- handleError(e)
118
+ if (e instanceof Error) handleError(e)
119
119
  }
120
120
  } else {
121
121
  if (D) {
@@ -124,7 +124,7 @@ async function app () {
124
124
  try {
125
125
  await execute(DEPS_PATH, getDevDependencies(PACKAGE), getDevDependencies(CONFIGURATION), save, registry, force)
126
126
  } catch (e) {
127
- handleError(e)
127
+ if (e instanceof Error) handleError(e)
128
128
  }
129
129
  } else {
130
130
  if (O) {
@@ -133,7 +133,7 @@ async function app () {
133
133
  try {
134
134
  await execute(DEPS_PATH, getOptionalDependencies(PACKAGE), getOptionalDependencies(CONFIGURATION), save, registry, force)
135
135
  } catch (e) {
136
- handleError(e)
136
+ if (e instanceof Error) handleError(e)
137
137
  }
138
138
  } else {
139
139
  if (B) {
@@ -142,7 +142,7 @@ async function app () {
142
142
  try {
143
143
  await execute(DEPS_PATH, getBundleDependencies(PACKAGE), getBundleDependencies(CONFIGURATION), save, registry, force)
144
144
  } catch (e) {
145
- handleError(e)
145
+ if (e instanceof Error) handleError(e)
146
146
  }
147
147
  } else {
148
148
  if (p) {
@@ -151,7 +151,7 @@ async function app () {
151
151
  try {
152
152
  await execute(DEPS_PATH, getPeerDependencies(PACKAGE), getPeerDependencies(CONFIGURATION), save, registry, force)
153
153
  } catch (e) {
154
- handleError(e)
154
+ if (e instanceof Error) handleError(e)
155
155
  }
156
156
  }
157
157
  }
package/bin/node/push.mjs CHANGED
@@ -4,39 +4,23 @@ import {
4
4
  exec
5
5
  } from 'node:child_process'
6
6
 
7
- import {
8
- join
9
- } from 'node:path'
10
-
11
7
  import '#deps/src/common/debug'
12
8
 
13
- import {
14
- PLATFORM,
15
- BIN
16
- } from '#deps/src/common/env'
17
-
18
9
  import {
19
10
  getOptions
20
11
  } from '#deps/src/common/options'
21
12
 
22
13
  import {
23
- getArgs,
14
+ PUSH,
15
+ ARGS,
24
16
  use,
25
17
  handleComplete
26
18
  } from '#deps/bin/common'
27
19
 
28
- const command = (
29
- PLATFORM === 'win32'
30
- ? `bash "${join(BIN, '.\\bash\\push.sh')}"`
31
- : `bash '${join(BIN, './bash/push.sh')}'`
32
- )
33
-
34
- const args = getArgs()
35
-
36
20
  const {
37
21
  stdout,
38
22
  stderr
39
- } = exec(`${command} ${args}`, getOptions(), handleComplete)
23
+ } = exec(`${PUSH} ${ARGS}`, getOptions(), handleComplete)
40
24
 
41
- stdout.on('data', use('deps-push'))
42
- stderr.on('data', use('deps-push:error'))
25
+ if (stdout) stdout.on('data', use('deps-push'))
26
+ if (stderr) stderr.on('data', use('deps-push:error'))
package/bin/node/wipe.mjs CHANGED
@@ -4,39 +4,23 @@ import {
4
4
  exec
5
5
  } from 'node:child_process'
6
6
 
7
- import {
8
- join
9
- } from 'node:path'
10
-
11
- import {
12
- PLATFORM,
13
- BIN
14
- } from '#deps/src/common/env'
7
+ import '#deps/src/common/debug'
15
8
 
16
9
  import {
17
10
  getOptions
18
11
  } from '#deps/src/common/options'
19
12
 
20
- import '#deps/src/common/debug'
21
-
22
13
  import {
23
- getArgs,
14
+ WIPE,
15
+ ARGS,
24
16
  use,
25
17
  handleComplete
26
18
  } from '#deps/bin/common'
27
19
 
28
- const command = (
29
- PLATFORM === 'win32'
30
- ? `bash "${join(BIN, '.\\bash\\wipe.sh')}"`
31
- : `bash '${join(BIN, './bash/wipe.sh')}'`
32
- )
33
-
34
- const args = getArgs()
35
-
36
20
  const {
37
21
  stdout,
38
22
  stderr
39
- } = exec(`${command} ${args}`, getOptions(), handleComplete)
23
+ } = exec(`${WIPE} ${ARGS}`, getOptions(), handleComplete)
40
24
 
41
- stdout.on('data', use('deps-wipe'))
42
- stderr.on('data', use('deps-wipe:error'))
25
+ if (stdout) stdout.on('data', use('deps-wipe'))
26
+ if (stderr) stderr.on('data', use('deps-wipe:error'))
@@ -0,0 +1,86 @@
1
+ import globals from 'globals'
2
+ import standard from '@sequencemedia/eslint-config-standard/configs/recommended/merge'
3
+ import typescript from '@sequencemedia/eslint-config-typescript/configs/recommended/merge'
4
+ import typescriptParser from '@typescript-eslint/parser'
5
+
6
+ export default [
7
+ /**
8
+ * Standard config
9
+ */
10
+ standard({
11
+ files: [
12
+ '**/*.{mjs,cjs,mts,cts}'
13
+ ],
14
+ ignores: [
15
+ 'src',
16
+ 'test'
17
+ ],
18
+ languageOptions: {
19
+ globals: {
20
+ ...globals.node
21
+ }
22
+ }
23
+ }),
24
+ standard({
25
+ files: [
26
+ 'src/**/*.{mjs,cjs,mts,cts}'
27
+ ],
28
+ languageOptions: {
29
+ globals: {
30
+ ...globals.browser
31
+ }
32
+ }
33
+ }),
34
+ standard({
35
+ files: [
36
+ 'test/**/*.{mjs,cjs,mts,cts}'
37
+ ],
38
+ languageOptions: {
39
+ globals: {
40
+ ...globals.mocha
41
+ }
42
+ }
43
+ }),
44
+ /**
45
+ * TypeScript config
46
+ */
47
+ typescript({
48
+ files: [
49
+ '**/*.{mts,cts}'
50
+ ],
51
+ ignores: [
52
+ 'src',
53
+ 'test'
54
+ ],
55
+ languageOptions: {
56
+ parser: typescriptParser,
57
+ parserOptions: {
58
+ projectService: true,
59
+ project: 'tsconfig.json'
60
+ },
61
+ globals: {
62
+ ...globals.node,
63
+ DepsTypes: 'readonly',
64
+ NodeJS: 'readonly'
65
+ }
66
+ }
67
+ }),
68
+ typescript({
69
+ files: [
70
+ 'src/**/*.{mts,cts}',
71
+ 'test/**/*.{mts,cts}'
72
+ ],
73
+ languageOptions: {
74
+ parser: typescriptParser,
75
+ parserOptions: {
76
+ projectService: true,
77
+ project: 'tsconfig.json'
78
+ },
79
+ globals: {
80
+ ...globals.browser,
81
+ DepsTypes: 'readonly',
82
+ NodeJS: 'readonly'
83
+ }
84
+ }
85
+ })
86
+ ]
package/index.d.mts ADDED
@@ -0,0 +1,50 @@
1
+ declare global {
2
+ namespace DepsTypes {
3
+ export interface Options {
4
+ maxBuffer: number
5
+ stdio: string
6
+ env: NodeJS.ProcessEnv
7
+ }
8
+
9
+ /**
10
+ * Package or configuration dependencies
11
+ */
12
+ export type Dependencies = Record<string, string>
13
+
14
+ /**
15
+ * A dependency descriptor
16
+ */
17
+ export interface DependencyDescriptor {
18
+ name: string
19
+ version: string
20
+ }
21
+
22
+ /**
23
+ * A package
24
+ */
25
+ export type Package = Record<string, string> & {
26
+ author?: string | { name: string; email: string }
27
+ dependencies?: Dependencies
28
+ devDependencies?: Dependencies
29
+ optionalDependencies?: Dependencies
30
+ bundleDependencies?: Dependencies
31
+ peerDependencies?: Dependencies
32
+ }
33
+
34
+ /**
35
+ * A configuration
36
+ */
37
+ export type Configuration = Record<string, string> & {
38
+ author?: string | { name: string; email: string }
39
+ ignore?: boolean
40
+ message?: string
41
+ dependencies?: Dependencies
42
+ devDependencies?: Dependencies
43
+ optionalDependencies?: Dependencies
44
+ bundleDependencies?: Dependencies
45
+ peerDependencies?: Dependencies
46
+ }
47
+ }
48
+ }
49
+
50
+ export {}