Skip to content

Commit

Permalink
fix: CreateOptions.transform should return stream or void (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Lee <malept@users.noreply.github.com>
  • Loading branch information
toyobayashi and malept committed Mar 31, 2020
1 parent 3f243e2 commit c9cc0a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
7 changes: 6 additions & 1 deletion test/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit c9cc0a1

Please sign in to comment.