Packages that don't use the output flag or have a "main" in their package.json have their preferred filename output ignored.
For example, say I have the following package:
{
"name": "foo",
"exports": {
".": "./dist/bar.js",
...
}
}
Unfortunately, because of the replaceName() here, the desired output is replaced by the package name instead.
|
mainsByFormat.modern = replaceName( |
|
(pkg.exports && walk(pkg.exports)) || |
|
(pkg.syntax && pkg.syntax.esmodules) || |
|
pkg.esmodule || |
|
'x.modern.js', |
|
mainNoExtension, |
|
); |
|
function replaceName(filename, name) { |
|
return resolve( |
|
dirname(filename), |
|
name + basename(filename).replace(/^[^.]+/, ''), |
|
); |
|
} |
mainNoExtension traces back to here, which defines a couple of fallbacks.
|
async function getOutput({ cwd, output, pkgMain, pkgName }) { |
|
let main = resolve(cwd, output || pkgMain || 'dist'); |
|
if (!main.match(/\.[a-z]+$/) || (await isDir(main))) { |
|
main = resolve(main, `${removeScope(pkgName)}.js`); |
|
} |
|
return main; |
|
} |
I can't really say that I understand why this was done in the first place, so don't want to go "fixing" it as there might be some relying on this. To me, it seems like that in the absence of the output flag, these fields should be read and used exactly, no replacing.
mainNoExtension seems like it should be the last of the fallbacks, not something that overwrites valid entries & chosen names.
Packages that don't use the
outputflag or have a"main"in theirpackage.jsonhave their preferred filename output ignored.For example, say I have the following package:
Unfortunately, because of the
replaceName()here, the desired output is replaced by the package name instead.microbundle/src/index.js
Lines 297 to 303 in b1a6374
microbundle/src/index.js
Lines 255 to 260 in b1a6374
mainNoExtensiontraces back to here, which defines a couple of fallbacks.microbundle/src/index.js
Lines 219 to 225 in b1a6374
I can't really say that I understand why this was done in the first place, so don't want to go "fixing" it as there might be some relying on this. To me, it seems like that in the absence of the
outputflag, these fields should be read and used exactly, no replacing.mainNoExtensionseems like it should be the last of the fallbacks, not something that overwrites valid entries & chosen names.