Why are there .js and .d.ts files in source control? #48
-
@conartist6 (I don't see you in https://github.com/iter-tools/regex/watchers so I'm pinging you with a friendly notification 📬) I was browsing through the source code in GitHub.dev https://github.dev/iter-tools/regex and wondered "why is there a .ts with the same code in .js and .d.ts right next to it?" It seemed to defy all logic... But then I looked at the build process: {
"scripts": {
"build": "macrome build",
// ...
}
} So then I looked at the https://github.com/macrome-js/macrome#readme GitHub repo (I couldn't find it on https://npms.io/search?q=macrome ?) and figured out that this was intentional:
This makes sense! You want to be able to no-build import from GitHub with npm! But then I got to thinking... Doesn't npm have a way to hook into the package installation only when installed from a Git repo to build your project? Right? https://blog.jim-nielsen.com/2018/installing-and-building-an-npm-package-from-github/
I'm not trying to be confrontational even though I know I'm basically pointing out "all the ways you're wrong" which is a really great way to turn the human brain into rationalizing defense mode. I genuinely want to understand the reasons. If there is a benefit, I might adopt this in-source .ts+.js+.d.ts in my own projects! You want it to be easy to use forks in-place in npm package.json without publishing to npm Here's another resource: https://docs.npmjs.com/cli/v9/using-npm/scripts. This one mentions prepack instead of prepare which may be more of what you're after.
TL;DR: Why commit .js build artifacts to Git source control when you can build them using npm's prepack/prepare hook script? {
"scripts": {
// Either delegate to npm run build, or just make 'npm pack' your build command!
"prepack": "npm run build",
"prepack": "vite build",
"prepack": "tsc",
"prepack": "next build",
"prepack": "rollup -c",
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I agree that it is possible to do the same thing with prepack, but my intent was not to be practical but explore what is possible when you make different ways of working possible. My observation is that people assume that things which are not yet possible or are difficult using current tools must not be worth exploring. Many of my explorations are centered around the idea of achieving ecosystems with much greater decentralization than those we have now. The problem I see is that if everyone embraced building with prepack and consuming with git, the result would be a giant mess. Without having necessarily made any mistake you might end up with 18 versions of typescript in |
Beta Was this translation helpful? Give feedback.
I agree that it is possible to do the same thing with prepack, but my intent was not to be practical but explore what is possible when you make different ways of working possible. My observation is that people assume that things which are not yet possible or are difficult using current tools must not be worth exploring.
Many of my explorations are centered around the idea of achieving ecosystems with much greater decentralization than those we have now. The problem I see is that if everyone embraced building with prepack and consuming with git, the result would be a giant mess. Without having necessarily made any mistake you might end up with 18 versions of typescript in
node_modules
. You…