isaacs / tshy

Other
886 stars 18 forks source link

enable discussions for dumb questions like this #51

Closed boneskull closed 7 months ago

boneskull commented 8 months ago

I added selfLink: false to my tshy config because I saw node_modules in my dist folder and started to worry it'd be published. But--just now--I realized that npm probably would avoid packing that folder unless explicitly instructed to (is that right?).

...but I'm still fuzzy on what selfLink: false implies. What's a local package export? The top search result for this phrase is this site.

svallory commented 8 months ago

A local package export is an export from the package you are building. Some people avoid using relative imports by doing import X from "my_package" where my_package is the package you are building.

Node will look for that export in the exports field of your package.json, but since tshy manages the exports for you after the build is done, the temporary package.json it generates to compile your project will not contain it.

The work around is then to symlink your package to a node_modules inside src for compilation and inside dist to support tests that load code from dist instead of src

It will not automatically be published as npm will expect that installing your package will re-create the node_modules with all the required dependencies.

At the very end of the readme there's a Local Package Exports section with a tl;dr with more details if you want to read more.

@isaacs I also found the term "local" confusing at first. Maybe it is better to call it "current package exports" or "Importing package.json exports" ? I don't know 🤷🏻‍♂️

boneskull commented 8 months ago

Isn't that what subpath imports are for?

Anyway...

I think this might be easier to pick up on if that TL;DR a) was first and b) was not collapsed by default.

I do wonder how prevalent this setup is, and if selfLink: false should actually be the default behavior? Given selfLink: true is the default behavior, maybe @isaacs uses this himself elsewhere; if so, it'd be helpful to see an example of where & how it's helping.

isaacs commented 7 months ago

I think technically the tl;dr isn't the bit that's collapsed, the tl;dr is the bit you see, and the longer explanation is the bit that's collapsed.

I've seen them referred to as "local package exports" in discussions, but the node docs calls it "self-referencing a package by its name".