Skip to content
Closed
Show file tree
Hide file tree
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
28 changes: 24 additions & 4 deletions packages/create/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,34 @@ exports.run = async function run(options = {}) {
result.on("download", () =>
setLoadingMessage(spinner, "Downloading app...")
);
result.on("install", () =>
setLoadingMessage(spinner, "Installing npm modules...")
result.on("install", installer => {
// Stop the spinner so the package manager's own output is readable.
clearTimeout(spinner.timeout);
spinner.stopAndPersist({
symbol: chalk.cyan("→"),
text: `Installing dependencies with ${installer}...\n`
});
});
result.on("install-error", (_err, installer) =>
spinner.warn(
`\`${installer} install\` did not finish cleanly. Your project was still ` +
`created — you may need to install dependencies manually.\n`
)
);
result.on("init", () => setLoadingMessage(spinner, "Initializing repo..."));
const { projectPath, scripts: { start, dev } = {} } = await result;
result.on("init", () => {
spinner.start();
setLoadingMessage(spinner, "Initializing repo...");
});
const {
projectPath,
scripts: { start, dev } = {},
installer,
installed
} = await result;
spinner.succeed(
"Project created! To get started, run:\n\n" +
chalk.cyan(` cd ${path.relative(process.cwd(), projectPath)}\n`) +
(installed ? "" : chalk.cyan(` ${installer} install\n`)) +
(dev
? chalk.cyan(" npm run dev\n")
: start
Expand Down
7 changes: 5 additions & 2 deletions packages/create/src/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ const spawn = require("child_process").spawn;

module.exports = function exec(cwd, bin, args) {
return new Promise((resolve, reject) => {
spawn(bin, args, {
// Pass a single command string rather than (bin, args) with `shell: true`.
// Passing an args array together with `shell: true` triggers Node's DEP0190
// deprecation warning. bin/args are always internally controlled here.
spawn([bin, ...args].join(" "), {
cwd,
shell: true,
stdio: "ignore",
stdio: "inherit",
windowsHide: true
})
.once("error", reject)
Expand Down
17 changes: 13 additions & 4 deletions packages/create/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ async function create(options = {}, emitter) {

await downloadRepo(template, projectPath, options, emitter);
const { scripts } = await rewritePackageJson(projectPath, name);
await installPackages(installer, projectPath, emitter);
const installed = await installPackages(installer, projectPath, emitter);
await initGitRepo(projectPath, emitter);

return { projectPath, scripts };
return { projectPath, scripts, installer, installed };
}

exports.getExamples = async function () {
Expand Down Expand Up @@ -149,8 +149,17 @@ async function rewritePackageJson(fullPath, name) {
}

async function installPackages(installer, fullPath, emitter) {
emitter.emit("install");
await exec(fullPath, installer, ["install"]);
emitter.emit("install", installer);
try {
await exec(fullPath, installer, ["install"]);
return true;
} catch (err) {
// Don't fail the whole scaffold if dependency install exits non-zero.
// Some package managers (e.g. pnpm's ignored-build-scripts warning) exit
// non-zero even though the project is usable, so warn and keep going.
emitter.emit("install-error", err, installer);
return false;
}
}

function getExampleUrl(example, tag) {
Expand Down
Loading