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

Remove dependency on current-git-branch #335

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-monkeys-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Remove dependency on `current-git-branch` package
15 changes: 13 additions & 2 deletions lib/provideDefaultConfig.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
const readPackage = require('read-pkg-up');
const currentGitBranch = require('current-git-branch');
const { execSync } = require('child_process');

/**
* @returns {string | null} The current git branch name, or null if no branch is found
*/
const getGitBranch = () => {
try {
return execSync('git branch --show-current').toString().trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've previously been burnt by OS differences when running raw child_process commands.

Is this something we should worry about?

I believe current-git-branch was using execa which builds in some "Make work on Windows" stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of the stuff execa (via cross-spawn) solves as far as Windows is concerned is irrelevant for this very simple command. I've just tested this on my Windows machine in both Cmd and PowerShell, and it worked fine.

} catch (e) {
return null;
}
};

const generateStorageKey = () => {
const pkg = readPackage.sync();
const packageName = (pkg && pkg.packageJson && pkg.packageJson.name) || null;
const branchName = currentGitBranch();
const branchName = getGitBranch();

const packageLabel = packageName ? `package:${packageName}` : null;
const branchLabel = branchName ? `branch:${branchName}` : null;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"command-line-usage": "^6.1.3",
"copy-to-clipboard": "^3.3.3",
"css-loader": "^6.7.2",
"current-git-branch": "^1.1.0",
"dedent": "^1.5.1",
"fast-glob": "^3.2.12",
"find-up": "^5.0.0",
Expand Down
74 changes: 7 additions & 67 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.