Skip to content

Commit

Permalink
Merge pull request #21 from Gozala/fix/make-esm-mjs
Browse files Browse the repository at this point in the history
fix: make esm mjs
  • Loading branch information
Gozala authored Apr 20, 2021
2 parents 3992702 + 3f10167 commit 5c35750
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
"TextEncoder",
"TextDecoder"
],
"type": "module",
"react-native": "./src/lib.react-native.js",
"main": "./src/lib.cjs",
"module": "./src/lib.js",
"browser": "./src/lib.cjs",
"main": "./src/lib.js",
"module": "./src/lib.mjs",
"browser": "./src/lib.js",
"types": "./src/lib.d.ts",
"exports": {
".": {
"import": "./src/lib.js",
"require": "./src/lib.cjs"
"import": "./src/lib.mjs",
"require": "./src/lib.js"
}
},
"scripts": {
"test:node": "mocha test/test-*.spec.cjs",
"test:browser": "playwright-test test/test-*.cjs",
"test:node": "mocha test/test-*.spec.js",
"test:browser": "playwright-test test/test-*.js",
"test:react-native": "jest test/test-lib.react-native.spec.js",
"test:es": "mocha test/test-lib.spec.js",
"test:es": "mocha test/test-lib.spec.mjs",
"test:cjs": "npm run test:node && npm run test:browser",
"test:types:ts": "npm test --prefix test/ts-use",
"test:types:esm": "npm test --prefix test/esm-use",
Expand Down
7 changes: 0 additions & 7 deletions src/lib.cjs

This file was deleted.

12 changes: 6 additions & 6 deletions src/lib.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// In node `export { TextEncoder }` throws:
// "Export 'TextEncoder' is not defined in module"
// To workaround we first define constants and then export with as.
const Encoder = TextEncoder
const Decoder = TextDecoder
"use strict"

export { Encoder as TextEncoder, Decoder as TextDecoder }
exports.TextEncoder =
typeof TextEncoder !== "undefined" ? TextEncoder : require("util").TextEncoder

exports.TextDecoder =
typeof TextDecoder !== "undefined" ? TextDecoder : require("util").TextDecoder
7 changes: 7 additions & 0 deletions src/lib.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// In node `export { TextEncoder }` throws:
// "Export 'TextEncoder' is not defined in module"
// To workaround we first define constants and then export with as.
const Encoder = TextEncoder
const Decoder = TextDecoder

export { Encoder as TextEncoder, Decoder as TextDecoder }
4 changes: 2 additions & 2 deletions test/test-lib.react-native.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextEncoder, TextDecoder } from "../src/lib.react-native.js"
import assert from "assert"
const { TextEncoder, TextDecoder } = require("../src/lib.react-native.js")
const assert = require("assert")

describe("text encode/decode", () => {
const data = Uint8Array.from([
Expand Down
4 changes: 2 additions & 2 deletions test/test-lib.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextEncoder, TextDecoder } from "../src/lib.js"
import assert from "assert"
const { TextEncoder, TextDecoder } = require("../src/lib")
const assert = require("assert")

describe("text encode/decode", () => {
const data = Uint8Array.from([
Expand Down
4 changes: 2 additions & 2 deletions test/test-lib.spec.cjs → test/test-lib.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { TextEncoder, TextDecoder } = require("..")
const assert = require("assert")
import { TextEncoder, TextDecoder } from "../src/lib.js"
import assert from "assert"

describe("text encode/decode", () => {
const data = Uint8Array.from([
Expand Down

0 comments on commit 5c35750

Please sign in to comment.