From 736a6619e498f89ff97bf867ea1e3422dac047fd Mon Sep 17 00:00:00 2001 From: toyobayashi Date: Mon, 30 Mar 2020 10:54:54 +0800 Subject: [PATCH 1/3] fix: CreateOptions.transform should return stream --- lib/index.d.ts | 2 +- test/index.test-d.ts | 3 ++- 2 files changed, 3 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..1b9800b 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,7 @@ await asar.createPackageWithOptions('bin', 'tmp/foo.asar', { globOptions: { debug: true, }, - transform: (filePath: string) => filePath.replace('/', ':'), + transform: (filePath: string) => 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'); From aef63d92254347af134866bcd0725d866fd0577b Mon Sep 17 00:00:00 2001 From: toyobayashi Date: Tue, 31 Mar 2020 08:14:41 +0800 Subject: [PATCH 2/3] remove CreateOptions.transform void return type --- lib/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index a95ba9a..cb553fe 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) => NodeJS.ReadWriteStream | void; + transform?: (filePath: string) => NodeJS.ReadWriteStream; unpack?: string; unpackDir?: string; }; From 60c829ddc87c109e80afaa8c03694bafc31c57be Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Mon, 30 Mar 2020 17:44:50 -0700 Subject: [PATCH 3/3] fix: put void back & add a better test --- lib/index.d.ts | 2 +- test/index.test-d.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index cb553fe..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) => NodeJS.ReadWriteStream; + 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 1b9800b..504d05b 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -9,7 +9,11 @@ await asar.createPackageWithOptions('bin', 'tmp/foo.asar', { globOptions: { debug: true, }, - transform: (filePath: string) => crypto.createCipheriv('aes-256-cbc', crypto.randomBytes(32), crypto.randomBytes(16)).setAutoPadding(true).setEncoding('base64'), + 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');