Skip to content

Commit

Permalink
default to npm (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Mar 4, 2024
1 parent 505afec commit 27c5d2a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function create(options = {}, effects: CreateEffects = defaultEffec
{value: "yarn", label: "Yes, via yarn", hint: "recommended"},
{value: null, label: "No"}
],
initialValue: inferPackageManager()
initialValue: inferPackageManager("npm")
}),
initializeGit: () =>
clack.confirm({
Expand Down Expand Up @@ -205,12 +205,12 @@ async function recursiveCopyTemplate(
}
}

function inferPackageManager(): string | null {
function inferPackageManager(defaultValue: string | null): string | null {
const userAgent = process.env["npm_config_user_agent"];
if (!userAgent) return null;
if (!userAgent) return defaultValue;
const pkgSpec = userAgent.split(" ")[0]!; // userAgent is non-empty, so this is always defined
if (!pkgSpec) return null;
if (!pkgSpec) return defaultValue;
const [name, version] = pkgSpec.split("/");
if (!name || !version) return null;
if (!name || !version) return defaultValue;
return name;
}

0 comments on commit 27c5d2a

Please sign in to comment.