Skip to content

Commit

Permalink
fix(webpack): Aliased module paths now properly map to the correct au…
Browse files Browse the repository at this point in the history
…relia-loader module id
  • Loading branch information
pat841 committed Nov 8, 2019
1 parent 9f6f798 commit 348fea9
Show file tree
Hide file tree
Showing 3 changed files with 437 additions and 133 deletions.
13 changes: 10 additions & 3 deletions src/AureliaDependenciesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IncludeDependency } from "./IncludeDependency";
import BasicEvaluatedExpression = require("webpack/lib/BasicEvaluatedExpression");
import { preserveModuleName } from "./PreserveModuleNamePlugin";

const TAP_NAME = "Aurelia:Dependencies";

Expand All @@ -13,7 +14,13 @@ class AureliaDependency extends IncludeDependency {

class Template {
apply(dep: AureliaDependency, source: Webpack.Source) {
source.replace(dep.range[0], dep.range[1] - 1, "'" + dep.request.replace(/^async(?:\?[^!]*)?!/, "") + "'");
// Get the module id, fallback to using the module request
let moduleId: string = dep.request;
if (dep.module && typeof dep.module[preserveModuleName] === 'string') {
moduleId = dep.module[preserveModuleName];
}

source.replace(dep.range[0], dep.range[1] - 1, "'" + moduleId.replace(/^async(?:\?[^!]*)?!/, "") + "'");
};
}

Expand Down Expand Up @@ -41,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") {
String(expr.object.type) === "Identifier") {
return new BasicEvaluatedExpression().setIdentifier("PLATFORM.moduleName").setRange(expr.range);
}
return undefined;
Expand All @@ -56,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")) {
String(expr.object.type) === "Identifier" && expr.object.name === "PLATFORM")) {
return new BasicEvaluatedExpression().setIdentifier("PLATFORM.moduleName").setRange(expr.range);
}
return undefined;
Expand Down
Loading

0 comments on commit 348fea9

Please sign in to comment.