-
Notifications
You must be signed in to change notification settings - Fork 360
Description
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.
Lines 297 to 303 in b1a6374
| mainsByFormat.modern = replaceName( | |
| (pkg.exports && walk(pkg.exports)) || | |
| (pkg.syntax && pkg.syntax.esmodules) || | |
| pkg.esmodule || | |
| 'x.modern.js', | |
| mainNoExtension, | |
| ); |
Lines 255 to 260 in b1a6374
| function replaceName(filename, name) { | |
| return resolve( | |
| dirname(filename), | |
| name + basename(filename).replace(/^[^.]+/, ''), | |
| ); | |
| } |
mainNoExtension traces back to here, which defines a couple of fallbacks.
Lines 219 to 225 in b1a6374
| 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.