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

Use .shopify/.gitignore instead of appending to .gitignore #5475

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sambostock
Copy link

WHY are these changes introduced?

We should avoid "dirtying" the host application's .gitignore.

WHAT is this pull request doing?

Instead of writing to the host application's .gitignore to hide the .shopify directory, we can write a .gitignore in the directory itself, which makes the directory self-ignoring.

How to test your changes?

Test coverage should be good enough, but you could use the previous version of the CLI to perform a task which writes to .gitignore, and inspect that it wrote to it, then repeat that task using this branch and ensure the .shopify directory and its contents remain ignored even if .gitignore doesn't contain .shopify.

Post-release steps

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Instead of writing to the host application's `.gitignore` to hide the
`.shopify` directory, we can write a `.gitignore` in the directory
itself, which makes the directory self-ignoring.
Copy link
Contributor

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/public/node/hiddenFolder.d.ts
/**
 * Creates a git ignored hidden .shopify folder in the given app directory, and pass its path to the given callback.
 *
 * @param appDirectory - The directory of the app.
 * @param callback - A callback that receives the path to the hidden folder.
 * @returns The value returned by the callback function.
 */
export declare function withHiddenShopifyFolderIn<T>(appDirectory: string, callback: (hiddenFolder: string) => T): T;
/**
 * Calls the given callback with the path to the config file in the hidden .shopify folder,
 * ensuring the hidden folder is set up first.
 *
 * @param appDirectory - The directory of the app.
 * @param callback - A callback that receives the path to the hidden config file.
 * @returns The value returned by the callback function.
 */
export declare function withHiddenConfigPathIn<T>(appDirectory: string, callback: (hiddenConfigPath: string) => T): T;

Existing type declarations

packages/cli-kit/dist/public/node/git.d.ts
@@ -35,6 +35,8 @@ export declare function createGitIgnore(directory: string, template: GitIgnoreTe
  *
  * @param root - The directory containing the .gitignore file.
  * @param entry - The entry to add to the .gitignore file.
+ *
+ * @deprecated We should not edit the user's existing gitignore.
  */
 export declare function addToGitIgnore(root: string, entry: string): void;
 /**

Copy link
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
75.97% (+0.01% 🔼)
9187/12093
🟡 Branches
71.11% (-0.02% 🔻)
4493/6318
🟡 Functions
75.55% (+0.03% 🔼)
2398/3174
🟡 Lines
76.54% (+0.01% 🔼)
8678/11338
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / hiddenFolder.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / app.ts
87.43% (-0.07% 🔻)
71.43% 92.98%
90.14% (-0.07% 🔻)
🟢
... / app-event-watcher.ts
96.39% (-1.2% 🔻)
88.57% (-2.86% 🔻)
95.45% 100%
🟢
... / ConcurrentOutput.tsx
98.36% (-1.64% 🔻)
88% (-4% 🔻)
100%
98.33% (-1.67% 🔻)

Test suite run success

2086 tests passing in 927 suites.

Report generated by 🧪jest coverage report action from b63fb66

Comment on lines +16 to +17
mkdirSync(hiddenFolder, {recursive: true})
writeFileSync(joinPath(hiddenFolder, '.gitignore'), `# Ignore the entire ${HIDDEN_FOLDER_NAME} directory\n*`)
Copy link
Contributor

Choose a reason for hiding this comment

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

We call mkdir and writeFile everytime? is that cheaper than checking for existance of the file?

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.

2 participants