@neurodevs/meta-node 0.19.12 → 0.19.14
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/.vscode/launch.json +1 -0
- package/build/__tests__/impl/NpmAutopackage.test.d.ts +31 -2
- package/build/__tests__/impl/NpmAutopackage.test.js +270 -44
- package/build/__tests__/impl/NpmAutopackage.test.js.map +1 -1
- package/build/impl/NpmAutopackage.d.ts +30 -5
- package/build/impl/NpmAutopackage.js +141 -14
- package/build/impl/NpmAutopackage.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/impl/NpmAutopackage.test.ts +387 -47
- package/src/impl/NpmAutopackage.ts +214 -19
|
@@ -24,7 +24,9 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
24
24
|
private author?: string
|
|
25
25
|
|
|
26
26
|
private originalPackageJson!: Record<string, unknown>
|
|
27
|
-
private
|
|
27
|
+
private originalGitignore!: string
|
|
28
|
+
|
|
29
|
+
private originalTsconfig!: TsConfig
|
|
28
30
|
private metaNodeVersion!: string
|
|
29
31
|
|
|
30
32
|
private originalTasksJson!: {
|
|
@@ -40,8 +42,8 @@ export default class NpmAutopackage implements Autopackage {
|
|
|
40
42
|
private readonly packageDir: string
|
|
41
43
|
private readonly packageJsonPath: string
|
|
42
44
|
private readonly gitignorePath: string
|
|
45
|
+
private readonly tsconfigPath: string
|
|
43
46
|
private readonly tasksJsonPath: string
|
|
44
|
-
private readonly settingsJsonPath: string
|
|
45
47
|
private readonly testDirPath: string
|
|
46
48
|
private readonly abstractTestPath: string
|
|
47
49
|
|
|
@@ -52,6 +54,16 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
52
54
|
await super.beforeEach()
|
|
53
55
|
}
|
|
54
56
|
}
|
|
57
|
+
`
|
|
58
|
+
|
|
59
|
+
private readonly eslintConfigFile = `import esConfigNdx from './src/eslint.config.js'
|
|
60
|
+
|
|
61
|
+
export default esConfigNdx
|
|
62
|
+
`
|
|
63
|
+
|
|
64
|
+
private readonly prettierConfigFile = `import prettierConfigNdx from '@neurodevs/prettier-config-ndx'
|
|
65
|
+
|
|
66
|
+
export default prettierConfigNdx
|
|
55
67
|
`
|
|
56
68
|
|
|
57
69
|
protected constructor(options: AutopackageOptions) {
|
|
@@ -78,13 +90,8 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
78
90
|
this.packageDir = path.join(this.installDir, this.packageName)
|
|
79
91
|
this.packageJsonPath = path.join(this.packageDir, 'package.json')
|
|
80
92
|
this.gitignorePath = path.join(this.packageDir, '.gitignore')
|
|
93
|
+
this.tsconfigPath = path.join(this.packageDir, 'tsconfig.json')
|
|
81
94
|
this.tasksJsonPath = path.join(this.packageDir, '.vscode/tasks.json')
|
|
82
|
-
|
|
83
|
-
this.settingsJsonPath = path.join(
|
|
84
|
-
this.packageDir,
|
|
85
|
-
'.vscode/settings.json'
|
|
86
|
-
)
|
|
87
|
-
|
|
88
95
|
this.testDirPath = path.join(this.packageDir, 'src', '__tests__')
|
|
89
96
|
|
|
90
97
|
this.abstractTestPath = path.join(
|
|
@@ -107,10 +114,14 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
107
114
|
await this.spruceCreateModule()
|
|
108
115
|
await this.updatePackageJson()
|
|
109
116
|
await this.updateGitignore()
|
|
117
|
+
await this.updateTsconfig()
|
|
110
118
|
await this.setupVscode()
|
|
111
119
|
await this.updateVscodeTasks()
|
|
112
120
|
await this.installDefaultDevDependencies()
|
|
113
121
|
await this.installAbstractPackageTest()
|
|
122
|
+
await this.removeOldEslintConfigMjs()
|
|
123
|
+
await this.installNewEslintConfigJs()
|
|
124
|
+
await this.installPrettierConfigFile()
|
|
114
125
|
await this.openVscode()
|
|
115
126
|
}
|
|
116
127
|
|
|
@@ -244,7 +255,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
244
255
|
}
|
|
245
256
|
|
|
246
257
|
private async updatePackageJson() {
|
|
247
|
-
this.originalPackageJson = await this.
|
|
258
|
+
this.originalPackageJson = await this.loadPackageJson()
|
|
248
259
|
|
|
249
260
|
if (!this.isPackageUpToDate) {
|
|
250
261
|
console.log('Updating package.json...')
|
|
@@ -254,7 +265,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
254
265
|
}
|
|
255
266
|
}
|
|
256
267
|
|
|
257
|
-
private async
|
|
268
|
+
private async loadPackageJson() {
|
|
258
269
|
const raw = await this.readFile(this.packageJsonPath, {
|
|
259
270
|
encoding: 'utf-8',
|
|
260
271
|
})
|
|
@@ -301,6 +312,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
301
312
|
...this.originalPackageJson,
|
|
302
313
|
name: this.scopedPackageName,
|
|
303
314
|
description: this.description,
|
|
315
|
+
type: 'module',
|
|
304
316
|
keywords: this.keywords ?? [],
|
|
305
317
|
license: this.license,
|
|
306
318
|
author: this.author,
|
|
@@ -350,7 +362,7 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
350
362
|
}
|
|
351
363
|
|
|
352
364
|
private async updateGitignore() {
|
|
353
|
-
this.
|
|
365
|
+
this.originalGitignore = await this.loadGitignore()
|
|
354
366
|
|
|
355
367
|
if (!this.isGitignoreUpdated) {
|
|
356
368
|
console.log('Updating .gitignore...')
|
|
@@ -360,14 +372,14 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
360
372
|
}
|
|
361
373
|
}
|
|
362
374
|
|
|
363
|
-
private async
|
|
375
|
+
private async loadGitignore() {
|
|
364
376
|
return await this.readFile(this.gitignorePath, {
|
|
365
377
|
encoding: 'utf-8',
|
|
366
378
|
})
|
|
367
379
|
}
|
|
368
380
|
|
|
369
381
|
private get isGitignoreUpdated() {
|
|
370
|
-
const lines = this.
|
|
382
|
+
const lines = this.originalGitignore
|
|
371
383
|
.split(/\r?\n/)
|
|
372
384
|
.map((line) => line.trim())
|
|
373
385
|
|
|
@@ -387,10 +399,97 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
387
399
|
)
|
|
388
400
|
}
|
|
389
401
|
|
|
402
|
+
private async updateTsconfig() {
|
|
403
|
+
this.originalTsconfig = await this.loadTsconfig()
|
|
404
|
+
|
|
405
|
+
if (!this.isTsconfigUpdated) {
|
|
406
|
+
console.log('Updating tsconfig...')
|
|
407
|
+
await this.updateTsconfigFile()
|
|
408
|
+
await this.commitUpdateTsconfig()
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private async loadTsconfig() {
|
|
413
|
+
const raw = await this.readFile(this.tsconfigPath, {
|
|
414
|
+
encoding: 'utf-8',
|
|
415
|
+
})
|
|
416
|
+
return JSON.parse(raw)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private get isTsconfigUpdated() {
|
|
420
|
+
return (
|
|
421
|
+
JSON.stringify(this.originalTsconfig) ==
|
|
422
|
+
JSON.stringify(this.updatedTsconfig)
|
|
423
|
+
)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
private async updateTsconfigFile() {
|
|
427
|
+
await this.writeFile(
|
|
428
|
+
this.tsconfigPath,
|
|
429
|
+
JSON.stringify(this.updatedTsconfig, null, 4) + '\n',
|
|
430
|
+
{
|
|
431
|
+
encoding: 'utf-8',
|
|
432
|
+
flag: 'a',
|
|
433
|
+
}
|
|
434
|
+
)
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private get updatedTsconfig() {
|
|
438
|
+
return {
|
|
439
|
+
...this.originalTsconfig,
|
|
440
|
+
compilerOptions: {
|
|
441
|
+
module: 'nodenext',
|
|
442
|
+
moduleResolution: 'nodenext',
|
|
443
|
+
target: 'ES2022',
|
|
444
|
+
lib: Array.from(
|
|
445
|
+
new Set([
|
|
446
|
+
...(this.originalTsconfig?.compilerOptions?.lib ?? []),
|
|
447
|
+
'ES2022',
|
|
448
|
+
])
|
|
449
|
+
),
|
|
450
|
+
types: Array.from(
|
|
451
|
+
new Set([
|
|
452
|
+
...(this.originalTsconfig?.compilerOptions?.types ??
|
|
453
|
+
[]),
|
|
454
|
+
'node',
|
|
455
|
+
])
|
|
456
|
+
),
|
|
457
|
+
baseUrl: 'src',
|
|
458
|
+
outDir: 'build',
|
|
459
|
+
sourceMap: false,
|
|
460
|
+
strict: true,
|
|
461
|
+
noImplicitAny: true,
|
|
462
|
+
noImplicitReturns: true,
|
|
463
|
+
noUnusedLocals: true,
|
|
464
|
+
forceConsistentCasingInFileNames: true,
|
|
465
|
+
declaration: true,
|
|
466
|
+
skipLibCheck: true,
|
|
467
|
+
esModuleInterop: true,
|
|
468
|
+
moduleDetection: 'force',
|
|
469
|
+
allowJs: true,
|
|
470
|
+
resolveJsonModule: true,
|
|
471
|
+
experimentalDecorators: true,
|
|
472
|
+
},
|
|
473
|
+
include: Array.from(
|
|
474
|
+
new Set([
|
|
475
|
+
...(this.originalTsconfig?.include ?? []),
|
|
476
|
+
'./src/*.ts',
|
|
477
|
+
'./src/**/*.ts',
|
|
478
|
+
])
|
|
479
|
+
),
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
private async commitUpdateTsconfig() {
|
|
484
|
+
await this.GitAutocommit(
|
|
485
|
+
`patch: update tsconfig (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
486
|
+
)
|
|
487
|
+
}
|
|
488
|
+
|
|
390
489
|
private async setupVscode() {
|
|
391
|
-
const
|
|
490
|
+
const vscodeTasksExist = await this.checkIfVscodeTasksExist()
|
|
392
491
|
|
|
393
|
-
if (!
|
|
492
|
+
if (!vscodeTasksExist) {
|
|
394
493
|
console.log('Setting up VSCode...')
|
|
395
494
|
|
|
396
495
|
await this.spruceSetupVscode()
|
|
@@ -398,8 +497,8 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
398
497
|
}
|
|
399
498
|
}
|
|
400
499
|
|
|
401
|
-
private async
|
|
402
|
-
return this.pathExists(this.
|
|
500
|
+
private async checkIfVscodeTasksExist() {
|
|
501
|
+
return this.pathExists(this.tasksJsonPath)
|
|
403
502
|
}
|
|
404
503
|
|
|
405
504
|
private async spruceSetupVscode() {
|
|
@@ -505,14 +604,24 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
505
604
|
'@neurodevs/node-tdd'
|
|
506
605
|
)
|
|
507
606
|
|
|
607
|
+
const eslintConfigNdxVersion = await this.getLatestVersion(
|
|
608
|
+
'@neurodevs/eslint-config-ndx'
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
const prettierConfigNdxVersion = await this.getLatestVersion(
|
|
612
|
+
'@neurodevs/prettier-config-ndx'
|
|
613
|
+
)
|
|
614
|
+
|
|
508
615
|
if (
|
|
509
616
|
this.currentGenerateIdVersion != generateIdVersion ||
|
|
510
|
-
this.currentNodeTddVersion != nodeTddVersion
|
|
617
|
+
this.currentNodeTddVersion != nodeTddVersion ||
|
|
618
|
+
this.currentEslintConfigNdxVersion != eslintConfigNdxVersion ||
|
|
619
|
+
this.currentPrettierConfigNdxVersion != prettierConfigNdxVersion
|
|
511
620
|
) {
|
|
512
621
|
console.log('Installing default devDependencies...')
|
|
513
622
|
|
|
514
623
|
await this.exec(
|
|
515
|
-
'yarn add -D @neurodevs/generate-id
|
|
624
|
+
'yarn add -D @neurodevs/generate-id @neurodevs/node-tdd @neurodevs/eslint-config-ndx @neurodevs/prettier-config-ndx',
|
|
516
625
|
{ cwd: this.packageDir }
|
|
517
626
|
)
|
|
518
627
|
await this.commitInstallDevDependencies()
|
|
@@ -543,6 +652,22 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
543
652
|
).replace('^', '')
|
|
544
653
|
}
|
|
545
654
|
|
|
655
|
+
private get currentEslintConfigNdxVersion() {
|
|
656
|
+
return (
|
|
657
|
+
(this.originalPackageJson.devDependencies as any)[
|
|
658
|
+
'@neurodevs/eslint-config-ndx'
|
|
659
|
+
] || ''
|
|
660
|
+
).replace('^', '')
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
private get currentPrettierConfigNdxVersion() {
|
|
664
|
+
return (
|
|
665
|
+
(this.originalPackageJson.devDependencies as any)[
|
|
666
|
+
'@neurodevs/prettier-config-ndx'
|
|
667
|
+
] || ''
|
|
668
|
+
).replace('^', '')
|
|
669
|
+
}
|
|
670
|
+
|
|
546
671
|
private async commitInstallDevDependencies() {
|
|
547
672
|
await this.GitAutocommit(
|
|
548
673
|
`patch: install default devDependencies (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
@@ -582,6 +707,66 @@ export default abstract class AbstractPackageTest extends AbstractModuleTest {
|
|
|
582
707
|
)
|
|
583
708
|
}
|
|
584
709
|
|
|
710
|
+
private async removeOldEslintConfigMjs() {
|
|
711
|
+
const fileExists = await this.pathExists(
|
|
712
|
+
path.join(this.packageDir, 'eslint.config.mjs')
|
|
713
|
+
)
|
|
714
|
+
|
|
715
|
+
if (fileExists) {
|
|
716
|
+
console.log('Removing old eslint.config.mjs...')
|
|
717
|
+
|
|
718
|
+
await this.exec(`git rm eslint.config.mjs`, {
|
|
719
|
+
cwd: this.packageDir,
|
|
720
|
+
})
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
private async installNewEslintConfigJs() {
|
|
725
|
+
const eslintConfigPath = path.join(this.packageDir, 'eslint.config.js')
|
|
726
|
+
const fileExists = await this.pathExists(eslintConfigPath)
|
|
727
|
+
|
|
728
|
+
if (!fileExists) {
|
|
729
|
+
console.log('Installing eslint.config.js...')
|
|
730
|
+
|
|
731
|
+
await this.writeFile(eslintConfigPath, this.eslintConfigFile, {
|
|
732
|
+
encoding: 'utf-8',
|
|
733
|
+
})
|
|
734
|
+
|
|
735
|
+
await this.commitInstallEslintConfigFile()
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
private async commitInstallEslintConfigFile() {
|
|
740
|
+
await this.GitAutocommit(
|
|
741
|
+
`patch: install eslint.config.js (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
742
|
+
)
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
private async installPrettierConfigFile() {
|
|
746
|
+
const prettierConfigPath = path.join(
|
|
747
|
+
this.packageDir,
|
|
748
|
+
'prettier.config.js'
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
const fileExists = await this.pathExists(prettierConfigPath)
|
|
752
|
+
|
|
753
|
+
if (!fileExists) {
|
|
754
|
+
console.log('Installing prettier.config.js...')
|
|
755
|
+
|
|
756
|
+
await this.writeFile(prettierConfigPath, this.prettierConfigFile, {
|
|
757
|
+
encoding: 'utf-8',
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
await this.commitInstallPrettierConfigFile()
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
private async commitInstallPrettierConfigFile() {
|
|
765
|
+
await this.GitAutocommit(
|
|
766
|
+
`patch: install prettier.config.js (@neurodevs/meta-node: ${this.metaNodeVersion})`
|
|
767
|
+
)
|
|
768
|
+
}
|
|
769
|
+
|
|
585
770
|
private async openVscode() {
|
|
586
771
|
if (this.shouldOpenVscode) {
|
|
587
772
|
await this.exec('code .', { cwd: this.packageDir })
|
|
@@ -635,3 +820,13 @@ export interface AutopackageOptions {
|
|
|
635
820
|
export type AutopackageConstructor = new (
|
|
636
821
|
options: AutopackageOptions
|
|
637
822
|
) => Autopackage
|
|
823
|
+
|
|
824
|
+
export interface TsConfig {
|
|
825
|
+
compilerOptions?: {
|
|
826
|
+
lib?: string[]
|
|
827
|
+
types?: string[]
|
|
828
|
+
[key: string]: unknown
|
|
829
|
+
}
|
|
830
|
+
include?: string[]
|
|
831
|
+
[key: string]: unknown
|
|
832
|
+
}
|