Skip to content

Commit 402d480

Browse files
authored
feat: engines to ^20.17.0 || >=22.9.0 (#500)
prereq for #498
1 parent c172754 commit 402d480

File tree

6 files changed

+49
-19
lines changed

6 files changed

+49
-19
lines changed

Diff for: .github/workflows/ci-release.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,17 @@ jobs:
8787
os: windows-latest
8888
shell: cmd
8989
node-version:
90-
- 18.17.0
91-
- 18.x
92-
- 20.5.0
90+
- 20.17.0
9391
- 20.x
92+
- 22.9.0
9493
- 22.x
9594
exclude:
9695
- platform: { name: macOS, os: macos-13, shell: bash }
97-
node-version: 18.17.0
98-
- platform: { name: macOS, os: macos-13, shell: bash }
99-
node-version: 18.x
100-
- platform: { name: macOS, os: macos-13, shell: bash }
101-
node-version: 20.5.0
96+
node-version: 20.17.0
10297
- platform: { name: macOS, os: macos-13, shell: bash }
10398
node-version: 20.x
99+
- platform: { name: macOS, os: macos-13, shell: bash }
100+
node-version: 22.9.0
104101
- platform: { name: macOS, os: macos-13, shell: bash }
105102
node-version: 22.x
106103
runs-on: ${{ matrix.platform.os }}

Diff for: .github/workflows/ci.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,17 @@ jobs:
6868
os: windows-latest
6969
shell: cmd
7070
node-version:
71-
- 18.17.0
72-
- 18.x
73-
- 20.5.0
71+
- 20.17.0
7472
- 20.x
73+
- 22.9.0
7574
- 22.x
7675
exclude:
7776
- platform: { name: macOS, os: macos-13, shell: bash }
78-
node-version: 18.17.0
79-
- platform: { name: macOS, os: macos-13, shell: bash }
80-
node-version: 18.x
81-
- platform: { name: macOS, os: macos-13, shell: bash }
82-
node-version: 20.5.0
77+
node-version: 20.17.0
8378
- platform: { name: macOS, os: macos-13, shell: bash }
8479
node-version: 20.x
80+
- platform: { name: macOS, os: macos-13, shell: bash }
81+
node-version: 22.9.0
8582
- platform: { name: macOS, os: macos-13, shell: bash }
8683
node-version: 22.x
8784
runs-on: ${{ matrix.platform.os }}

Diff for: lib/util/import-or-require.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ const importOrRequire = async path => {
1414
let content = {}
1515
try {
1616
content = require(path)
17+
// this is for node 22+
18+
// istanbul ignore next
19+
if (content.__esModule) {
20+
return content.default
21+
}
1722
} catch {
23+
// istanbul ignore next
1824
try {
19-
content = await import(pathToFileURL(path)).then(r => r.default)
25+
// this is for node under 20
26+
const results = await import(pathToFileURL(path))
27+
// istanbul ignore next
28+
return results.default
2029
} catch {
2130
// its ok if this fails since the content dir might only be to provide
2231
// other files. the index.js is optional

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"prettier": true
9595
},
9696
"engines": {
97-
"node": "^18.17.0 || >=20.5.0"
97+
"node": "^20.17.0 || >=22.9.0"
9898
},
9999
"workspaces": [
100100
"workspace/test-workspace"

Diff for: test/apply/esm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ t.test('basic', async t => {
1818
})
1919
await s.apply()
2020

21-
const file = await s.readFile('file.js')
21+
const file = await s.readFile('content_dir/file.js')
2222
t.match(file, 'var x = 1;')
2323
})

Diff for: test/apply/import-or-require.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const t = require('tap')
2+
const importOrRequire = require('../../lib/util/import-or-require.js')
3+
const path = require('path')
4+
5+
t.test('importOrRequire', async t => {
6+
const dir = t.testdir({
7+
esm: {
8+
'package.json': JSON.stringify({
9+
type: 'module',
10+
}),
11+
'index.js': 'export default "type module";',
12+
},
13+
'esm.js': 'export default "esm";',
14+
'mjs.mjs': 'export default "mjs";',
15+
'cjs.cjs': 'module.exports = "cjs";',
16+
'js.js': 'module.exports = "js";',
17+
'invalid.js': 'invalid',
18+
})
19+
20+
await Promise.all(
21+
// double 'js' triggers the cache
22+
['mjs', 'cjs', 'js', 'js'].map(async type => {
23+
const output = await importOrRequire(path.join(dir, `${type}.${type}`))
24+
t.same(output, type)
25+
}),
26+
)
27+
})

0 commit comments

Comments
 (0)