Skip to content

Commit 5fc85dc

Browse files
committed
build(exports): configure package exports for typescript imports
- update `.` export to use correct `import` and `require` fields - add `default` field for compatibiliy with typescript imports - rename `browser.ts` entry point to support module resolution - update build configuration to use new entry point
1 parent bfdfee0 commit 5fc85dc

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

package.json

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"url": "https://github.com/dcantu476"
2121
}
2222
],
23-
"main": "lib/Typesense.min.js",
24-
"types": "lib/Typesense.d.ts",
25-
"module": "lib/Typesense.min.mjs",
2623
"browser": {
2724
"crypto": false,
2825
"http": false,
@@ -31,20 +28,18 @@
3128
"exports": {
3229
".": {
3330
"types": "./lib/Typesense.d.ts",
34-
"import": "./lib/Typesense.min.mjs",
35-
"require": "./lib/Typesense.min.js"
31+
"default": "./lib/Typesense.js"
32+
},
33+
"./lib/Typesense/*": {
34+
"types": "./lib/Typesense/*.d.ts",
35+
"default": "./lib/Typesense/*.js"
3636
},
3737
"./dist": {
38-
"types": "./dist/Typesense.d.ts",
39-
"import": "./dist/Typesense.min.mjs",
40-
"require": "./dist/Typesense.min.js"
38+
"types": "./dist/typesense.d.ts",
39+
"import": "./dist/typesense.min.mjs",
40+
"require": "./dist/typesense.min.js"
4141
}
4242
},
43-
"files": [
44-
"lib/",
45-
"dist/",
46-
"src/"
47-
],
4843
"keywords": [
4944
"typesense",
5045
"api",
@@ -109,9 +104,8 @@
109104
"prepare": "npm run build",
110105
"test": "nyc --reporter=html --reporter=text ts-mocha --require @babel/register --recursive",
111106
"build": "tsc && tsup",
112-
"build:tsc": "tsc",
113-
"build:web:dev": "webpack --config webpack.config.js --mode development",
114-
"build:web:prod": "webpack --config webpack.config.js --mode production",
107+
"prebuild": "rimraf dist lib",
108+
"postbuild": "rimraf lib/browser*",
115109
"build:tsc:watch": "tsc --watch",
116110
"ci-lint": "eslint .",
117111
"ci-test": "nyc --reporter=text --reporter=html ts-mocha --require @babel/register --reporter mocha-junit-reporter --recursive --colors",

src/Typesense.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import SearchClient from "./Typesense/SearchClient";
21
import Client from "./Typesense/Client";
2+
import SearchClient from "./Typesense/SearchClient";
3+
import * as Errors from "./Typesense/Errors";
34

4-
export { SearchClient };
5-
export { Client };
6-
export * as Errors from "./Typesense/Errors";
7-
5+
export { Client, SearchClient, Errors };
6+
export default { Client, SearchClient, Errors };
87
export type * from "./Typesense/Aliases";
98
export type * from "./Typesense/AnalyticsEvent";
109
export type * from "./Typesense/AnalyticsRule";

src/browser.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import SearchClient from "./Typesense/SearchClient";
2+
import Client from "./Typesense/Client";
3+
4+
export { SearchClient };
5+
export { Client };
6+
export * as Errors from "./Typesense/Errors";
7+
8+
export type * from "./Typesense/Aliases";
9+
export type * from "./Typesense/AnalyticsEvent";
10+
export type * from "./Typesense/AnalyticsRule";
11+
export type * from "./Typesense/AnalyticsRules";
12+
export type * from "./Typesense/Collection";
13+
export type * from "./Typesense/Collections";
14+
export type * from "./Typesense/Configuration";
15+
export type * from "./Typesense/Conversations";
16+
export type * from "./Typesense/Conversation";
17+
export type * from "./Typesense/ConversationModel";
18+
export type * from "./Typesense/Debug";
19+
export type * from "./Typesense/Documents";
20+
export type * from "./Typesense/Health";
21+
export type * from "./Typesense/Key";
22+
export type * from "./Typesense/Keys";
23+
export type * from "./Typesense/Metrics";
24+
export type * from "./Typesense/MultiSearch";
25+
export type * from "./Typesense/Override";
26+
export type * from "./Typesense/Overrides";
27+
export type * from "./Typesense/Preset";
28+
export type * from "./Typesense/Presets";
29+
export type * from "./Typesense/Stats";
30+
export type * from "./Typesense/Stopword";
31+
export type * from "./Typesense/Stopwords";
32+
export type * from "./Typesense/Synonym";
33+
export type * from "./Typesense/Synonyms";

tsup.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { nodeModulesPolyfillPlugin } from "esbuild-plugins-node-modules-polyfill
66
export default defineConfig([
77
{
88
target: browserList(["defaults"]) as Options["target"],
9-
entry: ["src/Typesense.ts"],
9+
entry: {
10+
typesense: "src/browser.ts",
11+
},
1012
sourcemap: true,
1113
clean: true,
1214
format: ["cjs", "esm"],

0 commit comments

Comments
 (0)