From b8507dc64ee91b8423de2ab6145cb3e7d8072528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor?= Date: Tue, 12 Sep 2023 10:19:53 +0200 Subject: [PATCH] feat: set packageManager on app creation (#1561) Co-authored-by: Julius Marminge --- .changeset/soft-moose-care.md | 5 +++++ cli/src/index.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/soft-moose-care.md diff --git a/.changeset/soft-moose-care.md b/.changeset/soft-moose-care.md new file mode 100644 index 0000000000..a485e915f7 --- /dev/null +++ b/.changeset/soft-moose-care.md @@ -0,0 +1,5 @@ +--- +"create-t3-app": patch +--- + +Add packageManager field in package.json at app creation diff --git a/cli/src/index.ts b/cli/src/index.ts index 651f3cdb30..f945b04e20 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -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"; @@ -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"; @@ -27,6 +29,7 @@ type CT3APackageJSON = PackageJson & { const main = async () => { const npmVersion = await getNpmVersion(); + const pkgManager = getUserPkgManager(); renderTitle(); npmVersion && renderVersionWarning(npmVersion); @@ -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, });