From ce8470ee7cc2af222f1a93c69a127cea9ea4130e Mon Sep 17 00:00:00 2001 From: Hubert Date: Tue, 8 Aug 2023 07:17:30 -0300 Subject: [PATCH] Chore: Resolves #8609: Some auto-generated .js files are commited to the repository (#8632) --- .gitignore | 1 + packages/lib/RotatingLogs.js | 56 ------------------------------- packages/lib/RotatingLogs.test.js | 56 ------------------------------- 3 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 packages/lib/RotatingLogs.js delete mode 100644 packages/lib/RotatingLogs.test.js diff --git a/.gitignore b/.gitignore index 5424b673d2..46e6583d41 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ packages/tools/github_oauth_token.txt lerna-debug.log .env docs/**/*.mustache +.idea # Yarn stuff # https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored diff --git a/packages/lib/RotatingLogs.js b/packages/lib/RotatingLogs.js deleted file mode 100644 index 29d70e01f0..0000000000 --- a/packages/lib/RotatingLogs.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const shim_1 = require("./shim"); -class RotatingLogs { - constructor(logFilesDir, maxFileSize = null, inactiveMaxAge = null) { - this.maxFileSize = 1024 * 1024 * 100; - this.inactiveMaxAge = 90 * 24 * 60 * 60 * 1000; - this.logFilesDir = logFilesDir; - if (maxFileSize) - this.maxFileSize = maxFileSize; - if (inactiveMaxAge) - this.inactiveMaxAge = inactiveMaxAge; - } - cleanActiveLogFile() { - return __awaiter(this, void 0, void 0, function* () { - const stats = yield this.fsDriver().stat(this.logFileFullpath()); - if (stats.size >= this.maxFileSize) { - const newLogFile = this.logFileFullpath(this.getNameToNonActiveLogFile()); - yield this.fsDriver().move(this.logFileFullpath(), newLogFile); - } - }); - } - getNameToNonActiveLogFile() { - return `log-${Date.now()}.txt`; - } - deleteNonActiveLogFiles() { - return __awaiter(this, void 0, void 0, function* () { - const files = yield this.fsDriver().readDirStats(this.logFilesDir); - for (const file of files) { - if (!file.path.match(/^log-[0-9]+.txt$/gi)) - continue; - const ageOfTheFile = Date.now() - file.birthtime; - if (ageOfTheFile >= this.inactiveMaxAge) { - yield this.fsDriver().remove(this.logFileFullpath(file.path)); - } - } - }); - } - logFileFullpath(fileName = 'log.txt') { - return `${this.logFilesDir}/${fileName}`; - } - fsDriver() { - return shim_1.default.fsDriver(); - } -} -exports.default = RotatingLogs; -//# sourceMappingURL=RotatingLogs.js.map \ No newline at end of file diff --git a/packages/lib/RotatingLogs.test.js b/packages/lib/RotatingLogs.test.js deleted file mode 100644 index a4ecc2f03a..0000000000 --- a/packages/lib/RotatingLogs.test.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs_extra_1 = require("fs-extra"); -const test_utils_1 = require("./testing/test-utils"); -const RotatingLogs_1 = require("./RotatingLogs"); -const createTestLogFile = (dir) => __awaiter(void 0, void 0, void 0, function* () { - yield (0, fs_extra_1.writeFile)(`${dir}/log.txt`, 'some content'); -}); -describe('RotatingLogs', () => { - test('should rename log.txt to log-TIMESTAMP.txt', () => __awaiter(void 0, void 0, void 0, function* () { - let dir; - try { - dir = yield (0, test_utils_1.createTempDir)(); - yield createTestLogFile(dir); - let files = yield (0, fs_extra_1.readdir)(dir); - expect(files.find(file => file.match(/^log.txt$/gi))).toBeTruthy(); - expect(files.length).toBe(1); - const rotatingLogs = new RotatingLogs_1.default(dir, 1, 1); - yield rotatingLogs.cleanActiveLogFile(); - files = yield (0, fs_extra_1.readdir)(dir); - expect(files.find(file => file.match(/^log.txt$/gi))).toBeFalsy(); - expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeTruthy(); - expect(files.length).toBe(1); - } - finally { - yield (0, fs_extra_1.remove)(dir); - } - })); - test('should delete inative log file after 1ms', () => __awaiter(void 0, void 0, void 0, function* () { - let dir; - try { - dir = yield (0, test_utils_1.createTempDir)(); - yield createTestLogFile(dir); - const rotatingLogs = new RotatingLogs_1.default(dir, 1, 1); - yield rotatingLogs.cleanActiveLogFile(); - yield (0, test_utils_1.msleep)(1); - yield rotatingLogs.deleteNonActiveLogFiles(); - const files = yield (0, fs_extra_1.readdir)(dir); - expect(files.find(file => file.match(/^log-[0-9]+.txt$/gi))).toBeFalsy(); - expect(files.length).toBe(0); - } - finally { - yield (0, fs_extra_1.remove)(dir); - } - })); -}); -//# sourceMappingURL=RotatingLogs.test.js.map \ No newline at end of file