@notionhq/custom-blocks-dev-shell 0.1.37 → 0.1.39
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/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Workers local shell</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-F7t8rjQ8.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-DpKdfNws.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
@@ -17,7 +17,7 @@ export class ProcessSupervisor {
|
|
|
17
17
|
}
|
|
18
18
|
addResource(resource) {
|
|
19
19
|
if (this.shuttingDown) {
|
|
20
|
-
closeResource(resource);
|
|
20
|
+
void closeResource(resource);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
this.resources.push(resource);
|
|
@@ -49,7 +49,11 @@ export class ProcessSupervisor {
|
|
|
49
49
|
this.shutdown("SIGTERM");
|
|
50
50
|
});
|
|
51
51
|
proc.on("exit", code => {
|
|
52
|
-
|
|
52
|
+
// Retain an unexpectedly failed process until cleanup. Its PID may
|
|
53
|
+
// still identify a detached process group with live descendants.
|
|
54
|
+
if (!this.shuttingDown && (code === 0 || code === null)) {
|
|
55
|
+
this.processes.delete(proc);
|
|
56
|
+
}
|
|
53
57
|
if (this.shuttingDown || code === 0 || code === null) {
|
|
54
58
|
return;
|
|
55
59
|
}
|
|
@@ -61,6 +65,9 @@ export class ProcessSupervisor {
|
|
|
61
65
|
}
|
|
62
66
|
shutdown(signal) {
|
|
63
67
|
if (this.shuttingDown) {
|
|
68
|
+
if (signal !== "exit") {
|
|
69
|
+
this.forceShutdown();
|
|
70
|
+
}
|
|
64
71
|
return;
|
|
65
72
|
}
|
|
66
73
|
this.shuttingDown = true;
|
|
@@ -68,44 +75,82 @@ export class ProcessSupervisor {
|
|
|
68
75
|
(this.processes.size > 0 || this.resources.length > 0)) {
|
|
69
76
|
console.log(`\n${dim}Shutting down...${reset}`);
|
|
70
77
|
}
|
|
71
|
-
for (const resource of this.resources) {
|
|
72
|
-
closeResource(resource);
|
|
73
|
-
}
|
|
74
78
|
for (const [proc, detached] of this.processes) {
|
|
75
79
|
killProcess(proc, detached, "SIGTERM");
|
|
76
80
|
}
|
|
77
81
|
if (signal === "exit") {
|
|
82
|
+
for (const resource of this.resources) {
|
|
83
|
+
void closeResource(resource);
|
|
84
|
+
}
|
|
78
85
|
return;
|
|
79
86
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
void this.finishShutdown();
|
|
88
|
+
}
|
|
89
|
+
async finishShutdown() {
|
|
90
|
+
const resourceCleanup = Promise.all(this.resources.map(resource => closeResource(resource)));
|
|
91
|
+
const processCleanup = Promise.all([...this.processes.keys()].map(proc => waitForExit(proc)));
|
|
92
|
+
let finished = false;
|
|
93
|
+
await Promise.race([
|
|
94
|
+
Promise.all([resourceCleanup, processCleanup]).then(() => {
|
|
95
|
+
finished = true;
|
|
96
|
+
}),
|
|
97
|
+
delay(SHUTDOWN_GRACE_MS),
|
|
98
|
+
]);
|
|
99
|
+
if (!finished) {
|
|
100
|
+
this.forceShutdown();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// A process can exit before its descendants do. Re-signal every
|
|
104
|
+
// remaining process group even after the direct child has exited.
|
|
105
|
+
this.forceKillProcesses();
|
|
106
|
+
process.exit(process.exitCode ?? 0);
|
|
107
|
+
}
|
|
108
|
+
forceShutdown() {
|
|
109
|
+
this.forceKillProcesses();
|
|
110
|
+
process.exit(process.exitCode ?? 130);
|
|
111
|
+
}
|
|
112
|
+
forceKillProcesses() {
|
|
113
|
+
for (const [proc, detached] of this.processes) {
|
|
114
|
+
killProcess(proc, detached, "SIGKILL", true);
|
|
115
|
+
}
|
|
87
116
|
}
|
|
88
117
|
}
|
|
89
|
-
function closeResource(resource) {
|
|
118
|
+
async function closeResource(resource) {
|
|
90
119
|
try {
|
|
91
|
-
resource();
|
|
120
|
+
await resource();
|
|
92
121
|
}
|
|
93
122
|
catch { }
|
|
94
123
|
}
|
|
95
|
-
function killProcess(proc, detached, signal) {
|
|
96
|
-
|
|
124
|
+
function killProcess(proc, detached, signal, force = false) {
|
|
125
|
+
const pid = proc.pid;
|
|
126
|
+
if (pid === undefined) {
|
|
97
127
|
return;
|
|
98
128
|
}
|
|
99
129
|
try {
|
|
100
130
|
if (detached && process.platform !== "win32") {
|
|
101
|
-
process.kill(-
|
|
131
|
+
process.kill(-pid, signal);
|
|
132
|
+
return;
|
|
102
133
|
}
|
|
103
|
-
|
|
134
|
+
if (force || isProcessRunning(proc)) {
|
|
104
135
|
proc.kill(signal);
|
|
105
136
|
}
|
|
106
137
|
}
|
|
107
138
|
catch { }
|
|
108
139
|
}
|
|
140
|
+
function isProcessRunning(proc) {
|
|
141
|
+
return proc.exitCode === null && proc.signalCode === null;
|
|
142
|
+
}
|
|
143
|
+
function waitForExit(proc) {
|
|
144
|
+
if (proc.exitCode !== null || proc.signalCode !== null) {
|
|
145
|
+
return Promise.resolve();
|
|
146
|
+
}
|
|
147
|
+
return new Promise(resolve => {
|
|
148
|
+
proc.once("exit", () => resolve());
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function delay(milliseconds) {
|
|
152
|
+
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
|
153
|
+
}
|
|
109
154
|
export function installProcessSignalHandlers(run) {
|
|
110
155
|
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
111
156
|
process.on(signal, () => run.shutdown(signal));
|
|
@@ -51,7 +51,11 @@ const createShellLaunch = async ({ args, plan, log }) => {
|
|
|
51
51
|
}
|
|
52
52
|
return {
|
|
53
53
|
processes: [],
|
|
54
|
-
resources: [
|
|
54
|
+
resources: [
|
|
55
|
+
() => new Promise(resolve => {
|
|
56
|
+
server.close(() => resolve());
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
55
59
|
};
|
|
56
60
|
};
|
|
57
61
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/custom-blocks-dev-shell",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
4
4
|
"description": "Local preview shell for Notion custom block workers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,17 +34,19 @@
|
|
|
34
34
|
"@types/react": "^19.2.14",
|
|
35
35
|
"@types/react-dom": "^19.2.3",
|
|
36
36
|
"@vitejs/plugin-react": "^6.0.1",
|
|
37
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
37
38
|
"tailwindcss": "^4.2.4",
|
|
38
39
|
"typescript": "^6.0.3",
|
|
39
40
|
"vite": "^8.0.10",
|
|
40
|
-
"vitest": "^4.1.
|
|
41
|
-
"@notionhq/custom-blocks-
|
|
42
|
-
"@notionhq/custom-blocks-
|
|
41
|
+
"vitest": "^4.1.11",
|
|
42
|
+
"@notionhq/custom-blocks-host": "0.0.0",
|
|
43
|
+
"@notionhq/custom-blocks-protocol": "0.1.0"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"dev": "vite",
|
|
46
47
|
"build": "vite build && tsc --project cli/tsconfig.build.json",
|
|
47
48
|
"test": "vitest run",
|
|
49
|
+
"test:coverage": "vitest run --coverage --coverage.provider=v8 --coverage.reporter=json",
|
|
48
50
|
"typecheck": "tsc --project tsconfig.json && tsc --project cli/tsconfig.json"
|
|
49
51
|
}
|
|
50
52
|
}
|