Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix windows paths (#177)
  • Loading branch information
sokra authored and rauchg committed Dec 20, 2018
1 parent 132bda3 commit 484b415
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.js
@@ -1,5 +1,6 @@
const resolve = require("resolve");
const fs = require("graceful-fs");
const { sep } = require("path");
const webpack = require("webpack");
const MemoryFS = require("memory-fs");
const WebpackParser = require("webpack/lib/Parser");
Expand Down Expand Up @@ -85,20 +86,20 @@ module.exports = async (
else if (request.startsWith("../node_modules/")) request = request.substr(16);
else return callback();
}
if (request[0] === "/" || nodeBuiltins.has(request) ||
if (request[0] === "/" || /^[a-z]:\\/i.test(request) || nodeBuiltins.has(request) ||
tsconfigMatchPath && tsconfigMatchPath(request, undefined, undefined, SUPPORTED_EXTENSIONS))
return callback();
const pkgNameMatch = request.match(pkgNameRegEx);
if (pkgNameMatch) request = pkgNameMatch[0];
let pkgPath = context + '/node_modules/' + request;
let pkgPath = context + sep + 'node_modules' + sep + request;
do {
if (await new Promise((resolve, reject) =>
fs.stat(pkgPath, (err, stats) =>
err && err.code !== 'ENOENT' ? reject(err) : resolve(stats ? stats.isDirectory() : false)
)
))
return callback();
} while (pkgPath.length > (pkgPath = pkgPath.substr(0, pkgPath.lastIndexOf('/', pkgPath.length - 15 - request.length)) + '/node_modules/' + request).length);
} while (pkgPath.length > (pkgPath = pkgPath.substr(0, pkgPath.lastIndexOf(sep, pkgPath.length - 15 - request.length)) + sep + 'node_modules' + sep + request).length);
console.error(`ncc: Module directory "${context}" attempted to require "${request}" but could not be resolved, assuming external.`);
return callback(null, `commonjs ${request}`);
},
Expand Down

0 comments on commit 484b415

Please sign in to comment.