-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
🦋 Changeset detectedLatest commit: a310c86 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
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 |
There was a problem hiding this 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 :)
--allow-non-empty
flag
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:
|
3048ccd
to
7efa734
Compare
Dismissing review due to alternate approach
copyTemplateToTempDirStep, | ||
copyTempDirToAppDirStep, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
packages/create-remix/index.ts
Outdated
|
||
await fse.copy(ctx.tempDir, ctx.cwd); |
There was a problem hiding this comment.
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
packages/create-remix/utils.ts
Outdated
// 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"]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--allow-non-empty
flag--overwrite
flag
Co-authored-by: Mark Dalgleish <[email protected]>
600a43a
to
a722933
Compare
a722933
to
8e0180a
Compare
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 () => { |
There was a problem hiding this comment.
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.
if (result?.localTemplateDirectory) { | ||
ctx.tempDir = path.resolve(result.localTemplateDirectory); | ||
} |
There was a problem hiding this comment.
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.
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
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:
Users can skip the confirmation prompt with
--overwrite
.Closes #6676