Skip to content

Commit 3a54eae

Browse files
flevi29Strift
authored andcommitted
Use package.json directly for version in src files, bundle ESM as well
1 parent d70451a commit 3a54eae

File tree

7 files changed

+18
-31
lines changed

7 files changed

+18
-31
lines changed

.github/scripts/check-release.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,5 @@ if [ "$current_tag" != "$package_json_version" ]; then
1010
exit 1
1111
fi
1212

13-
package_version_ts=$(grep "PACKAGE_VERSION =" src/package-version.ts | cut -d "=" -f 2- | tr -d ';' | tr -d " " | tr -d '"')
14-
if [ "$current_tag" != "$package_version_ts" ]; then
15-
echo "Error: the current tag does not match the version in src/package-version.ts."
16-
echo "$current_tag vs $package_version_ts"
17-
exit 1
18-
fi
19-
2013
echo 'OK'
2114
exit 0

CONTRIBUTING.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ Make a PR modifying the following files with the right version:
125125
"version": "X.X.X",
126126
```
127127

128-
[`src/package-version`](/src/package-version.ts)
129-
130-
```javascript
131-
export const PACKAGE_VERSION = 'X.X.X'
132-
```
133-
134128
#### Github publish
135129

136130
Once the changes are merged on `main`, you can publish the current draft release via the [GitHub interface](https://github.com/meilisearch/meilisearch-js/releases): on this page, click on `Edit` (related to the draft release) > update the description (be sure you apply [these recommendations](https://github.com/meilisearch/integration-guides/blob/main/resources/integration-release.md#writting-the-release-description)) > when you are ready, click on `Publish release`.

src/http-requests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
URLSearchParamsRecord,
77
MeiliSearchErrorResponse,
88
} from "./types/index.js";
9-
import { PACKAGE_VERSION } from "./package-version.js";
9+
import pkg from "../package.json" with { type: "json" };
1010
import {
1111
MeiliSearchError,
1212
MeiliSearchApiError,
@@ -42,7 +42,7 @@ function appendRecordToURLSearchParams(
4242
*/
4343
function getHeaders(config: Config, headersInit?: HeadersInit): Headers {
4444
const agentHeader = "X-Meilisearch-Client";
45-
const packageAgent = `Meilisearch JavaScript (v${PACKAGE_VERSION})`;
45+
const packageAgent = `Meilisearch JavaScript (v${pkg.version})`;
4646
const contentType = "Content-Type";
4747
const authorization = "Authorization";
4848

src/package-version.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/client.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "vitest";
1111
import type { Health, Version, Stats, IndexSwap } from "../src/index.js";
1212
import { ErrorStatusCode, MeiliSearchRequestError } from "../src/index.js";
13-
import { PACKAGE_VERSION } from "../src/package-version.js";
13+
import pkg from "../package.json" with { type: "json" };
1414
import {
1515
clearAllIndexes,
1616
getKey,
@@ -320,7 +320,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
320320
assert.instanceOf(requestInit.headers, Headers);
321321
assert.strictEqual(
322322
requestInit.headers.get("X-Meilisearch-Client"),
323-
`Meilisearch JavaScript (v${PACKAGE_VERSION})`,
323+
`Meilisearch JavaScript (v${pkg.version})`,
324324
);
325325
});
326326

@@ -341,7 +341,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
341341
assert.instanceOf(requestInit.headers, Headers);
342342
assert.strictEqual(
343343
requestInit.headers.get("X-Meilisearch-Client"),
344-
`Meilisearch JavaScript (v${PACKAGE_VERSION})`,
344+
`Meilisearch JavaScript (v${pkg.version})`,
345345
);
346346
});
347347

@@ -362,7 +362,7 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
362362
assert.instanceOf(requestInit.headers, Headers);
363363
assert.strictEqual(
364364
requestInit.headers.get("X-Meilisearch-Client"),
365-
`random plugin 1 ; random plugin 2 ; Meilisearch JavaScript (v${PACKAGE_VERSION})`,
365+
`random plugin 1 ; random plugin 2 ; Meilisearch JavaScript (v${pkg.version})`,
366366
);
367367
});
368368
});

tsconfig.build.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"declaration": true,
5+
"emitDeclarationOnly": true,
56
"declarationMap": true,
6-
"declarationDir": "./dist/types",
7-
"sourceMap": true,
8-
"outDir": "./dist/esm"
7+
"declarationDir": "./dist/types"
98
},
109
"include": ["src/**/*.ts"]
1110
}

vite.config.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,37 @@ const tokenInput = "src/token.ts";
66
const globalVarName = pkg.name;
77

88
export default defineConfig(({ mode }) => {
9-
const isCJSBuild = mode === "production";
9+
const isNotUMDBuild = mode === "production";
1010

1111
return {
1212
build: {
1313
// for UMD build we do not want to empty directory, so previous builds stay intact
14-
emptyOutDir: isCJSBuild,
14+
emptyOutDir: isNotUMDBuild,
1515
// don't minify CJS build, Node.js doesn't benefit from it
16-
minify: !isCJSBuild,
16+
minify: !isNotUMDBuild,
1717
sourcemap: true,
1818
// UMD build should target the lowest level ES,
1919
// while CJS the lowest Node.js LTS/Maintenance compatible version (https://node.green/#ES2023)
20-
target: isCJSBuild ? "es2023" : "es6",
20+
target: isNotUMDBuild ? "es2023" : "es6",
2121
lib: {
2222
// leave out token export from UMD build
23-
entry: isCJSBuild ? [indexInput, tokenInput] : indexInput,
24-
name: isCJSBuild ? undefined : globalVarName,
25-
formats: isCJSBuild ? ["cjs"] : ["umd"],
23+
entry: isNotUMDBuild ? [indexInput, tokenInput] : indexInput,
24+
name: isNotUMDBuild ? undefined : globalVarName,
25+
formats: isNotUMDBuild ? ["cjs", "es"] : ["umd"],
2626
fileName: (format, entryName) => {
2727
switch (format) {
2828
case "umd":
2929
return `umd/${entryName}.min.js`;
3030
case "cjs":
3131
return `cjs/${entryName}.cjs`;
32+
case "es":
33+
return `esm/${entryName}.js`;
3234
default:
3335
throw new Error(`unsupported format ${format}`);
3436
}
3537
},
3638
},
37-
rollupOptions: !isCJSBuild
39+
rollupOptions: !isNotUMDBuild
3840
? // the following code enables Vite in UMD mode to extend the global object with all of
3941
// the exports, and not just a property of it ( https://github.com/vitejs/vite/issues/11624 )
4042
// TODO: Remove this in the future ( https://github.com/meilisearch/meilisearch-js/issues/1806 )

0 commit comments

Comments
 (0)