build: use a stripped down non-conflicting version of lib.deno.d.ts instead

This commit is contained in:
alina 🌸 2024-04-29 05:50:18 +03:00
parent b1b79e2ab1
commit 67b290643d
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
11 changed files with 9083 additions and 68 deletions

View file

@ -10,7 +10,7 @@
], ],
"scripts": { "scripts": {
"prepare": "husky install .config/husky", "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": "pnpm run -r test && vitest --config .config/vite.mts run",
"test:dev": "vitest --config .config/vite.mts watch", "test:dev": "vitest --config .config/vite.mts watch",
"test:ui": "vitest --config .config/vite.mts --ui", "test:ui": "vitest --config .config/vite.mts --ui",

View file

@ -171,8 +171,7 @@ export async function uploadFile(
throw new MtArgumentError('Fetch response contains `null` body') throw new MtArgumentError('Fetch response contains `null` body')
} }
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion file = file.body
file = file.body as ReadableStream<Uint8Array>
} }
if (!(file instanceof ReadableStream)) { if (!(file instanceof ReadableStream)) {

View file

@ -1,4 +1,3 @@
/// <reference lib="dom" />
import type { Worker as NodeWorker } from 'node:worker_threads' import type { Worker as NodeWorker } from 'node:worker_threads'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'

View file

@ -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}`) fetch(`https://rpc.pwrtelegram.xyz/?code=${error.code}&method=${method}&error=${error.text}`)
.then((r) => r.json()) .then((r) => r.json())
// eslint-disable-next-line @typescript-eslint/no-explicit-any .then((r) => {
.then((r: any) => {
if (r.ok) { if (r.ok) {
log.info('telerpc responded with error info for %s: %s', error.text, r.result) log.info('telerpc responded with error info for %s: %s', error.text, r.result)
} else { } else {

View file

@ -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 { setPlatform } from '@mtcute/core/platform.js'
import { import {
ClientMessageHandler, ClientMessageHandler,
@ -20,10 +18,6 @@ export type { TelegramWorkerOptions, TelegramWorkerPortOptions, WorkerCustomMeth
let _registered = false 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> { export class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorkerBase<T> {
registerWorker(handler: WorkerMessageHandler): RespondFn { registerWorker(handler: WorkerMessageHandler): RespondFn {
if (_registered) { if (_registered) {
@ -36,7 +30,7 @@ export class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorke
const respond: RespondFn = self.postMessage.bind(self) const respond: RespondFn = self.postMessage.bind(self)
// eslint-disable-next-line // eslint-disable-next-line
self.addEventListener('message', (message: any) => handler(message.data, respond)) self.addEventListener('message', (message) => handler(message.data, respond))
return respond return respond
} }

View file

@ -115,8 +115,7 @@ export class IdbStorageDriver extends BaseStorageDriver {
db.createObjectStore(`${REPO_VERSION_PREFIX}${repo}:${targetVer}`) db.createObjectStore(`${REPO_VERSION_PREFIX}${repo}:${targetVer}`)
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any for (const key of db.objectStoreNames) {
for (const key of db.objectStoreNames as any as string[]) {
if (!key.startsWith(REPO_VERSION_PREFIX)) continue if (!key.startsWith(REPO_VERSION_PREFIX)) continue
const [, repo, version] = key.split(':') const [, repo, version] = key.split(':')
@ -143,7 +142,7 @@ export class IdbStorageDriver extends BaseStorageDriver {
this._pendingWrites = [] this._pendingWrites = []
this._pendingWritesOses = new Set() this._pendingWritesOses = new Set()
const tx = this.db.transaction([...oses], 'readwrite') const tx = this.db.transaction(oses, 'readwrite')
const osMap = new Map<string, IDBObjectStore>() const osMap = new Map<string, IDBObjectStore>()

View file

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { setPlatform } from '@mtcute/core/platform.js' import { setPlatform } from '@mtcute/core/platform.js'
import { import {
ClientMessageHandler, ClientMessageHandler,
@ -19,11 +18,6 @@ export type { TelegramWorkerOptions, TelegramWorkerPortOptions, WorkerCustomMeth
let _registered = false 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> { export class TelegramWorker<T extends WorkerCustomMethods> extends TelegramWorkerBase<T> {
registerWorker(handler: WorkerMessageHandler): RespondFn { registerWorker(handler: WorkerMessageHandler): RespondFn {
if (_registered) { if (_registered) {

View file

@ -428,6 +428,12 @@ if (buildConfig.buildTs && !IS_JSR) {
'from: (data: any, encoding?: string) => { toString(encoding?: string): string }, ' + 'from: (data: any, encoding?: string) => { toString(encoding?: string): string }, ' +
' }', ' }',
SharedWorker: ['type', 'never'], 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 }, ' + '}', process: '{ ' + 'hrtime: { bigint: () => bigint }, ' + '}',
} }
@ -561,7 +567,9 @@ if (IS_JSR) {
if (depsToPopulate.length) { if (depsToPopulate.length) {
console.log('[i] Populating %d dependencies...', depsToPopulate.length) console.log('[i] Populating %d dependencies...', depsToPopulate.length)
cp.spawnSync('pnpm', [ cp.spawnSync(
'pnpm',
[
'exec', 'exec',
'slow-types-compiler', 'slow-types-compiler',
'populate', 'populate',
@ -571,9 +579,11 @@ if (IS_JSR) {
process.env.JSR_TOKEN, process.env.JSR_TOKEN,
'--unstable-create-via-api', '--unstable-create-via-api',
...depsToPopulate, ...depsToPopulate,
], { ],
{
stdio: 'inherit', stdio: 'inherit',
}) },
)
} }
} }

View file

@ -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')

View 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

File diff suppressed because it is too large Load diff