Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Update node to 22 #14079

Draft
wants to merge 13 commits into
base: dev
Choose a base branch
from
Draft

feat!: Update node to 22 #14079

wants to merge 13 commits into from

Conversation

sobolk
Copy link
Member

@sobolk sobolk commented Jan 24, 2025

Description of changes

This PR:

  1. Substitutes pkg/pkg-fetch with yao-pkg/pkg. The yao-pkg/pkg is actively developed fork of archived pkg project.
  2. Uses node22 binaries when producing CLI binary
  3. Fixes in the code that were required for tests to pass.
  4. Migrates lambda templates to use Node 22 runtime.

Companion PR: #14078

Issue #, if available

Description of how you validated changes

Obtained passing e2e run.

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
shell: isWin ? true : undefined,
Copy link
Member Author

@sobolk sobolk Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using shell: true is required in latest versions of node (all LTS lines) to run .cmd files on Windows.

@@ -152,7 +153,7 @@ const createCustomResource = (
): void => {
const triggerCode = fs.readFileSync(authTriggerAssetFilePath, 'utf-8');
const authTriggerFn = new lambda.Function(stack, 'authTriggerFn', {
runtime: lambda.Runtime.NODEJS_18_X,
runtime: new lambda.Runtime('nodejs22.x', RuntimeFamily.NODEJS, { supportsInlineCode: true }),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// as they bundle AWS SDK v2. This mechanism isn't viable to upgrade to nodejs18.x
// as that version bundles AWS SDK v3 which is not compatible.
const lambdaRuntimeVersion = 'nodejs16.x';
const previousLambdaRuntimeVersions = ['nodejs18.x'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pre-18 runtimes are long gone. So we can move the baseline in this file at this point.

Comment on lines +13 to +24
const fileContents = fs.readFileSync(awsExportsPath, 'utf-8');
// transpile the file contents to CommonJS
const { code } = transformSync(fileContents, {
plugins: [babelTransformEsmToCjs],
configFile: false,
babelrc: false,
});
const mod = new Module('aws-exports.js');
// @ts-expect-error This is private api.
mod._compile(code, 'aws-exports.js');
mod.paths = [projectRoot];
return mod.exports;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The esm 3rd party package that was used here before causes V8 to crash with segfault.
I have replaced this with solution borrowed from here

const fileContents = fs.readFileSync(targetFilePath, 'utf-8');
try {
// transpile the file contents to CommonJS
const { code } = babel.transformSync(fileContents, {
plugins: [babelTransformEsmToCjs],
configFile: false,
babelrc: false,
});
const mod = new Module();
mod._compile(code, 'aws-exports.js');
// add paths to the module to account for node_module imports in aws-exports.js (should there be any)
mod.paths = [projectPath];
// the transpiled result will contain `exports.default`
awsExports = mod.exports?.default || mod.exports;

@sobolk sobolk mentioned this pull request Jan 24, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant