Skip to content

Commit

Permalink
restore support for Node.js v14
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Dec 28, 2023
1 parent 354ad53 commit cd5623a
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ env:
node_js:
- "20"
- "18"
- "16"
- "14"

language: node_js
script: "npm run coverage"
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "eg2.vscode-npm-script", "esbenp.prettier-vscode", "myh.preview-vscode", "rohit-gohri.format-code-action", "streetsidesoftware.code-spell-checker"]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "myh.preview-vscode", "rohit-gohri.format-code-action", "streetsidesoftware.code-spell-checker"]
}
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"program": "${workspaceFolder}/node_modules/mocha/bin/mocha",
"args": ["-r", "ts-node/register", "--timeout", "999999", "--colors", "${workspaceFolder}/test/*.ts"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector"
"internalConsoleOptions": "neverOpen"
}
]
}
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
"jvassev",
"kbirger",
"lcov",
"linebreak",
"nonblock",
"nonwords",
"parens",
"pyues",
"rakshith",
"ravi",
"reclose",
"refinal",
"ricci",
"wangao"
"satoshis",
"wangao",
"zmssi"
],
"editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"],
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- 2023-12-28 - v3.2.1
- Restored support for **Node.js v14**.
- Badges (but dependents) from [shields.io](https://shields.io/).
- 2023-12-27 - v3.2.0
- Added `intervalUTC` as [requested](https://github.com/iccicci/rotating-file-stream/issues/97).
- 2023-07-22 - v3.1.1
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
[code-url]: https://codeclimate.com/github/iccicci/rotating-file-stream
[cover-badge]: https://codeclimate.com/github/iccicci/rotating-file-stream/badges/coverage.svg
[deps-badge]: https://badgen.net/npm/dependents/rotating-file-stream?icon=npm
[deps-badge2]: https://img.shields.io/librariesio/dependents/npm/rotating-file-stream?logo=npm
[deps-url]: https://www.npmjs.com/package/rotating-file-stream?activeTab=dependents
[donate-badge]: https://badgen.net/badge/donate/bitcoin?icon=bitcoin
[donate-badge]: https://img.shields.io/static/v1?label=donate&message=bitcoin&color=blue&logo=bitcoin
[donate-url]: https://blockchain.info/address/12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN
[github-url]: https://github.com/iccicci/rotating-file-stream
[npm-downloads-badge]: https://badgen.net/npm/dw/rotating-file-stream?icon=npm
[npm-badge]: https://badgen.net/npm/v/rotating-file-stream?color=green&icon=npm
[npm-downloads-badge]: https://img.shields.io/npm/dw/rotating-file-stream?logo=npm
[npm-badge]: https://img.shields.io/npm/v/rotating-file-stream?color=green&logo=npm
[npm-url]: https://www.npmjs.com/package/rotating-file-stream
[stars-badge]: https://badgen.net/github/stars/iccicci/rotating-file-stream?icon=github
[stars-badge]: https://img.shields.io/github/stars/iccicci/rotating-file-stream?logo=github
[stars-url]: https://github.com/iccicci/rotating-file-stream/stargazers
[travis-badge]: https://badgen.net/travis/iccicci/rotating-file-stream/master?icon=travis
[travis-badge]: https://img.shields.io/travis/com/iccicci/rotating-file-stream?logo=travis
[travis-url]: https://app.travis-ci.com/github/iccicci/rotating-file-stream
[types-badge]: https://badgen.net/npm/types/rotating-file-stream?color=green&icon=typescript
[types-badge]: https://img.shields.io/static/v1?label=types&message=included&color=green&logo=typescript

### Description

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"logrotate"
],
"engines": {
"node": ">=18.0"
"node": ">=14.0"
},
"author": "Daniele Ricci <daniele.icc@gmail.com> (https://github.com/iccicci)",
"contributors": [
Expand Down
18 changes: 11 additions & 7 deletions test/02write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import { deepStrictEqual as deq, strictEqual as eq } from "assert";
import { readFileSync } from "fs";
import { createStream } from "..";
import { test } from "./helper";
import { gte14, test, v14 } from "./helper";

export function v14Error(): { error?: string[] } {
return gte14 ? {} : { error: ["ERR_STREAM_DESTROYED"] };
}

describe("write(s)", () => {
describe("single write", () => {
const events = test({}, rfs => rfs.end("test\n"));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
});

Expand All @@ -20,7 +24,7 @@ describe("write(s)", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\ntest\ntest\ntest\n"));
});

Expand All @@ -29,14 +33,14 @@ describe("write(s)", () => {
rfs.end("test\n", "utf8", () => (events.endcb = true));
});

it("events", () => deq(events, { close: 1, endcb: true, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { endcb: true, finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
});

describe("write after open", function() {
const events = test({}, rfs => rfs.once("open", () => rfs.end("test\n", "utf8")));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
});

Expand All @@ -61,7 +65,7 @@ describe("write(s)", () => {
stream.on("open", () => event(done));
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"] }));
it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], ...v14Error() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), ""));
});

Expand All @@ -73,7 +77,7 @@ describe("write(s)", () => {
})
);

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"] }));
it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], ...v14Error() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), ""));
});

Expand Down
12 changes: 6 additions & 6 deletions test/03size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import { deepStrictEqual as deq, strictEqual as eq } from "assert";
import { readFileSync } from "fs";
import { sep } from "path";
import { test } from "./helper";
import { test, v14 } from "./helper";

describe("size", () => {
describe("initial rotation", () => {
const events = test({ files: { "test.log": "test\ntest\n" }, options: { size: "10B" } }, rfs => rfs.end("test\n"));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], rotated: ["1-test.log"], rotation: 1, write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n"));
});

describe("single write rotation by size", () => {
const events = test({ files: { "test.log": "test\n" }, options: { size: "10B" } }, rfs => rfs.end("test\n"));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), ""));
it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n"));
});
Expand All @@ -29,7 +29,7 @@ describe("size", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n"));
});
Expand All @@ -41,7 +41,7 @@ describe("size", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\ntest\ntest\n"));
});
Expand All @@ -55,7 +55,7 @@ describe("size", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync(filename, "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync(rotated, "utf8"), "test\ntest\n"));
});
Expand Down
28 changes: 14 additions & 14 deletions test/05options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@ import { deepStrictEqual as deq, strictEqual as eq } from "assert";
import { gunzipSync } from "zlib";
import { readFileSync } from "fs";
import { sep } from "path";
import { test } from "./helper";
import { test, v14 } from "./helper";

describe("options", () => {
describe("size KiloBytes", () => {
let size: number;
const events = test({ options: { size: "10K" } }, rfs => rfs.end("test\n", () => (size = rfs.options.size)));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("10K", () => eq(size, 10240));
});

describe("size MegaBytes", () => {
let size: number;
const events = test({ options: { size: "10M" } }, rfs => rfs.end("test\n", () => (size = rfs.options.size)));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("10M", () => eq(size, 10485760));
});

describe("size GigaBytes", () => {
let size: number;
const events = test({ options: { size: "10G" } }, rfs => rfs.end("test\n", () => (size = rfs.options.size)));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("10G", () => eq(size, 10737418240));
});

describe("interval minutes", () => {
let interval: number;
const events = test({ options: { interval: "3m" } }, rfs => rfs.end("test\n", () => (interval = rfs.options.interval)));

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("3'", () => deq(interval, { num: 3, unit: "m" }));
});

Expand All @@ -49,7 +49,7 @@ describe("options", () => {
})
);

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("3h", () => deq(interval, { num: 3, unit: "h" }));
it("hours daylight saving", () => eq(next - prev, 7200000));
});
Expand All @@ -64,7 +64,7 @@ describe("options", () => {
})
);

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, ...v14() }));
it("3h", () => deq(interval, { num: 3, unit: "d" }));
it("hours daylight saving", () => eq(next - prev, 255600000));
});
Expand All @@ -78,7 +78,7 @@ describe("options", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync(filename, "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync(rotated, "utf8"), "test\ntest\n"));
});
Expand All @@ -92,7 +92,7 @@ describe("options", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: [filename, filename], rotated: [rotated], rotation: 1, write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync(filename, "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync(rotated, "utf8"), "test\ntest\n"));
});
Expand All @@ -107,7 +107,7 @@ describe("options", () => {
});

it("options", () => deq(options, { interval: { num: 1, unit: "d" }, path: "", rotate: 5, size: 10485760 }));
it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log"], write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log"], write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\ntest\ntest\n"));
});

Expand All @@ -118,7 +118,7 @@ describe("options", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["log/1-test.log", "log/2-test.log"], rotated: ["log/1-test.log"], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["log/1-test.log", "log/2-test.log"], rotated: ["log/1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() }));
it("first file content", () => eq(readFileSync("log/1-test.log", "utf8"), "test\ntest\n"));
it("second file content", () => eq(readFileSync("log/2-test.log", "utf8"), "test\n"));
});
Expand All @@ -131,7 +131,7 @@ describe("options", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["1-test.log", "2-test.log", "3-test.log"], rotated: ["1-test.log", "2-test.log"], rotation: 2, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["1-test.log", "2-test.log", "3-test.log"], rotated: ["1-test.log", "2-test.log"], rotation: 2, write: 1, writev: 1, ...v14() }));
it("first file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n"));
it("second file content", () => eq(readFileSync("2-test.log", "utf8"), "test\ntest\n"));
it("third file content", () => eq(readFileSync("3-test.log", "utf8"), "test\n"));
Expand All @@ -147,7 +147,7 @@ describe("options", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() }));
it("stdout", () => deq(content, [Buffer.from("test\n"), Buffer.from("test\n"), Buffer.from("test\n")]));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
it("rotated file content", () => eq(readFileSync("1-test.log", "utf8"), "test\ntest\n"));
Expand All @@ -163,7 +163,7 @@ describe("options", () => {
rfs.end("test\n");
});

it("events", () => deq(events, { close: 1, finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1 }));
it("events", () => deq(events, { finish: 1, open: ["test.log", "test.log"], rotated: ["1-test.log"], rotation: 1, write: 1, writev: 1, ...v14() }));
it("file content", () => eq(readFileSync("test.log", "utf8"), "test\n"));
it("rotated file content", () => eq(gunzipSync(readFileSync("1-test.log")).toString(), "test\ntest\n"));
});
Expand Down
Loading

0 comments on commit cd5623a

Please sign in to comment.