Skip to content

Commit 4832ad9

Browse files
authored
feat(create-react-router): add Deno support (#12327)
* Add Deno as a supported package manager in create-react-router * Update contributors.yml
1 parent 9022200 commit 4832ad9

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

.changeset/blue-owls-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-react-router": minor
3+
---
4+
5+
Add Deno as a supported and detectable package manager. Note that this detection will only work with Deno versions 2.0.5 and above. If you are using an older version version of Deno then you must specify the --package-manager CLI flag set to `deno`.

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
- pruszel
293293
- pwdcd
294294
- pyitphyoaung
295+
- redabacha
295296
- refusado
296297
- renyu-io
297298
- reyronald

packages/create-react-router/__tests__/create-react-router-test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,39 @@ describe("create-react-router CLI", () => {
697697
process.env.npm_config_user_agent = originalUserAgent;
698698
});
699699

700+
it("recognizes when Deno was used to run the command", async () => {
701+
let originalUserAgent = process.env.npm_config_user_agent;
702+
process.env.npm_config_user_agent =
703+
"deno/2.0.6 npm/? deno/2.0.6 linux x86_64";
704+
705+
let projectDir = getProjectDir("deno-create-from-user-agent");
706+
707+
let execa = require("execa");
708+
execa.mockImplementation(async () => {});
709+
710+
// Suppress terminal output
711+
let stdoutMock = jest
712+
.spyOn(process.stdout, "write")
713+
.mockImplementation(() => true);
714+
715+
await createReactRouter([
716+
projectDir,
717+
"--template",
718+
path.join(__dirname, "fixtures", "blank"),
719+
"--no-git-init",
720+
"--yes",
721+
]);
722+
723+
stdoutMock.mockReset();
724+
725+
expect(execa).toHaveBeenCalledWith(
726+
"deno",
727+
expect.arrayContaining(["install"]),
728+
expect.anything()
729+
);
730+
process.env.npm_config_user_agent = originalUserAgent;
731+
});
732+
700733
it("supports specifying the package manager, regardless of user agent", async () => {
701734
let originalUserAgent = process.env.npm_config_user_agent;
702735
process.env.npm_config_user_agent =

packages/create-react-router/index.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async function getContext(argv: string[]): Promise<Context> {
151151
noMotion,
152152
pkgManager: validatePackageManager(
153153
pkgManager ??
154-
// npm, pnpm, Yarn, and Bun set the user agent environment variable that can be used
154+
// npm, pnpm, Yarn, Bun and Deno (v2.0.5+) set the user agent environment variable that can be used
155155
// to determine which package manager ran the command.
156156
(process.env.npm_config_user_agent ?? "npm").split("/")[0]
157157
),
@@ -514,19 +514,11 @@ async function doneStep(ctx: Context) {
514514
await sleep(200);
515515
}
516516

517-
type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
518-
519-
const packageManagerExecScript: Record<PackageManager, string> = {
520-
npm: "npx",
521-
yarn: "yarn",
522-
pnpm: "pnpm exec",
523-
bun: "bunx",
524-
};
517+
const validPackageManagers = ["npm", "yarn", "pnpm", "bun", "deno"] as const;
518+
type PackageManager = (typeof validPackageManagers)[number];
525519

526520
function validatePackageManager(pkgManager: string): PackageManager {
527-
return packageManagerExecScript.hasOwnProperty(pkgManager)
528-
? (pkgManager as PackageManager)
529-
: "npm";
521+
return validPackageManagers.find((name) => pkgManager === name) ?? "npm";
530522
}
531523

532524
async function installDependencies({

0 commit comments

Comments
 (0)