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/tests/fixtures/fiddles/642fa8daaebea6044c9079e3f8a46390.asar b/tests/fixtures/fiddles/642fa8daaebea6044c9079e3f8a46390.asar new file mode 100644 index 0000000..2df2a9a Binary files /dev/null and b/tests/fixtures/fiddles/642fa8daaebea6044c9079e3f8a46390.asar differ 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==