Skip to content

Commit

Permalink
Use resolve insteadof require.resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Apr 17, 2020
1 parent 673f4b0 commit c00689d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -62,6 +62,7 @@
"regexp-util": "1.2.2",
"remark-math": "1.0.6",
"remark-parse": "5.0.0",
"resolve": "1.16.0",
"semver": "7.3.2",
"srcset": "2.0.1",
"string-width": "4.2.0",
Expand Down
10 changes: 6 additions & 4 deletions src/common/load-plugins.js
Expand Up @@ -5,10 +5,10 @@ const partition = require("lodash/partition");
const fs = require("fs");
const globby = require("globby");
const path = require("path");
const resolve = require("resolve");
const thirdParty = require("./third-party");
const internalPlugins = require("./internal-plugins");
const mem = require("mem");
const resolve = require("./resolve");

const memoizedLoad = mem(load, { cacheKey: JSON.stringify });
const memoizedSearch = mem(findPluginsInNodeModules);
Expand Down Expand Up @@ -43,10 +43,10 @@ function load(plugins, pluginSearchDirs) {
let requirePath;
try {
// try local files
requirePath = resolve(path.resolve(process.cwd(), pluginName));
requirePath = resolve.sync(path.resolve(process.cwd(), pluginName));
} catch (_) {
// try node modules
requirePath = resolve(pluginName, { paths: [process.cwd()] });
requirePath = resolve.sync(pluginName, { basedir: process.cwd() });
}

return {
Expand Down Expand Up @@ -82,7 +82,9 @@ function load(plugins, pluginSearchDirs) {

return memoizedSearch(nodeModulesDir).map((pluginName) => ({
name: pluginName,
requirePath: resolve(pluginName, { paths: [resolvedPluginSearchDir] }),
requirePath: resolve.sync(pluginName, {
basedir: resolvedPluginSearchDir,
}),
}));
})
.reduce((a, b) => a.concat(b), []);
Expand Down
12 changes: 0 additions & 12 deletions src/common/resolve.js

This file was deleted.

7 changes: 4 additions & 3 deletions src/config/resolve-config.js
Expand Up @@ -2,12 +2,12 @@

const thirdParty = require("../common/third-party");
const minimatch = require("minimatch");
const resolve = require("resolve");
const path = require("path");
const mem = require("mem");

const resolveEditorConfig = require("./resolve-config-editorconfig");
const loadToml = require("../utils/load-toml");
const resolve = require("../common/resolve");

const getExplorerMemoized = mem(
(opts) => {
Expand All @@ -17,8 +17,9 @@ const getExplorerMemoized = mem(
transform: (result) => {
if (result && result.config) {
if (typeof result.config === "string") {
const dir = path.dirname(result.filepath);
const modulePath = resolve(result.config, { paths: [dir] });
const modulePath = resolve.sync(result.config, {
basedir: path.dirname(result.filepath),
});
result.config = eval("require")(modulePath);
}

Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Expand Up @@ -6463,6 +6463,13 @@ resolve@1.1.7:
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=

resolve@1.16.0:
version "1.16.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.16.0.tgz#063dc704fa3413e13ac1d0d1756a7cbfe95dd1a7"
integrity sha512-LarL/PIKJvc09k1jaeT4kQb/8/7P+qV4qSnN2K80AES+OHdfZELAKVOBjxsvtToT/uLOfFbvYvKfZmV8cee7nA==
dependencies:
path-parse "^1.0.6"

resolve@^1.1.6, resolve@^1.10.0, resolve@^1.11.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.15.1, resolve@^1.3.2:
version "1.15.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.15.1.tgz#27bdcdeffeaf2d6244b95bb0f9f4b4653451f3e8"
Expand Down

0 comments on commit c00689d

Please sign in to comment.