Skip to content

Commit adbebb4

Browse files
committed
fix
1 parent ca0ffa3 commit adbebb4

File tree

5 files changed

+16
-37
lines changed

5 files changed

+16
-37
lines changed

.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 }}

.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 }}

lib/util/import-or-require.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// then subsequent requires for the same path would return an empty object. Not
44
// sure if a bug or I'm doing something wrong but since the require/imports here
55
// are short lived, it is safe to create our own cache and use that.
6-
const { pathToFileURL } = require('url')
76

87
const importOrRequireCache = new Map()
98

@@ -14,21 +13,12 @@ const importOrRequire = async path => {
1413
let content = {}
1514
try {
1615
content = require(path)
17-
// this is for node 22+
18-
// istanbul ignore next
1916
if (content.__esModule) {
20-
return content.default
17+
content = content.default
2118
}
2219
} catch {
23-
try {
24-
// this is for node under 18
25-
const results = await import(pathToFileURL(path))
26-
// istanbul ignore next
27-
return results.default
28-
} catch {
29-
// its ok if this fails since the content dir might only be to provide
30-
// other files. the index.js is optional
31-
}
20+
// its ok if this fails since the content dir might only be to provide
21+
// other files. the index.js is optional
3222
}
3323
importOrRequireCache.set(path, content)
3424
return content

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"

test/apply/import-or-require.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ t.test('importOrRequire', async t => {
2020
const typeModule = await importOrRequire(path.join(dir, 'esm/index.js'))
2121
t.same(typeModule, 'type module')
2222

23-
if (process.version.replace('v', '').split('.')[0] >= '22') {
24-
const results = await importOrRequire(path.join(dir, 'esm.js'))
25-
t.same(results, 'esm')
26-
} else {
27-
const results = await importOrRequire(path.join(dir, 'esm.js'))
28-
t.same(results, {})
29-
}
23+
const results = await importOrRequire(path.join(dir, 'esm.js'))
24+
t.same(results, 'esm')
3025

3126
await Promise.all(
3227
// double 'js' triggers the cache

0 commit comments

Comments
 (0)