Skip to content

Commit 9eea1f3

Browse files
authored
build: remove package.json syncing (aws#5629)
Removes the need to copy/sync package JSON contents from core -> subproject extensions on build and package. Summary of changes: - Delete syncPackageJson.ts and handlePackageJson.ts - Consolidate testing scripts and make small improvements (e.g. validation, handle multiple directories to import tests from) - package.json is now fully complete in `amazonq/`, `toolkit/`. Changes to extensions should be made only the respective file (except for icons). - `toolkit/` runs unit, e2e, and integ tests from `core/`. It will also run any of its own tests (but those don't exist yet). - Web tests now moved to and run from `amazonq/`. This was decided because `amazonq/` is more likely to support web than `toolkit/` at this time. Also, it didn't seem possible to run the web tests from `core/` like the other tests because it relies on webpack and a separate test runner. - No longer create web-based webpacks for `core/` Follow up work: - Get [packageJSON properties](https://github.com/aws/aws-toolkit-vscode/blob/46b409c3353ce0dafefb796f5994c1fa88a23b47/packages/core/src/shared/vscode/env.ts#L61-L74) from `context.extension.packageJSON` instead. - Cleanup any remaining unneeded tasks in `.vscode/tasks.json` - Move icons out of `core/package.json`. - Continue to investigate: can we run web tests from core like other tests? Toolkit may have a use in web mode one day. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 7f3f45c commit 9eea1f3

Some content is hidden

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

50 files changed

+3432
-4285
lines changed

buildspec/lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ phases:
2626
build:
2727
commands:
2828
- export HOME=/home/codebuild-user
29-
- npm run testCompile
29+
- npm run compile -w packages/core
30+
- npm run testCompile -w packages/ --if-present
3031
- npm run lint
3132
- VCS_COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
3233
- CI_BUILD_URL=$(echo $CODEBUILD_BUILD_URL | sed 's/#/%23/g') # Encode `#` in the URL because otherwise the url is clipped in the Codecov.io site

buildspec/windowsTests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ phases:
3030

3131
build:
3232
commands:
33-
- npm run testCompile
33+
- npm run compile -w packages/core
34+
- npm run testCompile -w packages/ --if-present
3435
- npm run lint
3536
- $env:TEST_REPORT_DIR="$env:CODEBUILD_SRC_DIR/.test_reports"; npm run test
3637
- |

docs/TESTPLAN.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ The test suite has the following categories of tests:
4545

4646
## Test files
4747

48-
Currently, most if not all testing code lives in the subproject `packages/core/`.
49-
For more information, see [arch_develop.md](./arch_develop.md#monorepo-structure)
48+
Currently, most testing code lives in the subproject `packages/core/` due to the move to monorepo. See [arch_develop.md](./arch_develop.md#monorepo-structure).
5049

5150
- `src/test/` : unit tests
5251
- `src/test/globalSetup.test.ts` :
@@ -60,6 +59,8 @@ For more information, see [arch_develop.md](./arch_develop.md#monorepo-structure
6059
- `.vscode/launch.json` : defines VSCode launch configs useful for Toolkit
6160
developers, e.g. the `Extension Tests` config runs all tests in `src/test/`.
6261

62+
Many tests required running in an activated extension environment, but the core-lib is just a library and does not have any extension to activate itself. Core-lib tests are run from `packages/toolkit`, and web tests are run from `packages/amazonq`.
63+
6364
## How we test
6465

6566
VSCode documentation describes an [extension testing](https://code.visualstudio.com/api/working-with-extensions/testing-extension)

docs/arch_develop.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you are considering contributing, please consider whether your implementation
2323
library or in `packages/toolkit`. If your work could be re-used by other packages (e.g. auth mechanisms,
2424
utilities), then it may belong in the core library. If instead you are adding something toolkit specific
2525
(eg. an integration to a new AWS service in the Explorer Tree), consider putting it in `packages/toolkit`.
26-
To import from the core library, please export your desired code using `index.ts` files, and add an appropriate `exports` statement
26+
To import from the core library, please export your desired code using `index.ts` files and add an appropriate `exports` statement
2727
in `packages/core/package.json`.
2828

2929
Unless otherwise stated, the documentation throughout this project is referring to the code and
@@ -51,25 +51,9 @@ Current quirks of the current monorepo status that should be resolved/evaluated
5151
- Pre-release only publishes packages/toolkit extension directly. It should be extended to other added extensions. See [`release.yml`](../.github/workflows/release.yml)
5252
- VSCode does not support inheriting/extending `.vscode/` settings: https://github.com/microsoft/vscode/issues/15909
5353

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 extension properties 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-
6154
### Contributes and Settings
6255

63-
Some components of the core library depend on the `package.json`s of the extensions. One example of this is compile time checking of the extension's settings values. However, VSCode also requires a complete local `package.json` for the individual extensions during packaging. As a temporary workaround to this, we are using scripts to auto-populate the `package.json`s for the individual extensions from the core `package.json`.
64-
65-
- [`packages/toolkit/../handlePackageJson.ts`](../packages/toolkit/scripts/build/handlePackageJson.ts)
66-
- Copies the entirety of the `contributes` and `engine` sections, except for `configuration.properties` relating to `packages/amazon`.
67-
- Restores to the original barebones `package.json` after packaging/debugging, to avoid a large amount of duplicate code.
68-
- To develop for the Toolkit extension: add all changes to `packages/core/package.json`
69-
- [`packages/amazonq/../syncPackageJson.ts`](../packages/amazonq/scripts/build/syncPackageJson.ts)
70-
- Moves all Amazon Q related `configuration.properties` to the local `package.json` only, overwriting anything that exists with the same name locally.
71-
- Does not restore, it is a superset of what exists in `packages/core` for `configuration.properties`.
72-
- To develop for the Amazon Q extension: add all changes to `packages/amazonq/package.json`, EXCEPT for settings that are references by code in the core library, or settings that already exist in the core `package.json`
56+
`packages/toolkit/` and `packages/amazonq` have independent extension packageJSON files. They do not rely on `packages/core/package.json`. However, to get typed icons in the core-lib we require a place to store the icon entries. This currently happens in `packages/core/package.json`. See [`icons.md`](./icons.md) for more information.
7357

7458
If you are modifying or registering new debuggers in VS Code via the `debuggers` contribution point, you may need to regenerate the [definitions file](../packages/core/src/shared/sam/debugger/awsSamDebugConfiguration.gen.ts). After updating ['toolkit/package.json'](../packages/toolkit/package.json), run `npm run generateConfigurationAttributes -w packages/toolkit`
7559

package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/amazonq/.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@
9999
"order": 2
100100
}
101101
},
102+
{
103+
"name": "Extension Tests (web)",
104+
"type": "extensionHost",
105+
"debugWebWorkerHost": true,
106+
"request": "launch",
107+
"args": [
108+
"--disable-extension=amazonwebservices.aws-toolkit-vscode",
109+
"--extensionDevelopmentPath=${workspaceFolder}",
110+
"--extensionDevelopmentKind=web",
111+
"--extensionTestsPath=${workspaceFolder}/dist/test/web/testRunnerWebCore",
112+
"${workspaceFolder}/../core/dist/src/testFixtures/workspaceFolder"
113+
],
114+
"outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/../core/dist/**/*.js"],
115+
"preLaunchTask": "webRun",
116+
"presentation": {
117+
"group": "3_ExtensionTests",
118+
"order": 3
119+
}
120+
},
102121
{
103122
"name": "E2E Test (current file)",
104123
"type": "extensionHost",

packages/amazonq/.vscode/tasks.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
// Since `webpack --watch` never terminates (but finishes packaging at some point),
110110
// VS Code uses this to parse the CLI output to pattern match something that indicates it is done
111111
"problemMatcher": "$ts-webpack-watch",
112-
"dependsOn": ["copyPackageJson"],
113112
"options": {
114113
"cwd": "${workspaceFolder}/../../packages/core"
115114
}
@@ -124,7 +123,7 @@
124123
"label": "webRunTerminate",
125124
"command": "echo ${input:webRunTerminate}",
126125
"type": "shell",
127-
"dependsOn": ["restorePackageJson"]
126+
"dependsOn": []
128127
},
129128
// ---------- End: Web Mode Tasks ----------
130129
{

packages/amazonq/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,20 @@
4646
"browser": "./dist/src/extensionWeb",
4747
"scripts": {
4848
"vscode:prepublish": "npm run clean && npm run buildScripts && webpack --mode production",
49-
"buildScripts": "npm run generateNonCodeFiles && npm run copyFiles && npm run generateIcons && npm run generateSettings && npm run syncPackageJson && tsc -p ./ --noEmit",
49+
"buildScripts": "npm run generateNonCodeFiles && npm run copyFiles && npm run generateIcons && npm run generateSettings && tsc -p ./ --noEmit",
5050
"generateNonCodeFiles": "ts-node ../../scripts/generateNonCodeFiles.ts",
5151
"copyFiles": "ts-node ./scripts/build/copyFiles.ts",
52-
"syncPackageJson": "ts-node ./scripts/build/syncPackageJson.ts",
5352
"clean": "ts-node ../../scripts/clean.ts dist/ LICENSE NOTICE",
54-
"compile": "npm run clean && npm run buildScripts && webpack --mode development",
53+
"compile": "npm run clean && npm run buildScripts && webpack",
54+
"compileDev": "npm run testCompile && webpack --mode development",
5555
"compileOnly": "tsc -p ./",
5656
"package": "ts-node ../../scripts/package.ts",
5757
"lint": "true",
5858
"watch": "npm run clean && npm run buildScripts && tsc -watch -p ./",
5959
"testCompile": "npm run clean && npm run buildScripts && npm run compileOnly",
60-
"test": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/test.ts dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
61-
"testE2E": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/testE2E.ts dist/test/e2e/index.js ../core/dist/src/testFixtures/workspaceFolder",
60+
"test": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts unit dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
61+
"testE2E": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts e2e dist/test/e2e/index.js ../core/dist/src/testFixtures/workspaceFolder",
62+
"testWeb": "npm run compileDev && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts web dist/test/web/testRunnerWebCore.js",
6263
"webRun": "npx @vscode/test-web --open-devtools --browserOption=--disable-web-security --waitForDebugger=9222 --extensionDevelopmentPath=. .",
6364
"webWatch": "npm run clean && npm run buildScripts && webpack --mode development --watch",
6465
"serve": "webpack serve --config-name mainServe --mode development",

packages/amazonq/scripts/build/syncPackageJson.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/amazonq/test/e2e/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { runTests } from 'aws-core-vscode/test'
77
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'
88

99
export function run(): Promise<void> {
10-
return runTests(
11-
process.env.TEST_DIR ?? 'test/e2e',
12-
['../../core/dist/src/testInteg/globalSetup.test.ts'],
13-
VSCODE_EXTENSION_ID.amazonq
14-
)
10+
return runTests(process.env.TEST_DIR ?? 'test/e2e', VSCODE_EXTENSION_ID.amazonq, [
11+
'../../core/dist/src/testInteg/globalSetup.test.ts',
12+
])
1513
}

0 commit comments

Comments
 (0)