Skip to content

Commit

Permalink
fix(build): missing babel helpers, true esm modules, simplify (#290)
Browse files Browse the repository at this point in the history
* fix(build): remove redundent Rollup Flow plugin

- This is already handled by babel-preset-flow

* fix(build): no longer override esm build with commonjs

- Use Rollup for both cjs and esm build
- Don't re-run babel on top preventing overrides

* fix(build): Don't exlude Babel helpers from bundle

- Since only the typeof helper is used, it's much more simple and
efficient to include it.

* fix(test): allow ES modules require in smoke tests
  • Loading branch information
pascalduez authored and vvo committed Jun 20, 2018
1 parent 526267e commit faa8f46
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -24,7 +24,7 @@ script:
- yarn run smoke esm 15.6.2
- yarn run smoke cjs 16.1.0
- yarn run smoke esm 16.1.0
- yarn run smoke cjs default
- yarn run smoke esm default
- yarn run smoke cjs latest
- yarn run smoke esm latest
- yarn run smoke cjs next
- yarn run smoke esm next
Empty file removed dist/cjs/.gitkeep
Empty file.
Empty file removed dist/esm/.gitkeep
Empty file.
16 changes: 6 additions & 10 deletions package.json
Expand Up @@ -6,14 +6,11 @@
"module": "dist/esm/index.js",
"browser": "dist/cjs/index.js",
"scripts": {
"clean": "npm run esm:clean && npm run cjs:clean",
"build": "npm run esm:build && npm run cjs:build",
"preesm:build": "npm run esm:clean",
"esm:build": "babel ./src/ --ignore=*.spec.js --source-maps --out-dir ./dist/esm && flow-copy-source -v --ignore=*.spec.js src/ dist/esm",
"esm:clean": "rm -rf ./dist/esm/*",
"precjs:build": "npm run cjs:clean",
"cjs:build": "rollup --config rollup.config.js",
"cjs:clean": "rm -rf ./dist/cjs/*",
"build": "rollup -c",
"build:flow": "flow-copy-source -v --ignore=*.spec.js src/ dist/cjs",
"prebuild": "rm -rf dist/",
"postbuild": "npm run build:flow",
"prepare": "npm run build",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"flow": "flow",
Expand Down Expand Up @@ -43,7 +40,6 @@
"babel-cli": "6.26.0",
"babel-eslint": "8.2.3",
"babel-jest": "22.2.2",
"babel-plugin-external-helpers": "6.22.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-flow": "6.23.0",
"babel-preset-react": "6.24.1",
Expand All @@ -58,6 +54,7 @@
"eslint-plugin-jest": "21.17.0",
"eslint-plugin-prettier": "2.6.0",
"eslint-plugin-react": "7.9.1",
"esm": "^3.0.51",
"expect": "22.3.0",
"flow-bin": "0.74.0",
"flow-copy-source": "2.0.0",
Expand All @@ -73,7 +70,6 @@
"rollup": "0.60.7",
"rollup-plugin-babel": "3.0.4",
"rollup-plugin-commonjs": "9.1.3",
"rollup-plugin-flow": "1.1.1",
"rollup-plugin-node-builtins": "2.1.2",
"rollup-plugin-node-globals": "1.2.1",
"rollup-plugin-node-resolve": "3.3.0",
Expand Down
32 changes: 15 additions & 17 deletions rollup.config.js
@@ -1,26 +1,27 @@
import fs from 'fs';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import flow from 'rollup-plugin-flow';
import resolve from 'rollup-plugin-node-resolve';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import pkg from './package.json';

const extractPackagePeerDependencies = () => {
const packageNpm = JSON.parse(
fs.readFileSync('./package.json', { encoding: 'utf8' })
);

return Object.keys(packageNpm.peerDependencies || {});
};
const extractPackagePeerDependencies = () =>
Object.keys(pkg.peerDependencies) || [];

export default {
input: 'src/index.js',
output: {
file: 'dist/cjs/index.js',
format: 'cjs',
sourcemap: true,
},
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
},
],
external: extractPackagePeerDependencies(),
plugins: [
babel({
Expand All @@ -39,8 +40,6 @@ export default {
'react',
'flow',
],
plugins: ['external-helpers'],
externalHelpers: true,
}),
resolve({
module: true,
Expand All @@ -56,6 +55,5 @@ export default {
}),
globals(),
builtins(),
flow(),
],
};
4 changes: 0 additions & 4 deletions tests/smoke/prepare.js
Expand Up @@ -31,10 +31,6 @@ const deleteExistingDependencies = () => () => {
};

const preparePackageJson = reactVersion => () => {
if (reactVersion === 'default') {
return;
}

const packageJson = {
name: 'smoke',
version: '0.0.1',
Expand Down
5 changes: 3 additions & 2 deletions tests/smoke/smoke.js
@@ -1,7 +1,8 @@
#!/usr/bin/env node

/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console, import/no-extraneous-dependencies, no-global-assign */

require = require('esm')(module);

const requireReactElementToJsxString = buildType => {
if (buildType === 'esm') {
Expand Down
28 changes: 6 additions & 22 deletions yarn.lock
Expand Up @@ -766,12 +766,6 @@ babel-plugin-check-es2015-constants@^6.22.0:
dependencies:
babel-runtime "^6.22.0"

babel-plugin-external-helpers@6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-external-helpers/-/babel-plugin-external-helpers-6.22.0.tgz#2285f48b02bd5dede85175caf8c62e86adccefa1"
dependencies:
babel-runtime "^6.22.0"

babel-plugin-istanbul@^4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.5.tgz#6760cdd977f411d3e175bb064f2bc327d99b2b6e"
Expand Down Expand Up @@ -1226,7 +1220,7 @@ babylon@7.0.0-beta.44:
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.44.tgz#89159e15e6e30c5096e22d738d8c0af8a0e8ca1d"

babylon@^6.15.0, babylon@^6.18.0:
babylon@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"

Expand Down Expand Up @@ -2513,6 +2507,10 @@ eslint@4.19.1:
table "4.0.2"
text-table "~0.2.0"

esm@^3.0.51:
version "3.0.51"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.0.51.tgz#35c3bcd0237867ab09020728135bfdb91ec79c90"

espree@^3.5.4:
version "3.5.4"
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7"
Expand Down Expand Up @@ -2825,13 +2823,6 @@ flow-copy-source@2.0.0:
kefir "^3.7.3"
yargs "^11.0.0"

flow-remove-types@^1.1.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/flow-remove-types/-/flow-remove-types-1.2.3.tgz#6131aefc7da43364bb8b479758c9dec7735d1a18"
dependencies:
babylon "^6.15.0"
vlq "^0.2.1"

for-in@^1.0.1, for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand Down Expand Up @@ -6021,13 +6012,6 @@ rollup-plugin-commonjs@9.1.3:
resolve "^1.5.0"
rollup-pluginutils "^2.0.1"

rollup-plugin-flow@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-flow/-/rollup-plugin-flow-1.1.1.tgz#6ce568f1dd559666b77ab76b4bae251407528db6"
dependencies:
flow-remove-types "^1.1.0"
rollup-pluginutils "^1.5.1"

rollup-plugin-node-builtins@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-builtins/-/rollup-plugin-node-builtins-2.1.2.tgz#24a1fed4a43257b6b64371d8abc6ce1ab14597e9"
Expand Down Expand Up @@ -6063,7 +6047,7 @@ rollup-plugin-sourcemaps@0.4.2:
rollup-pluginutils "^2.0.1"
source-map-resolve "^0.5.0"

rollup-pluginutils@^1.5.0, rollup-pluginutils@^1.5.1:
rollup-pluginutils@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408"
dependencies:
Expand Down

0 comments on commit faa8f46

Please sign in to comment.