Skip to content

Commit

Permalink
fix: Fix scoped packages handling when bundling on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Apr 1, 2020
1 parent 4934500 commit fc7fc8b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ if (!isValue(sep)) {
throw new Error("Unsupported Node version. Please upgrade, Webmake needs at least Node v0.8");
}
const dirEndMatch = new RegExp(`(?:^|/|\\${ sep })\\.*$`, "u");
const packageNamePattern = /(@[^/]+\/[^/]+|[^@/][^/]*)(?:\/|$)/u;
const packageNamePattern = new RegExp(
`(@[^\\${ sep }]+\\${ sep }[^\\${ sep }]+|[^@\\${ sep }][^\\${ sep }]*)(?:\\${ sep }|$)`, "u"
);

const cssDeps = [
{
Expand Down Expand Up @@ -483,9 +485,10 @@ const parser = {
let filename = join(dep.value), tree, currentRequire, main, path, ext;

const [, name] = filename.match(packageNamePattern);
const packageName = name.includes(sep) && sep !== "/" ? name.replace(sep, "/") : name;
return deferred.promisifySync(() => {
// If already processed, return result
if (this.modules[name]) return this.modules[name];
if (this.modules[packageName]) return this.modules[packageName];

if (name === "webmake") {
this.packages.webmake = resolve(__dirname, "../");
Expand Down Expand Up @@ -545,23 +548,23 @@ const parser = {
this.packages[name] = path.slice(
0, name.length - (filename.length + ext.length)
);
return (this.modules[name] = {});
return (this.modules[packageName] = {});
}
if (endsWith.call(path, filename)) {
this.packages[name] = path.slice(0, name.length - filename.length);
return (this.modules[name] = {});
return (this.modules[packageName] = {});
}
}
// Use dedicated findRoot
const promise = (this.modules[name] = findRoot(path)(root => {
const promise = (this.modules[packageName] = findRoot(path)(root => {
const currentModule = {};
this.packages[name] = root;
return getMain(root)(mainModule => {
currentModule[":mainpath:"] = mainModule;
return currentModule;
}, currentModule);
}));
promise.aside(currentModule => { this.modules[name] = currentModule; });
promise.aside(currentModule => { this.modules[packageName] = currentModule; });
return promise;
})()(currentScope => {
if (!currentScope) return null;
Expand Down

0 comments on commit fc7fc8b

Please sign in to comment.