Skip to content

Commit

Permalink
refactor: remove text-encoding polyfill
Browse files Browse the repository at this point in the history
Node supports WHATWG Encoding Standard.
Node 11+ exports TextEncoder and TextDecoder in global scope.
In lower versions, both classes are exported under util module.

Note: we use "require" import of util because it seems that "import"
imports a no-buil-in "util" package. More investigation is required.

Fixes #171
  • Loading branch information
Conaclos committed Mar 22, 2020
1 parent e583a82 commit 22e471a
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ npm install netflux
npm install rxjs
```

- `ws` and `text-encoding` if you target NodeJS (developing a bot):
- `ws` if you target NodeJS (developing a bot):

```shell
npm install ws text-encoding
npm install ws
```

**Why peer dependencies?**
Expand Down
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ module.exports = (config) => {
lib: ['es2017', 'dom'],
moduleResolution: 'node',
downlevelIteration: true,
types: ['node', 'text-encoding'],
types: ['node'],
allowJs: true,
},
bundlerOptions: {
exclude: ['wrtc', 'text-encoding', 'util', 'ws', 'url', 'crypto'],
exclude: ['wrtc', 'util', 'ws', 'url', 'crypto'],
noParse: ['webrtc-adapter/out/adapter_no_edge_no_global.js'],
addNodeGlobals: false,
},
Expand Down
12 changes: 0 additions & 12 deletions package-lock.json

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

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
},
"peerDependencies": {
"rxjs": "^6.2.0",
"text-encoding": "^0.7.0",
"ws": "^7.2.2"
},
"devDependencies": {
Expand All @@ -63,7 +62,6 @@
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-node-resolve": "^7.1.0",
"@types/jasmine": "^3.5.8",
"@types/text-encoding": "0.0.35",
"@types/ws": "^7.2.2",
"esdoc": "^1.1.0",
"esdoc-inject-style-plugin": "^1.0.0",
Expand Down Expand Up @@ -92,7 +90,6 @@
"rxjs": "^6.3.2",
"semantic-release": "^17.0.4",
"sigver": "^20.0.2",
"text-encoding": "^0.7.0",
"travis-deploy-once": "^5.0.7",
"tslib": "^1.11.1",
"typescript": "^3.8.3",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default [
sourcemap: true,
},
],
external: ['url', 'crypto', 'ws', 'text-encoding', 'util'],
external: ['url', 'crypto', 'ws', 'util'],
plugins: [
typescript(),
resolve({ preferBuiltins: true }),
Expand Down Expand Up @@ -81,7 +81,7 @@ export default [
format: 'es',
sourcemap: true,
},
external: ['url', 'crypto', 'ws', 'text-encoding', 'uil', 'rxjs', 'rxjs/operators'],
external: ['url', 'crypto', 'ws', 'uil', 'rxjs', 'rxjs/operators'],
plugins: [
typescript(tsConfigDeclaration),
resolve({ preferBuiltins: true }),
Expand Down
6 changes: 3 additions & 3 deletions src/misc/polyfills.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as crypto from 'crypto'
import { TextDecoder, TextEncoder } from 'text-encoding'
import * as WebSocket from 'ws'
const util = require('util')

import { env } from './env'

Expand All @@ -13,6 +13,6 @@ import { env } from './env'
// console.warn(err.message)
// }
env.WebSocket = WebSocket as any
env.TextEncoder = TextEncoder
env.TextDecoder = TextDecoder
env.TextEncoder = util.TextEncoder
env.TextDecoder = util.TextDecoder
env.cryptoNode = crypto
2 changes: 1 addition & 1 deletion test/util/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
format: 'cjs',
},
context: 'global',
external: ['url', 'crypto', 'ws', 'text-encoding'],
external: ['url', 'crypto', 'ws'],
plugins: [
typescript({
include: ['src/**/*.ts', 'test/**/*.ts'],
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"lib": ["es2017", "dom"],
"moduleResolution": "node",
"downlevelIteration": true,
"types": ["node", "text-encoding"],
"types": ["node"],
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
Expand Down

0 comments on commit 22e471a

Please sign in to comment.