Skip to content

Commit 881f269

Browse files
committed
feat(build): add support for windows filesystem
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.
1 parent 965222f commit 881f269

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/AureliaDependenciesPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ParserPlugin {
4444
parser.plugin("evaluate Identifier imported var.moduleName", (expr: Webpack.MemberExpression) => {
4545
if (expr.property.name === "moduleName" &&
4646
expr.object.name === "PLATFORM" &&
47-
expr.object.type === "Identifier") {
47+
expr.object.type.toString() === "Identifier") {
4848
return new BasicEvaluatedExpression().setIdentifier("PLATFORM.moduleName").setRange(expr.range);
4949
}
5050
return undefined;
@@ -59,7 +59,7 @@ class ParserPlugin {
5959
parser.plugin("evaluate MemberExpression", (expr: Webpack.MemberExpression) => {
6060
if (expr.property.name === "moduleName" &&
6161
(expr.object.type === "MemberExpression" && expr.object.property.name === "PLATFORM" ||
62-
expr.object.type === "Identifier" && expr.object.name === "PLATFORM")) {
62+
expr.object.type.toString() === "Identifier" && expr.object.name === "PLATFORM")) {
6363
return new BasicEvaluatedExpression().setIdentifier("PLATFORM.moduleName").setRange(expr.range);
6464
}
6565
return undefined;

src/PreserveModuleNamePlugin.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class PreserveModuleNamePlugin {
5656
}
5757

5858
// Metadata?
59+
moduleId = moduleId.replace(/\\/g, '/');
5960
if (module.meta) {
6061
module.meta['aurelia-id'] = moduleId;
6162
}
@@ -148,11 +149,22 @@ function getNodeModuleData(module: Webpack.Module): NodeModule.Data | null {
148149
return null;
149150
}
150151

152+
function cleanWindowsPaths(paths: RegExpMatchArray | null) {
153+
var out: string[] = [];
154+
if (!paths) {
155+
return out;
156+
}
157+
for (var i = 0; i < paths.length; i += 1) {
158+
out[i] = paths[i].replace(':', '').split('\\').join('/');
159+
}
160+
return out;
161+
}
162+
151163
// Note that the negative lookahead (?!.*node_modules) ensures that we only match the last node_modules/ folder in the path,
152164
// in case the package was located in a sub-node_modules (which can occur in special circumstances).
153165
// We also need to take care of scoped modules. If the name starts with @ we must keep two parts,
154166
// so @corp/bar is the proper module name.
155-
const modulePaths = module.resource.match(/(.*\bnode_modules[\\/](?!.*\bnode_modules\b)((?:@[^\\/]+[\\/])?[^\\/]+))(.*)/i);
167+
const modulePaths = cleanWindowsPaths(module.resource.match(/(.*\bnode_modules[\\/](?!.*\bnode_modules\b)((?:@[^\\/]+[\\/])?[^\\/]+))(.*)/i));
156168
if (!modulePaths || modulePaths.length !== 4) {
157169
return null;
158170
}

0 commit comments

Comments
 (0)