From 236fa3f4de808c1980c61a697e2d16cb2ffd6333 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 23 Jan 2018 14:52:55 -0500 Subject: [PATCH] Automatically detect and use `index.ts` & `src/index.ts` entry rather than requiring it to be manually specified. --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 27003c3..b395106 100644 --- a/src/index.js +++ b/src/index.js @@ -55,9 +55,11 @@ export default async function microbundle(options) { } } + const jsOrTs = async filename => resolve(cwd, `${filename}${await isFile(resolve(cwd, filename+'.ts')) ? '.ts' : '.js'}`); + options.input = []; [].concat( - options.entries && options.entries.length ? options.entries : options.pkg.source || (await isDir(resolve(cwd, 'src')) && 'src/index.js') || (await isFile(resolve(cwd, 'index.js')) && 'index.js') || options.pkg.module + options.entries && options.entries.length ? options.entries : options.pkg.source || (await isDir(resolve(cwd, 'src')) && await jsOrTs('src/index')) || await jsOrTs('index') || options.pkg.module ).map( file => glob.sync(resolve(cwd, file)) ).forEach( file => options.input.push(...file) ); let main = resolve(cwd, options.output || options.pkg.main || 'dist');