file-timestamp-stream
Advanced tools
Comparing version 2.2.4 to 3.0.0
@@ -1,4 +0,4 @@ | ||
/// <reference types="node" /> | ||
import fs, { WriteStream } from "fs"; | ||
import { Writable, WritableOptions } from "stream"; | ||
import * as fs from "node:fs"; | ||
import { WriteStream } from "node:fs"; | ||
import { Writable, WritableOptions } from "node:stream"; | ||
export interface FileTimestampStreamOptions extends WritableOptions { | ||
@@ -29,6 +29,6 @@ /** a string with [flags](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) for opened stream (default: `'a'`) */ | ||
constructor(options?: FileTimestampStreamOptions); | ||
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void; | ||
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void; | ||
_writev(chunks: Array<{ | ||
chunk: any; | ||
encoding: string; | ||
encoding: BufferEncoding; | ||
}>, callback: (error?: Error | null) => void): void; | ||
@@ -35,0 +35,0 @@ _final(callback: (error?: Error | null) => void): void; |
@@ -1,10 +0,7 @@ | ||
"use strict"; | ||
/// <reference types="node" /> | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const fs_1 = tslib_1.__importDefault(require("fs")); | ||
const stream_1 = require("stream"); | ||
const stream_finished_1 = tslib_1.__importDefault(require("stream.finished")); | ||
const ultra_strftime_1 = tslib_1.__importDefault(require("ultra-strftime")); | ||
class FileTimestampStream extends stream_1.Writable { | ||
import * as fs from "node:fs"; | ||
import { finished, Writable } from "node:stream"; | ||
import * as timers from "timers-obj"; | ||
import strftime from "ultra-strftime"; | ||
export class FileTimestampStream extends Writable { | ||
constructor(options = {}) { | ||
@@ -14,3 +11,3 @@ super(options); | ||
this.flags = this.options.flags || "a"; | ||
this.fs = this.options.fs || fs_1.default; | ||
this.fs = this.options.fs || fs; | ||
this.path = this.options.path || "out.log"; | ||
@@ -92,3 +89,3 @@ this.destroyed = false; | ||
for (const closer of this.closers.values()) { | ||
clearInterval(closer); | ||
closer.close(); | ||
} | ||
@@ -109,3 +106,3 @@ this.streams.clear(); | ||
newFilename() { | ||
return ultra_strftime_1.default(this.path, new Date()); | ||
return strftime(this.path, new Date()); | ||
} | ||
@@ -135,13 +132,15 @@ rotate() { | ||
this.streamErrorHandlers.set(newFilename, newStreamErrorHandler); | ||
const newCloser = setInterval(() => { | ||
const newCloser = timers | ||
.interval(FileTimestampStream.CLOSE_UNUSED_FILE_AFTER, () => { | ||
if (newFilename !== this.newFilename()) { | ||
clearInterval(newCloser); | ||
newCloser.close(); | ||
this.closers.delete(newFilename); | ||
newStream.end(); | ||
} | ||
}, FileTimestampStream.CLOSE_UNUSED_FILE_AFTER).unref(); | ||
}) | ||
.unref(); | ||
this.closer = closer; | ||
this.closers.set(newFilename, newCloser); | ||
const newStreamCancelFinisher = stream_finished_1.default(newStream, () => { | ||
clearInterval(newCloser); | ||
const newStreamCancelFinisher = finished(newStream, () => { | ||
newCloser.close(); | ||
this.closers.delete(newFilename); | ||
@@ -159,5 +158,3 @@ if (typeof newStream.destroy === "function") { | ||
} | ||
exports.FileTimestampStream = FileTimestampStream; | ||
FileTimestampStream.CLOSE_UNUSED_FILE_AFTER = 1000; | ||
exports.default = FileTimestampStream; | ||
//# sourceMappingURL=file-timestamp-stream.js.map | ||
export default FileTimestampStream; |
{ | ||
"name": "file-timestamp-stream", | ||
"version": "2.2.4", | ||
"version": "3.0.0", | ||
"description": "Writing stream with file rotating based on timestamp", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"default": "./lib/file-timestamp-stream.js", | ||
"typings": "./lib/file-timestamp-stream.d.ts" | ||
} | ||
}, | ||
"main": "lib/file-timestamp-stream.js", | ||
@@ -23,34 +30,33 @@ "typings": "lib/file-timestamp-stream.d.ts", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=16.0.0" | ||
}, | ||
"dependencies": { | ||
"stream.finished": "^1.2.0", | ||
"tslib": "^1.10.0", | ||
"timers-obj": "^3.1.0", | ||
"ultra-strftime": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.3", | ||
"@types/dirty-chai": "^2.0.2", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.7.11", | ||
"@types/ultra-strftime": "^1.0.0", | ||
"chai": "^4.2.0", | ||
"coveralls": "^3.0.6", | ||
"cross-env": "^6.0.3", | ||
"dirty-chai": "^2.0.1", | ||
"eslint": "^6.5.1", | ||
"eslint-config-prettier": "^6.4.0", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-node": "^10.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"markdownlint-cli": "^0.18.0", | ||
"mocha": "^6.2.1", | ||
"@eslint/js": "^9.5.0", | ||
"@tsconfig/node16": "^16.1.3", | ||
"@types/chai": "^4.3.16", | ||
"@types/eslint__js": "^8.42.3", | ||
"@types/mocha": "^10.0.7", | ||
"@types/node": "^20.14.9", | ||
"@types/semver": "^7.5.8", | ||
"@types/ultra-strftime": "^1.0.3", | ||
"@typescript-eslint/parser": "^7.14.1", | ||
"c8": "^10.1.2", | ||
"chai": "^5.1.1", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"markdownlint-cli": "^0.41.0", | ||
"mocha": "^10.5.2", | ||
"mocha-steps": "^1.3.0", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.18.2", | ||
"shx": "^0.3.2", | ||
"ts-node": "^8.4.1", | ||
"tslint": "^5.20.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.6.3" | ||
"prettier": "^3.3.2", | ||
"semver": "^7.6.2", | ||
"shx": "^0.3.4", | ||
"ts-node": "^10.9.2", | ||
"tslib": "^2.6.3", | ||
"typescript": "^5.5.2", | ||
"typescript-eslint": "^7.14.1" | ||
}, | ||
@@ -62,4 +68,9 @@ "scripts": { | ||
"clean:coverage": "shx rm -rf coverage .nyc_output", | ||
"lint": "npm run compile && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && prettier --ignore-path .gitignore --list-different '**/*.{js,json,md,ts,yml}' && markdownlint \"*.md\"", | ||
"postpublish": "git tag v$npm_package_version -a -m \"Release v$npm_package_version\" && git push --tags", | ||
"lint": "npm run lint:tsc:src && npm run lint:tsc:test && npm run lint:tsc:examples && npm run lint:eslint && npm run lint:prettier && npm run lint:markdownlint", | ||
"lint:tsc:examples": "tsc --noEmit --pretty --project examples", | ||
"lint:tsc:src": "tsc --noEmit --pretty --project .", | ||
"lint:tsc:test": "tsc --noEmit --pretty --project test", | ||
"lint:eslint": "eslint .", | ||
"lint:prettier": "prettier --ignore-path .gitignore --list-different '**/*.{js,json,md,ts,yml}'", | ||
"lint:markdownlint": "markdownlint \"*.md\"", | ||
"prepack": "npm run compile", | ||
@@ -69,5 +80,7 @@ "prepublishOnly": "npm run test", | ||
"test": "npm run test:spec", | ||
"test:spec": "$NYC mocha \"test/*.ts\"", | ||
"test:coverage": "npm run clean:coverage && cross-env NYC=\"nyc --no-clean --reporter=lcov\" npm run test:spec && nyc report --reporter=text-summary --color" | ||
"test:spec": "mocha", | ||
"test:coverage": "npm run test:coverage:spec && npm run test:coverage:report", | ||
"test:coverage:spec": "c8 --no-clean --reporter=lcov npm run test:spec", | ||
"test:coverage:report": "c8 report --reporter=text-summary --color" | ||
} | ||
} |
@@ -5,3 +5,7 @@ # file-timestamp-stream | ||
[![Build Status](https://secure.travis-ci.org/dex4er/js-file-timestamp-stream.svg)](http://travis-ci.org/dex4er/js-file-timestamp-stream) [![Coverage Status](https://coveralls.io/repos/github/dex4er/js-file-timestamp-stream/badge.svg)](https://coveralls.io/github/dex4er/js-file-timestamp-stream) [![npm](https://img.shields.io/npm/v/file-timestamp-stream.svg)](https://www.npmjs.com/package/file-timestamp-stream) | ||
[![GitHub](https://img.shields.io/github/v/release/dex4er/js-file-timestamp-stream?display_name=tag&sort=semver)](https://github.com/dex4er/js-file-timestamp-stream) | ||
[![CI](https://github.com/dex4er/js-file-timestamp-stream/actions/workflows/ci.yaml/badge.svg)](https://github.com/dex4er/js-file-timestamp-stream/actions/workflows/ci.yaml) | ||
[![Trunk Check](https://github.com/dex4er/js-file-timestamp-stream/actions/workflows/trunk.yaml/badge.svg)](https://github.com/dex4er/js-file-timestamp-stream/actions/workflows/trunk.yaml) | ||
[![Coverage Status](https://coveralls.io/repos/github/dex4er/js-file-timestamp-stream/badge.svg)](https://coveralls.io/github/dex4er/js-file-timestamp-stream) | ||
[![npm](https://img.shields.io/npm/v/file-timestamp-stream.svg)](https://www.npmjs.com/package/file-timestamp-stream) | ||
@@ -17,3 +21,3 @@ <!-- markdownlint-enable MD013 --> | ||
This module requires ES6 with Node >= 6. | ||
This module requires ES2021 with Node >= 16. | ||
@@ -37,8 +41,2 @@ ## Installation | ||
```js | ||
const {FileTimestampStream} = require("file-timestamp-stream") | ||
``` | ||
_Typescript:_ | ||
```ts | ||
import FileTimestampStream from "file-timestamp-stream" | ||
@@ -53,3 +51,3 @@ // or | ||
[flags](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) | ||
for opened stream (default: `'a'`) | ||
for the opened stream (default: `'a'`) | ||
- `fs` is a custom [fs](https://nodejs.org/api/fs.html) module (optional) | ||
@@ -71,5 +69,5 @@ - `path` is a template for new filenames (default: `'out.log'`) | ||
This method can be overriden in subclass. | ||
This method can be overridden in the subclass. | ||
The method generates a filename for new files. By default it returns new | ||
The method generates a filename for new files. By default, it returns a new | ||
filename based on path and current time. | ||
@@ -109,5 +107,5 @@ | ||
Protected properties for custom subclass: | ||
Protected properties for a custom subclass: | ||
- `currentFilename` contains last opened filename | ||
- `currentFilename` contains the last opened filename | ||
- `stream` contains current | ||
@@ -119,12 +117,12 @@ [fs.WriteStream](https://nodejs.org/api/fs.html#fs_class_fs_writestream) | ||
Path can contain [strftime](https://www.npmjs.com/package/strftime) specifiers. | ||
A path can contain [strftime](https://www.npmjs.com/package/strftime) specifiers. | ||
### Warning | ||
This stream have to be closed to free own streams and timers. | ||
This stream has to be closed to free streams and timers. | ||
## License | ||
Copyright (c) 2017-2019 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
Copyright (c) 2017-2024 Piotr Roszatycki <piotr.roszatycki@gmail.com> | ||
[MIT](https://opensource.org/licenses/MIT) |
/// <reference types="node" /> | ||
import fs, {WriteStream} from "fs" | ||
import {Writable, WritableOptions} from "stream" | ||
import finished from "stream.finished" | ||
import * as fs from "node:fs" | ||
import {WriteStream} from "node:fs" | ||
import {finished, Writable, WritableOptions} from "node:stream" | ||
import * as timers from "timers-obj" | ||
import strftime from "ultra-strftime" | ||
@@ -34,3 +36,3 @@ | ||
private readonly streamErrorHandlers: Map<string, (err: Error) => void> = new Map() | ||
private readonly closers: Map<string, NodeJS.Timer> = new Map() | ||
private readonly closers: Map<string, timers.Interval> = new Map() | ||
@@ -43,3 +45,3 @@ private closer?: NodeJS.Timer | ||
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void { | ||
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void { | ||
if (this.destroyed) { | ||
@@ -53,7 +55,7 @@ return callback(new Error("write after destroy")) | ||
} catch (e) { | ||
callback(e) | ||
callback(e as Error) | ||
} | ||
} | ||
_writev(chunks: Array<{chunk: any; encoding: string}>, callback: (error?: Error | null) => void): void { | ||
_writev(chunks: Array<{chunk: any; encoding: BufferEncoding}>, callback: (error?: Error | null) => void): void { | ||
if (this.destroyed) { | ||
@@ -77,3 +79,3 @@ return callback(new Error("write after destroy")) | ||
} | ||
callback(e) | ||
callback(e as Error) | ||
} | ||
@@ -117,3 +119,3 @@ } | ||
for (const closer of this.closers.values()) { | ||
clearInterval(closer) | ||
closer.close() | ||
} | ||
@@ -146,3 +148,3 @@ this.streams.clear() | ||
if (currentFilename && stream && closer) { | ||
clearInterval(closer) | ||
clearInterval(closer as NodeJS.Timeout) | ||
stream.end() | ||
@@ -170,9 +172,11 @@ | ||
const newCloser = setInterval(() => { | ||
if (newFilename !== this.newFilename()) { | ||
clearInterval(newCloser) | ||
this.closers.delete(newFilename) | ||
newStream.end() | ||
} | ||
}, FileTimestampStream.CLOSE_UNUSED_FILE_AFTER).unref() | ||
const newCloser = timers | ||
.interval(FileTimestampStream.CLOSE_UNUSED_FILE_AFTER, () => { | ||
if (newFilename !== this.newFilename()) { | ||
newCloser.close() | ||
this.closers.delete(newFilename) | ||
newStream.end() | ||
} | ||
}) | ||
.unref() | ||
this.closer = closer | ||
@@ -182,3 +186,3 @@ this.closers.set(newFilename, newCloser) | ||
const newStreamCancelFinisher = finished(newStream, () => { | ||
clearInterval(newCloser) | ||
newCloser.close() | ||
this.closers.delete(newFilename) | ||
@@ -185,0 +189,0 @@ |
{ | ||
"extends": "@tsconfig/node16/tsconfig.json", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"importHelpers": true, | ||
"lib": ["es6"], | ||
"module": "commonjs", | ||
"noImplicitAny": true, | ||
@@ -13,8 +11,8 @@ "noImplicitReturns": true, | ||
"outDir": "./lib", | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "es6", | ||
"typeRoots": ["node_modules/@types"] | ||
}, | ||
"exclude": ["./examples/**/*", "./lib/**/*", "./test/**/*"] | ||
"exclude": ["./examples/**/*", "./lib/**/*", "./test/**/*"], | ||
"ts-node": { | ||
"transpileOnly": true | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
0
Yes
20764
7
382
122
+ Addedtimers-obj@^3.1.0
+ Addedtimers-obj@3.1.0(transitive)
- Removedstream.finished@^1.2.0
- Removedtslib@^1.10.0
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedstream.finished@1.2.0(transitive)
- Removedtslib@1.14.1(transitive)