Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Shouldn't fall back to pkg name in the absence of output flag & pkg main #884

Open
rschristian opened this issue Aug 26, 2021 · 0 comments · May be fixed by #896
Open

Bug: Shouldn't fall back to pkg name in the absence of output flag & pkg main #884

rschristian opened this issue Aug 26, 2021 · 0 comments · May be fixed by #896

Comments

@rschristian
Copy link
Collaborator

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.

microbundle/src/index.js

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,
);

microbundle/src/index.js

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.

microbundle/src/index.js

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.

@rschristian rschristian linked a pull request Sep 15, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant