rkusa / pdfjs

A Portable Document Format (PDF) generation library targeting both the server- and client-side.
MIT License
767 stars 142 forks source link

Convert to es6 modules #87

Open rkusa opened 6 years ago

rkusa commented 6 years ago

Before leaving alpha, the library should be converted to using es6 modules.

rkusa commented 6 years ago

Anyone aware of a tool to automatically convert a library to es6 modules?

rkusa commented 6 years ago

While I did an initial conversion, I am not yet sure how to handle the fact that pdfjs should work for both server and client. Since Node.js requires the file extension of .mjs

jpbourgeon commented 6 years ago

Hello have a look here https://github.com/nolanlawson/cjs-to-es6

Other ideas on stackoverflow https://stackoverflow.com/questions/43106130/convert-existing-legacy-library-to-es6-module

rkusa commented 6 years ago

Hi @jpbourgeon, thanks for the links. I have already converted the library in a local branch, but was not able to find a good es6 modules solution for libraries that target both server (Node.js) and client πŸ˜•

jpbourgeon commented 6 years ago

Would it help to split the library into two components and take advantage of npmjs namespaces?

Something like @pdfjs/server and @pdfjs/browser

rkusa commented 6 years ago

I guess there are the following options.

1) Write client-side ES modules (.js)

2) Write server-side ES modules (.mjs)

3) Keep CJS modules

In Summary, either transpile the code for Node.js usage or live with import {Document} from "pdfjs". TBH, I really dislike both options πŸ˜•

rkusa commented 5 years ago

The conversion happens here https://github.com/rkusa/pdfjs/tree/es6-modules Though, the branch is unfortunately not green yet

AllNamesRTaken commented 5 years ago

Would it be of interest to move to TS instead of ES6?

amotl commented 5 years ago

Would it be of interest to move to TS instead of ES6?

I've recently had the pleasure to work on a TypeScript codebase [1] using WebStorm [2]Β and I want to report that the overall experience is absolutely amazing and totally washed away any hesitations I had regarding TypeScript. Finally, I feel like I can get similar productive with JavaScript as I am with Python. ES6 did not give me that feeling yet.

[1] https://github.com/hiveeyes/grafana-worldmap-panel [2] https://www.jetbrains.com/webstorm/


@rkusa: Amazing project, greetings from Berlin and keep up the spirit!

AllNamesRTaken commented 5 years ago

My pet project is https://github.com/AllNamesRTaken/GoodCore outside workhours and i could help out is needed.

amotl commented 5 years ago

@AllNamesRTaken: Sounds interesting, thanks for letting us know. Star-given ;].

rkusa commented 5 years ago

Would it be of interest to move to TS instead of ES6?

I am, generally speaking, not opposed to TS.

I've recently had the pleasure to work on a TypeScript codebase [1] using WebStorm [2] and I want to report that the overall experience is absolutely amazing and totally washed away any hesitations I had regarding TypeScript.

I can confirm that. In my day job, I also work more with TS than JS and the whole TS dev experience (editor integration, less errors when refactoring, ...) is superior than JS ...


What currently holds me off from converting the codebase to TS: