From 93ad75c49314b1455bd62f8ed25a49908df2838c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= Date: Wed, 27 Oct 2021 16:37:30 +0200 Subject: [PATCH] async execa shells --- .../generators/app/lib/utils/fetch-npm-template.js | 10 +++++----- packages/generators/app/lib/utils/merge-template.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/generators/app/lib/utils/fetch-npm-template.js b/packages/generators/app/lib/utils/fetch-npm-template.js index d670cb13c1..e2b987f2ba 100644 --- a/packages/generators/app/lib/utils/fetch-npm-template.js +++ b/packages/generators/app/lib/utils/fetch-npm-template.js @@ -9,8 +9,8 @@ const chalk = require('chalk'); * @param {string} packageName - Name to look up on npm, may include a specific version * @returns {Object} */ -function getPackageInfo(packageName) { - const { stdout } = execa.shellSync(`npm view ${packageName} name version --silent`); +async function getPackageInfo(packageName) { + const { stdout } = await execa.shell(`npm view ${packageName} name version --silent`); // Use regex to parse name and version from CLI result const [name, version] = stdout.match(/(?<=')(.*?)(?=')/gm); return { name, version }; @@ -24,7 +24,7 @@ async function getTemplatePackageInfo(template) { // Check if template is a shorthand try { const longhand = `@strapi/template-${template}`; - const packageInfo = getPackageInfo(longhand); + const packageInfo = await getPackageInfo(longhand); // Hasn't crashed so it is indeed a shorthand return packageInfo; } catch (error) { @@ -44,9 +44,9 @@ async function getTemplatePackageInfo(template) { * @param {string} packageInfo.version * @param {string} parentDir - Path inside of which we install the template. */ -function downloadNpmTemplate({ name, version }, parentDir) { +async function downloadNpmTemplate({ name, version }, parentDir) { // Download from npm - execa.shellSync(`npm install ${name}@${version} --no-save --silent`, { + await execa.shell(`npm install ${name}@${version} --no-save --silent`, { cwd: parentDir, }); diff --git a/packages/generators/app/lib/utils/merge-template.js b/packages/generators/app/lib/utils/merge-template.js index 954086997d..5e58ccf4ff 100644 --- a/packages/generators/app/lib/utils/merge-template.js +++ b/packages/generators/app/lib/utils/merge-template.js @@ -44,7 +44,7 @@ module.exports = async function mergeTemplate(scope, rootPath) { // Download template repository to a temporary directory templateParentPath = await fse.mkdtemp(path.join(os.tmpdir(), 'strapi-')); - templatePath = downloadNpmTemplate(templatePackageInfo, templateParentPath); + templatePath = await downloadNpmTemplate(templatePackageInfo, templateParentPath); } // Make sure the template is compatible with this version of strapi