mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Create getName function
This commit is contained in:
parent
fd7b890cb8
commit
b696954a15
41
src/index.js
41
src/index.js
@ -62,23 +62,13 @@ export default async function microbundle(inputOptions) {
|
||||
const { hasPackageJson, pkg } = await getConfigFromPkgJson(cwd);
|
||||
options.pkg = pkg;
|
||||
|
||||
if (!options.pkg.name) {
|
||||
options.pkg.name = basename(options.cwd);
|
||||
if (hasPackageJson) {
|
||||
stderr(
|
||||
chalk.yellow(
|
||||
`${chalk.yellow.inverse(
|
||||
'WARN',
|
||||
)} missing package.json "name" field. Assuming "${
|
||||
options.pkg.name
|
||||
}".`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
options.name =
|
||||
options.name || options.pkg.amdName || safeVariableName(options.pkg.name);
|
||||
options.name = getName({
|
||||
name: options.name,
|
||||
pkgName: options.pkg.name,
|
||||
amdName: options.pkg.amdName,
|
||||
hasPackageJson,
|
||||
cwd,
|
||||
});
|
||||
|
||||
if (options.sourcemap !== false) {
|
||||
options.sourcemap = true;
|
||||
@ -238,6 +228,23 @@ async function getConfigFromPkgJson(cwd) {
|
||||
}
|
||||
}
|
||||
|
||||
function getName({ name, pkgName, amdName, cwd, hasPackageJson }) {
|
||||
if (!pkgName) {
|
||||
pkgName = basename(cwd);
|
||||
if (hasPackageJson) {
|
||||
stderr(
|
||||
chalk.yellow(
|
||||
`${chalk.yellow.inverse(
|
||||
'WARN',
|
||||
)} missing package.json "name" field. Assuming "${pkgName}".`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return name || amdName || safeVariableName(pkgName);
|
||||
}
|
||||
|
||||
function createConfig(options, entry, format, writeMeta) {
|
||||
let { pkg } = options;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user