Update NPM packaging, linting, and a bunch of types (#275)

Preparation for
https://github.com/webrecorder/archiveweb.page/issues/198 /
https://github.com/webrecorder/archiveweb.page/pull/199.

## Changes

- Organizes published files more cleanly, using `dist/types` folder as
the target for type declarations and sourcemaps
- Configures type field in `package.json`
- Updates ESLint & its config
  - Sets up type-informed linting rules mirroring browsertrix
- Adds a bunch of other useful eslint and eslint-typescript rules, and
applies auto-fixes to the codebase
- Cleans up a bunch of types throughout the codebase, particularly parts
of the code used by ArchiveWebPage
- Changes `ItemIndex#_deleting` from `private` to `protected` so that a
part of AWP that extends it can do so properly
- Makes a bunch of previously-implied [non-null
assertions](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#non-null-assertion-operator-postfix-)
explicit
- Updates `URLResource` and `ItemType` types (and renames `Item` →
`ItemType` to disambiguate from the `Item` class)
- Removes `node-sass` and replaces it with `sass-embedded` for much
quicker installs and compilation
This commit is contained in:
Emma Segal-Grossman
2024-02-06 18:50:12 -08:00
committed by GitHub
parent a40471128f
commit a63390f10c
32 changed files with 898 additions and 1550 deletions
+10 -22
View File
@@ -1,8 +1,8 @@
/*eslint-env node */
import { CollectionLoader } from "@webrecorder/wabac/src/loaders";
import { type IpcRendererEvent } from "electron";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ipcRenderer, contextBridge } = require("electron");
contextBridge.exposeInMainWorld("electron", { IS_APP: true });
@@ -11,12 +11,7 @@ const dbs = {};
const loader = new CollectionLoader();
/**
*
* @param {string} name
* @returns
*/
async function getColl(name) {
async function getColl(name: string) {
if (!dbs[name]) {
dbs[name] = await loader.loadColl(name);
await dbs[name].initing;
@@ -25,25 +20,18 @@ async function getColl(name) {
return dbs[name];
}
/**
* @param {string} name
* @returns
*/
async function getDB(name) {
async function getDB(name: string) {
const coll = await getColl(name);
return coll.store;
}
/**
*
* @param {import("electron").IpcRendererEvent} event
* @param {*} request
* @param {*} coll
* @param {*} ts
* @param {*} channel
* @returns
*/
async function getResponse(event, request, coll, ts, channel) {
async function getResponse(
event: IpcRendererEvent,
request: Request,
coll: string,
ts: string,
channel: string,
): Promise<void> {
const db = await getDB(coll);
const req = { request, url: request.url, timestamp: ts };