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

feat!: Remove resolve dependency which increases min Node version to v8.10.0 #104

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 1 addition & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test-vers:
strategy:
matrix:
node: ['8.6', '8', '10.0', '10', '12.0', '12', '14.0', '14', '16.0', '16', '18.0', '18', '20', '22']
node: ['8.10', '10.0', '10', '12.0', '12', '14.0', '14', '16.0', '16', '18.0', '18', '20', '22']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -20,15 +20,3 @@ jobs:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm test
test-expose-http2:
strategy:
matrix:
node: ['8.6']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: NODE_OPTIONS='--expose-http2' npm test
29 changes: 2 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,7 @@ if (Module.isBuiltin) { // Added in node v18.6.0, v16.17.0
return builtinModules.has(moduleName)
}
} else {
const _resolve = require('resolve')
const [major, minor] = process.versions.node.split('.').map(Number)
if (major === 8 && minor < 8) {
// For node versions `[8.0, 8.8)` the "http2" module was built-in but
// behind the `--expose-http2` flag. `resolve` only considers unflagged
// modules to be core: https://github.com/browserify/resolve/issues/139
// However, for `ExportsCache` to work for "http2" we need it to be
// considered core.
isCore = moduleName => {
if (moduleName === 'http2') {
return true
}
// Prefer `resolve.core` lookup to `resolve.isCore(moduleName)` because
// the latter is doing version range matches for every call.
return !!_resolve.core[moduleName]
}
} else {
isCore = moduleName => {
// Prefer `resolve.core` lookup to `resolve.isCore(moduleName)` because
// the latter is doing version range matches for every call.
return !!_resolve.core[moduleName]
}
}
throw new Error('\'require-in-the-middle\' requires Node.js >= v9.3.0 or v8.10.0')
}

// Feature detection: This property was added in Node.js 8.9.0, the same time
Expand All @@ -69,10 +47,7 @@ if (require.resolve.paths) {
return require.resolve(moduleName, { paths: [basedir] })
}
} else {
const _resolve = require('resolve')
resolve = function (moduleName, basedir) {
return _resolve.sync(moduleName, { basedir })
}
throw new Error('\'require-in-the-middle\' requires Node.js >= v9.3.0 or v8.10.0')
}

// 'foo/bar.js' or 'foo/bar/index.js' => 'foo/bar'
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"types": "types/index.d.ts",
"dependencies": {
"debug": "^4.3.5",
"module-details-from-path": "^1.0.3",
"resolve": "^1.22.8"
"module-details-from-path": "^1.0.3"
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand Down