Skip to content

Commit

Permalink
build(exports): configure package exports for typescript imports
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tharropoulos committed Feb 6, 2025
1 parent bfdfee0 commit 5fc85dc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
26 changes: 10 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"url": "https://github.com/dcantu476"
}
],
"main": "lib/Typesense.min.js",
"types": "lib/Typesense.d.ts",
"module": "lib/Typesense.min.mjs",
"browser": {
"crypto": false,
"http": false,
Expand All @@ -31,20 +28,18 @@
"exports": {
".": {
"types": "./lib/Typesense.d.ts",
"import": "./lib/Typesense.min.mjs",
"require": "./lib/Typesense.min.js"
"default": "./lib/Typesense.js"
},
"./lib/Typesense/*": {
"types": "./lib/Typesense/*.d.ts",
"default": "./lib/Typesense/*.js"
},
"./dist": {
"types": "./dist/Typesense.d.ts",
"import": "./dist/Typesense.min.mjs",
"require": "./dist/Typesense.min.js"
"types": "./dist/typesense.d.ts",
"import": "./dist/typesense.min.mjs",
"require": "./dist/typesense.min.js"
}
},
"files": [
"lib/",
"dist/",
"src/"
],
"keywords": [
"typesense",
"api",
Expand Down Expand Up @@ -109,9 +104,8 @@
"prepare": "npm run build",
"test": "nyc --reporter=html --reporter=text ts-mocha --require @babel/register --recursive",
"build": "tsc && tsup",
"build:tsc": "tsc",
"build:web:dev": "webpack --config webpack.config.js --mode development",
"build:web:prod": "webpack --config webpack.config.js --mode production",
"prebuild": "rimraf dist lib",
"postbuild": "rimraf lib/browser*",
"build:tsc:watch": "tsc --watch",
"ci-lint": "eslint .",
"ci-test": "nyc --reporter=text --reporter=html ts-mocha --require @babel/register --reporter mocha-junit-reporter --recursive --colors",
Expand Down
9 changes: 4 additions & 5 deletions src/Typesense.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import SearchClient from "./Typesense/SearchClient";
import Client from "./Typesense/Client";
import SearchClient from "./Typesense/SearchClient";
import * as Errors from "./Typesense/Errors";

export { SearchClient };
export { Client };
export * as Errors from "./Typesense/Errors";

export { Client, SearchClient, Errors };
export default { Client, SearchClient, Errors };
export type * from "./Typesense/Aliases";
export type * from "./Typesense/AnalyticsEvent";
export type * from "./Typesense/AnalyticsRule";
Expand Down
33 changes: 33 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SearchClient from "./Typesense/SearchClient";
import Client from "./Typesense/Client";

export { SearchClient };
export { Client };
export * as Errors from "./Typesense/Errors";

export type * from "./Typesense/Aliases";
export type * from "./Typesense/AnalyticsEvent";
export type * from "./Typesense/AnalyticsRule";
export type * from "./Typesense/AnalyticsRules";
export type * from "./Typesense/Collection";
export type * from "./Typesense/Collections";
export type * from "./Typesense/Configuration";
export type * from "./Typesense/Conversations";
export type * from "./Typesense/Conversation";
export type * from "./Typesense/ConversationModel";
export type * from "./Typesense/Debug";
export type * from "./Typesense/Documents";
export type * from "./Typesense/Health";
export type * from "./Typesense/Key";
export type * from "./Typesense/Keys";
export type * from "./Typesense/Metrics";
export type * from "./Typesense/MultiSearch";
export type * from "./Typesense/Override";
export type * from "./Typesense/Overrides";
export type * from "./Typesense/Preset";
export type * from "./Typesense/Presets";
export type * from "./Typesense/Stats";
export type * from "./Typesense/Stopword";
export type * from "./Typesense/Stopwords";
export type * from "./Typesense/Synonym";
export type * from "./Typesense/Synonyms";
4 changes: 3 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { nodeModulesPolyfillPlugin } from "esbuild-plugins-node-modules-polyfill
export default defineConfig([
{
target: browserList(["defaults"]) as Options["target"],
entry: ["src/Typesense.ts"],
entry: {
typesense: "src/browser.ts",
},
sourcemap: true,
clean: true,
format: ["cjs", "esm"],
Expand Down

0 comments on commit 5fc85dc

Please sign in to comment.