Skip to content

Commit

Permalink
Fix TypeScript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmurphy committed Jan 19, 2020
1 parent 34a1093 commit cf98a87
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
32 changes: 19 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import babelPresetEnv from '@babel/preset-env';
import babelPresetTypescript from '@babel/preset-typescript';
import builtinModules from 'builtin-modules';
import { outputFile, readFile } from 'fs-extra';
import { rollup, watch, OutputOptions, InputOptions } from 'rollup';
import {
rollup,
watch,
OutputOptions,
InputOptions,
RollupWarning,
RollupWatchOptions,
} from 'rollup';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import dts from 'rollup-plugin-dts';
Expand Down Expand Up @@ -126,7 +133,7 @@ async function createRollupConfig({
return { inputOptions, outputOptions };
}

function dtsOnWarn(warning: { code: string; message: string }) {
function dtsOnWarn(warning: RollupWarning) {
if (warning.code === 'EMPTY_BUNDLE') return;

console.error(warning.message);
Expand All @@ -140,7 +147,7 @@ async function createTypes({
outputDir: string;
}) {
// build our Rollup input options for rollup-plugin-dts
const inputOptions = {
const inputOptions: InputOptions = {
input,
plugins: [dts()],
onwarn: dtsOnWarn,
Expand All @@ -153,7 +160,7 @@ async function createTypes({
const { name } = parse(input);

// build our Rollup output options
const outputOptions = {
const outputOptions: OutputOptions = {
file: resolve(outputDir, format({ name, ext: '.d.ts' })),
format: 'esm',
};
Expand Down Expand Up @@ -234,7 +241,7 @@ export async function bundler({

for (const { inputOptions, outputOptions } of runs) {
if (watchBuild) {
const watcher = watch(
const watchOptions: RollupWatchOptions[] = [
Object.assign(
{
output: outputOptions,
Expand All @@ -243,16 +250,15 @@ export async function bundler({
},
},
inputOptions
)
);
),
];

const watcher = watch(watchOptions);

watcher.on('event', ({ code, error }) => {
switch (code) {
case 'FATAL':
throw new Error(error);
watcher.on('event', event => {
switch (event.code) {
case 'ERROR':
console.error(error);
break;
throw event.error;
case 'END':
console.log(`Successful build. (${inputOptions.input})`);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/vendor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '@babel/preset-env';
declare module '@babel/preset-typescript';
declare module 'rollup-plugin-babel';
declare module 'rollup-plugin-json';
4 changes: 0 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"target": "esnext",
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
// Process & infer types from .js files.
"allowJs": true,
// Don't emit; allow Babel to transform files.
"noEmit": true,
// Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": true,
// Disallow features that require cross-file information for emit.
Expand Down

0 comments on commit cf98a87

Please sign in to comment.