Skip to content

Commit b7f863d

Browse files
committed
Switch to new style imports.
1 parent 9fb56c7 commit b7f863d

16 files changed

+47
-35
lines changed

fix-commonjs-dist.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as fs from 'fs'
2+
3+
fs.writeFileSync('./dist/main/package.json', '{"type": "commonjs"}')

jest.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module.exports = {
1+
export default {
22
preset: 'ts-jest',
33
testEnvironment: 'node',
4+
moduleNameMapper: {
5+
'^(\\.{1,2}/.*)\\.js$': '$1',
6+
},
47
}

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@
1414
"dist",
1515
"src"
1616
],
17+
"type": "module",
1718
"main": "dist/main/index.js",
1819
"module": "dist/module/index.js",
1920
"types": "dist/module/index.d.ts",
21+
"exports": {
22+
"require": "./dist/main/index.js",
23+
"import": "./dist/module/index.js",
24+
"types": "./dist/module/index.d.ts"
25+
},
2026
"repository": "supabase/postgrest-js",
2127
"scripts": {
2228
"clean": "rimraf dist docs/v2",
2329
"format": "prettier --write \"{src,test}/**/*.ts\"",
2430
"build": "run-s clean format build:*",
25-
"build:main": "tsc -p tsconfig.json",
31+
"build:main": "tsc -p tsconfig.json && node ./fix-commonjs-dist.js",
2632
"build:module": "tsc -p tsconfig.module.json",
2733
"docs": "typedoc src/index.ts --out docs/v2",
2834
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",

src/PostgrestBuilder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import crossFetch from 'cross-fetch'
22

3-
import type { Fetch, PostgrestSingleResponse } from './types'
3+
import type { Fetch, PostgrestSingleResponse } from './types.js'
44

55
export default abstract class PostgrestBuilder<Result>
66
implements PromiseLike<PostgrestSingleResponse<Result>>

src/PostgrestClient.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import PostgrestQueryBuilder from './PostgrestQueryBuilder'
2-
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
3-
import PostgrestBuilder from './PostgrestBuilder'
4-
import { DEFAULT_HEADERS } from './constants'
5-
import { Fetch, GenericSchema } from './types'
1+
import PostgrestQueryBuilder from './PostgrestQueryBuilder.js'
2+
import PostgrestFilterBuilder from './PostgrestFilterBuilder.js'
3+
import PostgrestBuilder from './PostgrestBuilder.js'
4+
import { DEFAULT_HEADERS } from './constants.js'
5+
import { Fetch, GenericSchema } from './types.js'
66

77
/**
88
* PostgREST client.

src/PostgrestFilterBuilder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PostgrestTransformBuilder from './PostgrestTransformBuilder'
2-
import { GenericSchema } from './types'
1+
import PostgrestTransformBuilder from './PostgrestTransformBuilder.js'
2+
import { GenericSchema } from './types.js'
33

44
type FilterOperator =
55
| 'eq'

src/PostgrestQueryBuilder.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import PostgrestBuilder from './PostgrestBuilder'
2-
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
3-
import { GetResult } from './select-query-parser'
4-
import { Fetch, GenericSchema, GenericTable, GenericView } from './types'
1+
import PostgrestBuilder from './PostgrestBuilder.js'
2+
import PostgrestFilterBuilder from './PostgrestFilterBuilder.js'
3+
import { GetResult } from './select-query-parser.js'
4+
import { Fetch, GenericSchema, GenericTable, GenericView } from './types.js'
55

66
export default class PostgrestQueryBuilder<
77
Schema extends GenericSchema,

src/PostgrestTransformBuilder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import PostgrestBuilder from './PostgrestBuilder'
2-
import { GetResult } from './select-query-parser'
3-
import { GenericSchema } from './types'
1+
import PostgrestBuilder from './PostgrestBuilder.js'
2+
import { GetResult } from './select-query-parser.js'
3+
import { GenericSchema } from './types.js'
44

55
export default class PostgrestTransformBuilder<
66
Schema extends GenericSchema,

src/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { version } from './version'
1+
import { version } from './version.js'
22
export const DEFAULT_HEADERS = { 'X-Client-Info': `postgrest-js/${version}` }

src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
export { default as PostgrestClient } from './PostgrestClient'
2-
export { default as PostgrestQueryBuilder } from './PostgrestQueryBuilder'
3-
export { default as PostgrestFilterBuilder } from './PostgrestFilterBuilder'
4-
export { default as PostgrestTransformBuilder } from './PostgrestTransformBuilder'
5-
export { default as PostgrestBuilder } from './PostgrestBuilder'
1+
export { default as PostgrestClient } from './PostgrestClient.js'
2+
export { default as PostgrestQueryBuilder } from './PostgrestQueryBuilder.js'
3+
export { default as PostgrestFilterBuilder } from './PostgrestFilterBuilder.js'
4+
export { default as PostgrestTransformBuilder } from './PostgrestTransformBuilder.js'
5+
export { default as PostgrestBuilder } from './PostgrestBuilder.js'
66
export {
77
PostgrestResponse,
88
PostgrestResponseFailure,
99
PostgrestResponseSuccess,
1010
PostgrestSingleResponse,
1111
PostgrestMaybeSingleResponse,
1212
PostgrestError,
13-
} from './types'
13+
} from './types.js'

src/select-query-parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Credits to @bnjmnt4n (https://www.npmjs.com/package/postgrest-query)
22

3-
import { GenericSchema, Prettify } from './types'
3+
import { GenericSchema, Prettify } from './types.js'
44

55
type Whitespace = ' ' | '\n' | '\t'
66

test/basic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { PostgrestClient } from '../src/index'
2-
import { Database } from './types'
1+
import { PostgrestClient } from '../src/index.js'
2+
import { Database } from './types.js'
33

44
const REST_URL = 'http://localhost:3000'
55
const postgrest = new PostgrestClient<Database>(REST_URL)

test/filters.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { PostgrestClient } from '../src/index'
2-
import { Database } from './types'
1+
import { PostgrestClient } from '../src/index.js'
2+
import { Database } from './types.js'
33

44
const postgrest = new PostgrestClient<Database>('http://localhost:3000')
55

test/index.test-d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expectError, expectType } from 'tsd'
2-
import { PostgrestClient } from '../src/index'
3-
import { Database, Json } from './types'
2+
import { PostgrestClient } from '../src/index.js'
3+
import { Database, Json } from './types.js'
44

55
const REST_URL = 'http://localhost:3000'
66
const postgrest = new PostgrestClient<Database>(REST_URL)

test/resource-embedding.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { PostgrestClient } from '../src/index'
2-
import { Database } from './types'
1+
import { PostgrestClient } from '../src/index.js'
2+
import { Database } from './types.js'
33

44
const postgrest = new PostgrestClient<Database>('http://localhost:3000')
55

test/transforms.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { PostgrestClient } from '../src/index'
2-
import { Database } from './types'
1+
import { PostgrestClient } from '../src/index.js'
2+
import { Database } from './types.js'
33

44
import { AbortController } from 'node-abort-controller'
55

0 commit comments

Comments
 (0)