Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
simplify component name checking
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Feb 24, 2024
1 parent 09684ac commit 02f8de1
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions pkg/platform/src/auto/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,20 @@ export async function run(program: automation.PulumiFn) {

const componentNames = new Set<string>();
runtime.registerStackTransformation((args: ResourceTransformationArgs) => {
if (args.type.startsWith("pulumi")) {
return;
}

if (componentNames.has(args.name)) {
throw new VisibleError(
`Invalid component name "${args.name}". Component names must be unique.`,
);
}
componentNames.add(args.name);
let normalizedName = args.name;
if (
args.type === "pulumi-nodejs:dynamic:Resource" ||
args.type === "pulumi:providers:aws"
) {
const parts = args.name.split(".");
if (parts.length === 4 && parts[1] === "sst") {
normalizedName = parts[0];
}
}

if (!normalizedName.match(/^[A-Z][a-zA-Z0-9]*$/)) {
if (!args.name.match(/^[A-Z][a-zA-Z0-9]*$/)) {
throw new Error(
`Invalid component name "${normalizedName}". Component names must start with an uppercase letter and contain only alphanumeric characters.`,
`Invalid component name "${args.name}". Component names must start with an uppercase letter and contain only alphanumeric characters.`,
);
}

Expand All @@ -63,8 +57,7 @@ export async function run(program: automation.PulumiFn) {

Link.makeLinkable(aws.dynamodb.Table, function () {
return {
type: `{ tableName: string }`,
value: { tableName: this.name },
properties: { tableName: this.name },
};
});
Link.AWS.makeLinkable(aws.dynamodb.Table, function () {
Expand Down

0 comments on commit 02f8de1

Please sign in to comment.