Skip to content

Commit

Permalink
feat(cli): bundle package to workaround node_moduless tree resolution…
Browse files Browse the repository at this point in the history
… problems with npm
  • Loading branch information
pieh committed Oct 23, 2020
1 parent 95edecb commit 15f0f14
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 7 deletions.
19 changes: 18 additions & 1 deletion packages/gatsby-cli/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
{
"presets": [["babel-preset-gatsby-package"]]
"presets": [
[
"@babel/env",
{
"modules": false,
"shippedProposals": true,
"targets": { "node": "10.13.0" }
}
],
"@babel/preset-react"
],
"plugins": ["@babel/plugin-transform-runtime"],
"overrides": [
{
"test": ["**/*.ts", "**/*.tsx"],
"plugins": [["@babel/plugin-transform-typescript", { "isTSX": true }]]
}
]
}
7 changes: 7 additions & 0 deletions packages/gatsby-cli/non-rollup-babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This being a babel.config.js file instead of a .babelrc file allows the
// packages in `internal-plugins` to be compiled with the rest of the source.
// Ref: https://github.com/babel/babel/pull/7358

const configPath = require(`path`).join(__dirname, `..`, `..`, `.babelrc.js`)

module.exports = require(configPath)
24 changes: 19 additions & 5 deletions packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"gatsby-recipes": "^0.2.33",
"gatsby-telemetry": "^1.3.38",
"hosted-git-info": "^3.0.6",
"ink": "^2.7.1",
"ink-spinner": "^3.1.0",
"is-valid-path": "^0.1.1",
"lodash": "^4.17.20",
"meant": "^1.0.2",
Expand All @@ -37,7 +35,6 @@
"pretty-error": "^2.1.1",
"progress": "^2.0.3",
"prompts": "^2.3.2",
"react": "^16.8.0",
"redux": "^4.0.5",
"resolve-cwd": "^3.0.0",
"semver": "^7.3.2",
Expand All @@ -48,16 +45,29 @@
"update-notifier": "^4.1.3",
"uuid": "3.4.0",
"yargs": "^15.4.1",
"yoga-layout-prebuilt": "^1.9.6",
"yurnalist": "^1.1.2"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@rollup/plugin-babel": "^5.1.0",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"@rollup/plugin-replace": "^2.3.3",
"@types/hosted-git-info": "^3.0.1",
"@types/yargs": "^15.0.8",
"babel-preset-gatsby-package": "^0.5.3",
"concurrently": "^5.0.0",
"cross-env": "^7.0.2",
"rimraf": "^3.0.2",
"ink": "^2.7.1",
"ink-spinner": "^3.1.0",
"react": "^16.8.0",
"rollup": "^2.23.0",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-internal": "^1.0.0",
"typescript": "^3.9.7"
},
"files": [
Expand All @@ -77,10 +87,14 @@
"directory": "packages/gatsby-cli"
},
"scripts": {
"build": "babel src --out-dir lib --ignore \"**/__tests__\" --extensions \".ts,.js,.tsx\"",
"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\"",
"build:rollup": "rollup -c",
"build": "concurrently \"npm run build:babel\" \"npm run build:rollup\"",
"prepare": "cross-env NODE_ENV=production npm run build && npm run typegen",
"typegen": "rimraf \"lib/**/*.d.ts\" && tsc --emitDeclarationOnly --declaration --declarationDir lib/",
"watch": "babel -w src --out-dir lib --ignore \"**/__tests__\" --extensions \".ts,.js,.tsx\"",
"watch:babel": "npm run build:babel -- --watch",
"watch:rollup": "npm run build:rollup -- -w",
"watch": "concurrently \"npm run watch:babel\" \"npm run watch:rollup\"",
"postinstall": "node scripts/postinstall.js"
},
"engines": {
Expand Down
69 changes: 69 additions & 0 deletions packages/gatsby-cli/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import resolve from "@rollup/plugin-node-resolve"
import babel from "@rollup/plugin-babel"
import commonjs from "@rollup/plugin-commonjs"
import json from "@rollup/plugin-json"
import replace from "@rollup/plugin-replace";
import autoExternal from "rollup-plugin-auto-external"
import internal from "rollup-plugin-internal"

import path from "path"

// Rollup hoists Ink's dynamic require of react-devtools-core which causes
// a window not found error so we exclude Ink's devtools file for now.
function excludeDevTools() {
const re = /ink/
return {
name: `ignoreDevTools`,

load(id) {
if (id.match(re)) {
if (path.parse(id).name === `devtools`) {
return { code: `` }
}
}
},
}
}

export default {
input: `src/reporter/loggers/ink/index.tsx`,
output: {
file: `lib/reporter/loggers/ink/index.js`,
format: `cjs`,
},
cache: false,
plugins: [
replace({
values: {
"process.env.NODE_ENV": JSON.stringify(`production`)
}
}),
excludeDevTools(),
json(),
babel({
extensions: [`.js`, `.jsx`, `.es6`, `.es`, `.mjs`, `.ts`, `.tsx`] ,
babelHelpers: `runtime`,
skipPreflightCheck: true,
exclude: `node_modules/**`,
}),
resolve({
extensions: [`.mjs`, `.js`, `.json`, `.node`, `.ts`, `.tsx`],
dedupe: [ `react`, `ink` ]
}),
commonjs(),
autoExternal(),
internal([
`react`,
`ink`,
`ink-spinner`
]),
],
external: [
`yoga-layout-prebuilt`,
// Next one deserve explanation: ... it's because ink logger imports
// getStore, onLogAction from higher up (../../redux). But we don't want
// two copies of it - one bundled and one not, because it would result
// in multiple store copies
`../../redux`
]
}
43 changes: 42 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7347,6 +7347,21 @@ concat-with-sourcemaps@*, concat-with-sourcemaps@^1.1.0:
dependencies:
source-map "^0.6.1"

concurrently@^5.0.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-5.3.0.tgz#7500de6410d043c912b2da27de3202cb489b1e7b"
integrity sha512-8MhqOB6PWlBfA2vJ8a0bSFKATOdWlHiQlk11IfmQBPaHVP8oP2gsh2MObE6UR3hqDHqvaIvLTyceNW6obVuFHQ==
dependencies:
chalk "^2.4.2"
date-fns "^2.0.1"
lodash "^4.17.15"
read-pkg "^4.0.1"
rxjs "^6.5.2"
spawn-command "^0.0.2-1"
supports-color "^6.1.0"
tree-kill "^1.2.2"
yargs "^13.3.0"

config-chain@^1.1.11:
version "1.1.12"
resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa"
Expand Down Expand Up @@ -8291,7 +8306,7 @@ date-fns@^1.27.2, date-fns@^1.30.1:
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==

date-fns@^2.14.0, date-fns@^2.16.1, date-fns@^2.8.1:
date-fns@^2.0.1, date-fns@^2.14.0, date-fns@^2.16.1, date-fns@^2.8.1:
version "2.16.1"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.16.1.tgz#05775792c3f3331da812af253e1a935851d3834b"
integrity sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==
Expand Down Expand Up @@ -20066,6 +20081,15 @@ read-pkg@^3.0.0:
normalize-package-data "^2.3.2"
path-type "^3.0.0"

read-pkg@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-4.0.1.tgz#963625378f3e1c4d48c85872b5a6ec7d5d093237"
integrity sha1-ljYlN48+HE1IyFhytabsfV0JMjc=
dependencies:
normalize-package-data "^2.3.2"
parse-json "^4.0.0"
pify "^3.0.0"

read-pkg@^5.1.1, read-pkg@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc"
Expand Down Expand Up @@ -21996,6 +22020,13 @@ rxjs@^6.1.0, rxjs@^6.4.0:
dependencies:
tslib "^1.9.0"

rxjs@^6.5.2:
version "6.6.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552"
integrity sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==
dependencies:
tslib "^1.9.0"

sade@^1.7.3:
version "1.7.3"
resolved "https://registry.yarnpkg.com/sade/-/sade-1.7.3.tgz#a217ccc4fb4abb2d271648bf48f6628b2636fa1b"
Expand Down Expand Up @@ -22756,6 +22787,11 @@ sparse-bitfield@^3.0.3:
dependencies:
memory-pager "^1.0.2"

spawn-command@^0.0.2-1:
version "0.0.2-1"
resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0"
integrity sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A=

spdx-correct@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82"
Expand Down Expand Up @@ -24158,6 +24194,11 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"

tree-kill@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==

trim-lines@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/trim-lines/-/trim-lines-1.1.1.tgz#da738ff58fa74817588455e30b11b85289f2a396"
Expand Down

0 comments on commit 15f0f14

Please sign in to comment.