mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Refactor the jsOrTs function
* Calc the extension and save it in a const to make the code simpler
This commit is contained in:
parent
1e7c9b3a3d
commit
3acca423bc
26
src/index.js
26
src/index.js
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user