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

[PR WELCOME] Set language level for library sources (es5, es6, es7, dom, webworker, ...) #162

Closed
1 of 2 tasks
JulienOuvrard opened this issue Oct 5, 2017 · 10 comments
Closed
1 of 2 tasks

Comments

@JulienOuvrard
Copy link

@JulienOuvrard JulienOuvrard commented Oct 5, 2017

Type of Issue

  • Bug Report
  • Feature Request

Description

I have made an application using a custom component library that I have implemented, and now i wanted to use ng-packagr to externalize my custom component library.
The application was created by angular-cli, and i have followed the tutorial of Nikolas LeBlanc and the structure shown in the ng-packaged project.

For some reasons i have used in development es7 features like includes on arrays and padStart on strings.
With the angular-cli builds including polyfills of core-js everything was working fine but the ng-packagr build gave me errors like this

Property 'includes' does not exist on type 'any[]'.

I have tried to include them as externals and import them in the components that required the functions but still have theses errors.

So, how can i add polyfills functions on the build ?

Version Information

ng-packagr: v1.3.0
node: v7.10.0
@angular: v4.1.3
rxjs: v5.4.2
zone.js: v0.8.14
core-js: v2.4.1
@dherges
Copy link
Member

@dherges dherges commented Oct 5, 2017

Hi @JulienOuvrard,

it seems to be not possible at the moment as the auto-configuration for the TypeScript compiler is dom, es2015 API.

What is the current best practice / recommendation for polyfills? Is es7 (es2016) already released "to go at it"? I remember there was a discussion on the angular main repo saying "we don't want to use ES7 yet"

@JulienOuvrard
Copy link
Author

@JulienOuvrard JulienOuvrard commented Oct 5, 2017

Hi @dherges,

Thanks for the answer, i'll manage to avoid the usage of es7 features for the moment to get my library compiled. (I've already made changes to avoid includes and padStart)

I really don't know the state of that practice, i need to make further research on it.

Here's an hypothesis, can we include a tsconfig in custom libraries ? In that way, ng-packagr will use that configuration instead of the auto-configuration.

@dherges
Copy link
Member

@dherges dherges commented Oct 6, 2017

Quick look at angular: they still use lib: ["es2015", "dom"]

Here is where they track it:

https://github.com/angular/angular/blob/master/packages/es6-subset.d.ts#L3-L6

@dherges
Copy link
Member

@dherges dherges commented Oct 6, 2017

If wanted, the setting should be included in ng-package.json, e.g.:

{
  "lib": {
    "target": "es7" /** values: "es5", "es6", "es7" **/
    /** other possible names: "runtime", "environment", ... */
  }
}

And from there, we would write it to the generated tsconfig.json file and then (I think) the assumption about the target environment should be somewhere written in package.json (?)

@dherges dherges changed the title How can i add polyfills ? Develop libraries for specific runtimes (How can I add polyfills?) (es5, es6, es7, ...) Oct 6, 2017
@JulienOuvrard
Copy link
Author

@JulienOuvrard JulienOuvrard commented Oct 9, 2017

I think that would be nice to have this feature in future release of ng-packagr.
The idea of the assumption about the target environment written in package.json seems good to me considering that it describe the package.

@dherges dherges changed the title Develop libraries for specific runtimes (How can I add polyfills?) (es5, es6, es7, ...) Specify target runtime for a library (es5, es6, es7, ...) [PREV: How can I add polyfills?] Oct 10, 2017
@dherges dherges changed the title Specify target runtime for a library (es5, es6, es7, ...) [PREV: How can I add polyfills?] Develop libraries using a given runtime api (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] Oct 10, 2017
@dherges dherges changed the title Develop libraries using a given runtime api (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] Develop libraries using API of a given runtime api (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] Oct 10, 2017
@dherges dherges changed the title Develop libraries using API of a given runtime api (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] Develop libraries using API of a given runtime (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] Oct 10, 2017
@DavidParks8
Copy link
Member

@DavidParks8 DavidParks8 commented Oct 11, 2017

Why duplicate the lib config in ng-package.json and tsconfig.json? It should be possible to search for and read the developer's tsconfig.json dynamically to determine what libs should be included. This could be accompanied by a field to specify a custom tsconfig file such as:

{
  "tsconfig": "./../tsconfig.app.json"
}

It would also be nice to dynamically search .angular-cli.json for the tsconfig.

@dherges dherges changed the title Develop libraries using API of a given runtime (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] [PR WELCOME] Set language level for library sources (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] Dec 7, 2017
@fr0
Copy link

@fr0 fr0 commented Dec 14, 2017

What is the workaround for this? If there is no workaround, I can't use ng-packagr until it is implemented.

@dherges dherges changed the title [PR WELCOME] Set language level for library sources (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] [PR WELCOME] Set language level for library sources (es5, es6, es7, dom, webworker, ...) Dec 30, 2017
@dherges
Copy link
Member

@dherges dherges commented Jan 15, 2018

Closed by #486

@dherges dherges closed this Jan 15, 2018
@tommck
Copy link

@tommck tommck commented Mar 19, 2018

So, was there a reason I missed for not just pointing this to a tsconfig.json file?

@github-actions
Copy link

@github-actions github-actions bot commented Jun 19, 2020

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants