Skip to content

Commit

Permalink
fix: browser field should point to cjs (#20)
Browse files Browse the repository at this point in the history
> a top-level "browser" field should point to CJS files that, when bundled by a non-broken module bundler, work in a browser

browserify/browser-resolve#101 (comment)

I've changed the `browser` field to point to the `cjs` version of this module in
line with the above comment because this module is currently broken when used with
browserify.

I've also added the [util](https://www.npmjs.com/package/util) module as a dep since it's used
in the code. It would be ignored in most environments so the only cost is a slightly larger
bundle but it's likely to be included in any non-trivial bundle somewhere anyway so there's
likely to be no real-world impact.

Also:

- Adds typescript dep to tests that test typescript, otherwise tests fail with
  'cannot determine executable to run' - unless you have tsc installed globally I guess?
- Fixes a typo in a comment
- Simplifies .gitignore

Fixes #19
  • Loading branch information
achingbrain authored Apr 6, 2021
1 parent 77028b0 commit 3992702
Show file tree
Hide file tree
Showing 7 changed files with 6,592 additions and 6,449 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/**
test/**/package-lock.json
**/node_modules
node_modules
package-lock.json
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react-native": "./src/lib.react-native.js",
"main": "./src/lib.cjs",
"module": "./src/lib.js",
"browser": "./src/lib.js",
"browser": "./src/lib.cjs",
"types": "./src/lib.d.ts",
"exports": {
".": {
Expand All @@ -33,6 +33,9 @@
"license": "MIT",
"author": "Irakli Gozalishvili <[email protected]>",
"homepage": "https://github.com/gozala/web-encoding",
"dependencies": {
"util": "^0.12.3"
},
"devDependencies": {
"assert": "^2.0.0",
"jest": "^26.6.3",
Expand Down
2 changes: 1 addition & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// In node `export { TextEncoder }` throws:
// "Export 'TextEncoder' is not definedin module"
// "Export 'TextEncoder' is not defined in module"
// To workaround we first define constants and then export with as.
const Encoder = TextEncoder
const Decoder = TextDecoder
Expand Down
5 changes: 4 additions & 1 deletion test/cjs-use/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"web-encoding": "file:../.."
},
"scripts": {
"test": "npm install && npx typescript --noEmit --allowJs --checkJs src/main.js"
"test": "npm install && tsc --noEmit --allowJs --checkJs src/main.js"
},
"devDependencies": {
"typescript": "^4.2.3"
}
}
5 changes: 4 additions & 1 deletion test/esm-use/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"web-encoding": "file:../.."
},
"scripts": {
"test": "npm install && npx typescript --noEmit --allowJs --checkJs src/main.js"
"test": "npm install && tsc --noEmit --allowJs --checkJs src/main.js"
},
"devDependencies": {
"typescript": "^4.2.3"
}
}
5 changes: 4 additions & 1 deletion test/ts-use/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"web-encoding": "file:../.."
},
"scripts": {
"test": "npm install && npx typescript --noEmit"
"test": "npm install && tsc --noEmit"
},
"devDependencies": {
"typescript": "^4.2.3"
}
}
13,014 changes: 6,573 additions & 6,441 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 3992702

Please sign in to comment.