Skip to content

Commit

Permalink
feat(build): add support for windows filesystem
Browse files Browse the repository at this point in the history
When building on the Windows filesystem back-slashes were being used for
file paths and module ids.  The back-slashes were being escaped but in
the case of modules that start with the letter 'u' ended up being
interpreted as starting a unicode character.  To fix this we are
replacing back-slashes with forward-slashes in module paths and module
ids.

This is believed to be a non-breaking change.
  • Loading branch information
jsleuth authored and pat841 committed Jun 26, 2018
1 parent e5adcc9 commit ff34bb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/AureliaDependenciesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ParserPlugin {
hooks.evaluateIdentifier.tap("imported var.moduleName", TAP_NAME, (expr: Webpack.MemberExpression) => {
if (expr.property.name === "moduleName" &&
expr.object.name === "PLATFORM" &&
expr.object.type === "Identifier") {
expr.object.type.toString() === "Identifier") {
return new BasicEvaluatedExpression().setIdentifier("PLATFORM.moduleName").setRange(expr.range);
}
return undefined;
Expand All @@ -63,7 +63,7 @@ class ParserPlugin {
hooks.evaluate.tap("MemberExpression", TAP_NAME, expr => {
if (expr.property.name === "moduleName" &&
(expr.object.type === "MemberExpression" && expr.object.property.name === "PLATFORM" ||
expr.object.type === "Identifier" && expr.object.name === "PLATFORM")) {
expr.object.type.toString() === "Identifier" && expr.object.name === "PLATFORM")) {
return new BasicEvaluatedExpression().setIdentifier("PLATFORM.moduleName").setRange(expr.range);
}
return undefined;
Expand Down
14 changes: 13 additions & 1 deletion src/PreserveModuleNamePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class PreserveModuleNamePlugin {
if (/^async[?!]/.test(realModule.rawRequest))
id = "async!" + id;

id = id.replace(/\\/g, '/');
if (module.buildMeta) // meta can be null if the module contains errors
module.buildMeta["aurelia-id"] = id;
if (!this.isDll) {
Expand Down Expand Up @@ -198,11 +199,22 @@ function getNodeModuleData(module: Webpack.Module): NodeModule.Data | null {
return null;
}

function cleanWindowsPaths(paths: RegExpMatchArray | null) {
var out: string[] = [];
if (!paths) {
return out;
}
for (var i = 0; i < paths.length; i += 1) {
out[i] = paths[i].replace(':', '').split('\\').join('/');
}
return out;
}

// Note that the negative lookahead (?!.*node_modules) ensures that we only match the last node_modules/ folder in the path,
// in case the package was located in a sub-node_modules (which can occur in special circumstances).
// We also need to take care of scoped modules. If the name starts with @ we must keep two parts,
// so @corp/bar is the proper module name.
const modulePaths = module.resource.match(/(.*\bnode_modules[\\/](?!.*\bnode_modules\b)((?:@[^\\/]+[\\/])?[^\\/]+))(.*)/i);
const modulePaths = cleanWindowsPaths(module.resource.match(/(.*\bnode_modules[\\/](?!.*\bnode_modules\b)((?:@[^\\/]+[\\/])?[^\\/]+))(.*)/i));
if (!modulePaths || modulePaths.length !== 4) {
return null;
}
Expand Down

0 comments on commit ff34bb1

Please sign in to comment.