-
-
Notifications
You must be signed in to change notification settings - Fork 321
Add support for AWS CDK #1037
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
base: main
Are you sure you want to change the base?
Add support for AWS CDK #1037
Changes from 3 commits
6d06906
8bd27ad
30dff7b
7c45bbe
7efb03d
f4f417e
a6ff92a
88d6d87
f46f843
e98d583
2d4f42e
bdb5726
695ea46
22739ce
34f4efe
83ddcff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // @ts-ignore | ||
| import * as cdk from 'aws-cdk-lib'; | ||
| import { MyStack } from '../lib/myStack'; | ||
|
|
||
| const app = new cdk.App(); | ||
| new MyStack(app, 'MyStack'); | ||
|
|
||
| app.synth(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "app": "ts-node --project=tsconfig.json --prefer-ts-exts cdk/bin/infra.ts", | ||
| "watch": { | ||
| "include": ["cdk/lib/**", "cdk/bin/**"] | ||
| }, | ||
| "context": { | ||
| "aws-cdk-lib/core:enableDiffNoFail": true, | ||
| "aws-cdk-lib/core:bootstrapQualifier": "custom-v2", | ||
| "aws-cdk-lib/core:checkSecretUsage": true, | ||
| "aws-cdk-lib/core:target-partitions": [ | ||
| "aws", | ||
| "aws-cn" | ||
| ], | ||
| "aws-cdk-lib/aws-apigateway:disableCloudWatchRole": true, | ||
| "aws-cdk-lib/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, | ||
| "aws-cdk-lib/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": false, | ||
| "aws-cdk-lib/aws-lambda:recognizeLayerVersion": true | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // @ts-ignore | ||
| import { Construct } from 'constructs'; | ||
|
|
||
| export class MyConstruct extends Construct { | ||
| constructor(scope: Construct, id: string) { | ||
| super(scope, id); | ||
|
|
||
| // The code that defines your stack goes here | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // @ts-ignore | ||
| import * as cdk from 'aws-cdk-lib'; | ||
|
|
||
| export class MyStack extends cdk.Stack { | ||
| constructor(scope: cdk.App, id: string) { | ||
| super(scope, id); | ||
|
|
||
| // The code that defines your stack goes here | ||
| } | ||
| } | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "@fixtures/aws-cdk", | ||
| "dependencies": { | ||
| "aws-cdk-lib": "^2.0.0", | ||
| "constructs": "^10.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "aws-cdk": "^2.0.0", | ||
| "@types/aws-cdk-lib": "^2.0.0", | ||
| "@types/constructs": "^10.0.0", | ||
| "ts-node": "^10.0.0", | ||
| "typescript": "^5.0.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { toDependency } from 'src/util/input.js'; | ||
| import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js'; | ||
| import { compact } from '../../util/array.js'; | ||
| import { hasDependency } from '../../util/plugin.js'; | ||
| import type { AwsCdkConfig } from './types.ts'; | ||
|
|
||
| // https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib-readme.html | ||
|
|
||
| const title = 'aws-cdk'; | ||
|
|
||
| const enablers = ['aws-cdk']; | ||
|
|
||
| const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); | ||
|
|
||
| const config: string[] = ["cdk.json"]; | ||
|
|
||
| const resolveConfig: ResolveConfig<AwsCdkConfig> = async config => { | ||
| if (!config) return []; | ||
|
|
||
| const app = config.app.split(" ")[0]; | ||
| const watch = config.watch?.include ?? []; | ||
|
||
| const context = Object.keys(config.context ?? {}).map(key => key.split("/")[0]) ?? []; | ||
| return compact([app, ...watch, ...context]).map(id => toDependency(id)); | ||
|
||
| }; | ||
|
|
||
| const production: string[] = [ | ||
| '{src/,cdk/,}bin/**/*.{js,ts}', | ||
| '{src/,cdk/,}lib/**/*.{js,ts}', | ||
| ]; | ||
|
|
||
| export default { | ||
| title, | ||
| enablers, | ||
| isEnabled, | ||
| config, | ||
| resolveConfig, | ||
| production, | ||
| } satisfies Plugin; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export type AwsCdkConfig = { | ||
| app: string; | ||
| watch?: { | ||
| include: string[]; | ||
| }; | ||
| context?: Record<string, unknown>; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { test } from 'bun:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { main } from '../../src/index.js'; | ||
| import { resolve } from '../../src/util/path.js'; | ||
| import baseArguments from '../helpers/baseArguments.js'; | ||
| import baseCounters from '../helpers/baseCounters.js'; | ||
|
|
||
| const cwd = resolve('fixtures/plugins/aws-cdk'); | ||
|
|
||
| test('Find dependencies with the aws-cdk plugin', async () => { | ||
| const { issues, counters } = await main({ | ||
| ...baseArguments, | ||
| cwd, | ||
| }); | ||
|
|
||
| console.log(issues); | ||
|
|
||
| assert(issues.devDependencies['package.json']['aws-cdk']); | ||
|
|
||
| assert.deepEqual(counters, { | ||
| ...baseCounters, | ||
| dependencies: 0, | ||
| devDependencies: 1, | ||
| unlisted: 1, | ||
| processed: 3, | ||
| total: 3, | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
appoption looks like a command, we should usegetInputsFromScriptsfor this.This function is available on the second
optionsargument thatResolveConfigis invoked with.Look for
getInputsFromScriptsin the plugins folder for other usage examples.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 7c45bbe. Just a question though: what is the
knownBinsOnlyoption for?PS: I initially forgot to run the test again (somehow) before pushing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, binaries are expected to be shipped alongside the dependencies in
node_modules/.bin- it's a setting that allows to be less strict and accept "any" binary name in CI environments—which are usually provisioned with unknown binaries—to prevent false positives for "unlisted binaries". However, the variable should def be improved.