Skip to content

Commit

Permalink
feat: set packageManager on app creation (#1561)
Browse files Browse the repository at this point in the history
Co-authored-by: Julius Marminge <[email protected]>
  • Loading branch information
Nsttt and juliusmarminge authored Sep 12, 2023
1 parent c27bf3c commit b8507dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-moose-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

Add packageManager field in package.json at app creation
12 changes: 12 additions & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import path from "path";
import { execa } from "execa";
import fs from "fs-extra";
import { type PackageJson } from "type-fest";

Expand All @@ -9,6 +10,7 @@ import { initializeGit } from "~/helpers/git.js";
import { logNextSteps } from "~/helpers/logNextSteps.js";
import { setImportAlias } from "~/helpers/setImportAlias.js";
import { buildPkgInstallerMap } from "~/installers/index.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";
import { renderTitle } from "~/utils/renderTitle.js";
Expand All @@ -27,6 +29,7 @@ type CT3APackageJSON = PackageJson & {

const main = async () => {
const npmVersion = await getNpmVersion();
const pkgManager = getUserPkgManager();
renderTitle();
npmVersion && renderVersionWarning(npmVersion);

Expand Down Expand Up @@ -55,6 +58,15 @@ const main = async () => {
) as CT3APackageJSON;
pkgJson.name = scopedAppName;
pkgJson.ct3aMetadata = { initVersion: getVersion() };

// ? Bun doesn't support this field (yet)
if (pkgManager !== "bun") {
const { stdout } = await execa(pkgManager, ["-v"], {
cwd: projectDir,
});
pkgJson.packageManager = `${pkgManager}@${stdout.trim()}`;
}

fs.writeJSONSync(path.join(projectDir, "package.json"), pkgJson, {
spaces: 2,
});
Expand Down

1 comment on commit b8507dc

@vercel
Copy link

@vercel vercel bot commented on b8507dc Sep 12, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

t3-upgrade – ./upgrade

t3-upgrade.vercel.app
t3-upgrade-git-next-t3-oss.vercel.app
t3-upgrade-t3-oss.vercel.app

Please sign in to comment.