Skip to content

Commit 3f45c37

Browse files
fix(build): webviews sometimes did not load during development (#6556)
## Problem: In our development build we spawn a webpack server that serves the Vue files used by our webviews. It is served on port 8080, but sometimes an existing process is already using it, and this causes the webpack server to use the next available port. But because we assume it will use 8080 it silently breaks, and when developing the Q webview would not load as expected. ## Solution: Explicitly require 8080 in the webpack server cli command, also create a custom script to catch the error early and explain how to resolve it. Now in the build tasks if 8080 is in use the dev can see the failed task with the solution explicitly stated. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: nkomonen-amazon <[email protected]>
1 parent fa431af commit 3f45c37

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

packages/amazonq/.vscode/tasks.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"problemMatcher": "$ts-webpack-watch",
4545
"options": {
4646
"cwd": "${workspaceFolder}/../../packages/core"
47-
}
47+
},
48+
"presentation": { "panel": "dedicated" }
4849
},
4950
{
5051
"label": "terminate",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@
424424
"compileOnly": "tsc -p ./",
425425
"compileDev": "npm run compile -- --mode development",
426426
"webpackDev": "webpack --mode development",
427-
"serveVue": "webpack serve --config-name vue --mode development",
427+
"serveVue": "ts-node ./scripts/build/checkServerPort.ts && webpack serve --port 8080 --config-name vue --mode development",
428428
"watch": "npm run clean && npm run buildScripts && npm run compileOnly -- --watch",
429429
"lint": "ts-node ./scripts/lint/testLint.ts",
430430
"generateClients": "ts-node ./scripts/build/generateServiceClient.ts ",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* Validate that the required port used by webviews during development is not being used.
8+
*/
9+
10+
import * as net from 'net'
11+
12+
/** This must be kept up to date with the port that is being used to serve the vue files. */
13+
const portNumber = 8080
14+
15+
function checkPort(port: number): Promise<boolean> {
16+
return new Promise((resolve) => {
17+
const server = net.createServer()
18+
19+
server.once('error', (err) => {
20+
if ((err as NodeJS.ErrnoException).code === 'EADDRINUSE') {
21+
resolve(true)
22+
}
23+
})
24+
25+
server.once('listening', () => {
26+
server.close()
27+
resolve(false)
28+
})
29+
30+
server.listen(port)
31+
})
32+
}
33+
34+
async function main() {
35+
try {
36+
const isPortInUse = await checkPort(portNumber)
37+
38+
if (isPortInUse) {
39+
console.error(`
40+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
41+
42+
ERROR: Webviews will not load as expected, meaning Q may not work.
43+
REASON: Port ${portNumber} is already in use, preventing the latest webview files from being served.
44+
SOLUTION: Kill the current process using port ${portNumber}.
45+
- Unix: "kill -9 $(lsof -t -i :${portNumber})"
46+
47+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
48+
`)
49+
process.exit(1)
50+
}
51+
} catch (error) {
52+
console.error('Error checking port:', error)
53+
process.exit(1)
54+
}
55+
}
56+
57+
void main()

0 commit comments

Comments
 (0)