Skip to content

Commit cfd7428

Browse files
Merge pull request #252 from marvinhagemeister/fix_jsx
Fix jsx error
2 parents 0d77987 + bd6b552 commit cfd7428

File tree

16 files changed

+299
-114
lines changed

16 files changed

+299
-114
lines changed

.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@
1111
"brace-style": "off",
1212
"comma-dangle": ["warn", "always-multiline"],
1313
"indent": "off"
14+
},
15+
"settings": {
16+
"react": {
17+
"version": "16.6"
18+
}
1419
}
1520
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ build
66
dist
77
package-lock.json
88
yarn.lock
9-
.vscode
9+
.vscode
10+
.rts2*

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,3 @@ Here's what's coming up for Microbundle:
111111

112112
[rollup]: https://github.com/rollup/rollup
113113
[bublé]: https://github.com/Rich-Harris/buble
114-
[nodent]: https://github.com/MatAtBread/nodent-compiler

babel.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
exclude: [
7+
'transform-async-to-generator',
8+
'proposal-async-generator-functions',
9+
'transform-regenerator',
10+
],
11+
loose: true,
12+
targets: {
13+
chrome: '58',
14+
ie: '11',
15+
},
16+
},
17+
],
18+
],
19+
plugins: [
20+
['babel-plugin-transform-async-to-promises', { inlineHelpers: true }],
21+
'@babel/plugin-syntax-jsx',
22+
],
23+
};

package.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
77
"bin": "dist/cli.js",
88
"scripts": {
99
"build": "npm run -s build:babel && npm run -s build:self",
10-
"build:babel": "babel-node src/cli.js --target=node --format cjs src/{cli,index}.js --presets env",
10+
"build:babel": "babel-node src/cli.js --target=node --format cjs src/{cli,index}.js",
1111
"build:self": "node dist/cli.js --target=node --format cjs src/{cli,index}.js",
1212
"prepare": "npm run -s build",
13-
"prepare:babel": "babel --presets env src/*.js -d dist && npm t",
13+
"prepare:babel": "babel src/*.js -d dist && npm t",
1414
"lint": "eslint src",
1515
"test": "npm run -s lint && npm run -s build && jest",
1616
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
1717
},
1818
"repository": "developit/microbundle",
19-
"babel": {
20-
"presets": [
21-
"env"
22-
]
23-
},
2419
"prettier": {
2520
"singleQuote": true,
2621
"trailingComma": "all",
@@ -47,39 +42,45 @@
4742
"author": "Jason Miller <[email protected]> (http://jasonformat.com)",
4843
"license": "MIT",
4944
"dependencies": {
50-
"acorn-jsx": "^4.1.1",
45+
"@babel/core": "^7.1.6",
46+
"@babel/plugin-proposal-class-properties": "^7.1.0",
47+
"@babel/plugin-syntax-jsx": "^7.0.0",
48+
"@babel/polyfill": "^7.0.0",
5149
"asyncro": "^3.0.0",
5250
"autoprefixer": "^9.0.0",
53-
"babel-polyfill": "^6.26.0",
51+
"babel-plugin-transform-async-to-promises": "^0.8.1",
5452
"brotli-size": "^0.0.3",
5553
"camelcase": "^5.0.0",
5654
"chalk": "^2.4.0",
5755
"cssnano": "^4.1.7",
5856
"es6-promisify": "^6.0.1",
5957
"gzip-size": "^5.0.0",
6058
"pretty-bytes": "^5.1.0",
61-
"rollup": "^0.66.6",
62-
"rollup-plugin-buble": "^0.19.2",
59+
"rollup": "^0.67.3",
60+
"rollup-plugin-babel": "^4.1.0-0",
61+
"rollup-plugin-buble": "^0.19.4",
6362
"rollup-plugin-bundle-size": "^1.0.1",
6463
"rollup-plugin-commonjs": "^9.0.0",
6564
"rollup-plugin-es3": "^1.1.0",
6665
"rollup-plugin-flow": "^1.1.1",
6766
"rollup-plugin-node-resolve": "^3.3.0",
68-
"rollup-plugin-nodent": "^0.2.2",
6967
"rollup-plugin-postcss": "^1.6.1",
7068
"rollup-plugin-preserve-shebang": "^0.1.6",
7169
"rollup-plugin-sizes": "^0.4.2",
7270
"rollup-plugin-strict-alias": "^1.0.0",
7371
"rollup-plugin-terser": "^3.0.0",
74-
"rollup-plugin-typescript2": "^0.17.2",
72+
"rollup-plugin-typescript2": "^0.18.0",
7573
"sade": "^1.4.0",
7674
"tiny-glob": "^0.2.0",
7775
"tslib": "^1.9.0",
7876
"typescript": ">=2.8.3"
7977
},
8078
"devDependencies": {
81-
"babel-cli": "^6.26.0",
82-
"babel-preset-env": "^1.6.1",
79+
"@babel/cli": "^7.1.5",
80+
"@babel/node": "^7.0.0",
81+
"@babel/preset-env": "^7.1.6",
82+
"babel-core": "^7.0.0-bridge.0",
83+
"babel-jest": "^23.6.0",
8384
"directory-tree": "^2.1.0",
8485
"eslint": "^5.0.0",
8586
"eslint-config-developit": "^1.1.1",
@@ -90,6 +91,7 @@
9091
"jest": "^23.6.0",
9192
"lint-staged": "^8.0.0",
9293
"prettier": "^1.13.0",
94+
"regenerator-runtime": "^0.12.1",
9395
"rimraf": "^2.6.2",
9496
"shell-quote": "^1.6.1",
9597
"strip-ansi": "^5.0.0"

src/cli.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env node
21
import microbundle from '.';
32
import prog from './prog';
43
import { stdout } from './utils';

src/index.js

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'acorn-jsx';
21
import fs from 'fs';
32
import { resolve, relative, dirname, basename, extname } from 'path';
43
import chalk from 'chalk';
@@ -7,8 +6,8 @@ import glob from 'tiny-glob/sync';
76
import autoprefixer from 'autoprefixer';
87
import cssnano from 'cssnano';
98
import { rollup, watch } from 'rollup';
10-
import nodent from 'rollup-plugin-nodent';
119
import commonjs from 'rollup-plugin-commonjs';
10+
import babel from 'rollup-plugin-babel';
1211
import nodeResolve from 'rollup-plugin-node-resolve';
1312
import buble from 'rollup-plugin-buble';
1413
import { terser } from 'rollup-plugin-terser';
@@ -44,6 +43,16 @@ const WATCH_OPTS = {
4443
exclude: 'node_modules/**',
4544
};
4645

46+
// Hoist function because something (rollup?) incorrectly removes it
47+
function formatSize(size, filename, type, raw) {
48+
const pretty = raw ? `${size} B` : prettyBytes(size);
49+
const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow';
50+
const MAGIC_INDENTATION = type === 'br' ? 13 : 10;
51+
return `${' '.repeat(MAGIC_INDENTATION - pretty.length)}${chalk[color](
52+
pretty,
53+
)}: ${chalk.white(basename(filename))}.${type}`;
54+
}
55+
4756
export default async function microbundle(options) {
4857
let cwd = (options.cwd = resolve(process.cwd(), options.cwd)),
4958
hasPackageJson = true;
@@ -97,8 +106,8 @@ export default async function microbundle(options) {
97106
(await isFile(resolve(cwd, filename + '.ts')))
98107
? '.ts'
99108
: (await isFile(resolve(cwd, filename + '.tsx')))
100-
? '.tsx'
101-
: '.js'
109+
? '.tsx'
110+
: '.js'
102111
}`,
103112
);
104113

@@ -108,9 +117,10 @@ export default async function microbundle(options) {
108117
options.entries && options.entries.length
109118
? options.entries
110119
: (options.pkg.source && resolve(cwd, options.pkg.source)) ||
111-
((await isDir(resolve(cwd, 'src'))) && (await jsOrTs('src/index'))) ||
112-
(await jsOrTs('index')) ||
113-
options.pkg.module,
120+
((await isDir(resolve(cwd, 'src'))) &&
121+
(await jsOrTs('src/index'))) ||
122+
(await jsOrTs('index')) ||
123+
options.pkg.module,
114124
)
115125
.map(file => glob(file))
116126
.forEach(file => options.input.push(...file));
@@ -146,15 +156,6 @@ export default async function microbundle(options) {
146156
}
147157
}
148158

149-
function formatSize(size, filename, type, raw) {
150-
const pretty = raw ? `${size} B` : prettyBytes(size);
151-
const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow';
152-
const MAGIC_INDENTATION = type === 'br' ? 13 : 10;
153-
return `${' '.repeat(MAGIC_INDENTATION - pretty.length)}${chalk[color](
154-
pretty,
155-
)}: ${chalk.white(basename(filename))}.${type}`;
156-
}
157-
158159
async function getSizeInfo(code, filename) {
159160
const raw = options.raw || code.length < 5000;
160161
const gzip = formatSize(await gzipSize(code), filename, 'gz', raw);
@@ -322,6 +323,9 @@ function createConfig(options, entry, format, writeMeta) {
322323
inputOptions: {
323324
input: exportType ? resolve(__dirname, '../src/lib/__entry__.js') : entry,
324325
external: id => {
326+
if (id === 'babel-plugin-transform-async-to-promises/helpers') {
327+
return false;
328+
}
325329
if (options.multipleEntries && id === '.') {
326330
return true;
327331
}
@@ -355,31 +359,39 @@ function createConfig(options, entry, format, writeMeta) {
355359
jsx: options.jsx,
356360
},
357361
},
362+
tsconfigOverride: {
363+
compilerOptions: {
364+
target: 'es2017',
365+
},
366+
},
358367
}),
359368
!useTypescript && flow({ all: true, pretty: true }),
360-
nodent({
369+
// Only used for async await
370+
babel({
371+
// We mainly use bublé to transpile JS and only use babel to
372+
// transpile down `async/await`. To prevent conflicts with user
373+
// supplied configurations we set this option to false. Note
374+
// that we never supported using custom babel configs anyway.
375+
babelrc: false,
361376
exclude: 'node_modules/**',
362-
noRuntime: true,
363-
promises: true,
364-
transformations: {
365-
forOf: false,
366-
},
367-
parser: {
368-
plugins: {
369-
jsx: true,
370-
},
377+
plugins: [
378+
'@babel/plugin-syntax-jsx',
379+
[
380+
'babel-plugin-transform-async-to-promises',
381+
{ inlineHelpers: true, externalHelpers: true },
382+
],
383+
['@babel/plugin-proposal-class-properties', { loose: true }],
384+
],
385+
}),
386+
buble({
387+
exclude: 'node_modules/**',
388+
jsx: options.jsx || 'h',
389+
objectAssign: options.assign || 'Object.assign',
390+
transforms: {
391+
dangerousForOf: true,
392+
dangerousTaggedTemplateString: true,
371393
},
372394
}),
373-
!useTypescript &&
374-
buble({
375-
exclude: 'node_modules/**',
376-
jsx: options.jsx || 'h',
377-
objectAssign: options.assign || 'Object.assign',
378-
transforms: {
379-
dangerousForOf: true,
380-
dangerousTaggedTemplateString: true,
381-
},
382-
}),
383395
useNodeResolve &&
384396
commonjs({
385397
include: 'node_modules/**',

0 commit comments

Comments
 (0)