Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use user customized npm registry in create-turbo #885

Merged
merged 7 commits into from
Mar 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions packages/create-turbo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import * as path from "path";
import execa from "execa";
import fs from "fs";
import fse from "fs-extra";
import inquirer from "inquirer";
import ora from "ora";
Expand All @@ -29,7 +28,7 @@ const help = `

If <dir> is not provided up front you will be prompted for it.

Flags:
Flags:
--use-npm Explicitly tell the CLI to bootstrap the app using npm
--use-pnpm Explicitly tell the CLI to bootstrap the app using pnpm
--no-install Explicitly do not run the package manager's install command
Expand Down Expand Up @@ -209,10 +208,18 @@ async function run() {
},
}).start();

await execa(`${answers.packageManager}`, [`install`], {
stdio: "ignore",
cwd: projectDir,
});
// Using the official npm registry in the installation could be very slow,
// So we use the user customized registry from default instead.
const npmRegistry = await getNpmRegistry(answers.packageManager);

await execa(
`${answers.packageManager}`,
[`install`, `--registry=${npmRegistry}`],
{
stdio: "ignore",
cwd: projectDir,
}
);
spinner.stop();
} else {
console.log();
Expand Down Expand Up @@ -278,6 +285,20 @@ async function run() {
console.log();
}

async function getNpmRegistry(pkgManager: PackageManager): Promise<string> {
try {
// npm/pnpm/yarn share the same CLI configuration commands
const { stdout: registry } = await execa(pkgManager, [
"config",
"get",
"registry",
]);
return registry;
} catch (error) {
return "";
}
}

const update = checkForUpdate(cliPkgJson).catch(() => null);

async function notifyUpdate(): Promise<void> {
Expand Down