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

What is the best approach for publishing pure TypeScript libaries? #12398

Closed
atrauzzi opened this issue Nov 20, 2016 · 5 comments
Closed

What is the best approach for publishing pure TypeScript libaries? #12398

atrauzzi opened this issue Nov 20, 2016 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@atrauzzi
Copy link

I'm working on a library that depends on React, Redux and a handful of other usual suspects.

The thing about this library is that it's really not intended to be consumed by ES. It's just a handful of base classes and conventions that will be used by other TS projects.

This means it has no entrypoint. Almost like a class library in C#, etc...

What I'm basically aiming for is that the inclusion of this package will cause all the downstream dependencies to be pulled in - which I believe npm/yarn will take care of. Then I want the consuming project to reference my .ts and .tsx files, and then when it builds, that's when the files actually get compiled into what will invariably be entrypoints.

In my mind, the biggest challenge is just ensuring that somehow the modules can be referenced by other TS code. But as always, there could be more to this than what I'm immediately aware of ;)

@mhegazy
Copy link
Contributor

mhegazy commented Nov 21, 2016

related discussion can be found in to #12358.

Typically you would ship a library with a .js file(s) and a matching .d.ts file(s).

You should be able to ship a source-only library, where your users would need to "include" the sources. some of the issues you would have to address are:

  • how do your users include the files? do they copy them locally, then build them? or do you use a bundler like webpack to do this?
  • what happens if your users are using different build settings? would they get errors in your sources? how can they address these?
  • what happens when you library users publish their own libraries? what happens if some one wants to depend on two of these libraries, do they get two copies of your code?

@atrauzzi
Copy link
Author

The issue is that there's no JS to ship until they use it really. They're TypeScript classes in various modules, not a single module and should only be compiled when referenced.

Ideally I think they'd be using JSPM or WebPack, yeah. Or tsc actually. So long as their sources can path to mine I guess?

@mhegazy
Copy link
Contributor

mhegazy commented Nov 22, 2016

I do not think we have recommendation for this scenario specifically. potentially, your users can add a pre-build step that copies the sources from your files locally before passing them to tsc or webpack.

@atrauzzi
Copy link
Author

atrauzzi commented Nov 22, 2016

Would it be enough that they can be accessed from the node_modules folder?

@mhegazy
Copy link
Contributor

mhegazy commented Nov 22, 2016

I do not think i have any recommendations to share. i had a few possible issues raised in #12398 (comment). You might want to make sure that your workflow addresses these issues .

@DanielRosenwasser DanielRosenwasser added the Question An issue which isn't directly actionable in code label Nov 23, 2016
@mhegazy mhegazy closed this as completed Dec 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants