From 29ca9e3b6f49ed49eb27a5e079913b73e28b5f77 Mon Sep 17 00:00:00 2001 From: Mike Marcacci Date: Fri, 1 Nov 2019 21:31:05 -0700 Subject: [PATCH] Avoid named imports of cjs deps --- README.md | 2 +- src/index.mjs | 6 +++++- src/test.mjs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0aad81c..c61c49f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This is useful for file uploads and other situations where you want to avoid del ```js import fs from "fs"; import http from "http"; -import WriteStream from "fs-capacitor"; +import { WriteStream } from "fs-capacitor"; http.createServer((req, res) => { const capacitor = new WriteStream(); diff --git a/src/index.mjs b/src/index.mjs index 4d0b0d8..d00bd1c 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -2,7 +2,11 @@ import crypto from "crypto"; import fs from "fs"; import os from "os"; import path from "path"; -import { Readable, Writable } from "readable-stream"; +import rs from "readable-stream"; + +// Because we target .mjs files and this dependency is commonjs, we can't use +// named exports. Instead, we'll just destructure the object. +const { Readable, Writable } = rs; let haveCheckedSignalListeners = false; function checkSignalListeners() { diff --git a/src/test.mjs b/src/test.mjs index 4cbf90b..621e97b 100644 --- a/src/test.mjs +++ b/src/test.mjs @@ -3,7 +3,7 @@ import "leaked-handles"; import fs from "fs"; import stream from "stream"; import t from "tap"; -import WriteStream, { ReadAfterDestroyedError } from "."; +import { ReadAfterDestroyedError, WriteStream } from "."; const streamToString = stream => new Promise((resolve, reject) => {