Comparing version 1.0.1 to 1.0.2
@@ -1,60 +0,4 @@ | ||
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __async = (__this, __arguments, generator) => { | ||
return new Promise((resolve, reject) => { | ||
var fulfilled = (value) => { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
var rejected = (value) => { | ||
try { | ||
step(generator.throw(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
step((generator = generator.apply(__this, __arguments)).next()); | ||
}); | ||
}; | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
onExit: () => onExit | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/on-exit.ts | ||
var import_node_process = __toESM(require("process")); | ||
var import_node_util = require("util"); | ||
import process from "process"; | ||
import { types } from "util"; | ||
var LOG_PREFIX = "[gracy]"; | ||
@@ -64,6 +8,5 @@ var DEFAULT_EVENTS = ["uncaughtException", "unhandledRejection"]; | ||
function onExit(options, ...fns) { | ||
var _a, _b; | ||
const logger = options.logger; | ||
const events = (_a = options.events) != null ? _a : DEFAULT_EVENTS; | ||
const signals = (_b = options.signals) != null ? _b : DEFAULT_SIGNALS; | ||
const events = options.events ?? DEFAULT_EVENTS; | ||
const signals = options.signals ?? DEFAULT_SIGNALS; | ||
function loggerEnabled(logger2) { | ||
@@ -107,8 +50,8 @@ return logger2 !== false; | ||
} | ||
import_node_process.default.on("beforeExit", (code) => __async(this, null, function* () { | ||
process.on("beforeExit", async (code) => { | ||
try { | ||
logDebug({ code }, "Received beforeExit hook"); | ||
for (const fn of fns) { | ||
if (import_node_util.types.isAsyncFunction(fn)) { | ||
yield fn(); | ||
if (types.isAsyncFunction(fn)) { | ||
await fn(); | ||
} else { | ||
@@ -123,15 +66,15 @@ void fn(); | ||
} finally { | ||
import_node_process.default.exit(code); | ||
process.exit(code); | ||
} | ||
})); | ||
}); | ||
for (const event of events) { | ||
import_node_process.default.on(event, (err) => { | ||
process.on(event, (err) => { | ||
logFatal(err, `Received ${event}`); | ||
import_node_process.default.emit("beforeExit", 1); | ||
process.emit("beforeExit", 1); | ||
}); | ||
} | ||
for (const signal of signals) { | ||
import_node_process.default.on(signal, () => { | ||
process.on(signal, () => { | ||
logDebug(`Received ${signal}`); | ||
import_node_process.default.emit("beforeExit", 0); | ||
process.emit("beforeExit", 0); | ||
}); | ||
@@ -141,5 +84,4 @@ } | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
export { | ||
onExit | ||
}); | ||
}; |
{ | ||
"name": "gracy", | ||
"version": "1.0.2", | ||
"description": "Execute custom cleanup functions before Node.js exits", | ||
"version": "1.0.1", | ||
"author": "Sami Al-Dury", | ||
@@ -15,9 +15,10 @@ "license": "MIT", | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"type": "module", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.js" | ||
}, | ||
@@ -34,21 +35,21 @@ "./package.json": "./package.json" | ||
"devDependencies": { | ||
"@changesets/changelog-git": "0.1.14", | ||
"@changesets/cli": "2.26.1", | ||
"@commitlint/cli": "17.5.0", | ||
"@commitlint/config-conventional": "17.4.4", | ||
"@types/node": "18.15.10", | ||
"@typescript-eslint/eslint-plugin": "5.56.0", | ||
"@typescript-eslint/parser": "5.56.0", | ||
"@vitest/coverage-c8": "0.29.7", | ||
"eslint": "8.36.0", | ||
"eslint-config-prettier": "8.8.0", | ||
"eslint-import-resolver-typescript": "3.5.3", | ||
"eslint-plugin-import": "2.27.5", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"husky": "8.0.3", | ||
"lint-staged": "13.2.0", | ||
"prettier": "2.8.6", | ||
"tsup": "6.7.0", | ||
"typescript": "5.0.2", | ||
"vitest": "0.29.7" | ||
"@changesets/changelog-git": "^0.1.14", | ||
"@changesets/cli": "^2.26.1", | ||
"@commitlint/cli": "^17.5.0", | ||
"@commitlint/config-conventional": "^17.4.4", | ||
"@types/node": "^18.15.10", | ||
"@typescript-eslint/eslint-plugin": "^5.56.0", | ||
"@typescript-eslint/parser": "^5.56.0", | ||
"@vitest/coverage-c8": "^0.29.7", | ||
"eslint": "^8.36.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-import-resolver-typescript": "^3.5.3", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^13.2.0", | ||
"prettier": "^2.8.6", | ||
"tsup": "^6.7.0", | ||
"typescript": "^5.0.2", | ||
"vitest": "^0.29.7" | ||
}, | ||
@@ -55,0 +56,0 @@ "keywords": [ |
@@ -9,3 +9,3 @@ # Gracy | ||
Execute custom cleanup functions before Node.js exits. Zero dependencies. | ||
Gracy is a zero-dependency library that provides a simple way to execute custom functions before a Node.js process exits. It helps you ensure that your applications perform cleanup tasks, gracefully close resources, and maintain data integrity during (un)expected shutdowns or terminations. | ||
@@ -23,2 +23,3 @@ ## Usage | ||
{ logger: pinoInstance }, | ||
// Supports sync/async functions | ||
closeHttpServer, | ||
@@ -43,13 +44,4 @@ closeDatabaseConnection | ||
- [Node.js](https://github.com/nodejs/node) & [Typescript](https://github.com/microsoft/TypeScript) (ESM) | ||
- [tsup](https://github.com/egoist/tsup) for bundling | ||
- [pnpm](https://github.com/pnpm/pnpm) package manager | ||
- [Vitest](https://github.com/vitest-dev/vitest) for testing (coverage via [c8](https://github.com/bcoe/c8)) | ||
- [Prettier](https://github.com/prettier/prettier) formatter | ||
- [ESLint](https://github.com/eslint/eslint) linter | ||
- [Husky](https://github.com/typicode/husky) Git hooks | ||
- [Changesets](https://github.com/changesets/changesets) for versioning | ||
## License | ||
[MIT](LICENSE) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Yes
16862
365
45
1