Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/socket.io-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 34 additions & 0 deletions packages/socket.io-client/test/browser-export.ts
Original file line number Diff line number Diff line change
@@ -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"));
});
});
1 change: 1 addition & 0 deletions packages/socket.io-client/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./browser-export";
import "./url";
import "./connection";
import "./socket";
Expand Down