diff --git a/package-lock.json b/package-lock.json index 90e295a..eff07f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,7 +47,6 @@ "@tsconfig/node16": "^16.1.3", "@tsconfig/recommended": "^1.0.6", "@tsconfig/strictest": "^2.0.5", - "@types/estree": "^1.0.5", "@types/lodash-es": "^4.17.12", "@types/node": "^20.12.6", "@types/semver": "^7.5.8", diff --git a/package.json b/package.json index 72622d6..b2e8163 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "@tsconfig/node16": "^16.1.3", "@tsconfig/recommended": "^1.0.6", "@tsconfig/strictest": "^2.0.5", - "@types/estree": "^1.0.5", "@types/lodash-es": "^4.17.12", "@types/node": "^20.12.6", "@types/semver": "^7.5.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32f45e8..aaa388c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -75,9 +75,6 @@ importers: '@tsconfig/strictest': specifier: ^2.0.5 version: 2.0.5 - '@types/estree': - specifier: ^1.0.5 - version: 1.0.5 '@types/lodash-es': specifier: ^4.17.12 version: 4.17.12 @@ -1586,7 +1583,7 @@ packages: eslint: 8.57.0 eslint-module-utils: 2.8.0(@typescript-eslint/parser@7.6.0)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.6.0)(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) - fast-glob: 3.3.1 + fast-glob: 3.3.2 get-tsconfig: 4.5.0 is-core-module: 2.13.1 is-glob: 4.0.3 @@ -1788,17 +1785,6 @@ packages: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} dev: true - /fast-glob@3.3.1: - resolution: {integrity: sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==} - engines: {node: '>=8.6.0'} - dependencies: - '@nodelib/fs.stat': 2.0.5 - '@nodelib/fs.walk': 1.2.8 - glob-parent: 5.1.2 - merge2: 1.4.1 - micromatch: 4.0.5 - dev: true - /fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} @@ -1808,7 +1794,6 @@ packages: glob-parent: 5.1.2 merge2: 1.4.1 micromatch: 4.0.5 - dev: false /fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} @@ -1988,7 +1973,7 @@ packages: dependencies: array-union: 2.1.0 dir-glob: 3.0.1 - fast-glob: 3.3.1 + fast-glob: 3.3.2 ignore: 5.3.1 merge2: 1.4.1 slash: 3.0.0 diff --git a/sources/@types/acorn.ts b/sources/@types/acorn.ts deleted file mode 100644 index 8d7dfaf..0000000 --- a/sources/@types/acorn.ts +++ /dev/null @@ -1,20 +0,0 @@ -declare module "acorn" { - // https://github.com/acornjs/acorn/issues/1136#issuecomment-1203671368 - type ExtendNode = - (T extends estree.Node - ? { - start: number - end: number - } : unknown) - & { [K in keyof T]: T[K] extends object ? ExtendNode : T[K] } - function parse(s: string, o: Options): ExtendNode & Node - function parseExpressionAt( - input: string, - pos: number, - options: Options, - ): ExtendNode & Node -} -// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error -// @ts-ignore -import type { Node, Options } from "acorn" -import type estree from "estree" diff --git a/sources/main.ts b/sources/main.ts index 517fa43..43f7908 100644 --- a/sources/main.ts +++ b/sources/main.ts @@ -10,7 +10,7 @@ import { } from "@polyipseity/obsidian-plugin-library" import { LocalSettings, Settings } from "./settings-data.js" import { MAX_FETCH_CONCURRENCY, PLUGIN_UNLOAD_DELAY } from "./magic.js" -import { type WorkerPool, pool } from "workerpool" +import { type Pool, pool } from "workerpool" import type { API } from "obsidian-modules" // eslint-disable-next-line @typescript-eslint/naming-convention import PLazy from "p-lazy" @@ -37,7 +37,7 @@ export class ModulesPlugin concurrencyLimit: MAX_FETCH_CONCURRENCY, }) - public readonly workerPool = PLazy.from(async (): Promise => { + public readonly workerPool = PLazy.from(async (): Promise => { const url = toObjectURL(await worker) try { this.register(() => { URL.revokeObjectURL(url) }) diff --git a/sources/require/context.ts b/sources/require/context.ts index 9dc0695..cc69b34 100644 --- a/sources/require/context.ts +++ b/sources/require/context.ts @@ -72,7 +72,7 @@ export function patchContextForEditor(context: ModulesPlugin): void { const req = requires.get(self), info = this.state.field( // Typing bug - editorInfoField as StateField, + editorInfoField as unknown as StateField, false, ) let path = info?.file?.parent?.path diff --git a/sources/require/require.ts b/sources/require/require.ts index c67a55c..4d374d6 100644 --- a/sources/require/require.ts +++ b/sources/require/require.ts @@ -146,7 +146,9 @@ function createRequire( })()).add(id) if (oldID !== void 0 && id2 !== oldID) { aliases.get(oldID)?.delete(id) - invalidate(self2, id).catch(error => { self0.console.error(error) }) + invalidate(self2, id).catch((error: unknown) => { + self0.console.error(error) + }) } if (resolved.cache === false) { cache.delete(id2) } return [ @@ -399,9 +401,7 @@ function createRequire( get(target, property, receiver): unknown { const own = Reflect.getOwnPropertyDescriptor(target, property) if (Reflect.has(target, property) || - // eslint-disable-next-line @typescript-eslint/no-extra-parens (!(own?.configurable ?? true) && - // eslint-disable-next-line @typescript-eslint/no-extra-parens (!(own?.writable ?? true) || (own?.set && !own.get)))) { return Reflect.get(target, property, receiver) } @@ -480,7 +480,6 @@ function createRequire( set(target, property, newValue, receiver): boolean { const own = Reflect.getOwnPropertyDescriptor(target, property) if (!(own?.configurable ?? true) && - // eslint-disable-next-line @typescript-eslint/no-extra-parens (!(own?.writable ?? true) || (own?.get && !own.set)) && !Reflect.set(target, property, newValue, receiver)) { return false diff --git a/sources/require/resolve.ts b/sources/require/resolve.ts index 5b7d772..bef303f 100644 --- a/sources/require/resolve.ts +++ b/sources/require/resolve.ts @@ -23,8 +23,9 @@ import { isObject } from "lodash-es" import { normalizeURL } from "../util.js" const - tsMorphBootstrap = dynamicRequire(BUNDLE, "@ts-morph/bootstrap") + tsMorphBootstrap = + dynamicRequire( + BUNDLE, "@ts-morph/bootstrap") abstract class AbstractResolve implements Resolve { public readonly onInvalidate = new EventEmitterLite() @@ -257,7 +258,7 @@ export namespace AbstractFileResolve { await this.uncache(file.path) })) context.register(preloadRules.onChanged.listen(preload)) - preload().catch(error => { self.console.error(error) }) + preload().catch((error: unknown) => { self.console.error(error) }) } public get(path: string): Cache.Identity | undefined { @@ -445,6 +446,7 @@ export class MarkdownLinkResolve try { resolve(this.resolvePath(...args)) } catch (error) { + // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors reject(error) } }) @@ -474,6 +476,7 @@ export class WikilinkResolve try { resolve(this.resolvePath(...args)) } catch (error) { + // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors reject(error) } }) @@ -629,7 +632,7 @@ export class ExternalLinkResolve }, )) preload(settings.value.preloadedExternalLinks) - .catch(error => { self.console.error(error) }) + .catch((error: unknown) => { self.console.error(error) }) } public override async invalidate(id: string): Promise { @@ -705,8 +708,7 @@ export class ExternalLinkResolve href, identity = (async (): Promise => { - const ret: Writable = { + const ret: Writable = { [ExternalLinkResolve.Identity]: true, code: (await this.fetchPool.addSingleTask({ data: href, diff --git a/sources/require/startup-modules.ts b/sources/require/startup-modules.ts index 2f1991f..53e26a4 100644 --- a/sources/require/startup-modules.ts +++ b/sources/require/startup-modules.ts @@ -82,7 +82,7 @@ export async function loadStartupModules( startupMods.unload(...prev.filter(mod => !curSet.has(mod))) if (!set.autoReloadStartupModules) { return } startupMods.load(STARTUP_MODULES_LOAD_DELAY, ...cur) - .catch(error => { self.console.error(error) }) + .catch((error: unknown) => { self.console.error(error) }) }) settings.onMutate( set => set.autoReloadStartupModules, @@ -95,7 +95,7 @@ export async function loadStartupModules( if (!settings.value.startupModules.includes(id)) { return } if (settings.value.autoReloadStartupModules) { startupMods.reload(STARTUP_MODULES_LOAD_DELAY, id) - .catch(error => { self.console.error(error) }) + .catch((error: unknown) => { self.console.error(error) }) return } startupMods.unload(id) diff --git a/sources/require/transpile.ts b/sources/require/transpile.ts index b9bfca3..1c8c611 100644 --- a/sources/require/transpile.ts +++ b/sources/require/transpile.ts @@ -17,10 +17,12 @@ import type { TFile } from "obsidian" import type { tsc } from "../worker.js" const - tsMorphBootstrap = dynamicRequire(BUNDLE, "@ts-morph/bootstrap"), - tsMorphBootstrapSync = dynamicRequireLazy(BUNDLE, "@ts-morph/bootstrap") + tsMorphBootstrap = + dynamicRequire( + BUNDLE, "@ts-morph/bootstrap"), + tsMorphBootstrapSync = + dynamicRequireLazy( + BUNDLE, "@ts-morph/bootstrap") export interface Transpile { readonly onInvalidate: EventEmitterLite diff --git a/sources/worker.ts b/sources/worker.ts index 1ab5af2..2e04390 100644 --- a/sources/worker.ts +++ b/sources/worker.ts @@ -1,6 +1,5 @@ import { type Options, parse, parseExpressionAt } from "acorn" import { createProject, type ts } from "@ts-morph/bootstrap" -import type { CallExpression } from "estree" import { generate } from "astring" import { normalizeURL } from "./util.js" import { simple } from "acorn-walk" @@ -64,8 +63,7 @@ export async function parseAndRewriteRequire( simple(tree, { // eslint-disable-next-line @typescript-eslint/naming-convention CallExpression: node => { - const node2 = node as CallExpression & typeof node, - { callee } = node2 + const node2 = node, { callee } = node2 if (callee.type !== "Identifier" || callee.name !== "require") { return }