build: use a stripped down non-conflicting version of lib.deno.d.ts instead
This commit is contained in:
parent
b1b79e2ab1
commit
67b290643d
11 changed files with 9083 additions and 68 deletions
|
@ -10,7 +10,7 @@
|
|||
],
|
||||
"scripts": {
|
||||
"prepare": "husky install .config/husky",
|
||||
"postinstall": "node scripts/validate-deps-versions.mjs && node scripts/fetch-deno-dts.mjs && node scripts/remove-jsr-sourcefiles.mjs",
|
||||
"postinstall": "node scripts/validate-deps-versions.mjs && node scripts/install-deno-dts.mjs && node scripts/remove-jsr-sourcefiles.mjs",
|
||||
"test": "pnpm run -r test && vitest --config .config/vite.mts run",
|
||||
"test:dev": "vitest --config .config/vite.mts watch",
|
||||
"test:ui": "vitest --config .config/vite.mts --ui",
|
||||
|
|
|
@ -171,8 +171,7 @@ export async function uploadFile(
|
|||
throw new MtArgumentError('Fetch response contains `null` body')
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
file = file.body as ReadableStream<Uint8Array>
|
||||
file = file.body
|
||||
}
|
||||
|
||||
if (!(file instanceof ReadableStream)) {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/// <reference lib="dom" />
|
||||
import type { Worker as NodeWorker } from 'node:worker_threads'
|
||||
|
||||
import { tl } from '@mtcute/tl'
|
||||
|
|
|
@ -7,8 +7,7 @@ export function reportUnknownError(log: Logger, error: tl.RpcError, method: stri
|
|||
|
||||
fetch(`https://rpc.pwrtelegram.xyz/?code=${error.code}&method=${method}&error=${error.text}`)
|
||||
.then((r) => r.json())
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.then((r: any) => {
|
||||
.then((r) => {
|
||||
if (r.ok) {
|
||||
log.info('telerpc responded with error info for %s: %s', error.text, r.result)
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
import { setPlatform } from '@mtcute/core/platform.js'
|
||||
import {
|
||||
ClientMessageHandler,
|
||||
|
@ -20,10 +18,6 @@ export type { TelegramWorkerOptions, TelegramWorkerPortOptions, WorkerCustomMeth
|
|||
|
||||
let _registered = false
|
||||
|
||||
// thanks deno for this awesome lack of typings
|
||||
declare const WorkerGlobalScope: any
|
||||
declare const self: any
|
||||
|
||||
export class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorkerBase<T> {
|
||||
registerWorker(handler: WorkerMessageHandler): RespondFn {
|
||||
if (_registered) {
|
||||
|
@ -36,7 +30,7 @@ export class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorke
|
|||
const respond: RespondFn = self.postMessage.bind(self)
|
||||
|
||||
// eslint-disable-next-line
|
||||
self.addEventListener('message', (message: any) => handler(message.data, respond))
|
||||
self.addEventListener('message', (message) => handler(message.data, respond))
|
||||
|
||||
return respond
|
||||
}
|
||||
|
|
|
@ -115,8 +115,7 @@ export class IdbStorageDriver extends BaseStorageDriver {
|
|||
db.createObjectStore(`${REPO_VERSION_PREFIX}${repo}:${targetVer}`)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
for (const key of db.objectStoreNames as any as string[]) {
|
||||
for (const key of db.objectStoreNames) {
|
||||
if (!key.startsWith(REPO_VERSION_PREFIX)) continue
|
||||
const [, repo, version] = key.split(':')
|
||||
|
||||
|
@ -143,7 +142,7 @@ export class IdbStorageDriver extends BaseStorageDriver {
|
|||
this._pendingWrites = []
|
||||
this._pendingWritesOses = new Set()
|
||||
|
||||
const tx = this.db.transaction([...oses], 'readwrite')
|
||||
const tx = this.db.transaction(oses, 'readwrite')
|
||||
|
||||
const osMap = new Map<string, IDBObjectStore>()
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { setPlatform } from '@mtcute/core/platform.js'
|
||||
import {
|
||||
ClientMessageHandler,
|
||||
|
@ -19,11 +18,6 @@ export type { TelegramWorkerOptions, TelegramWorkerPortOptions, WorkerCustomMeth
|
|||
|
||||
let _registered = false
|
||||
|
||||
// thanks deno for this awesome lack of typings
|
||||
declare const WorkerGlobalScope: any
|
||||
declare const SharedWorkerGlobalScope: any
|
||||
declare const self: any
|
||||
|
||||
export class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorkerBase<T> {
|
||||
registerWorker(handler: WorkerMessageHandler): RespondFn {
|
||||
if (_registered) {
|
||||
|
|
|
@ -428,6 +428,12 @@ if (buildConfig.buildTs && !IS_JSR) {
|
|||
'from: (data: any, encoding?: string) => { toString(encoding?: string): string }, ' +
|
||||
' }',
|
||||
SharedWorker: ['type', 'never'],
|
||||
WorkerGlobalScope:
|
||||
'{ ' +
|
||||
' new (): typeof WorkerGlobalScope, ' +
|
||||
' postMessage: (message: any, transfer?: Transferable[]) => void, ' +
|
||||
' addEventListener: (type: "message", listener: (ev: MessageEvent) => void) => void, ' +
|
||||
' }',
|
||||
process: '{ ' + 'hrtime: { bigint: () => bigint }, ' + '}',
|
||||
}
|
||||
|
||||
|
@ -561,7 +567,9 @@ if (IS_JSR) {
|
|||
|
||||
if (depsToPopulate.length) {
|
||||
console.log('[i] Populating %d dependencies...', depsToPopulate.length)
|
||||
cp.spawnSync('pnpm', [
|
||||
cp.spawnSync(
|
||||
'pnpm',
|
||||
[
|
||||
'exec',
|
||||
'slow-types-compiler',
|
||||
'populate',
|
||||
|
@ -571,9 +579,11 @@ if (IS_JSR) {
|
|||
process.env.JSR_TOKEN,
|
||||
'--unstable-create-via-api',
|
||||
...depsToPopulate,
|
||||
], {
|
||||
],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
import { createHash } from 'crypto'
|
||||
import * as fs from 'fs/promises'
|
||||
import { dirname } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const DTS_URL = 'https://github.com/denoland/deno/releases/download/v1.42.4/lib.deno.d.ts'
|
||||
const SHA256 = '554b5da7baf05e5693ca064fcf1665b0b847743ccfd0db89cb6f2388f2de0276'
|
||||
const LIB_TARGET = fileURLToPath(new URL('../node_modules/@types/deno/index.d.ts', import.meta.url))
|
||||
|
||||
const stat = await fs.stat(LIB_TARGET).catch(() => null)
|
||||
|
||||
if (stat?.isFile()) {
|
||||
const sha256 = createHash('sha256').update(await fs.readFile(LIB_TARGET)).digest('hex')
|
||||
|
||||
if (sha256 === SHA256) {
|
||||
console.log('lib.deno.d.ts is up to date')
|
||||
process.exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
const stream = await fetch(DTS_URL)
|
||||
const dts = await stream.text()
|
||||
|
||||
const sha256 = createHash('sha256').update(dts).digest('hex')
|
||||
|
||||
if (sha256 !== SHA256) {
|
||||
console.error(`lib.deno.d.ts SHA256 mismatch: expected ${SHA256}, got ${sha256}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
await fs.mkdir(dirname(LIB_TARGET), { recursive: true }).catch(() => null)
|
||||
await fs.writeFile(LIB_TARGET, dts)
|
||||
console.log('lib.deno.d.ts updated')
|
16
scripts/install-deno-dts.mjs
Normal file
16
scripts/install-deno-dts.mjs
Normal file
|
@ -0,0 +1,16 @@
|
|||
import * as fs from 'fs/promises'
|
||||
import { dirname } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const LIB_SOURCE = fileURLToPath(new URL('./lib.deno.d.ts', import.meta.url))
|
||||
const LIB_TARGET = fileURLToPath(new URL('../node_modules/@types/deno/index.d.ts', import.meta.url))
|
||||
|
||||
await fs.mkdir(dirname(LIB_TARGET), { recursive: true })
|
||||
|
||||
if (await fs.stat(LIB_TARGET).catch(() => null)) {
|
||||
await fs.unlink(LIB_TARGET)
|
||||
}
|
||||
|
||||
await fs.symlink(LIB_SOURCE, LIB_TARGET)
|
||||
|
||||
console.log('lib.deno.d.ts linked')
|
9038
scripts/lib.deno.d.ts
vendored
Normal file
9038
scripts/lib.deno.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue