chore: update deps & search indice action refactor (#11339)

* chore: update deps & search indice action refactor

- Updated pnpm, dependencies and regenerated the lockfile
- Removed immer and some eslint plugins that weren't being used
- Updated the version of `@types/node` to v24 on internal packages as
  that's the version that is being used on github actions
- Refactored the uploadSearchIndices action slightly and upgraded the
  meilisearch dependency

* chore: remove more deps
This commit is contained in:
Almeida
2025-12-09 12:47:46 +00:00
committed by GitHub
parent 2c3bf5c817
commit 06c8da23d1
14 changed files with 544 additions and 1155 deletions

View File

@@ -48,7 +48,7 @@
"@discordjs/scripts": "workspace:^",
"cloudflare": "^5.2.0",
"commander": "^14.0.2",
"meilisearch": "^0.38.0",
"meilisearch": "^0.54.0",
"p-limit": "^7.2.0",
"p-queue": "^9.0.1",
"tslib": "^2.8.1",
@@ -56,8 +56,8 @@
},
"devDependencies": {
"@npm/types": "^2.1.0",
"@types/bun": "^1.3.3",
"@types/node": "^22.19.1",
"@types/bun": "^1.3.4",
"@types/node": "^24.10.1",
"@vitest/coverage-v8": "^4.0.15",
"cross-env": "^10.1.0",
"eslint": "^9.39.1",

View File

@@ -2,33 +2,35 @@ import process from 'node:process';
import { setFailed } from '@actions/core';
import { generateAllIndices } from '@discordjs/scripts';
import Cloudflare from 'cloudflare';
import { MeiliSearch } from 'meilisearch';
import { type EnqueuedTask, MeiliSearch } from 'meilisearch';
import pLimit from 'p-limit';
import { fetch } from 'undici';
if (!(process.env.CF_D1_DOCS_API_KEY && process.env.CF_D1_DOCS_ID && process.env.CF_ACCOUNT_ID)) {
if (!process.env.CF_D1_DOCS_API_KEY || !process.env.CF_D1_DOCS_ID || !process.env.CF_ACCOUNT_ID) {
setFailed('Missing Cloudflare D1 environment variables.');
process.exit(1);
}
if (!process.env.SEARCH_API_URL) {
setFailed('SEARCH_API_URL is not set');
process.exit(1);
}
if (!process.env.SEARCH_API_KEY) {
setFailed('SEARCH_API_KEY is not set');
process.exit(1);
}
const cf = new Cloudflare({
apiToken: process.env.CF_D1_DOCS_API_KEY!,
apiToken: process.env.CF_D1_DOCS_API_KEY,
});
const client = new MeiliSearch({
host: process.env.SEARCH_API_URL!,
apiKey: process.env.SEARCH_API_KEY!,
host: process.env.SEARCH_API_URL,
apiKey: process.env.SEARCH_API_KEY,
});
const limit = pLimit(10);
let promises: Promise<any>[] = [];
try {
console.log('Generating all indices...');
@@ -62,35 +64,31 @@ try {
console.log('Uploading indices...');
try {
promises = indices.map(async (index) =>
limit(async () => {
console.log(`Uploading ${index.index}...`);
let task;
try {
task = await client.createIndex(index.index);
} catch {}
const promises = indices.map(async (index) =>
limit(async () => {
console.log(`Uploading ${index.index}...`);
let task: EnqueuedTask | undefined;
try {
task = await client.createIndex(index.index);
} catch {}
if (task) {
await client.waitForTask(task.taskUid);
}
if (task) {
await client.tasks.waitForTask(task);
}
const searchIndex = client.index(index.index);
await searchIndex.updateSettings({ sortableAttributes: ['type'] });
const searchIndex = client.index(index.index);
await searchIndex.updateSettings({ sortableAttributes: ['type'] });
await searchIndex.addDocuments(index.data);
}),
);
} catch {}
await searchIndex.addDocuments(index.data);
}),
);
await Promise.all(promises);
console.log('Uploaded all indices.');
} catch (error) {
const err = error as Error;
console.error(err);
setFailed(err.message);
}
try {
await Promise.all(promises);
} catch (error) {
console.log(error);
process.exit(1);
}