@go-to-k/cdkd 0.16.0 → 0.16.1

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
@@ -1008,11 +1008,27 @@ async function resolveStateBucketWithDefaultAndSource(cliBucket, region) {
1008
1008
  const legacyName = getLegacyStateBucketName(accountId, region);
1009
1009
  const probe = new S3Client11({ region: "us-east-1" });
1010
1010
  try {
1011
- if (await bucketExists(probe, newName)) {
1011
+ const newExists = await bucketExists(probe, newName);
1012
+ const legacyExists = await bucketExists(probe, legacyName);
1013
+ if (newExists && legacyExists) {
1014
+ const newHasState = await bucketHasAnyState(probe, newName);
1015
+ if (!newHasState) {
1016
+ const legacyHasState = await bucketHasAnyState(probe, legacyName);
1017
+ if (legacyHasState) {
1018
+ logger.warn(
1019
+ `Both '${newName}' (new default) and '${legacyName}' (legacy default) exist, but the new bucket is empty and the legacy one has state. Reading from legacy. Run \`cdkd state migrate --region ${region}\` to copy the state into the new bucket and stop seeing this warning.`
1020
+ );
1021
+ return { bucket: legacyName, source: "default-legacy" };
1022
+ }
1023
+ }
1012
1024
  logger.debug(`State bucket: ${newName}`);
1013
1025
  return { bucket: newName, source: "default" };
1014
1026
  }
1015
- if (await bucketExists(probe, legacyName)) {
1027
+ if (newExists) {
1028
+ logger.debug(`State bucket: ${newName}`);
1029
+ return { bucket: newName, source: "default" };
1030
+ }
1031
+ if (legacyExists) {
1016
1032
  logger.warn(
1017
1033
  `Using legacy state bucket name '${legacyName}'. The default has changed to '${newName}'. To migrate, run:
1018
1034
 
@@ -1029,6 +1045,21 @@ async function resolveStateBucketWithDefaultAndSource(cliBucket, region) {
1029
1045
  probe.destroy();
1030
1046
  }
1031
1047
  }
1048
+ async function bucketHasAnyState(client, bucketName) {
1049
+ const { ListObjectsV2Command: ListObjectsV2Command5 } = await import("@aws-sdk/client-s3");
1050
+ try {
1051
+ const resp = await client.send(
1052
+ new ListObjectsV2Command5({
1053
+ Bucket: bucketName,
1054
+ Prefix: "cdkd/",
1055
+ MaxKeys: 1
1056
+ })
1057
+ );
1058
+ return (resp.KeyCount ?? 0) > 0;
1059
+ } catch {
1060
+ return true;
1061
+ }
1062
+ }
1032
1063
  async function bucketExists(client, bucketName) {
1033
1064
  const { HeadBucketCommand: HeadBucketCommand5 } = await import("@aws-sdk/client-s3");
1034
1065
  try {
@@ -31630,7 +31661,7 @@ function reorderArgs(argv) {
31630
31661
  }
31631
31662
  async function main() {
31632
31663
  const program = new Command12();
31633
- program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.16.0");
31664
+ program.name("cdkd").description("CDK Direct - Deploy AWS CDK apps directly via SDK/Cloud Control API").version("0.16.1");
31634
31665
  program.addCommand(createBootstrapCommand());
31635
31666
  program.addCommand(createSynthCommand());
31636
31667
  program.addCommand(createListCommand());