Skip to content

Commit 056bc8f

Browse files
committed
fix: use proper dual-packaging
Support CommonJS & ESM. Previously the ESM build (dist/module) is broken - it's recognized as CommonJS. For more on dual-packaging: https://nodejs.org/api/packages.html#dual-commonjses-module-packages
1 parent 52bf37f commit 056bc8f

File tree

6 files changed

+284
-15
lines changed

6 files changed

+284
-15
lines changed

package-lock.json

+256
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+12-7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
"dist",
1616
"src"
1717
],
18-
"main": "dist/main/index.js",
19-
"module": "dist/module/index.js",
20-
"types": "dist/module/index.d.ts",
18+
"main": "dist/cjs/index.js",
19+
"module": "dist/esm/wrapper.mjs",
20+
"exports": {
21+
"import": "./dist/esm/wrapper.mjs",
22+
"require": "./dist/cjs/index.js"
23+
},
24+
"types": "dist/cjs/index.d.ts",
2125
"sideEffects": false,
2226
"repository": "supabase/supabase-js",
2327
"scripts": {
2428
"clean": "rimraf dist docs/v2",
25-
"format": "prettier --write \"{src,test}/**/*.ts\"",
29+
"format": "prettier --write \"{src,test}/**/*.ts\" wrapper.mjs",
2630
"build": "run-s clean format build:*",
27-
"build:main": "tsc -p tsconfig.json",
28-
"build:module": "tsc -p tsconfig.module.json",
31+
"build:cjs": "tsc -p tsconfig.json",
32+
"build:esm": "cpy wrapper.mjs dist/esm/",
2933
"build:umd": "webpack",
3034
"types-generate": "dts-gen -m '@supabase/supabase-js' -s",
3135
"test": "run-s test:types test:run",
@@ -34,7 +38,7 @@
3438
"test:db": "cd infra/db && docker-compose down && docker-compose up -d && sleep 5",
3539
"test:watch": "jest --watch --verbose false --silent false",
3640
"test:clean": "cd infra/db && docker-compose down",
37-
"test:types": "run-s build:module && tsd --files test/*.test-d.ts",
41+
"test:types": "run-s build && tsd --files test/*.test-d.ts",
3842
"docs": "typedoc --entryPoints src/index.ts --out docs/v2 --includes src/**/*.ts",
3943
"docs:json": "typedoc --entryPoints src/index.ts --includes src/**/*.ts --json docs/v2/spec.json --excludeExternals",
4044
"serve:coverage": "npm run test:coverage && serve test/coverage"
@@ -50,6 +54,7 @@
5054
"devDependencies": {
5155
"@sebbo2002/semantic-release-jsr": "^1.0.0",
5256
"@types/jest": "^29.2.5",
57+
"cpy-cli": "^5.0.0",
5358
"husky": "^4.3.0",
5459
"jest": "^29.3.1",
5560
"npm-run-all": "^4.1.5",

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Always update wrapper.mjs when updating this file.
2+
13
import SupabaseClient from './SupabaseClient'
24
import type { GenericSchema, SupabaseClientOptions } from './lib/types'
35

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"declaration": true,
66
"declarationMap": true,
77
"module": "CommonJS",
8-
"outDir": "dist/main",
8+
"outDir": "dist/cjs",
99
"sourceMap": true,
1010
"target": "ES2015",
1111

tsconfig.module.json

-7
This file was deleted.

wrapper.mjs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import cjsModule from '../cjs/index.js'
2+
3+
export * from '@supabase/auth-js'
4+
export {
5+
FunctionsHttpError,
6+
FunctionsFetchError,
7+
FunctionsRelayError,
8+
FunctionsError,
9+
FunctionRegion,
10+
} from '@supabase/functions-js'
11+
export * from '@supabase/realtime-js'
12+
export { default as SupabaseClient } from '../cjs/SupabaseClient.js'
13+
export const createClient = cjsModule.createClient

0 commit comments

Comments
 (0)