Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make esm mjs #21

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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