NathanaelA / fluentreports

:page_facing_up: Fluent Reports - Data Driven Reporting Engine for Node.js and Browsers :page_facing_up:
https://fluentreports.com
MIT License
377 stars 84 forks source link

ES6 Support #268

Closed fvfv closed 1 year ago

fvfv commented 1 year ago

Trying to do an import Report from "fluentreports";

and
var pdf = new Report("buffer")

And getting the dreaded Report is not a constructor.

This tells me that there is not ES6 Support yet, which is a shame, as fluentreports is a great package.

Is there any way to use ES6 for this package ?

NathanaelA commented 1 year ago

I've uploaded v1.4.2 which has should allow esm to work fine. You will need to do: import Report from "fluentreports/lib/esm/fluentreports.mjs"; to import the esm version.

Adding a "exports" field to the package.json requires a lot more testing that I don't have time for at the moment, as it is a larger breaking change...

NathanaelA commented 1 year ago

I am looking of a the potentially breaking change adding the following "exports"

 "exports": {
    ".": [
      {
        "import": "./lib/esm/fluentReports.mjs",
        "require": "./lib/fluentReports.js"
      },
      "./lib/fluentReports.js"
    ],
    "./lib/*": "./lib/*.js",
    "./lib/*.js": "./lib/*.js",
    "./lib/esm/*": "./lib/esm/*.mjs",
    "./lib/esm/*.mjs": "./lib/esm/*.mjs",
    "./package.json": "./package.json",
    "./lib/esm/package.json": "./lib/esm/package.json"
  },

To simplify it for ESM users... Then esm users could do:

import Report from "fluentreports";

If you have any knowledge of the "exports" field in package.json, let me know if you see any corner cases that this might still break under....

fvfv commented 1 year ago

You might be right about the major changes on the Exports part.

However, what I did is to comment //(typeof exports === 'undefined' ? this : exports)); and added export default Report

On the caller side, I did import Report from "fluentreports";

And on the constructor, I did var pdf = new Report.Report("buffer", {xxxx}

I think I just got lucky.

I will implement v1.4.2

Thanks for a wonderful package.