initial commit
This commit is contained in:
2
node_modules/when-exit/dist/browser/index.d.ts
generated
vendored
Normal file
2
node_modules/when-exit/dist/browser/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const whenExit: (callback: import("../types.js").Callback) => import("../types.js").Disposer;
|
||||
export default whenExit;
|
||||
6
node_modules/when-exit/dist/browser/index.js
generated
vendored
Normal file
6
node_modules/when-exit/dist/browser/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/* IMPORT */
|
||||
import Interceptor from './interceptor.js';
|
||||
/* MAIN */
|
||||
const whenExit = Interceptor.register;
|
||||
/* EXPORT */
|
||||
export default whenExit;
|
||||
10
node_modules/when-exit/dist/browser/interceptor.d.ts
generated
vendored
Normal file
10
node_modules/when-exit/dist/browser/interceptor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { Callback, Disposer } from '../types.js';
|
||||
declare class Interceptor {
|
||||
private callbacks;
|
||||
constructor();
|
||||
exit: () => void;
|
||||
hook: () => void;
|
||||
register: (callback: Callback) => Disposer;
|
||||
}
|
||||
declare const _default: Interceptor;
|
||||
export default _default;
|
||||
27
node_modules/when-exit/dist/browser/interceptor.js
generated
vendored
Normal file
27
node_modules/when-exit/dist/browser/interceptor.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/* IMPORT */
|
||||
/* MAIN */
|
||||
class Interceptor {
|
||||
/* CONSTRUCTOR */
|
||||
constructor() {
|
||||
/* VARIABLES */
|
||||
this.callbacks = new Set();
|
||||
/* API */
|
||||
this.exit = () => {
|
||||
for (const callback of this.callbacks) {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
this.hook = () => {
|
||||
window.addEventListener('beforeunload', this.exit);
|
||||
};
|
||||
this.register = (callback) => {
|
||||
this.callbacks.add(callback);
|
||||
return () => {
|
||||
this.callbacks.delete(callback);
|
||||
};
|
||||
};
|
||||
this.hook();
|
||||
}
|
||||
}
|
||||
/* EXPORT */
|
||||
export default new Interceptor();
|
||||
3
node_modules/when-exit/dist/node/constants.d.ts
generated
vendored
Normal file
3
node_modules/when-exit/dist/node/constants.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const IS_LINUX: boolean;
|
||||
declare const IS_WINDOWS: boolean;
|
||||
export { IS_LINUX, IS_WINDOWS };
|
||||
7
node_modules/when-exit/dist/node/constants.js
generated
vendored
Normal file
7
node_modules/when-exit/dist/node/constants.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/* IMPORT */
|
||||
import process from 'node:process';
|
||||
/* MAIN */
|
||||
const IS_LINUX = (process.platform === 'linux');
|
||||
const IS_WINDOWS = (process.platform === 'win32');
|
||||
/* EXPORT */
|
||||
export { IS_LINUX, IS_WINDOWS };
|
||||
2
node_modules/when-exit/dist/node/index.d.ts
generated
vendored
Normal file
2
node_modules/when-exit/dist/node/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const whenExit: (callback: import("../types.js").Callback) => import("../types.js").Disposer;
|
||||
export default whenExit;
|
||||
6
node_modules/when-exit/dist/node/index.js
generated
vendored
Normal file
6
node_modules/when-exit/dist/node/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/* IMPORT */
|
||||
import Interceptor from './interceptor.js';
|
||||
/* MAIN */
|
||||
const whenExit = Interceptor.register;
|
||||
/* EXPORT */
|
||||
export default whenExit;
|
||||
11
node_modules/when-exit/dist/node/interceptor.d.ts
generated
vendored
Normal file
11
node_modules/when-exit/dist/node/interceptor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { Callback, Disposer } from '../types.js';
|
||||
declare class Interceptor {
|
||||
private callbacks;
|
||||
private exited;
|
||||
constructor();
|
||||
exit: (signal?: string) => void;
|
||||
hook: () => void;
|
||||
register: (callback: Callback) => Disposer;
|
||||
}
|
||||
declare const _default: Interceptor;
|
||||
export default _default;
|
||||
50
node_modules/when-exit/dist/node/interceptor.js
generated
vendored
Normal file
50
node_modules/when-exit/dist/node/interceptor.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/* IMPORT */
|
||||
import process from 'node:process';
|
||||
import { IS_WINDOWS } from './constants.js';
|
||||
import Signals from './signals.js';
|
||||
/* MAIN */
|
||||
class Interceptor {
|
||||
/* CONSTRUCTOR */
|
||||
constructor() {
|
||||
/* VARIABLES */
|
||||
this.callbacks = new Set();
|
||||
this.exited = false;
|
||||
/* API */
|
||||
this.exit = (signal) => {
|
||||
if (this.exited)
|
||||
return;
|
||||
this.exited = true;
|
||||
for (const callback of this.callbacks) {
|
||||
callback();
|
||||
}
|
||||
if (signal) {
|
||||
if (IS_WINDOWS && (signal !== 'SIGINT' && signal !== 'SIGTERM' && signal !== 'SIGKILL')) { // Windows doesn't support POSIX signals, but Node emulates these 3 signals for us
|
||||
process.kill(process.pid, 'SIGTERM');
|
||||
}
|
||||
else {
|
||||
process.kill(process.pid, signal);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.hook = () => {
|
||||
process.once('exit', () => this.exit());
|
||||
for (const signal of Signals) {
|
||||
try {
|
||||
process.once(signal, () => this.exit(signal));
|
||||
}
|
||||
catch {
|
||||
// Sometimes "process.once" can throw...
|
||||
}
|
||||
}
|
||||
};
|
||||
this.register = (callback) => {
|
||||
this.callbacks.add(callback);
|
||||
return () => {
|
||||
this.callbacks.delete(callback);
|
||||
};
|
||||
};
|
||||
this.hook();
|
||||
}
|
||||
}
|
||||
/* EXPORT */
|
||||
export default new Interceptor();
|
||||
2
node_modules/when-exit/dist/node/signals.d.ts
generated
vendored
Normal file
2
node_modules/when-exit/dist/node/signals.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare const Signals: string[];
|
||||
export default Signals;
|
||||
13
node_modules/when-exit/dist/node/signals.js
generated
vendored
Normal file
13
node_modules/when-exit/dist/node/signals.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
/* IMPORT */
|
||||
import { IS_LINUX, IS_WINDOWS } from './constants.js';
|
||||
/* MAIN */
|
||||
//URL: https://github.com/tapjs/signal-exit/blob/03dd77a96caa309c6a02c59274d58c812a2dce45/signals.js
|
||||
const Signals = ['SIGABRT', 'SIGALRM', 'SIGHUP', 'SIGINT', 'SIGTERM'];
|
||||
if (!IS_WINDOWS) {
|
||||
Signals.push('SIGVTALRM', 'SIGXCPU', 'SIGXFSZ', 'SIGUSR2', 'SIGTRAP', 'SIGSYS', 'SIGQUIT', 'SIGIOT');
|
||||
}
|
||||
if (IS_LINUX) {
|
||||
Signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT', 'SIGUNUSED');
|
||||
}
|
||||
/* EXPORT */
|
||||
export default Signals;
|
||||
3
node_modules/when-exit/dist/types.d.ts
generated
vendored
Normal file
3
node_modules/when-exit/dist/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type Callback = () => void;
|
||||
type Disposer = () => void;
|
||||
export type { Callback, Disposer };
|
||||
2
node_modules/when-exit/dist/types.js
generated
vendored
Normal file
2
node_modules/when-exit/dist/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/* MAIN */
|
||||
export {};
|
||||
Reference in New Issue
Block a user