Skip to content
Permalink
Browse files
feat: provide an ESM build with and without debug
  • Loading branch information
darrachequesne committed Oct 13, 2021
1 parent 7187453 commit 16b65698aed766e1e645c78847f2e91bfc5b6f56
@@ -1,19 +1,14 @@
import { url } from "./url";
import { Manager, ManagerOptions } from "./manager";
import { Socket, SocketOptions } from "./socket";
import { url } from "./url.js";
import { Manager, ManagerOptions } from "./manager.js";
import { Socket, SocketOptions } from "./socket.js";
import debugModule from "debug"; // debug()

const debug = require("debug")("socket.io-client");

/**
* Module exports.
*/

module.exports = exports = lookup;
const debug = debugModule("socket.io-client"); // debug()

/**
* Managers cache.
*/
const cache: Record<string, Manager> = (exports.managers = {});
const cache: Record<string, Manager> = {};

/**
* Looks up an existing `Manager` for multiplexing.
@@ -84,22 +79,17 @@ function lookup(

export { protocol } from "socket.io-parser";

/**
* `connect`.
*
* @param {String} uri
* @public
*/

exports.connect = lookup;

/**
* Expose constructors for standalone build.
*
* @public
*/

export { Manager, ManagerOptions } from "./manager";
export { Socket } from "./socket";
export { lookup as io, SocketOptions };
export default lookup;
export {
Manager,
ManagerOptions,
Socket,
SocketOptions,
lookup as io,

This comment has been minimized.

Copy link
@chriskrycho

chriskrycho Oct 14, 2021

Contributor

This appears to be the change which caused socketio/socket.io#4121. This module—not the browser-entrypoint module introduced in c76d367—is for some reason getting resolved as the root.

lookup as connect,
};
@@ -3,18 +3,19 @@ import {
SocketOptions as EngineOptions,
installTimerFunctions,
} from "engine.io-client";
import { Socket, SocketOptions } from "./socket";
import { Socket, SocketOptions } from "./socket.js";
import * as parser from "socket.io-parser";
import { Decoder, Encoder, Packet } from "socket.io-parser";
import { on } from "./on";
import * as Backoff from "backo2";
import { on } from "./on.js";
import Backoff from "backo2";
import {
DefaultEventsMap,
EventsMap,
StrictEventEmitter,
} from "./typed-events";
} from "./typed-events.js";
import debugModule from "debug"; // debug()

const debug = require("debug")("socket.io-client:manager");
const debug = debugModule("socket.io-client:manager"); // debug()

export interface ManagerOptions extends EngineOptions {
/**
@@ -1,5 +1,5 @@
import type * as Emitter from "component-emitter";
import { StrictEventEmitter } from "./typed-events";
import { StrictEventEmitter } from "./typed-events.js";

export function on(
obj: Emitter | StrictEventEmitter<any, any>,
@@ -1,15 +1,16 @@
import { Packet, PacketType } from "socket.io-parser";
import { on } from "./on";
import { Manager } from "./manager";
import { on } from "./on.js";
import { Manager } from "./manager.js";
import {
DefaultEventsMap,
EventNames,
EventParams,
EventsMap,
StrictEventEmitter,
} from "./typed-events";
} from "./typed-events.js";
import debugModule from "debug"; // debug()

const debug = require("debug")("socket.io-client:socket");
const debug = debugModule("socket.io-client:socket"); // debug()

export interface SocketOptions {
/**
@@ -1,6 +1,7 @@
import * as parseuri from "parseuri";
import parseuri from "parseuri";
import debugModule from "debug"; // debug()

const debug = require("debug")("socket.io-client:url");
const debug = debugModule("socket.io-client:url"); // debug()

type ParsedUrl = {
source: string;
@@ -11,21 +11,24 @@
],
"files": [
"dist/",
"build/",
"wrapper.mjs"
"build/"
],
"type": "commonjs",
"main": "./build/index.js",
"main": "./build/cjs/index.js",
"module": "./build/esm/index.js",
"exports": {
"./package.json": "./package.json",
"./dist/socket.io.js": "./dist/socket.io.js",
"./dist/socket.io.js.map": "./dist/socket.io.js.map",
".": {
"import": "./wrapper.mjs",
"require": "./build/index.js"
"import": {
"node": "./build/esm-debug/index.js",
"default": "./build/esm/index.js"
},
"require": "./build/cjs/index.js"
}
},
"types": "./build/index.d.ts",
"types": "./build/esm/index.d.ts",
"dependencies": {
"@socket.io/component-emitter": "~2.0.0",
"backo2": "~1.0.2",
@@ -68,7 +71,7 @@
"zuul-ngrok": "4.0.0"
},
"scripts": {
"compile": "rimraf ./build && tsc",
"compile": "rimraf ./build && tsc && tsc -p tsconfig.esm.json && ./postcompile.sh",
"test": "npm run format:check && npm run compile && if test \"$BROWSERS\" = \"1\" ; then npm run test:browser; else npm run test:node; fi",
"test:node": "mocha --require ts-node/register --reporter dot --require test/support/server.js test/index.js",
"test:browser": "zuul test/index.js",
@@ -0,0 +1,8 @@
#!/bin/bash

cp ./support/package.cjs.json ./build/cjs/package.json
cp ./support/package.esm.json ./build/esm/package.json

cp -r ./build/esm/ ./build/esm-debug/

sed -i '/debug(/d' ./build/esm/*.js
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
@@ -0,0 +1,3 @@
{
"type": "module"
}
@@ -6,7 +6,7 @@ const banner = `Socket.IO v${version}
Released under the MIT License.`;

module.exports = {
entry: "./build/index.js",
entry: "./build/esm/index.js",
output: {
filename: "socket.io.js",
library: "io",
@@ -1,9 +1,9 @@
import * as expect from "expect.js";
import expect from "expect.js";
import { io, Manager, ManagerOptions } from "..";
import * as hasCORS from "has-cors";
import * as FakeTimers from "@sinonjs/fake-timers";
import * as textBlobBuilder from "text-blob-builder";
import * as env from "./support/env";
import hasCORS from "has-cors";
import FakeTimers from "@sinonjs/fake-timers";
import textBlobBuilder from "text-blob-builder";
import env from "./support/env";

describe("connection", function () {
this.timeout(70000);
@@ -1,4 +1,4 @@
const io = require("../..");
const { io } = require("../..");
const socket = io("http://localhost:3211", {
autoUnref: false,
});
@@ -1,4 +1,4 @@
const io = require("../..");
const { io } = require("../..");
const socket = io("http://localhost:3211", {
autoUnref: true,
});
@@ -1,4 +1,4 @@
const io = require("../..");
const { io } = require("../..");
const socket = io("http://localhost:3210", {
autoUnref: true,
transports: ["polling"],
@@ -1,4 +1,4 @@
const io = require("../..");
const { io } = require("../..");
const socket = io("http://localhost:3210", {
autoUnref: true,
transports: ["websocket"],
@@ -1,4 +1,4 @@
const io = require("../..");
const { io } = require("../..");
const socket = io("http://localhost:3210", {
autoUnref: true,
});
@@ -1,4 +1,4 @@
import * as expect from "expect.js";
import expect from "expect.js";
import { io } from "..";

describe("socket", function () {
@@ -1,5 +1,5 @@
import { url } from "../build/url";
import * as expect from "expect.js";
import { url } from "../build/cjs/url";
import expect from "expect.js";

const loc: any = {};

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"outDir": "build/esm/",
"target": "es2018",
"module": "esnext",
"moduleResolution": "node",
"declaration": true
},
"include": [
"./lib/**/*"
]
}
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"outDir": "./build",
"allowJs": false,
"target": "es2017",
"outDir": "build/cjs/",
"target": "es2018", // Node.js 10 (https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping)
"module": "commonjs",
"declaration": true
"declaration": false,
"esModuleInterop": true
},
"include": [
"./lib/**/*"

This file was deleted.

0 comments on commit 16b6569

Please sign in to comment.