geraintluff / uri-templates

JavaScript utility for RFC 6570: URI Templates
138 stars 21 forks source link

feat: offer ESM source/dist #29

Closed brettz9 closed 8 months ago

brettz9 commented 9 months ago

feat: offer ESM source/dist

Also:

This PR technically introduces a breaking change by adding exports to package.json, offering encapsulation by restricting access by Node to other files except those specified in exports. We could allow other files through, but I figure it is not necessary. (Browsers can still access the minified file, of course.)

I had to update source-map-support for the sake of adding Rollup. (The other package.json changes were just alphabetizing the devDependencies.)

What I essentially did in this PR was to extract the bulk of your UMD code into an ESM source file, and then have Rollup convert that ESM file into a UMD file.

The Rollup process overwrites the preexisting UMD file, but as you can see, it barely changes the original UMD file at all, since I didn't introduce any other changes from your code in the new ESM source. (The changes to the now-auto-generated UMD file that do exist were introduced by Rollup.) This process lets you see that there were no other changes introduced, allowing you to easily review any other changes going forward, while still having just one authoritative source file.

If it's ok with you, I can update the other devDependencies, dropping Grunt in favor of npm scripts and Rollup plugins, switching to ESLint, etc., as per more common current practices. I could also drop the bower.json file as it is deprecated. If so, let me know if you want it in this PR.

For future PRs, I'd like to use const/let in source, optionally using Babel on the source to compile for very old environments. I'd also like to generate a TypeScript declaration file from JavaScript source, as I find it reassuring to check the code with TypeScript and ensure the types are up to date. (TypeScript does indeed let one use plain JavaScript in source, so long as it has appropriate JSDoc comments.).