developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.03k stars 362 forks source link

Packages with `npm:` are copied into dist even if they are described in `dependencies`. #955

Closed arthurfiorette closed 2 years ago

arthurfiorette commented 2 years ago

If, in my code, I use import {} from 'package', and in my package.json I use "npm:package" instead of "package", package is copied into bundle, the same way as if it was described inside devDependencies.

rschristian commented 2 years ago

Can you provide an example?

package is copied into bundle, the same way as if it was described inside devDependencies.

Do you mean the module is inlined? I cannot reproduce.

arthurfiorette commented 2 years ago

Exactly, the module gets inlined

rschristian commented 2 years ago

Are you writing the following?

{
    "dependencies": {
        "npm:foo": "latest"
    }
}

If so, why?

arthurfiorette commented 2 years ago

I'm working with a very unique setup...

I'm writing nom:dependency because it is inside a monorepo and I need to install the version from NPM instead of the local one.

I can't give you a reproductive example right now, but it is a OSS repository.

https://github.com/arthurfiorette/tinylibs/tree/main/packages/axios-cache-hooks

By writing npm:object-code it is going to fetch the npm version instead of the local one, but it will inline it too.

rschristian commented 2 years ago

I'm pretty sure what you want to be writing is this:

{
    "dependencies": {
        "foo": "npm:foo"
    }
}

I see 0 information or support around npm:pkg as a valid key for dependencies. It looks to just be ignored.

Edit: The root issue here is that we don't strip protocols from package names, so "npm:foo" in your dependencies list only makes usage of "npm:foo" external. I'm not convinced that there's a real reason for us to support this, as it looks like you're relying on chance behaviour more than anything by using that protocol (please correct me if I'm wrong, but I haven't been able to find a single reference documenating or supporting the behaviour you're after by using that).

You can always use the --external flag to specify what should and should not be external, i.e., $ yarn microbundle build --external foo will ensure that foo will not be inlined.

arthurfiorette commented 2 years ago

Hey, You're right!

The "correct" usage should be "foo": "npm:foo". Thanks for your super fast help!!!