From 64b6992ae2405f071175ace294e4708671248faf Mon Sep 17 00:00:00 2001 From: Hachi Metsu <107677571+hachimetsu@users.noreply.github.com> Date: Sat, 16 Mar 2024 10:58:28 +0000 Subject: [PATCH 1/2] asar feature --- package.json | 1 + src/fiddle.ts | 19 ++++++++++++++++++- yarn.lock | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index de270c5..b5aa9e7 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "test:ci": "jest --runInBand --coverage" }, "dependencies": { + "@electron/asar": "^3.2.9", "@electron/get": "^2.0.0", "debug": "^4.3.3", "env-paths": "^2.2.1", diff --git a/src/fiddle.ts b/src/fiddle.ts index 17b8864..ac8ab32 100644 --- a/src/fiddle.ts +++ b/src/fiddle.ts @@ -3,7 +3,8 @@ import * as path from 'path'; import debug from 'debug'; import simpleGit from 'simple-git'; import { createHash } from 'crypto'; - +import { tmpdir } from 'os'; +import { extractAll } from '@electron/asar'; import { DefaultPaths } from './paths'; function hashString(str: string): string { @@ -95,10 +96,26 @@ export class FiddleFactory { return new Fiddle(path.join(folder, 'main.js'), 'entries'); } + public async fromASAR(source: string): Promise { + const tempFiddleDir = await fs.mkdtemp( + path.join(tmpdir(), 'fiddle-asar-content'), + ); + try { + extractAll(source, tempFiddleDir); + if (fs.existsSync(tempFiddleDir)) return this.fromFolder(tempFiddleDir); + } catch (error) { + // Handle unpacking errors + console.error('Error unpacking ASAR:', error); + await fs.rm(tempFiddleDir, { recursive: true }); + throw error; + } + } + public async create(src: FiddleSource): Promise { if (src instanceof Fiddle) return src; if (typeof src === 'string') { + if (fs.existsSync(src) && /\.asar$/.test(src)) return this.fromASAR(src); if (fs.existsSync(src)) return this.fromFolder(src); if (/^[0-9A-Fa-f]{32}$/.test(src)) return this.fromGist(src); if (/^https:/.test(src) || /\.git$/.test(src)) return this.fromRepo(src); diff --git a/yarn.lock b/yarn.lock index 17a56b5..8e17a3e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -575,6 +575,15 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== +"@electron/asar@^3.2.9": + version "3.2.9" + resolved "https://registry.yarnpkg.com/@electron/asar/-/asar-3.2.9.tgz#7b3a1fd677b485629f334dd80ced8c85353ba7e7" + integrity sha512-Vu2P3X2gcZ3MY9W7yH72X9+AMXwUQZEJBrsPIbX0JsdllLtoh62/Q8Wg370/DawIEVKOyfD6KtTLo645ezqxUA== + dependencies: + commander "^5.0.0" + glob "^7.1.6" + minimatch "^3.0.4" + "@electron/get@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@electron/get/-/get-2.0.0.tgz#d991e68dc089fc66b521ec3ca4021515482bef91" @@ -1728,6 +1737,11 @@ commander@^2.7.1: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== +commander@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" + integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== + compress-brotli@^1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/compress-brotli/-/compress-brotli-1.3.8.tgz#0c0a60c97a989145314ec381e84e26682e7b38db" @@ -2356,7 +2370,7 @@ glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" -glob@^7.1.3: +glob@^7.1.3, glob@^7.1.6: version "7.2.3" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== From de9b059a413e8cca32c9e259c609778107ea36cd Mon Sep 17 00:00:00 2001 From: Hachi Metsu <107677571+hachimetsu@users.noreply.github.com> Date: Sat, 16 Mar 2024 11:15:18 +0000 Subject: [PATCH 2/2] asar fiddle file for testing --- .../642fa8daaebea6044c9079e3f8a46390.asar | Bin 0 -> 5235 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fixtures/fiddles/642fa8daaebea6044c9079e3f8a46390.asar diff --git a/tests/fixtures/fiddles/642fa8daaebea6044c9079e3f8a46390.asar b/tests/fixtures/fiddles/642fa8daaebea6044c9079e3f8a46390.asar new file mode 100644 index 0000000000000000000000000000000000000000..2df2a9afe96517399480782dcc845c8f093d4785 GIT binary patch literal 5235 zcmb_g*>2lN7R|%Vi@u^PG$1N1QKZC8j_pPkHxgiyxMK&IMi8`%#iGPEMQX^BZN<>1 z&f7f9XUw@(q$NA)P6wXAcEnola_+ec^|wcl9{u<4j~@L8zyHSXO*hSQS$Fqux>=FP zYkRI1IX%_cXW8BN$Kjw`rfDrzcfad&2RNnVtjg4y4)J_e;`4lg&C{1p$9{klb6(H! z%%gGW2+#3C8HTYF_+m2k!Z=M6FZIHy=LKOLr!tA+&>1^XEJD|J-DJX@Nf^bxgrqnx z#l@*M#B-|ANv5pNs`d>WaK7Z;)!594xDJp zr^59nJmi4no31}tfpNW(dC8MIF%N>tuH&H>eUIZ&3hIg|96RA8z+Z1F9oLs2cMt^b zBnnaiK*pgT`tigSVKSNW@iYuWCzjJN^1kW#gB57UD~SZJWOc{$@pRYoiRZfC<9U!K zz7&y&(9p3H_9!PbmL+jz3s|_PkbW z)HqwzyJ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