Skip to content

Commit

Permalink
refactor: remove resolve dependency
Browse files Browse the repository at this point in the history
This replaces the dependency on resolve-from with node's native
`require.resolve` method.

If this and gulpjs/rechoir#47 are merged, a false positive related to
[resolve's `monorepo-symlink-test`](browserify/resolve#312)
file will be resolved.
  • Loading branch information
elliotttf committed Jun 21, 2024
1 parent 176151d commit 3900954
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const rechoir = require('rechoir');
const merge = require('lodash/merge');
const interpret = require('interpret');
const resolveFrom = require('resolve-from');
const path = require('path');
const tildify = require('tildify');
const commander = require('commander');
Expand All @@ -23,6 +22,7 @@ const {
findUpModulePath,
findUpConfig,
} = require('./utils/cli-config-utils');
const { silent } = require('./utils/resolve-from');
const {
existsSync,
readFile,
Expand Down Expand Up @@ -93,7 +93,7 @@ function invoke() {

// TODO add knexpath here eventually
const modulePath =
resolveFrom.silent(cwd, 'knex') ||
silent(cwd, 'knex') ||
findUpModulePath(cwd, 'knex') ||
process.env.KNEX_PATH;

Expand Down
9 changes: 9 additions & 0 deletions bin/utils/resolve-from.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function silent(fromDirectory, moduleId) {
try {
return require.resolve(moduleId, { paths: [fromDirectory] })
} catch (e) {
return '';
}
}

module.exports = { silent };
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"lodash": "^4.17.21",
"pg-connection-string": "2.6.2",
"rechoir": "^0.8.0",
"resolve-from": "^5.0.0",
"tarn": "^3.0.2",
"tildify": "2.0.0"
},
Expand Down

0 comments on commit 3900954

Please sign in to comment.