@codedrifters/configulator 0.0.121 → 0.0.123

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/lib/index.mjs CHANGED
@@ -746,7 +746,8 @@ var VERSION_NPM_PACKAGES = [
746
746
  { key: "AWS_CONSTRUCTS_VERSION", npmPackage: "constructs" },
747
747
  { key: "PNPM_VERSION", npmPackage: "pnpm" },
748
748
  { key: "PROJEN_VERSION", npmPackage: "projen" },
749
- { key: "TURBO_VERSION", npmPackage: "turbo" }
749
+ { key: "TURBO_VERSION", npmPackage: "turbo" },
750
+ { key: "VITEST_VERSION", npmPackage: "vitest" }
750
751
  ];
751
752
  var VERSION_KEYS_SKIP = ["NODE_WORKFLOWS"];
752
753
 
@@ -783,7 +784,11 @@ var VERSION = {
783
784
  /**
784
785
  * What version of the turborepo library should we use?
785
786
  */
786
- TURBO_VERSION: "2.8.13"
787
+ TURBO_VERSION: "2.8.13",
788
+ /**
789
+ * What version of Vitest to use when testRunner is 'vitest'.
790
+ */
791
+ VITEST_VERSION: "4.0.18"
787
792
  };
788
793
 
789
794
  // src/jsii/jsii-faker.ts
@@ -933,7 +938,7 @@ import {
933
938
  import { merge as merge2 } from "ts-deepmerge";
934
939
 
935
940
  // src/tasks/reset-task.ts
936
- import { Component as Component7 } from "projen";
941
+ import { Component as Component8 } from "projen";
937
942
 
938
943
  // src/projects/typescript-project.ts
939
944
  import { typescript } from "projen";
@@ -944,10 +949,104 @@ import {
944
949
  } from "projen/lib/javascript";
945
950
  import { ReleaseTrigger } from "projen/lib/release";
946
951
  import { merge } from "ts-deepmerge";
952
+
953
+ // src/vitest/vitest-component.ts
954
+ import { Component as Component7 } from "projen";
955
+ import { Jest } from "projen/lib/javascript";
956
+ import { TextFile } from "projen/lib/textfile";
957
+ var Vitest = class _Vitest extends Component7 {
958
+ constructor(project, options = {}) {
959
+ super(project);
960
+ this.project = project;
961
+ this.configFilePath = options.configFilePath ?? "vitest.config.ts";
962
+ const config = options.config ?? {};
963
+ this.include = config.include ?? ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
964
+ this.exclude = config.exclude ?? [
965
+ "**/node_modules/**",
966
+ "**/dist/**",
967
+ "**/lib/**",
968
+ "**/.?*"
969
+ ];
970
+ this.environment = config.environment ?? "node";
971
+ this.passWithNoTests = config.passWithNoTests ?? true;
972
+ this.coverageEnabled = config.coverageEnabled ?? true;
973
+ this.coverageDirectory = config.coverageDirectory ?? "coverage";
974
+ this.coverageReporters = config.coverageReporters ?? ["text", "lcov"];
975
+ this.version = options.vitestVersion ?? VERSION.VITEST_VERSION;
976
+ project.addDevDeps(`vitest@${this.version}`);
977
+ if (this.coverageEnabled) {
978
+ project.addDevDeps(`@vitest/coverage-v8@${this.version}`);
979
+ }
980
+ const coveragePath = `/${this.coverageDirectory}/`;
981
+ project.gitignore.addPatterns(coveragePath);
982
+ project.npmignore?.exclude(coveragePath);
983
+ this.addTestTasks();
984
+ this.synthesizeConfig();
985
+ }
986
+ /**
987
+ * Find the Vitest component on a project.
988
+ */
989
+ static of(project) {
990
+ const isVitest = (c) => c instanceof _Vitest;
991
+ return project.components.find(isVitest);
992
+ }
993
+ preSynthesize() {
994
+ super.preSynthesize();
995
+ for (const component of this.project.components) {
996
+ if (component instanceof Jest) {
997
+ throw new Error("Vitest cannot be used together with Jest");
998
+ }
999
+ }
1000
+ }
1001
+ addTestTasks() {
1002
+ this.project.testTask.exec("vitest run --update");
1003
+ if (!this.project.tasks.tryFind("test:watch")) {
1004
+ this.project.addTask("test:watch", {
1005
+ description: "Run tests in watch mode",
1006
+ exec: "vitest watch",
1007
+ receiveArgs: true
1008
+ });
1009
+ }
1010
+ }
1011
+ synthesizeConfig() {
1012
+ this.project.tryRemoveFile(this.configFilePath);
1013
+ new TextFile(this, this.configFilePath, {
1014
+ lines: this.renderConfig()
1015
+ });
1016
+ }
1017
+ renderConfig() {
1018
+ return [
1019
+ 'import { defineConfig } from "vitest/config";',
1020
+ "",
1021
+ "export default defineConfig({",
1022
+ " test: {",
1023
+ ` include: ${JSON.stringify(this.include)},`,
1024
+ ` exclude: ${JSON.stringify(this.exclude)},`,
1025
+ ` environment: "${this.environment}",`,
1026
+ ` passWithNoTests: ${this.passWithNoTests},`,
1027
+ " coverage: {",
1028
+ ` enabled: ${this.coverageEnabled},`,
1029
+ ` provider: "v8",`,
1030
+ ` reportsDirectory: "${this.coverageDirectory}",`,
1031
+ ` reporter: ${JSON.stringify(this.coverageReporters)},`,
1032
+ " },",
1033
+ " },",
1034
+ "});"
1035
+ ];
1036
+ }
1037
+ };
1038
+
1039
+ // src/projects/typescript-project.ts
1040
+ var TestRunner = {
1041
+ JEST: "jest",
1042
+ VITEST: "vitest"
1043
+ };
947
1044
  var TypeScriptProject = class extends typescript.TypeScriptProject {
948
1045
  constructor(userOptions) {
949
1046
  const pnpmVersion = userOptions.parent && userOptions.parent instanceof MonorepoProject ? userOptions.parent.pnpmVersion : VERSION.PNPM_VERSION;
950
1047
  const pnpmWorkspace = userOptions.parent && userOptions.parent instanceof MonorepoProject ? PnpmWorkspace.of(userOptions.parent) : void 0;
1048
+ const testRunner = userOptions.testRunner ?? TestRunner.JEST;
1049
+ const useJest = testRunner === TestRunner.JEST;
951
1050
  const defaultOptions = {
952
1051
  /**
953
1052
  * This is a standard, so don't require it to passed in everywhere.
@@ -969,27 +1068,32 @@ var TypeScriptProject = class extends typescript.TypeScriptProject {
969
1068
  * Don't add sample code.
970
1069
  */
971
1070
  sampleCode: false,
972
- /**
973
- * Make sure jest config is stored outside of package.json
974
- */
975
- jestOptions: {
976
- configFilePath: "jest.config.json",
977
- jestConfig: {
978
- roots: [`<rootDir>/src`],
979
- transform: {
980
- ["^.+\\.[t]sx?$"]: new Transform("@swc/jest")
981
- },
982
- moduleFileExtensions: ["js", "ts"]
983
- }
1071
+ ...useJest ? {
1072
+ /**
1073
+ * Make sure jest config is stored outside of package.json
1074
+ */
1075
+ jestOptions: {
1076
+ configFilePath: "jest.config.json",
1077
+ jestConfig: {
1078
+ roots: [`<rootDir>/src`],
1079
+ transform: {
1080
+ ["^.+\\.[t]sx?$"]: new Transform("@swc/jest")
1081
+ },
1082
+ moduleFileExtensions: ["js", "ts"]
1083
+ }
1084
+ },
1085
+ /**
1086
+ * SWC for faster testing
1087
+ */
1088
+ devDeps: ["@swc/jest", "@swc/core"]
1089
+ } : {
1090
+ jest: false,
1091
+ devDeps: []
984
1092
  },
985
1093
  /**
986
1094
  * Turn on prettier formatting
987
1095
  */
988
1096
  prettier: true,
989
- /**
990
- * SWC for faster testing
991
- */
992
- devDeps: ["@swc/jest", "@swc/core"],
993
1097
  /**
994
1098
  * Don't package test files.
995
1099
  */
@@ -1026,7 +1130,19 @@ var TypeScriptProject = class extends typescript.TypeScriptProject {
1026
1130
  };
1027
1131
  const options = merge(defaultOptions, userOptions);
1028
1132
  super(options);
1029
- this.deps.removeDependency("ts-jest");
1133
+ this.tsconfig?.addExclude("**/*.test.*");
1134
+ this.tsconfig?.addExclude("**/*.spec.*");
1135
+ if (options.testRunner === TestRunner.VITEST) {
1136
+ new Vitest(this, {
1137
+ config: {
1138
+ include: ["src/**/*.{test,spec}.?(c|m)[jt]s?(x)"],
1139
+ ...options.vitestOptions?.config
1140
+ },
1141
+ ...options.vitestOptions
1142
+ });
1143
+ } else {
1144
+ this.deps.removeDependency("ts-jest");
1145
+ }
1030
1146
  this.package.file.addOverride(
1031
1147
  "packageManager",
1032
1148
  `pnpm@${options.pnpmVersion}`
@@ -1037,7 +1153,7 @@ var TypeScriptProject = class extends typescript.TypeScriptProject {
1037
1153
  "import/no-extraneous-dependencies": "off"
1038
1154
  }
1039
1155
  });
1040
- this.gitignore?.addPatterns(".DS_Store");
1156
+ this.gitignore?.addPatterns(".DS_Store", "test-reports");
1041
1157
  this.npmignore?.addPatterns("*.spec.*", "*.test.*", "__fixtures__");
1042
1158
  const turboActive = userOptions.parent && TurboRepo.of(userOptions.parent) !== void 0;
1043
1159
  if (turboActive) {
@@ -1085,7 +1201,7 @@ var TypeScriptProject = class extends typescript.TypeScriptProject {
1085
1201
  };
1086
1202
 
1087
1203
  // src/tasks/reset-task.ts
1088
- var ResetTask = class _ResetTask extends Component7 {
1204
+ var ResetTask = class _ResetTask extends Component8 {
1089
1205
  constructor(project, options = {}) {
1090
1206
  super(project);
1091
1207
  this.project = project;
@@ -1158,8 +1274,8 @@ var ResetTask = class _ResetTask extends Component7 {
1158
1274
  };
1159
1275
 
1160
1276
  // src/vscode/vscode.ts
1161
- import { Component as Component8, vscode } from "projen";
1162
- var VSCodeConfig = class extends Component8 {
1277
+ import { Component as Component9, vscode } from "projen";
1278
+ var VSCodeConfig = class extends Component9 {
1163
1279
  constructor(project) {
1164
1280
  super(project);
1165
1281
  const vsConfig = new vscode.VsCode(project);
@@ -1356,10 +1472,22 @@ var MonorepoProject = class extends TypeScriptAppProject {
1356
1472
  new PnpmWorkspace(this, options.pnpmOptions?.pnpmWorkspaceOptions);
1357
1473
  if (options.turbo) {
1358
1474
  new TurboRepo(this, options.turboOptions);
1359
- this.buildWorkflow?.addPostBuildSteps({
1360
- name: "Build Sub Projects",
1361
- run: `npx projen ${ROOT_CI_TASK_NAME}`
1362
- });
1475
+ this.buildWorkflow?.addPostBuildSteps(
1476
+ {
1477
+ name: "Build Sub Projects",
1478
+ run: `npx projen ${ROOT_CI_TASK_NAME}`
1479
+ },
1480
+ {
1481
+ name: "Upload Turbo runs",
1482
+ if: "always()",
1483
+ uses: "actions/upload-artifact@v4.6.2",
1484
+ with: {
1485
+ name: "turbo-runs",
1486
+ path: ".turbo/runs"
1487
+ },
1488
+ continueOnError: true
1489
+ }
1490
+ );
1363
1491
  }
1364
1492
  if (options.resetTask !== false) {
1365
1493
  const defaultResetTaskOptions = {
@@ -1382,7 +1510,7 @@ var MonorepoProject = class extends TypeScriptAppProject {
1382
1510
  "packageManager",
1383
1511
  `pnpm@${options.pnpmVersion}`
1384
1512
  );
1385
- this.gitignore?.addPatterns(".DS_Store");
1513
+ this.gitignore?.addPatterns(".DS_Store", "test-reports");
1386
1514
  this.addDevDeps("constructs@catalog:");
1387
1515
  if (options.upgradeConfigulatorTask === true) {
1388
1516
  this.upgradeConfigulatorTask = new UpgradeDependencies(
@@ -1432,9 +1560,9 @@ var MonorepoProject = class extends TypeScriptAppProject {
1432
1560
 
1433
1561
  // src/typescript/typescript-config.ts
1434
1562
  import { relative as relative3 } from "path";
1435
- import { Component as Component9 } from "projen";
1563
+ import { Component as Component10 } from "projen";
1436
1564
  import { ensureRelativePathStartsWithDot } from "projen/lib/util/path";
1437
- var TypeScriptConfig = class extends Component9 {
1565
+ var TypeScriptConfig = class extends Component10 {
1438
1566
  constructor(project) {
1439
1567
  super(project);
1440
1568
  let tsPaths = {};
@@ -1462,12 +1590,12 @@ var TypeScriptConfig = class extends Component9 {
1462
1590
 
1463
1591
  // src/workflows/aws-deploy-workflow.ts
1464
1592
  var import_utils3 = __toESM(require_lib());
1465
- import { Component as Component10 } from "projen";
1593
+ import { Component as Component11 } from "projen";
1466
1594
  import { BuildWorkflow } from "projen/lib/build";
1467
1595
  import { GitHub } from "projen/lib/github";
1468
1596
  import { JobPermission as JobPermission2 } from "projen/lib/github/workflows-model";
1469
1597
  var PROD_DEPLOY_NAME = "prod-deploy";
1470
- var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component10 {
1598
+ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component11 {
1471
1599
  constructor(project, options = {}) {
1472
1600
  super(project);
1473
1601
  this.project = project;
@@ -1709,10 +1837,22 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component10 {
1709
1837
  }
1710
1838
  preSynthesize() {
1711
1839
  if (!this.externalWorkflow && TurboRepo.of(this.rootProject)) {
1712
- this.buildWorkflow.addPostBuildSteps({
1713
- name: "Build Sub Projects",
1714
- run: `npx projen ${ROOT_CI_TASK_NAME}`
1715
- });
1840
+ this.buildWorkflow.addPostBuildSteps(
1841
+ {
1842
+ name: "Build Sub Projects",
1843
+ run: `npx projen ${ROOT_CI_TASK_NAME}`
1844
+ },
1845
+ {
1846
+ name: "Upload Turbo runs",
1847
+ if: "always()",
1848
+ uses: "actions/upload-artifact@v4.6.2",
1849
+ with: {
1850
+ name: "turbo-runs",
1851
+ path: ".turbo/runs"
1852
+ },
1853
+ continueOnError: true
1854
+ }
1855
+ );
1716
1856
  }
1717
1857
  super.preSynthesize();
1718
1858
  }
@@ -1729,6 +1869,7 @@ export {
1729
1869
  ROOT_CI_TASK_NAME,
1730
1870
  ROOT_TURBO_TASK_NAME,
1731
1871
  ResetTask,
1872
+ TestRunner,
1732
1873
  TurboRepo,
1733
1874
  TurboRepoTask,
1734
1875
  TypeScriptConfig,
@@ -1737,6 +1878,7 @@ export {
1737
1878
  VERSION_KEYS_SKIP,
1738
1879
  VERSION_NPM_PACKAGES,
1739
1880
  VSCodeConfig,
1881
+ Vitest,
1740
1882
  getLatestEligibleVersion
1741
1883
  };
1742
1884
  //# sourceMappingURL=index.mjs.map