Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(toolkit): prevent unintended public exports, file re-org #32967

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions packages/@aws-cdk/toolkit/.gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
# Build artifacts
*.js
*.js.map
*.d.ts
*.d.ts.map
*.gz
node_modules
npm-shrinkwrap.json
tsconfig.tsbuildinfo
dist
.jsii
docs

# Generated by generate.sh
build-info.json

# Test artifacts
assets.json
junit.xml
.LAST_BUILD
.nyc_output
coverage
nyc.config.js
.LAST_PACKAGE
*.snk

assets.json
npm-shrinkwrap.json
!.eslintrc.js
!jest.config.js

junit.xml

# Exclude resources
build-info.json
lib/**/*.wasm
lib/**/*.yaml

# Include config files
!.eslintrc.js
!jest.config.js
3 changes: 0 additions & 3 deletions packages/@aws-cdk/toolkit/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ bundle.mjs
# Explicitly allow all required files
!build-info.json
!db.json.gz
# !lib/main.js
# !lib/bridge.js
# !lib/setup-sandbox.js
# !lib/api/bootstrap/bootstrap-template.yaml
!*.d.ts
!*.d.ts.map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Deployments, StackActivityProgress, WorkGraph } from '../api/aws-cdk';
import { StackSelector } from '../api/cloud-assembly/stack-selector';
import { StackActivityProgress } from '../../api/aws-cdk';
import type { StackSelector } from '../../api/cloud-assembly';

export type DeploymentMethod = DirectDeploymentMethod | ChangeSetDeploymentMethod;

Expand Down Expand Up @@ -243,36 +243,3 @@ export interface DeployOptions extends BaseDeployOptions {
*/
readonly progress?: StackActivityProgress;
}

export function buildParameterMap(parameters?: Map<string, string | undefined>): { [name: string]: { [name: string]: string | undefined } } {
const parameterMap: {
[name: string]: { [name: string]: string | undefined };
} = {};
parameterMap['*'] = {};

const entries = parameters?.entries() ?? [];
for (const [key, value] of entries) {
const [stack, parameter] = key.split(':', 2) as [string, string | undefined];
if (!parameter) {
parameterMap['*'][stack] = value;
} else {
if (!parameterMap[stack]) {
parameterMap[stack] = {};
}
parameterMap[stack][parameter] = value;
}
}

return parameterMap;
}

/**
* Remove the asset publishing and building from the work graph for assets that are already in place
*/
export async function removePublishedAssets(graph: WorkGraph, deployments: Deployments, options: DeployOptions) {
await graph.removeUnnecessaryAssets(assetNode => deployments.isSingleAssetPublished(assetNode.assetManifest, assetNode.asset, {
stack: assetNode.parentStack,
roleArn: options.roleArn,
stackName: assetNode.parentStack.stackName,
}));
}
35 changes: 35 additions & 0 deletions packages/@aws-cdk/toolkit/lib/actions/deploy/private/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DeployOptions } from '..';
import { Deployments, WorkGraph } from '../../../api/aws-cdk';

export function buildParameterMap(parameters?: Map<string, string | undefined>): { [name: string]: { [name: string]: string | undefined } } {
const parameterMap: {
[name: string]: { [name: string]: string | undefined };
} = {};
parameterMap['*'] = {};

const entries = parameters?.entries() ?? [];
for (const [key, value] of entries) {
const [stack, parameter] = key.split(':', 2) as [string, string | undefined];
if (!parameter) {
parameterMap['*'][stack] = value;
} else {
if (!parameterMap[stack]) {
parameterMap[stack] = {};
}
parameterMap[stack][parameter] = value;
}
}

return parameterMap;
}

/**
* Remove the asset publishing and building from the work graph for assets that are already in place
*/
export async function removePublishedAssets(graph: WorkGraph, deployments: Deployments, options: DeployOptions) {
await graph.removeUnnecessaryAssets(assetNode => deployments.isSingleAssetPublished(assetNode.assetManifest, assetNode.asset, {
stack: assetNode.parentStack,
roleArn: options.roleArn,
stackName: assetNode.parentStack.stackName,
}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './helpers';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StackSelector } from '../api/cloud-assembly/stack-selector';
import type { StackSelector } from '../../api/cloud-assembly';

export interface DestroyOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StackSelector } from '../api/cloud-assembly/stack-selector';
import type { StackSelector } from '../../api/cloud-assembly';

export interface CloudFormationDiffOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseDeployOptions } from './deploy';
import type { BaseDeployOptions } from '../deploy';

export interface ImportOptions extends Omit<BaseDeployOptions, 'reuseAssets' | 'hotswap'> {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StackSelector } from '../api/cloud-assembly/stack-selector';
import type { StackSelector } from '../../api/cloud-assembly';

export interface ListOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StackSelector } from '../api/cloud-assembly';
import type { StackSelector } from '../../api/cloud-assembly';

export interface RollbackOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StackSelector } from '../api/cloud-assembly/stack-selector';
import type { StackSelector } from '../../api/cloud-assembly';

export interface SynthOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseDeployOptions } from './deploy';
import type { BaseDeployOptions } from '../deploy';

export interface WatchOptions extends BaseDeployOptions {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { MissingContext } from '@aws-cdk/cloud-assembly-schema';
import * as cxapi from '@aws-cdk/cx-api';
import { ToolkitServices } from '../../../toolkit/private';
import { Context, contextproviders, PROJECT_CONTEXT } from '../../aws-cdk';
import { ToolkitError } from '../../errors';
import { ActionAwareIoHost, debug } from '../../io/private';
import { ToolkitServices } from '../../toolkit/private';
import { ICloudAssemblySource } from '../types';

export interface ContextAwareCloudAssemblyProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import * as fs from 'fs-extra';
import { lte } from 'semver';
import type { AppSynthOptions } from './source-builder';
import { prepareDefaultEnvironment as oldPrepare, prepareContext, spaceAvailableForContext, Settings, loadTree, some, splitBySize, versionNumber } from '../../../api/aws-cdk';
import { ToolkitServices } from '../../../toolkit/private';
import { ToolkitError } from '../../errors';
import { ActionAwareIoHost, asLogger, error } from '../../io/private';
import { ToolkitServices } from '../../toolkit/private';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { ICloudAssemblySource } from '../';
import { ContextAwareCloudAssembly, ContextAwareCloudAssemblyProps } from './context-aware-source';
import { execInChildProcess } from './exec';
import { assemblyFromDirectory, changeDir, guessExecutable, prepareDefaultEnvironment, withContext, withEnv } from './prepare-source';
import { ToolkitServices } from '../../../toolkit/private';
import { Context, ILock, RWLock } from '../../aws-cdk';
import { ToolkitError } from '../../errors';
import { debug } from '../../io/private';
import { ToolkitServices } from '../../toolkit/private';

/**
* Configuration for creating a CLI from an AWS CDK App directory
Expand Down
42 changes: 0 additions & 42 deletions packages/@aws-cdk/toolkit/lib/cloud-assembly-source.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file was left in accidentally and is not used

This file was deleted.

3 changes: 0 additions & 3 deletions packages/@aws-cdk/toolkit/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ export * from './api/aws-auth';
export * from './api/cloud-assembly';
export * from './api/io';
export * from './api/errors';

// shared types
export * from './api/cloud-assembly/stack-selector';
1 change: 1 addition & 0 deletions packages/@aws-cdk/toolkit/lib/toolkit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './toolkit';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

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

/**
* Helper struct to pass internal services around.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@

import * as path from 'node:path';
import * as cxapi from '@aws-cdk/cx-api';
import * as chalk from 'chalk';
import * as chokidar from 'chokidar';
import * as fs from 'fs-extra';
import { AssetBuildTime, buildParameterMap, DeployOptions, removePublishedAssets, RequireApproval } from './actions/deploy';
import { DestroyOptions } from './actions/destroy';
import { DiffOptions } from './actions/diff';
import { ListOptions } from './actions/list';
import { RollbackOptions } from './actions/rollback';
import { SynthOptions } from './actions/synth';
import { patternsArrayForWatch, WatchOptions } from './actions/watch';
import { SdkOptions } from './api/aws-auth';
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';
import { CachedCloudAssemblySource, IdentityCloudAssemblySource, StackAssembly, ICloudAssemblySource } from './api/cloud-assembly';
import { CloudAssemblySourceBuilder } from './api/cloud-assembly/private/source-builder';
import { StackSelectionStrategy } from './api/cloud-assembly/stack-selector';
import { ToolkitError } from './api/errors';
import { IIoHost, IoMessageCode, IoMessageLevel } from './api/io';
import { asSdkLogger, withAction, Timer, confirm, data, error, highlight, info, success, warn, ActionAwareIoHost, debug } from './api/io/private';
import { ToolkitServices } from './api/toolkit/private';
import { ToolkitServices } from './private';
import { AssetBuildTime, DeployOptions, RequireApproval } from '../actions/deploy';
import { buildParameterMap, removePublishedAssets } from '../actions/deploy/private';
import { DestroyOptions } from '../actions/destroy';
import { DiffOptions } from '../actions/diff';
import { ListOptions } from '../actions/list';
import { RollbackOptions } from '../actions/rollback';
import { SynthOptions } from '../actions/synth';
import { patternsArrayForWatch, WatchOptions } from '../actions/watch';
import { SdkOptions } from '../api/aws-auth';
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';
import { CachedCloudAssemblySource, IdentityCloudAssemblySource, StackAssembly, ICloudAssemblySource, StackSelectionStrategy } from '../api/cloud-assembly';
import { CloudAssemblySourceBuilder } from '../api/cloud-assembly/private/source-builder';
import { ToolkitError } from '../api/errors';
import { IIoHost, IoMessageCode, IoMessageLevel } from '../api/io';
import { asSdkLogger, withAction, Timer, confirm, data, error, highlight, info, success, warn, ActionAwareIoHost, debug } from '../api/io/private';

/**
* The current action being performed by the CLI. 'none' represents the absence of an action.
Expand Down
Loading