sst 2.48.5 → 2.49.2

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.
@@ -0,0 +1,89 @@
1
+ export declare const PROJECT_CONFIG = "cdk.json";
2
+ export declare const USER_DEFAULTS = "~/.cdk.json";
3
+ export declare enum Command {
4
+ LS = "ls",
5
+ LIST = "list",
6
+ DIFF = "diff",
7
+ BOOTSTRAP = "bootstrap",
8
+ DEPLOY = "deploy",
9
+ DESTROY = "destroy",
10
+ SYNTHESIZE = "synthesize",
11
+ SYNTH = "synth",
12
+ METADATA = "metadata",
13
+ INIT = "init",
14
+ VERSION = "version",
15
+ WATCH = "watch",
16
+ GC = "gc",
17
+ ROLLBACK = "rollback",
18
+ IMPORT = "import",
19
+ ACKNOWLEDGE = "acknowledge",
20
+ ACK = "ack",
21
+ NOTICES = "notices",
22
+ MIGRATE = "migrate",
23
+ CONTEXT = "context",
24
+ DOCS = "docs",
25
+ DOC = "doc",
26
+ DOCTOR = "doctor",
27
+ REFACTOR = "refactor",
28
+ DRIFT = "drift"
29
+ }
30
+ export type Arguments = {
31
+ readonly _: [Command, ...string[]];
32
+ readonly exclusively?: boolean;
33
+ readonly STACKS?: string[];
34
+ readonly lookups?: boolean;
35
+ readonly [name: string]: unknown;
36
+ };
37
+ export interface ConfigurationProps {
38
+ /**
39
+ * Configuration passed via command line arguments
40
+ *
41
+ * @default - Nothing passed
42
+ */
43
+ readonly commandLineArguments?: Arguments;
44
+ /**
45
+ * Whether or not to use context from `.cdk.json` in user home directory
46
+ *
47
+ * @default true
48
+ */
49
+ readonly readUserContext?: boolean;
50
+ }
51
+ /**
52
+ * All sources of settings combined
53
+ */
54
+ export declare class Configuration {
55
+ private readonly props;
56
+ settings: any;
57
+ context: any;
58
+ readonly defaultConfig: any;
59
+ private readonly commandLineArguments;
60
+ private readonly commandLineContext;
61
+ private _projectConfig?;
62
+ private _projectContext?;
63
+ private loaded;
64
+ constructor(props?: ConfigurationProps);
65
+ private get projectConfig();
66
+ get projectContext(): any;
67
+ /**
68
+ * Load all config
69
+ */
70
+ load(): Promise<this>;
71
+ /**
72
+ * Save the project context
73
+ */
74
+ saveContext(): Promise<this>;
75
+ }
76
+ /**
77
+ * Parse CLI arguments into Settings
78
+ *
79
+ * CLI arguments in must be accessed in the CLI code via
80
+ * `configuration.settings.get(['argName'])` instead of via `args.argName`.
81
+ *
82
+ * The advantage is that they can be configured via `cdk.json` and
83
+ * `$HOME/.cdk.json`. Arguments not listed below and accessed via this object
84
+ * can only be specified on the command line.
85
+ *
86
+ * @param argv - the received CLI arguments.
87
+ * @returns a new Settings object.
88
+ */
89
+ export declare function commandLineArgumentsToSettings(argv: Arguments): any;
@@ -0,0 +1,311 @@
1
+ // @ts-nocheck
2
+ import * as os from "os";
3
+ import * as fs_path from "path";
4
+ import * as fs from "fs";
5
+ export const PROJECT_CONFIG = "cdk.json";
6
+ export const USER_DEFAULTS = "~/.cdk.json";
7
+ const CONTEXT_KEY = "context";
8
+ const cdkToolkitUrl = await import.meta.resolve("@aws-cdk/toolkit-lib");
9
+ const cdkToolkitPath = new URL(cdkToolkitUrl).pathname;
10
+ const { ToolkitError } = await import(cdkToolkitPath);
11
+ const { Context, PROJECT_CONTEXT } = await import(fs_path.resolve(cdkToolkitPath, "..", "api", "context.js"));
12
+ const { Settings } = await import(fs_path.resolve(cdkToolkitPath, "..", "api", "settings.js"));
13
+ const { Tags } = await import(fs_path.resolve(cdkToolkitPath, "..", "api", "tags", "index.js"));
14
+ export var Command;
15
+ (function (Command) {
16
+ Command["LS"] = "ls";
17
+ Command["LIST"] = "list";
18
+ Command["DIFF"] = "diff";
19
+ Command["BOOTSTRAP"] = "bootstrap";
20
+ Command["DEPLOY"] = "deploy";
21
+ Command["DESTROY"] = "destroy";
22
+ Command["SYNTHESIZE"] = "synthesize";
23
+ Command["SYNTH"] = "synth";
24
+ Command["METADATA"] = "metadata";
25
+ Command["INIT"] = "init";
26
+ Command["VERSION"] = "version";
27
+ Command["WATCH"] = "watch";
28
+ Command["GC"] = "gc";
29
+ Command["ROLLBACK"] = "rollback";
30
+ Command["IMPORT"] = "import";
31
+ Command["ACKNOWLEDGE"] = "acknowledge";
32
+ Command["ACK"] = "ack";
33
+ Command["NOTICES"] = "notices";
34
+ Command["MIGRATE"] = "migrate";
35
+ Command["CONTEXT"] = "context";
36
+ Command["DOCS"] = "docs";
37
+ Command["DOC"] = "doc";
38
+ Command["DOCTOR"] = "doctor";
39
+ Command["REFACTOR"] = "refactor";
40
+ Command["DRIFT"] = "drift";
41
+ })(Command || (Command = {}));
42
+ const BUNDLING_COMMANDS = [
43
+ Command.DEPLOY,
44
+ Command.DIFF,
45
+ Command.SYNTH,
46
+ Command.SYNTHESIZE,
47
+ Command.WATCH,
48
+ Command.IMPORT,
49
+ ];
50
+ /**
51
+ * All sources of settings combined
52
+ */
53
+ export class Configuration {
54
+ props;
55
+ settings = new Settings();
56
+ context = new Context();
57
+ defaultConfig = new Settings({
58
+ versionReporting: true,
59
+ assetMetadata: true,
60
+ pathMetadata: true,
61
+ output: "cdk.out",
62
+ });
63
+ commandLineArguments;
64
+ commandLineContext;
65
+ _projectConfig;
66
+ _projectContext;
67
+ loaded = false;
68
+ constructor(props = {}) {
69
+ this.props = props;
70
+ this.commandLineArguments = props.commandLineArguments
71
+ ? commandLineArgumentsToSettings(props.commandLineArguments)
72
+ : new Settings();
73
+ this.commandLineContext = this.commandLineArguments
74
+ .subSettings([CONTEXT_KEY])
75
+ .makeReadOnly();
76
+ }
77
+ get projectConfig() {
78
+ if (!this._projectConfig) {
79
+ throw new ToolkitError("#load has not been called yet!");
80
+ }
81
+ return this._projectConfig;
82
+ }
83
+ get projectContext() {
84
+ if (!this._projectContext) {
85
+ throw new ToolkitError("#load has not been called yet!");
86
+ }
87
+ return this._projectContext;
88
+ }
89
+ /**
90
+ * Load all config
91
+ */
92
+ async load() {
93
+ const userConfig = await loadAndLog(USER_DEFAULTS);
94
+ this._projectConfig = await loadAndLog(PROJECT_CONFIG);
95
+ this._projectContext = await loadAndLog(PROJECT_CONTEXT);
96
+ // @todo cannot currently be disabled by cli users
97
+ const readUserContext = this.props.readUserContext ?? true;
98
+ if (userConfig.get(["build"])) {
99
+ throw new ToolkitError("The `build` key cannot be specified in the user config (~/.cdk.json), specify it in the project config (cdk.json) instead");
100
+ }
101
+ const contextSources = [
102
+ { bag: this.commandLineContext },
103
+ {
104
+ fileName: PROJECT_CONFIG,
105
+ bag: this.projectConfig.subSettings([CONTEXT_KEY]).makeReadOnly(),
106
+ },
107
+ { fileName: PROJECT_CONTEXT, bag: this.projectContext },
108
+ ];
109
+ if (readUserContext) {
110
+ contextSources.push({
111
+ fileName: USER_DEFAULTS,
112
+ bag: userConfig.subSettings([CONTEXT_KEY]).makeReadOnly(),
113
+ });
114
+ }
115
+ this.context = new Context(...contextSources);
116
+ // Build settings from what's left
117
+ this.settings = this.defaultConfig
118
+ .merge(userConfig)
119
+ .merge(this.projectConfig)
120
+ .merge(this.commandLineArguments)
121
+ .makeReadOnly();
122
+ this.loaded = true;
123
+ return this;
124
+ }
125
+ /**
126
+ * Save the project context
127
+ */
128
+ async saveContext() {
129
+ if (!this.loaded) {
130
+ return this;
131
+ } // Avoid overwriting files with nothing
132
+ await this.projectContext.save(PROJECT_CONTEXT);
133
+ return this;
134
+ }
135
+ }
136
+ async function loadAndLog(fileName) {
137
+ return await settingsFromFile(fileName);
138
+ }
139
+ async function settingsFromFile(fileName) {
140
+ let settings;
141
+ const expanded = expandHomeDir(fileName);
142
+ if (fs.existsSync(expanded)) {
143
+ const data = JSON.parse(fs.readFileSync(expanded, "utf-8"));
144
+ settings = new Settings(data);
145
+ }
146
+ else {
147
+ settings = new Settings();
148
+ }
149
+ // See https://github.com/aws/aws-cdk/issues/59
150
+ prohibitContextKeys(settings, ["default-account", "default-region"], fileName);
151
+ warnAboutContextKey(settings, "aws:", fileName);
152
+ return settings;
153
+ }
154
+ function prohibitContextKeys(settings, keys, fileName) {
155
+ const context = settings.get(["context"]);
156
+ if (!context || typeof context !== "object") {
157
+ return;
158
+ }
159
+ for (const key of keys) {
160
+ if (key in context) {
161
+ throw new ToolkitError(`The 'context.${key}' key was found in ${fs_path.resolve(fileName)}, but it is no longer supported. Please remove it.`);
162
+ }
163
+ }
164
+ }
165
+ function warnAboutContextKey(settings, prefix, fileName) {
166
+ const context = settings.get(["context"]);
167
+ if (!context || typeof context !== "object") {
168
+ return;
169
+ }
170
+ for (const contextKey of Object.keys(context)) {
171
+ if (contextKey.startsWith(prefix)) {
172
+ console.warn(`A reserved context key ('context.${prefix}') key was found in ${fs_path.resolve(fileName)}, it might cause surprising behavior and should be removed.`);
173
+ }
174
+ }
175
+ }
176
+ function expandHomeDir(x) {
177
+ if (x.startsWith("~")) {
178
+ return fs_path.join(os.homedir(), x.slice(1));
179
+ }
180
+ return x;
181
+ }
182
+ /**
183
+ * Parse CLI arguments into Settings
184
+ *
185
+ * CLI arguments in must be accessed in the CLI code via
186
+ * `configuration.settings.get(['argName'])` instead of via `args.argName`.
187
+ *
188
+ * The advantage is that they can be configured via `cdk.json` and
189
+ * `$HOME/.cdk.json`. Arguments not listed below and accessed via this object
190
+ * can only be specified on the command line.
191
+ *
192
+ * @param argv - the received CLI arguments.
193
+ * @returns a new Settings object.
194
+ */
195
+ export function commandLineArgumentsToSettings(argv) {
196
+ const context = parseStringContextListToObject(argv);
197
+ const tags = parseStringTagsListToObject(expectStringList(argv.tags));
198
+ // Determine bundling stacks
199
+ let bundlingStacks;
200
+ if (BUNDLING_COMMANDS.includes(argv._[0])) {
201
+ // If we deploy, diff, synth or watch a list of stacks exclusively we skip
202
+ // bundling for all other stacks.
203
+ bundlingStacks = argv.exclusively ? argv.STACKS ?? ["**"] : ["**"];
204
+ }
205
+ else {
206
+ // Skip bundling for all stacks
207
+ bundlingStacks = [];
208
+ }
209
+ return new Settings({
210
+ app: argv.app,
211
+ browser: argv.browser,
212
+ build: argv.build,
213
+ caBundlePath: argv.caBundlePath,
214
+ context,
215
+ debug: argv.debug,
216
+ tags,
217
+ language: argv.language,
218
+ pathMetadata: argv.pathMetadata,
219
+ assetMetadata: argv.assetMetadata,
220
+ profile: argv.profile,
221
+ plugin: argv.plugin,
222
+ requireApproval: argv.requireApproval,
223
+ toolkitStackName: argv.toolkitStackName,
224
+ toolkitBucket: {
225
+ bucketName: argv.bootstrapBucketName,
226
+ kmsKeyId: argv.bootstrapKmsKeyId,
227
+ },
228
+ versionReporting: argv.versionReporting,
229
+ staging: argv.staging,
230
+ output: argv.output,
231
+ outputsFile: argv.outputsFile,
232
+ progress: argv.progress,
233
+ proxy: argv.proxy,
234
+ bundlingStacks,
235
+ lookups: argv.lookups,
236
+ rollback: argv.rollback,
237
+ notices: argv.notices,
238
+ assetParallelism: argv["asset-parallelism"],
239
+ assetPrebuild: argv["asset-prebuild"],
240
+ ignoreNoStacks: argv["ignore-no-stacks"],
241
+ hotswap: {
242
+ ecs: {
243
+ minimumHealthyPercent: argv.hotswapEcsMinimumHealthyPercent,
244
+ maximumHealthyPercent: argv.hotswapEcsMaximumHealthyPercent,
245
+ stabilizationTimeoutSeconds: argv.hotswapEcsStabilizationTimeoutSeconds,
246
+ },
247
+ },
248
+ unstable: argv.unstable,
249
+ });
250
+ }
251
+ function expectStringList(x) {
252
+ if (x === undefined) {
253
+ return undefined;
254
+ }
255
+ if (!Array.isArray(x)) {
256
+ throw new ToolkitError(`Expected array, got '${x}'`);
257
+ }
258
+ const nonStrings = x.filter((e) => typeof e !== "string");
259
+ if (nonStrings.length > 0) {
260
+ throw new ToolkitError(`Expected list of strings, found ${nonStrings}`);
261
+ }
262
+ return x;
263
+ }
264
+ function parseStringContextListToObject(argv) {
265
+ const context = {};
266
+ for (const assignment of argv.context || []) {
267
+ const parts = assignment.split(/=(.*)/, 2);
268
+ if (parts.length === 2) {
269
+ if (parts[0].match(/^aws:.+/)) {
270
+ throw new ToolkitError(`User-provided context cannot use keys prefixed with 'aws:', but ${parts[0]} was provided.`);
271
+ }
272
+ context[parts[0]] = parts[1];
273
+ }
274
+ else {
275
+ console.warn("Context argument is not an assignment (key=value): %s", assignment);
276
+ }
277
+ }
278
+ return context;
279
+ }
280
+ /**
281
+ * Parse tags out of arguments
282
+ *
283
+ * Return undefined if no tags were provided, return an empty array if only empty
284
+ * strings were provided
285
+ */
286
+ function parseStringTagsListToObject(argTags) {
287
+ if (argTags === undefined) {
288
+ return undefined;
289
+ }
290
+ if (argTags.length === 0) {
291
+ return undefined;
292
+ }
293
+ const nonEmptyTags = argTags.filter((t) => t !== "");
294
+ if (nonEmptyTags.length === 0) {
295
+ return [];
296
+ }
297
+ const tags = [];
298
+ for (const assignment of nonEmptyTags) {
299
+ const parts = assignment.split(/=(.*)/, 2);
300
+ if (parts.length === 2) {
301
+ tags.push({
302
+ Key: parts[0],
303
+ Value: parts[1],
304
+ });
305
+ }
306
+ else {
307
+ console.warn("Tags argument is not an assignment (key=value): %s", assignment);
308
+ }
309
+ }
310
+ return tags.length > 0 ? tags : undefined;
311
+ }
@@ -1,180 +0,0 @@
1
- import * as cxapi from "@aws-cdk/cx-api";
2
- import type { Tag } from "@aws-sdk/client-cloudformation";
3
- import { ResourcesToImport } from "sst-aws-cdk/lib/api/deployments/cloudformation.js";
4
- import { DeploymentMethod } from "sst-aws-cdk/lib/api/deployments/deployment-method.js";
5
- import { DeployStackResult } from "sst-aws-cdk/lib/api/deployments/deployment-result.js";
6
- import type { SDK, SdkProvider } from "sst-aws-cdk/lib/api/aws-auth/index.js";
7
- import type { EnvironmentResources } from "sst-aws-cdk/lib/api/environment-resources.js";
8
- import { HotswapMode, HotswapPropertyOverrides } from "sst-aws-cdk/lib/api/hotswap/common.js";
9
- import { type StackActivityProgress } from "sst-aws-cdk/lib/api/util/cloudformation/stack-activity-monitor.js";
10
- import { StringWithoutPlaceholders } from "sst-aws-cdk/lib/api/util/placeholders.js";
11
- export interface DeployStackOptions {
12
- /**
13
- * The stack to be deployed
14
- */
15
- readonly stack: cxapi.CloudFormationStackArtifact;
16
- /**
17
- * Skip monitoring
18
- */
19
- readonly noMonitor?: boolean;
20
- /**
21
- * The environment to deploy this stack in
22
- *
23
- * The environment on the stack artifact may be unresolved, this one
24
- * must be resolved.
25
- */
26
- readonly resolvedEnvironment: cxapi.Environment;
27
- /**
28
- * The SDK to use for deploying the stack
29
- *
30
- * Should have been initialized with the correct role with which
31
- * stack operations should be performed.
32
- */
33
- readonly sdk: SDK;
34
- /**
35
- * SDK provider (seeded with default credentials)
36
- *
37
- * Will be used to:
38
- * - Publish assets, either legacy assets or large CFN templates
39
- * that aren't themselves assets from a manifest. (Needs an SDK
40
- * Provider because the file publishing role is declared as part
41
- * of the asset).
42
- * - Hotswap
43
- */
44
- readonly sdkProvider: SdkProvider;
45
- /**
46
- * Information about the bootstrap stack found in the target environment
47
- */
48
- readonly envResources: EnvironmentResources;
49
- /**
50
- * Role to pass to CloudFormation to execute the change set
51
- *
52
- * To obtain a `StringWithoutPlaceholders`, run a regular
53
- * string though `TargetEnvironment.replacePlaceholders`.
54
- *
55
- * @default - No execution role; CloudFormation either uses the role currently associated with
56
- * the stack, or otherwise uses current AWS credentials.
57
- */
58
- readonly roleArn?: StringWithoutPlaceholders;
59
- /**
60
- * Notification ARNs to pass to CloudFormation to notify when the change set has completed
61
- *
62
- * @default - No notifications
63
- */
64
- readonly notificationArns?: string[];
65
- /**
66
- * Name to deploy the stack under
67
- *
68
- * @default - Name from assembly
69
- */
70
- readonly deployName?: string;
71
- /**
72
- * Quiet or verbose deployment
73
- *
74
- * @default false
75
- */
76
- readonly quiet?: boolean;
77
- /**
78
- * List of asset IDs which shouldn't be built
79
- *
80
- * @default - Build all assets
81
- */
82
- readonly reuseAssets?: string[];
83
- /**
84
- * Tags to pass to CloudFormation to add to stack
85
- *
86
- * @default - No tags
87
- */
88
- readonly tags?: Tag[];
89
- /**
90
- * What deployment method to use
91
- *
92
- * @default - Change set with defaults
93
- */
94
- readonly deploymentMethod?: DeploymentMethod;
95
- /**
96
- * The collection of extra parameters
97
- * (in addition to those used for assets)
98
- * to pass to the deployed template.
99
- * Note that parameters with `undefined` or empty values will be ignored,
100
- * and not passed to the template.
101
- *
102
- * @default - no additional parameters will be passed to the template
103
- */
104
- readonly parameters?: {
105
- [name: string]: string | undefined;
106
- };
107
- /**
108
- * Use previous values for unspecified parameters
109
- *
110
- * If not set, all parameters must be specified for every deployment.
111
- *
112
- * @default false
113
- */
114
- readonly usePreviousParameters?: boolean;
115
- /**
116
- * Display mode for stack deployment progress.
117
- *
118
- * @default StackActivityProgress.Bar stack events will be displayed for
119
- * the resource currently being deployed.
120
- */
121
- readonly progress?: StackActivityProgress;
122
- /**
123
- * Deploy even if the deployed template is identical to the one we are about to deploy.
124
- * @default false
125
- */
126
- readonly force?: boolean;
127
- /**
128
- * Whether we are on a CI system
129
- *
130
- * @default false
131
- */
132
- readonly ci?: boolean;
133
- /**
134
- * Rollback failed deployments
135
- *
136
- * @default true
137
- */
138
- readonly rollback?: boolean;
139
- readonly hotswap?: HotswapMode;
140
- /**
141
- * Extra properties that configure hotswap behavior
142
- */
143
- readonly hotswapPropertyOverrides?: HotswapPropertyOverrides;
144
- /**
145
- * The extra string to append to the User-Agent header when performing AWS SDK calls.
146
- *
147
- * @default - nothing extra is appended to the User-Agent header
148
- */
149
- readonly extraUserAgent?: string;
150
- /**
151
- * If set, change set of type IMPORT will be created, and resourcesToImport
152
- * passed to it.
153
- */
154
- readonly resourcesToImport?: ResourcesToImport;
155
- /**
156
- * If present, use this given template instead of the stored one
157
- *
158
- * @default - Use the stored template
159
- */
160
- readonly overrideTemplate?: any;
161
- /**
162
- * Whether to build/publish assets in parallel
163
- *
164
- * @default true To remain backward compatible.
165
- */
166
- readonly assetParallelism?: boolean;
167
- }
168
- export declare function deployStack(options: DeployStackOptions): Promise<DeployStackResult | undefined>;
169
- export interface DestroyStackOptions {
170
- /**
171
- * The stack to be destroyed
172
- */
173
- stack: cxapi.CloudFormationStackArtifact;
174
- sdk: SDK;
175
- roleArn?: string;
176
- deployName?: string;
177
- quiet?: boolean;
178
- ci?: boolean;
179
- }
180
- export declare function destroyStack(options: DestroyStackOptions): Promise<void>;