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(webpack): Aliased module paths now properly map to the correct aurelia-loader module id [SIMPLE] #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion 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 = dep.request;
if (dep.module && typeof dep.module[preserveModuleName] === "string") {
moduleId = dep.module[preserveModuleName];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what the impact of this change is.
Can you explain briefly, maybe with an example that behaves differently before/after this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AureliaDependenciesPlugin uses the preserveModuleName symbol to set the generated moduleId. We then check that it is set here and use that for the webpack moduleId, otherwise fallback to the default usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see.
I had this idea of rewriting user code with Webpack generated id but it breaks quite a few things (such as conventions).

You take a middle ground where you rewrite user's code with our normalized id.
That seems safe and would solve a few issue, I think, as aurelia-loader will do the same normalization anyway.., and in the rare cases where it doesn't (there are a few) it would break at runtime anyway.

Looks like a good change to me 👍

Out of curiosity: does this fix a specific problem you have?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does see #121

}

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

Expand Down
Loading