Skip to content

Commit

Permalink
feat: provide an ESM build with and without debug
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Oct 11, 2021
1 parent 75530b4 commit 388c616
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist/
build/
2 changes: 1 addition & 1 deletion lib/binary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBinary } from "./is-binary";
import { isBinary } from "./is-binary.js";

/**
* Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
Expand Down
9 changes: 5 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Emitter = require("component-emitter");
import { deconstructPacket, reconstructPacket } from "./binary";
import { isBinary, hasBinary } from "./is-binary";
import Emitter from "@socket.io/component-emitter";
import { deconstructPacket, reconstructPacket } from "./binary.js";
import { isBinary, hasBinary } from "./is-binary.js";
import debugModule from "debug"; // debug()

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

/**
* Protocol version.
Expand Down
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
"url": "https://github.com/socketio/socket.io-parser.git"
},
"files": [
"dist/"
"build/"
],
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "./build/cjs/index.js",
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"exports": {
"import": {
"node": "./build/esm-debug/index.js",
"default": "./build/esm/index.js"
},
"require": "./build/cjs/index.js"
},
"dependencies": {
"@types/component-emitter": "^1.2.10",
"component-emitter": "~1.3.0",
"@socket.io/component-emitter": "~2.0.0",
"debug": "~4.3.1"
},
"devDependencies": {
Expand All @@ -33,7 +40,7 @@
"zuul-ngrok": "4.0.0"
},
"scripts": {
"compile": "rimraf ./dist && 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 --reporter dot --bail test/index.js",
"test:browser": "zuul test/index.js --no-coverage",
Expand Down
8 changes: 8 additions & 0 deletions postcompile.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions support/package.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 3 additions & 0 deletions support/package.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
12 changes: 12 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"outDir": "build/esm/",
"target": "es2018",
"module": "esnext",
"moduleResolution": "node",
"declaration": true
},
"include": [
"./lib/**/*"
]
}
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"compilerOptions": {
"outDir": "./dist",
"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
},
"include": [
"./lib/**/*"
Expand Down

0 comments on commit 388c616

Please sign in to comment.