diff --git a/apps/demo/components/connect.tsx b/apps/demo/components/connect.tsx index 6f2e9861..99afc992 100644 --- a/apps/demo/components/connect.tsx +++ b/apps/demo/components/connect.tsx @@ -207,7 +207,7 @@ function _Connect(): JSX.Element | null { return { items, }; - }, [addWsBackend, addTcpBackend]); + }, [addUsbBackend, addWsBackend, addTcpBackend]); return ( 1) { - const props = pieces[1]; + const props = pieces[1]!; for (const prop of props.split(';')) { if (!prop) { continue; @@ -188,7 +188,7 @@ export class Adb { this._device = value; break; case AdbPropKey.Features: - this._features = value.split(',') as AdbFeatures[]; + this._features = value!.split(',') as AdbFeatures[]; break; } } diff --git a/libraries/adb/src/commands/reverse.ts b/libraries/adb/src/commands/reverse.ts index d5f5999d..229e22b5 100644 --- a/libraries/adb/src/commands/reverse.ts +++ b/libraries/adb/src/commands/reverse.ts @@ -78,7 +78,7 @@ export class AdbReverseCommand extends AutoDisposable { const response = await AdbReverseStringResponse.deserialize(stream); return response.content!.split('\n').map(line => { - const [deviceSerial, localName, remoteName] = line.split(' '); + const [deviceSerial, localName, remoteName] = line.split(' ') as [string, string, string]; return { deviceSerial, localName, remoteName }; }); diff --git a/libraries/adb/src/commands/shell/protocol.ts b/libraries/adb/src/commands/shell/protocol.ts index f94b8790..c86bf837 100644 --- a/libraries/adb/src/commands/shell/protocol.ts +++ b/libraries/adb/src/commands/shell/protocol.ts @@ -72,7 +72,7 @@ export class AdbShellProtocol implements AdbShell { this.stderrEvent.fire(packet.data); break; case AdbShellProtocolId.Exit: - this.exitEvent.fire(new Uint8Array(packet.data)[0]); + this.exitEvent.fire(new Uint8Array(packet.data)[0]!); break; case AdbShellProtocolId.CloseStdin: case AdbShellProtocolId.Stdin: diff --git a/libraries/adb/src/commands/sync/response.ts b/libraries/adb/src/commands/sync/response.ts index 30c28f0e..a57a4803 100644 --- a/libraries/adb/src/commands/sync/response.ts +++ b/libraries/adb/src/commands/sync/response.ts @@ -51,7 +51,7 @@ export async function adbSyncReadResponse BigInt0) { uint64Array.push(BigInt.asUintN(64, value)); - value /= BigInt2To64; + value >>= BigInt64; } const view = new DataView(buffer); for (let i = uint64Array.length - 1; i >= 0; i -= 1) { - view.setBigUint64(offset, uint64Array[i], false); + setBigUint64(view, offset, uint64Array[i]!, false); offset += 8; } } @@ -42,9 +43,9 @@ export function setBig(buffer: ArrayBuffer, value: bigint, offset: number = 0) { export function setBigLE(buffer: ArrayBuffer, value: bigint, offset = 0) { const view = new DataView(buffer); while (value > BigInt0) { - view.setBigUint64(offset, value, true); + setBigUint64(view, offset, value, true); offset += 8; - value /= BigInt2To64; + value >>= BigInt64; } } @@ -108,7 +109,7 @@ export function modInverse(a: number, m: number) { let x = 1; let y = 0; for (let i = s.length - 2; i >= 0; --i) { - [x, y] = [y, x - y * Math.floor(s[i].a / s[i].b)]; + [x, y] = [y, x - y * Math.floor(s[i]!.a / s[i]!.b)]; } return (y % m + m) % m; } diff --git a/libraries/adb/src/utils/base64.ts b/libraries/adb/src/utils/base64.ts index 04cfd639..7eb27983 100644 --- a/libraries/adb/src/utils/base64.ts +++ b/libraries/adb/src/utils/base64.ts @@ -6,7 +6,6 @@ const paddingChar = '='.charCodeAt(0); function addRange(start: string, end: string) { const charCodeStart = start.charCodeAt(0); const charCodeEnd = end.charCodeAt(0); - const length = charCodeEnd - charCodeStart + 1; for (let charCode = charCodeStart; charCode <= charCodeEnd; charCode += 1) { charToIndex[String.fromCharCode(charCode)] = indexToChar.length; @@ -142,7 +141,7 @@ export function encodeBase64( if (paddingLength === 2) { // aaaaaabb - const x = input[inputIndex]; + const x = input[inputIndex]!; inputIndex -= 1; output[outputIndex] = paddingChar; @@ -151,56 +150,56 @@ export function encodeBase64( output[outputIndex] = paddingChar; outputIndex -= 1; - output[outputIndex] = indexToChar[((x & 0b11) << 4)]; + output[outputIndex] = indexToChar[((x & 0b11) << 4)]!; outputIndex -= 1; - output[outputIndex] = indexToChar[x >> 2]; + output[outputIndex] = indexToChar[x >> 2]!; outputIndex -= 1; } else if (paddingLength === 1) { // bbbbcccc - const y = input[inputIndex]; + const y = input[inputIndex]!; inputIndex -= 1; // aaaaaabb - const x = input[inputIndex]; + const x = input[inputIndex]!; inputIndex -= 1; output[outputIndex] = paddingChar; outputIndex -= 1; - output[outputIndex] = indexToChar[((y & 0b1111) << 2)]; + output[outputIndex] = indexToChar[((y & 0b1111) << 2)]!; outputIndex -= 1; - output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]; + output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]!; outputIndex -= 1; - output[outputIndex] = indexToChar[x >> 2]; + output[outputIndex] = indexToChar[x >> 2]!; outputIndex -= 1; } while (inputIndex >= inputOffset) { // ccdddddd - const z = input[inputIndex]; + const z = input[inputIndex]!; inputIndex -= 1; // bbbbcccc - const y = input[inputIndex]; + const y = input[inputIndex]!; inputIndex -= 1; // aaaaaabb - const x = input[inputIndex]; + const x = input[inputIndex]!; inputIndex -= 1; - output[outputIndex] = indexToChar[z & 0b111111]; + output[outputIndex] = indexToChar[z & 0b111111]!; outputIndex -= 1; - output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)]; + output[outputIndex] = indexToChar[((y & 0b1111) << 2) | (z >> 6)]!; outputIndex -= 1; - output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]; + output[outputIndex] = indexToChar[((x & 0b11) << 4) | (y >> 4)]!; outputIndex -= 1; - output[outputIndex] = indexToChar[x >> 2]; + output[outputIndex] = indexToChar[x >> 2]!; outputIndex -= 1; } @@ -226,16 +225,16 @@ export function decodeBase64(input: string): ArrayBuffer { let dIndex = 0; while (sIndex < input.length - (padding !== 0 ? 4 : 0)) { - const a = charToIndex[input[sIndex]]; + const a = charToIndex[input[sIndex]!]!; sIndex += 1; - const b = charToIndex[input[sIndex]]; + const b = charToIndex[input[sIndex]!]!; sIndex += 1; - const c = charToIndex[input[sIndex]]; + const c = charToIndex[input[sIndex]!]!; sIndex += 1; - const d = charToIndex[input[sIndex]]; + const d = charToIndex[input[sIndex]!]!; sIndex += 1; result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4); @@ -249,23 +248,23 @@ export function decodeBase64(input: string): ArrayBuffer { } if (padding === 1) { - const a = charToIndex[input[sIndex]]; + const a = charToIndex[input[sIndex]!]!; sIndex += 1; - const b = charToIndex[input[sIndex]]; + const b = charToIndex[input[sIndex]!]!; sIndex += 1; - const c = charToIndex[input[sIndex]]; + const c = charToIndex[input[sIndex]!]!; result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4); dIndex += 1; result[dIndex] = ((b & 0b1111) << 4) | ((c & 0b11_1100) >> 2); } else if (padding === 2) { - const a = charToIndex[input[sIndex]]; + const a = charToIndex[input[sIndex]!]!; sIndex += 1; - const b = charToIndex[input[sIndex]]; + const b = charToIndex[input[sIndex]!]!; result[dIndex] = (a << 2) | ((b & 0b11_0000) >> 4); } diff --git a/libraries/adb/src/utils/event-queue.ts b/libraries/adb/src/utils/event-queue.ts index 9e6d89a6..16c0fa67 100644 --- a/libraries/adb/src/utils/event-queue.ts +++ b/libraries/adb/src/utils/event-queue.ts @@ -22,9 +22,9 @@ interface LinkedListItem { } class LinkedList{ - private head?: LinkedListItem; + private head?: LinkedListItem | undefined; - private tail?: LinkedListItem; + private tail?: LinkedListItem | undefined; private _length = 0; public get length() { return this._length; } diff --git a/libraries/scrcpy/src/client.ts b/libraries/scrcpy/src/client.ts index 72e8ad46..5017f4f3 100644 --- a/libraries/scrcpy/src/client.ts +++ b/libraries/scrcpy/src/client.ts @@ -4,27 +4,11 @@ import { EventEmitter } from '@yume-chan/event'; import Struct from '@yume-chan/struct'; import { ScrcpyClientConnection } from "./connection"; import { AndroidKeyEventAction, AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectScrollControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage } from './message'; -import { ScrcpyLogLevel, ScrcpyOptions } from "./options"; +import { ScrcpyOptions } from "./options"; import { pushServer, PushServerOptions } from "./push-server"; import { parse_sequence_parameter_set, SequenceParameterSet } from './sps'; import { decodeUtf8 } from "./utils"; -interface ScrcpyError { - type: string; - - message: string; - - stackTrace: string[]; -} - -interface ScrcpyOutput { - level: ScrcpyLogLevel; - - message: string; - - error?: ScrcpyError; -} - function* splitLines(text: string): Generator { let start = 0; @@ -100,7 +84,7 @@ export class ScrcpyClient { client.onOutput((line) => { const match = line.match(encoderNameRegex); if (match) { - encoders.push(match[1]); + encoders.push(match[1]!); } }); diff --git a/libraries/scrcpy/src/sps.ts b/libraries/scrcpy/src/sps.ts index d9645912..44c1ea65 100644 --- a/libraries/scrcpy/src/sps.ts +++ b/libraries/scrcpy/src/sps.ts @@ -18,7 +18,7 @@ class BitReader { } public next(): number { - const value = (this.buffer[this.bytePosition] >> (7 - this.bitPosition)) & 1; + const value = (this.buffer[this.bytePosition]! >> (7 - this.bitPosition)) & 1; this.bitPosition += 1; if (this.bitPosition === 8) { this.bytePosition += 1; @@ -179,13 +179,17 @@ export function parse_sequence_parameter_set(buffer: ArrayBuffer) { profile_idc === 134) { const chroma_format_idc = reader.decodeExponentialGolombNumber(); if (chroma_format_idc === 3) { - const separate_colour_plane_flag = !!reader.next(); + // separate_colour_plane_flag + reader.next(); } - const bit_depth_luma_minus8 = reader.decodeExponentialGolombNumber(); - const bit_depth_chroma_minus8 = reader.decodeExponentialGolombNumber(); + // bit_depth_luma_minus8 + reader.decodeExponentialGolombNumber(); + // bit_depth_chroma_minus8 + reader.decodeExponentialGolombNumber(); - const qpprime_y_zero_transform_bypass_flag = !!reader.next(); + // qpprime_y_zero_transform_bypass_flag + reader.next(); const seq_scaling_matrix_present_flag = !!reader.next(); if (seq_scaling_matrix_present_flag) { @@ -206,14 +210,19 @@ export function parse_sequence_parameter_set(buffer: ArrayBuffer) { } } - const log2_max_frame_num_minus4 = reader.decodeExponentialGolombNumber(); + // log2_max_frame_num_minus4 + reader.decodeExponentialGolombNumber(); const pic_order_cnt_type = reader.decodeExponentialGolombNumber(); if (pic_order_cnt_type === 0) { - const log2_max_pic_order_cnt_lsb_minus4 = reader.decodeExponentialGolombNumber(); + // log2_max_pic_order_cnt_lsb_minus4 + reader.decodeExponentialGolombNumber(); } else if (pic_order_cnt_type === 1) { - const delta_pic_order_always_zero_flag = reader.next(); - const offset_for_non_ref_pic = reader.decodeExponentialGolombNumber(); - const offset_for_top_to_bottom_field = reader.decodeExponentialGolombNumber(); + // delta_pic_order_always_zero_flag + reader.next(); + // offset_for_non_ref_pic + reader.decodeExponentialGolombNumber(); + // offset_for_top_to_bottom_field + reader.decodeExponentialGolombNumber(); const num_ref_frames_in_pic_order_cnt_cycle = reader.decodeExponentialGolombNumber(); const offset_for_ref_frame: number[] = []; for (let i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) { @@ -221,17 +230,21 @@ export function parse_sequence_parameter_set(buffer: ArrayBuffer) { } } - const max_num_ref_frames = reader.decodeExponentialGolombNumber(); - const gaps_in_frame_num_value_allowed_flag = reader.next(); + // max_num_ref_frames + reader.decodeExponentialGolombNumber(); + // gaps_in_frame_num_value_allowed_flag + reader.next(); const pic_width_in_mbs_minus1 = reader.decodeExponentialGolombNumber(); const pic_height_in_map_units_minus1 = reader.decodeExponentialGolombNumber(); const frame_mbs_only_flag = reader.next(); if (!frame_mbs_only_flag) { - const mb_adaptive_frame_field_flag = !!reader.next(); + // mb_adaptive_frame_field_flag + reader.next(); } - const direct_8x8_inference_flag = reader.next(); + // direct_8x8_inference_flag + reader.next(); const frame_cropping_flag = !!reader.next(); let frame_crop_left_offset: number; diff --git a/libraries/struct/package.json b/libraries/struct/package.json index 5f4b3778..81133cb8 100644 --- a/libraries/struct/package.json +++ b/libraries/struct/package.json @@ -33,9 +33,9 @@ "prepublishOnly": "npm run build" }, "dependencies": { + "@yume-chan/dataview-bigint-polyfill": "0.0.10", "bluebird": "^3.7.2", - "tslib": "^2.3.1", - "@yume-chan/dataview-bigint-polyfill": "0.0.10" + "tslib": "^2.3.1" }, "devDependencies": { "jest": "^26.6.3", diff --git a/libraries/struct/src/types/bigint.ts b/libraries/struct/src/types/bigint.ts index 0b61a28f..c0a23daa 100644 --- a/libraries/struct/src/types/bigint.ts +++ b/libraries/struct/src/types/bigint.ts @@ -1,4 +1,3 @@ - import { getBigInt64, getBigUint64, setBigInt64, setBigUint64 } from '@yume-chan/dataview-bigint-polyfill/esm/fallback'; import { StructAsyncDeserializeStream, StructDeserializeStream, StructFieldDefinition, StructFieldValue, StructOptions, StructValue } from "../basic"; import { Syncbird } from "../syncbird"; diff --git a/toolchain/ts-package-builder/src/index.js b/toolchain/ts-package-builder/src/index.js index 520ed3aa..493a0bdb 100755 --- a/toolchain/ts-package-builder/src/index.js +++ b/toolchain/ts-package-builder/src/index.js @@ -8,35 +8,12 @@ const temp = path.resolve(__dirname, '..', 'temp', process.pid.toString()); fs.mkdirSync(temp, { recursive: true }); if (process.argv[2] !== '--incremental') { - fs.rmSync(path.resolve(cwd, 'cjs'), { force: true, recursive: true }); fs.rmSync(path.resolve(cwd, 'esm'), { force: true, recursive: true }); - fs.rmSync(path.resolve(cwd, 'dts'), { force: true, recursive: true }); } const tsconfigPath = path.resolve(cwd, 'tsconfig.json'); const tsconfigValue = JSON5.parse(fs.readFileSync(tsconfigPath), 'utf8'); -// const cjsTsconfigPath = path.resolve(temp, 'tsconfig.cjs.json'); -// const cjsTsconfigValue = { -// ...tsconfigValue, -// extends: tsconfigPath, -// compilerOptions: { -// composite: false, -// outDir: path.resolve(cwd, 'cjs'), -// module: 'CommonJS', -// declaration: false, -// declarationDir: null, -// declarationMap: false, -// typeRoots: [ -// ...(tsconfigValue.compilerOptions?.typeRoots || []), -// path.resolve(cwd, 'node_modules', '@types'), -// path.resolve(__dirname, '..', 'node_modules', '@types'), -// ], -// }, -// references: [], -// }; -// fs.writeFileSync(cjsTsconfigPath, JSON.stringify(cjsTsconfigValue, undefined, 4)); - const esmTsconfigPath = path.resolve(temp, 'tsconfig.esm.json'); const testTypes = tsconfigValue.testTypes || ['jest']; const esmTsconfigValue = { @@ -64,7 +41,6 @@ fs.writeFileSync(esmTsconfigPath, JSON.stringify(esmTsconfigValue, undefined, 4) const tsc = path.resolve(cwd, 'node_modules', '.bin', 'tsc'); const tscResult = childProcess.spawnSync(tsc, [ '--build', - // cjsTsconfigPath, esmTsconfigPath, ], { cwd, diff --git a/toolchain/ts-package-builder/tsconfig.base.json b/toolchain/ts-package-builder/tsconfig.base.json index ce48b9e4..ae52f733 100644 --- a/toolchain/ts-package-builder/tsconfig.base.json +++ b/toolchain/ts-package-builder/tsconfig.base.json @@ -8,10 +8,10 @@ "ESNext" ], "rootDir": "../../../src", - "outDir": "../../../cjs", + "outDir": "../../../esm", "sourceMap": true, "declaration": true, - "declarationDir": "../../../dts", + "declarationDir": "../../../esm", "declarationMap": true, "stripInternal": true, // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ @@ -23,12 +23,17 @@ /* Strict Type-Checking Options */ "strict": true, // /* Enable all strict type-checking options. */ /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ + "noUnusedLocals": true, // /* Report errors on unused locals. */ // "noUnusedParameters": true, /* Report errors on unused parameters. */ "noImplicitOverride": true, "noImplicitReturns": true, // /* Report error when not all code paths in function return a value. */ "noFallthroughCasesInSwitch": true, // /* Report errors for fallthrough cases in switch statement. */ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ + "exactOptionalPropertyTypes": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noUncheckedIndexedAccess": true, + "resolveJsonModule": true, /* Module Resolution Options */ "moduleResolution": "node", // /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */