1- import 'acorn-jsx' ;
21import fs from 'fs' ;
32import { resolve , relative , dirname , basename , extname } from 'path' ;
43import chalk from 'chalk' ;
@@ -7,8 +6,8 @@ import glob from 'tiny-glob/sync';
76import autoprefixer from 'autoprefixer' ;
87import cssnano from 'cssnano' ;
98import { rollup , watch } from 'rollup' ;
10- import nodent from 'rollup-plugin-nodent' ;
119import commonjs from 'rollup-plugin-commonjs' ;
10+ import babel from 'rollup-plugin-babel' ;
1211import nodeResolve from 'rollup-plugin-node-resolve' ;
1312import buble from 'rollup-plugin-buble' ;
1413import { 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+
4756export 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