Skip to content

Commit 55e3211

Browse files
refactor: webpack/build scripts (#4670)
* test: fix core tests prompting build task Problem: When we run the core tests they prompt for a build task before running. We should not have to do this. Solution: Create a specific build task and explicitly use that. I think due to our recent changes the "defaultBuildTask" cannot be appropriately resolved which is why this change was needed. Signed-off-by: Nikolas Komonen <[email protected]> * refactor: remove index files in core Problem: We had index files in the core package which we used to expose certain methods once we packaged core in to a node module for use by the toolkit and amazonq package. We don't need it. Solution: Stop using the index files and go back to using the extension*.ts files Signed-off-by: Nikolas Komonen <[email protected]> * refactor: dynamically build webpack configs Now we can dynamically build webpack configs by exporting a function instead of the config. This will allow us to check for the 'development' mode at creation and from there we can modify the webpack config that we return. So now if we have `webpack --mode development`, we can recognize we are in development mode and incrementally change our config to our liking. Signed-off-by: Nikolas Komonen <[email protected]> * refactor: webpack/build scripts This commit: - Adds some comments to certain parts of the build process - Fixes our build tasks so that `core` will build all of the required artifacts for `toolkit` will run properly. Before there were cases where running the `Extension (toolkit)` would fail due to a missing `dist/vue` folder - Fixes webviews not reflecting updated code when we refresh the webview during debugging. This was due to the `webview serve` not being utilized correctly. Now if you change `.vue` code and reload the webview the changes should be seen. Signed-off-by: Nikolas Komonen <[email protected]> * refactor: remove vue hot reload This feature doesn't seem to work, or just isn't worth the effort to get working. This removes use of it, but we can always look to add it in if we have a need for it. Signed-off-by: Nikolas Komonen <[email protected]> * fix: post debug task not found We had multiple debug tasks with the same name, so when we tried to run them it didn't know which one to use. Solution: Rename one of them so the names are unique Signed-off-by: Nikolas Komonen <[email protected]> * refactor: webpack web configs + scripts This commit: - Updates the webpack web config to be dynamic, exporting a function which is used to create the config. Previously we exported the final object. - As a result the users of the config had to update to work with this change. - Now we can tweak the config depending on input arguments - Update the tasks in the launch.json to improve the debug mode in VS Code. - Remove the `serve` configs from the main webpack. - We previously used these for hot reloading but since we do not have a use for them anymore we are getting rid of them and simplifying things. Signed-off-by: Nikolas Komonen <[email protected]> * refactor: browser test output unique file Problem: We need to both compile all source code + webpack a web extension when running the Web unit tests so that we do not have type errors + have an executable file (webpacked file) The problem is that the name extensionWeb.js is shared by both the compiled output AND webpacked output. So one gets overwritten. Solution: Change the name of the webpacked output so that it does not get overwritten. Now in unit tests we target that specifically. Signed-off-by: Nikolas Komonen <[email protected]> * refactor: clean up VS Code Debug menu Problem: The VS Code Debug launch menu is cluttered with lots of different launch configs. It is confusing and there are many rarely used configs. Solution: Clean it up and reorder the configs so they are more relevant. Signed-off-by: Nikolas Komonen <[email protected]> * refactor: web mode webpack Before we had a custom flag to not build certain Web mode bundles. But it is instead easier to always build it, but output the bundle with a different name. We did this due to overlapping output files with the same name, but with this new change it does not happen anymore. Signed-off-by: Nikolas Komonen <[email protected]> * upgrade @vscode/test-web module Signed-off-by: Nikolas Komonen <[email protected]> * PR comment fixes: - Update CONTRIBUTING regarding webview dev server - Change the script name for web development compilation Signed-off-by: Nikolas Komonen <[email protected]> --------- Signed-off-by: Nikolas Komonen <[email protected]>
1 parent 3d4c65e commit 55e3211

25 files changed

+485
-611
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,13 @@ requests just from the model/types.
517517

518518
### Webview dev-server
519519

520-
Webviews can be hot-reloaded (updated without restarting the extension) by running a developer server provided by webpack. This server is started automatically when running the `Extension` launch configuration. You can also start it by running `npm serve`. Note that only frontend components will be updated; if you change backend code you will still need to restart the development extension.
520+
Webviews can be refreshed to show changes to `.vue` code when running in Debug mode. You do not have to
521+
reload the Debug VS Code window.
522+
523+
- Use `Command Palette` -> `Reload Webviews`
524+
- Only the frontend `.vue` changes will be reflected. If changing any backend code you must restart Debug mode.
525+
526+
This works by continuously building the final Vue webview files (`webpack watch`) and then serving them through a local server (`webpack serve`). Whenever a webview is loaded it will grab the latest build from the server.
521527

522528
### Font generation
523529

aws-toolkit-vscode.code-workspace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"path": "."
55
},
66
{
7-
"path": "packages/core"
7+
"path": "packages/toolkit"
88
},
99
{
10-
"path": "packages/toolkit"
10+
"path": "packages/core"
1111
},
1212
{
1313
"path": "packages/amazonq"

package-lock.json

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

packages/amazonq/webpack.config.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77
* This is the final webpack config that collects all webpack configs.
88
*/
99

10-
const baseConfig = require('../webpack.base.config')
11-
const baseVueConfig = require('../webpack.vue.config')
12-
const baseWebConfig = require('../webpack.web.config')
10+
const baseConfigFactory = require('../webpack.base.config')
11+
const baseVueConfigFactory = require('../webpack.vue.config')
12+
const baseWebConfigFactory = require('../webpack.web.config')
1313

14-
const config = {
15-
...baseConfig,
16-
entry: {
17-
'src/extension': './src/extension.ts',
18-
},
19-
}
14+
module.exports = (env, argv) => {
15+
const config = {
16+
...baseConfigFactory(env, argv),
17+
entry: {
18+
'src/extension': './src/extension.ts',
19+
},
20+
}
2021

21-
const vueConfigs = baseVueConfig.configs.map(c => {
22-
// Inject entry point into all configs.
23-
return {
24-
...c,
22+
const vue = baseVueConfigFactory(env, argv)
23+
const vueConfig = {
24+
...vue.config,
2525
entry: {
26-
...baseVueConfig.utils.createVueEntries(),
26+
...vue.createVueEntries(),
2727
//'src/amazonq/webview/ui/amazonq-ui': './src/amazonq/webview/ui/main.ts',
2828
},
2929
}
30-
})
3130

32-
const webConfig = {
33-
...baseWebConfig,
34-
entry: {
35-
'src/extensionWeb': './src/extensionWeb.ts',
36-
},
37-
}
31+
const webConfig = {
32+
...baseWebConfigFactory(env, argv),
33+
entry: {
34+
'src/extensionWeb': './src/extensionWeb.ts',
35+
},
36+
}
3837

39-
module.exports = [config, ...vueConfigs, webConfig]
38+
return [config, vueConfig, webConfig]
39+
}

packages/core/.vscode/launch.json

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"AWS_TOOLKIT_AUTOMATION": "local"
2222
},
2323
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
24-
"preLaunchTask": "${defaultBuildTask}"
24+
"preLaunchTask": "build"
2525
},
2626
{
2727
"name": "Extension Tests (current file)",
@@ -40,7 +40,7 @@
4040
"AWS_TOOLKIT_AUTOMATION": "local"
4141
},
4242
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
43-
"preLaunchTask": "${defaultBuildTask}"
43+
"preLaunchTask": "build"
4444
},
4545
{
4646
"name": "Extension Tests (web)",
@@ -51,12 +51,11 @@
5151
"--disable-extension=amazonwebservices.aws-toolkit-vscode",
5252
"--extensionDevelopmentPath=${workspaceFolder}",
5353
"--extensionDevelopmentKind=web",
54-
"--extensionTestsPath=${workspaceFolder}/dist/src/testWeb/testRunner",
54+
"--extensionTestsPath=${workspaceFolder}/dist/src/testWeb/testRunnerWebCore",
5555
"${workspaceRoot}/dist/src/testFixtures/workspaceFolder"
5656
],
5757
"outFiles": ["${workspaceFolder}/dist/src/**/*.js"],
58-
"preLaunchTask": "webWatch",
59-
"postDebugTask": "webRunTerminate"
58+
"preLaunchTask": "testsBuildWatch"
6059
},
6160
{
6261
"name": "Integration Tests",
@@ -74,7 +73,7 @@
7473
"AWS_TOOLKIT_AUTOMATION": "local"
7574
},
7675
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
77-
"preLaunchTask": "${defaultBuildTask}"
76+
"preLaunchTask": "build"
7877
},
7978
{
8079
"name": "Integration Tests (current file)",
@@ -93,7 +92,7 @@
9392
"AWS_TOOLKIT_AUTOMATION": "local"
9493
},
9594
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
96-
"preLaunchTask": "${defaultBuildTask}"
95+
"preLaunchTask": "build"
9796
},
9897
{
9998
"name": "E2E Test (current file)",
@@ -112,37 +111,39 @@
112111
"AWS_TOOLKIT_AUTOMATION": "local"
113112
},
114113
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
115-
"preLaunchTask": "${defaultBuildTask}"
114+
"preLaunchTask": "build"
116115
},
117116
{
118117
"name": "Test Lint",
119118
"type": "node",
120119
"request": "launch",
121120
"program": "${workspaceFolder}/scripts/lint/testLint.ts",
122121
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
123-
"preLaunchTask": "${defaultBuildTask}"
124-
},
125-
{
126-
"name": "Attach to ASL Server",
127-
"type": "node",
128-
"request": "attach",
129-
"port": 6009,
130-
"restart": true,
131-
"outFiles": ["${workspaceRoot}/dist/src/stepFunctions/asl/**.js"]
132-
},
133-
{
134-
"name": "Attach to SSM Document Language Server",
135-
"type": "node",
136-
"request": "attach",
137-
"port": 6010,
138-
"restart": true,
139-
"outFiles": ["${workspaceRoot}/dist/src/ssmDocument/ssm/ssmServer.js"]
122+
"preLaunchTask": "build"
140123
}
124+
// ---- We do not need the following currently, and we want to reduce clutter. Re-enable if necessary ----
125+
// {
126+
// "name": "Attach to ASL Server",
127+
// "type": "node",
128+
// "request": "attach",
129+
// "port": 6009,
130+
// "restart": true,
131+
// "outFiles": ["${workspaceRoot}/dist/src/stepFunctions/asl/**.js"]
132+
// },
133+
// {
134+
// "name": "Attach to SSM Document Language Server",
135+
// "type": "node",
136+
// "request": "attach",
137+
// "port": 6010,
138+
// "restart": true,
139+
// "outFiles": ["${workspaceRoot}/dist/src/ssmDocument/ssm/ssmServer.js"]
140+
// }
141141
],
142142
"compounds": [
143-
{
144-
"name": "Extension + Attach to SSM Document Language Server",
145-
"configurations": ["Extension", "Attach to SSM Document Language Server"]
146-
}
143+
// ---- We do not need the following currently, and we want to reduce clutter. Re-enable if necessary ----
144+
// {
145+
// "name": "Extension + Attach to SSM Document Language Server",
146+
// "configurations": ["Extension", "Attach to SSM Document Language Server"]
147+
// }
147148
]
148149
}

packages/core/.vscode/tasks.json

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,31 @@
33
{
44
"version": "2.0.0",
55
"tasks": [
6+
{
7+
// Single build task to enable parallel tasks
8+
"label": "build",
9+
"dependsOn": ["watch", "webpackWatch"]
10+
},
611
{
712
"label": "watch",
813
"type": "npm",
914
"script": "watch",
1015
"problemMatcher": "$tsc-watch",
11-
"isBackground": true,
12-
"group": {
13-
"kind": "build",
14-
"isDefault": true
15-
},
16-
"dependsOn": ["serve"]
16+
"isBackground": true
1717
},
1818
{
19-
"label": "serve",
20-
"type": "npm",
21-
"script": "serve",
22-
"group": "build",
19+
"label": "webpackWatch",
20+
"command": "npm run webpackDev -- --watch",
21+
"type": "shell",
2322
"isBackground": true,
24-
"problemMatcher": {
25-
"owner": "custom",
26-
"pattern": {
27-
"regexp": ".",
28-
"file": 1,
29-
"location": 2,
30-
"message": 3
31-
},
32-
"background": {
33-
"activeOnStart": true,
34-
"beginsPattern": "Project is running at",
35-
"endsPattern": "compiled successfully"
36-
}
37-
}
23+
"problemMatcher": "$ts-webpack-watch"
3824
},
3925
{
40-
"label": "webWatch",
41-
"type": "npm",
42-
"script": "webWatch",
43-
"detail": "Webpacks our toolkit code (with --watch) in preparation to be run in the browser",
26+
"label": "testsBuildWatch",
27+
"command": "npm run compileDev -- --watch",
28+
"detail": "Build that is sufficient for Web mode tests",
29+
"type": "shell",
4430
"isBackground": true,
45-
// Since `webpack --watch` never terminates (but finishes packaging at some point),
46-
// VS Code uses this to parse the CLI output to pattern match something that indicates it is done
4731
"problemMatcher": "$ts-webpack-watch"
4832
},
4933
/**
@@ -53,8 +37,8 @@
5337
From: https://stackoverflow.com/a/60330174
5438
**/
5539
{
56-
"label": "webRunTerminate",
57-
"command": "echo ${input:webRunTerminate}",
40+
"label": "webRunTerminateCore",
41+
"command": "echo ${input:webRunTerminateCore}",
5842
"type": "shell"
5943
},
6044
{
@@ -94,7 +78,7 @@
9478
"args": "terminateAll"
9579
},
9680
{
97-
"id": "webRunTerminate",
81+
"id": "webRunTerminateCore",
9882
"type": "command",
9983
"command": "workbench.action.tasks.terminate",
10084
"args": "webRun"

0 commit comments

Comments
 (0)