Skip to content

Commit 4ed52b0

Browse files
fix: null extension during Debug mode (#4953)
Fixes: #4658 Signed-off-by: Nikolas Komonen <[email protected]>
1 parent 20c948b commit 4ed52b0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/toolkit/scripts/build/handlePackageJson.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import * as fs from 'fs-extra'
1717

1818
function main() {
19+
fixNullExtensionIssue()
20+
1921
const packageJsonFile = './package.json'
2022
const backupJsonFile = `${packageJsonFile}.handlePackageJson.bk`
2123
const coreLibPackageJsonFile = '../core/package.json'
@@ -56,4 +58,40 @@ function main() {
5658
}
5759
}
5860

61+
/**
62+
* HACK:
63+
*
64+
* During **Debug mode** the extension is not detected, this breaks things like the VS Code URI handler.
65+
* A TEMPORARY fix has been narrowed down to setting `engines.vscode` to `*` temporarily in the core package.json.
66+
* When this field is copied to the toolkit/amazonq package.json by this script, the error stops.
67+
*
68+
* Github Issue: https://github.com/aws/aws-toolkit-vscode/issues/4658
69+
*/
70+
function fixNullExtensionIssue() {
71+
const corePackageJsonFile = '../core/package.json'
72+
const backupJsonFile = `${corePackageJsonFile}.core.bk`
73+
let restoreMode = false
74+
75+
const args = process.argv.slice(2)
76+
if (args.includes('--restore')) {
77+
restoreMode = true
78+
}
79+
80+
if (restoreMode) {
81+
try {
82+
fs.copyFileSync(backupJsonFile, corePackageJsonFile)
83+
fs.unlinkSync(backupJsonFile)
84+
} catch (err) {
85+
console.log(`Could not restore package.json. Error: ${err}`)
86+
}
87+
} else {
88+
fs.copyFileSync(corePackageJsonFile, backupJsonFile)
89+
const corePackageJson = JSON.parse(fs.readFileSync(corePackageJsonFile, { encoding: 'utf-8' }))
90+
91+
corePackageJson.engines.vscode = '*'
92+
93+
fs.writeFileSync(corePackageJsonFile, JSON.stringify(corePackageJson, undefined, ' '))
94+
}
95+
}
96+
5997
main()

0 commit comments

Comments
 (0)