Skip to content

Commit

Permalink
core internal
Browse files Browse the repository at this point in the history
Signed-off-by: Francis <colifran@amazon.com>
  • Loading branch information
colifran committed Dec 8, 2023
1 parent c89f470 commit b0e9ba4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ import {
Expression,
} from '@cdklabs/typewriter';
import { CdkHandlerFrameworkModule } from './framework';
import { CONSTRUCTS_MODULE, LAMBDA_MODULE, CORE_MODULE } from './modules';
import {
CONSTRUCTS_MODULE,
LAMBDA_MODULE,
CORE_MODULE,
STACK,
CUSTOM_RESOURCE_PROVIDER_BASE,
CUSTOM_RESOURCE_PROVIDER_OPTIONS,
} from './modules';
import { Runtime } from './runtime';

/**
Expand Down Expand Up @@ -171,15 +178,23 @@ export abstract class CdkHandlerFrameworkClass extends ClassType {
*/
public static buildCdkCustomResourceProvider(scope: CdkHandlerFrameworkModule, props: CdkHandlerClassProps): CdkHandlerFrameworkClass {
return new (class CdkCustomResourceProvider extends CdkHandlerFrameworkClass {
protected readonly externalModules = [CONSTRUCTS_MODULE, CORE_MODULE];
protected readonly externalModules: ExternalModule[] = [CONSTRUCTS_MODULE];

public constructor() {
super(scope, {
name: props.name,
extends: CORE_MODULE.CustomResourceProviderBase,
extends: scope.coreInternal
? CUSTOM_RESOURCE_PROVIDER_BASE.CustomResourceProviderBase
: CORE_MODULE.CustomResourceProviderBase,
export: true,
});

if (scope.coreInternal) {
this.externalModules.push(...[STACK, CUSTOM_RESOURCE_PROVIDER_BASE, CUSTOM_RESOURCE_PROVIDER_OPTIONS]);
} else {
this.externalModules.push(CORE_MODULE);
}

this.externalModules.forEach(module => scope.addExternalModule(module));

const getOrCreateMethod = this.addMethod({
Expand All @@ -200,7 +215,9 @@ export abstract class CdkHandlerFrameworkClass extends ClassType {
});
getOrCreateMethod.addParameter({
name: 'props',
type: CORE_MODULE.CustomResourceProviderOptions,
type: scope.coreInternal
? CUSTOM_RESOURCE_PROVIDER_OPTIONS.CustomResourceProviderOptions
: CORE_MODULE.CustomResourceProviderOptions,
optional: true,
});
getOrCreateMethod.addBody(
Expand All @@ -225,7 +242,9 @@ export abstract class CdkHandlerFrameworkClass extends ClassType {
});
getOrCreateProviderMethod.addParameter({
name: 'props',
type: CORE_MODULE.CustomResourceProviderOptions,
type: scope.coreInternal
? CUSTOM_RESOURCE_PROVIDER_OPTIONS.CustomResourceProviderOptions
: CORE_MODULE.CustomResourceProviderOptions,
optional: true,
});
getOrCreateProviderMethod.addBody(
Expand All @@ -241,7 +260,9 @@ export abstract class CdkHandlerFrameworkClass extends ClassType {
['runtimeName', expr.lit(props.runtime.name)],
]);
this.buildConstructor({
constructorPropsType: CORE_MODULE.CustomResourceProviderOptions,
constructorPropsType: scope.coreInternal
? CUSTOM_RESOURCE_PROVIDER_OPTIONS.CustomResourceProviderOptions
: CORE_MODULE.CustomResourceProviderOptions,
superProps,
constructorVisbility: MemberVisibility.Private,
optionalConstructorProps: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExternalModule, InterfaceType, Module, TypeScriptRenderer } from '@cdkl
import * as fs from 'fs-extra';
import { CdkHandlerClassProps, CdkHandlerFrameworkClass } from './classes';
import { ComponentType, ConfigProps } from './config';
import { CONSTRUCTS_MODULE, CORE_MODULE, LAMBDA_MODULE, PATH_MODULE } from './modules';
import { CONSTRUCTS_MODULE, CORE_MODULE, CUSTOM_RESOURCE_PROVIDER_BASE, CUSTOM_RESOURCE_PROVIDER_OPTIONS, LAMBDA_MODULE, PATH_MODULE, STACK } from './modules';
import { Runtime } from './runtime';
import { RuntimeDeterminer } from './runtime-determiner';

Expand All @@ -16,10 +16,12 @@ export class CdkHandlerFrameworkModule extends Module {
private readonly renderer = new TypeScriptRenderer();
private readonly externalModules = new Map<string, boolean>();
private readonly _interfaces = new Map<string, InterfaceType>();
public readonly coreInternal: boolean;
private hasComponents = false;

public constructor(fqn: string) {
super(fqn);
this.coreInternal = fqn.includes('core');
}

/**
Expand Down Expand Up @@ -105,6 +107,18 @@ export class CdkHandlerFrameworkModule extends Module {
]);
break;
}
case STACK.fqn: {
STACK.importSelective(this, ['Stack']);
break;
}
case CUSTOM_RESOURCE_PROVIDER_BASE.fqn: {
CUSTOM_RESOURCE_PROVIDER_BASE.importSelective(this, ['CustomResourceProviderBase']);
break;
}
case CUSTOM_RESOURCE_PROVIDER_OPTIONS.fqn: {
CUSTOM_RESOURCE_PROVIDER_OPTIONS.importSelective(this, ['CustomResourceProviderOptions']);
break;
}
case LAMBDA_MODULE.fqn: {
LAMBDA_MODULE.import(this, 'lambda');
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ class CoreModule extends ExternalModule {
}
}

class Stack extends ExternalModule {
public constructor() {
super('../../lib/stack');
}
}

class CustomResourceProviderBase extends ExternalModule {
public readonly CustomResourceProviderBase = Type.fromName(this, 'CustomResourceProviderBase');

public constructor() {
super('../../lib/custom-resource-provider/custom-resource-provider-base');
}
}

class CustomResourceProviderOptions extends ExternalModule {
public readonly CustomResourceProviderOptions = Type.fromName(this, 'CustomResourceProviderOptions');

public constructor() {
super('../../lib/custom-resource-provider/shared');
}
}

class LambdaModule extends ExternalModule {
public readonly Function = Type.fromName(this, 'Function');
public readonly SingletonFunction = Type.fromName(this, 'SingletonFunction');
Expand All @@ -38,3 +60,7 @@ export const PATH_MODULE = new PathModule();
export const CONSTRUCTS_MODULE = new ConstructsModule();
export const CORE_MODULE = new CoreModule();
export const LAMBDA_MODULE = new LambdaModule();

export const STACK = new Stack();
export const CUSTOM_RESOURCE_PROVIDER_BASE = new CustomResourceProviderBase();
export const CUSTOM_RESOURCE_PROVIDER_OPTIONS = new CustomResourceProviderOptions();
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
fs.mkdirSync(path.dirname(outfile), { recursive: true });
fs.copyFileSync(component.sourceCode, outfile);
} else {
await bundleAndMinify(component.sourceCode, outfile);
await minifyAndBundle(component.sourceCode, outfile);
}
const sourceCodeDirectory = path.dirname(outfile).split('/').pop();
module.build(component, `${sourceCodeDirectory}`);
Expand All @@ -43,7 +43,7 @@ async function main() {
}
}

async function bundleAndMinify(infile: string, outfile: string) {
async function minifyAndBundle(infile: string, outfile: string) {
const result = await esbuild.build({
entryPoints: [infile],
outfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ awscdklibdir=${scriptdir}/..
customresourcedir=$(node -p "path.dirname(require.resolve('@aws-cdk/custom-resource-handlers/package.json'))")

function airlift() {
echo $1
# core needs to be airlifted directly to core to prevent circular dependencies
if [[ $1 = dist/core/* || $1 = dist/core ]];
then
Expand Down

0 comments on commit b0e9ba4

Please sign in to comment.