APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
952 stars 227 forks source link

Webpack and Babel #290

Closed philsturgeon closed 6 months ago

philsturgeon commented 1 year ago

I have zero experience in setting up Webpack and Babel but apparently that's going to be needed to ESMify this package and remove a lot of the old-school JS stuff in here.

Modernizing and deleting things to simplify life sounds good, and made #288 seem appealing, but it's turned into a bit of a mess as it now seems like we'll need to make everything completely ESM and then convert to CommonJS format with Babel?

If anyone can do this I will pay them money, and if anyone wants this but doesn't know how please sponsor the package so that I have money to pay whoever does it.

philsturgeon commented 1 year ago

Or do we use SWC as its quicker or something. https://blog.logrocket.com/why-you-should-use-swc/

wparad commented 1 year ago

I recently wrapped this library to inline a bunch of things, and introduced babel, if someone picks this issue up the changes might provide some good inspiration: https://github.com/Rhosys/openapi-resolver.js

kevinswiber commented 1 year ago

I don't think Webpack or Babel are needed for this. If we want the codebase to be ESM, we can set type to module in package.json and have conditional exports that look like:

{
  "exports": {
    "import": "lib/index.js",
    "require": "lib/index.cjs"
  }
}

Then index.cjs can re-export what's in index.js but for CommonJS. This should work for Node versions all the way back to 12.6.x.

philsturgeon commented 1 year ago

@kevinswiber oh if that works then brilliant! I had a quick go and again clearly don't know what I'm doing because my wild stabs are giving more errors.

image