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

fix windows paths #177

Merged
merged 1 commit into from Dec 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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