Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
fix(load-cfg): use babel register in order to require using es6
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jan 21, 2019
1 parent 2c53e56 commit 7ad3b64
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 26 deletions.
7 changes: 5 additions & 2 deletions core/docz-core/src/states/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ const getInitialConfig = (config: Config): Payload => {
}
}

const updateConfig = (config: Config) => async ({ setState }: Params) =>
setState('config', load('docz', getInitialConfig(config), true, false))
const updateConfig = (config: Config) => async (p: Params) => {
const initial = getInitialConfig(config)
const next = load('docz', initial, true, true)
p.setState('config', next)
}

export const state = (config: Config): State => {
const watcher = chokidar.watch(finds('docz'), {
Expand Down
2 changes: 1 addition & 1 deletion core/docz-theme-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@emotion/cache": "^10.0.0",
"@emotion/core": "^10.0.6",
"@emotion/styled": "^10.0.6",
"codemirror": "^5.42.2",
"codemirror": "^5.43.0",
"copy-text-to-clipboard": "^1.0.4",
"docz": "^0.13.5",
"emotion-theming": "^10.0.6",
Expand Down
3 changes: 2 additions & 1 deletion other-packages/load-cfg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
"tslint": "tslint --project ."
},
"dependencies": {
"@babel/register": "^7.0.0",
"@babel/preset-env": "^7.2.3",
"deepmerge": "^3.1.0",
"esm": "^3.1.1",
"find-up": "^3.0.0",
"fs-extra": "^7.0.1"
},
Expand Down
24 changes: 10 additions & 14 deletions other-packages/load-cfg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ import * as fs from 'fs-extra'
import * as path from 'path'
import * as findup from 'find-up'
import merge from 'deepmerge'
import esm from 'esm'

export const loadFile = (filepath: string, noCache?: boolean) => {
let file
const require = esm(module, {
mode: 'auto',
require('@babel/register')({
cache: !noCache,
cjs: {
cache: !noCache,
namedExports: true,
vars: true,
},
presets: [['@babel/preset-env', { modules: 'commonjs' }]],
})

let file

if (noCache && filepath) {
delete require.cache[path.resolve(filepath)]
}
Expand Down Expand Up @@ -54,13 +49,14 @@ export function load<C = any>(
): C {
const filepath = findup.sync(finds(name))
const file = filepath ? loadFile(filepath, noCache) : {}

// tslint:disable
return defaultConfig
const next = defaultConfig
? deep
? merge(defaultConfig, file)
: Object.assign({}, defaultConfig, file)
: { ...defaultConfig, ...file }
: file

// tslint:disable
return next
}

export function loadFrom<C = any>(
Expand All @@ -75,6 +71,6 @@ export function loadFrom<C = any>(
return defaultConfig
? deep
? merge(defaultConfig, file)
: Object.assign({}, defaultConfig, file)
: { ...defaultConfig, ...file }
: file
}
54 changes: 46 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,19 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-transform-typescript" "^7.1.0"

"@babel/register@^7.0.0":
version "7.0.0"
resolved "https://registry.npmjs.org/@babel/register/-/register-7.0.0.tgz#fa634bae1bfa429f60615b754fc1f1d745edd827"
integrity sha512-f/+CRmaCe7rVEvcvPvxeA8j5aJhHC3aJie7YuqcMDhUOuyWLA7J/aNrTaHIzoWPEhpHA54mec4Mm8fv8KBlv3g==
dependencies:
core-js "^2.5.7"
find-cache-dir "^1.0.0"
home-or-tmp "^3.0.0"
lodash "^4.17.10"
mkdirp "^0.5.1"
pirates "^4.0.0"
source-map-support "^0.5.9"

"@babel/runtime@7.1.5":
version "7.1.5"
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.1.5.tgz#4170907641cf1f61508f563ece3725150cc6fe39"
Expand Down Expand Up @@ -4187,10 +4200,10 @@ code-point-at@^1.0.0:
resolved "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=

codemirror@^5.42.2:
version "5.42.2"
resolved "https://registry.npmjs.org/codemirror/-/codemirror-5.42.2.tgz#801ab715a7a7e1c7ed4162b78e9d8138b98de8f0"
integrity sha512-Tkv6im39VuhduFMsDA3MlXcC/kKas3Z0PI1/8N88QvFQbtOeiiwnfFJE4juGyC8/a4sb1BSxQlzsil8XLQdxRw==
codemirror@^5.43.0:
version "5.43.0"
resolved "https://registry.npmjs.org/codemirror/-/codemirror-5.43.0.tgz#2454b5e0f7005dc9945ab7b0d9594ccf233da040"
integrity sha512-mljwQWUaWIf85I7QwTBryF2ASaIvmYAL4s5UCanCJFfKeXOKhrqdHWdHiZWAMNT+hjLTCnVx2S/SYTORIgxsgA==

codesandboxer-fs@^0.4.7:
version "0.4.7"
Expand Down Expand Up @@ -5685,10 +5698,10 @@ eslint-scope@^4.0.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"

esm@^3.1.1:
version "3.1.1"
resolved "https://registry.npmjs.org/esm/-/esm-3.1.1.tgz#810d1144522547801a58a8ea01d6566d61578223"
integrity sha512-Md2pR4IbR37UqubbgbA4+wiBorOEFB05Oo+g4WJW7W2ajiOhUfjZt77NzzCoQdrCb40GdKcflitm+XHDF053OQ==
esm@3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/esm/-/esm-3.1.0.tgz#89eb950b3f04b691b12f96a0d9c8de93039a1a26"
integrity sha512-r4Go7Wh7Wh0WPinRXeeM9PIajRsUdt8SAyki5R1obVc0+BwtqvtjbngVSSdXg0jCe2xZkY8hyBMx6q/uymUkPw==

esprima@^3.1.3:
version "3.1.3"
Expand Down Expand Up @@ -7058,6 +7071,11 @@ home-or-tmp@^2.0.0:
os-homedir "^1.0.0"
os-tmpdir "^1.0.1"

home-or-tmp@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-3.0.0.tgz#57a8fe24cf33cdd524860a15821ddc25c86671fb"
integrity sha1-V6j+JM8zzdUkhgoVgh3cJchmcfs=

homedir-polyfill@^1.0.0, homedir-polyfill@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc"
Expand Down Expand Up @@ -9806,6 +9824,11 @@ node-libs-browser@^2.0.0:
util "^0.10.3"
vm-browserify "0.0.4"

node-modules-regexp@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40"
integrity sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA=

node-notifier@^5.2.1:
version "5.3.0"
resolved "https://registry.npmjs.org/node-notifier/-/node-notifier-5.3.0.tgz#c77a4a7b84038733d5fb351aafd8a268bfe19a01"
Expand Down Expand Up @@ -10640,6 +10663,13 @@ pinkie@^2.0.0:
resolved "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=

pirates@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/pirates/-/pirates-4.0.0.tgz#850b18781b4ac6ec58a43c9ed9ec5fe6796addbd"
integrity sha512-8t5BsXy1LUIjn3WWOlOuFDuKswhQb/tkak641lvBgmPOBUQHXveORtlMCp6OdPV1dtuTaEahKA8VNz6uLfKBtA==
dependencies:
node-modules-regexp "^1.0.0"

pkg-conf@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/pkg-conf/-/pkg-conf-2.1.0.tgz#2126514ca6f2abfebd168596df18ba57867f0058"
Expand Down Expand Up @@ -12475,6 +12505,14 @@ source-map-support@^0.5.6, source-map-support@~0.5.6:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-support@^0.5.9:
version "0.5.10"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.10.tgz#2214080bc9d51832511ee2bab96e3c2f9353120c"
integrity sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
Expand Down

0 comments on commit 7ad3b64

Please sign in to comment.