Skip to content

Commit 717d91d

Browse files
authored
chore(toolkit): prevent unintended public exports, file re-org (#32967)
### Description of changes Removing some unintentional public exports from the deploy action. Re-organizing files to improve project structure. Making the `.gitignore` file more readable. **No functional code changes!** ### Describe any new or updated permissions being added n/a ### Description of how you validated changes It builds. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 62a9d66 commit 717d91d

File tree

20 files changed

+80
-122
lines changed

20 files changed

+80
-122
lines changed

packages/@aws-cdk/toolkit/.gitignore

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1+
# Build artifacts
12
*.js
23
*.js.map
34
*.d.ts
45
*.d.ts.map
56
*.gz
67
node_modules
8+
npm-shrinkwrap.json
9+
tsconfig.tsbuildinfo
710
dist
811
.jsii
12+
docs
913

10-
# Generated by generate.sh
11-
build-info.json
12-
14+
# Test artifacts
15+
assets.json
16+
junit.xml
1317
.LAST_BUILD
1418
.nyc_output
1519
coverage
1620
nyc.config.js
1721
.LAST_PACKAGE
1822
*.snk
1923

20-
assets.json
21-
npm-shrinkwrap.json
22-
!.eslintrc.js
23-
!jest.config.js
24-
25-
junit.xml
26-
24+
# Exclude resources
25+
build-info.json
2726
lib/**/*.wasm
2827
lib/**/*.yaml
28+
29+
# Include config files
30+
!.eslintrc.js
31+
!jest.config.js

packages/@aws-cdk/toolkit/.npmignore

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ bundle.mjs
2121
# Explicitly allow all required files
2222
!build-info.json
2323
!db.json.gz
24-
# !lib/main.js
25-
# !lib/bridge.js
26-
# !lib/setup-sandbox.js
2724
# !lib/api/bootstrap/bootstrap-template.yaml
2825
!*.d.ts
2926
!*.d.ts.map

packages/@aws-cdk/toolkit/lib/actions/deploy.ts packages/@aws-cdk/toolkit/lib/actions/deploy/index.ts

+2-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Deployments, StackActivityProgress, WorkGraph } from '../api/aws-cdk';
2-
import { StackSelector } from '../api/cloud-assembly/stack-selector';
1+
import { StackActivityProgress } from '../../api/aws-cdk';
2+
import type { StackSelector } from '../../api/cloud-assembly';
33

44
export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;
55

@@ -243,36 +243,3 @@ export interface DeployOptions extends BaseDeployOptions {
243243
*/
244244
readonly progress?: StackActivityProgress;
245245
}
246-
247-
export function buildParameterMap(parameters?: Map<string, string | undefined>): { [name: string]: { [name: string]: string | undefined } } {
248-
const parameterMap: {
249-
[name: string]: { [name: string]: string | undefined };
250-
} = {};
251-
parameterMap['*'] = {};
252-
253-
const entries = parameters?.entries() ?? [];
254-
for (const [key, value] of entries) {
255-
const [stack, parameter] = key.split(':', 2) as [string, string | undefined];
256-
if (!parameter) {
257-
parameterMap['*'][stack] = value;
258-
} else {
259-
if (!parameterMap[stack]) {
260-
parameterMap[stack] = {};
261-
}
262-
parameterMap[stack][parameter] = value;
263-
}
264-
}
265-
266-
return parameterMap;
267-
}
268-
269-
/**
270-
* Remove the asset publishing and building from the work graph for assets that are already in place
271-
*/
272-
export async function removePublishedAssets(graph: WorkGraph, deployments: Deployments, options: DeployOptions) {
273-
await graph.removeUnnecessaryAssets(assetNode => deployments.isSingleAssetPublished(assetNode.assetManifest, assetNode.asset, {
274-
stack: assetNode.parentStack,
275-
roleArn: options.roleArn,
276-
stackName: assetNode.parentStack.stackName,
277-
}));
278-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { DeployOptions } from '..';
2+
import { Deployments, WorkGraph } from '../../../api/aws-cdk';
3+
4+
export function buildParameterMap(parameters?: Map<string, string | undefined>): { [name: string]: { [name: string]: string | undefined } } {
5+
const parameterMap: {
6+
[name: string]: { [name: string]: string | undefined };
7+
} = {};
8+
parameterMap['*'] = {};
9+
10+
const entries = parameters?.entries() ?? [];
11+
for (const [key, value] of entries) {
12+
const [stack, parameter] = key.split(':', 2) as [string, string | undefined];
13+
if (!parameter) {
14+
parameterMap['*'][stack] = value;
15+
} else {
16+
if (!parameterMap[stack]) {
17+
parameterMap[stack] = {};
18+
}
19+
parameterMap[stack][parameter] = value;
20+
}
21+
}
22+
23+
return parameterMap;
24+
}
25+
26+
/**
27+
* Remove the asset publishing and building from the work graph for assets that are already in place
28+
*/
29+
export async function removePublishedAssets(graph: WorkGraph, deployments: Deployments, options: DeployOptions) {
30+
await graph.removeUnnecessaryAssets(assetNode => deployments.isSingleAssetPublished(assetNode.assetManifest, assetNode.asset, {
31+
stack: assetNode.parentStack,
32+
roleArn: options.roleArn,
33+
stackName: assetNode.parentStack.stackName,
34+
}));
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './helpers';

packages/@aws-cdk/toolkit/lib/actions/destroy.ts packages/@aws-cdk/toolkit/lib/actions/destroy/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StackSelector } from '../api/cloud-assembly/stack-selector';
1+
import type { StackSelector } from '../../api/cloud-assembly';
22

33
export interface DestroyOptions {
44
/**

packages/@aws-cdk/toolkit/lib/actions/diff.ts packages/@aws-cdk/toolkit/lib/actions/diff/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StackSelector } from '../api/cloud-assembly/stack-selector';
1+
import type { StackSelector } from '../../api/cloud-assembly';
22

33
export interface CloudFormationDiffOptions {
44
/**

packages/@aws-cdk/toolkit/lib/actions/import.ts packages/@aws-cdk/toolkit/lib/actions/import/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseDeployOptions } from './deploy';
1+
import type { BaseDeployOptions } from '../deploy';
22

33
export interface ImportOptions extends Omit<BaseDeployOptions, 'reuseAssets' | 'hotswap'> {
44
/**

packages/@aws-cdk/toolkit/lib/actions/list.ts packages/@aws-cdk/toolkit/lib/actions/list/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StackSelector } from '../api/cloud-assembly/stack-selector';
1+
import type { StackSelector } from '../../api/cloud-assembly';
22

33
export interface ListOptions {
44
/**

packages/@aws-cdk/toolkit/lib/actions/rollback.ts packages/@aws-cdk/toolkit/lib/actions/rollback/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StackSelector } from '../api/cloud-assembly';
1+
import type { StackSelector } from '../../api/cloud-assembly';
22

33
export interface RollbackOptions {
44
/**

packages/@aws-cdk/toolkit/lib/actions/synth.ts packages/@aws-cdk/toolkit/lib/actions/synth/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StackSelector } from '../api/cloud-assembly/stack-selector';
1+
import type { StackSelector } from '../../api/cloud-assembly';
22

33
export interface SynthOptions {
44
/**

packages/@aws-cdk/toolkit/lib/actions/watch.ts packages/@aws-cdk/toolkit/lib/actions/watch/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseDeployOptions } from './deploy';
1+
import type { BaseDeployOptions } from '../deploy';
22

33
export interface WatchOptions extends BaseDeployOptions {
44
/**

packages/@aws-cdk/toolkit/lib/api/cloud-assembly/private/context-aware-source.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { MissingContext } from '@aws-cdk/cloud-assembly-schema';
22
import * as cxapi from '@aws-cdk/cx-api';
3+
import { ToolkitServices } from '../../../toolkit/private';
34
import { Context, contextproviders, PROJECT_CONTEXT } from '../../aws-cdk';
45
import { ToolkitError } from '../../errors';
56
import { ActionAwareIoHost, debug } from '../../io/private';
6-
import { ToolkitServices } from '../../toolkit/private';
77
import { ICloudAssemblySource } from '../types';
88

99
export interface ContextAwareCloudAssemblyProps {

packages/@aws-cdk/toolkit/lib/api/cloud-assembly/private/prepare-source.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import * as fs from 'fs-extra';
66
import { lte } from 'semver';
77
import type { AppSynthOptions } from './source-builder';
88
import { prepareDefaultEnvironment as oldPrepare, prepareContext, spaceAvailableForContext, Settings, loadTree, some, splitBySize, versionNumber } from '../../../api/aws-cdk';
9+
import { ToolkitServices } from '../../../toolkit/private';
910
import { ToolkitError } from '../../errors';
1011
import { ActionAwareIoHost, asLogger, error } from '../../io/private';
11-
import { ToolkitServices } from '../../toolkit/private';
1212

1313
export { guessExecutable } from '../../../api/aws-cdk';
1414

packages/@aws-cdk/toolkit/lib/api/cloud-assembly/private/source-builder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { ICloudAssemblySource } from '../';
55
import { ContextAwareCloudAssembly, ContextAwareCloudAssemblyProps } from './context-aware-source';
66
import { execInChildProcess } from './exec';
77
import { assemblyFromDirectory, changeDir, guessExecutable, prepareDefaultEnvironment, withContext, withEnv } from './prepare-source';
8+
import { ToolkitServices } from '../../../toolkit/private';
89
import { Context, ILock, RWLock } from '../../aws-cdk';
910
import { ToolkitError } from '../../errors';
1011
import { debug } from '../../io/private';
11-
import { ToolkitServices } from '../../toolkit/private';
1212

1313
/**
1414
* Configuration for creating a CLI from an AWS CDK App directory

packages/@aws-cdk/toolkit/lib/cloud-assembly-source.ts

-42
This file was deleted.

packages/@aws-cdk/toolkit/lib/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ export * from './api/aws-auth';
77
export * from './api/cloud-assembly';
88
export * from './api/io';
99
export * from './api/errors';
10-
11-
// shared types
12-
export * from './api/cloud-assembly/stack-selector';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './toolkit';

packages/@aws-cdk/toolkit/lib/api/toolkit/private/index.ts packages/@aws-cdk/toolkit/lib/toolkit/private/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
import { SdkProvider } from '../../aws-cdk';
3-
import { ActionAwareIoHost } from '../../io/private';
2+
import { SdkProvider } from '../../api/aws-cdk';
3+
import { ActionAwareIoHost } from '../../api/io/private';
44

55
/**
66
* Helper struct to pass internal services around.

packages/@aws-cdk/toolkit/lib/toolkit.ts packages/@aws-cdk/toolkit/lib/toolkit/toolkit.ts

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
21
import * as path from 'node:path';
32
import * as cxapi from '@aws-cdk/cx-api';
43
import * as chalk from 'chalk';
54
import * as chokidar from 'chokidar';
65
import * as fs from 'fs-extra';
7-
import { AssetBuildTime, buildParameterMap, DeployOptions, removePublishedAssets, RequireApproval } from './actions/deploy';
8-
import { DestroyOptions } from './actions/destroy';
9-
import { DiffOptions } from './actions/diff';
10-
import { ListOptions } from './actions/list';
11-
import { RollbackOptions } from './actions/rollback';
12-
import { SynthOptions } from './actions/synth';
13-
import { patternsArrayForWatch, WatchOptions } from './actions/watch';
14-
import { SdkOptions } from './api/aws-auth';
15-
import { DEFAULT_TOOLKIT_STACK_NAME, SdkProvider, SuccessfulDeployStackResult, StackCollection, Deployments, HotswapMode, StackActivityProgress, ResourceMigrator, obscureTemplate, serializeStructure, tagsForStack, CliIoHost, validateSnsTopicArn, Concurrency, WorkGraphBuilder, AssetBuildNode, AssetPublishNode, StackNode } from './api/aws-cdk';
16-
import { CachedCloudAssemblySource, IdentityCloudAssemblySource, StackAssembly, ICloudAssemblySource } from './api/cloud-assembly';
17-
import { CloudAssemblySourceBuilder } from './api/cloud-assembly/private/source-builder';
18-
import { StackSelectionStrategy } from './api/cloud-assembly/stack-selector';
19-
import { ToolkitError } from './api/errors';
20-
import { IIoHost, IoMessageCode, IoMessageLevel } from './api/io';
21-
import { asSdkLogger, withAction, Timer, confirm, data, error, highlight, info, success, warn, ActionAwareIoHost, debug } from './api/io/private';
22-
import { ToolkitServices } from './api/toolkit/private';
6+
import { ToolkitServices } from './private';
7+
import { AssetBuildTime, DeployOptions, RequireApproval } from '../actions/deploy';
8+
import { buildParameterMap, removePublishedAssets } from '../actions/deploy/private';
9+
import { DestroyOptions } from '../actions/destroy';
10+
import { DiffOptions } from '../actions/diff';
11+
import { ListOptions } from '../actions/list';
12+
import { RollbackOptions } from '../actions/rollback';
13+
import { SynthOptions } from '../actions/synth';
14+
import { patternsArrayForWatch, WatchOptions } from '../actions/watch';
15+
import { SdkOptions } from '../api/aws-auth';
16+
import { DEFAULT_TOOLKIT_STACK_NAME, SdkProvider, SuccessfulDeployStackResult, StackCollection, Deployments, HotswapMode, StackActivityProgress, ResourceMigrator, obscureTemplate, serializeStructure, tagsForStack, CliIoHost, validateSnsTopicArn, Concurrency, WorkGraphBuilder, AssetBuildNode, AssetPublishNode, StackNode } from '../api/aws-cdk';
17+
import { CachedCloudAssemblySource, IdentityCloudAssemblySource, StackAssembly, ICloudAssemblySource, StackSelectionStrategy } from '../api/cloud-assembly';
18+
import { CloudAssemblySourceBuilder } from '../api/cloud-assembly/private/source-builder';
19+
import { ToolkitError } from '../api/errors';
20+
import { IIoHost, IoMessageCode, IoMessageLevel } from '../api/io';
21+
import { asSdkLogger, withAction, Timer, confirm, data, error, highlight, info, success, warn, ActionAwareIoHost, debug } from '../api/io/private';
2322

2423
/**
2524
* The current action being performed by the CLI. 'none' represents the absence of an action.

0 commit comments

Comments
 (0)