Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix: get real path from __filename instead of __dirname (NS)
Browse files Browse the repository at this point in the history
Without this fix, this plugin doesn't work if your node_modules tree is
made up of directories, but your files are symlinks. It's admittedly a
weird environment, but that's the environment that the Bazel build
system runs code in, which is the build system we use at Dropbox.

This is the bug:

 - index.js is called from the runfiles directory, and it uses the
   realpath of its directory as the key for a function on the
   loaderContext object.

 - loader.js is called from the bazel-bin/npm directory outside
   of its runfiles (because Webpack escapes the runfiles when it
   calls loaders). It uses the realpath of its directory as a
   key on the loaderContext object, but because it's in a
   different directory from index.js, it can't find the function
   set on the loaderContext by index.js.

The fix is to get the realpath of the filename instead of the
directory so that both files point to the same place.
  • Loading branch information
samertm authored and evilebottnawi committed Sep 14, 2017
1 parent 510704f commit 8de6558
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -17,7 +17,7 @@ import {
isFunction,
} from './lib/helpers';

const NS = fs.realpathSync(__dirname);
const NS = path.dirname(fs.realpathSync(__filename));

let nextId = 0;

Expand Down
3 changes: 2 additions & 1 deletion src/loader.js
@@ -1,12 +1,13 @@
import fs from 'fs';
import path from 'path';
import loaderUtils from 'loader-utils';
import NodeTemplatePlugin from 'webpack/lib/node/NodeTemplatePlugin';
import NodeTargetPlugin from 'webpack/lib/node/NodeTargetPlugin';
import LibraryTemplatePlugin from 'webpack/lib/LibraryTemplatePlugin';
import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';
import LimitChunkCountPlugin from 'webpack/lib/optimize/LimitChunkCountPlugin';

const NS = fs.realpathSync(__dirname);
const NS = path.dirname(fs.realpathSync(__filename));

export default source => source;

Expand Down

0 comments on commit 8de6558

Please sign in to comment.