From e434c7b5b462473148061cb52615389f663e85d2 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 22 Jul 2024 09:02:01 -0700 Subject: [PATCH] some cleanup/formatting around onWriteEntry --- src/pack.ts | 12 ++++++++---- test/list.ts | 18 ++++++++++++------ test/pack.js | 5 ++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/pack.ts b/src/pack.ts index ce095884..306189fe 100644 --- a/src/pack.ts +++ b/src/pack.ts @@ -91,8 +91,8 @@ export class Pack filter: Exclude jobs: number; - [WRITEENTRYCLASS]: typeof WriteEntry | typeof WriteEntrySync; - onWriteEntry?: (entry: WriteEntry) => void + [WRITEENTRYCLASS]: typeof WriteEntry | typeof WriteEntrySync + onWriteEntry?: (entry: WriteEntry) => void; [QUEUE]: Yallist; [JOBS]: number = 0; [PROCESSING]: boolean = false; @@ -387,9 +387,13 @@ export class Pack [ENTRY](job: PackJob) { this[JOBS] += 1 try { - const e = new this[WRITEENTRYCLASS](job.path, this[ENTRYOPT](job)) + const e = new this[WRITEENTRYCLASS]( + job.path, + this[ENTRYOPT](job), + ) this.onWriteEntry?.(e) - return e.on('end', () => this[JOBDONE](job)) + return e + .on('end', () => this[JOBDONE](job)) .on('error', er => this.emit('error', er)) } catch (er) { this.emit('error', er) diff --git a/test/list.ts b/test/list.ts index a424c0eb..9a28d0f7 100644 --- a/test/list.ts +++ b/test/list.ts @@ -34,7 +34,8 @@ t.test('basic', t => { t.test('file maxReadSize=' + maxReadSize, t => { t.test('sync', t => { const actual: string[] = [] - const onReadEntry = (entry: ReadEntry) => actual.push(entry.path) + const onReadEntry = (entry: ReadEntry) => + actual.push(entry.path) list({ file: file, sync: true, @@ -46,7 +47,8 @@ t.test('basic', t => { t.test('async promise', async t => { const actual: string[] = [] - const onReadEntry = (entry: ReadEntry) => actual.push(entry.path) + const onReadEntry = (entry: ReadEntry) => + actual.push(entry.path) return await list({ file, onReadEntry, @@ -56,7 +58,8 @@ t.test('basic', t => { t.test('async cb', t => { const actual: string[] = [] - const onReadEntry = (entry: ReadEntry) => actual.push(entry.path) + const onReadEntry = (entry: ReadEntry) => + actual.push(entry.path) list( { file: file, @@ -79,7 +82,8 @@ t.test('basic', t => { t.test('stream', t => { t.test('sync', t => { const actual: string[] = [] - const onReadEntry = (entry: ReadEntry) => actual.push(entry.path) + const onReadEntry = (entry: ReadEntry) => + actual.push(entry.path) const l = list({ sync: true, onReadEntry }) l.end(fs.readFileSync(file)) return check(actual, t) @@ -87,7 +91,8 @@ t.test('basic', t => { t.test('async', t => { const actual: string[] = [] - const onReadEntry = (entry: ReadEntry) => actual.push(entry.path) + const onReadEntry = (entry: ReadEntry) => + actual.push(entry.path) const l = list() l.on('entry', onReadEntry) l.on('end', _ => check(actual, t).then(_ => t.end())) @@ -130,7 +135,8 @@ t.test('basic', t => { t.test('no filter function, stream', t => { const check = () => t.same(actual, expect) const actual: string[] = [] - const onReadEntry = (entry: ReadEntry) => actual.push(entry.path) + const onReadEntry = (entry: ReadEntry) => + actual.push(entry.path) fs.createReadStream(file).pipe( list(fileList) .on('entry', onReadEntry) diff --git a/test/pack.js b/test/pack.js index 02276b9c..8026dcc5 100644 --- a/test/pack.js +++ b/test/pack.js @@ -99,7 +99,10 @@ t.test('pack a file', t => { ) const hs = new Header(sync) t.match(hs, expect) - t.strictSame(seen.map(e => e.path), ['one-byte.txt']) + t.strictSame( + seen.map(e => e.path), + ['one-byte.txt'], + ) t.end() }) })