ionic-team / stencil

A toolchain for building scalable, enterprise-ready component systems on top of TypeScript and Web Component standards. Stencil components can be distributed natively to React, Angular, Vue, and traditional web developers from a single, framework-agnostic codebase.
https://stenciljs.com
Other
12.56k stars 787 forks source link

d.ts file is always generated as "components.d.ts" instead of given name in package.json #386

Closed marinho closed 6 years ago

marinho commented 6 years ago

Stencil version:

 @stencil/core@0.1.0

I'm submitting a:

Current behavior:

Documentation in https://stenciljs.com/docs/distribution mentions that in order to distribute a components library, one should add a types entry to package.json, which in given example is "dist/collection/index.d.ts".

That is actually not working as expected as different values are provided to types, as you can see below:

When "types" = "dist/types/components.d.ts"

dist/types/components.d.ts is generated aside with folder dist/types/components which results not being possible to triple comment reference to other d.ts files inside that folder (look at [3]).

As dist/types/components.d.ts encapsulates all interfaces and types, I can only use HTML{MyComponentHere}Element from global declarations.

When "types" = "dist/types/index.d.ts"

No warning or error appears, but dist/types/components.d.ts is still generated instead of dist/types/index.d.ts.

When "types" = "dist/types/foo.d.ts"

[ ERROR ]  package.json error
    package.json "types" property is required when generating a distribution. Recommended entry d.ts file is:
    dist/types/components.d.ts

Expected behavior:

Steps to reproduce:

Just try the different values I mentioned above.

Related code:

Guess there's no need.

Other information:

[1] That was partially fixed in https://github.com/ionic-team/stencil/commit/5083ff14 [2] I can file a PR as contribution if this is accepted. I haven't done it, as I don't know if there's a policy or approval to follow before. [3] I couldn't find confirmation about components.d.ts encapsulating folder components from the same folder, but that was the behaviour I got when tried it myself.

marinho commented 6 years ago

After a chat with @adamdbradley in Slack, one important clarification made clear I was misunderstanding types key in package.json all the time.

I was thinking it was used to generate the entry d.ts file of src and so dist/types too.

I was very wrong. types is just used to point to which file in dist/types should be taken by external apps. dist/types/components.d.ts is just a copy of src/components.d.ts, and so, by writing my own src/index.d.ts, I could easily solve the issues I was facing.

In my opinion, that means this issue should be just about showing a warning instead of an error when types is a value other than index.d.ts or components.d.ts. But I wouldn't see it as a priority, as it's a good practice to stay with one of both instead of foo.d.ts.

marinho commented 6 years ago

Additionally: I think we need something about that in https://stenciljs.com/docs/distribution, as it's not documented at all.

jthoms1 commented 6 years ago

@marinho I agree that this is something that we need to document better. I have changed the tags on this to better represent what we need to do to resolve this.

jgw96 commented 6 years ago

After discussing this with @jthoms1 and looking at the code we decided the actual issue here is that the index.d.ts file that was in the src folder of the component starter was actually not needed and misleading, which caused the confusion above. I have removed that file from the component starter and am going to close this issue for now. Thanks for using Stencil!