From c9cc0a186c0f621b8e13e57be055035a41b65af7 Mon Sep 17 00:00:00 2001 From: Fenglin Li Date: Mon, 30 Mar 2020 17:58:01 -0700 Subject: [PATCH] fix: CreateOptions.transform should return stream or void (#195) Co-authored-by: Mark Lee --- lib/index.d.ts | 2 +- test/index.test-d.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 8c7f896..a95ba9a 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -6,7 +6,7 @@ export type CreateOptions = { globOptions?: GlobOptions; ordering?: string; pattern?: string; - transform?: (filePath: string) => string; + transform?: (filePath: string) => NodeJS.ReadWriteStream | void; unpack?: string; unpackDir?: string; }; diff --git a/test/index.test-d.ts b/test/index.test-d.ts index 9642dd5..504d05b 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -1,5 +1,6 @@ import * as asar from '..'; import * as fs from 'fs'; +import * as crypto from 'crypto' import { expectType } from 'tsd'; await asar.createPackage('bin', 'tmp/foo.asar'); @@ -8,7 +9,11 @@ await asar.createPackageWithOptions('bin', 'tmp/foo.asar', { globOptions: { debug: true, }, - transform: (filePath: string) => filePath.replace('/', ':'), + transform: (filePath: string) => { + if (process.env.TRANSFORM_ASAR) { + return crypto.createCipheriv('aes-256-cbc', crypto.randomBytes(32), crypto.randomBytes(16)).setAutoPadding(true).setEncoding('base64') + } + } }); await asar.createPackageFromFiles('bin', 'tmp/foo.asar', ['bin/asar.js']); const stat = fs.statSync('bin/asar.js');