From 927860d4480d0f1d625155c6b1f76ad017263c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=2E=20Rom=C3=A1n?= Date: Thu, 2 Jun 2022 10:29:25 +0200 Subject: [PATCH 1/4] feat: add ESM support --- index.mjs | 28 ++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 29 insertions(+) create mode 100644 index.mjs diff --git a/index.mjs b/index.mjs new file mode 100644 index 000000000..eaf713f21 --- /dev/null +++ b/index.mjs @@ -0,0 +1,28 @@ +import mod from './index.js' + +export default mod; +export const { Canvas } = mod; +export const { Context2d } = mod; +export const { CanvasRenderingContext2D } = mod; +export const { CanvasGradient } = mod; +export const { CanvasPattern } = mod; +export const { Image } = mod; +export const { ImageData } = mod; +export const { PNGStream } = mod; +export const { PDFStream } = mod; +export const { JPEGStream } = mod; +export const { DOMMatrix } = mod; +export const { DOMPoint } = mod; +export const { registerFont } = mod; +export const { deregisterAllFonts } = mod; +export const { parseFont } = mod; +export const { createCanvas } = mod; +export const { createImageData } = mod; +export const { loadImage } = mod; +export const { backends } = mod; +export const { version } = mod; +export const { cairoVersion } = mod; +export const { jpegVersion } = mod; +export const { gifVersion } = mod; +export const { freetypeVersion } = mod; +export const { rsvgVersion } = mod; diff --git a/package.json b/package.json index 5f382675e..69d7b4a03 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "version": "2.9.1", "author": "TJ Holowaychuk ", "main": "index.js", + "module": "index.mjs", "browser": "browser.js", "contributors": [ "Nathan Rajlich ", From 21c3f10451fc2b96ddd5db155f7ff5e1d140dc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=2E=20Rom=C3=A1n?= Date: Thu, 2 Jun 2022 10:31:55 +0200 Subject: [PATCH 2/4] docs: updated CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b32b16f52..6d3ca1f7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ================== ### Changed ### Added +* Added ESM support. ### Fixed 2.9.1 From ba0e4ff97b02f44d4a8a645dcc566fc88d0c6a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=2E=20Rom=C3=A1n?= Date: Thu, 2 Jun 2022 21:03:12 +0200 Subject: [PATCH 3/4] refactor: destructure once Co-authored-by: Mohammed Keyvanzadeh --- index.mjs | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/index.mjs b/index.mjs index eaf713f21..158149f6c 100644 --- a/index.mjs +++ b/index.mjs @@ -1,28 +1,28 @@ import mod from './index.js' export default mod; -export const { Canvas } = mod; -export const { Context2d } = mod; -export const { CanvasRenderingContext2D } = mod; -export const { CanvasGradient } = mod; -export const { CanvasPattern } = mod; -export const { Image } = mod; -export const { ImageData } = mod; -export const { PNGStream } = mod; -export const { PDFStream } = mod; -export const { JPEGStream } = mod; -export const { DOMMatrix } = mod; -export const { DOMPoint } = mod; -export const { registerFont } = mod; -export const { deregisterAllFonts } = mod; -export const { parseFont } = mod; -export const { createCanvas } = mod; -export const { createImageData } = mod; -export const { loadImage } = mod; -export const { backends } = mod; -export const { version } = mod; -export const { cairoVersion } = mod; -export const { jpegVersion } = mod; -export const { gifVersion } = mod; -export const { freetypeVersion } = mod; -export const { rsvgVersion } = mod; +export const { + Canvas, + Context2d, + CanvasRenderingContext2D, + CanvasGradient, + CanvasPattern, + Image, + ImageData, + PNGStream, + DOMMatrix, + DOMPoint, + registerFont, + deregisterAllFonts, + parseFont, + createCanvas, + createImageData, + loadImage, + backends, + version, + cairoVersion, + jpegVersion, + gifVersion, + freetypeVersion, + rsvgVersion +} = mod; From fbdeedaaafe2c5416df56c837bfbeff1e25c450d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=2E=20Rom=C3=A1n?= Date: Wed, 15 Jun 2022 21:39:44 +0200 Subject: [PATCH 4/4] fix: use `exports.[name] = value` instead --- CHANGELOG.md | 2 +- index.js | 64 +++++++++++++++++++++++++--------------------------- index.mjs | 28 ----------------------- package.json | 1 - 4 files changed, 32 insertions(+), 63 deletions(-) delete mode 100644 index.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d3ca1f7b..f104c3d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,8 @@ project adheres to [Semantic Versioning](http://semver.org/). ================== ### Changed ### Added -* Added ESM support. ### 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 diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 158149f6c..000000000 --- a/index.mjs +++ /dev/null @@ -1,28 +0,0 @@ -import mod from './index.js' - -export default mod; -export const { - Canvas, - Context2d, - CanvasRenderingContext2D, - CanvasGradient, - CanvasPattern, - Image, - ImageData, - PNGStream, - DOMMatrix, - DOMPoint, - registerFont, - deregisterAllFonts, - parseFont, - createCanvas, - createImageData, - loadImage, - backends, - version, - cairoVersion, - jpegVersion, - gifVersion, - freetypeVersion, - rsvgVersion -} = mod; diff --git a/package.json b/package.json index 69d7b4a03..5f382675e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "version": "2.9.1", "author": "TJ Holowaychuk ", "main": "index.js", - "module": "index.mjs", "browser": "browser.js", "contributors": [ "Nathan Rajlich ",