Skip to content

Commit

Permalink
Fix --format=es (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer authored May 31, 2019
1 parent e1c3c68 commit 47fb723
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

import sade from 'sade';
import glob from 'tiny-glob/sync';
import { rollup, watch, RollupOptions, OutputOptions } from 'rollup';
import {
rollup,
watch,
RollupOptions,
OutputOptions,
RollupWatchOptions,
WatcherOptions,
} from 'rollup';
import asyncro from 'asyncro';
import chalk from 'chalk';
import util from 'util';
Expand All @@ -17,12 +24,7 @@ import { paths } from './constants';
import * as Messages from './messages';
import { createRollupConfig } from './createRollupConfig';
import { createJestConfig } from './createJestConfig';
import {
safeVariableName,
resolveApp,
safePackageName,
clearConsole,
} from './utils';
import { resolveApp, safePackageName, clearConsole } from './utils';
import * as Output from './output';
import { concatAllArray } from 'jpjs';
import getInstallCmd from './getInstallCmd';
Expand Down Expand Up @@ -84,7 +86,9 @@ async function getInputs(entries: string[], source?: string) {

return concatAllArray(inputs);
}
function createBuildConfigs(opts: any) {
function createBuildConfigs(
opts: any
): Array<RollupOptions & { output: OutputOptions }> {
return concatAllArray(
opts.input.map((input: string) => [
opts.format.includes('cjs') &&
Expand Down Expand Up @@ -252,7 +256,7 @@ prog
.action(async (opts: any) => {
opts.name = opts.name || appPackageJson.name;
opts.input = await getInputs(opts.entry, appPackageJson.source);
const [cjsDev, cjsProd, ...otherConfigs] = createBuildConfigs(opts);
const buildConfigs = createBuildConfigs(opts);
if (opts.format.includes('cjs')) {
await util.promisify(mkdirp)(resolveApp('dist'));
await fs.writeFile(
Expand All @@ -273,12 +277,12 @@ prog
}
const spinner = ora().start();
await watch(
[cjsDev, cjsProd, ...otherConfigs].map(inputOptions => ({
(buildConfigs as RollupWatchOptions[]).map(inputOptions => ({
watch: {
silent: true,
include: 'src/**',
exclude: 'node_modules/**',
},
include: ['src/**'],
exclude: ['node_modules/**'],
} as WatcherOptions,
...inputOptions,
}))
).on('event', async event => {
Expand Down Expand Up @@ -322,7 +326,7 @@ prog
.action(async (opts: any) => {
opts.name = opts.name || appPackageJson.name;
opts.input = await getInputs(opts.entry, appPackageJson.source);
const [cjsDev, cjsProd, ...otherConfigs] = createBuildConfigs(opts);
const buildConfigs = createBuildConfigs(opts);
if (opts.format.includes('cjs')) {
try {
await util.promisify(mkdirp)(resolveApp('./dist'));
Expand Down Expand Up @@ -353,7 +357,7 @@ prog
try {
const promise = asyncro
.map(
[cjsDev, cjsProd, ...otherConfigs],
buildConfigs,
async (inputOptions: RollupOptions & { output: OutputOptions }) => {
let bundle = await rollup(inputOptions);
await bundle.write(inputOptions.output);
Expand Down

0 comments on commit 47fb723

Please sign in to comment.