From d57e2b2fcf3f8c158d045b79ac47268f20f6c83b Mon Sep 17 00:00:00 2001 From: Teemu Koivisto Date: Tue, 30 Nov 2021 14:11:00 +0200 Subject: [PATCH] Set type to ESM module, update CommonJS .js files to .cjs --- .vscode/launch.json | 2 +- bin/{callback.js => callback.cjs} | 0 bin/{server.js => server.cjs} | 2 +- bin/{utils.js => utils.cjs} | 4 ++-- package.json | 9 +++++---- 5 files changed, 9 insertions(+), 8 deletions(-) rename bin/{callback.js => callback.cjs} (100%) rename bin/{server.js => server.cjs} (92%) rename bin/{utils.js => utils.cjs} (98%) diff --git a/.vscode/launch.json b/.vscode/launch.json index c6a5d971..28efac06 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "type": "node", "request": "launch", "name": "websocket server", - "program": "${workspaceFolder}/bin/server.js" + "program": "${workspaceFolder}/bin/server.cjs" } ] } \ No newline at end of file diff --git a/bin/callback.js b/bin/callback.cjs similarity index 100% rename from bin/callback.js rename to bin/callback.cjs diff --git a/bin/server.js b/bin/server.cjs similarity index 92% rename from bin/server.js rename to bin/server.cjs index cb3508a7..168fb970 100755 --- a/bin/server.js +++ b/bin/server.cjs @@ -6,7 +6,7 @@ const WebSocket = require('ws') const http = require('http') const wss = new WebSocket.Server({ noServer: true }) -const setupWSConnection = require('./utils.js').setupWSConnection +const setupWSConnection = require('./utils.cjs').setupWSConnection const host = process.env.HOST || 'localhost' const port = process.env.PORT || 1234 diff --git a/bin/utils.js b/bin/utils.cjs similarity index 98% rename from bin/utils.js rename to bin/utils.cjs index 0c9a7b7e..726087b8 100644 --- a/bin/utils.js +++ b/bin/utils.cjs @@ -9,8 +9,8 @@ const map = require('lib0/dist/map.cjs') const debounce = require('lodash.debounce') -const callbackHandler = require('./callback.js').callbackHandler -const isCallbackSet = require('./callback.js').isCallbackSet +const callbackHandler = require('./callback.cjs').callbackHandler +const isCallbackSet = require('./callback.cjs').isCallbackSet const CALLBACK_DEBOUNCE_WAIT = parseInt(process.env.CALLBACK_DEBOUNCE_WAIT) || 2000 const CALLBACK_DEBOUNCE_MAXWAIT = parseInt(process.env.CALLBACK_DEBOUNCE_MAXWAIT) || 10000 diff --git a/package.json b/package.json index 6ba02f1c..7b5df500 100644 --- a/package.json +++ b/package.json @@ -5,20 +5,21 @@ "main": "./dist/y-websocket.cjs", "module": "./src/y-websocket.js", "types": "./dist/src/y-websocket.d.ts", + "type": "module", "sideEffects": false, "funding": { "type": "GitHub Sponsors ❤", "url": "https://github.com/sponsors/dmonad" }, "scripts": { - "start": "node ./bin/server.js", + "start": "node ./bin/server.cjs", "dist": "rm -rf dist && rollup -c && tsc", "lint": "standard && tsc", "test": "npm run lint", "preversion": "npm run lint && npm run dist && test -e dist/src/y-websocket.d.ts && test -e dist/y-websocket.cjs" }, "bin": { - "y-websocket-server": "./bin/server.js" + "y-websocket-server": "./bin/server.cjs" }, "files": [ "dist/*", @@ -27,8 +28,8 @@ ], "exports": { "./package.json": "./package.json", - "./bin/utils": "./bin/utils.js", - "./bin/callback": "./bin/callback.js", + "./bin/utils": "./bin/utils.cjs", + "./bin/callback": "./bin/callback.cjs", ".": { "import": "./src/y-websocket.js", "require": "./dist/y-websocket.cjs"