cli icon indicating copy to clipboard operation
cli copied to clipboard

Setting "paths.root" to actual root directory leads to fatal results (detailed cause included)

Open uncttao opened this issue 7 years ago • 7 comments

I'm submitting a bug report

  • Library Version: aurelia-cli 0.18.0

  • Operating System: Windows Server 2012 R2 Datacenter

  • Node Version: 6.1.0

  • NPM Version: 3.8.6

  • Browser: all (this issue is not browser-related)

  • Language: ESNext

  • Current behavior: Change paths.root configuration in aurelia.json to the actual root directory instead of src. When running au build, this will lead to aurelia-cli looks for node_modules dependencies in your codes in the parent directory of the actual root directory instead in the actual root directory.

  • Expected/desired behavior: aurelia-cli should allow paths.root to be set to the actual root directory of the project without behaving errantly while bundling.

  • Verbose explanation of cause per self-investigation:

    When the bundling process comes to the normalizePath() function in Loader.js, the filePath parameter turns out to be the result of paths.root + ../node_modules/some-package, and the final version be acutal root + paths.root + ../node_modules/some-package given the code filePath = path.join(rootDir, filePath). This is no problem if paths.root is set to any sub-directory of the actual root, but if it is not, the final path would be actual root + ../node_modules/some-package, which is a wrong path. Unfortunately, trying to bypass this behavior by manually declaring the package path to node_modules/some-package in aurelia-json causes another equally severe problem. When bundling, the result of function getPackageFolder() in package-analyzer.js is determined by the relative path from actual root\.. to actual root\..\node_modules\some-package. If package path is declared as node_modules/some-package. the result of getPackageFolder() will become the relative path from actual root\.. to actual root\node_modules\some-package which leads to the final resolved version looks like actual root\actual root\node_modules\some-package, which is incorrect.

uncttao avatar Sep 15 '16 08:09 uncttao

Can you do me a favor and format this according to the issue template?

AStoker avatar Sep 15 '16 13:09 AStoker

This is a possible duplicate of https://github.com/aurelia/cli/issues/278 I wrote a PR for this once (I switched to webpack now though) But you can try if the changes would help you. I wrote the code mainly to allow deeper root paths. https://github.com/aurelia/cli/pull/295

alpox avatar Sep 15 '16 21:09 alpox

@alpox By trying your changes, you mean in what way?

uncttao avatar Sep 16 '16 08:09 uncttao

@twttao you can use my fork of Aurelia-CLI to see if it works for you.

alpox avatar Sep 16 '16 09:09 alpox

@AStoker It is updated. Thanks.

uncttao avatar Sep 16 '16 09:09 uncttao

@alpox Thanks a lot for the help. But since this is a professional enterprise project I am working for, I am afraid I cannot simply fork your repository and make it production for various administrative and executive reasons.

uncttao avatar Sep 16 '16 09:09 uncttao

@twttao It was not the intention to rely on my repository but rather to find out if the changes would help in your case too to figure out if you could apply an own patch on an in-enterprise repository or similar.

alpox avatar Sep 16 '16 11:09 alpox