Skip to content

Commit

Permalink
feat(node): support node 20 in tasks
Browse files Browse the repository at this point in the history
Requires a hacky patch to fix shell.js, which doesn't support bundlers.
Mitigates the issue described in aws#539

Credit to ivanduplenskikh:  ivanduplenskikh#1

Co-authored-by: Ivan Duplenskikh <ivanduplenskikh>
  • Loading branch information
hayemaxi committed Nov 25, 2024
1 parent f4b9ae1 commit 634462a
Show file tree
Hide file tree
Showing 26 changed files with 252 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Tasks now support Node 20"
}
11 changes: 2 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
{
"files.exclude": {
"build": true,
"package": true,
"package-lock.json": true,
".vscode": true
},
"files.exclude": {},
"search.exclude": {
"build": true,
"package": true,
".vscode": true
"package": true
},
"json.schemas": [
{
Expand Down
23 changes: 22 additions & 1 deletion build-scripts/packageExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ function packagePlugin(options: CommandLineOptions) {
// get required npm packages that will be copied
installNodePackages(npmFolder)

/**
* Patch shelljs, because it is not compatible with esbuild
* More info: https://github.com/aws/aws-toolkit-azure-devops/pull/539
*/
const shelljsRootPath = path.resolve(process.cwd(), './node_modules/shelljs/')
const shelljsEntryPath = path.join(shelljsRootPath, 'shell.js')
const sourceRequireString =
"require('./commands').forEach(function (command) {\n require('./src/' + command);\n});"
const originContent = fs.readFileSync(shelljsEntryPath, 'utf-8')

// eslint-disable-next-line @typescript-eslint/no-var-requires
const fixedRequireString = require(path.join(shelljsRootPath, 'commands.js'))
.map((command: string) => `require('./src/${command}.js');`)
.join('\n')

fs.writeFileSync(shelljsEntryPath, originContent.replace(sourceRequireString, fixedRequireString))
/** *************************************************************** */

// clean, dedupe and pack each task as needed
findMatchingFiles(folders.sourceTasks).forEach(function(taskName) {
console.log('Processing task ' + taskName)
Expand Down Expand Up @@ -116,7 +134,7 @@ function packagePlugin(options: CommandLineOptions) {
entryPoints: [inputFilename],
bundle: true,
platform: 'node',
target: ['node10'],
target: ['node10', 'node20'],
minify: true,
outfile: `${taskPackageFolder}/${taskName}.js`
})
Expand All @@ -127,6 +145,9 @@ function packagePlugin(options: CommandLineOptions) {
}
})

// undo shelljs patch
fs.writeFileSync(shelljsFilePath, originContent.replace(fixedRequireString, sourceRequireString))

console.log('Creating deployment vsix')

const binName = os.platform() === 'win32' ? `tfx.cmd` : 'tfx'
Expand Down
Loading

0 comments on commit 634462a

Please sign in to comment.