Skip to content

feat: engines to ^20.17.0 || >=22.9.0 #500

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

Merged
merged 8 commits into from
Jan 29, 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
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)
}),
)
})
Loading