From fa114e400a607a4d8686cf24f33ba7ea7999886e Mon Sep 17 00:00:00 2001 From: Ian Hou <45278651+iankhou@users.noreply.github.com> Date: Tue, 3 Feb 2026 15:41:36 -0500 Subject: [PATCH 1/2] feat: provide option for WindowsPlatform to omit chocolatey node installation --- lib/shellable.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/shellable.ts b/lib/shellable.ts index 8cd5235d8..a2a15cabd 100644 --- a/lib/shellable.ts +++ b/lib/shellable.ts @@ -546,7 +546,18 @@ export class LinuxPlatform extends ShellPlatform { export class WindowsPlatform extends ShellPlatform { public readonly platformType = PlatformType.Windows; + constructor( + buildImage: cbuild.IBuildImage, + private readonly upgradeNodeWithChocolatey: boolean = true, + ) { + super(buildImage); + } + public installCommands(): string[] | undefined { + if (!this.upgradeNodeWithChocolatey) { + return undefined; + } + return [ // Update the image's nodejs to the latest LTS release. 'Import-Module "C:\\ProgramData\\chocolatey\\helpers\\chocolateyProfile.psm1"', From 3adc33d3d71bf1efad6149f3a8782d72d6fb9c1f Mon Sep 17 00:00:00 2001 From: Ian Hou <45278651+iankhou@users.noreply.github.com> Date: Wed, 4 Feb 2026 11:50:22 -0500 Subject: [PATCH 2/2] feat(WindowsPlatform): add option to disable Chocolatey Node.js upgrade Add WindowsPlatformOptions interface with upgradeNodeWithChocolatey option (defaults to true for backward compatibility). This allows users to skip the Chocolatey Node.js upgrade during the install phase. --- lib/__tests__/shellable.test.ts | 21 ++++++++++++++++++++- lib/shellable.ts | 19 +++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/__tests__/shellable.test.ts b/lib/__tests__/shellable.test.ts index 46d0771d2..1402e6017 100644 --- a/lib/__tests__/shellable.test.ts +++ b/lib/__tests__/shellable.test.ts @@ -1,7 +1,8 @@ import * as path from 'path'; import * as cdk from 'aws-cdk-lib'; import { Template, Match } from 'aws-cdk-lib/assertions'; -import { Shellable, ShellPlatform } from '../../lib'; +import * as codebuild from 'aws-cdk-lib/aws-codebuild'; +import { Shellable, ShellPlatform, WindowsPlatform } from '../../lib'; // tslint:disable:max-line-length @@ -588,3 +589,21 @@ test('can exclude files from scriptDirectory', () => { }, }); }); + + +test('WindowsPlatform installs node via chocolatey by default', () => { + const platform = new WindowsPlatform(codebuild.WindowsBuildImage.WIN_SERVER_CORE_2019_BASE); + + expect(platform.installCommands()).toEqual([ + 'Import-Module "C:\\ProgramData\\chocolatey\\helpers\\chocolateyProfile.psm1"', + 'C:\\ProgramData\\chocolatey\\bin\\choco.exe upgrade nodejs-lts -y', + ]); +}); + +test('WindowsPlatform can disable chocolatey node upgrade', () => { + const platform = new WindowsPlatform(codebuild.WindowsBuildImage.WIN_SERVER_CORE_2019_BASE, { + upgradeNodeWithChocolatey: false, + }); + + expect(platform.installCommands()).toBeUndefined(); +}); diff --git a/lib/shellable.ts b/lib/shellable.ts index a2a15cabd..24eba1959 100644 --- a/lib/shellable.ts +++ b/lib/shellable.ts @@ -540,17 +540,28 @@ export class LinuxPlatform extends ShellPlatform { } } +/** + * Options for WindowsPlatform + */ +export interface WindowsPlatformOptions { + /** + * Whether to upgrade Node.js using Chocolatey during the install phase. + * + * @default true + */ + readonly upgradeNodeWithChocolatey?: boolean; +} + /** * A Windows Platform */ export class WindowsPlatform extends ShellPlatform { public readonly platformType = PlatformType.Windows; + private readonly upgradeNodeWithChocolatey: boolean; - constructor( - buildImage: cbuild.IBuildImage, - private readonly upgradeNodeWithChocolatey: boolean = true, - ) { + constructor(buildImage: cbuild.IBuildImage, options: WindowsPlatformOptions = {}) { super(buildImage); + this.upgradeNodeWithChocolatey = options.upgradeNodeWithChocolatey ?? true; } public installCommands(): string[] | undefined {