@neurodevs/meta-node 0.19.16 → 0.19.17

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.
@@ -79,7 +79,8 @@ export default class AbstractAutomoduleTest extends AbstractPackageTest {
79
79
  `
80
80
 
81
81
  protected static setFakeExec() {
82
- AbstractAutomodule.exec = fakeExec as unknown as typeof AbstractAutomodule.exec
82
+ AbstractAutomodule.exec =
83
+ fakeExec as unknown as typeof AbstractAutomodule.exec
83
84
  resetCallsToExec()
84
85
  }
85
86
 
@@ -116,7 +116,9 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
116
116
  private static readonly customLib = this.generateId()
117
117
  private static readonly customType = this.generateId()
118
118
  private static readonly customInclude = this.generateId()
119
- private static readonly customOption = this.generateId()
119
+ private static readonly customTsconfigOption = this.generateId()
120
+ private static readonly customJestOption = this.generateId()
121
+ private static readonly customScript = this.generateId()
120
122
 
121
123
  private static readonly setupVscodeCmd = 'spruce setup.vscode --all true'
122
124
 
@@ -130,6 +132,9 @@ export default class NpmAutopackageTest extends AbstractPackageTest {
130
132
  [this.generateId()]: this.generateId(),
131
133
  }
132
134
 
135
+ private static readonly yarnRemoveDevDepsCommand =
136
+ 'yarn remove eslint eslint-config-spruce prettier chokidar-cli ts-node @types/node'
137
+
133
138
  private static readonly yarnInstallDevDepsCommand =
134
139
  'yarn add -D @neurodevs/generate-id @neurodevs/node-tdd @neurodevs/eslint-config-ndx @neurodevs/prettier-config-ndx'
135
140
 
@@ -152,7 +157,7 @@ export default esConfigNdx
152
157
  export default prettierConfigNdx
153
158
  `
154
159
 
155
- private static readonly settingsJsonFile = `{
160
+ private static readonly settingsJsonFile = `{
156
161
  "debug.node.autoAttach": "on",
157
162
  "git.ignoreLimitWarning": true,
158
163
  "javascript.validate.enable": false,
@@ -400,7 +405,6 @@ private static readonly settingsJsonFile = `{
400
405
  'dependencies',
401
406
  'devDependencies',
402
407
  'jest',
403
- 'skill',
404
408
  ]
405
409
  )
406
410
 
@@ -548,13 +552,28 @@ private static readonly settingsJsonFile = `{
548
552
  )
549
553
  }
550
554
 
555
+ @test()
556
+ protected static async thenRemovesOldDevDependencies() {
557
+ this.setShouldInstallDevDeps()
558
+ await this.run()
559
+
560
+ assert.isEqualDeep(
561
+ callsToExec[6],
562
+ {
563
+ command: this.yarnRemoveDevDepsCommand,
564
+ options: { cwd: this.packageDir },
565
+ },
566
+ 'Did not remove old devDependencies!'
567
+ )
568
+ }
569
+
551
570
  @test()
552
571
  protected static async thenInstallsDefaultDevDependencies() {
553
572
  this.setShouldInstallDevDeps()
554
573
  await this.run()
555
574
 
556
575
  assert.isEqualDeep(
557
- callsToExec[10],
576
+ callsToExec[11],
558
577
  {
559
578
  command: this.yarnInstallDevDepsCommand,
560
579
  options: { cwd: this.packageDir },
@@ -624,7 +643,7 @@ private static readonly settingsJsonFile = `{
624
643
  }
625
644
 
626
645
  @test()
627
- protected static async thenDeletesOldEslintConfigMjs() {
646
+ protected static async thenRemovesOldEslintConfigMjs() {
628
647
  setPathShouldExist(
629
648
  path.join(this.packageDir, 'eslint.config.mjs'),
630
649
  true
@@ -634,12 +653,12 @@ private static readonly settingsJsonFile = `{
634
653
  await this.run()
635
654
 
636
655
  assert.isEqualDeep(
637
- callsToExec[11],
656
+ callsToExec[12],
638
657
  {
639
658
  command: `git rm eslint.config.mjs`,
640
659
  options: { cwd: this.packageDir },
641
660
  },
642
- 'Did not delete old eslint.config.mjs!'
661
+ 'Did not remove old eslint.config.mjs!'
643
662
  )
644
663
  }
645
664
 
@@ -741,12 +760,36 @@ private static readonly settingsJsonFile = `{
741
760
  await this.run()
742
761
 
743
762
  assert.isEqualDeep(
744
- callsToExec[11],
763
+ callsToExec[12],
745
764
  { command: 'code .', options: { cwd: this.packageDir } },
746
765
  'Did not open vscode at end!'
747
766
  )
748
767
  }
749
768
 
769
+ @test()
770
+ protected static async removesCertainKeysFromPackageJson() {
771
+ const keysToRemove = [
772
+ 'skill',
773
+ 'jest.testPathIgnorePatterns',
774
+ 'jest.moduleNameMapper',
775
+ 'scripts.build.resolve-paths',
776
+ 'scripts.lint.tsc',
777
+ 'scripts.post.watch.build',
778
+ 'scripts.resolve-paths.lint',
779
+ 'scripts.watch.rebuild',
780
+ 'scripts.watch.tsc',
781
+ ]
782
+
783
+ const pkg = JSON.parse(this.updatedPackageJson)
784
+
785
+ for (const key of keysToRemove) {
786
+ assert.isUndefined(
787
+ this.getByPath(pkg, key),
788
+ `Did not remove ${key} from package.json!`
789
+ )
790
+ }
791
+ }
792
+
750
793
  @test()
751
794
  protected static async installsEslintConfigIfNotExists() {
752
795
  setFakeReadFileThrowsFor(this.eslintConfigJsPath)
@@ -759,7 +802,7 @@ private static readonly settingsJsonFile = `{
759
802
 
760
803
  assert.isEqual(
761
804
  calls.length,
762
- 1,
805
+ 1,
763
806
  'Should install eslint.config.js if it does not exist!'
764
807
  )
765
808
  }
@@ -776,7 +819,7 @@ private static readonly settingsJsonFile = `{
776
819
 
777
820
  assert.isEqual(
778
821
  calls.length,
779
- 1,
822
+ 1,
780
823
  'Should install prettier.config.js if it does not exist!'
781
824
  )
782
825
  }
@@ -1041,7 +1084,10 @@ private static readonly settingsJsonFile = `{
1041
1084
  protected static async doesNotThrowIfGenerateIdNotInPackageJson() {
1042
1085
  setFakeReadFileResult(
1043
1086
  this.packageJsonPath,
1044
- this.originalPackageJson.replace('@neurodevs/generate-id', '')
1087
+ JSON.stringify(this.originalPackageJson).replace(
1088
+ '@neurodevs/generate-id',
1089
+ ''
1090
+ )
1045
1091
  )
1046
1092
 
1047
1093
  await this.runTwice()
@@ -1179,6 +1225,12 @@ private static readonly settingsJsonFile = `{
1179
1225
  await this.run()
1180
1226
  }
1181
1227
 
1228
+ private static getByPath(obj: any, path: string) {
1229
+ return path
1230
+ .split('.')
1231
+ .reduce((acc, key) => (acc == null ? undefined : acc[key]), obj)
1232
+ }
1233
+
1182
1234
  private static setShouldInstallDevDeps() {
1183
1235
  setFakeExecResult(this.checkGenerateIdVersionCmd, {
1184
1236
  stdout: '0.0.1',
@@ -1263,7 +1315,10 @@ private static readonly settingsJsonFile = `{
1263
1315
  NpmAutopackage.readFile = fakeReadFile as unknown as typeof readFile
1264
1316
  resetCallsToReadFile()
1265
1317
 
1266
- setFakeReadFileResult(this.packageJsonPath, this.originalPackageJson)
1318
+ setFakeReadFileResult(
1319
+ this.packageJsonPath,
1320
+ JSON.stringify(this.originalPackageJsonWithDummies)
1321
+ )
1267
1322
 
1268
1323
  setFakeReadFileResult(
1269
1324
  this.tasksJsonPath,
@@ -1308,9 +1363,12 @@ private static readonly settingsJsonFile = `{
1308
1363
  }
1309
1364
 
1310
1365
  private static get originalPackageJson() {
1311
- return JSON.stringify({
1366
+ return {
1312
1367
  name: this.packageName,
1313
1368
  description: 'Old description',
1369
+ scripts: {
1370
+ customScript: this.customScript,
1371
+ },
1314
1372
  dependencies: this.dependencies,
1315
1373
  devDependencies: {
1316
1374
  '@neurodevs/generate-id': '^1.0.0',
@@ -1318,12 +1376,36 @@ private static readonly settingsJsonFile = `{
1318
1376
  '@neurodevs/eslint-config-ndx': '^1.0.0',
1319
1377
  '@neurodevs/prettier-config-ndx': '^1.0.0',
1320
1378
  },
1321
- })
1379
+ jest: {
1380
+ ['customOption']: this.customJestOption,
1381
+ },
1382
+ }
1383
+ }
1384
+
1385
+ private static get originalPackageJsonWithDummies() {
1386
+ return {
1387
+ ...this.originalPackageJson,
1388
+ scripts: {
1389
+ ...this.originalPackageJson.scripts,
1390
+ 'build.resolve-paths': 'dummy',
1391
+ 'lint.tsc': 'dummy',
1392
+ 'post.watch.build': 'dummy',
1393
+ 'resolve-paths.lint': 'dummy',
1394
+ 'watch.rebuild': 'dummy',
1395
+ 'watch.tsc': 'dummy',
1396
+ },
1397
+ jest: {
1398
+ ...this.originalPackageJson.jest,
1399
+ testPathIgnorePatterns: 'dummy',
1400
+ moduleNameMapper: 'dummy',
1401
+ },
1402
+ skill: 'dummy',
1403
+ }
1322
1404
  }
1323
1405
 
1324
1406
  private static get updatedPackageJson() {
1325
1407
  return JSON.stringify({
1326
- ...JSON.parse(this.originalPackageJson),
1408
+ ...this.originalPackageJson,
1327
1409
  name: this.scopedPackageName,
1328
1410
  description: this.description,
1329
1411
  type: 'module',
@@ -1339,7 +1421,38 @@ private static readonly settingsJsonFile = `{
1339
1421
  bugs: {
1340
1422
  url: `https://github.com/${this.gitNamespace}/${this.packageName}/issues`,
1341
1423
  },
1424
+ scripts: {
1425
+ ...this.originalPackageJson.scripts,
1426
+ 'build.ci': 'yarn run build.tsc && yarn run lint',
1427
+ 'build.dev':
1428
+ 'yarn run build.tsc --sourceMap ; yarn run lint ; prettier --write .',
1429
+ 'build.copy-files':
1430
+ "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
1431
+ 'build.tsc': 'yarn run build.copy-files && tsc',
1432
+ clean: 'yarn run clean.build',
1433
+ 'clean.all':
1434
+ 'yarn run clean.dependencies && yarn run clean.build',
1435
+ 'clean.build': 'rm -rf build/',
1436
+ 'clean.dependencies':
1437
+ 'rm -rf node_modules/ package-lock.json yarn.lock',
1438
+ 'fix.lint': "eslint --fix --cache '**/*.ts'",
1439
+ lint: "eslint --cache '**/*.ts'",
1440
+ rebuild:
1441
+ 'yarn run clean.all && yarn install && yarn run build.dev',
1442
+ 'update.dependencies': 'yarn run clean.dependencies && yarn',
1443
+ test: 'NODE_OPTIONS=--experimental-vm-modules jest',
1444
+ 'watch.build.dev':
1445
+ "tsc-watch --sourceMap --onCompilationComplete 'yarn run build.copy-files'",
1446
+ },
1342
1447
  dependencies: this.dependencies,
1448
+ jest: {
1449
+ ...this.originalPackageJson.jest,
1450
+ testEnvironment: 'node',
1451
+ testRunner: 'jest-circus/runner',
1452
+ testMatch: ['<rootDir>/build/__tests__/**/*.test.js?(x)'],
1453
+ testTimeout: 5000,
1454
+ maxWorkers: 4,
1455
+ },
1343
1456
  })
1344
1457
  }
1345
1458
 
@@ -1350,7 +1463,7 @@ private static readonly settingsJsonFile = `{
1350
1463
  types: [this.customType],
1351
1464
  },
1352
1465
  include: [this.customInclude],
1353
- customOption: this.customOption,
1466
+ customOption: this.customTsconfigOption,
1354
1467
  }
1355
1468
  }
1356
1469
 
@@ -365,6 +365,8 @@ export default prettierConfigNdx
365
365
  }
366
366
 
367
367
  private async updatePackageJsonFile() {
368
+ this.removeOldKeysFromPackageJson()
369
+
368
370
  const ordered = this.orderJsonKeys(this.updatedPackageJson, [
369
371
  'name',
370
372
  'version',
@@ -382,7 +384,6 @@ export default prettierConfigNdx
382
384
  'dependencies',
383
385
  'devDependencies',
384
386
  'jest',
385
- 'skill',
386
387
  ])
387
388
 
388
389
  await this.writeFile(
@@ -392,6 +393,42 @@ export default prettierConfigNdx
392
393
  )
393
394
  }
394
395
 
396
+ private removeOldKeysFromPackageJson() {
397
+ const keysToRemove = [
398
+ 'skill',
399
+ 'jest.testPathIgnorePatterns',
400
+ 'jest.moduleNameMapper',
401
+ 'scripts.build.resolve-paths',
402
+ 'scripts.lint.tsc',
403
+ 'scripts.post.watch.build',
404
+ 'scripts.resolve-paths.lint',
405
+ 'scripts.watch.rebuild',
406
+ 'scripts.watch.tsc',
407
+ ]
408
+
409
+ for (const key of keysToRemove) {
410
+ this.deleteByPath(this.originalPackageJson, key)
411
+ }
412
+ }
413
+
414
+ private deleteByPath(obj: any, path: string): void {
415
+ const dot = path.indexOf('.')
416
+
417
+ if (dot === -1) {
418
+ delete obj[path]
419
+ return
420
+ }
421
+
422
+ const parentKey = path.slice(0, dot)
423
+ const childKey = path.slice(dot + 1)
424
+
425
+ const parent = obj[parentKey]
426
+
427
+ if (parent) {
428
+ delete parent[childKey]
429
+ }
430
+ }
431
+
395
432
  private get updatedPackageJson() {
396
433
  return {
397
434
  ...this.originalPackageJson,
@@ -410,7 +447,38 @@ export default prettierConfigNdx
410
447
  bugs: {
411
448
  url: `https://github.com/${this.gitNamespace}/${this.packageName}/issues`,
412
449
  },
450
+ scripts: {
451
+ ...(this.originalPackageJson.scripts ?? {}),
452
+ 'build.ci': 'yarn run build.tsc && yarn run lint',
453
+ 'build.dev':
454
+ 'yarn run build.tsc --sourceMap ; yarn run lint ; prettier --write .',
455
+ 'build.copy-files':
456
+ "mkdir -p build && rsync -avzq --exclude='*.ts' ./src/ ./build/",
457
+ 'build.tsc': 'yarn run build.copy-files && tsc',
458
+ clean: 'yarn run clean.build',
459
+ 'clean.all':
460
+ 'yarn run clean.dependencies && yarn run clean.build',
461
+ 'clean.build': 'rm -rf build/',
462
+ 'clean.dependencies':
463
+ 'rm -rf node_modules/ package-lock.json yarn.lock',
464
+ 'fix.lint': "eslint --fix --cache '**/*.ts'",
465
+ lint: "eslint --cache '**/*.ts'",
466
+ rebuild:
467
+ 'yarn run clean.all && yarn install && yarn run build.dev',
468
+ 'update.dependencies': 'yarn run clean.dependencies && yarn',
469
+ test: 'NODE_OPTIONS=--experimental-vm-modules jest',
470
+ 'watch.build.dev':
471
+ "tsc-watch --sourceMap --onCompilationComplete 'yarn run build.copy-files'",
472
+ },
413
473
  dependencies: this.originalPackageJson.dependencies ?? {},
474
+ jest: {
475
+ ...(this.originalPackageJson.jest ?? {}),
476
+ testEnvironment: 'node',
477
+ testRunner: 'jest-circus/runner',
478
+ testMatch: ['<rootDir>/build/__tests__/**/*.test.js?(x)'],
479
+ testTimeout: 5000,
480
+ maxWorkers: 4,
481
+ },
414
482
  }
415
483
  }
416
484
 
@@ -681,6 +749,8 @@ export default prettierConfigNdx
681
749
  }
682
750
 
683
751
  private async installDefaultDevDependencies() {
752
+ await this.removeDefaultDevDependencies()
753
+
684
754
  const generateIdVersion = await this.getLatestVersion(
685
755
  '@neurodevs/generate-id'
686
756
  )
@@ -713,6 +783,15 @@ export default prettierConfigNdx
713
783
  }
714
784
  }
715
785
 
786
+ private async removeDefaultDevDependencies() {
787
+ console.log('Removing default devDependencies...')
788
+
789
+ await this.exec(
790
+ 'yarn remove eslint eslint-config-spruce prettier chokidar-cli ts-node @types/node',
791
+ { cwd: this.packageDir }
792
+ )
793
+ }
794
+
716
795
  private async getLatestVersion(scopedPackageName: string) {
717
796
  const { stdout } = await this.exec(
718
797
  `yarn info ${scopedPackageName} version --silent`,
@@ -831,7 +910,7 @@ export default prettierConfigNdx
831
910
  return ''
832
911
  }
833
912
  }
834
-
913
+
835
914
  private get eslintConfigIsUpToDate() {
836
915
  return this.originalEslintConfig.trim() === this.eslintConfigFile.trim()
837
916
  }
@@ -848,9 +927,13 @@ export default prettierConfigNdx
848
927
  if (!this.prettierConfigIsUpToDate) {
849
928
  console.log('Installing prettier.config.js...')
850
929
 
851
- await this.writeFile(this.prettierConfigPath, this.prettierConfigFile, {
852
- encoding: 'utf-8',
853
- })
930
+ await this.writeFile(
931
+ this.prettierConfigPath,
932
+ this.prettierConfigFile,
933
+ {
934
+ encoding: 'utf-8',
935
+ }
936
+ )
854
937
 
855
938
  await this.commitInstallPrettierConfigFile()
856
939
  }
@@ -867,7 +950,10 @@ export default prettierConfigNdx
867
950
  }
868
951
 
869
952
  private get prettierConfigIsUpToDate() {
870
- return this.originalPrettierConfig.trim() === this.prettierConfigFile.trim()
953
+ return (
954
+ this.originalPrettierConfig.trim() ===
955
+ this.prettierConfigFile.trim()
956
+ )
871
957
  }
872
958
 
873
959
  private async commitInstallPrettierConfigFile() {
@@ -882,14 +968,10 @@ export default prettierConfigNdx
882
968
  if (!this.settingsJsonIsUpToDate) {
883
969
  console.log('Installing .vscode/settings.json...')
884
970
 
885
- await this.writeFile(
886
- this.settingsJsonPath,
887
- this.settingsJsonFile,
888
- {
889
- encoding: 'utf-8',
890
- }
891
- )
892
-
971
+ await this.writeFile(this.settingsJsonPath, this.settingsJsonFile, {
972
+ encoding: 'utf-8',
973
+ })
974
+
893
975
  await this.commitInstallSettingsJsonFile()
894
976
  }
895
977
  }
package/tsconfig.json CHANGED
@@ -1,28 +1,25 @@
1
1
  {
2
- "compilerOptions": {
3
- "module": "nodenext",
4
- "moduleResolution": "nodenext",
5
- "target": "ES2022",
6
- "lib": ["ES2022"],
7
- "types": ["node"],
8
- "baseUrl": "src",
9
- "outDir": "build",
10
- "sourceMap": false,
11
- "strict": true,
12
- "noImplicitAny": true,
13
- "noImplicitReturns": true,
14
- "noUnusedLocals": true,
15
- "forceConsistentCasingInFileNames": true,
16
- "declaration": true,
17
- "skipLibCheck": true,
18
- "esModuleInterop": true,
19
- "moduleDetection": "force",
20
- "allowJs": true,
21
- "resolveJsonModule": true,
22
- "experimentalDecorators": true
23
- },
24
- "include": [
25
- "./src/*.ts",
26
- "./src/**/*.ts"
27
- ]
28
- }
2
+ "compilerOptions": {
3
+ "module": "nodenext",
4
+ "moduleResolution": "nodenext",
5
+ "target": "ES2022",
6
+ "lib": ["ES2022"],
7
+ "types": ["node"],
8
+ "baseUrl": "src",
9
+ "outDir": "build",
10
+ "sourceMap": false,
11
+ "strict": true,
12
+ "noImplicitAny": true,
13
+ "noImplicitReturns": true,
14
+ "noUnusedLocals": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "declaration": true,
17
+ "skipLibCheck": true,
18
+ "esModuleInterop": true,
19
+ "moduleDetection": "force",
20
+ "allowJs": true,
21
+ "resolveJsonModule": true,
22
+ "experimentalDecorators": true
23
+ },
24
+ "include": ["./src/*.ts", "./src/**/*.ts"]
25
+ }