Skip to content

Commit

Permalink
feat: engines to ^20.17.0 || >=22.9.0 (#500)
Browse files Browse the repository at this point in the history
prereq for #498
  • Loading branch information
reggi authored Jan 29, 2025
1 parent c172754 commit 402d480
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 19 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,17 @@ jobs:
os: windows-latest
shell: cmd
node-version:
- 18.17.0
- 18.x
- 20.5.0
- 20.17.0
- 20.x
- 22.9.0
- 22.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.5.0
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
runs-on: ${{ matrix.platform.os }}
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,17 @@ jobs:
os: windows-latest
shell: cmd
node-version:
- 18.17.0
- 18.x
- 20.5.0
- 20.17.0
- 20.x
- 22.9.0
- 22.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 18.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.5.0
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
runs-on: ${{ matrix.platform.os }}
Expand Down
11 changes: 10 additions & 1 deletion lib/util/import-or-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ const importOrRequire = async path => {
let content = {}
try {
content = require(path)
// this is for node 22+
// istanbul ignore next
if (content.__esModule) {
return content.default
}
} catch {
// istanbul ignore next
try {
content = await import(pathToFileURL(path)).then(r => r.default)
// this is for node under 20
const results = await import(pathToFileURL(path))
// istanbul ignore next
return results.default
} catch {
// its ok if this fails since the content dir might only be to provide
// other files. the index.js is optional
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"prettier": true
},
"engines": {
"node": "^18.17.0 || >=20.5.0"
"node": "^20.17.0 || >=22.9.0"
},
"workspaces": [
"workspace/test-workspace"
Expand Down
2 changes: 1 addition & 1 deletion test/apply/esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ t.test('basic', async t => {
})
await s.apply()

const file = await s.readFile('file.js')
const file = await s.readFile('content_dir/file.js')
t.match(file, 'var x = 1;')
})
27 changes: 27 additions & 0 deletions test/apply/import-or-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const t = require('tap')
const importOrRequire = require('../../lib/util/import-or-require.js')
const path = require('path')

t.test('importOrRequire', async t => {
const dir = t.testdir({
esm: {
'package.json': JSON.stringify({
type: 'module',
}),
'index.js': 'export default "type module";',
},
'esm.js': 'export default "esm";',
'mjs.mjs': 'export default "mjs";',
'cjs.cjs': 'module.exports = "cjs";',
'js.js': 'module.exports = "js";',
'invalid.js': 'invalid',
})

await Promise.all(
// double 'js' triggers the cache
['mjs', 'cjs', 'js', 'js'].map(async type => {
const output = await importOrRequire(path.join(dir, `${type}.${type}`))
t.same(output, type)
}),
)
})

0 comments on commit 402d480

Please sign in to comment.