From 3f3af3af3d590869b799a7ae630854623147c7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=2E=20Rom=C3=A1n?= Date: Thu, 16 Jun 2022 10:18:03 +0200 Subject: [PATCH] fix: resolved inconsistent exports in ESM (#2047) * feat: add ESM support * docs: updated CHANGELOG * refactor: destructure once Co-authored-by: Mohammed Keyvanzadeh * fix: use `exports.[name] = value` instead Co-authored-by: Mohammed Keyvanzadeh --- CHANGELOG.md | 1 + index.js | 64 +++++++++++++++++++++++++--------------------------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b32b16f52..f104c3d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed ### Added ### Fixed +* Fixed ESM exports. 2.9.1 ================== diff --git a/index.js b/index.js index 4d11d9a81..0cb14a1ed 100644 --- a/index.js +++ b/index.js @@ -55,40 +55,38 @@ function deregisterAllFonts () { return Canvas._deregisterAllFonts() } -module.exports = { - Canvas, - Context2d: CanvasRenderingContext2D, // Legacy/compat export - CanvasRenderingContext2D, - CanvasGradient: bindings.CanvasGradient, - CanvasPattern, - Image, - ImageData: bindings.ImageData, - PNGStream, - PDFStream, - JPEGStream, - DOMMatrix, - DOMPoint, +exports.Canvas = Canvas +exports.Context2d = CanvasRenderingContext2D // Legacy/compat export +exports.CanvasRenderingContext2D = CanvasRenderingContext2D +exports.CanvasGradient = bindings.CanvasGradient +exports.CanvasPattern = CanvasPattern +exports.Image = Image +exports.ImageData = bindings.ImageData +exports.PNGStream = PNGStream +exports.PDFStream = PDFStream +exports.JPEGStream = JPEGStream +exports.DOMMatrix = DOMMatrix +exports.DOMPoint = DOMPoint - registerFont, - deregisterAllFonts, - parseFont, +exports.registerFont = registerFont +exports.deregisterAllFonts = deregisterAllFonts +exports.parseFont = parseFont - createCanvas, - createImageData, - loadImage, +exports.createCanvas = createCanvas +exports.createImageData = createImageData +exports.loadImage = loadImage - backends: bindings.Backends, +exports.backends = bindings.Backends - /** Library version. */ - version: packageJson.version, - /** Cairo version. */ - cairoVersion: bindings.cairoVersion, - /** jpeglib version. */ - jpegVersion: bindings.jpegVersion, - /** gif_lib version. */ - gifVersion: bindings.gifVersion ? bindings.gifVersion.replace(/[^.\d]/g, '') : undefined, - /** freetype version. */ - freetypeVersion: bindings.freetypeVersion, - /** rsvg version. */ - rsvgVersion: bindings.rsvgVersion -} +/** Library version. */ +exports.version = packageJson.version +/** Cairo version. */ +exports.cairoVersion = bindings.cairoVersion +/** jpeglib version. */ +exports.jpegVersion = bindings.jpegVersion +/** gif_lib version. */ +exports.gifVersion = bindings.gifVersion ? bindings.gifVersion.replace(/[^.\d]/g, '') : undefined +/** freetype version. */ +exports.freetypeVersion = bindings.freetypeVersion +/** rsvg version. */ +exports.rsvgVersion = bindings.rsvgVersion