Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
chore(package): use Babel
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed Jun 7, 2019
1 parent 8c65e8b commit 7ab4d33
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 76 deletions.
6 changes: 6 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Browsers that we support

>0.2%
not dead
not ie < 11
not op_mini all
48 changes: 25 additions & 23 deletions build/gulp/tasks/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { task, series, parallel, src, dest } from 'gulp'
import merge2 from 'merge2'
import babel from 'gulp-babel'
import rimraf from 'rimraf'
import webpack from 'webpack'
import { argv } from 'yargs'
Expand Down Expand Up @@ -43,30 +43,29 @@ const componentsSrc = [
`!${paths.packageSrc(packageName, '**/umd.ts')}`,
]

task('bundle:package:commonjs', () => {
const tsConfig = paths.base('build/tsconfig.commonjs.json')
const settings = { declaration: true }

const typescript = g.typescript.createProject(tsConfig, settings)
const { dts, js } = src(componentsSrc).pipe(typescript())

return merge2([
dts.pipe(dest(paths.packageDist(packageName, 'commonjs'))),
js.pipe(dest(paths.packageDist(packageName, 'commonjs'))),
])
})
task('bundle:package:commonjs', () =>
src(componentsSrc)
.pipe(babel())
.pipe(dest(paths.packageDist(packageName, 'commonjs'))),
)

task('bundle:package:es', () => {
const tsConfig = paths.base('build/tsconfig.es.json')
const settings = { declaration: true }
task('bundle:package:es', () =>
src(componentsSrc)
.pipe(babel({ caller: { useESModules: true } }))
.pipe(dest(paths.packageDist(packageName, 'es'))),
)

const typescript = g.typescript.createProject(tsConfig, settings)
const { dts, js } = src(componentsSrc).pipe(typescript())
task('bundle:package:types', () => {
const tsConfig = paths.base('build/tsconfig.json')
const typescript = g.typescript.createProject(tsConfig, {
declaration: true,
isolatedModules: false,
module: 'esnext',
})

return merge2([
dts.pipe(dest(paths.packageDist(packageName, 'es'))),
js.pipe(dest(paths.packageDist(packageName, 'es'))),
])
return src(componentsSrc)
.pipe(typescript())
.dts.pipe(dest(paths.packageDist(packageName, 'es')))
})

task('bundle:package:umd', cb => {
Expand Down Expand Up @@ -101,7 +100,10 @@ task('bundle:package:umd', cb => {

task(
'bundle:package:no-umd',
series('bundle:package:clean', parallel('bundle:package:commonjs', 'bundle:package:es')),
series(
'bundle:package:clean',
parallel('bundle:package:commonjs', 'bundle:package:es', 'bundle:package:types'),
),
)
task('bundle:package', series('bundle:package:no-umd', 'bundle:package:umd'))

Expand Down
8 changes: 0 additions & 8 deletions build/tsconfig.commonjs.json

This file was deleted.

7 changes: 0 additions & 7 deletions build/tsconfig.es.json

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"gh-pages": "^1.0.0",
"glob": "^7.1.2",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-cache": "^1.0.2",
"gulp-debug": "^4.0.0",
"gulp-load-plugins": "^1.5.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/docs-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"author": "Oleksandr Fediashov <a@fedyashov.com>",
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"@babel/runtime": "^7.1.2",
"object.values": "^1.1.0",
"prismjs": "^1.16.0",
"prop-types": "^15.6.1",
"tslib": "^1.9.3"
"prop-types": "^15.6.1"
},
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-components/src/knobs/useKnobValues.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as values from 'object.values'
import values from 'object.values'
import * as React from 'react'

import KnobsContext from './KnobContext'
Expand Down
23 changes: 15 additions & 8 deletions packages/internal-tooling/babel/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
const isBabelRegister = caller => {
return !!(caller && caller.name === '@babel/register')
const isNodeCaller = caller => {
return caller && (caller.name === '@babel/register' || caller.name === 'babel-jest')
}
const isJest = caller => {
return !!(caller && caller.name === 'babel-jest')
const isDistCaller = caller => {
return !!(caller && caller.name === 'babel-gulp')
}
const supportsESM = caller => {
return !!((caller && caller.name === 'babel-loader') || caller.useESModules)
}

module.exports = api => {
const isNode = api.caller(isBabelRegister) || api.caller(isJest)
const isDistBuild = api.caller(isDistCaller)
const isNode = api.caller(isNodeCaller)
const useESModules = !isNode && api.caller(supportsESM)

const presets = [
[
'@babel/preset-env',
{
modules: isNode ? 'cjs' : false,
modules: useESModules ? false : 'cjs',
targets: isNode ? { node: '8' } : undefined,
exclude: ['transform-async-to-generator'],
},
Expand All @@ -23,8 +28,10 @@ module.exports = api => {
const plugins = [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-transform-runtime',
]
['@babel/plugin-transform-runtime', { corejs: false, useESModules }],

isDistBuild && 'lodash',
].filter(Boolean)

return {
presets,
Expand Down
1 change: 1 addition & 0 deletions packages/internal-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@typescript-eslint/parser": "^1.9.0",
"@stardust-ui/eslint-plugin": "^0.31.0",
"babel-jest": "^24.5.0",
"babel-plugin-lodash": "^3.3.4",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-component-event-listener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"author": "Oleksandr Fediashov <a@fedyashov.com>",
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"prop-types": "^15.6.1",
"tslib": "^1.9.3"
"@babel/runtime": "^7.1.2",
"prop-types": "^15.6.1"
},
"devDependencies": {
"@stardust-ui/internal-tooling": "^0.32.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-component-nesting-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"author": "Oleksandr Fediashov <a@fedyashov.com>",
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"prop-types": "^15.6.1",
"tslib": "^1.9.3"
"@babel/runtime": "^7.1.2",
"prop-types": "^15.6.1"
},
"devDependencies": {
"@stardust-ui/internal-tooling": "^0.32.0",
Expand Down
1 change: 1 addition & 0 deletions packages/react-component-ref/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "Oleksandr Fediashov <olfedias@microsoft.com>",
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"@babel/runtime": "^7.1.2",
"@stardust-ui/react-proptypes": "^0.32.0",
"prop-types": "^15.6.1",
"react-is": "^16.6.3"
Expand Down
4 changes: 2 additions & 2 deletions packages/react-proptypes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"author": "Oleksandr Fediashov <olfedias@microsoft.com>",
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"@babel/runtime": "^7.1.2",
"lodash": "^4.17.11",
"prop-types": "^15.6.1",
"tslib": "^1.9.3"
"prop-types": "^15.6.1"
},
"devDependencies": {
"@stardust-ui/internal-tooling": "^0.32.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "Levi Thomason <me@levithomason.com>",
"bugs": "https://github.com/stardust-ui/react/issues",
"dependencies": {
"@babel/runtime": "^7.1.2",
"@stardust-ui/react-component-event-listener": "^0.32.0",
"@stardust-ui/react-component-nesting-registry": "^0.32.0",
"@stardust-ui/react-component-ref": "^0.32.0",
Expand All @@ -20,12 +21,10 @@
"fela-plugin-rtl": "^10.2.0",
"keyboard-key": "^1.0.1",
"lodash": "^4.17.11",
"mdn-polyfills": "^5.15.0",
"popper.js": "^1.15.0",
"prop-types": "^15.6.1",
"react-fela": "^10.2.0",
"react-is": "^16.6.3",
"tslib": "^1.9.3"
"react-is": "^16.6.3"
},
"devDependencies": {
"@stardust-ui/internal-tooling": "^0.32.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export * from './themes/teams/types'
//
// Components
//
export * from '@stardust-ui/react-component-ref'

export * from './components/Accordion/Accordion'
export { default as Accordion } from './components/Accordion/Accordion'
export * from './components/Accordion/AccordionTitle'
Expand Down Expand Up @@ -241,3 +239,5 @@ export const FocusZoneUtilities = {
export * from './lib/accessibility/FocusZone/FocusZone.types'
export * from './lib/accessibility/types'
export * from './lib/accessibility/reactTypes'

export * from '@stardust-ui/react-component-ref'
4 changes: 0 additions & 4 deletions packages/react/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// TODO: remove after switch to Babel
import 'mdn-polyfills/Object.assign'
import 'mdn-polyfills/String.prototype.includes'

import * as commonPropTypes from './commonPropTypes'

export { default as applyAccessibilityKeyHandlers } from './applyAccessibilityKeyHandlers'
Expand Down
52 changes: 40 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
dependencies:
"@babel/types" "^7.0.0"

"@babel/helper-module-imports@^7.0.0":
"@babel/helper-module-imports@^7.0.0", "@babel/helper-module-imports@^7.0.0-beta.49":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d"
integrity sha512-aP/hlLq01DWNEiDg4Jn23i+CXxW/owM4WpDLFUbpjxe4NS3BhLVZQ5i7E0ZrxuQ/vwekIeciyamgB1UIYxxM6A==
Expand Down Expand Up @@ -759,7 +759,7 @@
globals "^11.1.0"
lodash "^4.17.11"

"@babel/types@^7.0.0", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.4.4":
"@babel/types@^7.0.0", "@babel/types@^7.0.0-beta.49", "@babel/types@^7.2.0", "@babel/types@^7.3.0", "@babel/types@^7.4.4":
version "7.4.4"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.4.4.tgz#8db9e9a629bb7c29370009b4b779ed93fe57d5f0"
integrity sha512-dOllgYdnEFOebhkKCjzSVFqw/PmmB8pH6RGOWkY4GsboQNd47b1fBThBSwlHAq9alF9vc1M3+6oqR47R50L0tQ==
Expand Down Expand Up @@ -2750,6 +2750,17 @@ babel-plugin-jest-hoist@^24.3.0:
dependencies:
"@types/babel__traverse" "^7.0.6"

babel-plugin-lodash@^3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196"
integrity sha512-yDZLjK7TCkWl1gpBeBGmuaDIFhZKmkoL+Cu2MUUjv5VxUZx/z7tBGBCBcQs5RI1Bkz5LLmNdjx7paOyQtMovyg==
dependencies:
"@babel/helper-module-imports" "^7.0.0-beta.49"
"@babel/types" "^7.0.0-beta.49"
glob "^7.1.1"
lodash "^4.17.10"
require-package-name "^2.0.1"

babel-preset-jest@^24.3.0:
version "24.3.0"
resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-24.3.0.tgz#db88497e18869f15b24d9c0e547d8e0ab950796d"
Expand Down Expand Up @@ -3979,9 +3990,9 @@ core-js@^1.0.0:
integrity sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=

core-js@^2.4.0, core-js@^2.5.7:
version "2.5.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.7.tgz#f972608ff0cead68b841a16a932d0b183791814e"
integrity sha512-RszJCAxg/PP6uzXVXL6BsxSXx/B05oJAQ2vkJRjyjrEcNVycaqOmNb5OTxZPE3xa5gwZduqza6L9JOCenh/Ecw==
version "2.6.9"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.9.tgz#6b4b214620c834152e179323727fc19741b084f2"
integrity sha512-HOpZf6eXmnl7la+cUdMnLvUxKNqLUzJvgIziQ0DiF3JwSImNphIqdGqzj6hIKyX04MmV0poclQ7+wjWvxQyR2A==

core-js@^3.0.0:
version "3.1.2"
Expand Down Expand Up @@ -6592,6 +6603,16 @@ growly@^1.3.0:
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=

gulp-babel@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/gulp-babel/-/gulp-babel-8.0.0.tgz#e0da96f4f2ec4a88dd3a3030f476e38ab2126d87"
integrity sha512-oomaIqDXxFkg7lbpBou/gnUkX51/Y/M2ZfSjL2hdqXTAlSWZcgZtd2o0cOH0r/eE8LWD0+Q/PsLsr2DKOoqToQ==
dependencies:
plugin-error "^1.0.1"
replace-ext "^1.0.0"
through2 "^2.0.0"
vinyl-sourcemaps-apply "^0.2.0"

gulp-cache@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/gulp-cache/-/gulp-cache-1.0.2.tgz#064ed713de47b0ff26b491abd899590891e426f4"
Expand Down Expand Up @@ -9360,11 +9381,6 @@ mdast-add-list-metadata@1.0.1:
dependencies:
unist-util-visit-parents "1.1.2"

mdn-polyfills@^5.15.0:
version "5.15.0"
resolved "https://registry.yarnpkg.com/mdn-polyfills/-/mdn-polyfills-5.15.0.tgz#ee0812604b1f922a6b83ee879e3466483b394bb1"
integrity sha512-xnHoz63bS0IpyRwmSFAUEHnx8g2nuC7TbavgtoJYVStg2i32gHnD9o8orjMuQsvltANt+2xPHWGeKgyXWCZV3g==

media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
Expand Down Expand Up @@ -12107,6 +12123,11 @@ require-main-filename@^1.0.1:
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
integrity sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=

require-package-name@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/require-package-name/-/require-package-name-2.0.1.tgz#c11e97276b65b8e2923f75dabf5fb2ef0c3841b9"
integrity sha1-wR6XJ2tluOKSP3Xav1+y7ww4Qbk=

requireindex@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.2.0.tgz#3463cdb22ee151902635aa6c9535d4de9c2ef1ef"
Expand Down Expand Up @@ -12921,7 +12942,7 @@ source-map-url@^0.4.0:
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
integrity sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=

source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.6:
source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.1, source-map@^0.5.6:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
Expand Down Expand Up @@ -14330,6 +14351,13 @@ vinyl-sourcemap@^1.1.0:
remove-bom-buffer "^3.0.0"
vinyl "^2.0.0"

vinyl-sourcemaps-apply@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/vinyl-sourcemaps-apply/-/vinyl-sourcemaps-apply-0.2.1.tgz#ab6549d61d172c2b1b87be5c508d239c8ef87705"
integrity sha1-q2VJ1h0XLCsbh75cUI0jnI74dwU=
dependencies:
source-map "^0.5.1"

vinyl@^0.5.0:
version "0.5.3"
resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-0.5.3.tgz#b0455b38fc5e0cf30d4325132e461970c2091cde"
Expand Down Expand Up @@ -14832,4 +14860,4 @@ yauzl@2.4.1:
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.4.1.tgz#9528f442dab1b2284e58b4379bb194e22e0c4005"
integrity sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=
dependencies:
fd-slicer "~1.0.1"
fd-slicer "~1.0.1"

0 comments on commit 7ab4d33

Please sign in to comment.