cdk-real-drift 0.4.13 → 0.4.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/dist/cli.js CHANGED
@@ -5,7 +5,7 @@ import { dirname, join, resolve } from "node:path";
5
5
  import { YAMLSeq, isSeq, parse, parseDocument } from "yaml";
6
6
  import { CloudControlClient, DeleteResourceCommand, GetResourceCommand, GetResourceRequestStatusCommand, UpdateResourceCommand } from "@aws-sdk/client-cloudcontrol";
7
7
  import { homedir } from "node:os";
8
- import { BaseCredentials, CdkAppMultiContext, NonInteractiveIoHost, Toolkit } from "@aws-cdk/toolkit-lib";
8
+ import { BaseCredentials, CdkAppMultiContext, NonInteractiveIoHost, StackSelectionStrategy, Toolkit } from "@aws-cdk/toolkit-lib";
9
9
  import { CloudFormationClient, DescribeStackResourcesCommand, DescribeStacksCommand, DescribeTypeCommand, GetTemplateCommand, ListExportsCommand, ListStackResourcesCommand } from "@aws-sdk/client-cloudformation";
10
10
  import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
11
11
  import { APIGatewayClient, GetAuthorizersCommand, GetGatewayResponsesCommand, GetModelsCommand, GetRequestValidatorsCommand, GetResourcesCommand, UpdateIntegrationCommand, UpdateIntegrationResponseCommand, UpdateMethodResponseCommand, UpdateRestApiCommand } from "@aws-sdk/client-api-gateway";
@@ -951,6 +951,31 @@ function missingContextWarning(keys, opts = {}) {
951
951
 
952
952
  //#endregion
953
953
  //#region src/synth/synth.ts
954
+ /**
955
+ * Map the requested stack name(s)/glob(s) to the toolkit-lib `StackSelector` that scopes
956
+ * `toolkit.synth`'s metadata validation (#905).
957
+ *
958
+ * - No patterns (`undefined` / empty) → `undefined`: the caller wants EVERY stack (no-args
959
+ * discovery or `--all`), so we pass no selector and toolkit-lib defaults to `ALL_STACKS` —
960
+ * the pre-#905 behavior, unchanged. Everything is validated because the user asked for it.
961
+ * - One or more patterns → a `PATTERN_MATCH` selector over those patterns. toolkit-lib then
962
+ * validates ONLY the matched stacks, so a sibling stack the user did NOT target can fail a
963
+ * context lookup without aborting synth. `PATTERN_MATCH` (NOT `PATTERN_MUST_MATCH`) is
964
+ * deliberate: it halts successfully — never throws — when the patterns match zero stacks.
965
+ * The selector matches on the toolkit's HIERARCHICAL id (`Stage/Stack` for a staged stack)
966
+ * via picomatch, which can differ from the deployed stackName resolveStacks filters on, so
967
+ * a staged-stack pattern may legitimately match nothing here; that must not error. The
968
+ * real "unknown stack / no-match glob" errors stay in resolveStacks, checked against the
969
+ * FULL discovered stack list (this selector only narrows what gets VALIDATED, never what
970
+ * gets discovered — the returned assembly still carries every stack).
971
+ */
972
+ function buildStackSelector(patterns) {
973
+ if (!patterns || patterns.length === 0) return void 0;
974
+ return {
975
+ strategy: StackSelectionStrategy.PATTERN_MATCH,
976
+ patterns
977
+ };
978
+ }
954
979
  const CONCRETE_REGION = /^[a-z]{2}(-[a-z]+)+-\d+$/;
955
980
  /**
956
981
  * Build the stderr message body (no `warning:` prefix — the caller adds it) for the case where
@@ -1004,6 +1029,7 @@ function cleanupEmptyContextFile(file, existedBefore) {
1004
1029
  }
1005
1030
  async function synthApp(app, opts = {}) {
1006
1031
  const { region, profile, context = {} } = opts;
1032
+ const stackSelector = buildStackSelector(opts.stackPatterns);
1007
1033
  const toolkit = new Toolkit({
1008
1034
  ioHost: new QuietIoHost(),
1009
1035
  sdkConfig: { baseCredentials: BaseCredentials.awsCliCompatible({
@@ -1033,7 +1059,7 @@ async function synthApp(app, opts = {}) {
1033
1059
  ...hasOverrides && { contextStore: new CdkAppMultiContext(process.cwd(), context) }
1034
1060
  });
1035
1061
  }
1036
- const cached = await toolkit.synth(source);
1062
+ const cached = await toolkit.synth(source, stackSelector ? { stacks: stackSelector } : void 0);
1037
1063
  if (!isDir) cleanupEmptyContextFile(contextFile, contextFileExistedBefore);
1038
1064
  try {
1039
1065
  const missingKeys = missingContextKeys(collectMissingRecursively(cached.cloudAssembly));
@@ -1128,10 +1154,12 @@ async function resolveProfileRegion(profile) {
1128
1154
  async function resolveStacks(a) {
1129
1155
  const app = resolveApp(a.app);
1130
1156
  if (!app) throw new Error("cdkrd needs a CDK app: run in a directory with cdk.json, pass --app \"<cmd>\" or --app <cdk.out> (a pre-synthesized assembly), or set $CDKRD_APP");
1157
+ const scopePatterns = !a.all && a.stackNames.length > 0 ? a.stackNames : void 0;
1131
1158
  const discovered = await discoverStacks(app, {
1132
1159
  region: a.region,
1133
1160
  profile: a.profile,
1134
- context: a.context
1161
+ context: a.context,
1162
+ stackPatterns: scopePatterns
1135
1163
  });
1136
1164
  let fallbackRegion = a.region;
1137
1165
  if (!fallbackRegion && discovered.some((s) => !s.region)) {
@@ -4734,21 +4762,37 @@ function collectNestedUndeclared(declaredVal, liveVal, path, emit, nestedArrayId
4734
4762
  }
4735
4763
  }
4736
4764
  const PATH_UNSAFE_KEY = /[.[\]]/;
4737
- function sortUnorderedSetProps(model, resourceType, schemaObjectArrayKeys = []) {
4765
+ function sortScalarSet(v) {
4766
+ if (Array.isArray(v) && v.every((e) => typeof e === "string" || typeof e === "number" || typeof e === "boolean")) return [...v].sort((a, b) => `${typeof a}:${String(a)}` < `${typeof b}:${String(b)}` ? -1 : 1);
4767
+ return v;
4768
+ }
4769
+ function sortScalarSetAtNestedPath(model, segs) {
4770
+ if (segs.length === 0 || model === null || typeof model !== "object") return;
4771
+ const [head, ...rest] = segs;
4772
+ if (head === "*") {
4773
+ const children = Array.isArray(model) ? model : Object.values(model);
4774
+ for (const child of children) sortScalarSetAtNestedPath(child, rest);
4775
+ return;
4776
+ }
4777
+ if (Array.isArray(model)) return;
4778
+ const obj = model;
4779
+ if (!(head in obj)) return;
4780
+ if (rest.length === 0) obj[head] = sortScalarSet(obj[head]);
4781
+ else sortScalarSetAtNestedPath(obj[head], rest);
4782
+ }
4783
+ function sortUnorderedSetProps(model, resourceType, schemaObjectArrayKeys = [], schemaScalarPaths = []) {
4738
4784
  const objKeys = new Set([...UNORDERED_OBJECT_ARRAY_PROPS[resourceType] ?? [], ...schemaObjectArrayKeys]);
4739
4785
  const orderSig = ORDER_SIGNIFICANT_ARRAY_KEYS[resourceType];
4740
4786
  for (const k of objKeys) if (!orderSig?.has(k) && Array.isArray(model[k])) model[k] = sortUnorderedObjectArray(model[k]);
4741
- for (const k of UNORDERED_ARRAY_PROPS[resourceType] ?? []) {
4742
- const v = model[k];
4743
- if (Array.isArray(v) && v.every((e) => typeof e === "string" || typeof e === "number" || typeof e === "boolean")) model[k] = [...v].sort((a, b) => `${typeof a}:${String(a)}` < `${typeof b}:${String(b)}` ? -1 : 1);
4744
- }
4787
+ for (const path of [...UNORDERED_ARRAY_PROPS[resourceType] ?? [], ...schemaScalarPaths]) if (path.includes(".")) sortScalarSetAtNestedPath(model, path.split("."));
4788
+ else if (path in model) model[path] = sortScalarSet(model[path]);
4745
4789
  }
4746
4790
  function normalizeLiveModel(liveRaw, schema, opts = {}) {
4747
4791
  const oaiMap = opts.oaiCanonicalIds ?? {};
4748
4792
  const live = canonicalizeForCompare(rewriteOaiPrincipalsDeep(stripAwsTagsDeep(stripCcApiAwsManagedFields(liveRaw)), oaiMap), opts.resourceType);
4749
4793
  deepStripPaths(live, schema.readOnlyPaths);
4750
4794
  deepStripPaths(live, schema.writeOnlyPaths);
4751
- if (opts.resourceType) sortUnorderedSetProps(live, opts.resourceType, (schema.unorderedObjectArrayPaths ?? []).filter((p) => !p.includes(".")));
4795
+ if (opts.resourceType) sortUnorderedSetProps(live, opts.resourceType, (schema.unorderedObjectArrayPaths ?? []).filter((p) => !p.includes(".")), schema.unorderedScalarPaths ?? []);
4752
4796
  return live;
4753
4797
  }
4754
4798
  function remapSortedIndexToDeclared(path, arrayKey, sortedDeclared, rawDeclared) {
@@ -8346,6 +8390,10 @@ const readCodeBuildProject = async ({ physicalId, declared, region }) => {
8346
8390
  ...cache.location !== void 0 && { Location: cache.location },
8347
8391
  ...cache.modes?.length && { Modes: cache.modes }
8348
8392
  };
8393
+ if (Array.isArray(p.tags) && p.tags.length > 0) model.Tags = p.tags.map((t) => ({
8394
+ Key: t.key,
8395
+ Value: t.value
8396
+ }));
8349
8397
  return model;
8350
8398
  };
8351
8399
  const readServiceDiscoveryNamespace = async ({ physicalId, region }) => {
@@ -9319,6 +9367,11 @@ const CC_IDENTIFIER_ADAPTERS = {
9319
9367
  "AWS::ApiGatewayV2::Integration": compositeWith("ApiId"),
9320
9368
  "AWS::ApiGatewayV2::Model": compositeWith("ApiId"),
9321
9369
  "AWS::ApiGatewayV2::Deployment": compositeWith("ApiId"),
9370
+ "AWS::ApiGatewayV2::ApiMapping": (pid, declared) => {
9371
+ if (pid.includes("|")) return pid;
9372
+ const domainName = declared.DomainName;
9373
+ return typeof domainName === "string" && domainName.length > 0 ? `${pid}|${domainName}` : void 0;
9374
+ },
9322
9375
  "AWS::ApiGatewayV2::Authorizer": (pid, declared) => {
9323
9376
  if (pid.includes("|")) return pid;
9324
9377
  const apiId = declared.ApiId;
@@ -9364,6 +9417,12 @@ const CC_IDENTIFIER_ADAPTERS = {
9364
9417
  const restApiId = declared.RestApiId;
9365
9418
  return typeof restApiId === "string" && restApiId.length > 0 ? `${pid}|${restApiId}` : void 0;
9366
9419
  },
9420
+ "AWS::ApiGateway::BasePathMapping": (pid, declared) => {
9421
+ if (pid.includes("|")) return pid;
9422
+ const domainName = declared.DomainName;
9423
+ if (typeof domainName !== "string" || domainName.length === 0) return void 0;
9424
+ return `${domainName}|${typeof declared.BasePath === "string" ? declared.BasePath : ""}`;
9425
+ },
9367
9426
  "AWS::ApplicationAutoScaling::ScalingPolicy": scalingPolicyComposite,
9368
9427
  "AWS::ECS::Service": (pid, declared) => {
9369
9428
  if (pid.includes("|")) return pid;