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

feat!: refactor to use execa & add git check working tree #27

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fratzinger
Copy link
Collaborator

@fratzinger fratzinger commented Sep 23, 2022

This is a hot take. Multiple things are going on.

Breaking:

context.pinion.exec runs https://github.com/sindresorhus/execa instead of child_process. I know it's another dependency, but it's sooo much nicer to use (Promises)!
The breaking change is: context.pinion.exec does not return Promise<number> anymore but Promise<ExecaChildProcess>. That we can access stdout easily, which is needed for a lot of operations (e.g. npm, git, yarn, npx npm-check-updates, you name it). Having that at your fingertips with context.pinion.exec is really nice! I think it's worth the breaking change.

Feat:

import { PinionContext, generator, confirmGitIsWorkingTreeClean } from '@feathershq/pinion'

export const generate = (context: Context) => generator(context)
  .then(confirmGitIsWorkingTreeClean())
  .then(/* whatever needs to be done */)

I consider this to be a core functionality. It checks if cwd is a git repository and if the working tree is clean. It shows a prompt to confirm, if the working tree is not clean.

Discussion:

I've added public utilities: utilExec, utilGitHasProjectGit. Imo they should be publicly available so developers can use them to get thing started easily. There are several problems with these utils, that are meant to be used in generators, but aren't generators:

  1. It get's confusing. What is a util, what is a generator operation?
  2. if exported globally the global @feathershq/pinion gets polluted very fast with every new util.
  3. The current naming convention utilExec and utilGitHasProjectGit help with 1. but not really with 2.. I think the best approach is to publish them under a separate folder or even package. Maybe this:
// In a separate folder:
import { exec } from '@feathershq/pinion/utils'
// would require a more complex build/compile step

// In a separate package (living in this mono-repo):
import { exec, hasProjectGit, isWorkingTreeClean } from '@feathershq/pinion-utils'

I think having a good set of common utils is a key factor to a fast adoption.

What do you think @daffl? Is @feathershq/pinion-utils the way to go? @pinion/utils would be nicer though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant