Skip to content

Commit

Permalink
Support Async/Await in Rollup Plugins (#208)
Browse files Browse the repository at this point in the history
* feat: support rollup-plugins that use async/await

fix: tweak plugin and build config re types/declarations

fix: remove console.log; reimplement babel-plugin

chore: resolve PR comments

* chore: address feedback, fix conflicts, & rebase
  • Loading branch information
Michael Edelman authored and jaredpalmer committed Oct 11, 2019
1 parent a99f216 commit bfc0590
Show file tree
Hide file tree
Showing 6 changed files with 1,585 additions and 2,012 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
"@babel/core": "^7.4.4",
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-regenerator": "^7.4.5",
"@babel/plugin-transform-runtime": "^7.6.0",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@typescript-eslint/eslint-plugin": "^2.3.1",
"@typescript-eslint/parser": "^2.3.1",
"@wessberg/rollup-plugin-ts": "^1.1.65",
"ansi-escapes": "^3.2.0",
"asyncro": "^3.0.0",
"babel-eslint": "^10.0.3",
Expand Down Expand Up @@ -83,7 +86,6 @@
"rollup-plugin-size-snapshot": "^0.8.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.21.1",
"sade": "^1.4.2",
"tiny-glob": "^0.2.6",
"ts-jest": "^24.0.2",
Expand Down
32 changes: 17 additions & 15 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import json from 'rollup-plugin-json';
import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript2';
import ts from '@wessberg/rollup-plugin-ts';
import { ScriptTarget, JsxEmit } from 'typescript';
import path from 'path';
import { extractErrors } from './errors/extractErrors';
import { babelPluginTsdx } from './babelPluginTsdx';
import { TsdxOptions } from './types';
Expand Down Expand Up @@ -125,22 +127,22 @@ export function createRollupConfig(opts: TsdxOptions) {
};
},
},
typescript({
typescript: require('typescript'),
cacheRoot: `./.rts2_cache_${opts.format}`,
tsconfig: opts.tsconfig,
tsconfigDefaults: {
compilerOptions: {
sourceMap: true,
declaration: true,
jsx: 'react',
},
},
tsconfigOverride: {
compilerOptions: {
target: 'esnext',
ts({
hook: {
outputPath: (fp, kind) => {
if (/declaration/.test(kind) && opts.format === 'esm') {
return path.join(path.dirname(fp), 'index.d.ts');
}
},
},
tsconfig: tsconfig => ({
...tsconfig,
target: ScriptTarget.ESNext,
sourceMap: true,
declaration: opts.format === 'esm',
jsx: JsxEmit.React,
}),
transpiler: 'babel',
}),
babelPluginTsdx({
exclude: 'node_modules/**',
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ prog
version: '0.1.0',
main: 'dist/index.js',
module: `dist/${safeName}.esm.js`,
typings: 'dist/index.d.ts',
typings: `dist/index.d.ts`,
files: ['dist'],
scripts: {
start: 'tsdx watch',
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/build-default/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"jsx": "react",
"esModuleInterop": true
},
"include": ["src", "types"],
}
"include": ["src", "types"]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"noImplicitAny": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"target": "es2017",
"target": "es2017"
}
}
}
Loading

0 comments on commit bfc0590

Please sign in to comment.