Setting "paths.root" to actual root directory leads to fatal results (detailed cause included)
- Dominant language
- JavaScript
- Stars
- 402
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Description
**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.
Contributor guide
Research direction
Read Loader.js, especially normalizePath(), and package-analyzer.js, especially getPackageFolder(). Reproduce the issue by setting paths.root to the actual project root and running au build, then compare the resolved dependency paths with the expected root\node_modules location. Done means bundling works without resolving dependencies through the parent directory or duplicating the project root.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- build-system, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100