Refactor the jsOrTs function

* Calc the extension and save it in a const to make the code simpler
This commit is contained in:
Matías Olivera 2019-01-03 14:47:28 -03:00
parent 1e7c9b3a3d
commit 3acca423bc

View File

@ -69,18 +69,6 @@ export default async function microbundle(inputOptions) {
options.sourcemap = true;
}
const jsOrTs = async filename =>
resolve(
cwd,
`${filename}${
(await isFile(resolve(cwd, filename + '.ts')))
? '.ts'
: (await isFile(resolve(cwd, filename + '.tsx')))
? '.tsx'
: '.js'
}`,
);
options.input = [];
[]
.concat(
@ -88,8 +76,8 @@ export default async function microbundle(inputOptions) {
? options.entries
: (options.pkg.source && resolve(cwd, options.pkg.source)) ||
((await isDir(resolve(cwd, 'src'))) &&
(await jsOrTs('src/index'))) ||
(await jsOrTs('index')) ||
(await jsOrTs(cwd, 'src/index'))) ||
(await jsOrTs(cwd, 'index')) ||
options.pkg.module,
)
.map(file => glob(file))
@ -247,6 +235,16 @@ function getName({ name, pkgName, amdName, cwd, hasPackageJson }) {
return name || amdName || safeVariableName(pkgName);
}
async function jsOrTs(cwd, filename) {
const extension = (await isFile(resolve(cwd, filename + '.ts')))
? '.ts'
: (await isFile(resolve(cwd, filename + '.tsx')))
? '.tsx'
: '.js';
return resolve(cwd, `${filename}${extension}`);
}
function createConfig(options, entry, format, writeMeta) {
let { pkg } = options;