@mtcute/bun 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,25 +2,27 @@
2
2
  let installed = false;
3
3
  let handled = false;
4
4
  const callbacks = new Set();
5
- function exit(shouldManuallyExit, signal, event) {
6
- return function eventHandler() {
5
+ // eslint-disable-next-line func-call-spacing
6
+ const myHandlers = new Map();
7
+ function register(shouldManuallyExit, signal, event) {
8
+ function eventHandler() {
7
9
  if (handled) {
8
10
  return;
9
11
  }
10
12
  handled = true;
11
- const exitCode = 128 + signal;
12
13
  for (const callback of callbacks) {
13
14
  callback();
14
15
  }
16
+ for (const [event, handler] of myHandlers) {
17
+ process.off(event, handler);
18
+ }
15
19
  if (shouldManuallyExit) {
16
- // if the user has some custom handlers after us, we don't want to exit the process
17
- const listeners = process.rawListeners(event);
18
- const idx = listeners.indexOf(eventHandler);
19
- if (idx === listeners.length - 1) {
20
- process.exit(exitCode);
21
- }
20
+ // send the signal again and let node handle it
21
+ process.kill(process.pid, signal);
22
22
  }
23
- };
23
+ }
24
+ process.on(event, eventHandler);
25
+ myHandlers.set(event, eventHandler);
24
26
  }
25
27
  export function beforeExit(fn) {
26
28
  // unsupported platform
@@ -28,10 +30,10 @@ export function beforeExit(fn) {
28
30
  return () => { };
29
31
  if (!installed) {
30
32
  installed = true;
31
- process.on('beforeExit', exit(true, -128, 'beforeExit'));
32
- process.on('SIGINT', exit(true, 2, 'SIGINT'));
33
- process.on('SIGTERM', exit(true, 15, 'SIGINT'));
34
- process.on('exit', exit(false, 15, 'exit'));
33
+ register(true, 0, 'beforeExit');
34
+ register(true, 2, 'SIGINT');
35
+ register(true, 15, 'SIGTERM');
36
+ register(false, 15, 'exit');
35
37
  }
36
38
  callbacks.add(fn);
37
39
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"exit-hook.js","sourceRoot":"","sources":["../../src/common-internals-node/exit-hook.ts"],"names":[],"mappings":"AAAA,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,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAA;QAC/C,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEjB,OAAO,GAAG,EAAE;QACR,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACxB,CAAC,CAAA;AACL,CAAC","sourcesContent":["// roughly based on https://github.com/sindresorhus/exit-hook/blob/main/index.js, MIT license\n\nlet installed = false\nlet handled = false\n\nconst callbacks = new Set<() => void>()\n\nfunction exit(shouldManuallyExit: boolean, signal: number, event: string) {\n return function eventHandler() {\n if (handled) {\n return\n }\n\n handled = true\n\n const exitCode = 128 + signal\n\n for (const callback of callbacks) {\n callback()\n }\n\n if (shouldManuallyExit) {\n // if the user has some custom handlers after us, we don't want to exit the process\n\n const listeners = process.rawListeners(event)\n const idx = listeners.indexOf(eventHandler)\n\n if (idx === listeners.length - 1) {\n process.exit(exitCode)\n }\n }\n }\n}\n\nexport function beforeExit(fn: () => void): () => void {\n // unsupported platform\n if (typeof process === 'undefined') return () => {}\n\n if (!installed) {\n installed = true\n\n process.on('beforeExit', exit(true, -128, 'beforeExit'))\n process.on('SIGINT', exit(true, 2, 'SIGINT'))\n process.on('SIGTERM', exit(true, 15, 'SIGINT'))\n process.on('exit', exit(false, 15, 'exit'))\n }\n\n callbacks.add(fn)\n\n return () => {\n callbacks.delete(fn)\n }\n}\n"]}
1
+ {"version":3,"file":"exit-hook.js","sourceRoot":"","sources":["../../src/common-internals-node/exit-hook.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAE7F,IAAI,SAAS,GAAG,KAAK,CAAA;AACrB,IAAI,OAAO,GAAG,KAAK,CAAA;AAEnB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;AACvC,6CAA6C;AAC7C,MAAM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QACR,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACxB,CAAC,CAAA;AACL,CAAC","sourcesContent":["// roughly based on https://github.com/sindresorhus/exit-hook/blob/main/index.js, MIT license\n\nlet installed = false\nlet handled = false\n\nconst callbacks = new Set<() => void>()\n// eslint-disable-next-line func-call-spacing\nconst myHandlers = new Map<string, () => void>()\n\nfunction register(shouldManuallyExit: boolean, signal: number, event: string) {\n function eventHandler() {\n if (handled) {\n return\n }\n\n handled = true\n\n for (const callback of callbacks) {\n callback()\n }\n\n for (const [event, handler] of myHandlers) {\n process.off(event, handler)\n }\n\n if (shouldManuallyExit) {\n // send the signal again and let node handle it\n process.kill(process.pid, signal)\n }\n }\n\n process.on(event, eventHandler)\n myHandlers.set(event, eventHandler)\n}\n\nexport function beforeExit(fn: () => void): () => void {\n // unsupported platform\n if (typeof process === 'undefined') return () => {}\n\n if (!installed) {\n installed = true\n\n register(true, 0, 'beforeExit')\n register(true, 2, 'SIGINT')\n register(true, 15, 'SIGTERM')\n register(false, 15, 'exit')\n }\n\n callbacks.add(fn)\n\n return () => {\n callbacks.delete(fn)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtcute/bun",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "Meta-package for Bun",
5
5
  "author": "alina sireneva <alina@tei.su>",
6
6
  "license": "MIT",
@@ -12,9 +12,14 @@
12
12
  "./utils.js": "./utils.js"
13
13
  },
14
14
  "dependencies": {
15
- "@mtcute/core": "^0.14.0",
16
- "@mtcute/wasm": "^0.14.0",
17
- "@mtcute/markdown-parser": "^0.14.0",
18
- "@mtcute/html-parser": "^0.14.0"
15
+ "@mtcute/core": "^0.16.0",
16
+ "@mtcute/wasm": "^0.16.0",
17
+ "@mtcute/markdown-parser": "^0.16.0",
18
+ "@mtcute/html-parser": "^0.16.0"
19
+ },
20
+ "homepage": "https://mtcute.dev",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/mtcute/mtcute"
19
24
  }
20
25
  }