Skip to content

Commit 778e214

Browse files
committed
feat(recipes): bundle package to workaround node_modules tree resolution problems with npm
1 parent dd264de commit 778e214

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+562
-648
lines changed

packages/gatsby-admin/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"lodash-es": "^4.17.15",
2929
"ncp": "^2.0.0",
3030
"nodemon": "^2.0.4",
31+
"normalize.css": "^8.0.1",
3132
"prism-react-renderer": "^1.1.1",
3233
"query-string": "^6.13.3",
3334
"react": "^16.12.0",

packages/gatsby-recipes/.babelrc.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = api => {
2+
const isTest = api.env('test');
3+
4+
return {
5+
presets: [
6+
["@babel/env", {
7+
// use ES modules for rollup and commonjs for jest
8+
modules: isTest ? `commonjs` : false,
9+
shippedProposals: true,
10+
targets: {
11+
"node": "10.13.0"
12+
}
13+
}],
14+
"@babel/preset-react"
15+
],
16+
plugins: ["@babel/plugin-transform-runtime"]
17+
}
18+
};
19+
20+
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
const StepRenderer = require(`./dist/components/step-renderer`).default
2-
console.log(StepRenderer)
3-
module.exports.StepRenderer = StepRenderer
1+
const components = require(`./dist/web/components`)
2+
module.exports = components

packages/gatsby-recipes/non-rollup-babel.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/gatsby-recipes/package.json

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,29 @@
1515
"@babel/standalone": "^7.11.6",
1616
"@babel/template": "^7.10.4",
1717
"@babel/types": "^7.11.5",
18-
"@emotion/core": "^10.0.14",
19-
"@emotion/styled": "^10.0.14",
2018
"@graphql-tools/schema": "^6.0.14",
2119
"@graphql-tools/utils": "^6.0.14",
2220
"@hapi/hoek": "8.x.x",
2321
"@hapi/joi": "^15.1.1",
24-
"@mdx-js/mdx": "^2.0.0-next.4",
25-
"@mdx-js/react": "^2.0.0-next.4",
26-
"@mdx-js/runtime": "^2.0.0-next.4",
27-
"acorn": "^7.2.0",
28-
"acorn-jsx": "^5.2.0",
29-
"ansi-html": "^0.0.7",
30-
"babel-plugin-remove-export-keywords": "^1.6.5",
3122
"better-queue": "^3.8.10",
3223
"chokidar": "^3.4.2",
33-
"concurrently": "^5.0.0",
3424
"contentful-management": "^5.26.3",
3525
"cors": "^2.8.5",
36-
"cross-fetch": "^3.0.6",
3726
"debug": "^4.1.1",
3827
"detect-port": "^1.3.0",
3928
"dotenv": "^8.2.0",
4029
"execa": "^4.0.2",
4130
"express": "^4.17.1",
4231
"express-graphql": "^0.9.0",
43-
"flatted": "^3.0.0",
44-
"formik": "^2.0.8",
4532
"fs-extra": "^8.1.0",
4633
"gatsby-core-utils": "^1.3.22",
47-
"gatsby-interface": "^0.0.193",
4834
"gatsby-telemetry": "^1.3.37",
4935
"glob": "^7.1.6",
5036
"graphql": "^14.6.0",
5137
"graphql-compose": "^6.3.8",
5238
"graphql-subscriptions": "^1.1.0",
5339
"graphql-type-json": "^0.3.2",
5440
"hicat": "^0.7.0",
55-
"html-tag-names": "^1.1.5",
56-
"ink-box": "^1.0.0",
5741
"is-binary-path": "^2.1.0",
5842
"is-url": "^1.2.4",
5943
"jest-diff": "^25.5.0",
@@ -62,14 +46,9 @@
6246
"mitt": "^1.2.0",
6347
"mkdirp": "^0.5.1",
6448
"node-fetch": "^2.5.0",
65-
"normalize.css": "^8.0.1",
6649
"pkg-dir": "^4.2.0",
6750
"prettier": "^2.0.5",
6851
"prop-types": "^15.6.1",
69-
"property-information": "5.5.0",
70-
"react-circular-progressbar": "^2.0.0",
71-
"react-icons": "^3.0.1",
72-
"react-reconciler": "^0.25.1",
7352
"remark-mdx": "^2.0.0-next.4",
7453
"remark-mdxjs": "^2.0.0-next.4",
7554
"remark-parse": "^6.0.3",
@@ -80,36 +59,39 @@
8059
"single-trailing-newline": "^1.0.0",
8160
"strip-ansi": "^6.0.0",
8261
"style-to-object": "^0.3.0",
83-
"subscriptions-transport-ws": "^0.9.16",
84-
"svg-tag-names": "^2.0.1",
8562
"unified": "^8.4.2",
8663
"unist-util-remove": "^2.0.0",
8764
"unist-util-visit": "^2.0.2",
88-
"urql": "^1.9.7",
8965
"uuid": "3.4.0",
9066
"ws": "^7.3.0",
9167
"xstate": "^4.9.1",
92-
"yoga-layout-prebuilt": "^1.9.6",
93-
"yup": "^0.27.0"
68+
"yoga-layout-prebuilt": "^1.9.6"
9469
},
9570
"devDependencies": {
9671
"@babel/cli": "^7.11.6",
72+
"@mdx-js/mdx": "^2.0.0-next.4",
73+
"@mdx-js/react": "^2.0.0-next.4",
74+
"@mdx-js/runtime": "^2.0.0-next.4",
9775
"@babel/plugin-transform-runtime": "^7.11.5",
9876
"@rollup/plugin-babel": "^5.1.0",
9977
"@rollup/plugin-commonjs": "^14.0.0",
10078
"@rollup/plugin-json": "^4.1.0",
10179
"@rollup/plugin-node-resolve": "^8.4.0",
80+
"@rollup/plugin-replace": "^2.3.3",
10281
"fetch-mock-jest": "^1.3.0",
10382
"ink": "next",
10483
"ink-select-input": "^4.0.0",
10584
"ink-spinner": "^4.0.0-0",
10685
"react": "^16.12.0",
86+
"react-reconciler": "^0.25.1",
10787
"rimraf": "^3.0.2",
10888
"rollup": "^2.23.0",
10989
"rollup-plugin-auto-external": "^2.0.0",
11090
"rollup-plugin-internal": "^1.0.0",
91+
"subscriptions-transport-ws": "^0.9.16",
11192
"terminal-link": "^2.0.0",
112-
"tmp-promise": "^2.1.0"
93+
"tmp-promise": "^2.1.0",
94+
"urql": "^1.9.7"
11395
},
11496
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-recipes#readme",
11597
"jest": {
@@ -126,9 +108,6 @@
126108
],
127109
"license": "MIT",
128110
"main": "dist/index.js",
129-
"peerDependencies": {
130-
"react": "^16.12.0"
131-
},
132111
"repository": {
133112
"type": "git",
134113
"url": "https://github.com/gatsbyjs/gatsby.git",
@@ -144,16 +123,12 @@
144123
"remark-mdxjs": "^2.0.0-next.4"
145124
},
146125
"scripts": {
147-
"build": "concurrently \"npm run build:babel\" \"npm run build:rollup\"",
148-
"build:babel": "babel --config-file ./non-rollup-babel.config.js src --out-dir dist --ignore \"**/__tests__\" --extensions \".ts,.js,.tsx\"",
149-
"build:rollup": "rollup -c",
150-
"build:watch": "npm run build:babel -- --watch",
126+
"build": "rollup -c",
151127
"prebuild": "rimraf dist",
152128
"prepare": "npm run build",
153129
"prewatch": "rimraf dist",
154130
"test": "jest",
155131
"test:watch": "jest --watch",
156-
"watch": "concurrently \"npm run build:watch\" \"npm run watch:rollup\"",
157-
"watch:rollup": "rollup -c -w"
132+
"watch": "rollup -c -w"
158133
}
159134
}

packages/gatsby-recipes/rollup.config.js

Lines changed: 101 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import resolve from "@rollup/plugin-node-resolve"
22
import babel from "@rollup/plugin-babel"
33
import commonjs from "@rollup/plugin-commonjs"
44
import json from "@rollup/plugin-json"
5+
import replace from "@rollup/plugin-replace";
56
import autoExternal from "rollup-plugin-auto-external"
67
import internal from "rollup-plugin-internal"
78
import path from "path"
@@ -23,38 +24,104 @@ function excludeDevTools() {
2324
}
2425
}
2526

26-
export default {
27-
input: "src/index.js",
28-
output: {
29-
file: "dist/index.js",
30-
format: "cjs",
27+
export default [
28+
{
29+
input: {
30+
index: `src/index.js`,
31+
"graphql-server/server": `src/graphql-server/server.js`
32+
},
33+
output: {
34+
dir: `dist`,
35+
entryFileNames: `[name].js`,
36+
format: "cjs",
37+
sourcemap: true,
38+
},
39+
plugins: [
40+
replace({
41+
values: {
42+
"process.env.NODE_ENV": JSON.stringify(`production`)
43+
}
44+
}),
45+
excludeDevTools(),
46+
json(),
47+
babel({
48+
babelHelpers: `runtime`,
49+
skipPreflightCheck: true,
50+
exclude: `node_modules/**`,
51+
}),
52+
commonjs({
53+
transformMixedEsModules: true
54+
}),
55+
resolve({
56+
dedupe: [
57+
`react`,
58+
`ink`,
59+
`ink-select-input`,
60+
`ink-spinner`,
61+
`terminal-link`,
62+
`react-reconcilier`,
63+
`@mdx-js/mdx`,
64+
`@mdx-js/react`,
65+
`@mdx-js/runtime`,
66+
`urql`,
67+
`@urql/core`,
68+
`subscriptions-transport-ws`,
69+
]
70+
}),
71+
autoExternal(),
72+
internal([
73+
`react`,
74+
`ink`,
75+
`ink-select-input`,
76+
`ink-spinner`,
77+
`terminal-link`,
78+
`react-reconcilier`,
79+
`@mdx-js/mdx`,
80+
`@mdx-js/react`,
81+
`@mdx-js/runtime`,
82+
`urql`,
83+
`@urql/core`,
84+
`subscriptions-transport-ws`,
85+
]),
86+
],
87+
external: [
88+
`ws`,
89+
`gatsby-telemetry`,
90+
`gatsby-core-utils`,
91+
`yoga-layout-prebuilt`,
92+
],
3193
},
32-
plugins: [
33-
excludeDevTools(),
34-
json(),
35-
babel({
36-
babelHelpers: "runtime",
37-
skipPreflightCheck: true,
38-
exclude: "node_modules/**",
39-
}),
40-
resolve(),
41-
commonjs(),
42-
autoExternal(),
43-
internal([
44-
"ink",
45-
"ink-select-input",
46-
"ink-spinner",
47-
"terminal-link",
48-
"react-reconcilier",
49-
]),
50-
],
51-
external: [
52-
`yoga-layout-prebuilt`,
53-
`ws`,
54-
`urql`,
55-
`node-fetch`,
56-
`react`,
57-
`react-devtools-core`,
58-
`graphql-server`,
59-
],
60-
}
94+
{
95+
input: {
96+
components: `src/components.js`,
97+
},
98+
output: {
99+
dir: `dist/web/`,
100+
entryFileNames: `[name].js`,
101+
format: "es",
102+
sourcemap: true,
103+
},
104+
plugins: [
105+
babel({
106+
babelHelpers: `runtime`,
107+
skipPreflightCheck: true,
108+
exclude: `node_modules/**`,
109+
}),
110+
commonjs({
111+
transformMixedEsModules: true
112+
}),
113+
resolve({
114+
dedupe: [
115+
`@mdx-js/react`,
116+
]
117+
}),
118+
autoExternal(),
119+
internal([
120+
`@mdx-js/react`
121+
])
122+
],
123+
external: [
124+
`react`
125+
]
126+
}
127+
]

packages/gatsby-recipes/src/__tests__/find-dependency-match.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const findDependencyMatch = require(`../find-dependency-match`)
1+
import findDependencyMatch from "../find-dependency-match"
22

33
describe(`findDependencyMatch`, () => {
44
test(`basic matching`, () => {
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const render = require(`./renderer`)
1+
import render from "./renderer"
22

3-
module.exports = (context, cb) =>
4-
render(context.recipe, cb, context, true, true, true)
3+
export default function ApplyPlan(context, cb) {
4+
return render(context.recipe, cb, context, true, true, true)
5+
}

packages/gatsby-recipes/src/cli/index.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
const React = require(`react`)
2-
const { useState, useEffect } = require(`react`)
1+
import React, { useState, useEffect } from "react"
32
import SelectInput from "ink-select-input"
43
import { render, Box, Text, useInput, useApp, Transform } from "ink"
54
import Spinner from "ink-spinner"
65
import StepRenderer from "../components/step-renderer"
7-
const hicat = require(`hicat`)
8-
const { trackCli } = require(`gatsby-telemetry`)
6+
import hicat from "hicat"
7+
import { trackCli } from "gatsby-telemetry"
98
import {
109
useResource,
1110
useResourceByUUID,
1211
ResourceProvider,
1312
} from "../renderer/resource-provider"
1413
import terminalLink from "terminal-link"
1514
import PropTypes from "prop-types"
16-
const {
15+
import {
1716
createClient,
1817
useMutation,
1918
useSubscription,
2019
Provider,
2120
defaultExchanges,
2221
subscriptionExchange,
23-
} = require(`urql`)
24-
const { SubscriptionClient } = require(`subscriptions-transport-ws`)
25-
const fetch = require(`node-fetch`)
26-
const ws = require(`ws`)
27-
const semver = require(`semver`)
28-
const remove = require(`unist-util-remove`)
29-
const recipesList = require(`./recipes-list`).default
22+
} from "urql"
23+
import { SubscriptionClient } from "subscriptions-transport-ws"
24+
import fetch from "node-fetch"
25+
import ws from "ws"
26+
import semver from "semver"
27+
import remove from "unist-util-remove"
28+
import recipesList from "../recipes-list"
3029

3130
const removeJsx = () => tree => {
3231
remove(tree, `export`, () => true)

0 commit comments

Comments
 (0)