Permalink
Browse files

Prepared build infrastructure, shipping es, cjs and umd formats

  • Loading branch information...
Andarist authored and mridgway committed Dec 22, 2017
1 parent 46b58b6 commit 03a7f2f87ae9d9a41696b2a7f109aa1aab6b9eab
Showing with 135 additions and 87 deletions.
  1. +2 −0 .eslintrc
  2. +1 −0 .gitignore
  3. +0 −6 .npmignore
  4. +0 −72 index.js
  5. +18 −7 package.json
  6. +48 −0 rollup.config.js
  7. +64 −0 src/index.js
  8. +1 −1 tests/.babelrc
  9. +1 −1 tests/unit/index.js
View
@@ -1,4 +1,6 @@
---
parserOptions:
sourceType: 'module'
env:
node: true
rules:
View
@@ -1,4 +1,5 @@
/artifacts/
/build/
dist
node_modules
npm-debug.log
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -2,16 +2,25 @@
"name": "hoist-non-react-statics",
"version": "2.5.0",
"description": "Copies non-react specific statics from a child component to a parent component",
"main": "index.js",
"main": "dist/hoist-non-react-statics.cjs.js",
"module": "src/index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/mridgway/hoist-non-react-statics.git"
},
"files": [
"src",
"dist"
],
"scripts": {
"cover": "node node_modules/istanbul/lib/cli.js cover --dir artifacts -- ./node_modules/mocha/bin/_mocha tests/unit/ --recursive --compilers js:babel/register --reporter spec",
"lint": "eslint ./index.js",
"test": "mocha tests/unit/ --recursive --compilers js:babel-register --reporter spec"
"lint": "eslint src",
"prebuild": "rimraf dist",
"build": "rollup -c",
"pretest": "npm run build",
"test": "mocha tests/unit/ --recursive --compilers js:babel-register --reporter spec",
"prepublish": "npm test"
},
"author": "Michael Ridgway <mcridgway@gmail.com>",
"license": "BSD-3-Clause",
@@ -20,18 +29,20 @@
"babel-cli": "^6.24.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-react-jsx-source": "^6.22.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.24.1",
"chai": "^4.0.1",
"coveralls": "^2.11.1",
"create-react-class": "^15.5.3",
"eslint": "^3.8.0",
"eslint": "^4.13.1",
"istanbul": "^0.4.5",
"mocha": "^3.4.2",
"pre-commit": "^1.0.7",
"react": "^15.0.0"
"react": "^15.0.0",
"rimraf": "^2.6.2",
"rollup": "^0.52.3",
"rollup-plugin-uglify": "^2.0.1"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
View
@@ -0,0 +1,48 @@
import uglify from 'rollup-plugin-uglify'
import pkg from './package.json'
const mergeAll = objs => Object.assign({}, ...objs)
const camelCase = string => {
const [first, ...rest] = string.split('-').map(str => str.toLowerCase())
return first + rest.map(str => str[0].toUpperCase() + str.slice(1)).join('')
}
const configBase = {
input: 'src/index.js',
}
const umdConfig = mergeAll([
configBase,
{
output: {
file: `dist/${pkg.name}.js`,
format: 'umd',
name: camelCase(pkg.name),
},
},
])
const prodUmdConfig = mergeAll([
umdConfig,
{ output: mergeAll([umdConfig.output, { file: umdConfig.output.file.replace(/\.js$/, '.min.js') }]) },
{
plugins: [
uglify({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
})
],
},
])
const cjsConfig = mergeAll([
configBase,
{ output: { file: pkg.main, format: 'cjs' } },
])
export default [umdConfig, prodUmdConfig, cjsConfig]
View
@@ -0,0 +1,64 @@
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
var REACT_STATICS = {
childContextTypes: true,
contextTypes: true,
defaultProps: true,
displayName: true,
getDefaultProps: true,
getDerivedStateFromProps: true,
mixins: true,
propTypes: true,
type: true
};
var KNOWN_STATICS = {
name: true,
length: true,
prototype: true,
caller: true,
callee: true,
arguments: true,
arity: true
};
var defineProperty = Object.defineProperty;
var getOwnPropertyNames = Object.getOwnPropertyNames;
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
var getPrototypeOf = Object.getPrototypeOf;
var objectPrototype = getPrototypeOf && getPrototypeOf(Object);
export default function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components
if (objectPrototype) {
var inheritedComponent = getPrototypeOf(sourceComponent);
if (inheritedComponent && inheritedComponent !== objectPrototype) {
hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
}
}
var keys = getOwnPropertyNames(sourceComponent);
if (getOwnPropertySymbols) {
keys = keys.concat(getOwnPropertySymbols(sourceComponent));
}
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
if (!REACT_STATICS[key] && !KNOWN_STATICS[key] && (!blacklist || !blacklist[key])) {
var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
try { // Avoid failures from read-only properties
defineProperty(targetComponent, key, descriptor);
} catch (e) {}
}
}
return targetComponent;
}
return targetComponent;
};
View
@@ -1,5 +1,5 @@
{
"presets": ["es2015", "es2016", "react"],
"presets": ["env", "react"],
"plugins": [
"transform-class-properties"
]
View
@@ -4,7 +4,7 @@
var expect = require('chai').expect;
var React = require('react');
var createReactClass = require('create-react-class');
var hoistNonReactStatics = require('../../index');
var hoistNonReactStatics = require('../..');
describe('hoist-non-react-statics', function () {

0 comments on commit 03a7f2f

Please sign in to comment.