From 229d1cfd2c05097f3900b2c650f757a67fcbc67d Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Fri, 29 Nov 2024 22:08:53 +0800 Subject: [PATCH] fix: scripts/buildPreload.mjs --- assets/preload/streamChunksPreloadScript.js.html | 4 ++-- scripts/buildPreload.mjs | 11 +++++++++-- .../streamChunksPreloadScript.ts | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/assets/preload/streamChunksPreloadScript.js.html b/assets/preload/streamChunksPreloadScript.js.html index 7d4af64..4a4174c 100644 --- a/assets/preload/streamChunksPreloadScript.js.html +++ b/assets/preload/streamChunksPreloadScript.js.html @@ -48,7 +48,8 @@ break; } case OnStreamChunksToWebViewEventTypes.CHECK_RECEIVER_READY: { - // @ts-ignore + // @ts-ignore error TS2339: Property 'service' does not exist on type 'Window & typeof globalThis' + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access (_c = (_b = (_a = window.service) === null || _a === void 0 ? void 0 : _a.wikiHookService) === null || _b === void 0 ? void 0 : _b.setWebviewReceiverReady) === null || _c === void 0 ? void 0 : _c.call(_b); break; } @@ -130,7 +131,6 @@ script.parentNode.replaceChild(newScript, script); } catch (error) { - // FIXME: can't catch error `SyntaxError: Can't create duplicate variable: 'A'` on iOS console.error("Faile to refresh script tag with error ".concat(error.message, ": newScript, script"), newScript, script, error); } } diff --git a/scripts/buildPreload.mjs b/scripts/buildPreload.mjs index 7e53324..98ffddd 100644 --- a/scripts/buildPreload.mjs +++ b/scripts/buildPreload.mjs @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -import { mkdir, readFile, writeFile } from 'fs/promises'; +import { mkdir, readFile, writeFile, rmdir } from 'fs/promises'; import { $ } from 'zx'; if (process.platform === 'win32') { @@ -25,7 +25,14 @@ await writeFile(tmpTsFilePath, modifiedTsContent); // Use TypeScript compiler to compile the temporary file const outFilePath = 'assets/preload/streamChunksPreloadScript.js.html'; -await $`tsc ${tmpTsFilePath.replace('C:\\', '/')} --outFile ${outFilePath}`; +try { + await $`tsc ${tmpTsFilePath.replace('C:\\', '/')} --outFile ${outFilePath}`; +} catch (error) { + console.error(error); + throw error; +} finally { + await rmdir('build', { recursive: true }); +} // Optionally, you can log the output file path or perform other actions console.log(`Compiled file written to: ${outFilePath}`); diff --git a/src/pages/WikiWebView/useStreamChunksToWebView/streamChunksPreloadScript.ts b/src/pages/WikiWebView/useStreamChunksToWebView/streamChunksPreloadScript.ts index 441fb34..3cd4a47 100644 --- a/src/pages/WikiWebView/useStreamChunksToWebView/streamChunksPreloadScript.ts +++ b/src/pages/WikiWebView/useStreamChunksToWebView/streamChunksPreloadScript.ts @@ -47,6 +47,8 @@ export enum OnStreamChunksToWebViewEventTypes { break; } case OnStreamChunksToWebViewEventTypes.CHECK_RECEIVER_READY: { + // @ts-ignore error TS2339: Property 'service' does not exist on type 'Window & typeof globalThis' + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access window.service?.wikiHookService?.setWebviewReceiverReady?.(); break; }