-
Notifications
You must be signed in to change notification settings - Fork 110
chore(treewide): natively support CommonJS #334
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
Changes from all commits
613852f
35b881b
09afb76
b1b3136
8095937
7840443
9d82e89
976821c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@livekit/rtc-node": minor | ||
| "livekit-server-sdk": minor | ||
| --- | ||
|
|
||
| natively support CommonJS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,15 @@ | |
| "author": "LiveKit", | ||
| "version": "0.11.1", | ||
| "main": "dist/index.js", | ||
| "require": "dist/index.cjs", | ||
| "types": "dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.js", | ||
| "require": "./dist/index.cjs" | ||
| } | ||
| }, | ||
| "type": "module", | ||
| "repository": { | ||
| "type": "git", | ||
|
|
@@ -42,6 +50,7 @@ | |
| "@napi-rs/cli": "^2.18.0", | ||
| "@types/node": "^20.9.2", | ||
| "prettier": "^3.0.3", | ||
| "tsup": "^8.3.5", | ||
| "typescript": "^5.2.2" | ||
| }, | ||
| "optionalDependencies": { | ||
|
|
@@ -56,9 +65,9 @@ | |
| }, | ||
| "scripts": { | ||
| "prebuild": "node -p \"'export const SDK_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts", | ||
| "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/", | ||
| "build": "pnpm build:ts && napi build --platform --release --dts native.d.ts --js native.cjs --pipe \"prettier -w\" src/napi", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a wrapper for esm, napi only generates CJS
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the error you're running into?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something about not being able to find the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🤷♀️ |
||
| "artifacts": "pnpm build:ts && napi artifacts", | ||
| "build:debug": "napi build --platform", | ||
| "lint": "eslint -f unix \"src/**/*.ts\" --ignore-pattern \"src/proto/*\"", | ||
| "universal": "napi universal", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "module": "ES2020", | ||
| "module": "ES2015", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the oldest node version we want to support?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| "esModuleInterop": true, | ||
| "allowJs": true, | ||
| "declaration": true, | ||
| "declarationMap": true, | ||
| "target": "es2020", | ||
| "lib": ["es2020"], | ||
| "target": "es2015", | ||
| "lib": ["es2015"], | ||
| "moduleResolution": "node", | ||
| "sourceMap": true, | ||
| "outDir": "dist", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { defineConfig } from 'tsup'; | ||
|
|
||
| import defaults from '../../tsup.config'; | ||
|
|
||
| export default defineConfig({ | ||
| ...defaults, | ||
| external: [/\.\/.*\.cjs/, /\.\/.*.node/], | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { defineConfig } from 'tsup'; | ||
|
|
||
| import defaults from '../../tsup.config'; | ||
|
|
||
| export default defineConfig({ | ||
| ...defaults, | ||
| }); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
buildscript 👀There was a problem hiding this comment.
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 🤷
There was a problem hiding this comment.
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