Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

build-optimizer hardcodes private "esm5" paths to enable optimizations #523

Closed
IgorMinar opened this issue Mar 18, 2018 · 4 comments
Closed

Comments

@IgorMinar
Copy link
Contributor

IgorMinar commented Mar 18, 2018

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting

Area

- [x] devkit

Versions

Angular CLI: 1.6.6
Node: 8.9.4
OS: darwin x64
Angular: 6.0.0-beta.7-ac402a5a85
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.6 (but the problematic code is still present in master)
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.6
@schematics/angular: 0.1.17
typescript: 2.7.2

Repro steps

the following line hardcodes "esm5" path - which is an implementation detail and not part of the public api:

/[\\/]node_modules[\\/]@angular[\\/][^\\/]+[\\/]esm5[\\/]/,

this line then uses the path above to test if build-optimizer optimizations should be enabled:

&& es5AngularModules.some((re) => re.test(filePath))

Desired functionality

it's not clear to me why we hardcode these paths. ideally we should follow the "module" property to see where the code is in the package, or even better we should check the new "sideEffects" property introduced by webpack v4.

It seems that we are intentionally excluding the es2015 distribution from these optimizations. I'm not sure why, but regardless of the reason, relying on paths is not the right way to go about this - we should be consulting the package.json and using the same resolution algorithm (or the reversed version of it) to understand what kind of file we are dealing with.

Mention any other details that might be useful

@filipesilva
Copy link
Contributor

filipesilva commented Mar 18, 2018

@IgorMinar the reason those paths are hardcoded is because Build Optimizer itself does not know about entry points as described in package.json. It only knows about file paths.

When used with Webpack, that information could be passed along. But Build Optimizer can be used outside of Webpack as well. Doing resolution for each file passed can be costly so that determination is left to the tooling.

I think the right approach to move out of the hardcoded paths is to make use of the isSideEffectFree flag on the consuming tooling: https://github.com/angular/devkit/blob/master/packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer.ts#L70

This is what we used for the Bazel integration via Rollup. The webpack loader hasn't yet been revisited to use this as well.

The es2015 are excluded intentionally because Build Optimizer doesn't support es2015 code, with some of the optimizations breaking it.

@IgorMinar
Copy link
Contributor Author

aha! great insights. thanks! I agree that we should just switch over to detection based on the sideEffects package.json flag.

IgorMinar added a commit that referenced this issue Mar 18, 2018
hansl pushed a commit that referenced this issue Mar 18, 2018
@clydin
Copy link
Member

clydin commented Mar 19, 2018

PR #531 allows the build optimizer to leverage the webpack side effect detection.

@clydin
Copy link
Member

clydin commented Mar 19, 2018

Also of note: The CLI v6 webpack 4 configuration marks previous versions of Angular as side effect free in addition to any packages with the sideEffects flag.

filipesilva added a commit to filipesilva/devkit that referenced this issue May 29, 2018
filipesilva added a commit to filipesilva/devkit that referenced this issue May 29, 2018
filipesilva added a commit to filipesilva/devkit that referenced this issue May 29, 2018
filipesilva added a commit to filipesilva/devkit that referenced this issue May 29, 2018
@clydin clydin closed this as completed in 4814a4a May 30, 2018
hansl pushed a commit that referenced this issue May 30, 2018
hansl pushed a commit to angular/angular-cli that referenced this issue Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants