Skip to content

Commit 4326d77

Browse files
authored
refactor: separate toolkit into core library (aws#4475)
In order to share code between multiple extensions we need to create a core library. Rather than create a core lib package, we decided to rename the current toolkit as a core library and create a barebones replacement that will generate the extension by importing from the core lib. This is easier than searching for common components, unwiring them, and hoisting them into an empty core lib package. List of commits: * initial restructuring and code moving * rename toolkit to core * rename stuff to core, 'inherit' fields from core package.json * rename toolkit2 to toolkit, cleanup * debugging works (non chrome/webpack only) * run in browser (but debugging doesnt work) * delete resources, package.nls.json * move/update auxillary files, e.g. types/, templates/, etc * update vscode configurations, build scripts, core lib tests. * update infra configs (e.g. root package.json, codecov) * remove unnecessary changes * update AWS.Token import error comments * fix web tests by adding webCompile to core * generalize .vscodeignore, remove dev artifacts * fix package.json scripts * update documentation * fix import from mainline commit, fix prepublish script * remove compile from postinstall in core lib * try compiling on install with bigger heap size * try to fix flaky linux unit tests * add more docs + workspace file for easier opening * fix up configs * update docs to specify how to import from core lib
1 parent bd7398a commit 4326d77

File tree

1,411 files changed

+5372
-4770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,411 files changed

+5372
-4770
lines changed

.eslintignore

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ src/codewhisperer/client/codewhispererclient.d.ts
1212
src/codewhisperer/client/codewhispereruserclient.d.ts
1313
src/amazonqFeatureDev/client/featuredevproxyclient.d.ts
1414
src/testFixtures/**
15-
packages/toolkit/src/shared/telemetry/clienttelemetry.d.ts
16-
packages/toolkit/src/codewhisperer/client/codewhispererclient.d.ts
17-
packages/toolkit/src/codewhisperer/client/codewhispereruserclient.d.ts
18-
packages/toolkit/src/amazonqFeatureDev/client/featuredevproxyclient.d.ts
19-
packages/toolkit/src/testFixtures/**
15+
packages/core/src/shared/telemetry/clienttelemetry.d.ts
16+
packages/core/src/codewhisperer/client/codewhispererclient.d.ts
17+
packages/core/src/codewhisperer/client/codewhispereruserclient.d.ts
18+
packages/core/src/amazonqFeatureDev/client/featuredevproxyclient.d.ts
19+
packages/core/src/testFixtures/**

.github/CODEOWNERS

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
* @aws/aws-ides-team
2-
packages/toolkit/src/codewhisperer/ @aws/codewhisperer-team
3-
packages/toolkit/src/amazonqFeatureDev/ @aws/earlybird
4-
packages/toolkit/src/codewhispererChat/ @aws/aws-mynah
5-
packages/toolkit/src/amazonq/ @aws/aws-mynah
2+
packages/core/src/codewhisperer/ @aws/codewhisperer-team
3+
packages/core/src/amazonqFeatureDev/ @aws/earlybird
4+
packages/core/src/codewhispererChat/ @aws/aws-mynah
5+
packages/core/src/amazonq/ @aws/aws-mynah

.github/dependabot.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
version: 2
88
updates:
99
- package-ecosystem: 'npm'
10-
directory: './packages/toolkit/' # Location of package manifests.
10+
directory: './packages/core/' # Location of package manifests.
1111
target-branch: 'master' # Avoid updates to "staging".
1212
commit-message:
1313
prefix: 'deps'
@@ -25,7 +25,7 @@ updates:
2525
- '@smithy*'
2626
- 'smithy*'
2727
- package-ecosystem: 'github-actions'
28-
directory: './packages/toolkit/'
28+
directory: './packages/core/'
2929
target-branch: 'master' # Avoid updates to "staging".
3030
commit-message:
3131
prefix: 'deps'

.gitignore

+14-11
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,37 @@ __pycache__
1919
/dependency-graph.svg
2020

2121
# Auto generated definitions
22-
packages/toolkit/src/**/*.gen.ts
22+
packages/*/src/**/*.gen.ts
2323
src.gen/*
24+
2425
# Telemetry definition for testing adding telemetry
25-
packages/toolkit/src/shared/telemetry/vscodeTelemetry.json
26+
packages/core/src/shared/telemetry/vscodeTelemetry.json
2627

2728
# Test reports
2829
.test-reports
2930

3031
# Auto generated type definitions
31-
packages/toolkit/src/shared/telemetry/clienttelemetry.d.ts
32-
packages/toolkit/src/codewhisperer/client/codewhispererclient.d.ts
33-
packages/toolkit/src/codewhisperer/client/codewhispereruserclient.d.ts
34-
packages/toolkit/src/amazonqFeatureDev/client/featuredevproxyclient.d.ts
32+
packages/core/src/shared/telemetry/clienttelemetry.d.ts
33+
packages/core/src/codewhisperer/client/codewhispererclient.d.ts
34+
packages/core/src/codewhisperer/client/codewhispereruserclient.d.ts
35+
packages/core/src/amazonqFeatureDev/client/featuredevproxyclient.d.ts
3536

3637
# Generated by tests
37-
packages/toolkit/src/testFixtures/**/bin
38-
packages/toolkit/src/testFixtures/**/obj
38+
packages/core/src/testFixtures/**/bin
39+
packages/core/src/testFixtures/**/obj
3940

4041
# Generated by copyFiles.ts
4142
packages/*/README*
4243
packages/*/CHANGELOG.md
4344
packages/*/LICENSE
4445
packages/*/NOTICE
46+
packages/toolkit/package.nls.json
47+
packages/toolkit/resources
4548

4649
# Icons
47-
packages/toolkit/resources/icons/cloud9/generated/**
48-
packages/toolkit/resources/fonts/aws-toolkit-icons.woff
49-
packages/toolkit/resources/css/icons.css
50+
packages/*/resources/icons/cloud9/generated/**
51+
packages/*/resources/fonts/aws-toolkit-icons.woff
52+
packages/*/resources/css/icons.css
5053

5154
# local configuration
5255
.local.env

.prettierignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ src.gen/**
1111
src/shared/telemetry/service-2.json
1212
src/testFixtures/**
1313

14-
packages/toolkit/src/shared/telemetry/service-2.json
15-
packages/toolkit/src/testFixtures/**
14+
packages/core/src/shared/telemetry/service-2.json
15+
packages/core/src/testFixtures/**

CONTRIBUTING.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ codebase and sending pull requests.
99
## Getting Started
1010

1111
This project is set up as a typescript monorepo. The documentation throughout this project
12-
is referring to the subproject in [`packages/toolkit/`](./packages/toolkit/). For more information,
13-
see [ARCHITECTURE.md](./docs/ARCHITECTURE.md#monorepo-structure)
12+
is referring to the subprojects [`packages/toolkit/`](./packages/toolkit/) and [`packages/core/`](./packages/core/).
13+
Please see [ARCHITECTURE.md](./docs/ARCHITECTURE.md#monorepo-structure) to understand the
14+
structure of thispackage before contributing.
1415

1516
### Find things to do
1617

@@ -40,8 +41,8 @@ Then clone the repository and install NPM packages:
4041

4142
### Run
4243

43-
Due to the monorepo structure of the project, you can run the extension in VSCode by either opening the
44-
`aws-toolkit-vscode/packages/toolkit` folder directly, or adding it as a root folder in the VSCode Workspace.
44+
Due to the monorepo structure of the project, you must have the `aws-toolkit-vscode/packages/toolkit` folder open as root folder in the workspace.
45+
The easiest way to open the project: File > Open Workspace from File > choose `aws-toolkit-vscode/aws-toolkit-vscode.code-workspace`
4546

4647
To run the extension from VSCode as a Node.js app:
4748

@@ -161,9 +162,8 @@ See [web.md](./docs/web.md) for working with the web mode implementation of the
161162
See [TESTPLAN.md](./docs/TESTPLAN.md) to understand the project's test
162163
structure, mechanics and philosophy.
163164
164-
You can run tests directly from VSCode. Due to the monorepo structure of the project, you must either open
165-
the `aws-toolkit-vscode/packages/toolkit/` folder directly, or add it as a root folder in the VSCode Workspace.
166-
Then:
165+
You can run tests directly from VSCode. Due to the monorepo structure of the project, you must have the `aws-toolkit-vscode/packages/toolkit` folder open as root folder in the workspace.
166+
The easiest way to open the project: File > Open Workspace from File > choose `aws-toolkit-vscode/aws-toolkit-vscode.code-workspace`
167167
168168
1. Select `View > Debug`, or select the Debug pane from the sidebar.
169169
2. From the dropdown at the top of the Debug pane, select the `Extension Tests` configuration.

aws-toolkit-vscode.code-workspace

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
},
6+
{
7+
"path": "packages/core"
8+
},
9+
{
10+
"path": "packages/toolkit"
11+
},
12+
{
13+
"path": "packages/amazonq"
14+
}
15+
],
16+
"settings": {
17+
"typescript.tsdk": "node_modules/typescript/lib"
18+
}
19+
}

buildspec/linuxE2ETests.yml

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ env:
88
AWS_TOOLKIT_TEST_NO_COLOR: '1'
99
# Suppress noisy apt-get/dpkg warnings like "debconf: unable to initialize frontend: Dialog").
1010
DEBIAN_FRONTEND: 'noninteractive'
11+
# Required dir overrides, otherwise the test will likely fail due to too long path names.
12+
# E.g. WARNING: IPC handle <path> is longer than 107 chars, try a shorter --user-data-dir
13+
# followed by Error: Could not delete obsolete instance handle Error: ENOENT: no such file or directory, unlink <path>
14+
AWS_TOOLKIT_TEST_CACHE_DIR: '/tmp/.vscode-test/'
15+
AWS_TOOLKIT_TEST_USER_DIR: '/tmp/.vscode-test/user-data/'
1116

1217
phases:
1318
install:

buildspec/linuxIntegrationTests.yml

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ env:
1111
AWS_TOOLKIT_TEST_NO_COLOR: '1'
1212
# Suppress noisy apt-get/dpkg warnings like "debconf: unable to initialize frontend: Dialog").
1313
DEBIAN_FRONTEND: 'noninteractive'
14+
# Required dir overrides, otherwise the test will likely fail due to too long path names.
15+
# E.g. WARNING: IPC handle <path> is longer than 107 chars, try a shorter --user-data-dir
16+
# followed by Error: Could not delete obsolete instance handle Error: ENOENT: no such file or directory, unlink <path>
17+
AWS_TOOLKIT_TEST_CACHE_DIR: '/tmp/.vscode-test/'
18+
AWS_TOOLKIT_TEST_USER_DIR: '/tmp/.vscode-test/user-data/'
1419

1520
phases:
1621
install:

buildspec/linuxTests.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ env:
88
shell: bash
99
variables:
1010
AWS_TOOLKIT_TEST_NO_COLOR: '1'
11+
# Required dir overrides, otherwise the test will likely fail due to too long path names.
12+
# E.g. WARNING: IPC handle <path> is longer than 107 chars, try a shorter --user-data-dir
13+
# followed by Error: Could not delete obsolete instance handle Error: ENOENT: no such file or directory, unlink <path>
14+
AWS_TOOLKIT_TEST_CACHE_DIR: '/tmp/.vscode-test/'
15+
AWS_TOOLKIT_TEST_USER_DIR: '/tmp/.vscode-test/user-data/'
1116

1217
phases:
1318
install:
@@ -25,12 +30,12 @@ phases:
2530
build:
2631
commands:
2732
- export HOME=/home/codebuild-user
28-
# TODO: remove this after lint.yml is enabled in codebuild.
29-
- |
30-
if [ "$VSCODE_TEST_VERSION" = 'insiders' ] ; then
31-
npm run testCompile
32-
npm run lint
33-
fi
33+
# TODO: Enable if we run into issues with GHA linting or remove.
34+
# - |
35+
# if [ "$VSCODE_TEST_VERSION" = 'insiders' ] ; then
36+
# npm run testCompile
37+
# npm run lint
38+
# fi
3439
- |
3540
{
3641
# Ensure that "foo | run_and_report" fails correctly.

buildspec/shared/linux-pre_build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ if [ "$TOOLKITS_CODEARTIFACT_DOMAIN" ] && [ "$TOOLKITS_CODEARTIFACT_REPO" ] && [
2222
fi
2323

2424
# TODO: move this to the "install" phase?
25+
export NODE_OPTIONS=--max-old-space-size=8192
2526
npm 2>&1 ci | run_and_report 2 'npm WARN deprecated' 'Deprecated dependencies must be updated.'

codecov.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ github_checks:
3838
flags:
3939
codewhisperer:
4040
paths:
41-
- packages/toolkit/src/codewhisperer/
41+
- packages/core/src/codewhisperer/
4242
amazonqFeatureDev:
4343
paths:
44-
- packages/toolkit/src/amazonqFeatureDev/
44+
- packages/core/src/amazonqFeatureDev/

designs/credentials/credentials-management.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ A formatted version of the Credentials Provider Id may be surfaced to users, how
3131

3232
When the user connects to AWS in the Toolkit, a Credentials Provider is requested, which is then used to obtain credentials. The toolkit requests a Credentials Provider by checking which credentials provider factories support the provider's credentials type. The factories of interest are queried to see which (if any) have the requested Credentials Provider.
3333

34-
At the time this document was written, Shared Credentials are the only supported Credentials. Additional credentials providers will reside at [/src/credentials/providers](/packages/toolkit/src/credentials/providers) as they are implemented.
34+
At the time this document was written, Shared Credentials are the only supported Credentials. Additional credentials providers will reside at [/src/credentials/providers](/packages/core/src/credentials/providers) as they are implemented.
3535

3636
### Shared Credentials Profiles
3737

38-
Profiles are retrieved from the user's shared credentials files. The profile is handled and validated differently based on which fields are present. Handling and validation logic can be found in [sharedCredentialsProvider.ts](/packages/toolkit/src/credentials/providers/sharedCredentialsProvider.ts).
38+
Profiles are retrieved from the user's shared credentials files. The profile is handled and validated differently based on which fields are present. Handling and validation logic can be found in [sharedCredentialsProvider.ts](/packages/core/src/credentials/providers/sharedCredentialsProvider.ts).
3939

4040
Only profiles that are considered valid are provided to the toolkit. When validation issues are detected, they are written to the logs to help users understand why the toolkit is having difficulties with a profile. Users running the 'Connect to AWS' command will not see invalid profiles in the list of Credentials.
4141

designs/modify-resources-attached-to-code-pipeline.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ The confirmation prompt can be implemented using one of two UI facilities:
150150

151151
### API Client
152152

153-
The `ResourceGroupsTaggingAPI` service client will be used. The client will be set up in a manner consistent with the Lambda and CloudFormation clients, allowing the clients to be stubbed out in unit tests. See the Toolkit's Lambda Client [Interface](/packages/toolkit/src/shared/clients/lambdaClient.ts) and [Implementation](/packages/toolkit/src/shared/clients/defaultLambdaClient.ts) as an example. A new client factory will be added to [ToolkitClientBuilder](/packages/toolkit/src/shared/clients/toolkitClientBuilder.ts) and [DefaultToolkitClientBuilder](/packages/toolkit/src/shared/clients/defaultToolkitClientBuilder.ts).
153+
The `ResourceGroupsTaggingAPI` service client will be used. The client will be set up in a manner consistent with the Lambda and CloudFormation clients, allowing the clients to be stubbed out in unit tests. See the Toolkit's Lambda Client [Interface](/packages/core/src/shared/clients/lambdaClient.ts) and [Implementation](/packages/core/src/shared/clients/defaultLambdaClient.ts) as an example. A new client factory will be added to [ToolkitClientBuilder](/packages/core/src/shared/clients/toolkitClientBuilder.ts) and [DefaultToolkitClientBuilder](/packages/core/src/shared/clients/defaultToolkitClientBuilder.ts).
154154

155155
### <a id="fallback-handling"></a>Fallback Handling
156156

docs/ARCHITECTURE.md

+33-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,29 @@ An overview of the architecture for various components within the Toolkit.
44

55
## Monorepo Structure
66

7-
This project is currently set up as a typescript monorepo with a single subproject.
8-
We are currently working on splitting the Toolkit into various subprojects to help with
9-
sharing code between modules, Web mode development, etc. For now, there is just
10-
one monolithic subproject with all the extension functionality: [`packages/toolkit/`](./packages/toolkit/).
7+
**The easiest way to open the project for running/debugging:** File > Open Workspace from File > choose `aws-toolkit-vscode/aws-toolkit-vscode.code-workspace`
8+
9+
This project is currently set up as a typescript monorepo with the following subprojects:
10+
11+
- [`packages/core/`](./packages/core/)
12+
- Currently, this package contains almost all of the functionality required for the extension.
13+
It was created by moving all of the code from `packages/tookit/` to here.
14+
We are currently working on separating non-shareable code out of the core library into the relevant
15+
subproject. Running tests for most of the toolkit extension logic occurs in this subproject.
16+
- [`packages/toolkit/`](./packages/toolkit/)
17+
- Currently, this package is a barebones wrapper that calls activation functions from the core library.
18+
As we discover what code cannot be shared across other projects, it will be moved to this package.
19+
Running and packaging the extension occurs from this subproject.
20+
21+
If you are considering contributing, please consider whether your implementation should live in the core
22+
library or in `packages/toolkit`. If your work could be re-used by other packages (e.g. auth mechanisms,
23+
utilities), then it may belong in the core library. If instead you are adding something toolkit specific
24+
(eg. an integration to a new AWS service in the Explorer Tree), consider putting it in `packages/toolkit`.
25+
To import from the core library, please export your desired code using `index.ts` files, and add an appropriate `exports` statement
26+
in `packages/core/package.json`.
1127

1228
Unless otherwise stated, the documentation throughout this project is referring to the code and
13-
functionality of that subproject.
29+
functionality in `packages/core/` and `packages/toolkit`.
1430

1531
Current quirks of the current monorepo status that should be resolved/evaluated in later versions (TODO):
1632

@@ -26,20 +42,27 @@ Current quirks of the current monorepo status that should be resolved/evaluated
2642
for more info on how `node_modules/` hoisting works.
2743
- Because of `node_modules/` hoisting, references to this folder in code access the root project modules folder. This may be
2844
an issue if more subprojects are added and the contents of the root and local modules folders differ.
29-
- [`globalSetup.test.ts`](../packages/toolkit/src/test/globalSetup.test.ts) should be configured to work as a library/run tests for all subprojects.
45+
- [`globalSetup.test.ts`](../packages/core/src/test/globalSetup.test.ts) should be configured to work as a library/run tests for all subprojects.
3046
- Subproject `tsconfig.json`s should extend a root `tsconfig.packages.json`.
3147
- Linting tests should run at the root level, not subproject level.
32-
- `packages/toolkit/scripts/` should be generalized and moved to the root of the project as needed.
48+
- `packages/*/scripts/` should be generalized and moved to the root of the project as needed.
3349
- LICENSE, README.md, and other non-code artifacts that must be packaged into the .vsix are currently
3450
being copied into the packaging subproject directory from the root project directory as part of the `copyFiles` task.
3551
- Pre-release only publishes packages/toolkit extension directly. It should be extended to other added extensions. See [`release.yml`](../.github/workflows/release.yml)
3652
- VSCode does not support inheriting/extending `.vscode/` settings: https://github.com/microsoft/vscode/issues/15909
3753

54+
Additional quirks introduced by creating a core library from the original extension code:
55+
56+
- Tests are ran from `packages/core/`
57+
- Extension runs from `packages/toolkit`
58+
- Extension tests run from the core lib. Since some of the tests require an extension context/sandbox, we initiate a "fake" extension to run these tests. This is also why there are vscode extensionproperties in the package.json
59+
- Some of original extension code (that now lives in `packages/core`) depends on the package.json, specifically the contributes section. This section is very large AND needs to be present in both the core library and toolkit extension package.jsons. The core library code needs access to this section to create types, set up SAM debuggers, etc. The toolkit needs this section during packaging/debugging so that the extension can run in vscode. The short term solution was to creat a [build script](../packages/toolkit/scripts/build/handlePackageJson.ts) to copy necessary fields over to the toolkit extension during packaging and debugging.
60+
3861
## Commands
3962

4063
Many parts of the VS Code API relies on the use of 'commands' which are simply functions bound to a global ID. For small projects, this simplicity is great. But the base API doesn't offer a lot of common functionality that a large project might want: logging, error handling, etc.
4164

42-
For the Toolkit, common command functionality is implemented in [Commands](../packages/toolkit/src/shared/vscode/commands2.ts). The goal with this abstraction is to increase consistency across the Toolkit for anything related to commands.
65+
For the Toolkit, common command functionality is implemented in [Commands](../packages/core/src/shared/vscode/commands2.ts). The goal with this abstraction is to increase consistency across the Toolkit for anything related to commands.
4366

4467
### Examples
4568

@@ -123,7 +146,7 @@ _See also [CODE_GUIDELINES.md](./CODE_GUIDELINES.md#exceptions)._
123146

124147
Large applications often have a correspondingly large number of failure points. For feature-level logic, these failures are often non-recoverable. The best we can do is show the user that something went wrong and maybe offer guidance on how to fix it.
125148

126-
Because this is such a common pattern, shared error handling logic is defined by `ToolkitError` found [here](../packages/toolkit/src/shared/errors.ts). This class provides the basic structure for errors throughout the Toolkit.
149+
Because this is such a common pattern, shared error handling logic is defined by `ToolkitError` found [here](../packages/core/src/shared/errors.ts). This class provides the basic structure for errors throughout the Toolkit.
127150

128151
### Chaining
129152

@@ -133,7 +156,7 @@ By adding additional information as the exception bubbles up, we can create a be
133156

134157
### Handlers
135158

136-
Any code paths exercised via `Commands` will have errors handled by `handleError` in [extensions.ts](../packages/toolkit/src/extension.ts). A better API for error handling across more than just commands will be added in a future PR.
159+
Any code paths exercised via `Commands` will have errors handled by `handleError` in [extensions.ts](../packages/core/src/extension.ts). A better API for error handling across more than just commands will be added in a future PR.
137160

138161
### Best Practices
139162

0 commit comments

Comments
 (0)