From 01c5ec46a865222ebf1ad583711c15f47d6a1e57 Mon Sep 17 00:00:00 2001 From: Gavin1012 Date: Fri, 10 Jun 2022 10:36:31 +0800 Subject: [PATCH] set default timeout and enable self-defined timeout for watch Signed-off-by: Gavin1012 --- ts2panda/src/cmdOptions.ts | 2 +- ts2panda/src/index.ts | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index 9844d6bd94..39d1276155 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -26,7 +26,7 @@ const ts2pandaOptions = [ { name: 'debug-log', alias: 'l', type: Boolean, defaultValue: false, description: "show info debug log and generate the json file."}, { name: 'dump-assembly', alias: 'a', type: Boolean, defaultValue: false, description: "dump assembly to file." }, { name: 'debug', alias: 'd', type: Boolean, defaultValue: false, description: "compile with debug info." }, - { name: 'debug-add-watch', alias: 'w', type: String, lazyMultiple: true, defaultValue: [], description: "watch expression and abc file path in debug mode." }, + { name: 'debug-add-watch', alias: 'w', type: String, lazyMultiple: true, defaultValue: [], description: "watch expression, abc file path and maybe watchTimeOut in debug mode." }, { name: 'keep-persistent-watch', alias: 'k', type: String, lazyMultiple: true, defaultValue: [], description: "keep persistent watch on js file with watched expression." }, { name: 'show-statistics', alias: 's', type: String, lazyMultiple: true, defaultValue: "", description: "show compile statistics(ast, histogram, hoisting, all)." }, { name: 'output', alias: 'o', type: String, defaultValue: "", description: "set output file." }, diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index bc5881e33a..456acac1e4 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -155,13 +155,13 @@ function getDtsFiles(libDir: string): string[] { } const stopWatchingStr = "####"; -const watchAbcFileTimeOut = 5000; +const watchAbcFileDefaultTimeOut = 10; const watchFileName = "watch_expressions"; -function updateWatchedFile() { +function updateWatchedFile(watchAbcFileTimeOut: number) { let watchArgs = CmdOptions.getAddWatchArgs(); let ideIputStr = watchArgs[0]; - if (watchArgs.length != 2 || !isBase64Str(ideIputStr)) { + if ((watchArgs.length > 3) || !isBase64Str(ideIputStr)) { throw new Error("Incorrect args' format or not enter base64 string in watch mode"); } let fragmentSep = "\\n"; @@ -184,7 +184,6 @@ function updateWatchedFile() { if (CmdOptions.isAssemblyMode()) { return; } - fs.watchFile(abcFileName, { persistent: true, interval: 50 }, (curr, prev) => { if (+curr.mtime <= +prev.mtime) { fs.unwatchFile(jsFileName); @@ -202,7 +201,7 @@ function updateWatchedFile() { fs.unlinkSync(jsFileName); fs.unlinkSync(abcFileName); throw new Error("watchFileServer has not been initialized"); - }, watchAbcFileTimeOut); + }, watchAbcFileTimeOut*1000); } function convertWatchExpression(jsfileName: string, parsed: ts.ParsedCommandLine | undefined) { @@ -282,7 +281,15 @@ function run(args: string[], options?: ts.CompilerOptions): void { return; } if (CmdOptions.isWatchMode()) { - updateWatchedFile(); + if (CmdOptions.getAddWatchArgs().length == 3) { + let watchAbcFileTimeOut = Number(CmdOptions.getAddWatchArgs()[2]); + if (watchAbcFileTimeOut.toString() == "NaN") { + throw new Error("Incorrect args' format for watch out time in watch mode"); + } + updateWatchedFile(watchAbcFileTimeOut); + return; + } + updateWatchedFile(watchAbcFileDefaultTimeOut); return; } main(parsed.fileNames.concat(CmdOptions.getIncludedFiles()), parsed.options); -- Gitee