Skip to content

Commit 28343b2

Browse files
authored
Lint class member order (#872)
1 parent 88f7a71 commit 28343b2

File tree

23 files changed

+507
-488
lines changed

23 files changed

+507
-488
lines changed

.changeset/thirty-onions-hear.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ module.exports = {
8383
],
8484
'@typescript-eslint/restrict-template-expressions': 'error',
8585
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
86+
'@typescript-eslint/member-ordering': 'error',
8687
'@shopify/prefer-early-return': 'error',
8788
'check-file/filename-blocklist': [
8889
'error',

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ expected-cdk-out
1111
.changeset/pre.json
1212
concurrent_workspace_script_cache.json
1313
scripts/components/api-changes-validator/test-resources/working-directory
14+
test-projects

packages/auth-construct/src/construct.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,26 @@ export class AmplifyAuth
217217
);
218218
}
219219

220+
/**
221+
* Attach a Lambda function trigger handler to the UserPool in this construct
222+
* @param event - The trigger event operation
223+
* @param handler - The function that will handle the event
224+
*/
225+
addTrigger = (
226+
event: TriggerEvent,
227+
handler: IFunction | AmplifyFunction
228+
): void => {
229+
if ('resources' in handler) {
230+
this.userPool.addTrigger(
231+
UserPoolOperation.of(event),
232+
handler.resources.lambda
233+
);
234+
} else {
235+
// handler is an IFunction
236+
this.userPool.addTrigger(UserPoolOperation.of(event), handler);
237+
}
238+
};
239+
220240
/**
221241
* Create Auth/UnAuth Roles
222242
* @returns DefaultRoles
@@ -813,24 +833,4 @@ export class AmplifyAuth
813833
payload: output,
814834
});
815835
};
816-
817-
/**
818-
* Attach a Lambda function trigger handler to the UserPool in this construct
819-
* @param event - The trigger event operation
820-
* @param handler - The function that will handle the event
821-
*/
822-
addTrigger = (
823-
event: TriggerEvent,
824-
handler: IFunction | AmplifyFunction
825-
): void => {
826-
if ('resources' in handler) {
827-
this.userPool.addTrigger(
828-
UserPoolOperation.of(event),
829-
handler.resources.lambda
830-
);
831-
} else {
832-
// handler is an IFunction
833-
this.userPool.addTrigger(UserPoolOperation.of(event), handler);
834-
}
835-
};
836836
}

packages/backend-deployer/src/cdk_deployer.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,59 @@ export class CDKDeployer implements BackendDeployer {
6767
return this.tryInvokeCdk(InvokableCommand.DESTROY, backendId, ['--force']);
6868
};
6969

70+
/**
71+
* Wrapper for the child process executor. Helps in unit testing as node:test framework
72+
* doesn't have capabilities to mock exported functions like `execa` as of right now.
73+
*/
74+
executeChildProcess = async (
75+
command: string,
76+
commandArgs: string[],
77+
options: { printStdout: boolean } = { printStdout: true }
78+
) => {
79+
// We let the stdout and stdin inherit and streamed to parent process but pipe
80+
// the stderr and use it to throw on failure. This is to prevent actual
81+
// actionable errors being hidden among the stdout. Moreover execa errors are
82+
// useless when calling CLIs unless you made execa calling error.
83+
let aggregatedStderr = '';
84+
const aggregatorStderrStream = new stream.Writable();
85+
aggregatorStderrStream._write = function (chunk, encoding, done) {
86+
aggregatedStderr += chunk;
87+
done();
88+
};
89+
90+
const childProcess = execa(command, commandArgs, {
91+
stdin: 'inherit',
92+
stdout: 'pipe',
93+
stderr: 'pipe',
94+
95+
// Piping the output by default strips off the color. This is a workaround to
96+
// preserve the color being piped to parent process.
97+
extendEnv: true,
98+
env: { FORCE_COLOR: '1' },
99+
});
100+
childProcess.stderr?.pipe(aggregatorStderrStream);
101+
102+
if (options?.printStdout) {
103+
childProcess.stdout?.pipe(process.stdout);
104+
}
105+
106+
const cdkOutput = { deploymentTimes: {} };
107+
if (childProcess.stdout) {
108+
await this.populateCDKOutputFromStdout(cdkOutput, childProcess.stdout);
109+
}
110+
111+
try {
112+
await childProcess;
113+
return cdkOutput;
114+
} catch (error) {
115+
// swallow execa error which is most of the time noise (basically child exited with exit code...)
116+
// bubbling this up to customers add confusion (Customers don't need to know we are running IPC calls
117+
// and their exit codes printed while sandbox continue to run). Hence we explicitly don't pass error in the cause
118+
// rather throw the entire stderr for clients to figure out what to do with it.
119+
throw new Error(aggregatedStderr);
120+
}
121+
};
122+
70123
private invokeTsc = async (deployProps?: DeployProps) => {
71124
if (!deployProps?.validateAppSources) {
72125
return;
@@ -172,59 +225,6 @@ export class CDKDeployer implements BackendDeployer {
172225
return await this.executeChildProcess('npx', cdkCommandArgs);
173226
};
174227

175-
/**
176-
* Wrapper for the child process executor. Helps in unit testing as node:test framework
177-
* doesn't have capabilities to mock exported functions like `execa` as of right now.
178-
*/
179-
executeChildProcess = async (
180-
command: string,
181-
commandArgs: string[],
182-
options: { printStdout: boolean } = { printStdout: true }
183-
) => {
184-
// We let the stdout and stdin inherit and streamed to parent process but pipe
185-
// the stderr and use it to throw on failure. This is to prevent actual
186-
// actionable errors being hidden among the stdout. Moreover execa errors are
187-
// useless when calling CLIs unless you made execa calling error.
188-
let aggregatedStderr = '';
189-
const aggregatorStderrStream = new stream.Writable();
190-
aggregatorStderrStream._write = function (chunk, encoding, done) {
191-
aggregatedStderr += chunk;
192-
done();
193-
};
194-
195-
const childProcess = execa(command, commandArgs, {
196-
stdin: 'inherit',
197-
stdout: 'pipe',
198-
stderr: 'pipe',
199-
200-
// Piping the output by default strips off the color. This is a workaround to
201-
// preserve the color being piped to parent process.
202-
extendEnv: true,
203-
env: { FORCE_COLOR: '1' },
204-
});
205-
childProcess.stderr?.pipe(aggregatorStderrStream);
206-
207-
if (options?.printStdout) {
208-
childProcess.stdout?.pipe(process.stdout);
209-
}
210-
211-
const cdkOutput = { deploymentTimes: {} };
212-
if (childProcess.stdout) {
213-
await this.populateCDKOutputFromStdout(cdkOutput, childProcess.stdout);
214-
}
215-
216-
try {
217-
await childProcess;
218-
return cdkOutput;
219-
} catch (error) {
220-
// swallow execa error which is most of the time noise (basically child exited with exit code...)
221-
// bubbling this up to customers add confusion (Customers don't need to know we are running IPC calls
222-
// and their exit codes printed while sandbox continue to run). Hence we explicitly don't pass error in the cause
223-
// rather throw the entire stderr for clients to figure out what to do with it.
224-
throw new Error(aggregatedStderr);
225-
}
226-
};
227-
228228
private populateCDKOutputFromStdout = async (
229229
output: DeployResult | DestroyResult,
230230
stdout: stream.Readable

packages/backend-secret/src/secret_error.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ export class SecretError extends Error {
2323
this.httpStatusCode = options?.httpStatusCode;
2424
}
2525

26+
/**
27+
* Creates a secret error from an underlying cause.
28+
*/
29+
static createInstance = (cause: Error): SecretError => {
30+
if (cause instanceof SSMServiceException) {
31+
return SecretError.fromSSMException(cause);
32+
}
33+
return new SecretError(cause.message, { cause });
34+
};
35+
2636
/**
2737
* Creates a secret error from an SSM exception.
2838
*/
@@ -36,14 +46,4 @@ export class SecretError extends Error {
3646
httpStatusCode: ssmException.$metadata.httpStatusCode,
3747
});
3848
};
39-
40-
/**
41-
* Creates a secret error from an underlying cause.
42-
*/
43-
static createInstance = (cause: Error): SecretError => {
44-
if (cause instanceof SSMServiceException) {
45-
return SecretError.fromSSMException(cause);
46-
}
47-
return new SecretError(cause.message, { cause });
48-
};
4949
}

packages/backend/src/backend_factory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ const rootStackTypeIdentifier = 'root';
2626
export class BackendFactory<
2727
T extends Record<string, ConstructFactory<ResourceProvider>>
2828
> {
29-
private readonly stackResolver: StackResolver;
3029
/**
3130
* These are the resolved CDK constructs that are created by the inputs to the constructor
3231
* Used for overriding properties of underlying CDK constructs or to reference in custom CDK code
3332
*/
3433
readonly resources: {
3534
[K in keyof T]: ReturnType<T[K]['getInstance']>;
3635
};
36+
37+
private readonly stackResolver: StackResolver;
3738
/**
3839
* Initialize an Amplify backend with the given construct factories and in the given CDK App.
3940
* If no CDK App is specified a new one is created

0 commit comments

Comments
 (0)