惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
GRAHAM CLULEY
S
Security @ Cisco Blogs
P
Proofpoint News Feed
Cisco Talos Blog
Cisco Talos Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
WordPress大学
WordPress大学
Project Zero
Project Zero
S
Schneier on Security
P
Proofpoint News Feed
小众软件
小众软件
P
Privacy International News Feed
美团技术团队
L
LangChain Blog
Know Your Adversary
Know Your Adversary
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
Engineering at Meta
Engineering at Meta
I
InfoQ
量子位
Vercel News
Vercel News
博客园 - 三生石上(FineUI控件)
Spread Privacy
Spread Privacy
D
DataBreaches.Net
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
U
Unit 42
P
Privacy & Cybersecurity Law Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
Latest news
Latest news
K
Kaspersky official blog
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
Simon Willison's Weblog
Simon Willison's Weblog
云风的 BLOG
云风的 BLOG
S
Securelist
AWS News Blog
AWS News Blog
F
Fortinet All Blogs
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
Scott Helme
Scott Helme
Help Net Security
Help Net Security
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Tenable Blog

Kent C. Dodds Blog

Implementing Hybrid Semantic + Lexical Search Simplifying Containers with Cloudflare Sandboxes Migrating to Workspaces and Nx Offloading FFmpeg with Cloudflare Building Semantic Search on my Content Helping YOU ask ME questions with AI How I used Cursor to Migrate Frameworks The Dow's Start on the Covenant Path 2025 in Review The next chapter: EpicAI.pro AI is taking your job How I increased my visibility Launching Epic Web 2023 in Review Stop Being a Junior RSC with Dan Abramov and Joe Savona Live Stream Fixing a Memory Leak in a Production Node.js App 2022 in Review My Car Accident I Migrated from a Postgres Cluster to Distributed SQLite with LiteFS I'm building EpicWeb.dev A review of my time at Remix Remix: The Yang to React's Yin How I help you build better websites Why I Love Remix The State Initializer Pattern How to React ⚛️ Get a catch block error message with TypeScript Building an awesome image loading experience How Remix makes CSS clashes predictable Introducing the new kentcdodds.com How I built a modern website in 2021 How to use React Context effectively Static vs Unit vs Integration vs E2E Testing for Frontend Apps The Testing Trophy and Testing Classifications Array reduce vs chaining vs for loop Don't Solve Problems, Eliminate Them Super Simple Start to Remix Super Simple Start to ESModules in Node.js JavaScript Pass By Value Function Parameters How to write a Constrained Identity Function (CIF) in TypeScript How to optimize your context value How to write a React Component in TypeScript TypeScript Function Syntaxes Listify a JavaScript Array Build vs Buy: Component Libraries edition Using fetch with TypeScript Wrapping React.useState with TypeScript Define function overload types with TypeScript 2020 in Review Business and Engineering alignment Hi, thanks for reaching out to me 👋 useEffect vs useLayoutEffect Super simple start to Firebase functions Super simple start to Netlify functions Super Simple Start to css variables Favor Progress Over Pride in Open Source Testing Implementation Details How getting into Open Source has been awesome for me useState lazy initialization and function updates Use ternaries rather than && in JSX Application State Management with React Use react-error-boundary to handle errors in React JavaScript to Know for React How I structure Express apps What open source project should I contribute to? When I follow TDD AHA Programming 💡 How I Record Educational Videos Should I write a test or fix a bug? Stop mocking fetch Intentional Career Building Improve test error messages of your abstractions Tracing user interactions with React Eliminate an entire category of bugs with a few simple tools Common mistakes with React Testing Library Super Simple Start to React Stop using client-side route redirects The State Reducer Pattern with React Hooks Function forms Replace axios with a simple custom fetch wrapper How to test custom React hooks React Production Performance Monitoring Should I useState or useReducer? Stop using isLoading booleans Make Your Test Fail Make your own DevTools An Argument for Automation Fix the "not wrapped in act(...)" warning Super Simple Start to ESModules in the Browser Implementing a simple state machine library in JavaScript 2010s Decade in Review Why users care about how you write code Why I avoid nesting closures Don't call a React function component Why your team needs TestingJavaScript.com Inversion of Control Understanding React's key prop How to Enable React Concurrent Mode Profile a React App for Performance
Why I don't commit generated files to master
2015-10-05 · via Kent C. Dodds Blog

This is an age old question and debate. There are pros and cons to both sides of the argument. In this post, I'll explain my experience committing generated (built) files to master for my libraries and why/how I don't do that anymore.

First, generated files?

In the context of a library, the generated files would be what the user of your library includes on their page with something like a script tag. So the concatenated, compiled, and minified version of your library files. For small libraries this may not be needed, but for multiple-file libraries that need to run in the browser of today which doesn't support ES6 modules yet, you're going to want to distribute a single file. This is what I mean when I say “generated files.”

So, why do it?

You might be tempted to commit built files to source for a few reasons:

  1. Bower needs them there (stop using bower)
  2. Makes it easier for people just downloading the files (not using npm or bower)
  3. Enables use of rawgit for examples in tools like jsbin or plunker

For a long time, these are the reasons that I committed my generated files for my libraries to my git repository. Everything worked out great! But I did have a few problems.

Problems…

These are some of the things that I just dealt with because I hadn't thought of a way to get those benefits without these issues. Until now.

Exploding git changes

ng-stats graph for collaborators

Looks like a huge boost of features right? Nope! that bump is when a build was added to ng-stats (there were a few other significant changes as well). The subsequent bumps are whenever a new version was released (and hence the build re-run and re-committed). This make's it difficult to get a good read of the activity of a project.

Terrible Git Diffs

A wall of git diffs

When developing the library, you have to make sure that you only commit the built files when doing a release (and not with other file changes), otherwise your git diffs are going to be a huge mess and it'll be hard to identify when and what changes entered in the codebase.

But even having this separation is frustrating at best because diffing two commits that are separated by a build will result in an impossible git diff as well. 😫

Contributions to dist

If you're writing an open source library, chances are you want to make it easy to contribute to and welcoming to new contributors. I have often received pullrequests that make changes to the generated files rather than the source files (or commit a run of the build script). Their contributions would be overwritten next time the build is run! Others will submit a PR that includes the updated dist (which ruins the diff for that commit as mentioned earlier).

For these kinds of contributions, I always have to (kindly) ask the contributor to resubmit the PR with a force push so that commit doesn't get into my history. This is not a very good experience for contributors 😿

If you want people to contribute to your library, you want to make it as straightforward as possible. In my experience, this is more easily accomplished when not committing the generated files.

My Solution

NOTE: This is no longer how I do things. I just rely on unpkg

So, how do we get the things we like about committing the generated files without these drawbacks? It's simple, only push the generated files to a special branch for releases. I call this branch “latest” and I've automated this with the package publish-latest.

Basically, you run your build, then run publish-latest which runs this scriptwhich will commit your built files and push them to your latest branch automatically. You can totally do this locally, but it actually works best when done with semantic-release and TravisCI (or some other CI service).

How do we still get the benefits?

  1. Bower -> tag the commit that publish-release makes (semantic-release does this for you)
  2. Downloading -> Look at the latest branch
  3. rawgit -> Point to the latest branch

How does this solve the problems?

  1. Exploding git changes -> Just ignore latest, focus on master (that's what github's contributing graph does as well).
  2. Terrible git diffs -> You never need a git diff on the latest branch. It's just as generated (useless to git) as the code.
  3. Contributions to dist -> Most people won't checkout the latest branch to contribute. I've never had that problem.

For an example of this actually working, you can see several of my projectsand other's that have already been moved over to this (including publish-latest itself).

Conclusion

There are a lot of tools to help you with the development of your open source libraries. If you're interested, I have a series on egghead.io that takes you from the very beginning to building out a great library. I recommend you give it a look: How to Write an Open Source JavaScript Library.

FAQ

  • Does this work with CDNJS? It appears to work just fine with angular-formly
  • What about storing the latest branch in an entirely different repository? This is actually not a bad idea, and with the url flag of publish-latest, you can totally do this.