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

Node.js 22 ESM require fix #78

Merged
merged 3 commits into from
Jan 17, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [ 16.x, 18.x, 20.x ]
node-version: [ 16.x, 18.x, 20.x, 22.x ]
os: [ windows-latest, ubuntu-latest, macOS-latest ]

# Go
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

---

## [4.0.6] 2025-01-17

### Changed

- Add support for new ESM-only import error message when importing plugins in Node.js 22; thanks @lpsinger!

---

## [4.0.5] 2024-04-29

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@architect/utils": "~4.0.6",
"@aws-lite/client": "^0.21.1",
"@aws-lite/ssm": "^0.2.3",
"lambda-runtimes": "~2.0.2"
"lambda-runtimes": "~2.0.5"
},
"devDependencies": {
"@architect/eslint-config": "~3.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/config/pragmas/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
if (arc?.plugins?.length) tagPlugins(arc.plugins, 'plugin')
if (arc?.macros?.length) tagPlugins(arc.macros, 'macro')

let { node } = process.versions
let nodeVer = Number(node.split('.')[0])

for (let pluginItem of pluginItems) {
let { plugin, type } = pluginItem
let name
Expand Down Expand Up @@ -52,6 +55,9 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
if (type === 'plugin') {
try {
plugins[name] = require(pluginPath)
if (nodeVer >= 22 && plugins[name].default) {
plugins[name] = plugins[name].default
}
}
catch (err) {
if (hasEsmError(err)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('Friendly runtime names (aka aliases)', t => {
t.equal(config.runtimeAlias, 'java', `Alias returned lowcase as runtimeAlias: ${config.runtimeAlias}`)

config = getRuntimes({ config: c('.net'), inventory })
t.match(config.runtime, /dotnet7/, `Alias mapped to valid AWS .NET string: ${config.runtime}`)
t.match(config.runtime, /dotnet8/, `Alias mapped to valid AWS .NET string: ${config.runtime}`)
t.equal(config.runtimeAlias, '.net', `Alias returned lowcase as runtimeAlias: ${config.runtimeAlias}`)

config = getRuntimes({ config: c('custom'), inventory })
Expand Down Expand Up @@ -64,7 +64,7 @@ test('Exact runtime names', t => {
t.equal(config.runtime, name, `Returned correct runtime string: ${name}`)
t.notOk(config.runtimeAlias, 'Did not get runtimeAlias')

name = 'dotnet6'
name = 'dotnet8'
config = getRuntimes({ config: c(name), inventory })
t.equal(config.runtime, name, `Returned correct runtime string: ${name}`)
t.notOk(config.runtimeAlias, 'Did not get runtimeAlias')
Expand Down
Loading