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

Commit 8de6558

Browse files
samertmevilebottnawi
authored andcommitted
fix: get real path from __filename instead of __dirname (NS)
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.
1 parent 510704f commit 8de6558

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
isFunction,
1818
} from './lib/helpers';
1919

20-
const NS = fs.realpathSync(__dirname);
20+
const NS = path.dirname(fs.realpathSync(__filename));
2121

2222
let nextId = 0;
2323

src/loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import fs from 'fs';
2+
import path from 'path';
23
import loaderUtils from 'loader-utils';
34
import NodeTemplatePlugin from 'webpack/lib/node/NodeTemplatePlugin';
45
import NodeTargetPlugin from 'webpack/lib/node/NodeTargetPlugin';
56
import LibraryTemplatePlugin from 'webpack/lib/LibraryTemplatePlugin';
67
import SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';
78
import LimitChunkCountPlugin from 'webpack/lib/optimize/LimitChunkCountPlugin';
89

9-
const NS = fs.realpathSync(__dirname);
10+
const NS = path.dirname(fs.realpathSync(__filename));
1011

1112
export default source => source;
1213

0 commit comments

Comments
 (0)