Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Es build (#347)
Browse files Browse the repository at this point in the history
* Isolate rollup build with exec

* Add es bundle

* Remove require from modules

* Add module fields
  • Loading branch information
TrySound authored and istarkov committed Apr 10, 2017
1 parent 2f7b1cd commit 8b44b87
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"license": "MIT",
"scripts": {
"lint": "eslint src",
"lint": "eslint scripts src",
"test": "ava --concurrency=5",
"test:watch": "npm run test -- --watch",
"release": "babel-node scripts/release.js",
Expand Down
55 changes: 15 additions & 40 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint global-require: 0 */
const fs = require('fs')
const path = require('path')
const { exec, exit, rm, cp, test } = require('shelljs')
Expand All @@ -6,10 +7,6 @@ const { flowRight: compose } = require('lodash')
const readline = require('readline-sync')
const semver = require('semver')
const glob = require('glob')
const { pascalCase } = require('change-case')
const { rollup } = require('rollup')
const uglify = require('rollup-plugin-uglify')
const rollupBaseConfig = require('../rollup.config')

const BIN = './node_modules/.bin'

Expand All @@ -33,8 +30,8 @@ const writeFile = (filepath, string) => (
const run = async () => {
if (exec('git diff-files --quiet').code !== 0) {
logError(
'You have unsaved changes in the working tree. Commit or stash changes ' +
'before releasing.'
'You have unsaved changes in the working tree. ' +
'Commit or stash changes before releasing.'
)
exit(1)
}
Expand All @@ -46,7 +43,7 @@ const run = async () => {
while (!packageNames.includes(packageName)) {
packageName = readline.question(
`The package "${packageName}" does not exist in this project. ` +
`Choose again: `
'Choose again: '
)
}

Expand All @@ -63,7 +60,7 @@ const run = async () => {
)) {
nextVersion = readline.question(
`Must provide a valid version that is greater than ${version}, ` +
`or leave blank to skip: `
'or leave blank to skip: '
)
}

Expand Down Expand Up @@ -122,40 +119,18 @@ const run = async () => {
JSON.stringify(packageConfig, null, 2)
)

const buildRollup = config => {
log(`Building ${config.dest}...`)
return rollup(config).then(bundle => bundle.write(config))
}

const libraryName = pascalCase(packageName)
const rollupConfig = {
...rollupBaseConfig,
entry: path.resolve(sourceDir, 'index.js'),
moduleName: libraryName,
dest: `${outDir}/build/${libraryName}.js`
}
const rollupMinConfig = {
...rollupConfig,
dest: `${outDir}/build/${libraryName}.min.js`,
plugins: [
...rollupConfig.plugins,
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true,
warnings: false
}
})
]
log(`Building ${packageName}...`)
const runRollup = build =>
'rollup --config scripts/rollup.config.js ' +
`--environment BUILD:${build},PACKAGE_NAME:${packageName}`
if (exec([
runRollup('es'),
runRollup('umd'),
runRollup('min')
].join(' && ')).code !== 0) {
exit(1)
}

await Promise.all([
buildRollup(rollupConfig),
buildRollup(rollupMinConfig)
])

log(`About to publish ${packageName}@${nextVersion} to npm.`)
if (!readline.keyInYN('Sound good? ')) {
log('OK. Stopping release.')
Expand Down
68 changes: 60 additions & 8 deletions rollup.config.js → scripts/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
const path = require('path')
const nodeResolve = require('rollup-plugin-node-resolve')
const babel = require('rollup-plugin-babel')
const replace = require('rollup-plugin-replace')
const commonjs = require('rollup-plugin-commonjs')
const uglify = require('rollup-plugin-uglify')
const { pascalCase } = require('change-case')
const { PACKAGES_SRC_DIR, PACKAGES_OUT_DIR } = require('./getPackageNames')

module.exports = {
const build = process.env.BUILD
const packageName = process.env.PACKAGE_NAME
const libraryName = pascalCase(packageName)
const sourceDir = path.resolve(PACKAGES_SRC_DIR, packageName)
const outDir = path.resolve(PACKAGES_OUT_DIR, packageName)

const config = {
entry: `${sourceDir}/index.js`,
external: [
'react'
],
globals: {
react: 'React'
},
// Set library in release script
// moduleName: 'Recompose',
format: 'umd',
moduleName: libraryName,
plugins: [
nodeResolve({
jsnext: true
}),
babel({
exclude: 'node_modules/**',
babelrc: false,
Expand Down Expand Up @@ -48,10 +54,56 @@ module.exports = {
'babel-plugin-transform-regenerator',
'babel-plugin-external-helpers'
]
})
]
}

if (build === 'es') {
config.external.push(
'fbjs/lib/shallowEqual',
'hoist-non-react-statics',
'change-emitter',
'symbol-observable'
)
config.dest = `${outDir}/es/${libraryName}.js`
config.format = 'es'
}

if (build === 'umd') {
config.dest = `${outDir}/build/${libraryName}.js`
config.format = 'umd'
config.plugins.push(
nodeResolve({
jsnext: true
}),
commonjs(),
replace({
'process.env.NODE_ENV': JSON.stringify('development')
})
)
}

if (build === 'min') {
config.dest = `${outDir}/build/${libraryName}.min.js`
config.format = 'umd'
config.plugins.push(
nodeResolve({
jsnext: true
}),
commonjs(),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true,
warnings: false
}
})
]
)
}

export default config
1 change: 1 addition & 0 deletions src/packages/recompose-relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"utilities",
"composition"
],
"module": "es/RecomposeRelay.js",
"dependencies": {
"lodash": "^4.0.0"
},
Expand Down
6 changes: 2 additions & 4 deletions src/packages/recompose/createHelper.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import wrapDisplayName from './wrapDisplayName'

const createHelper = (
func,
helperName,
setDisplayName = true,
noArgs = false
) => {
if (process.env.NODE_ENV !== 'production' && setDisplayName) {
/* eslint-disable global-require */
const wrapDisplayName = require('./wrapDisplayName').default
/* eslint-enable global-require */

if (noArgs) {
return BaseComponent => {
const Component = func(BaseComponent)
Expand Down
4 changes: 1 addition & 3 deletions src/packages/recompose/nest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import createEagerFactory from './createEagerFactory'
import getDisplayName from './getDisplayName'

const nest = (...Components) => {
const factories = Components.map(createEagerFactory)
Expand All @@ -9,9 +10,6 @@ const nest = (...Components) => {
)

if (process.env.NODE_ENV !== 'production') {
/* eslint-disable global-require */
const getDisplayName = require('./getDisplayName').default
/* eslint-enable global-require */
const displayNames = Components.map(getDisplayName)
Nest.displayName = `nest(${displayNames.join(', ')})`
}
Expand Down
4 changes: 1 addition & 3 deletions src/packages/recompose/onlyUpdateForPropTypes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import onlyUpdateForKeys from './onlyUpdateForKeys'
import createHelper from './createHelper'
import getDisplayName from './getDisplayName'

const onlyUpdateForPropTypes = BaseComponent => {
const propTypes = BaseComponent.propTypes

if (process.env.NODE_ENV !== 'production') {
/* eslint-disable global-require */
const getDisplayName = require('./getDisplayName').default
/* eslint-enable global-require */
if (!propTypes) {
/* eslint-disable */
console.error(
Expand Down
1 change: 1 addition & 0 deletions src/packages/recompose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"utilities",
"composition"
],
"module": "es/Recompose.js",
"dependencies": {
"change-emitter": "^0.1.2",
"fbjs": "^0.8.1",
Expand Down
4 changes: 1 addition & 3 deletions src/packages/recompose/renderComponent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import createHelper from './createHelper'
import createEagerFactory from './createEagerFactory'
import wrapDisplayName from './wrapDisplayName'

const renderComponent = Component => _ => {
const factory = createEagerFactory(Component)
const RenderComponent = props => factory(props)
if (process.env.NODE_ENV !== 'production') {
/* eslint-disable global-require */
const wrapDisplayName = require('./wrapDisplayName').default
/* eslint-enable global-require */
RenderComponent.displayName =
wrapDisplayName(Component, 'renderComponent')
}
Expand Down

0 comments on commit 8b44b87

Please sign in to comment.