1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
Description: don't download types from Internet
also drop prettier and fix ts for our old tsc
Author: Yadd <yadd@debian.org>
Forwarded: not-needed
Last-Update: 2025-10-07
--- a/scripts/build.ts
+++ b/scripts/build.ts
@@ -3,13 +3,12 @@
import chalk from 'chalk';
import { MimeDatabase, MimeEntry } from 'mime-db';
import mimeScore, { FACET_SCORES } from 'mime-score';
-import { mkdir, writeFile } from 'node:fs/promises';
+import { mkdir, writeFile, readFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
-import * as prettier from 'prettier';
const TYPES_MARKER = '/* TYPES GO HERE */';
-const TYPES_TEMPLATE = `const types = ${TYPES_MARKER} as const satisfies Readonly<{ [key: string]: string[] }>;
+const TYPES_TEMPLATE = `const types = ${TYPES_MARKER} as Record<string, string[]>;
// Make readonly
Object.freeze(types);
@@ -20,7 +19,7 @@
'https://raw.githubusercontent.com/jshttp/mime-db/master/db.json';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
-const ROOT_DIR = __dirname.replace(/\/mime\/.*/, '/mime');
+const ROOT_DIR = path.join(__dirname, '..', '..');
if (ROOT_DIR === __dirname) {
throw new Error('Could not find root directory');
@@ -32,8 +31,6 @@
score: number;
};
-const PRETTIER_OPTIONS = await prettier.resolveConfig(__dirname);
-
function normalizeTypes(types: MimeDatabase) {
const cloned: Record<string, MimeScoreEntry> = {};
const byExtension: Record<string, MimeScoreEntry> = {};
@@ -108,21 +105,12 @@
// Generate source content
let source = TYPES_TEMPLATE.replace(TYPES_MARKER, JSON.stringify(types));
- // Format
- source = await prettier.format(source, {
- parser: 'typescript',
- ...PRETTIER_OPTIONS,
- });
-
await writeFile(filepath, source);
}
async function main() {
- const mimedb = await fetch(MIME_DB_URL).then((res) => {
- if (!res.ok) {
- throw new Error(`Failed to fetch mime-db: ${res.url} ${res.statusText}`);
- }
- return res.json() as Promise<MimeDatabase>;
+ const mimedb = await readFile('debian/db.json').then((res) => {
+ return JSON.parse(res.toString()) as Promise<MimeDatabase>;
});
const types = normalizeTypes(mimedb);
|