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
JulienOuvrard opened this Issue Oct 5, 2017 · 9 comments

Comments

5 participants
@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

This comment has been minimized.

Show comment
Hide comment
@dherges

dherges Oct 5, 2017

Collaborator

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"

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@JulienOuvrard

JulienOuvrard 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.

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

This comment has been minimized.

Show comment
Hide comment
@dherges

dherges Oct 6, 2017

Collaborator

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

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@dherges

dherges Oct 6, 2017

Collaborator

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 (?)

Collaborator

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 from How can i add polyfills ? to Develop libraries for specific runtimes (How can I add polyfills?) (es5, es6, es7, ...) Oct 6, 2017

@JulienOuvrard

This comment has been minimized.

Show comment
Hide comment
@JulienOuvrard

JulienOuvrard 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.

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 from Develop libraries for specific runtimes (How can I add polyfills?) (es5, es6, es7, ...) to Specify target runtime for a library (es5, es6, es7, ...) [PREV: How can I add polyfills?] Oct 10, 2017

@dherges dherges changed the title from Specify target runtime for a library (es5, es6, es7, ...) [PREV: How can I add polyfills?] to 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 from Develop libraries using a given runtime api (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] to 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 from Develop libraries using API of a given runtime api (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] to Develop libraries using API of a given runtime (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] Oct 10, 2017

@DavidParks8

This comment has been minimized.

Show comment
Hide comment
@DavidParks8

DavidParks8 Oct 11, 2017

Contributor

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.

Contributor

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.

@DavidParks8 DavidParks8 referenced this issue Nov 30, 2017

Closed

feat: add ability to override tsconfig #334

2 of 2 tasks complete

@dherges dherges added the need help label Dec 7, 2017

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

@fr0

This comment has been minimized.

Show comment
Hide comment
@fr0

fr0 Dec 14, 2017

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

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 from [PR WELCOME] Set language level for library sources (es5, es6, es7, dom, webworker, ...) [PREV: How can I add polyfills?] to [PR WELCOME] Set language level for library sources (es5, es6, es7, dom, webworker, ...) Dec 30, 2017

@dherges

This comment has been minimized.

Show comment
Hide comment
@dherges

dherges Jan 15, 2018

Collaborator

Closed by #486

Collaborator

dherges commented Jan 15, 2018

Closed by #486

@dherges dherges closed this Jan 15, 2018

@tommck

This comment has been minimized.

Show comment
Hide comment
@tommck

tommck Mar 19, 2018

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

tommck commented Mar 19, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment