Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Node 14 #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
"node": true,
"jest/globals": true
},
"rules": {}
}
"rules": {
"unicorn/prefer-node-protocol": "off"
}
}
16 changes: 8 additions & 8 deletions src/file-log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createWriteStream, existsSync, mkdirSync } from 'node:fs';
import { join, resolve } from 'node:path';
import fs from 'fs';
import path from 'path';

import { stripAnsi } from './ansi';

Expand All @@ -17,26 +17,26 @@ type FileLoggerConfigAppend = {
};

export const FileLogger = (config: FileLoggerConfig) => {
let { path } = config;
let { path: filePath } = config;
const { mode } = config;

// If we are creating a new file generate the file name
if (mode == 'NEW_FILE') {
const { namePattern } = config;
const calculatedPattern = namePattern;

path = join(path, calculatedPattern);
filePath = path.join(filePath, calculatedPattern);
}

// Ensure the parent folder exists
const folder = resolve(path, '..');
const folder = path.resolve(filePath, '..');

if (!existsSync(folder)) {
mkdirSync(folder, { recursive: true });
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder, { recursive: true });
}

// Create the stream to write out to
const stream = createWriteStream(path, {
const stream = fs.createWriteStream(filePath, {
encoding: 'utf-8',
autoClose: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inspect } from 'node:util';
import { inspect } from 'util';

import { stripAnsi } from './ansi';

Expand Down
2 changes: 1 addition & 1 deletion tests/filelog.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'node:fs';
import fs from 'fs';

import { FileLogger } from '../src/file-log';

Expand Down