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: Deprecate gatsby-recipes #34094

Merged
merged 17 commits into from
Dec 9, 2021
21 changes: 21 additions & 0 deletions deprecated-packages/gatsby-recipes/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = api => {
const isTest = api.env(`test`)

return {
presets: [
[
`@babel/env`,
{
// use ES modules for rollup and commonjs for jest
modules: isTest ? `commonjs` : false,
shippedProposals: true,
targets: {
node: `10.13.0`,
},
},
],
`@babel/preset-react`,
],
plugins: [`@babel/plugin-transform-runtime`],
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const components = require(`./dist/web/components`)
module.exports = components
module.exports = components
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import path from "path"
function excludeDevTools() {
const re = /ink/
return {
name: "ignoreDevTools",

name: `ignoreDevTools`,
// eslint-disable-next-line
load(id) {
if (id.match(re)) {
if (path.parse(id).name === `devtools`) {
Expand All @@ -33,7 +33,7 @@ export default [
output: {
dir: `dist`,
entryFileNames: `[name].js`,
format: "cjs",
format: `cjs`,
sourcemap: true,
},
plugins: [
Expand Down Expand Up @@ -98,7 +98,7 @@ export default [
output: {
dir: `dist/web/`,
entryFileNames: `[name].js`,
format: "es",
format: `es`,
sourcemap: true,
},
plugins: [
Expand Down
32 changes: 19 additions & 13 deletions packages/create-gatsby/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# create-gatsby (alpha)
# create-gatsby

Create Gatsby apps in an interactive CLI experience that does the plumbing for you.

Expand All @@ -18,7 +18,7 @@ yarn create gatsby

It will ask you questions about what you're building, and set up a Gatsby project for you.

_Note: this package is different from the Gatsby CLI, it is intended solely to create new sites._
_Note: This package is different from `gatsby-cli`, it is intended solely to create new sites._

## Options

Expand All @@ -33,28 +33,34 @@ npm init gatsby -y <site-directory>
If you're making changes to the create-gatsby package, you can follow the steps below to test out your changes locally:

```sh
# Move into the create-gatsby package
cd packages/create-gatsby
# Move into the monorepo
cd <path-to-gatsby-monorepo>

# Install dependencies and build the package
yarn && yarn build
yarn bootstrap

# Run the create-gatsby script
node cli.js
node packages/create-gatsby/cli.js
```

Note that if you use the `build` script, you'll have to rebuild after each change. Alternatively, you can use the `watch` script to automatically rebuild after local changes. In that case, you'll need to run `cli.js` from the top-level directory of the `gatsby` repo:
Note that if you use the `bootstrap` script, you'll have to rebuild after each change. Alternatively, you can use the `watch` script to automatically rebuild after local changes:

```sh
# Move into the create-gatsby package
cd packages/create-gatsby
# Move into the monorepo
cd <path-to-gatsby-monorepo>

# Install dependencies and build the package
yarn && yarn watch
yarn bootstrap

# Open another terminal window and get back to the gatsby monorepo
cd <path-to-gatsby-monorepo>
# Watch changes
yarn watch --scope=create-gatsby
```

Open another terminal window and go to a folder where you can easily delete the test projects:

```
cd <path-to-playground>

# Run the create-gatsby script
node packages/create-gatsby/cli.js
node <some-path/packages/create-gatsby/cli.js
```
6 changes: 3 additions & 3 deletions packages/create-gatsby/src/site-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export async function setSiteMetadata(
value: string
): Promise<void> {
try {
const recipesPath = require.resolve(`gatsby-recipes`, {
const coreUtilsPath = require.resolve(`gatsby-core-utils`, {
paths: [root],
})
const { GatsbySiteMetadata } = require(recipesPath)
await GatsbySiteMetadata?.create({ root }, { name, value })
const { addFieldToMinimalSiteMetadata } = require(coreUtilsPath)
await addFieldToMinimalSiteMetadata({ root }, { name, value })
} catch (e) {
// Silently fail, as it's fine if we don't add it to the config
}
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"fs-exists-cached": "^1.0.0",
"fs-extra": "^10.0.0",
"gatsby-core-utils": "^3.3.0-next.1",
"gatsby-recipes": "^1.3.0-next.2",
"gatsby-telemetry": "^3.3.0-next.1",
"hosted-git-info": "^3.0.8",
"is-valid-path": "^0.1.1",
Expand Down
41 changes: 5 additions & 36 deletions packages/gatsby-cli/src/create-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,46 +386,15 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
),
})

cli.command({
command: `recipes [recipe]`,
describe: `[EXPERIMENTAL] Run a recipe`,
builder: _ =>
_.option(`D`, {
alias: `develop`,
type: `boolean`,
default: false,
describe: `Start recipe in develop mode to live-develop your recipe (defaults to false)`,
}).option(`I`, {
alias: `install`,
type: `boolean`,
default: false,
describe: `Install recipe (defaults to plan mode)`,
}),
handler: handlerP(async ({ recipe, develop, install }: yargs.Arguments) => {
const { recipesHandler } = require(`./recipes`)
await recipesHandler(
siteInfo.directory,
recipe as string,
develop as boolean,
install as boolean
)
}),
})

cli.command({
command: `plugin <cmd> [plugins...]`,
describe: `Useful commands relating to Gatsby plugins`,
builder: yargs =>
yargs
.positional(`cmd`, {
choices: [`docs`, `ls`],
describe: "Valid commands include `docs`, `ls`.",
type: `string`,
})
.positional(`plugins`, {
describe: `The plugin names`,
type: `string`,
}),
yargs.positional(`cmd`, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stub was added in #27725 but never used again. So plugins positional was never working, thus I removed this here + removed plugin-add.ts handler file

choices: [`docs`, `ls`],
describe: "Valid commands include `docs`, `ls`.",
type: `string`,
}),
handler: async ({
cmd,
}: yargs.Arguments<{
Expand Down
83 changes: 0 additions & 83 deletions packages/gatsby-cli/src/handlers/plugin-add.ts

This file was deleted.

46 changes: 25 additions & 21 deletions packages/gatsby-cli/src/handlers/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
import { GatsbyPlugin } from "gatsby-recipes"
import { listPlugins } from "gatsby-core-utils"
import reporter from "../reporter"

export default async (root: string, cmd: string | undefined): Promise<void> => {
switch (cmd) {
case `docs`:
console.log(`
Using a plugin:
- What is a Plugin? (https://www.gatsbyjs.com/docs/what-is-a-plugin/)
- Using a Plugin in Your Site (https://www.gatsbyjs.com/docs/using-a-plugin-in-your-site/)
- What You Don't Need Plugins For (https://www.gatsbyjs.com/docs/what-you-dont-need-plugins-for/)
- Loading Plugins from Your Local Plugins Folder (https://www.gatsbyjs.com/docs/loading-plugins-from-your-local-plugins-folder/)
- Plugin Library (https://www.gatsbyjs.com/plugins/)
Using a plugin:
- What is a Plugin? (https://www.gatsbyjs.com/docs/what-is-a-plugin/)
- Using a Plugin in Your Site (https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/using-a-plugin-in-your-site/)
- Loading Plugins from Your Local Plugins Folder (https://www.gatsbyjs.com/docs/loading-plugins-from-your-local-plugins-folder/)
- Plugin Library (https://www.gatsbyjs.com/plugins/)

Creating a plugin:
- Naming a Plugin (https://www.gatsbyjs.com/docs/naming-a-plugin/)
- Files Gatsby Looks for in a Plugin (https://www.gatsbyjs.com/docs/files-gatsby-looks-for-in-a-plugin/)
- Creating a Generic Plugin (https://www.gatsbyjs.com/docs/creating-a-generic-plugin/)
- Creating a Local Plugin (https://www.gatsbyjs.com/docs/creating-a-local-plugin/)
- Creating a Source Plugin (https://www.gatsbyjs.com/docs/creating-a-source-plugin/)
- Creating a Transformer Plugin (https://www.gatsbyjs.com/docs/creating-a-transformer-plugin/)
- Submit to Plugin Library (https://www.gatsbyjs.com/contributing/submit-to-plugin-library/)
- Source Plugin Tutorial (https://www.gatsbyjs.com/tutorial/source-plugin-tutorial/)
- Maintaining a Plugin (https://www.gatsbyjs.com/docs/maintaining-a-plugin/)
- Join Discord #plugin-authoring channel to ask questions! (https://gatsby.dev/discord/)
`)
Creating a plugin:
- Naming a Plugin (https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/naming-a-plugin/)
- Files Gatsby Looks for in a Plugin (https://www.gatsbyjs.com/docs/files-gatsby-looks-for-in-a-plugin/)
- Creating a Generic Plugin (https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/creating-a-generic-plugin/)
- Creating a Local Plugin (https://www.gatsbyjs.com/docs/creating-a-local-plugin/)
- Creating a Source Plugin (https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/creating-a-source-plugin/)
- Creating a Transformer Plugin (https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/creating-a-transformer-plugin/)
- Submit to Plugin Library (https://www.gatsbyjs.com/contributing/submit-to-plugin-library/)
- Maintaining a Plugin (https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/maintaining-a-plugin/)
- Join Discord #plugin-authoring channel to ask questions! (https://gatsby.dev/discord/)
`)
return
case `ls`: {
try {
const plugins = await GatsbyPlugin.all({ root }, false)
console.log(plugins)
const plugins = await listPlugins({ root })
let list = ``
plugins.forEach(plugin => (list += `- ${plugin}\n`))
console.log(`
Following plugins are installed:

${list}
`)
} catch {
reporter.error(
`There was a problem parsing your \`gatsby-config.js\` file.\nIt may be malformed. Or, the syntax you're using is not currently supported by this command.`
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-cli/src/init-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import isValid from "is-valid-path"
import sysPath from "path"
import prompts from "prompts"
import url from "url"
import { updateSiteMetadata } from "gatsby-core-utils"
import { updateInternalSiteMetadata } from "gatsby-core-utils"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming of the function confused me with the siteMetadata from gatsby-config.js so I renamed this

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem to be getting this error when running gatsby build now:

error (0 , _gatsbyCoreUtils.updateSiteMetadata) is not a function

TypeError: (0 , _gatsbyCoreUtils.updateSiteMetadata) is not a function
  
  - build.ts:87 build
    [project]/[gatsby]/src/commands/build.ts:87:9
  
  - create-cli.js:240 
    [project]/[gatsby-cli]/lib/create-cli.js:240:14
  
  - create-cli.js:130 
    [project]/[gatsby-cli]/lib/create-cli.js:130:24
  
  - create-cli.js:41 Object.handler
    [project]/[gatsby-cli]/lib/create-cli.js:41:19
  
  - command.js:196 Object.runCommand
    [project]/[gatsby-cli]/[yargs]/build/lib/command.js:196:48
  
  - yargs.js:1043 Object.parseArgs [as _parseArgs]
    [project]/[gatsby-cli]/[yargs]/build/lib/yargs.js:1043:55
  
  - yargs.js:584 Object.parse
    [project]/[gatsby-cli]/[yargs]/build/lib/yargs.js:584:29
  
  - create-cli.js:541 createCli
    [project]/[gatsby-cli]/lib/create-cli.js:541:136
  
  - index.js:84 Object.<anonymous>
    [project]/[gatsby-cli]/lib/index.js:84:26
  
  - loader:1101 Module._compile
    node:internal/modules/cjs/loader:1101:14
  
  - loader:1153 Object.Module._extensions..js
    node:internal/modules/cjs/loader:1153:10
  
  - loader:981 Module.load
    node:internal/modules/cjs/loader:981:32
  
  - loader:822 Function.Module._load
    node:internal/modules/cjs/loader:822:12
  
  - loader:1005 Module.require
    node:internal/modules/cjs/loader:1005:19
  
  - helpers:102 require
    node:internal/modules/cjs/helpers:102:18
  
  - gatsby.js:3 Object.<anonymous>
    [project]/[gatsby]/src/bin/gatsby.js:3:1
  

error Command failed with exit code 1.

I need to have a look into why this is happening though, as something in our build system isn't correctly pinning the version of gatsby + gatsby-cli it seems. (setting to the previous version doesn't fix the issue for some reason - should have an update tomorrow). I'm guessing (and unsure if this is always the case, but this change means that the gatsby + gatsby-cli versions must match)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn’t add gatsby-cli as a dependency to a project. It’s a global CLI package

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear we don't have it as a dependency in the package.json, however it's required in the CI system to be installed

import report from "./reporter"
import { getPackageManager, setPackageManager } from "./util/package-manager"
import reporter from "./reporter"
Expand Down Expand Up @@ -353,7 +353,7 @@ export async function initStarter(
)
})

await updateSiteMetadata(
await updateInternalSiteMetadata(
{
name: sitePackageJson?.name || rootPath,
sitePath,
Expand Down
21 changes: 0 additions & 21 deletions packages/gatsby-cli/src/recipes.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/gatsby-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"file-type": "^16.5.3",
"fs-extra": "^10.0.0",
"got": "^11.8.2",
"lock": "^1.1.0",
"node-object-hash": "^2.3.10",
"proper-lockfile": "^4.1.2",
"tmp": "^0.2.1",
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-core-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from "./service-lock"
export * from "./site-metadata"
export * from "./page-data"
export * from "./page-html"
export { listPlugins } from "./list-plugins"
Loading