Skip to content

Commit

Permalink
feat: set packageManager on app creation (t3-oss#1561)
Browse files Browse the repository at this point in the history
Co-authored-by: Julius Marminge <julius0216@outlook.com>
  • Loading branch information
Nsttt and juliusmarminge authored Sep 12, 2023
1 parent 747f408 commit 7225238
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

0 comments on commit 7225238

Please sign in to comment.