Skip to content

Commit c3e0d74

Browse files
committed
feat(cli): bundle package to workaround node_moduless tree resolution problems with npm
1 parent 778e214 commit c3e0d74

File tree

5 files changed

+155
-7
lines changed

5 files changed

+155
-7
lines changed

packages/gatsby-cli/.babelrc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
{
2-
"presets": [["babel-preset-gatsby-package"]]
2+
"presets": [
3+
[
4+
"@babel/env",
5+
{
6+
"modules": false,
7+
"shippedProposals": true,
8+
"targets": { "node": "10.13.0" }
9+
}
10+
],
11+
"@babel/preset-react"
12+
],
13+
"plugins": ["@babel/plugin-transform-runtime"],
14+
"overrides": [
15+
{
16+
"test": ["**/*.ts", "**/*.tsx"],
17+
"plugins": [["@babel/plugin-transform-typescript", { "isTSX": true }]]
18+
}
19+
]
320
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This being a babel.config.js file instead of a .babelrc file allows the
2+
// packages in `internal-plugins` to be compiled with the rest of the source.
3+
// Ref: https://github.com/babel/babel/pull/7358
4+
5+
const configPath = require(`path`).join(__dirname, `..`, `..`, `.babelrc.js`)
6+
7+
module.exports = require(configPath)

packages/gatsby-cli/package.json

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
"gatsby-recipes": "^0.2.30",
2828
"gatsby-telemetry": "^1.3.37",
2929
"hosted-git-info": "^3.0.5",
30-
"ink": "^2.7.1",
31-
"ink-spinner": "^3.1.0",
3230
"is-valid-path": "^0.1.1",
3331
"lodash": "^4.17.20",
3432
"meant": "^1.0.2",
@@ -37,7 +35,6 @@
3735
"pretty-error": "^2.1.1",
3836
"progress": "^2.0.3",
3937
"prompts": "^2.3.2",
40-
"react": "^16.8.0",
4138
"redux": "^4.0.5",
4239
"resolve-cwd": "^3.0.0",
4340
"semver": "^7.3.2",
@@ -48,16 +45,29 @@
4845
"update-notifier": "^4.1.1",
4946
"uuid": "3.4.0",
5047
"yargs": "^15.4.1",
48+
"yoga-layout-prebuilt": "^1.9.6",
5149
"yurnalist": "^1.1.2"
5250
},
5351
"devDependencies": {
5452
"@babel/cli": "^7.11.6",
5553
"@babel/core": "^7.11.6",
54+
"@rollup/plugin-babel": "^5.1.0",
55+
"@rollup/plugin-commonjs": "^14.0.0",
56+
"@rollup/plugin-json": "^4.1.0",
57+
"@rollup/plugin-node-resolve": "^8.4.0",
58+
"@rollup/plugin-replace": "^2.3.3",
5659
"@types/hosted-git-info": "^3.0.0",
5760
"@types/yargs": "^15.0.7",
5861
"babel-preset-gatsby-package": "^0.5.3",
62+
"concurrently": "^5.0.0",
5963
"cross-env": "^7.0.2",
6064
"rimraf": "^3.0.2",
65+
"ink": "^2.7.1",
66+
"ink-spinner": "^3.1.0",
67+
"react": "^16.8.0",
68+
"rollup": "^2.23.0",
69+
"rollup-plugin-auto-external": "^2.0.0",
70+
"rollup-plugin-internal": "^1.0.0",
6171
"typescript": "^3.9.7"
6272
},
6373
"files": [
@@ -77,10 +87,14 @@
7787
"directory": "packages/gatsby-cli"
7888
},
7989
"scripts": {
80-
"build": "babel src --out-dir lib --ignore \"**/__tests__\" --extensions \".ts,.js,.tsx\"",
90+
"build:babel": "babel --config-file ./non-rollup-babel.config.js src --out-dir lib --ignore \"**/__tests__\" --ignore \"src/reporter/loggers/ink/**/*\" --extensions \".ts,.js,.tsx\"",
91+
"build:rollup": "rollup -c",
92+
"build": "concurrently \"npm run build:babel\" \"npm run build:rollup\"",
8193
"prepare": "cross-env NODE_ENV=production npm run build && npm run typegen",
8294
"typegen": "rimraf \"lib/**/*.d.ts\" && tsc --emitDeclarationOnly --declaration --declarationDir lib/",
83-
"watch": "babel -w src --out-dir lib --ignore \"**/__tests__\" --extensions \".ts,.js,.tsx\"",
95+
"watch:babel": "npm run build:babel -- --watch",
96+
"watch:rollup": "npm run build:rollup -- -w",
97+
"watch": "concurrently \"npm run watch:babel\" \"npm run watch:rollup\"",
8498
"postinstall": "node scripts/postinstall.js"
8599
},
86100
"engines": {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import resolve from "@rollup/plugin-node-resolve"
2+
import babel from "@rollup/plugin-babel"
3+
import commonjs from "@rollup/plugin-commonjs"
4+
import json from "@rollup/plugin-json"
5+
import replace from "@rollup/plugin-replace";
6+
import autoExternal from "rollup-plugin-auto-external"
7+
import internal from "rollup-plugin-internal"
8+
9+
import path from "path"
10+
11+
// Rollup hoists Ink's dynamic require of react-devtools-core which causes
12+
// a window not found error so we exclude Ink's devtools file for now.
13+
function excludeDevTools() {
14+
const re = /ink/
15+
return {
16+
name: `ignoreDevTools`,
17+
18+
load(id) {
19+
if (id.match(re)) {
20+
if (path.parse(id).name === `devtools`) {
21+
return { code: `` }
22+
}
23+
}
24+
},
25+
}
26+
}
27+
28+
export default {
29+
input: `src/reporter/loggers/ink/index.tsx`,
30+
output: {
31+
file: `lib/reporter/loggers/ink/index.js`,
32+
format: `cjs`,
33+
},
34+
cache: false,
35+
plugins: [
36+
replace({
37+
values: {
38+
"process.env.NODE_ENV": JSON.stringify(`production`)
39+
}
40+
}),
41+
excludeDevTools(),
42+
json(),
43+
babel({
44+
extensions: [`.js`, `.jsx`, `.es6`, `.es`, `.mjs`, `.ts`, `.tsx`] ,
45+
babelHelpers: `runtime`,
46+
skipPreflightCheck: true,
47+
exclude: `node_modules/**`,
48+
}),
49+
resolve({
50+
extensions: [`.mjs`, `.js`, `.json`, `.node`, `.ts`, `.tsx`],
51+
dedupe: [ `react`, `ink` ]
52+
}),
53+
commonjs(),
54+
autoExternal(),
55+
internal([
56+
`react`,
57+
`ink`,
58+
`ink-spinner`
59+
]),
60+
],
61+
external: [
62+
`yoga-layout-prebuilt`,
63+
// Next one deserve explanation: ... it's because ink logger imports
64+
// getStore, onLogAction from higher up (../../redux). But we don't want
65+
// two copies of it - one bundled and one not, because it would result
66+
// in multiple store copies
67+
`../../redux`
68+
]
69+
}

yarn.lock

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7289,6 +7289,21 @@ concat-with-sourcemaps@*, concat-with-sourcemaps@^1.1.0:
72897289
dependencies:
72907290
source-map "^0.6.1"
72917291

7292+
concurrently@^5.0.0:
7293+
version "5.3.0"
7294+
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-5.3.0.tgz#7500de6410d043c912b2da27de3202cb489b1e7b"
7295+
integrity sha512-8MhqOB6PWlBfA2vJ8a0bSFKATOdWlHiQlk11IfmQBPaHVP8oP2gsh2MObE6UR3hqDHqvaIvLTyceNW6obVuFHQ==
7296+
dependencies:
7297+
chalk "^2.4.2"
7298+
date-fns "^2.0.1"
7299+
lodash "^4.17.15"
7300+
read-pkg "^4.0.1"
7301+
rxjs "^6.5.2"
7302+
spawn-command "^0.0.2-1"
7303+
supports-color "^6.1.0"
7304+
tree-kill "^1.2.2"
7305+
yargs "^13.3.0"
7306+
72927307
config-chain@^1.1.11:
72937308
version "1.1.12"
72947309
resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa"
@@ -8224,7 +8239,7 @@ date-fns@^1.27.2, date-fns@^1.30.1:
82248239
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
82258240
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==
82268241

8227-
date-fns@^2.14.0, date-fns@^2.16.1, date-fns@^2.8.1:
8242+
date-fns@^2.0.1, date-fns@^2.14.0, date-fns@^2.16.1, date-fns@^2.8.1:
82288243
version "2.16.1"
82298244
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.16.1.tgz#05775792c3f3331da812af253e1a935851d3834b"
82308245
integrity sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==
@@ -19899,6 +19914,15 @@ read-pkg@^3.0.0:
1989919914
normalize-package-data "^2.3.2"
1990019915
path-type "^3.0.0"
1990119916

19917+
read-pkg@^4.0.1:
19918+
version "4.0.1"
19919+
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-4.0.1.tgz#963625378f3e1c4d48c85872b5a6ec7d5d093237"
19920+
integrity sha1-ljYlN48+HE1IyFhytabsfV0JMjc=
19921+
dependencies:
19922+
normalize-package-data "^2.3.2"
19923+
parse-json "^4.0.0"
19924+
pify "^3.0.0"
19925+
1990219926
read-pkg@^5.1.1, read-pkg@^5.2.0:
1990319927
version "5.2.0"
1990419928
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc"
@@ -21845,6 +21869,13 @@ rxjs@^6.1.0, rxjs@^6.4.0:
2184521869
dependencies:
2184621870
tslib "^1.9.0"
2184721871

21872+
rxjs@^6.5.2:
21873+
version "6.6.3"
21874+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552"
21875+
integrity sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==
21876+
dependencies:
21877+
tslib "^1.9.0"
21878+
2184821879
sade@^1.7.3:
2184921880
version "1.7.3"
2185021881
resolved "https://registry.yarnpkg.com/sade/-/sade-1.7.3.tgz#a217ccc4fb4abb2d271648bf48f6628b2636fa1b"
@@ -22614,6 +22645,11 @@ sparse-bitfield@^3.0.3:
2261422645
dependencies:
2261522646
memory-pager "^1.0.2"
2261622647

22648+
spawn-command@^0.0.2-1:
22649+
version "0.0.2-1"
22650+
resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0"
22651+
integrity sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A=
22652+
2261722653
spdx-correct@^3.0.0:
2261822654
version "3.0.0"
2261922655
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82"
@@ -24002,6 +24038,11 @@ tr46@^1.0.1:
2400224038
dependencies:
2400324039
punycode "^2.1.0"
2400424040

24041+
tree-kill@^1.2.2:
24042+
version "1.2.2"
24043+
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
24044+
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
24045+
2400524046
trim-lines@^1.0.0:
2400624047
version "1.1.1"
2400724048
resolved "https://registry.yarnpkg.com/trim-lines/-/trim-lines-1.1.1.tgz#da738ff58fa74817588455e30b11b85289f2a396"

0 commit comments

Comments
 (0)