Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion packages/amazonq/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"problemMatcher": "$ts-webpack-watch",
"options": {
"cwd": "${workspaceFolder}/../../packages/core"
}
},
"presentation": { "panel": "dedicated" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This solved the following issue:

  • The webpack serve command would fail
  • A subsequent build task would reuse this terminal since it failed
  • The reuse caused the port in use error message to be hidden

Now the webpack serve command is in a dedicated terminal that does not disappear, so it is more obvious when it breaks.

},
{
"label": "terminate",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
"compileOnly": "tsc -p ./",
"compileDev": "npm run compile -- --mode development",
"webpackDev": "webpack --mode development",
"serveVue": "webpack serve --config-name vue --mode development",
"serveVue": "ts-node ./scripts/build/checkServerPort.ts && webpack serve --port 8080 --config-name vue --mode development",
Copy link
Contributor

Choose a reason for hiding this comment

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

is the explicitness just to make it easy to identify that the webpack port and the port in checkServerPort are easy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the explicit --port 8080 is a fallback in case something breaks in the script, but isn't explicitly needed. Also by default webpack serve will use 8080, so I thought it would just help make that more obvious.

"watch": "npm run clean && npm run buildScripts && npm run compileOnly -- --watch",
"lint": "ts-node ./scripts/lint/testLint.ts",
"generateClients": "ts-node ./scripts/build/generateServiceClient.ts ",
Expand Down
57 changes: 57 additions & 0 deletions packages/core/scripts/build/checkServerPort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Validate that the required port used by webviews during development is not being used.
*/

import * as net from 'net'

/** This must be kept up to date with the port that is being used to serve the vue files. */
const portNumber = 8080

function checkPort(port: number): Promise<boolean> {
return new Promise((resolve) => {
const server = net.createServer()

server.once('error', (err) => {
if ((err as NodeJS.ErrnoException).code === 'EADDRINUSE') {
resolve(true)
}
})

server.once('listening', () => {
server.close()
resolve(false)
})

server.listen(port)
})
}

async function main() {
try {
const isPortInUse = await checkPort(portNumber)

if (isPortInUse) {
console.error(`
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

ERROR: Webviews will not load as expected, meaning Q may not work.
REASON: Port ${portNumber} is already in use, preventing the latest webview files from being served.
SOLUTION: Kill the current process using port ${portNumber}.
- Unix: "kill -9 $(lsof -t -i :${portNumber})"

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
`)
process.exit(1)
}
} catch (error) {
console.error('Error checking port:', error)
process.exit(1)
}
}

void main()
Loading