readmeio / api

🚀 Automatic SDK generation from an OpenAPI definition
https://api.readme.dev
MIT License
599 stars 26 forks source link

fix: use correct import attributes syntax #957

Closed kanadgupta closed 1 week ago

kanadgupta commented 1 week ago
🚥 Resolves #950

🧰 Changes

(PR description stolen from https://github.com/readmeio/rdme/pull/993)

TC39 updated their import assertions to be import attributes and it's a bit of a mess now that we're running tests against Node v22.

Here's what importing JSON in ESM used to look like:

import { x } from "./mod" assert { type: "json" }

now it looks like this:

import { x } from "./mod" with { type: "json" };

Support for this new with keyword was added in Node v18.20.0 and Node v20.10.0 (and is supported on all v21 and v22 channels), but importantly the older assert keyword is not supported in Node v22, so unfortunately our package.json#engines.node field is going to look a little ridiculous for the time being.

Details: https://github.com/tc39/proposal-import-attributes?tab=readme-ov-file#history

🧬 QA & Testing

Annoyingly, we don't have anything in our unit tests to catch this sort of thing at the moment because we have stuff like this:

https://github.com/readmeio/api/blob/353cd8b52cdab893f7297f0fbf3ced1da6de352c/packages/api/src/codegen/languages/typescript/index.ts#L127-L130

but I confirmed that Node v22 works again with this change. See the before:

CleanShot 2024-11-18 at 08 32 53@2x

And the after:

CleanShot 2024-11-18 at 08 33 18@2x