Replies: 11 comments
-
You don't need to create separate packages per framework, you can just use subpath exports instead? I.e.,: import ... from 'my-pkg';
import ... from 'my-pkg/preact';
import ... from 'my-pkg/react'; |
Beta Was this translation helpful? Give feedback.
-
I think the good way is too promise user to add |
Beta Was this translation helpful? Give feedback.
-
If you're worried about the user not installing the bindings you could attempt to import the module and trigger an error that way, for sure. |
Beta Was this translation helpful? Give feedback.
-
I know but there are two runtimes for preact and react. I can't import both, because user at most of the time uses one of them. So here is two options:
And in case of pnpm we should ask user to use |
Beta Was this translation helpful? Give feedback.
-
Oh, you don't want to provide multiple exports? It's still doable, just use a |
Beta Was this translation helpful? Give feedback.
-
You meaning this? Its could be ok, but not convenient for users. But I'm using this packages inside others in monorepo |
Beta Was this translation helpful? Give feedback.
-
I thinks that code writen for signals should be interoperable between preact/react. So it would be better to core a peer dependency |
Beta Was this translation helpful? Give feedback.
-
That's what I suggested first, yes, but if you don't like subpath exports, again, you could always use dynamic imports to guess and check which is available. A bit hacky, but will work. To demonstrate: let useSignal;
try {
({ useSignal } = await import('@preact/signals'));
} catch (e) {
if (e.code !== 'ERR_MODULE_NOT_FOUND') throw e;
try {
({ useSignal } = await import('@preact/signals-react'));
} catch (e) {
if (e.code !== 'ERR_MODULE_NOT_FOUND') throw e;
throw new Error('Could not find valid signals package');
}
} |
Beta Was this translation helpful? Give feedback.
-
I don't think it a good way, because someone can have both runtime packages (for example exposed from other dependency with flat node modules). So we will install extra runtime (for preact, for example, that will rely on this inside component and throw while putting signal to jsx, because both runtimes mutates signal prototype and this behavior will depend from imports order) |
Beta Was this translation helpful? Give feedback.
-
Seems to be it's good way to provide undefined behavior. I really like this signals implementation, but for more wide adoption it should provide a way to safely write libraries |
Beta Was this translation helpful? Give feedback.
-
I think it's pretty unlikely that a user should ever have both installed (unintentionally is another thing), but just throwing it out there. It's an option, up to you to decide what fits your needs best. Edit: there is a very safe way, and that is peer deps & subpath exports. It's absolutely standard practice these days, but if you don't want to use them, you'll have to get a bit more creative. |
Beta Was this translation helpful? Give feedback.
-
I am developling libraries that can be accepted via react/preact. Each package has part that can be used without framework specific adapter, and some parts like hooks, that can be consumed with each of framework. I don't want to create 3 package for each package with framework specific imports, sounds dummy. How to be sure that user install framework specific bindings?
Beta Was this translation helpful? Give feedback.
All reactions