@neurodevs/meta-node 0.14.27 → 0.15.0
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/build/__tests__/AbstractPackageTest.d.ts +4 -0
- package/build/__tests__/AbstractPackageTest.js +11 -1
- package/build/__tests__/AbstractPackageTest.js.map +1 -1
- package/build/__tests__/impl/GitAutocloner.test.js +9 -9
- package/build/__tests__/impl/GitAutocloner.test.js.map +1 -1
- package/build/__tests__/impl/GitAutocommit.test.d.ts +11 -0
- package/build/__tests__/impl/GitAutocommit.test.js +49 -0
- package/build/__tests__/impl/GitAutocommit.test.js.map +1 -0
- package/build/__tests__/impl/ImplAutomodule.test.js +26 -8
- package/build/__tests__/impl/ImplAutomodule.test.js.map +1 -1
- package/build/__tests__/impl/NpmAutopackage.test.d.ts +1 -3
- package/build/__tests__/impl/NpmAutopackage.test.js +38 -64
- package/build/__tests__/impl/NpmAutopackage.test.js.map +1 -1
- package/build/__tests__/impl/NpmReleasePropagator.test.d.ts +17 -0
- package/build/__tests__/impl/NpmReleasePropagator.test.js +115 -0
- package/build/__tests__/impl/NpmReleasePropagator.test.js.map +1 -0
- package/build/__tests__/impl/UiAutomodule.test.js +26 -8
- package/build/__tests__/impl/UiAutomodule.test.js.map +1 -1
- package/build/impl/AbstractAutomodule.js +25 -7
- package/build/impl/AbstractAutomodule.js.map +1 -1
- package/build/impl/GitAutocommit.d.ts +15 -0
- package/build/impl/GitAutocommit.js +27 -0
- package/build/impl/GitAutocommit.js.map +1 -0
- package/build/impl/NpmAutopackage.d.ts +1 -9
- package/build/impl/NpmAutopackage.js +11 -48
- package/build/impl/NpmAutopackage.js.map +1 -1
- package/build/impl/NpmReleasePropagator.d.ts +40 -0
- package/build/impl/NpmReleasePropagator.js +78 -0
- package/build/impl/NpmReleasePropagator.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +10 -0
- package/build/index.js.map +1 -1
- package/build/scripts/runImplAutomodule.js +3 -3
- package/build/scripts/runImplAutomodule.js.map +1 -1
- package/build/scripts/runNpmReleasePropagator.d.ts +1 -0
- package/build/scripts/runNpmReleasePropagator.js +8 -0
- package/build/scripts/runNpmReleasePropagator.js.map +1 -0
- package/build/testDoubles/Autocommit/FakeAutocommit.d.ts +11 -0
- package/build/testDoubles/Autocommit/FakeAutocommit.js +18 -0
- package/build/testDoubles/Autocommit/FakeAutocommit.js.map +1 -0
- package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.d.ts +8 -0
- package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.js +15 -0
- package/build/testDoubles/ReleasePropagator/FakeReleasePropagator.js.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/AbstractPackageTest.ts +27 -1
- package/src/__tests__/impl/GitAutocloner.test.ts +13 -9
- package/src/__tests__/impl/GitAutocommit.test.ts +60 -0
- package/src/__tests__/impl/ImplAutomodule.test.ts +34 -8
- package/src/__tests__/impl/NpmAutopackage.test.ts +60 -91
- package/src/__tests__/impl/NpmReleasePropagator.test.ts +151 -0
- package/src/__tests__/impl/UiAutomodule.test.ts +34 -8
- package/src/impl/AbstractAutomodule.ts +33 -7
- package/src/impl/GitAutocommit.ts +40 -0
- package/src/impl/NpmAutopackage.ts +20 -64
- package/src/impl/NpmReleasePropagator.ts +134 -0
- package/src/index.ts +16 -0
- package/src/scripts/runImplAutomodule.ts +3 -3
- package/src/scripts/runNpmReleasePropagator.ts +9 -0
- package/src/testDoubles/Autocommit/FakeAutocommit.ts +26 -0
- package/src/testDoubles/ReleasePropagator/FakeReleasePropagator.ts +23 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ChildProcess, exec as execSync } from 'child_process'
|
|
2
2
|
import { readFile, writeFile } from 'fs/promises'
|
|
3
3
|
import { mkdir } from 'fs/promises'
|
|
4
|
-
import path from 'path'
|
|
5
4
|
import { promisify } from 'util'
|
|
6
5
|
import {
|
|
7
6
|
callsToChdir,
|
|
@@ -31,10 +30,12 @@ import {
|
|
|
31
30
|
} from '@neurodevs/fake-node-core'
|
|
32
31
|
import { test, assert } from '@neurodevs/node-tdd'
|
|
33
32
|
|
|
33
|
+
import GitAutocommit from '../../impl/GitAutocommit.js'
|
|
34
34
|
import NpmAutopackage, {
|
|
35
35
|
Autopackage,
|
|
36
36
|
AutopackageOptions,
|
|
37
37
|
} from '../../impl/NpmAutopackage.js'
|
|
38
|
+
import FakeAutocommit from '../../testDoubles/Autocommit/FakeAutocommit.js'
|
|
38
39
|
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
39
40
|
|
|
40
41
|
const exec = promisify(execSync)
|
|
@@ -53,6 +54,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
53
54
|
this.fakeReadFile()
|
|
54
55
|
this.fakeWriteFile()
|
|
55
56
|
|
|
57
|
+
this.setFakeAutocommit()
|
|
58
|
+
|
|
56
59
|
this.fakeFetchForRepoNotFound()
|
|
57
60
|
|
|
58
61
|
process.env.GITHUB_TOKEN = this.githubToken
|
|
@@ -127,7 +130,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
127
130
|
await this.run()
|
|
128
131
|
|
|
129
132
|
assert.isEqual(
|
|
130
|
-
callsToExec[0],
|
|
133
|
+
callsToExec[0]?.command,
|
|
131
134
|
`git clone https://github.com/${this.gitNamespace}/${this.name}.git`,
|
|
132
135
|
'Did not call git clone!'
|
|
133
136
|
)
|
|
@@ -149,7 +152,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
149
152
|
await this.run()
|
|
150
153
|
|
|
151
154
|
assert.isEqual(
|
|
152
|
-
callsToExec[1],
|
|
155
|
+
callsToExec[1]?.command,
|
|
153
156
|
`git fetch origin`,
|
|
154
157
|
'Did not call git fetch origin!'
|
|
155
158
|
)
|
|
@@ -160,7 +163,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
160
163
|
await this.run()
|
|
161
164
|
|
|
162
165
|
assert.isEqual(
|
|
163
|
-
callsToExec[2],
|
|
166
|
+
callsToExec[2]?.command,
|
|
164
167
|
`git reset --hard origin/main`,
|
|
165
168
|
'Did not call git reset hard!'
|
|
166
169
|
)
|
|
@@ -171,7 +174,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
171
174
|
await this.run()
|
|
172
175
|
|
|
173
176
|
assert.isEqual(
|
|
174
|
-
callsToExec[4],
|
|
177
|
+
callsToExec[4]?.command,
|
|
175
178
|
this.createModuleCmd,
|
|
176
179
|
'Did not call "spruce create.module"!'
|
|
177
180
|
)
|
|
@@ -182,12 +185,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
182
185
|
await this.run()
|
|
183
186
|
|
|
184
187
|
assert.isEqualDeep(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
'git add .',
|
|
188
|
-
`git commit -m "patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
|
|
189
|
-
'git push',
|
|
190
|
-
],
|
|
188
|
+
FakeAutocommit.callsToConstructor[0]?.commitMessage,
|
|
189
|
+
`patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
191
190
|
'Did not commit create package changes!'
|
|
192
191
|
)
|
|
193
192
|
}
|
|
@@ -255,12 +254,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
255
254
|
await this.run()
|
|
256
255
|
|
|
257
256
|
assert.isEqualDeep(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
'git add .',
|
|
261
|
-
`git commit -m "patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
|
|
262
|
-
'git push',
|
|
263
|
-
],
|
|
257
|
+
FakeAutocommit.callsToConstructor[1]?.commitMessage,
|
|
258
|
+
`patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
264
259
|
'Did not commit update package changes!'
|
|
265
260
|
)
|
|
266
261
|
}
|
|
@@ -285,12 +280,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
285
280
|
await this.run()
|
|
286
281
|
|
|
287
282
|
assert.isEqualDeep(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
'git add .',
|
|
291
|
-
`git commit -m "patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
|
|
292
|
-
'git push',
|
|
293
|
-
],
|
|
283
|
+
FakeAutocommit.callsToConstructor[2]?.commitMessage,
|
|
284
|
+
`patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
294
285
|
'Did not commit .gitignore changes!'
|
|
295
286
|
)
|
|
296
287
|
}
|
|
@@ -300,7 +291,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
300
291
|
await this.run()
|
|
301
292
|
|
|
302
293
|
assert.isEqual(
|
|
303
|
-
callsToExec[
|
|
294
|
+
callsToExec[5]?.command,
|
|
304
295
|
this.setupVscodeCmd,
|
|
305
296
|
'Did not call "spruce setup.vscode"!'
|
|
306
297
|
)
|
|
@@ -311,12 +302,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
311
302
|
await this.run()
|
|
312
303
|
|
|
313
304
|
assert.isEqualDeep(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
'git add .',
|
|
317
|
-
`git commit -m "patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
|
|
318
|
-
'git push',
|
|
319
|
-
],
|
|
305
|
+
FakeAutocommit.callsToConstructor[3]?.commitMessage,
|
|
306
|
+
`patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
320
307
|
'Did not commit vscode changes!'
|
|
321
308
|
)
|
|
322
309
|
}
|
|
@@ -337,12 +324,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
337
324
|
await this.run()
|
|
338
325
|
|
|
339
326
|
assert.isEqualDeep(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
'git add .',
|
|
343
|
-
`git commit -m "patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
|
|
344
|
-
'git push',
|
|
345
|
-
],
|
|
327
|
+
FakeAutocommit.callsToConstructor[4]?.commitMessage,
|
|
328
|
+
`patch: update vscode tasks.json (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
346
329
|
'Did not commit updated vscode tasks.json changes!'
|
|
347
330
|
)
|
|
348
331
|
}
|
|
@@ -352,7 +335,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
352
335
|
await this.run()
|
|
353
336
|
|
|
354
337
|
assert.isEqual(
|
|
355
|
-
callsToExec[
|
|
338
|
+
callsToExec[8]?.command,
|
|
356
339
|
this.yarnInstallDevDepsCommand,
|
|
357
340
|
'Did not install default devDependencies!'
|
|
358
341
|
)
|
|
@@ -363,12 +346,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
363
346
|
await this.run()
|
|
364
347
|
|
|
365
348
|
assert.isEqualDeep(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
'git add .',
|
|
369
|
-
`git commit -m "patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
|
|
370
|
-
'git push',
|
|
371
|
-
],
|
|
349
|
+
FakeAutocommit.callsToConstructor[5]?.commitMessage,
|
|
350
|
+
`patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
372
351
|
'Did not commit install devDependencies changes!'
|
|
373
352
|
)
|
|
374
353
|
}
|
|
@@ -407,12 +386,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
407
386
|
await this.run()
|
|
408
387
|
|
|
409
388
|
assert.isEqualDeep(
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
'git add .',
|
|
413
|
-
`git commit -m "patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})"`,
|
|
414
|
-
'git push',
|
|
415
|
-
],
|
|
389
|
+
FakeAutocommit.callsToConstructor[6]?.commitMessage,
|
|
390
|
+
`patch: install AbstractPackageTest (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
416
391
|
'Did not commit install AbstractPackageTest changes!'
|
|
417
392
|
)
|
|
418
393
|
}
|
|
@@ -421,7 +396,11 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
421
396
|
protected static async lastlyOpensVscodeAtEnd() {
|
|
422
397
|
await this.run()
|
|
423
398
|
|
|
424
|
-
assert.isEqual(
|
|
399
|
+
assert.isEqual(
|
|
400
|
+
callsToExec[9]?.command,
|
|
401
|
+
'code .',
|
|
402
|
+
'Did not open vscode at end!'
|
|
403
|
+
)
|
|
425
404
|
}
|
|
426
405
|
|
|
427
406
|
@test()
|
|
@@ -448,8 +427,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
448
427
|
|
|
449
428
|
assert.isEqual(
|
|
450
429
|
callsToExec.filter(
|
|
451
|
-
(
|
|
452
|
-
|
|
430
|
+
(call) =>
|
|
431
|
+
call?.command ===
|
|
453
432
|
`git clone https://github.com/${this.gitNamespace}/${this.name}.git`
|
|
454
433
|
).length,
|
|
455
434
|
1,
|
|
@@ -462,7 +441,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
462
441
|
await this.createAndRunAutopackage()
|
|
463
442
|
|
|
464
443
|
assert.isEqual(
|
|
465
|
-
callsToExec.filter((
|
|
444
|
+
callsToExec.filter((call) => call?.command === this.createModuleCmd)
|
|
445
|
+
.length,
|
|
466
446
|
1,
|
|
467
447
|
'Did not call spruce create.module once!'
|
|
468
448
|
)
|
|
@@ -473,7 +453,8 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
473
453
|
await this.createAndRunAutopackage()
|
|
474
454
|
|
|
475
455
|
assert.isEqual(
|
|
476
|
-
callsToExec.filter((
|
|
456
|
+
callsToExec.filter((call) => call?.command === this.setupVscodeCmd)
|
|
457
|
+
.length,
|
|
477
458
|
1,
|
|
478
459
|
'Did not call spruce setup.vscode once!'
|
|
479
460
|
)
|
|
@@ -484,10 +465,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
484
465
|
await this.createAndRunAutopackage()
|
|
485
466
|
|
|
486
467
|
assert.isEqual(
|
|
487
|
-
|
|
488
|
-
(
|
|
489
|
-
|
|
490
|
-
`
|
|
468
|
+
FakeAutocommit.callsToConstructor.filter(
|
|
469
|
+
(call) =>
|
|
470
|
+
call?.commitMessage ===
|
|
471
|
+
`patch: create package (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
491
472
|
).length,
|
|
492
473
|
1,
|
|
493
474
|
'Did not commit create package changes once!'
|
|
@@ -499,10 +480,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
499
480
|
await this.createAndRunAutopackage()
|
|
500
481
|
|
|
501
482
|
assert.isEqual(
|
|
502
|
-
|
|
503
|
-
(
|
|
504
|
-
|
|
505
|
-
`
|
|
483
|
+
FakeAutocommit.callsToConstructor.filter(
|
|
484
|
+
(call) =>
|
|
485
|
+
call?.commitMessage ===
|
|
486
|
+
`patch: update package.json (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
506
487
|
).length,
|
|
507
488
|
1,
|
|
508
489
|
'Did not commit update package changes once!'
|
|
@@ -514,10 +495,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
514
495
|
await this.createAndRunAutopackage()
|
|
515
496
|
|
|
516
497
|
assert.isEqual(
|
|
517
|
-
|
|
518
|
-
(
|
|
519
|
-
|
|
520
|
-
`
|
|
498
|
+
FakeAutocommit.callsToConstructor.filter(
|
|
499
|
+
(call) =>
|
|
500
|
+
call?.commitMessage ===
|
|
501
|
+
`patch: add build dir to gitignore (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
521
502
|
).length,
|
|
522
503
|
1,
|
|
523
504
|
'Did not commit gitignore changes once!'
|
|
@@ -529,10 +510,10 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
529
510
|
await this.createAndRunAutopackage()
|
|
530
511
|
|
|
531
512
|
assert.isEqual(
|
|
532
|
-
|
|
533
|
-
(
|
|
534
|
-
|
|
535
|
-
`
|
|
513
|
+
FakeAutocommit.callsToConstructor.filter(
|
|
514
|
+
(call) =>
|
|
515
|
+
call?.commitMessage ===
|
|
516
|
+
`patch: setup vscode (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
536
517
|
).length,
|
|
537
518
|
1,
|
|
538
519
|
'Did not commit vscode changes once!'
|
|
@@ -571,7 +552,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
571
552
|
await this.createAndRunAutopackage()
|
|
572
553
|
|
|
573
554
|
assert.isFalse(
|
|
574
|
-
callsToExec.
|
|
555
|
+
callsToExec.some((call) => call?.command === 'code .'),
|
|
575
556
|
'Should not open vscode if not cloned!'
|
|
576
557
|
)
|
|
577
558
|
}
|
|
@@ -585,7 +566,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
585
566
|
await this.createAndRunAutopackage()
|
|
586
567
|
|
|
587
568
|
const calls = callsToExec.filter(
|
|
588
|
-
(
|
|
569
|
+
(call) => call?.command === this.yarnInstallDevDepsCommand
|
|
589
570
|
)
|
|
590
571
|
|
|
591
572
|
assert.isEqual(
|
|
@@ -608,7 +589,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
608
589
|
await this.createAndRunAutopackage()
|
|
609
590
|
|
|
610
591
|
const calls = callsToExec.filter(
|
|
611
|
-
(
|
|
592
|
+
(call) => call?.command === this.yarnInstallDevDepsCommand
|
|
612
593
|
)
|
|
613
594
|
|
|
614
595
|
assert.isEqual(
|
|
@@ -709,9 +690,6 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
709
690
|
private static readonly checkGenerateIdVersionCmd = `yarn info @neurodevs/generate-id version --silent`
|
|
710
691
|
private static readonly checkNodeTddVersionCmd = `yarn info @neurodevs/node-tdd version --silent`
|
|
711
692
|
|
|
712
|
-
private static readonly yarnGlobalDirCmd = 'yarn global dir'
|
|
713
|
-
private static readonly fakeGlobalRoot = this.generateId()
|
|
714
|
-
|
|
715
693
|
private static orderJsonKeys(
|
|
716
694
|
json: Record<string, unknown>,
|
|
717
695
|
keyOrder: string[]
|
|
@@ -744,20 +722,7 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
744
722
|
NpmAutopackage.exec = fakeExec as unknown as typeof exec
|
|
745
723
|
resetCallsToExec()
|
|
746
724
|
|
|
747
|
-
|
|
748
|
-
stdout: this.fakeGlobalRoot,
|
|
749
|
-
} as unknown as ChildProcess)
|
|
750
|
-
|
|
751
|
-
setFakeReadFileResult(
|
|
752
|
-
path.join(
|
|
753
|
-
this.fakeGlobalRoot,
|
|
754
|
-
'node_modules',
|
|
755
|
-
'@neurodevs',
|
|
756
|
-
'meta-node',
|
|
757
|
-
'package.json'
|
|
758
|
-
),
|
|
759
|
-
JSON.stringify({ version: this.metaNodeVersion })
|
|
760
|
-
)
|
|
725
|
+
this.setFakeMetaNodeVersion()
|
|
761
726
|
}
|
|
762
727
|
|
|
763
728
|
private static fakeFetch() {
|
|
@@ -794,6 +759,11 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
794
759
|
resetCallsToWriteFile()
|
|
795
760
|
}
|
|
796
761
|
|
|
762
|
+
private static setFakeAutocommit() {
|
|
763
|
+
GitAutocommit.Class = FakeAutocommit
|
|
764
|
+
FakeAutocommit.resetTestDouble()
|
|
765
|
+
}
|
|
766
|
+
|
|
797
767
|
private static fakeFetchForRepoNotFound() {
|
|
798
768
|
const fakeResponse = new Response(null, {
|
|
799
769
|
status: 404,
|
|
@@ -813,7 +783,6 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
|
|
|
813
783
|
private static readonly author = this.generateId()
|
|
814
784
|
|
|
815
785
|
private static readonly githubToken = this.generateId()
|
|
816
|
-
private static readonly metaNodeVersion = this.generateId()
|
|
817
786
|
private static readonly randomId = this.generateId()
|
|
818
787
|
|
|
819
788
|
private static get reposUrl() {
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { exec as execSync } from 'node:child_process'
|
|
2
|
+
import { readFile } from 'node:fs/promises'
|
|
3
|
+
import { promisify } from 'node:util'
|
|
4
|
+
import {
|
|
5
|
+
callsToExec,
|
|
6
|
+
fakeExec,
|
|
7
|
+
fakeReadFile,
|
|
8
|
+
resetCallsToExec,
|
|
9
|
+
resetCallsToReadFile,
|
|
10
|
+
setFakeReadFileResult,
|
|
11
|
+
} from '@neurodevs/fake-node-core'
|
|
12
|
+
import { test, assert } from '@neurodevs/node-tdd'
|
|
13
|
+
|
|
14
|
+
import GitAutocommit from '../../impl/GitAutocommit.js'
|
|
15
|
+
import NpmReleasePropagator, {
|
|
16
|
+
ReleasePropagator,
|
|
17
|
+
ReleasePropagatorOptions,
|
|
18
|
+
} from '../../impl/NpmReleasePropagator.js'
|
|
19
|
+
import { FakeAutocommit } from '../../index.js'
|
|
20
|
+
import AbstractPackageTest from '../AbstractPackageTest.js'
|
|
21
|
+
|
|
22
|
+
const exec = promisify(execSync)
|
|
23
|
+
|
|
24
|
+
export default class NpmReleasePropagatorTest extends AbstractPackageTest {
|
|
25
|
+
private static instance: ReleasePropagator
|
|
26
|
+
|
|
27
|
+
private static readonly packageName = this.generateId()
|
|
28
|
+
private static readonly packageVersion = this.generateId()
|
|
29
|
+
private static readonly repoPaths = [this.generateId(), this.generateId()]
|
|
30
|
+
|
|
31
|
+
protected static async beforeEach() {
|
|
32
|
+
await super.beforeEach()
|
|
33
|
+
|
|
34
|
+
this.setFakeExec()
|
|
35
|
+
this.setFakeReadFile()
|
|
36
|
+
this.setFakeAutocommit()
|
|
37
|
+
|
|
38
|
+
this.instance = this.NpmReleasePropagator()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@test()
|
|
42
|
+
protected static async createsInstance() {
|
|
43
|
+
assert.isTruthy(this.instance, 'Failed to create instance!')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@test()
|
|
47
|
+
protected static async runInstallsReleaseForEachRepoPath() {
|
|
48
|
+
await this.run()
|
|
49
|
+
|
|
50
|
+
const expectedCalls = [
|
|
51
|
+
{
|
|
52
|
+
command: `yarn add ${this.packageName}@${this.packageVersion}`,
|
|
53
|
+
options: { cwd: this.repoPaths[0] },
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
command: `yarn add -D ${this.packageName}@${this.packageVersion}`,
|
|
57
|
+
options: { cwd: this.repoPaths[1] },
|
|
58
|
+
},
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
assert.isEqualDeep(
|
|
62
|
+
[callsToExec[0], callsToExec[2]],
|
|
63
|
+
expectedCalls,
|
|
64
|
+
'Did not install release in each repo path!'
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@test()
|
|
69
|
+
protected static async runThrowsIfRepoDoesNotHavePreviousRelease() {
|
|
70
|
+
const missingPackageName = this.generateId()
|
|
71
|
+
|
|
72
|
+
this.instance = this.NpmReleasePropagator({
|
|
73
|
+
packageName: missingPackageName,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
await assert.doesThrowAsync(async () => {
|
|
77
|
+
await this.run()
|
|
78
|
+
}, `Cannot propagate release for ${missingPackageName} because it is not listed in either dependencies or devDependencies! Please install it in the target repository before running propagation.`)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@test()
|
|
82
|
+
protected static async commitsChangesToGit() {
|
|
83
|
+
await this.run()
|
|
84
|
+
|
|
85
|
+
assert.isEqualDeep(
|
|
86
|
+
FakeAutocommit.callsToConstructor,
|
|
87
|
+
[
|
|
88
|
+
{
|
|
89
|
+
commitMessage: `patch: propagate ${this.packageName}@${this.packageVersion} (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
90
|
+
cwd: this.repoPaths[0],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
commitMessage: `patch: propagate ${this.packageName}@${this.packageVersion} (@neurodevs/meta-node: ${this.metaNodeVersion})`,
|
|
94
|
+
cwd: this.repoPaths[1],
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
'Did not commit changes to git for each repo path!'
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static async run() {
|
|
102
|
+
await this.instance.run()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private static setFakeExec() {
|
|
106
|
+
NpmReleasePropagator.exec = fakeExec as unknown as typeof exec
|
|
107
|
+
resetCallsToExec()
|
|
108
|
+
|
|
109
|
+
this.setFakeMetaNodeVersion()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private static setFakeReadFile() {
|
|
113
|
+
NpmReleasePropagator.readFile =
|
|
114
|
+
fakeReadFile as unknown as typeof readFile
|
|
115
|
+
resetCallsToReadFile()
|
|
116
|
+
|
|
117
|
+
setFakeReadFileResult(
|
|
118
|
+
`${this.repoPaths[0]}/package.json`,
|
|
119
|
+
JSON.stringify({
|
|
120
|
+
dependencies: {
|
|
121
|
+
[this.packageName]: this.generateId(),
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
setFakeReadFileResult(
|
|
127
|
+
`${this.repoPaths[1]}/package.json`,
|
|
128
|
+
JSON.stringify({
|
|
129
|
+
devDependencies: {
|
|
130
|
+
[this.packageName]: this.generateId(),
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private static setFakeAutocommit() {
|
|
137
|
+
GitAutocommit.Class = FakeAutocommit
|
|
138
|
+
FakeAutocommit.resetTestDouble()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private static NpmReleasePropagator(
|
|
142
|
+
options?: Partial<ReleasePropagatorOptions>
|
|
143
|
+
) {
|
|
144
|
+
return NpmReleasePropagator.Create({
|
|
145
|
+
packageName: this.packageName,
|
|
146
|
+
packageVersion: this.packageVersion,
|
|
147
|
+
repoPaths: this.repoPaths,
|
|
148
|
+
...options,
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -119,7 +119,7 @@ export default class UiAutomoduleTest extends AbstractAutomoduleTest {
|
|
|
119
119
|
await this.run()
|
|
120
120
|
|
|
121
121
|
assert.isEqualDeep(
|
|
122
|
-
callsToExec[0],
|
|
122
|
+
callsToExec[0]?.command,
|
|
123
123
|
'yarn version --minor --no-git-tag-version',
|
|
124
124
|
'Did not bump minor version!'
|
|
125
125
|
)
|
|
@@ -234,18 +234,44 @@ export default class UiAutomoduleTest extends AbstractAutomoduleTest {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
private static get sortedIndexFile() {
|
|
237
|
-
const blocks =
|
|
237
|
+
const blocks = this.originalIndexFile
|
|
238
238
|
.split(/(?=\/\/)/)
|
|
239
239
|
.map((s) => s.trim())
|
|
240
240
|
.filter(Boolean)
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
const newBlock = this.indexFilePattern.trim()
|
|
243
|
+
|
|
244
|
+
const newKey =
|
|
245
|
+
newBlock
|
|
246
|
+
.match(/^\/\/\s*([^\n]*)/)?.[1]
|
|
247
|
+
?.trim()
|
|
248
|
+
.toLowerCase() ?? ''
|
|
249
|
+
|
|
250
|
+
let inserted = false
|
|
251
|
+
const result: string[] = []
|
|
252
|
+
|
|
253
|
+
for (const block of blocks) {
|
|
254
|
+
if (!inserted) {
|
|
255
|
+
const blockKey =
|
|
256
|
+
block
|
|
257
|
+
.match(/^\/\/\s*([^\n]*)/)?.[1]
|
|
258
|
+
?.trim()
|
|
259
|
+
.toLowerCase() ?? ''
|
|
260
|
+
|
|
261
|
+
if (newKey.localeCompare(blockKey) < 0) {
|
|
262
|
+
result.push(newBlock)
|
|
263
|
+
inserted = true
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
result.push(block)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (!inserted) {
|
|
271
|
+
result.push(newBlock)
|
|
272
|
+
}
|
|
247
273
|
|
|
248
|
-
return
|
|
274
|
+
return result.join('\n\n')
|
|
249
275
|
}
|
|
250
276
|
|
|
251
277
|
private static toKebabCase(str: string): string {
|
|
@@ -151,18 +151,44 @@ export default abstract class AbstractAutomodule implements Automodule {
|
|
|
151
151
|
private readonly backupIndexFilePath = './src/exports.ts'
|
|
152
152
|
|
|
153
153
|
private get sortedIndexFile() {
|
|
154
|
-
const blocks =
|
|
154
|
+
const blocks = this.originalIndexFile
|
|
155
155
|
.split(/(?=\/\/)/)
|
|
156
156
|
.map((s) => s.trim())
|
|
157
157
|
.filter(Boolean)
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
const aKey = a.match(/^\/\/\s*([^\n]*)/)?.[1]?.trim() ?? ''
|
|
161
|
-
const bKey = b.match(/^\/\/\s*([^\n]*)/)?.[1]?.trim() ?? ''
|
|
162
|
-
return aKey.localeCompare(bKey)
|
|
163
|
-
})
|
|
159
|
+
const newBlock = this.indexFileContent.trim()
|
|
164
160
|
|
|
165
|
-
|
|
161
|
+
const newKey =
|
|
162
|
+
newBlock
|
|
163
|
+
.match(/^\/\/\s*([^\n]*)/)?.[1]
|
|
164
|
+
?.trim()
|
|
165
|
+
.toLowerCase() ?? ''
|
|
166
|
+
|
|
167
|
+
let inserted = false
|
|
168
|
+
const result: string[] = []
|
|
169
|
+
|
|
170
|
+
for (const block of blocks) {
|
|
171
|
+
if (!inserted) {
|
|
172
|
+
const blockKey =
|
|
173
|
+
block
|
|
174
|
+
.match(/^\/\/\s*([^\n]*)/)?.[1]
|
|
175
|
+
?.trim()
|
|
176
|
+
.toLowerCase() ?? ''
|
|
177
|
+
|
|
178
|
+
if (newKey.localeCompare(blockKey) < 0) {
|
|
179
|
+
result.push(newBlock)
|
|
180
|
+
inserted = true
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
result.push(block)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!inserted) {
|
|
188
|
+
result.push(newBlock)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return result.join('\n\n')
|
|
166
192
|
}
|
|
167
193
|
|
|
168
194
|
private async bumpMinorVersion() {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { exec as execSync } from 'node:child_process'
|
|
2
|
+
import { promisify } from 'node:util'
|
|
3
|
+
|
|
4
|
+
export default class GitAutocommit implements Autocommit {
|
|
5
|
+
public static Class?: AutocommitConstructor
|
|
6
|
+
public static exec = promisify(execSync)
|
|
7
|
+
|
|
8
|
+
private commitMessage: string
|
|
9
|
+
private cwd?: string
|
|
10
|
+
|
|
11
|
+
protected constructor(commitMessage: string, cwd?: string) {
|
|
12
|
+
this.commitMessage = commitMessage
|
|
13
|
+
this.cwd = cwd
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static async Create(commitMessage: string, cwd?: string) {
|
|
17
|
+
const instance = new (this.Class ?? this)(commitMessage, cwd)
|
|
18
|
+
await instance.run()
|
|
19
|
+
|
|
20
|
+
return instance
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async run() {
|
|
24
|
+
const execOptions = { cwd: this.cwd ?? process.cwd() }
|
|
25
|
+
|
|
26
|
+
await this.exec('git add .', execOptions)
|
|
27
|
+
await this.exec(`git commit -m "${this.commitMessage}"`, execOptions)
|
|
28
|
+
await this.exec('git push', execOptions)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private get exec() {
|
|
32
|
+
return GitAutocommit.exec
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Autocommit {
|
|
37
|
+
run(): Promise<void>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type AutocommitConstructor = new (commitMessage: string) => Autocommit
|