From b865572b19b889d4763974b2b04353aab8fc4a79 Mon Sep 17 00:00:00 2001 From: Saad Abdullah Date: Thu, 15 Oct 2026 10:18:40 +0000 Subject: [PATCH] feat(socket.io-client): expose the standalone ESM bundle through the "./browser" subpath export --- packages/socket.io-client/package.json | 4 +++ .../socket.io-client/test/browser-export.ts | 34 +++++++++++++++++++ packages/socket.io-client/test/index.ts | 1 + 3 files changed, 39 insertions(+) create mode 100644 packages/socket.io-client/test/browser-export.ts diff --git a/packages/socket.io-client/package.json b/packages/socket.io-client/package.json index 972c7bfea0..4f53f6ddb2 100644 --- a/packages/socket.io-client/package.json +++ b/packages/socket.io-client/package.json @@ -32,6 +32,10 @@ "default": "./build/cjs/index.js" } }, + "./browser": { + "types": "./build/esm/index.d.ts", + "default": "./dist/socket.io.esm.min.js" + }, "./debug": { "import": { "types": "./build/esm/index.d.ts", diff --git a/packages/socket.io-client/test/browser-export.ts b/packages/socket.io-client/test/browser-export.ts new file mode 100644 index 0000000000..64543ca60e --- /dev/null +++ b/packages/socket.io-client/test/browser-export.ts @@ -0,0 +1,34 @@ +import { existsSync, readFileSync } from "fs"; +import { createRequire } from "module"; +import { join } from "path"; +import expect = require("expect.js"); + +// the "socket.io-client/browser" subpath export allows importing the +// standalone ESM bundle directly (for example with Deno or in the browser), +// without a bundler and without copying the bundle locally +// see https://github.com/socketio/socket.io/issues/5383 +describe("browser export", () => { + const packageRoot = join(__dirname, ".."); + const pkg = JSON.parse( + readFileSync(join(packageRoot, "package.json"), "utf8"), + ); + + it("should declare a ./browser subpath export", () => { + expect(pkg.exports["./browser"]).to.eql({ + types: "./build/esm/index.d.ts", + default: "./dist/socket.io.esm.min.js", + }); + }); + + it("should point to files that exist", () => { + const entry = pkg.exports["./browser"]; + expect(existsSync(join(packageRoot, entry.default))).to.be(true); + expect(existsSync(join(packageRoot, entry.types))).to.be(true); + }); + + it("should be resolvable by its package name", () => { + const require = createRequire(join(packageRoot, "index.js")); + const resolved = require.resolve("socket.io-client/browser"); + expect(resolved).to.be(join(packageRoot, "dist", "socket.io.esm.min.js")); + }); +}); diff --git a/packages/socket.io-client/test/index.ts b/packages/socket.io-client/test/index.ts index 355c840ca4..926b3e63be 100644 --- a/packages/socket.io-client/test/index.ts +++ b/packages/socket.io-client/test/index.ts @@ -1,3 +1,4 @@ +import "./browser-export"; import "./url"; import "./connection"; import "./socket";