-
Notifications
You must be signed in to change notification settings - Fork 0
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
flag for packages that need to be unique #1
Comments
I think this is outside the scope of all current bundlers / module installers. For instance, JavaScript registers web components using an imperative API ( |
copied over from issue on package-name-maps: @arcanis Actually, it's not a requirement of pnm - but first recap the main goal of pnm as far as I understood. Keeping that in mind it means that we may have a lot of files on our server but we still want to ship as little a possible to our users/browser. Naturally, that means we don't want to ship code doing the same thing multiple times. So using like 4 versions of for example Entering WebcomponentsFor custom elements it's just not possibele to use different versions of the same element. It's a requirement of CustomElementRegistry. The relevant part is
In good old english this means: "Each custom elements tag name needs to be unique within a browsers Window object". Also a nice comment about it is WICG/import-maps#5 (comment). PS: there have been some workaround like creating unique custom element names by adding random strings but they definitely violate the idea to only ship as little as possible. [1]: This could be more than just a warning. You could even give some info on how to pin to certain versions that should be used. e.g. something like this,
PS: Have a safe flight 👍 |
@wmhilton: neither yarn nor npm have a way to override or limit the amount of versions that you use. In webpack you can do use resolutions to archive it and/or use tools like duplicate-package-checker-webpack-plugin to get a warning. So, in short, you can solve it with build tools but not with packager tools. There are some movement in this direction but no working implementation yet[1] and changes to npm and yarn always take quite some time and usually have a huge impact (as so many people use it) So having a specialized generator for package name maps that support a unique flag wound a preferred solution I would say. And it would definitely be awesome.
That is true but we are not interested in the name (as on package can have multiple custom elements) we just want to make sure that certain packages are only ONCE in the package name map. e.g.
is totally fine as long as However if those are different versions then they resists in different locations so it will be loaded again... and boom DOMException [1]: if you exclude |
So this project started as a proof-of-concept. I wanted to show that it was possible (and easy) to generate any type of data structure simply by extracting the data from the PnP API. Since the pnm proposal is something I kept an eye on, it was a good candidate 😃 Overall, I think it's important to stay close to the layout provided by the package manager. As you mentioned, the goal of pnm (if I understood correctly) is to be able to use the dependency as-is, by serving the installed app. To make it truly isomorphic, it has to use the same dependency tree than the one used by Node.
While I understand the size concern, I'm concerned about the burden of manually solving conflicts. That could in my mind be a big barrier to the pnm adoption. We would have to check in real case scenarios, but I suspect a lot of dependency ranges would conflict, requiring users to manually solve the conflicts (which is quite hard since they usually have no idea which one to use) 🤔
I think I quite like what @ljharb suggested - to enforce the "flatness" by using peer dependencies. There are some pitfalls that have to be considered, though:
Thanks @daKmoR! 😃 |
I may have not explained well enough what I would expect 🙈 I definitely don't want want to have a global flag so that users will need to choose for every package. But for packages that are "naturally" unique like web components it would help to catch the error while installing and not while opening the browser. Sending them both to the browser or even have a mapping for it is not usefull at all as you just can't load it. I would like to quote @zkat here
for webcomponents in the browser directly there is NO protection we can offer - it's really awesome that you don't need to care about it in node (or even react?)... but if you use webcomponents the browser (rightfully so) forces you. I'm sorry for beeing so persitent but it seem I may be a dreamer that still believes in a world where you don't need any build tools while developing. (I do not consider yarn install a build step) Let my try slightly different. Let's extend my demo repository with another dependency
something like this should give me the question "Could not find a sadisfying version for 'test-webcomponent ..." but ONLY because I have configured "test-webcomponent" to be unique. webpack will be installed nested if needed and nothing will change for it. possible configuration for unique packages could be
to summarize:
|
TLDR; @daKmoR I completely disagree with your reasoning but agree that the requested feature is a good one. The disagreeing part: I still think you're conflating WebComponents with modules. Let's say I have a module that exports a webcomponent, You could have multiple versions of that module in the graph. You just need to make sure that only one copy of the module actually registers It's pretty straightforward to say, "well, if you're publishing WebComponents that auto-register on import, you're doing it wrong" and toss the problem to userspace. BUT. That's not very helpful. 🤷♂️ The agreeing part: @daKmoR brought up the However, it seems very likely that the root of the issue is not in |
Yes and no. Imagine the following: you write a component Foo. Even if I think more generally the problem of singleton packages is something that should be solved by the package managers. It's far from being a Javascript-only problems: taking C and C++ as example, you can't link identical symbols together (unless static storage). This is the same here. The main question I'm still thinking about is whether it should come from the user or from the package. Should the user specify that package Foo should be singleton'd? Or should the package Foo says that it must be singleton'd (similar in some way to the |
yes that is the main point 🤗 very simple example // v1.0.0/foo.js
window.fooFlag = 'BAR';
// v2.0.0/foo.js
window.fooFlag = 'BAZ';
// app.js
import 'v1.0.0/foo.js';
if (window.fooFLAG === 'BAR') { ... } // e.g. depending on v1 so if ANY package you use is now loading the v2 version... this will just break... problem is it will silently break and stuff like that is usually tough to find and fix.
I totally agree that it should be solved on the npm or yarn side... but to be honest I have given up on that hope 🙈 (at least on the hope that it happens any time soon).
I would go with that the package author sets it... he knows if the package code needs to be unique or not. so if I do |
First thanks for starting something like this 👍
I am curius where you wana go with it e.g. what is planned? for example did you see the possible overhaul of the package-name-maps (maybe even with rename)? WICG/import-maps#53
I would like to use something like this to generate maps that can be used with web components.
However they need to be unique.
Given the following dependency tree
We should get an Error/Question while creating package name map.
Possible example flow:
I made an example Repository
https://github.com/daKmoR/build-pnm-webcomponent-issue
and published all needed packages to test it.
I'm curious on what you think? if I can help out in any way just let me know.
The text was updated successfully, but these errors were encountered: