|
16 | 16 | import * as fs from 'fs-extra'
|
17 | 17 |
|
18 | 18 | function main() {
|
| 19 | + fixNullExtensionIssue() |
| 20 | + |
19 | 21 | const packageJsonFile = './package.json'
|
20 | 22 | const backupJsonFile = `${packageJsonFile}.handlePackageJson.bk`
|
21 | 23 | const coreLibPackageJsonFile = '../core/package.json'
|
@@ -56,4 +58,40 @@ function main() {
|
56 | 58 | }
|
57 | 59 | }
|
58 | 60 |
|
| 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 | + |
59 | 97 | main()
|
0 commit comments