From d09d54be4bebde0d0059fc5e89d5a9dac9b06f8d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 18 Jan 2023 15:53:13 -0500 Subject: [PATCH] Update esptool-js to 0.2.0 (#317) --- package-lock.json | 36 ++++++------------- package.json | 4 +-- ...0001-import-pako-and-not-change-baud.patch | 16 --------- patches/0001-not-change-baud.patch | 11 ++++++ src/flash.ts | 28 +++++++++------ 5 files changed, 42 insertions(+), 53 deletions(-) delete mode 100644 patches/0001-import-pako-and-not-change-baud.patch create mode 100644 patches/0001-not-change-baud.patch diff --git a/package-lock.json b/package-lock.json index c80491a..01a01a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@material/mwc-formfield": "^0.27.0", "@material/mwc-icon-button": "^0.27.0", "@material/mwc-textfield": "^0.27.0", - "esptool-js": "github:espressif/esptool-js#076af269f44daa5b7823031221f39bf22124c129", + "esptool-js": "^0.2.0", "improv-wifi-serial-sdk": "^2.4.0", "lit": "^2.5.0", "pako": "^2.1.0", @@ -1857,10 +1857,6 @@ "node": ">= 8" } }, - "node_modules/crypto-js": { - "version": "4.1.1", - "license": "MIT" - }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -1926,12 +1922,12 @@ } }, "node_modules/esptool-js": { - "version": "0.1.0", - "resolved": "git+ssh://git@github.com/espressif/esptool-js.git#076af269f44daa5b7823031221f39bf22124c129", - "integrity": "sha512-zHc9T4qC2j8EZ+1YaFRZILXxk7T1R7eA2Z2Lx1KPxgce1XbFwCsJxp4CpntytGoIDf0ax6/vbb4YArLaehVHOQ==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/esptool-js/-/esptool-js-0.2.0.tgz", + "integrity": "sha512-TZehTn14FJ6YLfKc+YJlZxhcs5XZasE+85LFbju+TGtb/vb7bXUEkioCkVRUfSnmGBP3uZqAmd2/m7jpoSwOPg==", "dependencies": { - "crypto-js": "^4.0.0", - "xterm": "^4.13.0" + "pako": "^2.1.0", + "tslib": "^2.4.1" } }, "node_modules/estree-walker": { @@ -2929,10 +2925,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/xterm": { - "version": "4.19.0", - "license": "MIT" - }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", @@ -4389,9 +4381,6 @@ "which": "^2.0.1" } }, - "crypto-js": { - "version": "4.1.1" - }, "debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -4444,12 +4433,12 @@ "dev": true }, "esptool-js": { - "version": "git+ssh://git@github.com/espressif/esptool-js.git#076af269f44daa5b7823031221f39bf22124c129", - "integrity": "sha512-zHc9T4qC2j8EZ+1YaFRZILXxk7T1R7eA2Z2Lx1KPxgce1XbFwCsJxp4CpntytGoIDf0ax6/vbb4YArLaehVHOQ==", - "from": "esptool-js@github:espressif/esptool-js#076af269f44daa5b7823031221f39bf22124c129", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/esptool-js/-/esptool-js-0.2.0.tgz", + "integrity": "sha512-TZehTn14FJ6YLfKc+YJlZxhcs5XZasE+85LFbju+TGtb/vb7bXUEkioCkVRUfSnmGBP3uZqAmd2/m7jpoSwOPg==", "requires": { - "crypto-js": "^4.0.0", - "xterm": "^4.13.0" + "pako": "^2.1.0", + "tslib": "^2.4.1" } }, "estree-walker": { @@ -5162,9 +5151,6 @@ } } }, - "xterm": { - "version": "4.19.0" - }, "yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index 53382d6..b35c33b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "license": "Apache-2.0", "scripts": { "prepublishOnly": "script/build", - "postinstall": "patch -Ntu node_modules/esptool-js/ESPLoader.js -i patches/0001-import-pako-and-not-change-baud.patch || true" + "postinstall": "patch -Ntu node_modules/esptool-js/lib/esploader.js -i patches/0001-not-change-baud.patch || true" }, "devDependencies": { "@babel/plugin-proposal-class-properties": "^7.18.6", @@ -31,7 +31,7 @@ "@material/mwc-formfield": "^0.27.0", "@material/mwc-icon-button": "^0.27.0", "@material/mwc-textfield": "^0.27.0", - "esptool-js": "github:espressif/esptool-js#076af269f44daa5b7823031221f39bf22124c129", + "esptool-js": "^0.2.0", "improv-wifi-serial-sdk": "^2.4.0", "lit": "^2.5.0", "pako": "^2.1.0", diff --git a/patches/0001-import-pako-and-not-change-baud.patch b/patches/0001-import-pako-and-not-change-baud.patch deleted file mode 100644 index 62c5786..0000000 --- a/patches/0001-import-pako-and-not-change-baud.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- node_modules/esptool-js/ESPLoader.js 2022-07-19 09:17:05.000000000 -0700 -+++ node_modules/esptool-js/ESPLoader.fixed.js 2022-07-19 09:19:04.000000000 -0700 -@@ -1,3 +1,4 @@ -+import pako from 'pako'; - import {ESPError, TimeoutError} from "./error.js"; - - const MAGIC_TO_CHIP = { -@@ -680,7 +681,7 @@ - - await this.run_stub(); - -- await this.change_baud(); -+ // await this.change_baud(); - return chip; - } - diff --git a/patches/0001-not-change-baud.patch b/patches/0001-not-change-baud.patch new file mode 100644 index 0000000..ba13049 --- /dev/null +++ b/patches/0001-not-change-baud.patch @@ -0,0 +1,11 @@ +--- node_modules/esptool-js/lib/esploader.js 2023-01-18 15:30:02 ++++ node_modules/esptool-js/lib/esploader.fixed.js 2023-01-18 15:31:47 +@@ -677,7 +677,7 @@ + await this.chip._post_connect(this); + } + await this.run_stub(); +- await this.change_baud(); ++ // await this.change_baud(); + return chip; + } + parse_flash_size_arg(flsz) { diff --git a/src/flash.ts b/src/flash.ts index aa8dc04..284afd1 100644 --- a/src/flash.ts +++ b/src/flash.ts @@ -1,7 +1,4 @@ -// @ts-ignore-next-line -import { Transport } from "esptool-js/webserial.js"; -// @ts-ignore-next-line -import { ESPLoader } from "esptool-js/ESPLoader.js"; +import { Transport, ESPLoader } from "esptool-js"; import { Build, FlashError, @@ -41,7 +38,12 @@ export const flash = async ( }); const transport = new Transport(port); - const esploader = new ESPLoader(transport, 115200); + const esploader = new ESPLoader( + transport, + 115200, + // Wrong type, fixed in https://github.com/espressif/esptool-js/pull/75/files + undefined as any + ); // For debugging (window as any).esploader = esploader; @@ -68,7 +70,7 @@ export const flash = async ( return; } - chipFamily = await esploader.chip.CHIP_NAME; + chipFamily = esploader.chip.CHIP_NAME as any; if (!esploader.chip.ROM_TEXT) { fireStateEvent({ @@ -184,9 +186,15 @@ export const flash = async ( let totalWritten = 0; try { - await esploader.write_flash({ + await esploader.write_flash( fileArray, - reportProgress(fileIndex: number, written: number, total: number) { + "keep", + "keep", + "keep", + false, + true, + // report progress + (fileIndex: number, written: number, total: number) => { const uncompressedWritten = (written / total) * fileArray[fileIndex].data.length; @@ -209,8 +217,8 @@ export const flash = async ( percentage: newPct, }, }); - }, - }); + } + ); } catch (err: any) { fireStateEvent({ state: FlashStateType.ERROR,