Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat(learn): add article for publishing a typescript package #7279
base: main
Are you sure you want to change the base?
feat(learn): add article for publishing a typescript package #7279
Changes from 4 commits
b20dcbf
2d5d359
86394b6
d583e03
48e2ad9
081b7f2
2a20202
52d3a13
2228ab3
5034918
ddb1cf1
9258389
4906609
07095c6
33e744a
f1703ad
3fd8076
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sort of questioning linking to this page; reading it, it's pretty out of date and is part of the declaration file section, so sort of misses out on other important stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a note: types do not sobstitute unit testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just avoid mentioning "treat types like tests" in the first place? I don't really see how it weaves into the blog post (even in this section)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should treat types as a part of code quality checking. Like lintting and formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a note: types do not sobstitute unit testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted this in the other thread, but I would be cautious about this as a default; I really only see people setting noEmit when they're doing a quick check, or are using a bundler or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the type "test" command. Why would you want to emit a compilation?
Maybe the names could be better? When I have unit and end-to-end tests with different setups, I split those into different commands like:
test:unit
test:e2e
So in that scenario, it could make sense to name
types:check
→test:types
.But in the sample, there's no differentiation between units and e2e, so then what do I call what is currently
test
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, I guess it's fine, I am just wary of cases where
tsc
andtsc --noEmit
output different errors because the former is doing more. Maybe you'd hit it onprepack
and that's okay, but it's a little unfortunate to only hit an error when you go to release...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that likely? I've been doing this for years and never encountered that—am I just very lucky?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to gauge "likely", probably unlikely, but they're cases like "tsc failed to write the files", along with potentially some declaration transform errors. (The latter shouldn't actually end up mattering by my reading of the code, though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specific issues that come up that I can think of are when a declaration file can't reliably be generated because doing so might require referencing entities that are private or non-exported. Trying to figure out why this error is happening can be pretty frustrating, especially if you've been relying a specific pattern over time. Having a divergence between publish/CI probably just makes this even more confusing since most people outside of the person who set up the build won't be aware of any differences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does sound like an issue that you legitimately wouldn't catch with a dry-run, but also seems a very unlikely issue (and one that could still occur at publishing even if you were using non-dry-run for the test step). It seems an edge-case worth noting but not worth taking a hit every time to avoid something that likely will never happen (if it does, there are a very limited number of causes—two? permissions and storage availability).
That sounds very detectable for
--noEmit
; if it doesn't do that, that sounds like a defect intsc
? Why would you need to writing to disk in order to discover it?But maybe let's take a step back for a second: The reason I wrote the setup this way is because of performance—but perhaps my information is outdated. Last I heard,
tsc --noEmit
was significantly faster than with emit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as of recent releases (since
--isolatedDeclarations
), we've actually always checked declaration errors without emit, so I think the only errors one can see differently are just the errors that happen while writing, which may not really be important except in the case where you've somehow accidentally marked output paths as readonly in the FS or something.It can be, though I think at the scale of this demo, it's definitely not a big difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the default, but we generally recommend setting
outDir
to something else. ("rootDir": "src", "outDir": "dist"
is common.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was also about to comment that when I noticed the flat layout above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for that recommendation?
"outDir": "dist"
will cause that folder to get created and published though, whereas I want it to be in just the root to avoid unnecessary drilling.So I think I want neither
"rootDir": "src"
nor"outDir": "dist"
, because that will double what I want to avoid.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it at least implies that any large project is just going to dump a load of files at the root, which are going to be very annoying to
gitignore
/npmignore
/eslitignore
/prettierignore
/etc, and visually ignore in the repo. If you output todist
, they're all in one place, easy to ignore, and notably, less likely to be accidentally loaded by TS or something.I haven't personally seen a project which used a
src
and then dumped files at the root, onlysrc
->dist
, or, nooutDir
and allow the emitted JS to live next to the TS.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also makes it easier to throw away all the files for a clean build. With package.json
exports
, it feels like there really isn't much reason to publish at the root anymore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you say what those issues are? The only thing I can think of is compat with old node releases that do not support exports, or trying to support people who want to deep import when the package author does not want that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it preserves structure, but that feels beside the point. But by and large, the recommendation we've had (and really the de facto norm at this point) is to use a dedicated output directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maaybe there's a misunderstanding: these would not be run one right after the other:
tsc --noEmit
would run.tsc
would run.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that, I'm just saying that the two may behave differently as there are errors that can only happen when
tsc
is emitting, and you would never see them untiltsc
is run without--noEmit
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me just say that a release-blocker because of
.d.ts
emit problems is better caught as early as possible, and the delta in CI time is not worth it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can propose to just use release not tag. In some case tag is useful for example when you have monorepo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? Package releases should always have a git tag, no exceptions - single-package repos too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm sugest to use release
https://docs.npmjs.com/generating-provenance-statements#example-github-actions-workflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely think a release should have a tag, but I think different points are being argued here: It's not saying a release shouldn't have a tag, but is instead saying make this relative to the release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh i see, i was confused. yeah i think it's fine to trigger on release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW you cannot create a GitHub release without pointing it at a tag; the UI will force you to either select one or make one, so a tag will definitely have existed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to what @andrewbranch and @jakebailey said above, if you specify an
--outDir
, then you can use thepackage.json
"files"
array to avoid other hazards.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
.npmignore
, which avoids hazards endemic tofiles
:-)