w3c / reffy

Reffy is a Web spec crawler and analyzer tool. It is notably used to update Webref
MIT License
69 stars 23 forks source link

Switch to ECMAScript modules #1628

Closed tidoust closed 1 month ago

tidoust commented 1 month ago

Shaving yaks... I naively thought a couple of updates would be all that was required to switch to ECMAScript modules. The number of updates grew a bit out of control, but nothing fantastic in there, just turning calls to require into calls to import and adjusting the logic here and there (e.g., no more __dirname). We may still end up with a couple of bad surprises on things that are not fully covered by tests but they should be easy to fix.

I refreshed a bit the post-processor logic to load the modules once at the begining of the crawl so as to avoid making other functions asynchronous.

Scripts retain a .js file extension for now, mainly because it was easier to update the code without also changing the extensions. The switch to ECMAScript modules is done in package.json instead.

Note the check process.argv[1] === fileURLToPath(import.meta.url) is not a perfect replacement for require.main === module as it does not account for cases where the script is run without specifying the file extension, but that should still be good enough for the few modules where we still need that.

One breaking change: the getSchemaValidationFunction, exported by Reffy and used in Webref, becomes asynchronous.