Skip to content

Commit 31b148b

Browse files
committed
Apply prettier
1 parent 4eb3d16 commit 31b148b

File tree

9 files changed

+93
-104
lines changed

9 files changed

+93
-104
lines changed

adapter.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { writeFileSync } from 'fs'
22
import { join } from 'path'
33
import * as url from 'url'
44

5-
import { LocalProgramArgs, LocalWorkspace } from '@pulumi/pulumi/automation/index.js'
5+
import {
6+
LocalProgramArgs,
7+
LocalWorkspace,
8+
} from '@pulumi/pulumi/automation/index.js'
69
import {
710
buildServer,
811
buildOptions,
@@ -43,7 +46,7 @@ export function adapter({
4346
MEMORY_SIZE,
4447
zoneName = 'us-east-2',
4548
env = {},
46-
pulumiPaths = []
49+
pulumiPaths = [],
4750
}: AWSAdapterProps = {}) {
4851
/** @type {import('@sveltejs/kit').Adapter} */
4952
return {
@@ -69,12 +72,13 @@ export function adapter({
6972
serverArgs,
7073
{
7174
envVars: {
72-
'TS_NODE_IGNORE': '^(?!.*(sveltekit-adapter-aws-pulumi)).*'
73-
}
74-
})
75+
TS_NODE_IGNORE: '^(?!.*(sveltekit-adapter-aws-pulumi)).*',
76+
},
77+
}
78+
)
7579

7680
// Set the AWS region.
77-
await serverStack.setConfig("aws:region", { value: zoneName });
81+
await serverStack.setConfig('aws:region', { value: zoneName })
7882

7983
await serverStack.setAllConfig({
8084
projectPath: { value: '.env' },
@@ -83,7 +87,6 @@ export function adapter({
8387
memorySizeStr: { value: String(MEMORY_SIZE) },
8488
})
8589

86-
8790
const serverStackUpResult = await serverStack.up({
8891
onOutput: console.info,
8992
})
@@ -103,16 +106,14 @@ export function adapter({
103106
stackName: stackName,
104107
workDir: mainPath,
105108
}
106-
const mainStack = await LocalWorkspace.createOrSelectStack(
107-
mainArgs,
108-
{
109-
envVars: {
110-
'TS_NODE_IGNORE': '^(?!.*(sveltekit-adapter-aws-pulumi)).*'
111-
}
112-
})
109+
const mainStack = await LocalWorkspace.createOrSelectStack(mainArgs, {
110+
envVars: {
111+
TS_NODE_IGNORE: '^(?!.*(sveltekit-adapter-aws-pulumi)).*',
112+
},
113+
})
113114

114115
// Set the AWS region.
115-
await mainStack.setConfig("aws:region", { value: zoneName });
116+
await mainStack.setConfig('aws:region', { value: zoneName })
116117

117118
await mainStack.setAllConfig({
118119
edgePath: { value: edge_directory },
@@ -133,15 +134,17 @@ export function adapter({
133134
}
134135

135136
const mainStackUpResult = await mainStack.up({ onOutput: console.info })
136-
const mainAllowedOrigins = JSON.stringify(mainStackUpResult.outputs.allowedOrigins.value)
137-
137+
const mainAllowedOrigins = JSON.stringify(
138+
mainStackUpResult.outputs.allowedOrigins.value
139+
)
140+
138141
let serverAllowedOrigins: string = ''
139142
const serverConfig = await serverStack.getAllConfig()
140-
141-
if ('allowedOrigins' in serverConfig){
143+
144+
if ('allowedOrigins' in serverConfig) {
142145
serverAllowedOrigins = serverConfig['allowedOrigins'].value
143146
}
144-
147+
145148
if (serverAllowedOrigins !== mainAllowedOrigins) {
146149
// Call the server stack setting the allowed origins
147150
await serverStack.setConfig('allowedOrigins', {

bin/destroy.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ export async function main(args: string[]): Promise<void> {
3131
throw error
3232
}
3333
}
34-
34+
3535
for (const pulumiPath of adapterProps.pulumiPaths!) {
36-
3736
spawnSync(
3837
'pulumi',
3938
['destroy', '-f', '-s', adapterProps.stackName!, '-y', '--refresh'],
@@ -43,7 +42,6 @@ export async function main(args: string[]): Promise<void> {
4342
env: process.env,
4443
}
4544
)
46-
4745
}
4846
}
4947

stacks/main/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const routerHandler = buildRouter(iamForLambda, edgePath!)
3333

3434
let certificateArn: pulumi.Input<string> | undefined
3535

36-
3736
if (FQDN) {
3837
certificateArn = validateCertificate(FQDN!, domainName)
3938
}

stacks/main/resources.ts

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,40 @@ const eastRegion = new aws.Provider(registerName('ProviderEast'), {
1818
})
1919

2020
export function getLambdaRole(functionArns?: string[]): aws.iam.Role {
21-
2221
interface IAMPolicy {
2322
statements: [
2423
{
2524
principals?: [
2625
{
27-
type: string,
26+
type: string
2827
identifiers: string[]
2928
}
30-
],
31-
actions: string[],
32-
effect: string,
29+
]
30+
actions: string[]
31+
effect: string
3332
resources?: string[]
3433
}
3534
]
3635
}
37-
36+
3837
let lambdaPolicyStub: IAMPolicy = {
3938
statements: [
4039
{
4140
principals: [
4241
{
4342
type: 'Service',
44-
identifiers: [
45-
'lambda.amazonaws.com',
46-
'edgelambda.amazonaws.com'
47-
],
43+
identifiers: ['lambda.amazonaws.com', 'edgelambda.amazonaws.com'],
4844
},
4945
],
5046
actions: ['sts:AssumeRole'],
5147
effect: 'Allow',
5248
},
53-
]
49+
],
5450
}
55-
51+
5652
let lambdaPolicyDocument = aws.iam.getPolicyDocumentOutput(lambdaPolicyStub)
5753
const iamForLambda = new aws.iam.Role(registerName('IamForLambda'), {
58-
assumeRolePolicy: lambdaPolicyDocument.json
54+
assumeRolePolicy: lambdaPolicyDocument.json,
5955
})
6056

6157
new aws.iam.RolePolicyAttachment(
@@ -67,33 +63,28 @@ export function getLambdaRole(functionArns?: string[]): aws.iam.Role {
6763
)
6864

6965
if (functionArns) {
70-
7166
lambdaPolicyStub = {
7267
statements: [
7368
{
7469
actions: ['lambda:InvokeFunctionUrl'],
7570
effect: 'Allow',
76-
resources: functionArns
77-
}
78-
]
71+
resources: functionArns,
72+
},
73+
],
7974
}
80-
75+
8176
lambdaPolicyDocument = aws.iam.getPolicyDocumentOutput(lambdaPolicyStub)
82-
83-
const policy = new aws.iam.Policy(registerName("invokePolicy"), {
84-
policy: lambdaPolicyDocument.json
77+
78+
const policy = new aws.iam.Policy(registerName('invokePolicy'), {
79+
policy: lambdaPolicyDocument.json,
80+
})
81+
82+
new aws.iam.RolePolicyAttachment(registerName('ServerRPAInvokePolicy'), {
83+
role: iamForLambda.name,
84+
policyArn: policy.arn,
8585
})
86-
87-
new aws.iam.RolePolicyAttachment(
88-
registerName('ServerRPAInvokePolicy'),
89-
{
90-
role: iamForLambda.name,
91-
policyArn: policy.arn
92-
}
93-
)
94-
9586
}
96-
87+
9788
return iamForLambda
9889
}
9990

@@ -297,7 +288,7 @@ export function buildCDN(
297288
.apply(([arn, version]) => {
298289
return `${arn}:${version}`
299290
}),
300-
includeBody: true
291+
includeBody: true,
301292
},
302293
],
303294
originRequestPolicyId: defaultRequestPolicy.id,

tests/adapter.test.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,31 @@ vi.mock('@pulumi/pulumi/automation/index.js', () => {
1414
const Stack = {
1515
setConfig: vi.fn(),
1616
setAllConfig: vi.fn(),
17-
getAllConfig: vi.fn(() => {return {}}),
18-
up: vi.fn(() => {return {
19-
outputs: {
20-
serverDomain: {
21-
value: 'mock'
22-
},
23-
optionsDomain: {
24-
value: 'mock'
17+
getAllConfig: vi.fn(() => {
18+
return {}
19+
}),
20+
up: vi.fn(() => {
21+
return {
22+
outputs: {
23+
serverDomain: {
24+
value: 'mock',
25+
},
26+
optionsDomain: {
27+
value: 'mock',
28+
},
29+
allowedOrigins: {
30+
value: ['mock'],
31+
},
2532
},
26-
allowedOrigins: {
27-
value: ['mock']
28-
}
2933
}
30-
}
31-
}),
34+
}),
3235
}
3336
const LocalWorkspace = {
34-
createOrSelectStack: vi.fn(() => Stack)
37+
createOrSelectStack: vi.fn(() => Stack),
3538
}
36-
39+
3740
return {
38-
LocalWorkspace
41+
LocalWorkspace,
3942
}
4043
})
4144

@@ -57,10 +60,10 @@ describe('adapter.ts', () => {
5760
})
5861
;(buildOptions as any).mockImplementation(() => {
5962
return 'mock'
60-
})
63+
})
6164
;(buildRouter as any).mockImplementation(() => {
6265
return 'mock'
63-
})
66+
})
6467

6568
const builder = {
6669
log: {

tests/bin.destroy.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ describe('bin/destroy.ts', () => {
3333
const propsPath = path.join(buildDir, '.adapterprops.json')
3434

3535
const expectedStackName = 'mock'
36-
const expectedPulumiPaths = [
37-
'stacks/one',
38-
'stacks/two'
39-
]
36+
const expectedPulumiPaths = ['stacks/one', 'stacks/two']
4037
const json = JSON.stringify({
4138
stackName: expectedStackName,
4239
pulumiPaths: expectedPulumiPaths,
@@ -71,10 +68,7 @@ describe('bin/destroy.ts', () => {
7168
const propsPath = path.join(tmpDir, '.adapterprops.json')
7269

7370
const expectedStackName = 'mock'
74-
const expectedPulumiPaths = [
75-
'stacks/one',
76-
'stacks/two'
77-
]
71+
const expectedPulumiPaths = ['stacks/one', 'stacks/two']
7872
const json = JSON.stringify({
7973
stackName: expectedStackName,
8074
pulumiPaths: expectedPulumiPaths,

tests/stacks.main.index.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ describe('stacks/main/index.ts', () => {
3838
return '{"mock": "mock"}'
3939
}
4040
return ''
41-
})
41+
}),
4242
}
43-
});
43+
})
4444

4545
infra = await import('../stacks/main')
4646

@@ -50,8 +50,10 @@ describe('stacks/main/index.ts', () => {
5050
expect(resources.buildCDN).toHaveBeenCalledTimes(1)
5151
expect(resources.createAliasRecord).toHaveBeenCalledTimes(0)
5252
expect(resources.buildInvalidator).toHaveBeenCalledTimes(1)
53-
54-
const allowedOrigin = await promiseOf(infra.allowedOrigins[0] as pulumi.Output<string>)
53+
54+
const allowedOrigin = await promiseOf(
55+
infra.allowedOrigins[0] as pulumi.Output<string>
56+
)
5557
const appUrl = await promiseOf(infra.appUrl as pulumi.Output<string>)
5658
expect(allowedOrigin).toMatch('https://example.com')
5759
expect(appUrl).toMatch('https://example.com')
@@ -77,16 +79,18 @@ describe('stacks/main/index.ts', () => {
7779
return fqdn
7880
}
7981
return ''
80-
})
82+
}),
8183
}
82-
});
84+
})
8385

8486
infra = await import('../stacks/main')
8587

8688
expect(resources.validateCertificate).toHaveBeenCalledTimes(1)
8789
expect(resources.createAliasRecord).toHaveBeenCalledTimes(1)
88-
89-
const distOrigin = await promiseOf(infra.allowedOrigins[0] as pulumi.Output<string>)
90+
91+
const distOrigin = await promiseOf(
92+
infra.allowedOrigins[0] as pulumi.Output<string>
93+
)
9094
const fqdnOrigin = infra.allowedOrigins[1]
9195

9296
expect(distOrigin).toMatch('https://example.com')

0 commit comments

Comments
 (0)