@codedrifters/configulator 0.0.195 → 0.0.197

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
@@ -5586,8 +5586,14 @@ var TestRunner = {
5586
5586
  };
5587
5587
  var TypeScriptProject = class extends typescript.TypeScriptProject {
5588
5588
  constructor(userOptions) {
5589
- const pnpmVersion = userOptions.parent && userOptions.parent instanceof MonorepoProject ? userOptions.parent.pnpmVersion : VERSION.PNPM_VERSION;
5590
- const pnpmWorkspace = userOptions.parent && userOptions.parent instanceof MonorepoProject ? PnpmWorkspace.of(userOptions.parent) : void 0;
5589
+ if (!(userOptions.parent instanceof MonorepoProject)) {
5590
+ throw new Error(
5591
+ "TypeScriptProject must be parented to a MonorepoProject. Pass `parent: <MonorepoProject>` in the project options."
5592
+ );
5593
+ }
5594
+ const parent = userOptions.parent;
5595
+ const pnpmVersion = parent.pnpmVersion;
5596
+ const pnpmWorkspace = PnpmWorkspace.of(parent);
5591
5597
  const testRunner = userOptions.testRunner ?? TestRunner.JEST;
5592
5598
  const useJest = testRunner === TestRunner.JEST;
5593
5599
  const defaultOptions = {
@@ -5853,44 +5859,24 @@ var DEFAULT_INDEX_ASTRO = `---
5853
5859
  var DEFAULT_FAVICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><path d="M64 8a56 56 0 1 0 0 112A56 56 0 0 0 64 8Z" fill="#ff5d01"/></svg>
5854
5860
  `;
5855
5861
 
5856
- // src/typescript/typescript-config.ts
5857
- import { relative as relative4 } from "path";
5858
- import { Component as Component16 } from "projen";
5859
- import { ensureRelativePathStartsWithDot } from "projen/lib/util/path";
5860
- var TypeScriptConfig = class extends Component16 {
5861
- constructor(project) {
5862
- super(project);
5863
- let tsPaths = {};
5864
- const workspaceDeps = project.deps.all.filter(
5865
- (d) => d.version === "workspace:*"
5866
- );
5867
- workspaceDeps.forEach((dep) => {
5868
- const subproject = project.root.subprojects.find((p) => p.package.packageName === dep.name);
5869
- if (!subproject) {
5870
- throw new Error(`Could not find subproject ${dep.name} in monorepo.`);
5871
- }
5872
- tsPaths = {
5873
- ...tsPaths,
5874
- [dep.name]: [
5875
- ensureRelativePathStartsWithDot(
5876
- relative4(project.outdir, subproject.outdir)
5877
- )
5878
- ]
5879
- };
5880
- });
5881
- project.tsconfig?.file.addOverride("compilerOptions.paths", tsPaths);
5882
- project.tsconfigDev?.file.addOverride("compilerOptions.paths", tsPaths);
5883
- }
5884
- };
5862
+ // src/projects/aws-cdk-project.ts
5863
+ import { awscdk } from "projen";
5864
+ import {
5865
+ NodePackageManager as NodePackageManager3,
5866
+ Transform as Transform2,
5867
+ UpgradeDependenciesSchedule as UpgradeDependenciesSchedule3
5868
+ } from "projen/lib/javascript";
5869
+ import { ReleaseTrigger as ReleaseTrigger2 } from "projen/lib/release";
5870
+ import { merge as merge3 } from "ts-deepmerge";
5885
5871
 
5886
5872
  // src/workflows/aws-deploy-workflow.ts
5887
5873
  var import_utils11 = __toESM(require_lib());
5888
- import { Component as Component17 } from "projen";
5874
+ import { Component as Component16 } from "projen";
5889
5875
  import { BuildWorkflow } from "projen/lib/build";
5890
5876
  import { GitHub as GitHub2 } from "projen/lib/github";
5891
5877
  import { JobPermission as JobPermission5 } from "projen/lib/github/workflows-model";
5892
5878
  var PROD_DEPLOY_NAME = "prod-deploy";
5893
- var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component17 {
5879
+ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component16 {
5894
5880
  constructor(project, options = {}) {
5895
5881
  super(project);
5896
5882
  this.project = project;
@@ -6153,6 +6139,433 @@ var AwsDeployWorkflow = class _AwsDeployWorkflow extends Component17 {
6153
6139
  super.preSynthesize();
6154
6140
  }
6155
6141
  };
6142
+
6143
+ // src/workflows/aws-teardown-workflow.ts
6144
+ import { Component as Component17 } from "projen";
6145
+ import { GitHub as GitHub3, GithubWorkflow } from "projen/lib/github";
6146
+ import { JobPermission as JobPermission6 } from "projen/lib/github/workflows-model";
6147
+ var DEFAULT_TEARDOWN_BRANCH_PATTERNS = [
6148
+ "feat/*",
6149
+ "fix/*",
6150
+ "feature/*"
6151
+ ];
6152
+ var resolveBranchPatterns = (explicit, targets) => {
6153
+ if (explicit && explicit.length > 0) {
6154
+ return [...explicit];
6155
+ }
6156
+ const derived = Array.from(
6157
+ new Set(
6158
+ targets.flatMap((target) => target.branches.map((b) => b.branch)).filter((branch) => typeof branch === "string").filter((branch) => branch.includes("*"))
6159
+ )
6160
+ );
6161
+ if (derived.length > 0) {
6162
+ return derived;
6163
+ }
6164
+ return [...DEFAULT_TEARDOWN_BRANCH_PATTERNS];
6165
+ };
6166
+ var AwsTeardownWorkflow = class extends Component17 {
6167
+ constructor(rootProject, options) {
6168
+ super(rootProject);
6169
+ this.rootProject = rootProject;
6170
+ const {
6171
+ awsDestructionTargets,
6172
+ repoTagName,
6173
+ stageTypeTagName,
6174
+ environmentTypeTagName,
6175
+ branchNameTagName,
6176
+ deleteBranchPatterns
6177
+ } = options;
6178
+ if (!repoTagName) {
6179
+ throw new Error("AwsTeardownWorkflow requires `repoTagName`");
6180
+ }
6181
+ if (!stageTypeTagName) {
6182
+ throw new Error("AwsTeardownWorkflow requires `stageTypeTagName`");
6183
+ }
6184
+ if (!environmentTypeTagName) {
6185
+ throw new Error("AwsTeardownWorkflow requires `environmentTypeTagName`");
6186
+ }
6187
+ if (!branchNameTagName) {
6188
+ throw new Error("AwsTeardownWorkflow requires `branchNameTagName`");
6189
+ }
6190
+ if (!(rootProject instanceof MonorepoProject)) {
6191
+ throw new Error(
6192
+ "AwsTeardownWorkflow requires the root project to be a MonorepoProject"
6193
+ );
6194
+ }
6195
+ const github = GitHub3.of(this.rootProject);
6196
+ if (!github) {
6197
+ throw new Error(
6198
+ "AwsTeardownWorkflow requires a GitHub component in the root project"
6199
+ );
6200
+ }
6201
+ const branchPatterns = resolveBranchPatterns(
6202
+ deleteBranchPatterns,
6203
+ awsDestructionTargets
6204
+ );
6205
+ const workflow = new GithubWorkflow(github, "teardown-dev");
6206
+ workflow.on({
6207
+ workflowDispatch: {},
6208
+ schedule: [
6209
+ {
6210
+ cron: "32 6 * * *"
6211
+ }
6212
+ ],
6213
+ delete: {
6214
+ branches: branchPatterns
6215
+ }
6216
+ });
6217
+ awsDestructionTargets.forEach((target) => {
6218
+ const {
6219
+ awsStageType,
6220
+ deploymentTargetRole,
6221
+ account,
6222
+ region,
6223
+ ciDeploymentConfig
6224
+ } = target;
6225
+ const { roleArn } = ciDeploymentConfig ?? {};
6226
+ workflow.addJob(
6227
+ `teardown-${awsStageType}-${deploymentTargetRole}-${account}-${region}`.toLowerCase(),
6228
+ {
6229
+ name: `Teardown Stacks in ${awsStageType}/${deploymentTargetRole}/${account}/${region}`,
6230
+ runsOn: ["ubuntu-latest"],
6231
+ permissions: {
6232
+ contents: JobPermission6.READ,
6233
+ idToken: JobPermission6.WRITE
6234
+ },
6235
+ env: {
6236
+ REPO: "${{ github.repository }}",
6237
+ REGIONS: [region].join(" ")
6238
+ },
6239
+ steps: [
6240
+ {
6241
+ name: `AWS Creds ${account}/${region}`,
6242
+ uses: "aws-actions/configure-aws-credentials@v6",
6243
+ with: {
6244
+ "role-to-assume": roleArn,
6245
+ "aws-region": region,
6246
+ "role-duration-seconds": 900
6247
+ }
6248
+ },
6249
+ {
6250
+ name: "Fetch All Branches",
6251
+ id: "fetch_branches",
6252
+ uses: "actions/github-script@v9",
6253
+ with: {
6254
+ script: [
6255
+ "const all = await github.paginate(github.rest.repos.listBranches, {",
6256
+ " owner: context.repo.owner,",
6257
+ " repo: context.repo.repo,",
6258
+ " per_page: 100",
6259
+ "});",
6260
+ "const names = all.map(b => b.name);",
6261
+ "console.log(`Found branches: ${names}`);",
6262
+ 'core.setOutput("json", JSON.stringify(names));'
6263
+ ].join("\n")
6264
+ }
6265
+ },
6266
+ {
6267
+ name: "Save Branches to File",
6268
+ run: [
6269
+ 'echo "Saving branches to file"',
6270
+ "echo '${{ steps.fetch_branches.outputs.json }}' | jq -r '.[]' | sort -u > branches.txt",
6271
+ 'echo "Branches:"',
6272
+ "cat branches.txt"
6273
+ ].join("\n")
6274
+ },
6275
+ {
6276
+ name: "Find Stacks by Tag",
6277
+ id: "find_stacks",
6278
+ run: [
6279
+ "set -euo pipefail",
6280
+ ": > candidates.txt # columns: arn region branchTag",
6281
+ "# Build tag filters",
6282
+ `TAG_FILTERS=( "Key=${repoTagName},Values=$REPO" )`,
6283
+ `TAG_FILTERS+=( "Key=${stageTypeTagName},Values=${awsStageType}" )`,
6284
+ `TAG_FILTERS+=( "Key=${environmentTypeTagName},Values=${deploymentTargetRole}" )`,
6285
+ "for r in $REGIONS; do",
6286
+ ` echo "Scanning region: $r"`,
6287
+ " aws resourcegroupstaggingapi get-resources \\",
6288
+ ' --region "$r" \\',
6289
+ ' --resource-type-filters "cloudformation:stack" \\',
6290
+ ' --tag-filters "${TAG_FILTERS[@]}" \\',
6291
+ ` | jq -r --arg r "$r" '`,
6292
+ " .ResourceTagMappingList[]",
6293
+ " | . as $res",
6294
+ ` | ($res.Tags[] | select(.Key=="${branchNameTagName}") | .Value) as $branch`,
6295
+ ' | [$res.ResourceARN, $r, ($branch // "")]',
6296
+ " | @tsv",
6297
+ " ' >> candidates.txt",
6298
+ "done",
6299
+ "echo 'Tagged stacks:'",
6300
+ `(echo -e "ARN\\tREGION\\tBRANCH"; cat candidates.txt) | column -t -s $'\\t'`
6301
+ ].join("\n")
6302
+ },
6303
+ {
6304
+ name: "Determine Orphan Stacks (No Matching Branch)",
6305
+ run: [
6306
+ "set -euo pipefail",
6307
+ ": > orphans.txt # arn region branch",
6308
+ "while IFS=$'\\t' read -r arn region branch; do",
6309
+ ' [ -z "$arn" ] && continue',
6310
+ ' if [ -z "$branch" ]; then',
6311
+ " # If no Branch tag, treat as not-a-preview; skip",
6312
+ " continue",
6313
+ " fi",
6314
+ ' if ! grep -Fxq "$branch" branches.txt; then',
6315
+ ' echo -e "$arn\\t$region\\t$branch" >> orphans.txt',
6316
+ " fi",
6317
+ "done < candidates.txt",
6318
+ "",
6319
+ "if [ -s orphans.txt ]; then",
6320
+ ' echo "Orphan stacks (no matching branch):"',
6321
+ ` (echo -e "ARN\\tREGION\\tBRANCH"; cat orphans.txt) | column -t -s $'\\t'`,
6322
+ "else",
6323
+ ' echo "No orphan stacks found."',
6324
+ "fi"
6325
+ ].join("\n")
6326
+ },
6327
+ {
6328
+ name: "Delete Orphan Stacks",
6329
+ if: "hashFiles('orphans.txt') != ''",
6330
+ run: [
6331
+ "set -euo pipefail",
6332
+ "while IFS=$'\\t' read -r arn region branch; do",
6333
+ ' [ -z "$arn" ] && continue',
6334
+ ` stack_name=$(cut -d'/' -f2 <<<"$arn")`,
6335
+ ' echo "Deleting $stack_name (branch=$branch) in $region"',
6336
+ ' aws cloudformation delete-stack --region "$region" --stack-name "$stack_name" || true',
6337
+ "done < orphans.txt"
6338
+ ].join("\n")
6339
+ }
6340
+ ]
6341
+ }
6342
+ );
6343
+ });
6344
+ }
6345
+ };
6346
+
6347
+ // src/projects/aws-cdk-project.ts
6348
+ var AwsCdkProject = class extends awscdk.AwsCdkTypeScriptApp {
6349
+ constructor(userOptions) {
6350
+ if (!(userOptions.parent instanceof MonorepoProject)) {
6351
+ throw new Error(
6352
+ "AwsCdkProject must be parented to a MonorepoProject. Pass `parent: <MonorepoProject>` in the project options."
6353
+ );
6354
+ }
6355
+ const parent = userOptions.parent;
6356
+ const pnpmVersion = parent.pnpmVersion;
6357
+ const pnpmWorkspace = PnpmWorkspace.of(parent);
6358
+ const testRunner = userOptions.testRunner ?? TestRunner.JEST;
6359
+ const useJest = testRunner === TestRunner.JEST;
6360
+ const defaultOptions = {
6361
+ defaultReleaseBranch: "main",
6362
+ /**
6363
+ * Enable reset task by default.
6364
+ */
6365
+ resetTask: true,
6366
+ /**
6367
+ * Packaging options.
6368
+ */
6369
+ packageManager: NodePackageManager3.PNPM,
6370
+ pnpmVersion,
6371
+ licensed: userOptions.license !== void 0 || false,
6372
+ copyrightOwner: "CodeDrifters",
6373
+ release: false,
6374
+ /**
6375
+ * Don't add sample code.
6376
+ */
6377
+ sampleCode: false,
6378
+ /**
6379
+ * CDK versions sourced from the configulator-managed catalog.
6380
+ */
6381
+ cdkVersion: VERSION.AWS_CDK_LIB_VERSION,
6382
+ cdkCliVersion: VERSION.AWS_CDK_CLI_VERSION,
6383
+ ...useJest ? {
6384
+ /**
6385
+ * Make sure jest config is stored outside of package.json and use
6386
+ * SWC for faster compilation (matches TypeScriptProject).
6387
+ */
6388
+ jestOptions: {
6389
+ configFilePath: "jest.config.json",
6390
+ jestConfig: {
6391
+ roots: [`<rootDir>/src`],
6392
+ transform: {
6393
+ ["^.+\\.[t]sx?$"]: new Transform2("@swc/jest")
6394
+ },
6395
+ moduleFileExtensions: ["js", "ts"]
6396
+ }
6397
+ },
6398
+ devDeps: ["@swc/jest", "@swc/core"]
6399
+ } : {
6400
+ jest: false,
6401
+ devDeps: []
6402
+ },
6403
+ /**
6404
+ * Turn on prettier formatting.
6405
+ */
6406
+ prettier: true,
6407
+ /**
6408
+ * Don't package test files.
6409
+ */
6410
+ npmIgnoreOptions: {
6411
+ ignorePatterns: ["*.spec.*", "*.test.*"]
6412
+ },
6413
+ /**
6414
+ * Options for the automated dependency upgrade task / workflow.
6415
+ * Exclude any packages managed by the parent project's default catalog
6416
+ * so the catalog stays the source of truth.
6417
+ */
6418
+ depsUpgrade: true,
6419
+ depsUpgradeOptions: {
6420
+ workflow: false,
6421
+ exclude: Object.keys(pnpmWorkspace?.defaultCatalog || {}),
6422
+ workflowOptions: {
6423
+ schedule: UpgradeDependenciesSchedule3.WEEKLY
6424
+ },
6425
+ cooldown: 1
6426
+ },
6427
+ /**
6428
+ * Only release when the package source content or package.json changes.
6429
+ */
6430
+ releaseTrigger: ReleaseTrigger2.continuous({
6431
+ paths: [
6432
+ `${userOptions.outdir}/src/**`,
6433
+ `${userOptions.outdir}/package.json`
6434
+ ]
6435
+ })
6436
+ };
6437
+ const options = merge3(defaultOptions, userOptions);
6438
+ super(options);
6439
+ this.addDevDeps("@types/node@catalog:");
6440
+ this.tsconfig?.addExclude("**/*.test.*");
6441
+ this.tsconfig?.addExclude("**/*.spec.*");
6442
+ if (testRunner === TestRunner.VITEST) {
6443
+ new Vitest(this, {
6444
+ config: {
6445
+ include: ["src/**/*.{test,spec}.?(c|m)[jt]s?(x)"],
6446
+ ...options.vitestOptions?.config
6447
+ },
6448
+ ...options.vitestOptions
6449
+ });
6450
+ } else {
6451
+ this.deps.removeDependency("ts-jest");
6452
+ }
6453
+ this.package.file.addOverride(
6454
+ "packageManager",
6455
+ `pnpm@${options.pnpmVersion}`
6456
+ );
6457
+ this.eslint?.addOverride({
6458
+ files: ["**/*.test.*", "**/*.spec.*"],
6459
+ rules: {
6460
+ "import/no-extraneous-dependencies": "off"
6461
+ }
6462
+ });
6463
+ this.gitignore?.addPatterns(".DS_Store", "test-reports", "cdk.out");
6464
+ this.npmignore?.addPatterns("*.spec.*", "*.test.*", "__fixtures__");
6465
+ new AwsDeploymentConfig(this);
6466
+ (options.deploymentTargets ?? []).forEach(
6467
+ (targetOptions) => this.addDeploymentTarget(targetOptions)
6468
+ );
6469
+ const targetsForAutoDerive = AwsDeploymentConfig.of(this)?.awsDeploymentTargets ?? [];
6470
+ const deployWorkflows = options.deployWorkflows ?? Array.from(new Set(targetsForAutoDerive.map((t) => t.awsStageType))).map(
6471
+ (awsStageType) => ({
6472
+ awsStageType,
6473
+ buildWorkflow: options.sharedBuildWorkflow
6474
+ })
6475
+ );
6476
+ deployWorkflows.forEach(
6477
+ (workflowOptions) => new AwsDeployWorkflow(this, workflowOptions)
6478
+ );
6479
+ if (options.teardownWorkflow) {
6480
+ new AwsTeardownWorkflow(parent, options.teardownWorkflow);
6481
+ }
6482
+ const turboActive = TurboRepo.of(parent) !== void 0;
6483
+ if (turboActive) {
6484
+ const turbo = new TurboRepo(this);
6485
+ turbo.postCompileTask?.outputs.push("dist/**");
6486
+ turbo.postCompileTask?.inputs.push("src/**");
6487
+ }
6488
+ if (options.agentConfig === true || typeof options.agentConfig === "object") {
6489
+ new AgentConfig(
6490
+ this,
6491
+ typeof options.agentConfig === "object" ? options.agentConfig : {}
6492
+ );
6493
+ }
6494
+ if (options.resetTask !== false) {
6495
+ const defaultResetTaskOptions = {
6496
+ pathsToRemove: [
6497
+ "node_modules",
6498
+ "dist",
6499
+ "lib",
6500
+ "cdk.out",
6501
+ "coverage",
6502
+ "test-reports",
6503
+ ".turbo",
6504
+ "tsconfig.tsbuildinfo",
6505
+ this.artifactsDirectory
6506
+ ]
6507
+ };
6508
+ const userResetTaskOptions = options.resetTaskOptions ?? {};
6509
+ const resetTaskOptions = merge3(
6510
+ defaultResetTaskOptions,
6511
+ {
6512
+ ...userResetTaskOptions,
6513
+ pathsToRemove: [
6514
+ ...defaultResetTaskOptions.pathsToRemove ?? [],
6515
+ ...userResetTaskOptions.pathsToRemove ?? []
6516
+ ]
6517
+ }
6518
+ );
6519
+ new ResetTask(this, resetTaskOptions);
6520
+ }
6521
+ const originalResolve = this.package.resolveDepsAndWritePackageJson;
6522
+ this.package.installDependencies = () => {
6523
+ parent.requestInstallDependencies({
6524
+ resolveDepsAndWritePackageJson: () => originalResolve.apply(this.package)
6525
+ });
6526
+ };
6527
+ this.package.resolveDepsAndWritePackageJson = () => {
6528
+ };
6529
+ }
6530
+ /**
6531
+ * Add an AWS deployment target to this project after construction. The
6532
+ * target is registered on the existing `AwsDeploymentConfig` and immediately
6533
+ * available for `AwsDeployWorkflow` consumption.
6534
+ */
6535
+ addDeploymentTarget(options) {
6536
+ return new AwsDeploymentTarget(this, options);
6537
+ }
6538
+ };
6539
+
6540
+ // src/typescript/typescript-config.ts
6541
+ import { relative as relative4 } from "path";
6542
+ import { Component as Component18 } from "projen";
6543
+ import { ensureRelativePathStartsWithDot } from "projen/lib/util/path";
6544
+ var TypeScriptConfig = class extends Component18 {
6545
+ constructor(project) {
6546
+ super(project);
6547
+ let tsPaths = {};
6548
+ const workspaceDeps = project.deps.all.filter(
6549
+ (d) => d.version === "workspace:*"
6550
+ );
6551
+ workspaceDeps.forEach((dep) => {
6552
+ const subproject = project.root.subprojects.find((p) => p.package.packageName === dep.name);
6553
+ if (!subproject) {
6554
+ throw new Error(`Could not find subproject ${dep.name} in monorepo.`);
6555
+ }
6556
+ tsPaths = {
6557
+ ...tsPaths,
6558
+ [dep.name]: [
6559
+ ensureRelativePathStartsWithDot(
6560
+ relative4(project.outdir, subproject.outdir)
6561
+ )
6562
+ ]
6563
+ };
6564
+ });
6565
+ project.tsconfig?.file.addOverride("compilerOptions.paths", tsPaths);
6566
+ project.tsconfigDev?.file.addOverride("compilerOptions.paths", tsPaths);
6567
+ }
6568
+ };
6156
6569
  export {
6157
6570
  AGENT_MODEL,
6158
6571
  AGENT_PLATFORM,
@@ -6161,14 +6574,17 @@ export {
6161
6574
  AstroConfig,
6162
6575
  AstroOutput,
6163
6576
  AstroProject,
6577
+ AwsCdkProject,
6164
6578
  AwsDeployWorkflow,
6165
6579
  AwsDeploymentConfig,
6166
6580
  AwsDeploymentTarget,
6581
+ AwsTeardownWorkflow,
6167
6582
  BUILT_IN_BUNDLES,
6168
6583
  CLAUDE_RULE_TARGET,
6169
6584
  COMPLETE_JOB_ID,
6170
6585
  DEFAULT_PRIORITY_LABELS,
6171
6586
  DEFAULT_STATUS_LABELS,
6587
+ DEFAULT_TEARDOWN_BRANCH_PATTERNS,
6172
6588
  DEFAULT_TYPE_LABELS,
6173
6589
  JsiiFaker,
6174
6590
  MCP_TRANSPORT,