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(gatsby-cli): Remove one of package-lock.json and yarn.lock on gatsby new #13225

Merged
2 changes: 2 additions & 0 deletions packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@babel/runtime": "^7.0.0",
"bluebird": "^3.5.0",
"common-tags": "^1.4.0",
"configstore": "^4.0.0",
"convert-hrtime": "^2.0.0",
"core-js": "^2.5.0",
"envinfo": "^5.8.1",
Expand All @@ -27,6 +28,7 @@
"node-fetch": "2.3.0",
"opentracing": "^0.14.3",
"pretty-error": "^2.1.1",
"prompts": "^2.0.4",
"resolve-cwd": "^2.0.0",
"source-map": "^0.5.7",
"stack-trace": "^0.0.10",
Expand Down
30 changes: 28 additions & 2 deletions packages/gatsby-cli/src/init-starter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */
const { execSync } = require(`child_process`)
const Configstore = require(`configstore`)
const execa = require(`execa`)
const hostedGitInfo = require(`hosted-git-info`)
const fs = require(`fs-extra`)
Expand All @@ -8,11 +9,14 @@ const report = require(`./reporter`)
const url = require(`url`)
const existsSync = require(`fs-exists-cached`).sync
const { trackCli, trackError } = require(`gatsby-telemetry`)
const prompts = require(`prompts`)
const spawn = (cmd: string, options: any) => {
const [file, ...args] = cmd.split(/\s+/)
return execa(file, args, { stdio: `inherit`, ...options })
}

const conf = new Configstore(`gatsby`, {}, { globalConfigPath: true })
frinyvonnick marked this conversation as resolved.
Show resolved Hide resolved

// Checks the existence of yarn package
// We use yarnpkg instead of yarn to avoid conflict with Hadoop yarn
// Refer to https://github.com/yarnpkg/yarn/issues/673
Expand Down Expand Up @@ -67,8 +71,30 @@ const install = async rootPath => {
process.chdir(rootPath)

try {
let cmd = shouldUseYarn() ? spawn(`yarnpkg`) : spawn(`npm install`)
await cmd
const npmCmd = `npm install`
let response = npmCmd
if (shouldUseYarn()) {
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
const promptsAnswer = await prompts([
jamo marked this conversation as resolved.
Show resolved Hide resolved
{
type: `select`,
name: `package_manager`,
message: `Which package manager would you like to use ?`,
choices: [
{ title: `yarn`, value: `yarnpkg` },
{ title: `npm`, value: npmCmd },
],
initial: 0,
},
])
response = promptsAnswer.package_manager
frinyvonnick marked this conversation as resolved.
Show resolved Hide resolved
}
conf.set(`package_manager`, response)
if (response.includes(`yarn`)) {
await fs.remove(`package-lock.json`)
} else {
await fs.remove(`yarn.lock`)
}
await spawn(response)
} finally {
process.chdir(prevDir)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@babel/runtime": "^7.0.0",
"bluebird": "^3.5.0",
"ci-info": "2.0.0",
"configstore": "4.0.0",
"configstore": "^4.0.0",
"envinfo": "^5.8.1",
"fs-extra": "^7.0.1",
"is-docker": "1.1.0",
Expand Down
29 changes: 21 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6305,10 +6305,10 @@ config-chain@^1.1.11:
ini "^1.3.4"
proto-list "~1.2.1"

configstore@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-4.0.0.tgz#5933311e95d3687efb592c528b922d9262d227e7"
integrity sha512-CmquAXFBocrzaSM8mtGPMM/HiWmyIpr4CcJl/rgY2uCObZ/S7cKU0silxslqJejl+t/T9HS8E0PUNQD81JGUEQ==
configstore@^3.0.0, configstore@^3.1.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.2.tgz#c6f25defaeef26df12dd33414b001fe81a543f8f"
integrity sha512-vtv5HtGjcYUgFrXc6Kx747B83MRRVS5R1VTEQoXvuP+kMI+if6uywV0nDGoiydJRy4yk7h9od5Og0kxx4zUXmw==
dependencies:
dot-prop "^4.1.0"
graceful-fs "^4.1.2"
Expand All @@ -6317,10 +6317,10 @@ configstore@4.0.0:
write-file-atomic "^2.0.0"
xdg-basedir "^3.0.0"

configstore@^3.0.0, configstore@^3.1.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.2.tgz#c6f25defaeef26df12dd33414b001fe81a543f8f"
integrity sha512-vtv5HtGjcYUgFrXc6Kx747B83MRRVS5R1VTEQoXvuP+kMI+if6uywV0nDGoiydJRy4yk7h9od5Og0kxx4zUXmw==
configstore@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-4.0.0.tgz#5933311e95d3687efb592c528b922d9262d227e7"
integrity sha512-CmquAXFBocrzaSM8mtGPMM/HiWmyIpr4CcJl/rgY2uCObZ/S7cKU0silxslqJejl+t/T9HS8E0PUNQD81JGUEQ==
dependencies:
dot-prop "^4.1.0"
graceful-fs "^4.1.2"
Expand Down Expand Up @@ -13106,6 +13106,11 @@ kleur@^3.0.0:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.1.tgz#4f5b313f5fa315432a400f19a24db78d451ede62"
integrity sha512-P3kRv+B+Ra070ng2VKQqW4qW7gd/v3iD8sy/zOdcYRsfiD+QBokQNOps/AfP6Hr48cBhIIBFWckB9aO+IZhrWg==

kleur@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==

last-call-webpack-plugin@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz#9742df0e10e3cf46e5c0381c2de90d3a7a2d7555"
Expand Down Expand Up @@ -16934,6 +16939,14 @@ prompts@^2.0.1:
kleur "^3.0.0"
sisteransi "^1.0.0"

prompts@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.0.4.tgz#179f9d4db3128b9933aa35f93a800d8fce76a682"
integrity sha512-HTzM3UWp/99A0gk51gAegwo1QRYA7xjcZufMNe33rCclFszUYAuHe1fIN/3ZmiHeGPkUsNaRyQm1hHOfM0PKxA==
dependencies:
kleur "^3.0.2"
sisteransi "^1.0.0"

promzard@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/promzard/-/promzard-0.3.0.tgz#26a5d6ee8c7dee4cb12208305acfb93ba382a9ee"
Expand Down