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
21 changes: 20 additions & 1 deletion lib/__tests__/shellable.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
});
22 changes: 22 additions & 0 deletions lib/shellable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,35 @@ 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, options: WindowsPlatformOptions = {}) {
super(buildImage);
this.upgradeNodeWithChocolatey = options.upgradeNodeWithChocolatey ?? true;
}
Comment thread
iankhou marked this conversation as resolved.

public installCommands(): string[] | undefined {
if (!this.upgradeNodeWithChocolatey) {
return undefined;
}
Comment thread
iankhou marked this conversation as resolved.

return [
// Update the image's nodejs to the latest LTS release.
'Import-Module "C:\\ProgramData\\chocolatey\\helpers\\chocolateyProfile.psm1"',
Expand Down
Loading