diff --git a/packages/create-strapi-app/package.json b/packages/create-strapi-app/package.json index dc01c8bed8..2fdd380062 100644 --- a/packages/create-strapi-app/package.json +++ b/packages/create-strapi-app/package.json @@ -20,11 +20,11 @@ "index.js" ], "dependencies": { - "axios": "0.21.1", "chalk": "4.1.1", "commander": "6.1.0", "inquirer": "8.1.0", "js-yaml": "4.1.0", + "node-fetch": "^2.6.1", "strapi-generate-new": "3.6.3" }, "scripts": { diff --git a/packages/create-strapi-app/utils/prompt-user.js b/packages/create-strapi-app/utils/prompt-user.js index 821504543c..aed88ce252 100644 --- a/packages/create-strapi-app/utils/prompt-user.js +++ b/packages/create-strapi-app/utils/prompt-user.js @@ -1,7 +1,7 @@ 'use strict'; const inquirer = require('inquirer'); -const axios = require('axios'); +const fetch = require('node-fetch'); const yaml = require('js-yaml'); /** @@ -99,18 +99,16 @@ async function getPromptQuestions(projectName, template) { * @returns JSON template data */ async function getTemplateData() { - try { - const { - data: { content }, - } = await axios.get( - `https://api.github.com/repos/strapi/community-content/contents/templates/templates.yml` - ); - - const buff = Buffer.from(content, 'base64'); - const stringified = buff.toString('utf-8'); - - return yaml.load(stringified); - } catch (error) { + const response = await fetch( + `https://api.github.com/repos/strapi/community-content/contents/templates/templates.yml` + ); + if (!response.ok) { return null; } + + const { content } = await response.json(); + const buff = Buffer.from(content, 'base64'); + const stringified = buff.toString('utf-8'); + + return yaml.load(stringified); } diff --git a/packages/create-strapi-starter/package.json b/packages/create-strapi-starter/package.json index 252f3a159b..d0ab7e23eb 100644 --- a/packages/create-strapi-starter/package.json +++ b/packages/create-strapi-starter/package.json @@ -16,7 +16,6 @@ "create-strapi-starter": "./index.js" }, "dependencies": { - "axios": "0.21.1", "chalk": "4.1.1", "ci-info": "3.1.1", "commander": "7.1.0", @@ -25,6 +24,7 @@ "git-url-parse": "11.4.4", "inquirer": "8.1.0", "js-yaml": "4.1.0", + "node-fetch": "^2.6.1", "ora": "5.4.0", "strapi-generate-new": "3.6.3", "tar": "6.1.0" diff --git a/packages/create-strapi-starter/utils/fetch-github.js b/packages/create-strapi-starter/utils/fetch-github.js index 7cc39b98b4..4fb8e66f83 100644 --- a/packages/create-strapi-starter/utils/fetch-github.js +++ b/packages/create-strapi-starter/utils/fetch-github.js @@ -1,7 +1,7 @@ 'use strict'; const tar = require('tar'); -const axios = require('axios'); +const fetch = require('node-fetch'); const parseGitUrl = require('git-url-parse'); const chalk = require('chalk'); @@ -29,19 +29,18 @@ function parseShorthand(starter) { * @param {string} repo The full name of the repository. */ async function getDefaultBranch(repo) { - try { - const { - data: { default_branch }, - } = await axios.get(`https://api.github.com/repos/${repo}`); + const response = await fetch(`https://api.github.com/repos/${repo}`); - return default_branch; - } catch (error) { + if (!response.ok) { stopProcess( `Could not find the starter information for ${chalk.yellow( repo )}. Make sure it is publicly accessible on github.` ); } + + const { default_branch } = await response.json(); + return default_branch; } /** @@ -82,22 +81,17 @@ async function getRepoInfo(starter) { async function downloadGitHubRepo(repoInfo, tmpDir) { const { fullName, branch, usedShorthand } = repoInfo; - try { - // Download from GitHub - const codeload = `https://codeload.github.com/${fullName}/tar.gz/${branch}`; - const { data } = await axios({ - url: codeload, - method: 'GET', - responseType: 'stream', - }); + const codeload = `https://codeload.github.com/${fullName}/tar.gz/${branch}`; + const response = await fetch(codeload); - await new Promise(resolve => { - data.pipe(tar.extract({ strip: 1, cwd: tmpDir })).on('close', resolve); - }); - } catch (error) { + if (!response.ok) { const message = usedShorthand ? `using the shorthand` : `using the url`; stopProcess(`Could not download the repository ${message}: ${chalk.yellow(fullName)}.`); } + + await new Promise(resolve => { + response.body.pipe(tar.extract({ strip: 1, cwd: tmpDir })).on('close', resolve); + }); } module.exports = { getRepoInfo, downloadGitHubRepo }; diff --git a/packages/create-strapi-starter/utils/prompt-user.js b/packages/create-strapi-starter/utils/prompt-user.js index ff3af55ff8..f4c181cbe5 100644 --- a/packages/create-strapi-starter/utils/prompt-user.js +++ b/packages/create-strapi-starter/utils/prompt-user.js @@ -1,7 +1,7 @@ 'use strict'; const inquirer = require('inquirer'); -const axios = require('axios'); +const fetch = require('node-fetch'); const yaml = require('js-yaml'); /** @@ -87,17 +87,17 @@ async function getStarterQuestion() { * @returns JSON starter data */ async function getStarterData() { - try { - const { - data: { content }, - } = await axios.get( - `https://api.github.com/repos/strapi/community-content/contents/starters/starters.yml` - ); - const buff = Buffer.from(content, 'base64'); - const stringified = buff.toString('utf-8'); + const response = await fetch( + `https://api.github.com/repos/strapi/community-content/contents/starters/starters.yml` + ); - return yaml.load(stringified); - } catch (error) { + if (!response.ok) { return null; } + + const { content } = await response.json(); + const buff = Buffer.from(content, 'base64'); + const stringified = buff.toString('utf-8'); + + return yaml.load(stringified); } diff --git a/yarn.lock b/yarn.lock index f678bac1fe..2386ffcca7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4861,7 +4861,7 @@ axios-mock-adapter@^1.19.0: fast-deep-equal "^3.1.3" is-buffer "^2.0.3" -axios@0.21.1, axios@^0.21.1: +axios@^0.21.1: version "0.21.1" resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==