-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
CLI Bundler alias/paths matched incorrectly (Plugin development) #1093
Comments
TS is different, it requires config in tsconfig. Here is a fix unreleased. Note this fix only config "resources", means you can only do import { HelloWorld } from 'resources/elements/hello-world'; But not import { HelloWorld } from 'elements/hello-world'; You might be able to enhance tsconfig to support So for dev-app to access anything in the inner-plugin, use Also as you pointed out in FYI
These four are not designed to be used in AMD module loading (for both app and plugin projects), although it works because we hijacked requirejs paths config (if I fixed the shortcuts). |
@huochunpeng Thanks for your reply. This issue is not about typescript. Let me try to explain. "baseUrl": "src",
"paths": {
"resources/*": [ "./" ],
"elements/*": "./elements",
"attributes/*": "./attributes",
"valueConverters/*": "./value-converters",
"bindingBehaviors/*": "./binding-behaviors"
}, This would make both of the following imports possible from a TS point of view: But as you already mentioned This issue is also not just about the dev-app but also limits the usage of aliases in the inner plugin, this is why I raised this ticket. If the code would support multiple alias matches this problem would not exist or find the "best" match but I just realized this might break existing setups. |
I acknowledged that shortcuts issue. Will fix that. |
@huochunpeng I have some time to take a look. I will give it a go if you don't mind 😃 |
Sure. Thx! |
Define multiple aliases when they can be applied for a path. Closes aurelia#1093
I'm submitting a bug report
Library Version:
"aurelia-cli:
^1.0.0-beta.15
Please tell us about your environment:
Operating System:
Windows [10]
Node Version:
v10.15.0
6.9.0
Browser:
Not browser related
Language:
TS but assume it's an issue for all
Loader/bundler:
CLI Bundler
Current behavior:
When the bundler tries to add aliases it looks at the module id, for example
../src/elements/hello-world
and tries to match it with a configured path.One of the following in a default configuration:
It does this by going over this list top down and will only match 1. For the previously mentioned module id it will match with resources and this will result in failure when running the app.
Logic responsible for this behavior:
I would not expect order to influence alias path matching, neither would I expect duplicate entries with different paths to be an issue.
There is probably a good reason for current approach but I would expect imports to be converted to the actual paths instead of creating a creating a new module that returns an existing one. So search for key and replace by target (path).
A low impact solution might be to search for the best match based on amount of character matched (I think this could be accomplished by sorting by length before looping)Edit: Bad idea this could break existing setups
Given: You have the aurelia cli installed
And: run
au new --plugin
And: follow instructions, choose all examples at the final step
And: add
import { HelloWorld } from 'elements/hello-world';
todev-app/app.ts
And add
console.log(HelloWorld)
to a constructorAnd: run
au run
When: open
localhost:9000
in browserThen: console will show error
Expected:
Hello world class should load and be logged in the console.
I would like to utilize paths to keep my code clean and maintainable.
Work around
Reorder paths, deepest first, shortest last. This has a drawback, it will force you to use the correct (deepest) alias.
The text was updated successfully, but these errors were encountered: