Skip to content

Commit 3992702

Browse files
authored
fix: browser field should point to cjs (#20)
> 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
1 parent 77028b0 commit 3992702

File tree

7 files changed

+6592
-6449
lines changed

7 files changed

+6592
-6449
lines changed

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
node_modules/**
2-
test/**/package-lock.json
3-
**/node_modules
1+
node_modules
2+
package-lock.json

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"react-native": "./src/lib.react-native.js",
1111
"main": "./src/lib.cjs",
1212
"module": "./src/lib.js",
13-
"browser": "./src/lib.js",
13+
"browser": "./src/lib.cjs",
1414
"types": "./src/lib.d.ts",
1515
"exports": {
1616
".": {
@@ -33,6 +33,9 @@
3333
"license": "MIT",
3434
"author": "Irakli Gozalishvili <[email protected]>",
3535
"homepage": "https://github.com/gozala/web-encoding",
36+
"dependencies": {
37+
"util": "^0.12.3"
38+
},
3639
"devDependencies": {
3740
"assert": "^2.0.0",
3841
"jest": "^26.6.3",

src/lib.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// In node `export { TextEncoder }` throws:
2-
// "Export 'TextEncoder' is not definedin module"
2+
// "Export 'TextEncoder' is not defined in module"
33
// To workaround we first define constants and then export with as.
44
const Encoder = TextEncoder
55
const Decoder = TextDecoder

test/cjs-use/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"web-encoding": "file:../.."
66
},
77
"scripts": {
8-
"test": "npm install && npx typescript --noEmit --allowJs --checkJs src/main.js"
8+
"test": "npm install && tsc --noEmit --allowJs --checkJs src/main.js"
9+
},
10+
"devDependencies": {
11+
"typescript": "^4.2.3"
912
}
1013
}

test/esm-use/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"web-encoding": "file:../.."
66
},
77
"scripts": {
8-
"test": "npm install && npx typescript --noEmit --allowJs --checkJs src/main.js"
8+
"test": "npm install && tsc --noEmit --allowJs --checkJs src/main.js"
9+
},
10+
"devDependencies": {
11+
"typescript": "^4.2.3"
912
}
1013
}

test/ts-use/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"web-encoding": "file:../.."
66
},
77
"scripts": {
8-
"test": "npm install && npx typescript --noEmit"
8+
"test": "npm install && tsc --noEmit"
9+
},
10+
"devDependencies": {
11+
"typescript": "^4.2.3"
912
}
1013
}

yarn.lock

+6,573-6,441
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)