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(create-remix): add --overwrite flag #7062

Merged
merged 17 commits into from
Aug 22, 2023
Merged

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Aug 4, 2023

We first implemented this as an --allow-non-empty flag.

We pivoted and removed the empty directory requirement and moved to a more granular file-by-file check. You are now free to write into a non-empty directory. If no collisions are detected between the template and your directory - then it'll run normally with no additional user input.

If collisions are detected, we prompt for confirmation to overwrite:

Screenshot 2023-08-17 at 4 45 06 PM

Users can skip the confirmation prompt with --overwrite.

Closes #6676

@changeset-bot
Copy link

changeset-bot bot commented Aug 4, 2023

🦋 Changeset detected

Latest commit: a310c86

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
create-remix Minor
remix Minor
@remix-run/architect Minor
@remix-run/cloudflare Minor
@remix-run/cloudflare-pages Minor
@remix-run/cloudflare-workers Minor
@remix-run/css-bundle Minor
@remix-run/deno Minor
@remix-run/dev Minor
@remix-run/eslint-config Minor
@remix-run/express Minor
@remix-run/node Minor
@remix-run/react Minor
@remix-run/serve Minor
@remix-run/server-runtime Minor
@remix-run/testing Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

markdalgleish
markdalgleish previously approved these changes Aug 7, 2023
Copy link
Member

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

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

I think --allow-non-empty is okay given your point that it doesn't necessarily overwrite anything.

Should we include a note about the --allow-non-empty flag in the non-empty directory error message? Otherwise I feel like devs won't know this flag exists in the scenario from the linked issue.

Looks good otherwise, so I'm happy to approve and leave it with you :)

@MichaelDeBoey MichaelDeBoey changed the title Add allow-non-empty flag to create-remix CLI feat(create-remix): add --allow-non-empty flag Aug 7, 2023
MichaelDeBoey
MichaelDeBoey previously approved these changes Aug 7, 2023
@brophdawg11
Copy link
Contributor Author

brophdawg11 commented Aug 8, 2023

Chatted with @mjackson and we're going to make this a bit more granular. We shouldn't care if the directory is empty, instead we should only care if we're actually going to overwrite stuff. I'm going to update this to:

  • No longer require an empty directory
  • Check for collisions with existing files, and if found, prompt: "Are you sure you wish to overwrite?"
  • Change the flag to --overwrite to disable the prompt above

@brophdawg11 brophdawg11 force-pushed the brophdawg11/allow-non-empty branch from 3048ccd to 7efa734 Compare August 17, 2023 20:41
@brophdawg11 brophdawg11 dismissed stale reviews from MichaelDeBoey and markdalgleish August 17, 2023 20:41

Dismissing review due to alternate approach

Comment on lines +48 to +49
copyTemplateToTempDirStep,
copyTempDirToAppDirStep,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to do the file level comparison, we now extract into a temp directory and then compare the temp dir to the destination dir.

@@ -204,51 +216,28 @@ async function introStep(ctx: Context) {
}

async function projectNameStep(ctx: Context) {
let cwdIsEmpty = ctx.cwd && isEmpty(ctx.cwd);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer care if it's empty

debug: ctx.debug,
token: ctx.token,
async onError(err) {
let cwd = process.cwd();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to do this cleanup anymore - it's extracting into a temp dir which the OS should cleanup automatically.


await fse.copy(ctx.tempDir, ctx.cwd);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the population of the app directory now

Comment on lines 273 to 276
// Ignore comparing within these directories - but detect a collision
// at the directory level and count it. These get prepended to strippedFiles
// in reverse order below
let ignoreDirs = ["node_modules", ".git"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't check file-by-file inside .git/node_modules but we treat them as collisions regardless. There's a part of me that wants to add a hard stop on ever allowing an overwrite of .git/ though...Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree with this sentiment, overwriting .git feels pretty much guaranteed to be a mistake.

Rather than being an error, maybe we should just never copy the .git directory if it exists in a template? Especially since it's not possible to have one when the template is a GitHub repo, which is the primary mechanism for sharing a template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooh, yeah I like that even better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brophdawg11 brophdawg11 changed the title feat(create-remix): add --allow-non-empty flag feat(create-remix): add --overwrite flag Aug 17, 2023
@brophdawg11 brophdawg11 force-pushed the brophdawg11/allow-non-empty branch 6 times, most recently from 600a43a to a722933 Compare August 18, 2023 20:37
@brophdawg11 brophdawg11 force-pushed the brophdawg11/allow-non-empty branch from a722933 to 8e0180a Compare August 18, 2023 20:51
expect(fse.existsSync(path.join(emptyDir, "app/root.tsx"))).toBeTruthy();
});

it("does not copy .git nor node_modules directories if they exist in the template", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markdalgleish I decided to treat both .git and node_modules the same and not copy either of them from the template directory. We probably shouldn't promote bloated templates with committed node_modules that we have to download.

Comment on lines +307 to +309
if (result?.localTemplateDirectory) {
ctx.tempDir = path.resolve(result.localTemplateDirectory);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the optimization that if the template is a local directory on disk we just copy from there instead of "extracting" it to a temp dir.

@brophdawg11 brophdawg11 merged commit 23544d3 into dev Aug 22, 2023
@brophdawg11 brophdawg11 deleted the brophdawg11/allow-non-empty branch August 22, 2023 17:33
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Aug 22, 2023
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-49e8da1-20230823 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version 2.0.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed package:create-remix
Projects
No open projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

3 participants