Skip to content

Support external svelte module with component main entry (svelte key in package.json) #28

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

Closed
jasonlyu123 opened this issue Apr 11, 2020 · 6 comments
Labels
feature request New feature or request

Comments

@jasonlyu123
Copy link
Member

jasonlyu123 commented Apr 11, 2020

{
 "name": "@sveltech/routify",
 "version": "0.0.0-development",
 "description": "Routes for Svelte, automated by your filestructure",
 "main": "lib/index.js",
 "svelte": "runtime/index.js",

The svelte key is what is being resolved within Svelte apps, but code completion doesn't work, since VSCode uses the main key.

Could not find a declaration file for module '@sveltech/routify'. '... routify/lib/index.js' implicitly has an 'any' type.

Originally posted by @jakobrosenberg in #9 (comment)

As @jakobrosenberg point out. The svelte key in external module's package.json is a special custom main entry for svelte component source. See rollup-plugin-svelte for more info. This custom entry should be consider when resolving svelte module

@jasonlyu123 jasonlyu123 changed the title Support external svelte module with custom main(svelte key) Support external svelte module with component main entry(svelte key) Apr 11, 2020
@jasonlyu123 jasonlyu123 changed the title Support external svelte module with component main entry(svelte key) Support external svelte module with component main entry (svelte key in package.json) Apr 11, 2020
@jasonlyu123
Copy link
Member Author

jasonlyu123 commented Apr 13, 2020

Upon further study on how to implement, I actually not so sure if this is needed to be implement.
As this custom main field is used by bundler/ builder like webpack and rollup. But for the language-server, reading from source means it would have to recompile it every time, which is more inefficient. Also, as the doc of rollup-plugin-svelte said:

if you're publishing a component to npm, you should ship the uncompiled source (together with the compiled distributable, for people who aren't using Svelte elsewhere in their app) and include the "svelte" property in your package.json

It seems to means the field isn't intended to be required to build. It's like the more commonly used 'source' field but a svelte version. And typescript's module-resolving doesn't support custom entry too.

Maybe it could still be implemented but under some configuration with glob array to test for.

@btilford
Copy link

There really isn't a standard for source, module, types, or browser. Even main isn't super well-defined. Hopefully MS fixes it now that they have control of npm, GitHub, and Typescript.

I wish more projects did package up source it makes debugging and figuring out things so much better.

/rant

@dummdidumm dummdidumm added the feature request New feature or request label Apr 22, 2020
@swyxio
Copy link
Contributor

swyxio commented Jun 6, 2020

sounds like this is ok to close?

@jasonlyu123
Copy link
Member Author

Since it's much easier to manual type a component now there is not much need for this any more. I'll close this

@YogliB
Copy link

YogliB commented Aug 29, 2020

Since it's much easier to manual type a component now there is not much need for this any more. I'll close this

How can we manually type a component?

@dummdidumm
Copy link
Member

I assume you talk about providing types as a library author.

There is nothing official yet. For now the best way is to copy the contents of this class into your types and make all components extend that like

export class YourComponent extends Svelte2TsxComponent<{...props...}, {...events..}, {...slots...}> {}

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

No branches or pull requests

5 participants