Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(treewide): natively support CommonJS #334

Merged
merged 8 commits into from
Nov 28, 2024
Merged

chore(treewide): natively support CommonJS #334

merged 8 commits into from
Nov 28, 2024

Conversation

nbsp
Copy link
Member

@nbsp nbsp commented Nov 13, 2024

closes #304

Copy link

changeset-bot bot commented Nov 13, 2024

🦋 Changeset detected

Latest commit: 976821c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@livekit/rtc-node Minor
livekit-server-sdk Minor
agent-dispatch Patch
@livekit/rtc-node-darwin-arm64 Minor
@livekit/rtc-node-darwin-x64 Minor
@livekit/rtc-node-linux-arm64-gnu Minor
@livekit/rtc-node-linux-x64-gnu Minor
@livekit/rtc-node-win32-x64-msvc Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -1,12 +1,12 @@
{
"compilerOptions": {
"module": "ES2020",
"module": "ES2015",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the oldest node version we want to support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure but if it works with es2015 it'll work with all of them. before es2015 there was no const/let, so it's not worth going back any more

tsup.config.ts Outdated Show resolved Hide resolved
tsconfig.json Outdated Show resolved Hide resolved
"build:tsc": "pnpm prebuild && tsc && cp -r src/napi dist/",
"build": "pnpm build:tsc && napi build --platform --release --dts native.d.ts --js native.cjs --pipe \"prettier -w\" src/napi",
"artifacts": "pnpm build:tsc && napi artifacts",
"build:ts": "pnpm prebuild && tsup --onSuccess \"tsc --declaration --emitDeclarationOnly\" && cp -r src/napi dist/ && cp -r src/napi/* dist/",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is silly but it's to get around esbuild's issues with dynamic import of fs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the order of things correct here? it looks like it first copies napi files but napi build is only called afterwards in the build script 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm it was like this also before, just not sure I understand the reason 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a few files in src/napi already pre-generation, namely the shim to translate them from CJS to ESM if needed. i do think this might be a bit more convoluted than necessary but it works and doesn't seem to take too long on this part

"build": "pnpm build:tsc && napi build --platform --release --dts native.d.ts --js native.cjs --pipe \"prettier -w\" src/napi",
"artifacts": "pnpm build:tsc && napi artifacts",
"build:ts": "pnpm prebuild && tsup --onSuccess \"tsc --declaration --emitDeclarationOnly\" && cp -r src/napi dist/ && cp -r src/napi/* dist/",
"build": "pnpm build:ts && napi build --platform --release --dts native.d.ts --js native.cjs --pipe \"prettier -w\" src/napi",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like napi is only building for cjs, is that the behaviour we want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a wrapper for esm, napi only generates CJS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: this doesn't actually work, tried using agents and it broke. unsure where to go from here because napi doesn't do ESM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the error you're running into?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something about not being able to find the native.cjs file when running it under cjs. can't reproduce right now, i'm having a different issue related to tsup on Agents in specific

Copy link
Member Author

@nbsp nbsp Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upon further testing with node-sdks examples directly this doesn't appear to be reproducible 🤷‍♀️

@nbsp nbsp marked this pull request as ready for review November 27, 2024 10:24
@nbsp nbsp changed the title chore: support CommonJS modules chore(treewide): natively support CommonJS Nov 28, 2024
@nbsp nbsp merged commit 5a5d298 into main Nov 28, 2024
10 checks passed
@nbsp nbsp deleted the nbsp/chore/cjs branch November 28, 2024 11:26
@github-actions github-actions bot mentioned this pull request Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add commonJS support
2 participants