Skip to content

Commit

Permalink
feat(create-remix): allow dots in nested folder names in GitHub repo …
Browse files Browse the repository at this point in the history
…shorthand (#7277)
  • Loading branch information
brophdawg11 authored Aug 29, 2023
1 parent bf042e7 commit d5e82be
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/create-remix-folder-names-dot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-remix": patch
---

Allow dots in github repo shorthand notation folder names (i.e., `npx create-remix --template remix-run/examples/socket.io`)
19 changes: 19 additions & 0 deletions packages/create-remix/__tests__/create-remix-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ describe("create-remix CLI", () => {
expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
});

it("works for GitHub username/repo/path combo (when dots exist in folder)", async () => {
let projectDir = getProjectDir("github-username-repo-path-dots");

let { status, stderr } = await execCreateRemix({
args: [
projectDir,
"--template",
"fake-remix-tester/nested-dir/folder.with.dots",
"--no-git-init",
"--no-install",
],
});

expect(stderr.trim()).toBeFalsy();
expect(status).toBe(0);
expect(fse.existsSync(path.join(projectDir, "package.json"))).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeTruthy();
});

it("fails for GitHub username/repo/path combo when path doesn't exist", async () => {
let projectDir = getProjectDir("github-username-repo-path-missing");

Expand Down
Binary file modified packages/create-remix/__tests__/fixtures/nested-dir-repo.tar.gz
Binary file not shown.
6 changes: 5 additions & 1 deletion packages/create-remix/copy-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,14 @@ function isValidGithubRepoUrl(
}

function isGithubRepoShorthand(value: string) {
if (isUrl(value)) {
return false;
}
// This supports :owner/:repo and :owner/:repo/nested/path, e.g.
// remix-run/remix
// remix-run/remix/templates/express
return /^[\w-]+\/[\w-]+(\/[\w-]+)*$/.test(value);
// remix-run/examples/socket.io
return /^[\w-]+\/[\w-]+(\/[\w-.]+)*$/.test(value);
}

function isGithubReleaseAssetUrl(url: string) {
Expand Down
4 changes: 3 additions & 1 deletion packages/create-remix/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ async function copyTempDirToAppDirStep(ctx: Context) {

let files1 = await getDirectoryFilesRecursive(ctx.tempDir);
let files2 = await getDirectoryFilesRecursive(ctx.cwd);
let collisions = files1.filter((f) => files2.includes(f));
let collisions = files1
.filter((f) => files2.includes(f))
.sort((a, b) => a.localeCompare(b));

if (collisions.length > 0) {
let getFileList = (prefix: string) => {
Expand Down

0 comments on commit d5e82be

Please sign in to comment.