Skip to content

Commit

Permalink
Fix compile errors
Browse files Browse the repository at this point in the history
Signed-off-by: William So <[email protected]>
  • Loading branch information
polyipseity committed Apr 9, 2024
1 parent bf5bc5a commit a5a3f50
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 61 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 2 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions sources/@types/acorn.ts

This file was deleted.

4 changes: 2 additions & 2 deletions sources/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,7 +37,7 @@ export class ModulesPlugin
concurrencyLimit: MAX_FETCH_CONCURRENCY,
})

public readonly workerPool = PLazy.from(async (): Promise<WorkerPool> => {
public readonly workerPool = PLazy.from(async (): Promise<Pool> => {
const url = toObjectURL(await worker)
try {
this.register(() => { URL.revokeObjectURL(url) })
Expand Down
2 changes: 1 addition & 1 deletion sources/require/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function patchContextForEditor(context: ModulesPlugin): void {
const req = requires.get(self),
info = this.state.field(
// Typing bug
editorInfoField as StateField<MarkdownFileInfo>,
editorInfoField as unknown as StateField<MarkdownFileInfo>,
false,
)
let path = info?.file?.parent?.path
Expand Down
7 changes: 3 additions & 4 deletions sources/require/require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions sources/require/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import { isObject } from "lodash-es"
import { normalizeURL } from "../util.js"

const
tsMorphBootstrap = dynamicRequire<typeof import("@ts-morph/bootstrap")
>(BUNDLE, "@ts-morph/bootstrap")
tsMorphBootstrap =
dynamicRequire<typeof import("@ts-morph/bootstrap")>(
BUNDLE, "@ts-morph/bootstrap")

abstract class AbstractResolve implements Resolve {
public readonly onInvalidate = new EventEmitterLite<readonly [id: string]>()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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<void> {
Expand Down Expand Up @@ -705,8 +708,7 @@ export class ExternalLinkResolve
href,
identity = (async (): Promise<ExternalLinkResolve
.Identity> => {
const ret: Writable<ExternalLinkResolve
.Identity> = {
const ret: Writable<ExternalLinkResolve.Identity> = {
[ExternalLinkResolve.Identity]: true,
code: (await this.fetchPool.addSingleTask({
data: href,
Expand Down
4 changes: 2 additions & 2 deletions sources/require/startup-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions sources/require/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import type { TFile } from "obsidian"
import type { tsc } from "../worker.js"

const
tsMorphBootstrap = dynamicRequire<typeof import("@ts-morph/bootstrap")
>(BUNDLE, "@ts-morph/bootstrap"),
tsMorphBootstrapSync = dynamicRequireLazy<typeof import("@ts-morph/bootstrap")
>(BUNDLE, "@ts-morph/bootstrap")
tsMorphBootstrap =
dynamicRequire<typeof import("@ts-morph/bootstrap")>(
BUNDLE, "@ts-morph/bootstrap"),
tsMorphBootstrapSync =
dynamicRequireLazy<typeof import("@ts-morph/bootstrap")>(
BUNDLE, "@ts-morph/bootstrap")

export interface Transpile {
readonly onInvalidate: EventEmitterLite<readonly []>
Expand Down
4 changes: 1 addition & 3 deletions sources/worker.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a5a3f50

Please sign in to comment.