Skip to content

Commit

Permalink
fix: use proper dual-packaging
Browse files Browse the repository at this point in the history
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
  • Loading branch information
soedirgo committed May 22, 2024
1 parent 52bf37f commit 056bc8f
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 15 deletions.
256 changes: 256 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@
"dist",
"src"
],
"main": "dist/main/index.js",
"module": "dist/module/index.js",
"types": "dist/module/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/esm/wrapper.mjs",
"exports": {
"import": "./dist/esm/wrapper.mjs",
"require": "./dist/cjs/index.js"
},
"types": "dist/cjs/index.d.ts",
"sideEffects": false,
"repository": "supabase/supabase-js",
"scripts": {
"clean": "rimraf dist docs/v2",
"format": "prettier --write \"{src,test}/**/*.ts\"",
"format": "prettier --write \"{src,test}/**/*.ts\" wrapper.mjs",
"build": "run-s clean format build:*",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"build:cjs": "tsc -p tsconfig.json",
"build:esm": "cpy wrapper.mjs dist/esm/",
"build:umd": "webpack",
"types-generate": "dts-gen -m '@supabase/supabase-js' -s",
"test": "run-s test:types test:run",
Expand All @@ -34,7 +38,7 @@
"test:db": "cd infra/db && docker-compose down && docker-compose up -d && sleep 5",
"test:watch": "jest --watch --verbose false --silent false",
"test:clean": "cd infra/db && docker-compose down",
"test:types": "run-s build:module && tsd --files test/*.test-d.ts",
"test:types": "run-s build && tsd --files test/*.test-d.ts",
"docs": "typedoc --entryPoints src/index.ts --out docs/v2 --includes src/**/*.ts",
"docs:json": "typedoc --entryPoints src/index.ts --includes src/**/*.ts --json docs/v2/spec.json --excludeExternals",
"serve:coverage": "npm run test:coverage && serve test/coverage"
Expand All @@ -50,6 +54,7 @@
"devDependencies": {
"@sebbo2002/semantic-release-jsr": "^1.0.0",
"@types/jest": "^29.2.5",
"cpy-cli": "^5.0.0",
"husky": "^4.3.0",
"jest": "^29.3.1",
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Always update wrapper.mjs when updating this file.

import SupabaseClient from './SupabaseClient'
import type { GenericSchema, SupabaseClientOptions } from './lib/types'

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"declaration": true,
"declarationMap": true,
"module": "CommonJS",
"outDir": "dist/main",
"outDir": "dist/cjs",
"sourceMap": true,
"target": "ES2015",

Expand Down
7 changes: 0 additions & 7 deletions tsconfig.module.json

This file was deleted.

13 changes: 13 additions & 0 deletions wrapper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import cjsModule from '../cjs/index.js'

export * from '@supabase/auth-js'
export {
FunctionsHttpError,
FunctionsFetchError,
FunctionsRelayError,
FunctionsError,
FunctionRegion,
} from '@supabase/functions-js'
export * from '@supabase/realtime-js'
export { default as SupabaseClient } from '../cjs/SupabaseClient.js'
export const createClient = cjsModule.createClient

0 comments on commit 056bc8f

Please sign in to comment.