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

Forward all args to originalResolveFilename #778

Merged
merged 6 commits into from
May 22, 2019
Merged
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
1 change: 1 addition & 0 deletions internal/e2e/fine_grained_no_bin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nodejs_binary(
name = "index",
data = [
"index.js",
"test/test.js",
"@fine_grained_no_bin//fs.realpath",
],
entry_point = "build_bazel_rules_nodejs/internal/e2e/fine_grained_no_bin/index.js",
Expand Down
4 changes: 3 additions & 1 deletion internal/e2e/fine_grained_no_bin/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
console.log('hello world');
const path = require("path");

console.log('hello ' + require.resolve("./test.js", { paths: [ path.join(__dirname, 'test') ] }));
Empty file.
12 changes: 5 additions & 7 deletions internal/node/node_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function resolveRunfiles(parent, ...pathSegments) {
}

var originalResolveFilename = module.constructor._resolveFilename;
module.constructor._resolveFilename = function(request, parent) {
module.constructor._resolveFilename = function(request, parent, isMain, options) {
const parentFilename = (parent && parent.filename) ? parent.filename : undefined;
if (DEBUG)
console.error(`node_loader: resolve ${request} from ${parentFilename}`);
Expand All @@ -351,7 +351,7 @@ module.constructor._resolveFilename = function(request, parent) {
// Built-in modules, relative, absolute imports and npm dependencies
// can be resolved using request
try {
const resolved = originalResolveFilename(request, parent);
const resolved = originalResolveFilename(request, parent, isMain, options);
if (resolved === request || request.startsWith('.') || request.startsWith('/') ||
request.match(/^[A-Z]\:[\\\/]/i)) {
if (DEBUG)
Expand Down Expand Up @@ -391,7 +391,7 @@ module.constructor._resolveFilename = function(request, parent) {
// If the import is not a built-in module, an absolute, relative import or a
// dependency of an npm package, attempt to resolve against the runfiles location
try {
const resolved = originalResolveFilename(resolveRunfiles(parentFilename, request), parent);
const resolved = originalResolveFilename(resolveRunfiles(parentFilename, request), parent, isMain, options);
if (DEBUG)
console.error(
`node_loader: resolved ${request} within runfiles to ${resolved} from ${parentFilename}`
Expand All @@ -416,8 +416,7 @@ module.constructor._resolveFilename = function(request, parent) {
const parentSegments = relativeParentFilename.split('/');
if (parentSegments[0] !== USER_WORKSPACE_NAME) {
try {
const resolved = originalResolveFilename(
resolveRunfiles(undefined, parentSegments[0], 'node_modules', request), parent);
const resolved = originalResolveFilename(resolveRunfiles(undefined, parentSegments[0], 'node_modules', request), parent, isMain, options);
if (DEBUG)
console.error(
`node_loader: resolved ${request} within node_modules ` +
Expand All @@ -433,8 +432,7 @@ module.constructor._resolveFilename = function(request, parent) {
// If import was not resolved above then attempt to resolve
// within the node_modules filegroup in use
try {
const resolved = originalResolveFilename(
resolveRunfiles(undefined, NODE_MODULES_ROOT, request), parent);
const resolved = originalResolveFilename(resolveRunfiles(undefined, NODE_MODULES_ROOT, request), parent, isMain, options);
if (DEBUG)
console.error(
`node_loader: resolved ${request} within node_modules (${NODE_MODULES_ROOT}) to ` +
Expand Down