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
+11 -17
View File
@@ -2,16 +2,15 @@ import { LitElement, html, css, type PropertyValues } from "lit";
import { property } from "lit/decorators.js";
import { wrapCss, rwpLogo } from "./misc";
import type { Item } from "./types";
import type { ItemType } from "./types";
// ===========================================================================
class Replay extends LitElement {
@property({ type: Object })
collInfo: Item | Record<string, never> | null = null;
collInfo: ItemType | Record<string, never> | null = null;
@property({ type: String })
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO fixme
sourceUrl: any = null;
sourceUrl: string | null = null;
// external url set from parent
@property({ type: String })
@@ -34,14 +33,13 @@ class Replay extends LitElement {
title = "";
@property({ type: String })
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO fixme
iframeUrl: any = null;
iframeUrl: string | null = null;
@property({ type: Boolean })
showAuth = false;
@property({ type: Object })
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO fixme
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- requestPermission() type mismatch
authFileHandle: any = null;
private reauthWait: null | Promise<void> = null;
@@ -164,8 +162,7 @@ class Replay extends LitElement {
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO fixme
setDisablePointer(disable: any) {
setDisablePointer(disable: boolean) {
const iframe = this.renderRoot.querySelector("iframe");
if (iframe) {
@@ -173,8 +170,7 @@ class Replay extends LitElement {
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO fixme
onReplayMessage(event: any) {
onReplayMessage(event: MessageEvent) {
const iframe = this.renderRoot.querySelector("iframe");
if (iframe && event.source === iframe.contentWindow) {
@@ -238,14 +234,12 @@ class Replay extends LitElement {
this._loadPoll = window.setInterval(() => {
const iframe = this.renderRoot.querySelector("iframe");
if (
!iframe ||
!iframe.contentDocument ||
!iframe?.contentDocument ||
!iframe.contentWindow ||
(iframe.contentDocument.readyState === "complete" &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO fixme
!(iframe.contentWindow as Window & { _WBWombat: any })._WBWombat)
!(iframe.contentWindow as Window & { _WBWombat: unknown })._WBWombat)
) {
this.clearLoading(iframe && iframe.contentWindow);
this.clearLoading(iframe?.contentWindow);
}
}, 5000);
}
@@ -405,7 +399,7 @@ class Replay extends LitElement {
</button>
`
: html` <wr-gdrive
.sourceUrl="${this.sourceUrl}"
.sourceUrl="${this.sourceUrl!}"
state="trymanual"
.reauth="${true}"
@load-ready="${this.onReAuthed}"