lukeed / polka

A micro web server so fast, it'll make you dance! :dancers:
MIT License
5.4k stars 172 forks source link

Multiple versions of polka can't play nice #211

Open 43081j opened 2 months ago

43081j commented 2 months ago

In some cases, you may end up with something like this:

import {someApp} from 'wherever'; // Assume this package bundles polka, so it has its own copy
import polka from 'polka';

const server = polka();
const app = someApp();

app.server; // a Polka instance

server.use(app.server); // error since `!(app.server instanceof Polka)`

you shouldn't run into this often since your package manager would usually de-dupe and you'd have a single polka version

however, its very possible something you depend on which consumes polka instances (or any polka types) is pinned to an older 1.x than you are for example.

to solve this, maybe instead of base instanceof Polka, we can brand the class and check for that instead (some sort of _$polkaVersion or something, so we can also only consume same-major instances)

https://github.com/lukeed/polka/blob/08a6f63081b11a0130d2694fa1ced32444eb1e4c/packages/polka/index.js#L28