@agoric/internal 0.2.2-dev-2e05748.0 → 0.2.2-dev-316deca.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/internal",
3
- "version": "0.2.2-dev-2e05748.0+2e05748",
3
+ "version": "0.2.2-dev-316deca.0+316deca",
4
4
  "description": "Externally unsupported utilities internal to agoric-sdk",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -20,10 +20,11 @@
20
20
  "lint:types": "tsc -p jsconfig.json"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/zone": "0.1.1-dev-2e05748.0+2e05748",
23
+ "@agoric/zone": "0.1.1-dev-316deca.0+316deca",
24
24
  "@endo/far": "^0.2.14",
25
25
  "@endo/marshal": "^0.8.1",
26
26
  "@endo/promise-kit": "^0.2.52",
27
+ "anylogger": "^0.21.0",
27
28
  "jessie.js": "^0.3.2"
28
29
  },
29
30
  "devDependencies": {
@@ -38,5 +39,5 @@
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
41
- "gitHead": "2e05748a0237e6e08fdbdfc2ce25f009a7e45286"
42
+ "gitHead": "316decacf1abd1378459c40da658373d57cfba50"
42
43
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBundles.d.ts","sourceRoot":"","sources":["createBundles.js"],"names":[],"mappings":"AAUO,6EAyBN;AAEM,mFAMN;AAEM,iGAkCN"}
@@ -1,3 +1,5 @@
1
+ // Use modules not prefixed with `node:` since some deploy scripts may
2
+ // still be running in esm emulation
1
3
  import path from 'path';
2
4
  import { spawnSync } from 'child_process';
3
5
  import { createRequire } from 'module';
@@ -1,6 +1,6 @@
1
1
  import { createWriteStream } from 'node:fs';
2
2
  import { open } from 'node:fs/promises';
3
- import { makeAggregateError } from './utils.js';
3
+ import { makeAggregateError } from '../utils.js';
4
4
 
5
5
  /**
6
6
  * @param {import("fs").ReadStream | import("fs").WriteStream} stream
@@ -0,0 +1,6 @@
1
+ export function makeFreshShutdown(verbose?: boolean): {
2
+ registerShutdown: (thunk: any) => () => void;
3
+ };
4
+ export function makeCachedShutdown(...args: any[]): any;
5
+ export { makeCachedShutdown as makeShutdown };
6
+ //# sourceMappingURL=shutdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["shutdown.js"],"names":[],"mappings":"AAKO;;EAqDN;AAGM,wDAON"}
@@ -0,0 +1,71 @@
1
+ import process from 'node:process';
2
+ import anylogger from 'anylogger';
3
+
4
+ const console = anylogger('shutdown');
5
+
6
+ export const makeFreshShutdown = (verbose = true) => {
7
+ const shutdownThunks = new Set();
8
+
9
+ let shuttingDown = false;
10
+ /** @type {NodeJS.SignalsListener & NodeJS.BeforeExitListener} */
11
+ const shutdown = code => {
12
+ const sig = typeof code === 'string' && code.startsWith('SIG');
13
+ if (sig) {
14
+ process.exitCode = 98;
15
+ }
16
+ if (shuttingDown) {
17
+ return;
18
+ }
19
+ shuttingDown = true;
20
+ // Allow an explicit exit to terminate the process.
21
+ process.off('beforeExit', shutdown);
22
+ process.off('SIGINT', shutdown);
23
+ process.off('SIGTERM', shutdown);
24
+ verbose && console.error(`Shutting down cleanly...`);
25
+ const shutdowners = [...shutdownThunks.keys()];
26
+ shutdownThunks.clear();
27
+ Promise.allSettled([...shutdowners].map(t => Promise.resolve().then(t)))
28
+ .then(statuses => {
29
+ for (const status of statuses) {
30
+ if (status.status === 'rejected') {
31
+ verbose && console.warn(status.reason);
32
+ }
33
+ }
34
+ verbose && console.warn('Process terminated!');
35
+ })
36
+ .catch(error => verbose && console.warn('Error shutting down', error))
37
+ .finally(() => {
38
+ process.exit();
39
+ });
40
+ };
41
+
42
+ // gracefully shut down the thunks on process exit
43
+ process.on('SIGTERM', shutdown);
44
+ process.on('SIGINT', shutdown);
45
+ process.on('beforeExit', shutdown);
46
+ process.on('uncaughtException', e => {
47
+ console.error(e);
48
+ shutdown(-1);
49
+ });
50
+
51
+ return {
52
+ registerShutdown: thunk => {
53
+ shutdownThunks.add(thunk);
54
+ return () => {
55
+ shutdownThunks.delete(thunk);
56
+ };
57
+ },
58
+ };
59
+ };
60
+
61
+ let cachedShutdown = null;
62
+ export const makeCachedShutdown = (...args) => {
63
+ // It's possible our caller has specified different arguments.
64
+ // Since they control verbosity only, first-one-wins is acceptable.
65
+ if (!cachedShutdown) {
66
+ cachedShutdown = makeFreshShutdown(...args);
67
+ }
68
+ return cachedShutdown;
69
+ };
70
+
71
+ export { makeCachedShutdown as makeShutdown };
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBundles.d.ts","sourceRoot":"","sources":["createBundles.js"],"names":[],"mappings":"AAQO,6EAyBN;AAEM,mFAMN;AAEM,iGAkCN"}
File without changes