diff --git a/.gitignore b/.gitignore index 8365b14..869478f 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ yarn.lock .nyc_output coverage .DS_Store +dist/ diff --git a/dist/index.d.ts b/dist/index.d.ts index af749d0..9c24f5f 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,5 +1,5 @@ /// -import { EventEmitter } from 'events'; +import { EventEmitter2 } from 'eventemitter2'; import { TextFileDiffOption } from './types'; import stream from 'stream'; export declare class StreamLineReader { @@ -14,7 +14,7 @@ export declare class StreamLineReader { /** * line by line diff of two files */ -export default class TextFileDiff extends EventEmitter { +export default class TextFileDiff extends EventEmitter2 { options: TextFileDiffOption; constructor(options?: TextFileDiffOption); /** diff --git a/dist/index.js b/dist/index.js index 2d60d81..3fbe459 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StreamLineReader = void 0; -const events_1 = require("events"); +const eventemitter2_1 = require("eventemitter2"); const types_1 = require("./types"); const fs_1 = require("fs"); const readline_1 = require("readline"); @@ -41,7 +41,7 @@ exports.StreamLineReader = StreamLineReader; /** * line by line diff of two files */ -class TextFileDiff extends events_1.EventEmitter { +class TextFileDiff extends eventemitter2_1.EventEmitter2 { constructor(options) { super(); this.options = new types_1.TextFileDiffOption(); @@ -87,17 +87,16 @@ class TextFileDiff extends events_1.EventEmitter { // debug(line1, line1, cmpar); // debug(lineReader1.nextValue, lineReader2.nextValue, 'next', lineReader1.eof, lineReader2.eof); // emit on compared - this.emit('compared', line1, line2, cmpar, lineReader1, lineReader2); + await this.emitAsync('compared', line1, line2, cmpar, lineReader1, lineReader2); if (cmpar > 0) { // line1 > line2: new line detected // if file2 ended before file1, then file2 lost line1 // else file2 has new line - if (lineReader2.eof > lineReader1.eof) { - this.emit('-', line1, lineReader1, lineReader2); - } - else { - this.emit('+', line2, lineReader1, lineReader2); - } + /* eslint-disable @typescript-eslint/no-unused-expressions */ + lineReader2.eof > lineReader1.eof ? + await this.emitAsync('-', line1, lineReader1, lineReader2) : + await this.emitAsync('+', line2, lineReader1, lineReader2); + /* eslint-enable @typescript-eslint/no-unused-expressions */ // incr File2 to next line await lineReader2.moveNext(); } @@ -105,12 +104,11 @@ class TextFileDiff extends events_1.EventEmitter { // line1 < line2: deleted line // if file1 ended before file2, then file2 has new line // else file1 lost a line - if (lineReader1.eof > lineReader2.eof) { - this.emit('+', line2, lineReader1, lineReader2); - } - else { - this.emit('-', line1, lineReader1, lineReader2); - } + /* eslint-disable @typescript-eslint/no-unused-expressions */ + lineReader1.eof > lineReader2.eof ? + await this.emitAsync('+', line2, lineReader1, lineReader2) : + await this.emitAsync('-', line1, lineReader1, lineReader2); + /* eslint-enable @typescript-eslint/no-unused-expressions */ // incr File1 to next line await lineReader1.moveNext(); } @@ -122,4 +120,4 @@ class TextFileDiff extends events_1.EventEmitter { } } exports.default = TextFileDiff; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsbUNBQW9DO0FBQ3BDLG1DQUEyQztBQUMzQywyQkFBOEM7QUFDOUMsdUNBQW9EO0FBR3BELHFDQUFxQztBQUNyQywyQ0FBMkM7QUFFM0MsTUFBYSxnQkFBZ0I7SUFBN0I7UUFDRSxVQUFLLEdBQVcsRUFBRSxDQUFDO1FBQ25CLGNBQVMsR0FBVyxFQUFFLENBQUM7UUFDdkIsZUFBVSxHQUFXLENBQUMsQ0FBQyxDQUFDO1FBRXhCLFFBQUcsR0FBVyxDQUFDLENBQUMsQ0FBQztJQTZCbkIsQ0FBQztJQTVCQyxLQUFLLENBQUMsSUFBSSxDQUFDLFVBQTJCO1FBQ3BDLE1BQU0sRUFBRSxHQUFHLDBCQUFlLENBQUM7WUFDekIsS0FBSy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lXG4gICAgICBhd2FpdCBsaW5lUmVhZGVyMi5tb3ZlTmV4dCgpO1xuICAgIH0gZWxzZSBpZiAoY21wYXIgPCAwKSB7XG4gICAgICAvLyBsaW5lMSA8IGxpbmUyOiBkZWxldGVkIGxpbmVcbiAgICAgIC8vIGlmIGZpbGUxIGVuZGVkIGJlZm9yZSBmaWxlMiwgdGhlbiBmaWxlMiBoYXMgbmV3IGxpbmVcbiAgICAgIC8vIGVsc2UgZmlsZTEgbG9zdCBhIGxpbmVcblxuICAgICAgLyogZXNsaW50LWRpc2FibGUgQHR5cGVzY3JpcHQtZXNsaW50L25vLXVudXNlZC1leHByZXNzaW9ucyAqL1xuICAgICAgbGluZVJlYWRlcjEuZW9mID4gbGluZVJlYWRlcjIuZW9mID9cbiAgICAgICAgYXdhaXQgdGhpcy5lbWl0QXN5bmMoJysnLCBsaW5lMiwgbGluZVJlYWRlcjEsIGxpbmVSZWFkZXIyKSA6XG4gICAgICAgIGF3YWl0IHRoaXMuZW1pdEFzeW5jKCctJywgbGluZTEsIGxpbmVSZWFkZXIxLCBsaW5lUmVhZGVyMik7XG4gICAgICAvKiBlc2xpbnQtZW5hYmxlIEB0eXBlc2NyaXB0LWVzbGludC9uby11bnVzZWQtZXhwcmVzc2lvbnMgKi9cblxuICAgICAgLy8gaW5jciBGaWxlMSB0byBuZXh0IGxpbmVcbiAgICAgIGF3YWl0IGxpbmVSZWFkZXIxLm1vdmVOZXh0KCk7XG4gICAgfSBlbHNlIHtcbiAgICAgIC8vIGVxdWFsczogMCBpbmNyIGJvdGggZmlsZXMgdG8gbmV4dCBsaW5lXG4gICAgICBhd2FpdCBsaW5lUmVhZGVyMS5tb3ZlTmV4dCgpO1xuICAgICAgYXdhaXQgbGluZVJlYWRlcjIubW92ZU5leHQoKTtcbiAgICB9XG4gIH1cbn1cbiJdfQ== \ No newline at end of file diff --git a/package.json b/package.json index 0e3477a..13f4c9b 100755 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "npm": ">=6" }, "scripts": { - "build": "tsc", + "prepare": "mkdir -p dist/ && tsc", "test": "tsc && cross-env DEBUG=text-file-diff xo && cross-env DEBUG=text-file-diff nyc ava", "report": "tsc && cross-env DEBUG=text-file-diff nyc report --reporter=html" }, @@ -57,5 +57,8 @@ }, "ava": { "failWithoutAssertions": true + }, + "dependencies": { + "eventemitter2": "^6.4.4" } } diff --git a/src/index.ts b/src/index.ts index 7cc5a28..d94c78f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ -import {EventEmitter} from 'events'; +import {EventEmitter2} from 'eventemitter2'; import {TextFileDiffOption} from './types'; -import {PathLike, createReadStream} from 'fs'; -import {Interface, createInterface} from 'readline'; +import {createReadStream} from 'fs'; +import {createInterface} from 'readline'; import stream from 'stream'; // import myDebug = require('debug'); @@ -46,7 +46,7 @@ export class StreamLineReader { /** * line by line diff of two files */ -export default class TextFileDiff extends EventEmitter { +export default class TextFileDiff extends EventEmitter2 { options: TextFileDiffOption; constructor(options?: TextFileDiffOption) { @@ -101,17 +101,18 @@ export default class TextFileDiff extends EventEmitter { // debug(line1, line1, cmpar); // debug(lineReader1.nextValue, lineReader2.nextValue, 'next', lineReader1.eof, lineReader2.eof); // emit on compared - this.emit('compared', line1, line2, cmpar, lineReader1, lineReader2); + await this.emitAsync('compared', line1, line2, cmpar, lineReader1, lineReader2); if (cmpar > 0) { // line1 > line2: new line detected // if file2 ended before file1, then file2 lost line1 // else file2 has new line - if (lineReader2.eof > lineReader1.eof) { - this.emit('-', line1, lineReader1, lineReader2); - } else { - this.emit('+', line2, lineReader1, lineReader2); - } + + /* eslint-disable @typescript-eslint/no-unused-expressions */ + lineReader2.eof > lineReader1.eof ? + await this.emitAsync('-', line1, lineReader1, lineReader2) : + await this.emitAsync('+', line2, lineReader1, lineReader2); + /* eslint-enable @typescript-eslint/no-unused-expressions */ // incr File2 to next line await lineReader2.moveNext(); @@ -119,11 +120,12 @@ export default class TextFileDiff extends EventEmitter { // line1 < line2: deleted line // if file1 ended before file2, then file2 has new line // else file1 lost a line - if (lineReader1.eof > lineReader2.eof) { - this.emit('+', line2, lineReader1, lineReader2); - } else { - this.emit('-', line1, lineReader1, lineReader2); - } + + /* eslint-disable @typescript-eslint/no-unused-expressions */ + lineReader1.eof > lineReader2.eof ? + await this.emitAsync('+', line2, lineReader1, lineReader2) : + await this.emitAsync('-', line1, lineReader1, lineReader2); + /* eslint-enable @typescript-eslint/no-unused-expressions */ // incr File1 to next line await lineReader1.moveNext(); diff --git a/tests/index.js b/tests/index.js index 2946c0e..3bcdba4 100644 --- a/tests/index.js +++ b/tests/index.js @@ -35,6 +35,29 @@ test('test skip header', async t => { t.is(actual, expected); }); +test('test await listener', async t => { + const m = new TextFileDiff(); + const expected = 'compared+compared+comparedcompared+compared-compared-comparedcompared+'; + + let actual = ''; + + const getListenerFor = event => async () => new Promise(resolve => { + setTimeout(() => { + actual += event; + resolve(); + }, 200); + }); + + m.on('-', getListenerFor('-')); + m.on('+', getListenerFor('+')); + + m.on('compared', getListenerFor('compared')); + + await m.diff('tests/file1.txt', 'tests/file2.txt'); + + t.is(actual, expected); +}); + test('test against null or empty file', async t => { let expected = '-some,csv,data\n';