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

Use resolve if require.resolve is overridden #8072

Merged
merged 14 commits into from Apr 21, 2020
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
11 changes: 8 additions & 3 deletions src/common/resolve.js
Expand Up @@ -4,9 +4,14 @@ let { resolve } = eval("require");

// In the VS Code extension `require` is overridden and `require.resolve` doesn't support the 2nd argument.
if (resolve.length === 1) {
const Module = eval("require")("module");
const createRequire = Module.createRequire || Module.createRequireFromPath;
resolve = createRequire(__dirname).resolve;
resolve = (id, options) => {
let baseDir;
thorn0 marked this conversation as resolved.
Show resolved Hide resolved
if (options && options.paths && options.paths.length === 1) {
baseDir = options.paths[0];
}

return require("resolve").sync(id, { baseDir });
thorn0 marked this conversation as resolved.
Show resolved Hide resolved
};
}

module.exports = resolve;
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