Skip to content
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

feat: sandbox deployment events #254

Merged
merged 100 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
8bbde6d
feat: sandbox options add format
zhamujun Sep 15, 2023
7ad12f1
test: add format to available options
zhamujun Sep 15, 2023
0ef8755
fix: sandbox command option format
zhamujun Sep 15, 2023
1d7c2f9
Merge branch 'main' into sandbox-option-format
zhamujun Sep 15, 2023
92a49e7
add changeset
zhamujun Sep 15, 2023
0063a4d
chore: update API.md
zhamujun Sep 15, 2023
7a77b27
refactor: move get_config_path to client-config
zhamujun Sep 18, 2023
a45c889
chore: type and lint
zhamujun Sep 18, 2023
5c58fe4
chore: update API.md
zhamujun Sep 18, 2023
eefeaf0
Merge branch 'main' into sandbox-option-format
zhamujun Sep 18, 2023
bd0f86e
chore: import formatChoices to sandbox
zhamujun Sep 18, 2023
c861be3
Merge branch 'main' into sandbox-option-format
zhamujun Sep 19, 2023
6309b05
chore: change template literal
zhamujun Sep 19, 2023
87530a6
chore: update types, use Enum
zhamujun Sep 19, 2023
f176750
chore: update types for FormatOption
zhamujun Sep 19, 2023
1986cd0
chore: fix type
zhamujun Sep 19, 2023
ea110b3
chore: move getConfigPath to internal api
zhamujun Sep 19, 2023
516bb8a
chore: rename getClientConfigPath
zhamujun Sep 19, 2023
c1f1c0f
chore: rename FormatChoice
zhamujun Sep 19, 2023
40d20fb
chore: update API.md
zhamujun Sep 19, 2023
cf25eac
chore: add index.js to internal.ts
zhamujun Sep 19, 2023
75f6be7
chore: remove configFileName and formatChoices from API
zhamujun Sep 19, 2023
cddb7c2
fix: test
zhamujun Sep 20, 2023
94625e7
Merge branch 'main' into sandbox-option-format
zhamujun Sep 20, 2023
0feeafe
sandbox: initial implementation of deployment hooks
sdstolworthy Sep 20, 2023
05075f9
sandbox: simplify hook registration example
sdstolworthy Sep 20, 2023
bdb2f65
lint: fix lints
sdstolworthy Sep 20, 2023
c77acac
refactor: use events instead of hooks
sdstolworthy Sep 20, 2023
1e973a9
api: update api description files
sdstolworthy Sep 20, 2023
f98b49f
logging: added debug logging
sdstolworthy Sep 20, 2023
f43c10f
tests: fix broken test
sdstolworthy Sep 20, 2023
39d0d46
sandbox: base event handler on node:events EventEmitter
sdstolworthy Sep 20, 2023
8c546d1
tests: fix broken test
sdstolworthy Sep 20, 2023
57ec633
chore: move getConfigPath from GenerateConfigCommand to generateClien…
zhamujun Sep 20, 2023
3575c06
Update packages/client-config/src/paths/get_client_config_path.ts
0618 Sep 20, 2023
f941266
chore: rename FormatChoice to ClientConfigFormat
zhamujun Sep 20, 2023
944f373
refactor: generateClientConfigToFile to accept out and format
zhamujun Sep 20, 2023
5153d15
test: update tests for generate config and sandbox
zhamujun Sep 20, 2023
3b93e66
Update packages/cli/src/commands/sandbox/sandbox_command.ts
0618 Sep 20, 2023
42d79f2
test: misc var change
zhamujun Sep 20, 2023
692b804
chore: move ClientConfigFormat to public API
zhamujun Sep 20, 2023
b85d43e
chore: update API.md
zhamujun Sep 20, 2023
d53ccb1
test: add test for getClientConfigPath
zhamujun Sep 20, 2023
915b7b8
test: use path.join to resolve windows slash
zhamujun Sep 20, 2023
a60d541
test: use path.join to resolve windows slash
zhamujun Sep 21, 2023
fc86f13
chore: fix linting error
zhamujun Sep 21, 2023
aa35750
chore: fix linting error
zhamujun Sep 21, 2023
bda8e37
chore: remove defaultOptions
zhamujun Sep 21, 2023
006628f
test: add asserts for both out and format
zhamujun Sep 21, 2023
4813824
test: add absolut path test
zhamujun Sep 21, 2023
134f2a5
Merge branch 'main' into sandbox-hooks
sdstolworthy Sep 21, 2023
c1f2f00
Merge branch 'sandbox-option-format' into sandbox-hooks
sdstolworthy Sep 21, 2023
e378e28
fix: throw error if provided file path
zhamujun Sep 21, 2023
da5987d
fix: broken test
sdstolworthy Sep 21, 2023
5acd13a
Merge branch 'main' into sandbox-option-format
zhamujun Sep 21, 2023
8dd2666
fix: integrate format into event callback
sdstolworthy Sep 21, 2023
406a9fa
Merge branch 'sandbox-option-format' into sandbox-hooks
sdstolworthy Sep 21, 2023
f109014
api: update api description files
sdstolworthy Sep 21, 2023
2002f12
fix: address pr comments
sdstolworthy Sep 21, 2023
6498e71
Merge branch 'main' into sandbox-option-format
zhamujun Sep 21, 2023
fd3a87f
chore: rename --out to --outDir
zhamujun Sep 21, 2023
0098475
fix: use lstatSync to detect file path
zhamujun Sep 21, 2023
3a8dc90
chore: update API.md
zhamujun Sep 21, 2023
a9ca6ca
chore: changeset
zhamujun Sep 21, 2023
6f7bf38
chore: remove un-used var
zhamujun Sep 21, 2023
f17ca5a
fix: package-lock resolve registry
zhamujun Sep 21, 2023
cbc6e3b
chore: ignore spell of lstat
zhamujun Sep 21, 2023
810b694
chore: refactor mock-fs with node:mock
zhamujun Sep 21, 2023
4b7b051
chore: remove un-used var
zhamujun Sep 21, 2023
135d263
chore: make getClientConfigPath async
zhamujun Sep 21, 2023
5cb83a9
Merge branch 'sandbox-option-format' into sandbox-hooks
sdstolworthy Sep 21, 2023
4105ee0
fix: path for windows
zhamujun Sep 21, 2023
dbaed8c
Merge branch 'main' into sandbox-option-format
zhamujun Sep 21, 2023
cbd4e46
chore: remove auto-generated changelogs
zhamujun Sep 21, 2023
28a15b2
Merge branch 'sandbox-option-format' into sandbox-hooks
sdstolworthy Sep 21, 2023
305c2ca
fix: remove references to deleted events
sdstolworthy Sep 21, 2023
964b9be
api: update api description files
sdstolworthy Sep 21, 2023
49e3f11
Merge branch 'main' of github.com:aws-amplify/samsara-cli into sandbo…
sdstolworthy Sep 22, 2023
49dc760
refactor: rename event, move generate-config-adapter
sdstolworthy Sep 22, 2023
3da09fa
refactor: remove sandbox config adapter
sdstolworthy Sep 22, 2023
8ed1025
refactor: use args.out directly for config write path
sdstolworthy Sep 22, 2023
2ba6fd0
refactor: use exported getClientConfigPath from client-config package
sdstolworthy Sep 22, 2023
046eb3f
refactor: use mocks for test
sdstolworthy Sep 22, 2023
2c71a88
fix: explicitly export getClientConfigPath
sdstolworthy Sep 22, 2023
ff06a37
Update packages/sandbox/src/file_watching_sandbox.ts
sdstolworthy Sep 22, 2023
1356052
fix: remove unused import
sdstolworthy Sep 22, 2023
6c390d9
Merge branch 'sandbox-hooks' of github.com:sdstolworthy/samsara-cli i…
sdstolworthy Sep 22, 2023
30f5572
Update packages/cli/src/commands/sandbox/sandbox_command.ts
sdstolworthy Sep 22, 2023
a816b14
refactor: extract getBackendIdentifier
sdstolworthy Sep 22, 2023
6c201eb
test: add test to validate that successfulDeployment event is emitted
sdstolworthy Sep 22, 2023
bd5d258
test: refactor to allow asserting that a specific callback was regist…
sdstolworthy Sep 22, 2023
dcbcbc7
fix: remove unused import
sdstolworthy Sep 22, 2023
008406e
Merge branch 'main' into sandbox-hooks
sdstolworthy Sep 22, 2023
67f118a
refactor: creator method for registering sandbox events
sdstolworthy Sep 22, 2023
afd1012
fix: remove unused import
sdstolworthy Sep 22, 2023
6607c76
fix: fix naming, refactor for readability
sdstolworthy Sep 22, 2023
f2ab03e
Sandbox hooks (#274)
sdstolworthy Sep 22, 2023
7885a8c
Merge branch 'main' of github.com:aws-amplify/samsara-cli into sandbo…
sdstolworthy Sep 27, 2023
2f700db
fix: add delay
sdstolworthy Sep 27, 2023
f0b70c3
Merge branch 'e2e-sandbox-events' of github.com:aws-amplify/samsara-c…
sdstolworthy Sep 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { CommandModule } from 'yargs';
import { GenerateCommand } from './generate_command.js';
import { GenerateConfigCommand } from './config/generate_config_command.js';
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
import { GenerateFormsCommand } from './forms/generate_forms_command.js';
import { CwdPackageJsonLoader } from '../../cwd_package_json_loader.js';
import { GenerateGraphqlClientCodeCommand } from './graphql-client-code/generate_graphql_client_code_command.js';
import { LocalAppNameResolver } from '../../backend-identifier/local_app_name_resolver.js';
import { BackendIdentifierResolver } from '../../backend-identifier/backend_identifier_resolver.js';
import { ClientConfigGeneratorAdapter } from '../../client-config/client_config_generator_adapter.js';
import { FormGenerationHandler } from './forms/form_generation_handler.js';
import { BackendOutputClient } from '@aws-amplify/deployed-backend-client';
import { GenerateApiCodeAdapter } from './graphql-client-code/generate_api_code_adapter.js';

/**
* Creates wired generate command.
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/commands/sandbox/sandbox_command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createSandboxCommand } from './sandbox_command_factory.js';
import { SandboxDeleteCommand } from './sandbox-delete/sandbox_delete_command.js';
import { Sandbox, SandboxSingletonFactory } from '@aws-amplify/sandbox';
import { ClientConfigGeneratorAdapter } from '../../client-config/client_config_generator_adapter.js';
import { createSandboxSecretCommand } from './sandbox-secret/sandbox_secret_command_factory.js';

void describe('sandbox command factory', () => {
void it('instantiate a sandbox command correctly', () => {
Expand All @@ -23,7 +24,7 @@ void describe('sandbox command', () => {
let commandRunner: TestCommandRunner;
let sandbox: Sandbox;
let sandboxStartMock = mock.fn<typeof sandbox.start>();
let mockGenerate =
const mockGenerate =
mock.fn<ClientConfigGeneratorAdapter['generateClientConfigToFile']>();
const generationMock = mock.fn<EventHandler>();

Expand All @@ -38,7 +39,7 @@ void describe('sandbox command', () => {

const sandboxCommand = new SandboxCommand(
sandboxFactory,
sandboxDeleteCommand,
[sandboxDeleteCommand, createSandboxSecretCommand()],
() => ({
successfulDeployment: [generationMock],
})
Expand All @@ -49,7 +50,7 @@ void describe('sandbox command', () => {
mockGenerate.mock.resetCalls();
});

it('registers a callback on the "successfulDeployment" event', async () => {
void it('registers a callback on the "successfulDeployment" event', async () => {
const mockOn = mock.method(sandbox, 'on');
await commandRunner.runCommand('sandbox');
assert.equal(mockOn.mock.calls[0].arguments[0], 'successfulDeployment');
Expand All @@ -71,7 +72,7 @@ void describe('sandbox command', () => {
);
});

it('shows available options in help output', async () => {
void it('shows available options in help output', async () => {
const output = await commandRunner.runCommand('sandbox --help');
assert.match(output, /--name/);
assert.match(output, /--dirToWatch/);
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/commands/sandbox/sandbox_command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ArgumentsCamelCase, Argv, CommandModule } from 'yargs';
import { SandboxDeleteCommand } from './sandbox-delete/sandbox_delete_command.js';
import fs from 'fs';
import { AmplifyPrompter } from '../prompter/amplify_prompts.js';
import { SandboxSingletonFactory } from '@aws-amplify/sandbox';
Expand Down Expand Up @@ -56,7 +55,7 @@ export class SandboxCommand
*/
constructor(
private readonly sandboxFactory: SandboxSingletonFactory,
private readonly sandboxDeleteCommand: SandboxDeleteCommand,
private readonly sandboxSubCommands: CommandModule[],
private readonly sandboxEventHandlerCreator?: SandboxEventHandlerCreator
) {
this.command = 'sandbox';
Expand All @@ -74,7 +73,7 @@ export class SandboxCommand
const eventHandlers = this.sandboxEventHandlerCreator?.({
appName: args.name,
format: args.format,
outDir: args.out,
outDir: args.outDir,
});
if (eventHandlers) {
Object.entries(eventHandlers).forEach(([event, handlers]) => {
Expand All @@ -83,7 +82,7 @@ export class SandboxCommand
}
const watchExclusions = args.exclude ?? [];
const clientConfigWritePath = await getClientConfigPath(
args.out,
args.outDir,
args.format
);
watchExclusions.push(clientConfigWritePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const createSandboxCommand = (): CommandModule<
successfulDeployment: [
async () => {
const id = await getBackendIdentifier(appName);
clientConfigGeneratorAdapter.generateClientConfigToFile(
await clientConfigGeneratorAdapter.generateClientConfigToFile(
id,
outDir,
format
Expand All @@ -52,7 +52,7 @@ export const createSandboxCommand = (): CommandModule<
};
return new SandboxCommand(
sandboxFactory,
new SandboxDeleteCommand(sandboxFactory),
[new SandboxDeleteCommand(sandboxFactory), createSandboxSecretCommand()],
sandboxEventHandlerCreator
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class ProcessController {
if (typeof currentInteraction.payload === 'string') {
if (currentInteraction.payload === CONTROL_C) {
if (process.platform.startsWith('win')) {
// Wait X milliseconds before sending kill in hopes of draining the node event queue
await new Promise((resolve) => setTimeout(resolve, 5000));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved as long as we add a GH issue to the backlog to track this. Bonus points for linking to that issue in the comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// turns out killing child process on Windows is a huge PITA
// https://stackoverflow.com/questions/23706055/why-can-i-not-kill-my-child-process-in-nodejs-on-windows
// https://github.com/sindresorhus/execa#killsignal-options
Expand Down
4 changes: 2 additions & 2 deletions packages/sandbox/src/file_watching_sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void describe('Sandbox with absolute output path', () => {
await sandboxInstance.stop();
});

it('sets AWS profile when starting sandbox', async () => {
void it('sets AWS profile when starting sandbox', async () => {
assert.strictEqual(process.env.AWS_PROFILE, 'amplify-sandbox');
});
});
Expand Down Expand Up @@ -388,7 +388,7 @@ void describe('Sandbox ignoring paths in .gitignore', () => {
// CDK should also be called once
assert.strictEqual(execaDeployMock.mock.callCount(), 1);
});
it('emits the successfulDeployment event after deployment', async () => {
void it('emits the successfulDeployment event after deployment', async () => {
const mockListener = mock.fn();
const mockDeploy = mock.fn();
mockDeploy.mock.mockImplementation(async () => null);
Expand Down