Replace 'read-last-lines' with 'n-readlines'

read-last-lines had trouble reading lines
This commit is contained in:
Christian Koop 2020-11-24 15:36:21 +01:00
parent 877811bf50
commit d14b966ef1
No known key found for this signature in database
GPG Key ID: DECCA4CEE0E46D6D
7 changed files with 45 additions and 59 deletions

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

3
dist/package.json generated vendored
View File

@ -33,12 +33,13 @@
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"async": "^3.2.0", "async": "^3.2.0",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"read-last-lines": "^1.7.2" "n-readlines": "^1.0.1"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node12": "^1.0.7", "@tsconfig/node12": "^1.0.7",
"@types/async": "^3.2.4", "@types/async": "^3.2.4",
"@types/fs-extra": "^9.0.4", "@types/fs-extra": "^9.0.4",
"@types/n-readlines": "^1.0.1",
"@types/node": "~12.19.6", "@types/node": "~12.19.6",
"@vercel/ncc": "^0.25.1", "@vercel/ncc": "^0.25.1",
"ts-node": "^9.0.0", "ts-node": "^9.0.0",

56
package-lock.json generated
View File

@ -30,6 +30,15 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/n-readlines": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@types/n-readlines/-/n-readlines-1.0.1.tgz",
"integrity": "sha512-n1ND4k+9hgtil2HnHK+1tIj1UWchsD+RwoH7eVQqLbUe8AxwLuqDEnx3Riq+twHoMTjP80Q/ilB3LGdyXKfTEg==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/node": { "@types/node": {
"version": "12.19.6", "version": "12.19.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.6.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.6.tgz",
@ -42,11 +51,6 @@
"integrity": "sha512-dGecC5+1wLof1MQpey4+6i2KZv4Sfs6WfXkl9KfO32GED4ZPiKxRfvtGPjbjZv0IbqMl6CxtcV1RotXYfd5SSA==", "integrity": "sha512-dGecC5+1wLof1MQpey4+6i2KZv4Sfs6WfXkl9KfO32GED4ZPiKxRfvtGPjbjZv0IbqMl6CxtcV1RotXYfd5SSA==",
"dev": true "dev": true
}, },
"any-promise": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
"integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8="
},
"arg": { "arg": {
"version": "4.1.3", "version": "4.1.3",
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
@ -113,28 +117,10 @@
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
"dev": true "dev": true
}, },
"mz": { "n-readlines": {
"version": "2.7.0", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", "resolved": "https://registry.npmjs.org/n-readlines/-/n-readlines-1.0.1.tgz",
"integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", "integrity": "sha512-z4SyAIVgMy7CkgsoNw7YVz40v0g4+WWvvqy8+ZdHrCtgevcEO758WQyrYcw3XPxcLxF+//RszTz/rO48nzD0wQ=="
"requires": {
"any-promise": "^1.0.0",
"object-assign": "^4.0.1",
"thenify-all": "^1.0.0"
}
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"read-last-lines": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/read-last-lines/-/read-last-lines-1.7.2.tgz",
"integrity": "sha512-K0yUvTYAYn6qpyLJufaJ7yC6BeL23qpgZ8SKM7/fA1R1rHotCDxB/zDp9i1I2JHvexWBW6/35jkt07iiIKKp4g==",
"requires": {
"mz": "^2.7.0"
}
}, },
"source-map": { "source-map": {
"version": "0.6.1", "version": "0.6.1",
@ -152,22 +138,6 @@
"source-map": "^0.6.0" "source-map": "^0.6.0"
} }
}, },
"thenify": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
"integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==",
"requires": {
"any-promise": "^1.0.0"
}
},
"thenify-all": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
"integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=",
"requires": {
"thenify": ">= 3.1.0 < 4"
}
},
"ts-node": { "ts-node": {
"version": "9.0.0", "version": "9.0.0",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.0.0.tgz",

View File

@ -33,12 +33,13 @@
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"async": "^3.2.0", "async": "^3.2.0",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"read-last-lines": "^1.7.2" "n-readlines": "^1.0.1"
}, },
"devDependencies": { "devDependencies": {
"@tsconfig/node12": "^1.0.7", "@tsconfig/node12": "^1.0.7",
"@types/async": "^3.2.4", "@types/async": "^3.2.4",
"@types/fs-extra": "^9.0.4", "@types/fs-extra": "^9.0.4",
"@types/n-readlines": "^1.0.1",
"@types/node": "~12.19.6", "@types/node": "~12.19.6",
"@vercel/ncc": "^0.25.1", "@vercel/ncc": "^0.25.1",
"ts-node": "^9.0.0", "ts-node": "^9.0.0",

View File

@ -4,9 +4,7 @@ import { copy } from 'fs-extra';
import { rmdirSync } from 'fs'; import { rmdirSync } from 'fs';
import { parallelLimit } from 'async'; import { parallelLimit } from 'async';
import { cpuCount, downloadFile, exit, fixArgArr, isNumeric, resetWorkingDir, runCmd } from './utils'; import { cpuCount, downloadFile, exit, fixArgArr, isNumeric, readLastLines, resetWorkingDir, runCmd } from './utils';
const rll = require('read-last-lines');
const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = { const supportedBuildTools: { [key: string]: { url: string, prepareArgs: string[] } } = {
spraxdev: { spraxdev: {
@ -66,7 +64,7 @@ async function run(): Promise<{ code: number, msg?: string }> {
console.error(err); console.error(err);
console.error(`\nPrinting last 25 lines from '${resolvePath(appLogFile)}':`); console.error(`\nPrinting last 25 lines from '${resolvePath(appLogFile)}':`);
for (const line of (await rll.read(appLogFile, 25))) { for (const line of readLastLines(appLogFile, 25)) {
console.error(line); console.error(line);
} }
@ -122,14 +120,12 @@ async function run(): Promise<{ code: number, msg?: string }> {
console.error(err); console.error(err);
console.error(`\nPrinting last 25 lines from '${resolvePath(logFile)}':`); console.error(`\nPrinting last 25 lines from '${resolvePath(logFile)}':`);
rll.read(logFile, 25)
.then((lines: string[]) => { for (const line of readLastLines(logFile, 25)) {
for (const line of lines) {
console.error(line); console.error(line);
} }
})
.catch(console.error) rejectTask(err);
.finally(() => rejectTask(err));
} }
}); });
}); });

View File

@ -4,6 +4,7 @@ import { get as httpGet } from 'http';
import { get as httpsGet } from 'https'; import { get as httpsGet } from 'https';
import { cpus, tmpdir } from 'os'; import { cpus, tmpdir } from 'os';
import { createWriteStream, mkdirSync, readFileSync, rmdirSync, WriteStream } from 'fs'; import { createWriteStream, mkdirSync, readFileSync, rmdirSync, WriteStream } from 'fs';
import readLines from 'n-readlines';
const packageJson = JSON.parse(readFileSync(joinPath(__dirname, '..', 'package.json'), 'utf-8')); const packageJson = JSON.parse(readFileSync(joinPath(__dirname, '..', 'package.json'), 'utf-8'));
const userAgent = `${packageJson.name || 'Action-SpigotMC'}/${packageJson.version || 'UNKNOWN_VERSION'} (+${packageJson.homepage || 'https://github.com/SpraxDev/'})`; const userAgent = `${packageJson.name || 'Action-SpigotMC'}/${packageJson.version || 'UNKNOWN_VERSION'} (+${packageJson.homepage || 'https://github.com/SpraxDev/'})`;
@ -127,6 +128,23 @@ export async function downloadFile(url: string, dest: string, currRedirectDepth:
}); });
} }
export function readLastLines(file: string, lineCount: number, encoding: string = 'utf-8'): string[] {
const result = [];
const reader = new readLines(file);
let line;
while (line = reader.next()) {
result.push(line.toString(encoding));
if (result.length > lineCount) {
result.shift();
}
}
return result;
}
export function resetWorkingDir(): { base: string, cache: string, logs: string } { export function resetWorkingDir(): { base: string, cache: string, logs: string } {
const baseDir = joinPath(tmpdir(), 'SpraxDev-Action-SpigotMC'); const baseDir = joinPath(tmpdir(), 'SpraxDev-Action-SpigotMC');
const cacheDir = joinPath(baseDir, 'cache'); const cacheDir = joinPath(baseDir, 'cache');