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

Do not overwrite user tsconfig #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JLHwung
Copy link

@JLHwung JLHwung commented Jun 7, 2018

Motivation

We use jest to unit test Angular components with ngx-bootstrap 3.0.0 imports. The test will fail with

Can't resolve all parameters for ComponentLoaderFactory: (?, ?, ?, ?, ?)

since the decorate metadata is not emitted on the umd build of ngx-bootstrap even if the tsconfig of ngx-bootstrap declares emitDecoratorMetadata: true.

The bug is introduced in 03769f2 so ngx-bootstrap 2.0 is untouched.

webpack does not complain about metadata missing since webpack can use module field in package.json to resolve ngx-bootstrap. However, jest does not support this feature yet, so jest will use main field to resolve. When the umd build is lack of decorate metadata, it will fail with angular JIT compiler.

Workaround

(before this PR gets merged and ngx-bootstrap is re-bundled by updated ngm-cli)

Add the following line to jest.config.js

moduleNameMapper: {
    "ngx-bootstrap": "<rootDir>/node_modules/ngx-bootstrap/bundles/ngx-bootstrap.es2015.js"
},

The user cannot overwrite the compilerOptions.declaration since `compilerOptions` is always prioritized over `configFile`, see https://github.com/TypeStrong/ts-loader/blob/002c0f651cf1a8e27b0e232b7fe4a982ddce6323/src/config.ts#L66.
@JLHwung
Copy link
Author

JLHwung commented Jun 20, 2018

ping @valorkin.

@valorkin
Copy link
Member

Will not this bloat umd file size?

@JLHwung
Copy link
Author

JLHwung commented Jun 20, 2018

Hi valorkin,

Will not this bloat umd file size?

Yes, adding emitDecoratorMetadata: true will bloat umd file size a little bit, but this configuration is recommended on Angular Package Format. And one can verify that @angular/cdk also ships decorator metadata in their umd build. The decorator metadata should not contribute the size too much with gzip.

Adding declaration: true will generate *.d.ts files so it have nothing to do with umd bundles.

Besides, both ngx-bootstrap and ng2-select have specified emitDecoratorMetadata: true in their tsconfig.json, however, this config is overwritten silently by ngm-cli and therefore, decorators metadata are missing in the umd build. I don't think a packager should overwrite the user config. It would be more straightforward to giving defaults for user config. Any thoughts?

@JLHwung
Copy link
Author

JLHwung commented Aug 9, 2018

ping @valorkin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants