quidproquo-cli 0.1.18 → 0.1.20
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/README.md +1 -0
- package/lib/commonjs/cli/commandRegistry.js +6 -0
- package/lib/commonjs/cli/commandRegistry.js.map +1 -1
- package/lib/commonjs/commands/goDevApi.js +54 -8
- package/lib/commonjs/commands/goDevApi.js.map +1 -1
- package/lib/commonjs/commands/goDevWeb.js +10 -2
- package/lib/commonjs/commands/goDevWeb.js.map +1 -1
- package/lib/commonjs/commands/setup.d.ts +1 -0
- package/lib/commonjs/commands/setup.js +102 -0
- package/lib/commonjs/commands/setup.js.map +1 -0
- package/lib/commonjs/lib/args.d.ts +1 -0
- package/lib/commonjs/lib/args.js +11 -1
- package/lib/commonjs/lib/args.js.map +1 -1
- package/lib/commonjs/lib/keepOtherDevServersFlag.d.ts +1 -0
- package/lib/commonjs/lib/keepOtherDevServersFlag.js +11 -0
- package/lib/commonjs/lib/keepOtherDevServersFlag.js.map +1 -0
- package/lib/commonjs/lib/killChildWithEscalation.d.ts +10 -0
- package/lib/commonjs/lib/killChildWithEscalation.js +33 -0
- package/lib/commonjs/lib/killChildWithEscalation.js.map +1 -0
- package/lib/commonjs/lib/killStaleListeners.d.ts +14 -0
- package/lib/commonjs/lib/killStaleListeners.js +74 -24
- package/lib/commonjs/lib/killStaleListeners.js.map +1 -1
- package/lib/commonjs/lib/prompts.d.ts +2 -0
- package/lib/commonjs/lib/prompts.js +1 -1
- package/lib/commonjs/lib/prompts.js.map +1 -1
- package/lib/commonjs/lib/setupStep.d.ts +16 -0
- package/lib/commonjs/lib/setupStep.js +3 -0
- package/lib/commonjs/lib/setupStep.js.map +1 -0
- package/lib/commonjs/platforms/aws/index.js +2 -0
- package/lib/commonjs/platforms/aws/index.js.map +1 -1
- package/lib/commonjs/platforms/aws/setup/awsSetupContext.d.ts +12 -0
- package/lib/commonjs/platforms/aws/setup/awsSetupContext.js +23 -0
- package/lib/commonjs/platforms/aws/setup/awsSetupContext.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/awsSetupSteps.d.ts +8 -0
- package/lib/commonjs/platforms/aws/setup/awsSetupSteps.js +44 -0
- package/lib/commonjs/platforms/aws/setup/awsSetupSteps.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildBucketNamesStep.d.ts +4 -0
- package/lib/commonjs/platforms/aws/setup/buildBucketNamesStep.js +77 -0
- package/lib/commonjs/platforms/aws/setup/buildBucketNamesStep.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildCdkBootstrapSteps.d.ts +5 -0
- package/lib/commonjs/platforms/aws/setup/buildCdkBootstrapSteps.js +38 -0
- package/lib/commonjs/platforms/aws/setup/buildCdkBootstrapSteps.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildGithubDeployRoleStep.d.ts +4 -0
- package/lib/commonjs/platforms/aws/setup/buildGithubDeployRoleStep.js +55 -0
- package/lib/commonjs/platforms/aws/setup/buildGithubDeployRoleStep.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildGithubOidcProviderStep.d.ts +4 -0
- package/lib/commonjs/platforms/aws/setup/buildGithubOidcProviderStep.js +54 -0
- package/lib/commonjs/platforms/aws/setup/buildGithubOidcProviderStep.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildHostedZonesStep.d.ts +4 -0
- package/lib/commonjs/platforms/aws/setup/buildHostedZonesStep.js +63 -0
- package/lib/commonjs/platforms/aws/setup/buildHostedZonesStep.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildIamCapabilityStep.d.ts +4 -0
- package/lib/commonjs/platforms/aws/setup/buildIamCapabilityStep.js +48 -0
- package/lib/commonjs/platforms/aws/setup/buildIamCapabilityStep.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildIdentityStep.d.ts +4 -0
- package/lib/commonjs/platforms/aws/setup/buildIdentityStep.js +39 -0
- package/lib/commonjs/platforms/aws/setup/buildIdentityStep.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/buildStackSteps.d.ts +5 -0
- package/lib/commonjs/platforms/aws/setup/buildStackSteps.js +32 -0
- package/lib/commonjs/platforms/aws/setup/buildStackSteps.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/describeStackStatus.d.ts +4 -0
- package/lib/commonjs/platforms/aws/setup/describeStackStatus.js +32 -0
- package/lib/commonjs/platforms/aws/setup/describeStackStatus.js.map +1 -0
- package/lib/commonjs/platforms/aws/setup/index.d.ts +1 -0
- package/lib/commonjs/platforms/aws/setup/index.js +18 -0
- package/lib/commonjs/platforms/aws/setup/index.js.map +1 -0
- package/lib/commonjs/platforms/types.d.ts +2 -0
- package/lib/commonjs/platforms/types.js.map +1 -1
- package/lib/esm/cli/commandRegistry.js +6 -0
- package/lib/esm/cli/commandRegistry.js.map +1 -1
- package/lib/esm/commands/goDevApi.js +55 -9
- package/lib/esm/commands/goDevApi.js.map +1 -1
- package/lib/esm/commands/goDevWeb.js +10 -2
- package/lib/esm/commands/goDevWeb.js.map +1 -1
- package/lib/esm/commands/setup.d.ts +1 -0
- package/lib/esm/commands/setup.js +88 -0
- package/lib/esm/commands/setup.js.map +1 -0
- package/lib/esm/lib/args.d.ts +1 -0
- package/lib/esm/lib/args.js +9 -0
- package/lib/esm/lib/args.js.map +1 -1
- package/lib/esm/lib/keepOtherDevServersFlag.d.ts +1 -0
- package/lib/esm/lib/keepOtherDevServersFlag.js +8 -0
- package/lib/esm/lib/keepOtherDevServersFlag.js.map +1 -0
- package/lib/esm/lib/killChildWithEscalation.d.ts +10 -0
- package/lib/esm/lib/killChildWithEscalation.js +29 -0
- package/lib/esm/lib/killChildWithEscalation.js.map +1 -0
- package/lib/esm/lib/killStaleListeners.d.ts +14 -0
- package/lib/esm/lib/killStaleListeners.js +72 -23
- package/lib/esm/lib/killStaleListeners.js.map +1 -1
- package/lib/esm/lib/prompts.d.ts +2 -0
- package/lib/esm/lib/prompts.js +1 -1
- package/lib/esm/lib/prompts.js.map +1 -1
- package/lib/esm/lib/setupStep.d.ts +16 -0
- package/lib/esm/lib/setupStep.js +2 -0
- package/lib/esm/lib/setupStep.js.map +1 -0
- package/lib/esm/platforms/aws/index.js +2 -0
- package/lib/esm/platforms/aws/index.js.map +1 -1
- package/lib/esm/platforms/aws/setup/awsSetupContext.d.ts +12 -0
- package/lib/esm/platforms/aws/setup/awsSetupContext.js +18 -0
- package/lib/esm/platforms/aws/setup/awsSetupContext.js.map +1 -0
- package/lib/esm/platforms/aws/setup/awsSetupSteps.d.ts +8 -0
- package/lib/esm/platforms/aws/setup/awsSetupSteps.js +31 -0
- package/lib/esm/platforms/aws/setup/awsSetupSteps.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildBucketNamesStep.d.ts +4 -0
- package/lib/esm/platforms/aws/setup/buildBucketNamesStep.js +62 -0
- package/lib/esm/platforms/aws/setup/buildBucketNamesStep.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildCdkBootstrapSteps.d.ts +5 -0
- package/lib/esm/platforms/aws/setup/buildCdkBootstrapSteps.js +24 -0
- package/lib/esm/platforms/aws/setup/buildCdkBootstrapSteps.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildGithubDeployRoleStep.d.ts +4 -0
- package/lib/esm/platforms/aws/setup/buildGithubDeployRoleStep.js +40 -0
- package/lib/esm/platforms/aws/setup/buildGithubDeployRoleStep.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildGithubOidcProviderStep.d.ts +4 -0
- package/lib/esm/platforms/aws/setup/buildGithubOidcProviderStep.js +40 -0
- package/lib/esm/platforms/aws/setup/buildGithubOidcProviderStep.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildHostedZonesStep.d.ts +4 -0
- package/lib/esm/platforms/aws/setup/buildHostedZonesStep.js +49 -0
- package/lib/esm/platforms/aws/setup/buildHostedZonesStep.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildIamCapabilityStep.d.ts +4 -0
- package/lib/esm/platforms/aws/setup/buildIamCapabilityStep.js +34 -0
- package/lib/esm/platforms/aws/setup/buildIamCapabilityStep.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildIdentityStep.d.ts +4 -0
- package/lib/esm/platforms/aws/setup/buildIdentityStep.js +26 -0
- package/lib/esm/platforms/aws/setup/buildIdentityStep.js.map +1 -0
- package/lib/esm/platforms/aws/setup/buildStackSteps.d.ts +5 -0
- package/lib/esm/platforms/aws/setup/buildStackSteps.js +17 -0
- package/lib/esm/platforms/aws/setup/buildStackSteps.js.map +1 -0
- package/lib/esm/platforms/aws/setup/describeStackStatus.d.ts +4 -0
- package/lib/esm/platforms/aws/setup/describeStackStatus.js +17 -0
- package/lib/esm/platforms/aws/setup/describeStackStatus.js.map +1 -0
- package/lib/esm/platforms/aws/setup/index.d.ts +1 -0
- package/lib/esm/platforms/aws/setup/index.js +2 -0
- package/lib/esm/platforms/aws/setup/index.js.map +1 -0
- package/lib/esm/platforms/types.d.ts +2 -0
- package/lib/esm/platforms/types.js.map +1 -1
- package/package.json +13 -10
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
// generates the dev-server entry, builds the rspack config, then runs rspack
|
|
3
3
|
// in watch mode, restarting the server process on every successful rebuild.
|
|
4
4
|
//
|
|
5
|
+
// A restart is not instant: the server drains in-flight work and checkpoints
|
|
6
|
+
// its stores on the way out (typically tens of ms, 5s worst case), and this
|
|
7
|
+
// command waits for that before starting the replacement.
|
|
8
|
+
//
|
|
5
9
|
// The one thing NOT hot-reloaded is the qpq configs themselves: each service's
|
|
6
10
|
// infrastructure.ts is evaluated once at launch and baked into the
|
|
7
11
|
// `quidproquo-dynamic-loader` virtual module — config changes need a full
|
|
@@ -10,10 +14,13 @@ import { getAppServiceQpqConfigs, getDevServerRspackConfig } from 'quidproquo-de
|
|
|
10
14
|
import { spawn } from 'child_process';
|
|
11
15
|
import path from 'path';
|
|
12
16
|
import { rspack } from '@rspack/core';
|
|
17
|
+
import { hasArgFlag } from '../lib/args';
|
|
13
18
|
import { primeDeployEnvFromConfig } from '../lib/deployEnv';
|
|
14
19
|
import { writeDevServerEntry } from '../lib/devServerEntry';
|
|
15
20
|
import { getRoot } from '../lib/discovery';
|
|
16
|
-
import {
|
|
21
|
+
import { KEEP_OTHER_DEV_SERVERS_FLAG } from '../lib/keepOtherDevServersFlag';
|
|
22
|
+
import { killChildWithEscalation } from '../lib/killChildWithEscalation';
|
|
23
|
+
import { killOtherQpqDevProcesses, killStaleListeners, reportPortHolders } from '../lib/killStaleListeners';
|
|
17
24
|
import { resolveAppSelection } from '../lib/resolveAppSelection';
|
|
18
25
|
// 8080/8888 are set in the generated entry; 3001 is the quidproquo-dev-server
|
|
19
26
|
// file-storage (secure URL) default port.
|
|
@@ -25,11 +32,22 @@ export const goDevApiCommand = async (argv) => {
|
|
|
25
32
|
process.env.QPQ_DEV_APP = appName;
|
|
26
33
|
primeDeployEnvFromConfig(appName);
|
|
27
34
|
console.log(`Dev server for app [${appName}]`);
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
// The sweep matches on a RELATIVE bundle path, so every checkout's dev
|
|
36
|
+
// server looks like ours and a sibling worktree gets taken down with it.
|
|
37
|
+
// Opting out spares it, at the cost of this one not starting: the ports are
|
|
38
|
+
// the same either way, so what you get instead is EADDRINUSE. Report who
|
|
39
|
+
// holds them, or that failure says nothing about the cause.
|
|
40
|
+
if (hasArgFlag(argv, KEEP_OTHER_DEV_SERVERS_FLAG)) {
|
|
41
|
+
console.log(`${KEEP_OTHER_DEV_SERVERS_FLAG}: leaving other dev servers alone.`);
|
|
42
|
+
reportPortHolders(DEV_SERVER_PORTS);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// Catches a lingering watcher from a previous run even if its spawned
|
|
46
|
+
// child already exited (see killOtherQpqDevProcesses) — then the usual
|
|
47
|
+
// port-based sweep for anything else still bound to our ports.
|
|
48
|
+
killOtherQpqDevProcesses(root);
|
|
49
|
+
killStaleListeners(DEV_SERVER_PORTS, (command) => command.includes(DEV_SERVER_BUNDLE_PATH));
|
|
50
|
+
}
|
|
33
51
|
const qpqConfigs = getAppServiceQpqConfigs(root, appName);
|
|
34
52
|
const entry = writeDevServerEntry(root, appName);
|
|
35
53
|
const rspackConfig = getDevServerRspackConfig({ root, entry, qpqConfigs });
|
|
@@ -61,7 +79,10 @@ export const goDevApiCommand = async (argv) => {
|
|
|
61
79
|
restartQueued = false;
|
|
62
80
|
startServer();
|
|
63
81
|
});
|
|
64
|
-
|
|
82
|
+
// Not a bare kill: the server drains in-flight work before it exits, so it
|
|
83
|
+
// needs asking properly and then a hard backstop if it wedges. Waiting for
|
|
84
|
+
// the exit is what keeps the ports free for the replacement.
|
|
85
|
+
void killChildWithEscalation(child);
|
|
65
86
|
};
|
|
66
87
|
console.log('Bundling dev server (watch mode)...');
|
|
67
88
|
let lastHash;
|
|
@@ -85,10 +106,35 @@ export const goDevApiCommand = async (argv) => {
|
|
|
85
106
|
console.log(child ? 'Rebuilt. Restarting dev server...' : 'Dev server bundled. Starting...');
|
|
86
107
|
restartServer();
|
|
87
108
|
});
|
|
88
|
-
|
|
109
|
+
// Wait for the server to finish draining before tearing the watcher down and
|
|
110
|
+
// exiting: closing the compiler first would exit the parent while the child
|
|
111
|
+
// is still writing, which is the race this whole path exists to close.
|
|
112
|
+
//
|
|
113
|
+
// SIGTERM as well as SIGINT, and it is load-bearing rather than symmetry for
|
|
114
|
+
// its own sake. This process is a WRAPPER: the dev server that handles
|
|
115
|
+
// signals and drains its work is the child it spawned. Without a handler
|
|
116
|
+
// here, SIGTERM (what `docker stop` sends, and what any script stopping this
|
|
117
|
+
// programmatically sends) kills the wrapper outright on the default
|
|
118
|
+
// disposition, the child never gets asked to stop, and every guarantee the
|
|
119
|
+
// dev server's shutdown sequence makes is bypassed. go:dev:web already
|
|
120
|
+
// handles both.
|
|
121
|
+
let shuttingDown = false;
|
|
122
|
+
const handleShutdownSignal = async () => {
|
|
123
|
+
if (shuttingDown) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
shuttingDown = true;
|
|
89
127
|
restartQueued = true; // suppress the crash log / rebuild-restart on our own kill
|
|
90
|
-
child
|
|
128
|
+
if (child) {
|
|
129
|
+
await killChildWithEscalation(child);
|
|
130
|
+
}
|
|
91
131
|
compiler.close(() => process.exit(0));
|
|
132
|
+
};
|
|
133
|
+
process.on('SIGINT', () => {
|
|
134
|
+
void handleShutdownSignal();
|
|
135
|
+
});
|
|
136
|
+
process.on('SIGTERM', () => {
|
|
137
|
+
void handleShutdownSignal();
|
|
92
138
|
});
|
|
93
139
|
};
|
|
94
140
|
//# sourceMappingURL=goDevApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goDevApi.js","sourceRoot":"","sources":["../../../src/commands/goDevApi.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,6EAA6E;AAC7E,4EAA4E;AAC5E,EAAE;AACF,+EAA+E;AAC/E,mEAAmE;AACnE,0EAA0E;AAC1E,wBAAwB;AACxB,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAE7F,OAAO,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,8EAA8E;AAC9E,0CAA0C;AAC1C,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,C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AAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YAC/E,OAAO,CAAC,GAAG,CAAC,wEAAwE,CAAC,CAAC;YACtF,OAAO;QACT,CAAC;QACD,2EAA2E;QAC3E,2DAA2D;QAC3D,IAAI,KAAK,EAAE,IAAI,KAAK,QAAQ,IAAI,KAAK,EAAE,CAAC;YACtC,OAAO;QACT,CAAC;QACD,QAAQ,GAAG,KAAK,EAAE,IAAI,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC;QAC7F,aAAa,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,aAAa,GAAG,IAAI,CAAC,CAAC,2DAA2D;QACjF,KAAK,EAAE,IAAI,EAAE,CAAC;QACd,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["// `qpq go:dev:api` — boots the QPQ local dev server. Resolves the app,\n// generates the dev-server entry, builds the rspack config, then runs rspack\n// in watch mode, restarting the server process on every successful rebuild.\n//\n// The one thing NOT hot-reloaded is the qpq configs themselves: each service's\n// infrastructure.ts is evaluated once at launch and baked into the\n// `quidproquo-dynamic-loader` virtual module — config changes need a full\n// `go:dev:api` restart.\nimport { getAppServiceQpqConfigs, getDevServerRspackConfig } from 'quidproquo-deploy-rspack';\n\nimport { ChildProcess, spawn } from 'child_process';\nimport fs from 'fs';\nimport path from 'path';\nimport { rspack } from '@rspack/core';\n\nimport { primeDeployEnvFromConfig } from '../lib/deployEnv';\nimport { writeDevServerEntry } from '../lib/devServerEntry';\nimport { getRoot } from '../lib/discovery';\nimport { killOtherQpqDevProcesses, killStaleListeners } from '../lib/killStaleListeners';\nimport { resolveAppSelection } from '../lib/resolveAppSelection';\n\n// 8080/8888 are set in the generated entry; 3001 is the quidproquo-dev-server\n// file-storage (secure URL) default port.\nconst DEV_SERVER_PORTS = [8080, 8888, 3001];\nconst DEV_SERVER_BUNDLE_PATH = path.join('dist', 'qpq', 'dev-server', 'main.js');\n\nexport const goDevApiCommand = async (argv: string[]): Promise<void> => {\n const root = getRoot();\n const appName = await resolveAppSelection({ argv, envVar: 'QPQ_DEV_APP' });\n process.env.QPQ_DEV_APP = appName;\n primeDeployEnvFromConfig(appName);\n console.log(`Dev server for app [${appName}]`);\n\n // Catches a lingering watcher from a previous run even if its spawned\n // child already exited (see killOtherQpqDevProcesses) — then the usual\n // port-based sweep for anything else still bound to our ports.\n killOtherQpqDevProcesses(root);\n killStaleListeners(DEV_SERVER_PORTS, (command) => command.includes(DEV_SERVER_BUNDLE_PATH));\n\n const qpqConfigs = getAppServiceQpqConfigs(root, appName);\n const entry = writeDevServerEntry(root, appName);\n const rspackConfig = getDevServerRspackConfig({ root, entry, qpqConfigs });\n const bundlePath = path.join(root, DEV_SERVER_BUNDLE_PATH);\n const env = { ...process.env, QPQ_DEV_APP: appName };\n\n // The long-lived server process (HTTP 8080 / WS 8888), restarted per rebuild.\n let child: ChildProcess | null = null;\n let restartQueued = false;\n\n const startServer = (): void => {\n child = spawn('node', [bundlePath], { stdio: 'inherit', env });\n child.on('exit', (code) => {\n child = null;\n if (!restartQueued) {\n // Crashed (or exited) on its own — leave it down; the next successful\n // rebuild (i.e. the next file save) brings it back up.\n console.log(`Dev server exited with code ${code}. Save a file to restart it.`);\n }\n });\n };\n\n const restartServer = (): void => {\n if (restartQueued) return;\n if (!child) {\n startServer();\n return;\n }\n restartQueued = true;\n child.once('exit', () => {\n restartQueued = false;\n startServer();\n });\n child.kill();\n };\n\n console.log('Bundling dev server (watch mode)...');\n let lastHash: string | null | undefined;\n const compiler = rspack(rspackConfig);\n compiler.watch({ aggregateTimeout: 200 }, (err, stats) => {\n if (err) {\n console.error(err);\n return;\n }\n if (stats?.hasErrors()) {\n console.error(stats.toString({ colors: true, chunks: false, modules: false }));\n console.log('Build failed — dev server not restarted. Fix the error and save again.');\n return;\n }\n // Skip no-op rebuilds (e.g. the virtual-module-triggered second compile at\n // startup): only restart when the output actually changed.\n if (stats?.hash === lastHash && child) {\n return;\n }\n lastHash = stats?.hash;\n console.log(child ? 'Rebuilt. Restarting dev server...' : 'Dev server bundled. Starting...');\n restartServer();\n });\n\n process.on('SIGINT', () => {\n restartQueued = true; // suppress the crash log / rebuild-restart on our own kill\n child?.kill();\n compiler.close(() => process.exit(0));\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"goDevApi.js","sourceRoot":"","sources":["../../../src/commands/goDevApi.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,6EAA6E;AAC7E,4EAA4E;AAC5E,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,0DAA0D;AAC1D,EAAE;AACF,+EAA+E;AAC/E,mEAAmE;AACnE,0EAA0E;AAC1E,wBAAwB;AACxB,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAE7F,OAAO,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,2BA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AAO;QACT,CAAC;QACD,YAAY,GAAG,IAAI,CAAC;QAEpB,aAAa,GAAG,IAAI,CAAC,CAAC,2DAA2D;QAEjF,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,uBAAuB,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;QAED,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,KAAK,oBAAoB,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;QACzB,KAAK,oBAAoB,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["// `qpq go:dev:api` — boots the QPQ local dev server. Resolves the app,\n// generates the dev-server entry, builds the rspack config, then runs rspack\n// in watch mode, restarting the server process on every successful rebuild.\n//\n// A restart is not instant: the server drains in-flight work and checkpoints\n// its stores on the way out (typically tens of ms, 5s worst case), and this\n// command waits for that before starting the replacement.\n//\n// The one thing NOT hot-reloaded is the qpq configs themselves: each service's\n// infrastructure.ts is evaluated once at launch and baked into the\n// `quidproquo-dynamic-loader` virtual module — config changes need a full\n// `go:dev:api` restart.\nimport { getAppServiceQpqConfigs, getDevServerRspackConfig } from 'quidproquo-deploy-rspack';\n\nimport { ChildProcess, spawn } from 'child_process';\nimport fs from 'fs';\nimport path from 'path';\nimport { rspack } from '@rspack/core';\n\nimport { hasArgFlag } from '../lib/args';\nimport { primeDeployEnvFromConfig } from '../lib/deployEnv';\nimport { writeDevServerEntry } from '../lib/devServerEntry';\nimport { getRoot } from '../lib/discovery';\nimport { KEEP_OTHER_DEV_SERVERS_FLAG } from '../lib/keepOtherDevServersFlag';\nimport { killChildWithEscalation } from '../lib/killChildWithEscalation';\nimport { killOtherQpqDevProcesses, killStaleListeners, reportPortHolders } from '../lib/killStaleListeners';\nimport { resolveAppSelection } from '../lib/resolveAppSelection';\n\n// 8080/8888 are set in the generated entry; 3001 is the quidproquo-dev-server\n// file-storage (secure URL) default port.\nconst DEV_SERVER_PORTS = [8080, 8888, 3001];\nconst DEV_SERVER_BUNDLE_PATH = path.join('dist', 'qpq', 'dev-server', 'main.js');\n\nexport const goDevApiCommand = async (argv: string[]): Promise<void> => {\n const root = getRoot();\n const appName = await resolveAppSelection({ argv, envVar: 'QPQ_DEV_APP' });\n process.env.QPQ_DEV_APP = appName;\n primeDeployEnvFromConfig(appName);\n console.log(`Dev server for app [${appName}]`);\n\n // The sweep matches on a RELATIVE bundle path, so every checkout's dev\n // server looks like ours and a sibling worktree gets taken down with it.\n // Opting out spares it, at the cost of this one not starting: the ports are\n // the same either way, so what you get instead is EADDRINUSE. Report who\n // holds them, or that failure says nothing about the cause.\n if (hasArgFlag(argv, KEEP_OTHER_DEV_SERVERS_FLAG)) {\n console.log(`${KEEP_OTHER_DEV_SERVERS_FLAG}: leaving other dev servers alone.`);\n reportPortHolders(DEV_SERVER_PORTS);\n } else {\n // Catches a lingering watcher from a previous run even if its spawned\n // child already exited (see killOtherQpqDevProcesses) — then the usual\n // port-based sweep for anything else still bound to our ports.\n killOtherQpqDevProcesses(root);\n killStaleListeners(DEV_SERVER_PORTS, (command) => command.includes(DEV_SERVER_BUNDLE_PATH));\n }\n\n const qpqConfigs = getAppServiceQpqConfigs(root, appName);\n const entry = writeDevServerEntry(root, appName);\n const rspackConfig = getDevServerRspackConfig({ root, entry, qpqConfigs });\n const bundlePath = path.join(root, DEV_SERVER_BUNDLE_PATH);\n const env = { ...process.env, QPQ_DEV_APP: appName };\n\n // The long-lived server process (HTTP 8080 / WS 8888), restarted per rebuild.\n let child: ChildProcess | null = null;\n let restartQueued = false;\n\n const startServer = (): void => {\n child = spawn('node', [bundlePath], { stdio: 'inherit', env });\n child.on('exit', (code) => {\n child = null;\n if (!restartQueued) {\n // Crashed (or exited) on its own — leave it down; the next successful\n // rebuild (i.e. the next file save) brings it back up.\n console.log(`Dev server exited with code ${code}. Save a file to restart it.`);\n }\n });\n };\n\n const restartServer = (): void => {\n if (restartQueued) return;\n if (!child) {\n startServer();\n return;\n }\n restartQueued = true;\n child.once('exit', () => {\n restartQueued = false;\n startServer();\n });\n\n // Not a bare kill: the server drains in-flight work before it exits, so it\n // needs asking properly and then a hard backstop if it wedges. Waiting for\n // the exit is what keeps the ports free for the replacement.\n void killChildWithEscalation(child);\n };\n\n console.log('Bundling dev server (watch mode)...');\n let lastHash: string | null | undefined;\n const compiler = rspack(rspackConfig);\n compiler.watch({ aggregateTimeout: 200 }, (err, stats) => {\n if (err) {\n console.error(err);\n return;\n }\n if (stats?.hasErrors()) {\n console.error(stats.toString({ colors: true, chunks: false, modules: false }));\n console.log('Build failed — dev server not restarted. Fix the error and save again.');\n return;\n }\n // Skip no-op rebuilds (e.g. the virtual-module-triggered second compile at\n // startup): only restart when the output actually changed.\n if (stats?.hash === lastHash && child) {\n return;\n }\n lastHash = stats?.hash;\n console.log(child ? 'Rebuilt. Restarting dev server...' : 'Dev server bundled. Starting...');\n restartServer();\n });\n\n // Wait for the server to finish draining before tearing the watcher down and\n // exiting: closing the compiler first would exit the parent while the child\n // is still writing, which is the race this whole path exists to close.\n //\n // SIGTERM as well as SIGINT, and it is load-bearing rather than symmetry for\n // its own sake. This process is a WRAPPER: the dev server that handles\n // signals and drains its work is the child it spawned. Without a handler\n // here, SIGTERM (what `docker stop` sends, and what any script stopping this\n // programmatically sends) kills the wrapper outright on the default\n // disposition, the child never gets asked to stop, and every guarantee the\n // dev server's shutdown sequence makes is bypassed. go:dev:web already\n // handles both.\n let shuttingDown = false;\n\n const handleShutdownSignal = async (): Promise<void> => {\n if (shuttingDown) {\n return;\n }\n shuttingDown = true;\n\n restartQueued = true; // suppress the crash log / rebuild-restart on our own kill\n\n if (child) {\n await killChildWithEscalation(child);\n }\n\n compiler.close(() => process.exit(0));\n };\n\n process.on('SIGINT', () => {\n void handleShutdownSignal();\n });\n\n process.on('SIGTERM', () => {\n void handleShutdownSignal();\n });\n};\n"]}
|
|
@@ -13,9 +13,11 @@ import http from 'http';
|
|
|
13
13
|
import { rspack } from '@rspack/core';
|
|
14
14
|
import { RspackDevServer } from '@rspack/dev-server';
|
|
15
15
|
import { getArgValue } from '../lib/args';
|
|
16
|
+
import { hasArgFlag } from '../lib/args';
|
|
16
17
|
import { primeDeployEnvFromConfig } from '../lib/deployEnv';
|
|
17
18
|
import { getRoot } from '../lib/discovery';
|
|
18
|
-
import {
|
|
19
|
+
import { KEEP_OTHER_DEV_SERVERS_FLAG } from '../lib/keepOtherDevServersFlag';
|
|
20
|
+
import { isQpqCliCommand, killStaleListeners, reportPortHolders } from '../lib/killStaleListeners';
|
|
19
21
|
import { resolveAppSelection } from '../lib/resolveAppSelection';
|
|
20
22
|
export const goDevWebCommand = async (argv, options = {}) => {
|
|
21
23
|
const root = getRoot();
|
|
@@ -33,7 +35,13 @@ export const goDevWebCommand = async (argv, options = {}) => {
|
|
|
33
35
|
console.error('No views projects found.');
|
|
34
36
|
process.exit(1);
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
// See goDevApi for why this is opt-out rather than always-on.
|
|
39
|
+
if (hasArgFlag(argv, KEEP_OTHER_DEV_SERVERS_FLAG)) {
|
|
40
|
+
reportPortHolders(views.map((v) => v.port));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
killStaleListeners(views.map((v) => v.port), isQpqCliCommand);
|
|
44
|
+
}
|
|
37
45
|
// Every RspackDevServer.start() registers its own SIGINT/SIGTERM handler on
|
|
38
46
|
// process — with a dozen views servers in one process that trips node's
|
|
39
47
|
// default 10-listener warning. Size the limit to the fleet.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goDevWeb.js","sourceRoot":"","sources":["../../../src/commands/goDevWeb.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,8EAA8E;AAC9E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AAC;IAC1D,CAAC;IAED,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC","sourcesContent":["// `qpq go:dev:web` — boots every views microfrontend's Rspack dev server\n// in-process (shell is the MF host app, plus all remotes on their own ports).\n// Everything is served dynamically; remotes resolve at runtime via\n// mf-manifest.json on localhost ports. Programmatic — no per-views\n// rspack.config.ts or npm serve script needed.\n//\n// Usage:\n// qpq go:dev:web\n// qpq go:dev:web --only shell,design\n// qpq go:dev:web --app <name>\nimport { getAllViews, getViewsRspackConfig } from 'quidproquo-deploy-rspack';\n\nimport http from 'http';\nimport { rspack } from '@rspack/core';\nimport { RspackDevServer } from '@rspack/dev-server';\n\nimport { getArgValue } from '../lib/args';\nimport { primeDeployEnvFromConfig } from '../lib/deployEnv';\nimport { getRoot } from '../lib/discovery';\nimport { isQpqCliCommand, killStaleListeners } from '../lib/killStaleListeners';\nimport { resolveAppSelection } from '../lib/resolveAppSelection';\n\nexport type GoDevWebOptions = {\n // The in-place \"(started)\" chip rewrite assumes this command owns the\n // terminal; when stdout is shared with the API dev server (combined\n // `qpq go:dev`) the cursor math breaks. The plain-line fallback is just a\n // wall of \" auth started\" noise interleaved with the API output, so drop\n // the ready status altogether there.\n hideStartedStatus?: boolean;\n};\n\nexport const goDevWebCommand = async (argv: string[], options: GoDevWebOptions = {}): Promise<void> => {\n const root = getRoot();\n const appName = await resolveAppSelection({ argv, envVar: 'QPQ_DEV_APP' });\n\n process.env.LOCAL_DEV_SERVER = 'true';\n process.env.NODE_ENV = 'development';\n primeDeployEnvFromConfig(appName);\n\n const only = getArgValue(argv, '--only')\n ?.split(',')\n .map((s) => s.trim());\n\n let views = getAllViews(root, appName);\n if (only) views = views.filter((v) => only.includes(v.service));\n if (views.length === 0) {\n console.error('No views projects found.');\n process.exit(1);\n }\n\n killStaleListeners(\n views.map((v) => v.port),\n isQpqCliCommand,\n );\n\n // Every RspackDevServer.start() registers its own SIGINT/SIGTERM handler on\n // process — with a dozen views servers in one process that trips node's\n // default 10-listener warning. Size the limit to the fleet.\n process.setMaxListeners(Math.max(process.getMaxListeners(), views.length * 2 + 10));\n\n // Service names are padded to a common width so the \"(started)\" chips align.\n const serviceColumnWidth = Math.max(...views.map((v) => v.service.length));\n\n console.log(`Starting ${views.length} views dev servers for [${appName}]:`);\n for (const v of views) console.log(` http://localhost:${v.port} ${v.service.padEnd(serviceColumnWidth)}`);\n\n const servers: RspackDevServer[] = [];\n let shuttingDown = false;\n\n const shutdown = (code: number): void => {\n if (shuttingDown) return;\n shuttingDown = true;\n Promise.allSettled(servers.map((server) => server.stop())).then(() => process.exit(code));\n };\n\n // The URL list above gets a yellow \"(started)\" chip appended in place as\n // each dev server begins answering HTTP. The in-place rewrite moves the\n // cursor up past everything printed since the list, so every line printed\n // below it MUST go through logBelowList to keep the offset accurate.\n let linesBelowList = 0;\n\n const logBelowList = (line: string): void => {\n console.log(line);\n linesBelowList += 1;\n };\n\n const markStarted = (index: number): void => {\n const v = views[index];\n if (!process.stdout.isTTY) {\n logBelowList(` ${v.service} started`);\n return;\n }\n const line = ` http://localhost:${v.port} ${v.service.padEnd(serviceColumnWidth)} \\x1b[33m(started)\\x1b[0m`;\n const up = linesBelowList + (views.length - index);\n process.stdout.write(`\\x1b[${up}F\\x1b[2K${line}\\x1b[${up}E`);\n };\n\n const pollUntilStarted = (index: number): void => {\n const attempt = (): void => {\n if (shuttingDown) return;\n const req = http.get(\n {\n host: 'localhost',\n port: views[index].port,\n path: '/',\n timeout: 1000,\n },\n (res) => {\n res.resume();\n markStarted(index);\n },\n );\n req.on('error', () => setTimeout(attempt, 500));\n req.on('timeout', () => req.destroy());\n };\n attempt();\n };\n\n for (const [index, view] of views.entries()) {\n const config = getViewsRspackConfig(view.viewsDir);\n const compiler = rspack(config);\n const server = new RspackDevServer(config.devServer || { port: view.port }, compiler);\n servers.push(server);\n\n try {\n await server.start();\n } catch (e) {\n logBelowList(` [${view.service}] failed to start: ${(e as Error).message} — shutting down all views servers.`);\n shutdown(1);\n return;\n }\n\n // markStarted is the only consumer of the ready signal, so there is\n // nothing to poll for when the status is hidden.\n if (!options.hideStartedStatus) pollUntilStarted(index);\n }\n\n process.on('SIGINT', () => shutdown(0));\n process.on('SIGTERM', () => shutdown(0));\n};\n"]}
|
|
1
|
+
{"version":3,"file":"goDevWeb.js","sourceRoot":"","sources":["../../../src/commands/goDevWeb.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,8EAA8E;AAC9E,mEAAmE;AACnE,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,SAAS;AACT,mBAAmB;AACnB,uCAAuC;AACvC,gCAAgC;AAChC,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAE7E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnG,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAWjE,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,IAAc,EAAE,UAA2B,EAAE,EAAiB,EAAE;IACp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F,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;IAEF,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;QACtF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAErB,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,YAAY,CAAC,MAAM,IAAI,CAAC,OAAO,sBAAuB,CAAW,CAAC,OAAO,qCAAqC,CAAC,CAAC;YAChH,QAAQ,CAAC,CAAC,CAAC,CAAC;YACZ,OAAO;QACT,CAAC;QAED,oEAAoE;QACpE,iDAAiD;QACjD,IAAI,CAAC,OAAO,CAAC,iBAAiB;YAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC,CAAC","sourcesContent":["// `qpq go:dev:web` — boots every views microfrontend's Rspack dev server\n// in-process (shell is the MF host app, plus all remotes on their own ports).\n// Everything is served dynamically; remotes resolve at runtime via\n// mf-manifest.json on localhost ports. Programmatic — no per-views\n// rspack.config.ts or npm serve script needed.\n//\n// Usage:\n// qpq go:dev:web\n// qpq go:dev:web --only shell,design\n// qpq go:dev:web --app <name>\nimport { getAllViews, getViewsRspackConfig } from 'quidproquo-deploy-rspack';\n\nimport http from 'http';\nimport { rspack } from '@rspack/core';\nimport { RspackDevServer } from '@rspack/dev-server';\n\nimport { getArgValue } from '../lib/args';\nimport { hasArgFlag } from '../lib/args';\nimport { primeDeployEnvFromConfig } from '../lib/deployEnv';\nimport { getRoot } from '../lib/discovery';\nimport { KEEP_OTHER_DEV_SERVERS_FLAG } from '../lib/keepOtherDevServersFlag';\nimport { isQpqCliCommand, killStaleListeners, reportPortHolders } from '../lib/killStaleListeners';\nimport { resolveAppSelection } from '../lib/resolveAppSelection';\n\nexport type GoDevWebOptions = {\n // The in-place \"(started)\" chip rewrite assumes this command owns the\n // terminal; when stdout is shared with the API dev server (combined\n // `qpq go:dev`) the cursor math breaks. The plain-line fallback is just a\n // wall of \" auth started\" noise interleaved with the API output, so drop\n // the ready status altogether there.\n hideStartedStatus?: boolean;\n};\n\nexport const goDevWebCommand = async (argv: string[], options: GoDevWebOptions = {}): Promise<void> => {\n const root = getRoot();\n const appName = await resolveAppSelection({ argv, envVar: 'QPQ_DEV_APP' });\n\n process.env.LOCAL_DEV_SERVER = 'true';\n process.env.NODE_ENV = 'development';\n primeDeployEnvFromConfig(appName);\n\n const only = getArgValue(argv, '--only')\n ?.split(',')\n .map((s) => s.trim());\n\n let views = getAllViews(root, appName);\n if (only) views = views.filter((v) => only.includes(v.service));\n if (views.length === 0) {\n console.error('No views projects found.');\n process.exit(1);\n }\n\n // See goDevApi for why this is opt-out rather than always-on.\n if (hasArgFlag(argv, KEEP_OTHER_DEV_SERVERS_FLAG)) {\n reportPortHolders(views.map((v) => v.port));\n } else {\n killStaleListeners(\n views.map((v) => v.port),\n isQpqCliCommand,\n );\n }\n\n // Every RspackDevServer.start() registers its own SIGINT/SIGTERM handler on\n // process — with a dozen views servers in one process that trips node's\n // default 10-listener warning. Size the limit to the fleet.\n process.setMaxListeners(Math.max(process.getMaxListeners(), views.length * 2 + 10));\n\n // Service names are padded to a common width so the \"(started)\" chips align.\n const serviceColumnWidth = Math.max(...views.map((v) => v.service.length));\n\n console.log(`Starting ${views.length} views dev servers for [${appName}]:`);\n for (const v of views) console.log(` http://localhost:${v.port} ${v.service.padEnd(serviceColumnWidth)}`);\n\n const servers: RspackDevServer[] = [];\n let shuttingDown = false;\n\n const shutdown = (code: number): void => {\n if (shuttingDown) return;\n shuttingDown = true;\n Promise.allSettled(servers.map((server) => server.stop())).then(() => process.exit(code));\n };\n\n // The URL list above gets a yellow \"(started)\" chip appended in place as\n // each dev server begins answering HTTP. The in-place rewrite moves the\n // cursor up past everything printed since the list, so every line printed\n // below it MUST go through logBelowList to keep the offset accurate.\n let linesBelowList = 0;\n\n const logBelowList = (line: string): void => {\n console.log(line);\n linesBelowList += 1;\n };\n\n const markStarted = (index: number): void => {\n const v = views[index];\n if (!process.stdout.isTTY) {\n logBelowList(` ${v.service} started`);\n return;\n }\n const line = ` http://localhost:${v.port} ${v.service.padEnd(serviceColumnWidth)} \\x1b[33m(started)\\x1b[0m`;\n const up = linesBelowList + (views.length - index);\n process.stdout.write(`\\x1b[${up}F\\x1b[2K${line}\\x1b[${up}E`);\n };\n\n const pollUntilStarted = (index: number): void => {\n const attempt = (): void => {\n if (shuttingDown) return;\n const req = http.get(\n {\n host: 'localhost',\n port: views[index].port,\n path: '/',\n timeout: 1000,\n },\n (res) => {\n res.resume();\n markStarted(index);\n },\n );\n req.on('error', () => setTimeout(attempt, 500));\n req.on('timeout', () => req.destroy());\n };\n attempt();\n };\n\n for (const [index, view] of views.entries()) {\n const config = getViewsRspackConfig(view.viewsDir);\n const compiler = rspack(config);\n const server = new RspackDevServer(config.devServer || { port: view.port }, compiler);\n servers.push(server);\n\n try {\n await server.start();\n } catch (e) {\n logBelowList(` [${view.service}] failed to start: ${(e as Error).message} — shutting down all views servers.`);\n shutdown(1);\n return;\n }\n\n // markStarted is the only consumer of the ready signal, so there is\n // nothing to poll for when the status is hidden.\n if (!options.hideStartedStatus) pollUntilStarted(index);\n }\n\n process.on('SIGINT', () => shutdown(0));\n process.on('SIGTERM', () => shutdown(0));\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setupCommand: (argv: string[]) => Promise<void>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// `qpq setup` — takes a cloud environment from empty to deployed, in order, with
|
|
2
|
+
// every step checked first so the menu shows what is already in place and a
|
|
3
|
+
// rerun on a half-set-up account is safe. The platform (from the environment's
|
|
4
|
+
// entry in deploy.config.json) contributes the steps.
|
|
5
|
+
// --check print each step's status and exit, run nothing
|
|
6
|
+
// --yes run every step without the menu
|
|
7
|
+
// --only a,b run only the named step ids (no menu)
|
|
8
|
+
import { getArgValue } from '../lib/args';
|
|
9
|
+
import { resolveDeployEnvironment } from '../lib/deployEnv';
|
|
10
|
+
import { promptCheckbox } from '../lib/prompts';
|
|
11
|
+
import { resolveAppSelection } from '../lib/resolveAppSelection';
|
|
12
|
+
import { getPlatformDriver } from '../platforms';
|
|
13
|
+
const statusLabel = (result) => (result === null ? '?' : result.done ? 'done' : 'todo');
|
|
14
|
+
const printChecklist = (checked) => {
|
|
15
|
+
for (const { step, result } of checked) {
|
|
16
|
+
const detail = result?.detail ? ` ${result.detail}` : '';
|
|
17
|
+
console.log(` [${statusLabel(result).padEnd(4)}] ${step.name}${detail}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const checkAll = async (steps) => {
|
|
21
|
+
const checked = [];
|
|
22
|
+
for (const step of steps) {
|
|
23
|
+
try {
|
|
24
|
+
checked.push({ step, result: await step.check() });
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
checked.push({ step, result: { done: false, detail: `check failed: ${error instanceof Error ? error.message : String(error)}` } });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return checked;
|
|
31
|
+
};
|
|
32
|
+
// Steps not yet done are preselected; done ones can still be picked to rerun.
|
|
33
|
+
const chooseSteps = async (checked) => {
|
|
34
|
+
const chosen = await promptCheckbox('Setup steps to run (space toggles, enter runs in order)', checked.map(({ step, result }) => ({
|
|
35
|
+
name: `[${statusLabel(result).padEnd(4)}] ${step.name}`,
|
|
36
|
+
value: step,
|
|
37
|
+
checked: !result?.done,
|
|
38
|
+
description: result?.detail,
|
|
39
|
+
})));
|
|
40
|
+
// Always run in checklist order, whatever order they were ticked in.
|
|
41
|
+
return checked.map(({ step }) => step).filter((step) => chosen.includes(step));
|
|
42
|
+
};
|
|
43
|
+
const selectFromArgs = (steps, argv) => {
|
|
44
|
+
if (argv.includes('--yes')) {
|
|
45
|
+
return steps;
|
|
46
|
+
}
|
|
47
|
+
const only = getArgValue(argv, '--only');
|
|
48
|
+
if (!only) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const ids = only.split(',').map((id) => id.trim());
|
|
52
|
+
const unknown = ids.filter((id) => !steps.some((step) => step.id === id));
|
|
53
|
+
if (unknown.length > 0) {
|
|
54
|
+
console.error(`Unknown setup step id(s): ${unknown.join(', ')}. Known: ${steps.map((step) => step.id).join(', ')}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
return steps.filter((step) => ids.includes(step.id));
|
|
58
|
+
};
|
|
59
|
+
export const setupCommand = async (argv) => {
|
|
60
|
+
const appName = await resolveAppSelection({ argv, envVar: 'DEPLOY_APP_NAME' });
|
|
61
|
+
const { environment, platform } = await resolveDeployEnvironment(argv, appName);
|
|
62
|
+
const driver = getPlatformDriver(platform);
|
|
63
|
+
if (!driver.setupSteps) {
|
|
64
|
+
console.log(`The '${platform}' platform has nothing to set up for environment '${environment}'.`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const steps = await driver.setupSteps(appName, environment);
|
|
68
|
+
console.log(`\nSetup for app '${appName}', environment '${environment}' (${platform})\n`);
|
|
69
|
+
const checked = await checkAll(steps);
|
|
70
|
+
printChecklist(checked);
|
|
71
|
+
console.log('');
|
|
72
|
+
if (argv.includes('--check')) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const toRun = selectFromArgs(steps, argv) ?? (await chooseSteps(checked));
|
|
76
|
+
if (toRun.length === 0) {
|
|
77
|
+
console.log('Nothing selected.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
for (const step of toRun) {
|
|
81
|
+
console.log(`\n== ${step.name}\n`);
|
|
82
|
+
await step.run();
|
|
83
|
+
}
|
|
84
|
+
console.log('\nSetup complete. Final state:\n');
|
|
85
|
+
printChecklist(await checkAll(steps));
|
|
86
|
+
console.log(`\nNext: deploy the services with npx qpq go:docker all all --app ${appName} --env ${environment}`);
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/commands/setup.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,4EAA4E;AAC5E,+EAA+E;AAC/E,sDAAsD;AACtD,gEAAgE;AAChE,iDAAiD;AACjD,uDAAuD;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIjD,MAAM,WAAW,GAAG,CAAC,MAA+B,EAAU,EAAE,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzH,MAAM,cAAc,GAAG,CAAC,OAAsB,EAAQ,EAAE;IACtD,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,OAAO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KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QACjC,OAAO;IACT,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;QACnC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;IAChD,cAAc,CAAC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,qEAAqE,OAAO,UAAU,WAAW,EAAE,CAAC,CAAC;AACnH,CAAC,CAAC","sourcesContent":["// `qpq setup` — takes a cloud environment from empty to deployed, in order, with\n// every step checked first so the menu shows what is already in place and a\n// rerun on a half-set-up account is safe. The platform (from the environment's\n// entry in deploy.config.json) contributes the steps.\n// --check print each step's status and exit, run nothing\n// --yes run every step without the menu\n// --only a,b run only the named step ids (no menu)\nimport { getArgValue } from '../lib/args';\nimport { resolveDeployEnvironment } from '../lib/deployEnv';\nimport { promptCheckbox } from '../lib/prompts';\nimport { resolveAppSelection } from '../lib/resolveAppSelection';\nimport { SetupCheckResult, SetupStep } from '../lib/setupStep';\nimport { getPlatformDriver } from '../platforms';\n\ntype CheckedStep = { step: SetupStep; result: SetupCheckResult | null };\n\nconst statusLabel = (result: SetupCheckResult | null): string => (result === null ? '?' : result.done ? 'done' : 'todo');\n\nconst printChecklist = (checked: CheckedStep[]): void => {\n for (const { step, result } of checked) {\n const detail = result?.detail ? ` ${result.detail}` : '';\n console.log(` [${statusLabel(result).padEnd(4)}] ${step.name}${detail}`);\n }\n};\n\nconst checkAll = async (steps: SetupStep[]): Promise<CheckedStep[]> => {\n const checked: CheckedStep[] = [];\n for (const step of steps) {\n try {\n checked.push({ step, result: await step.check() });\n } catch (error) {\n checked.push({ step, result: { done: false, detail: `check failed: ${error instanceof Error ? error.message : String(error)}` } });\n }\n }\n return checked;\n};\n\n// Steps not yet done are preselected; done ones can still be picked to rerun.\nconst chooseSteps = async (checked: CheckedStep[]): Promise<SetupStep[]> => {\n const chosen = await promptCheckbox(\n 'Setup steps to run (space toggles, enter runs in order)',\n checked.map(({ step, result }) => ({\n name: `[${statusLabel(result).padEnd(4)}] ${step.name}`,\n value: step,\n checked: !result?.done,\n description: result?.detail,\n })),\n );\n\n // Always run in checklist order, whatever order they were ticked in.\n return checked.map(({ step }) => step).filter((step) => chosen.includes(step));\n};\n\nconst selectFromArgs = (steps: SetupStep[], argv: string[]): SetupStep[] | null => {\n if (argv.includes('--yes')) {\n return steps;\n }\n\n const only = getArgValue(argv, '--only');\n if (!only) {\n return null;\n }\n\n const ids = only.split(',').map((id) => id.trim());\n const unknown = ids.filter((id) => !steps.some((step) => step.id === id));\n if (unknown.length > 0) {\n console.error(`Unknown setup step id(s): ${unknown.join(', ')}. Known: ${steps.map((step) => step.id).join(', ')}`);\n process.exit(1);\n }\n\n return steps.filter((step) => ids.includes(step.id));\n};\n\nexport const setupCommand = async (argv: string[]): Promise<void> => {\n const appName = await resolveAppSelection({ argv, envVar: 'DEPLOY_APP_NAME' });\n const { environment, platform } = await resolveDeployEnvironment(argv, appName);\n const driver = getPlatformDriver(platform);\n\n if (!driver.setupSteps) {\n console.log(`The '${platform}' platform has nothing to set up for environment '${environment}'.`);\n return;\n }\n\n const steps = await driver.setupSteps(appName, environment);\n\n console.log(`\\nSetup for app '${appName}', environment '${environment}' (${platform})\\n`);\n const checked = await checkAll(steps);\n printChecklist(checked);\n console.log('');\n\n if (argv.includes('--check')) {\n return;\n }\n\n const toRun = selectFromArgs(steps, argv) ?? (await chooseSteps(checked));\n if (toRun.length === 0) {\n console.log('Nothing selected.');\n return;\n }\n\n for (const step of toRun) {\n console.log(`\\n== ${step.name}\\n`);\n await step.run();\n }\n\n console.log('\\nSetup complete. Final state:\\n');\n printChecklist(await checkAll(steps));\n console.log(`\\nNext: deploy the services with npx qpq go:docker all all --app ${appName} --env ${environment}`);\n};\n"]}
|
package/lib/esm/lib/args.d.ts
CHANGED
package/lib/esm/lib/args.js
CHANGED
|
@@ -6,6 +6,15 @@ export const getArgValue = (argv, flag) => {
|
|
|
6
6
|
const idx = argv.indexOf(flag);
|
|
7
7
|
return idx >= 0 ? argv[idx + 1] : undefined;
|
|
8
8
|
};
|
|
9
|
+
// A presence-only flag: `--foo`. `--foo=false` is honoured as off, so a
|
|
10
|
+
// wrapper script can pass the flag through with a computed value rather than
|
|
11
|
+
// having to conditionally omit it.
|
|
12
|
+
export const hasArgFlag = (argv, flag) => {
|
|
13
|
+
const eq = argv.find((a) => a.startsWith(`${flag}=`));
|
|
14
|
+
if (eq)
|
|
15
|
+
return eq.slice(`${flag}=`.length) !== 'false';
|
|
16
|
+
return argv.includes(flag);
|
|
17
|
+
};
|
|
9
18
|
// Positional args = non-flag args, skipping values consumed by known flags.
|
|
10
19
|
export const getPositionalArgs = (argv, valueFlags) => argv.filter((arg, index) => {
|
|
11
20
|
if (arg.startsWith('--'))
|
package/lib/esm/lib/args.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../../src/lib/args.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAc,EAAE,IAAY,EAAsB,EAAE;IAC9E,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;IACtD,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAc,EAAE,UAAoB,EAAY,EAAE,CAClF,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;IACzB,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACjC,OAAO,CAAC,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC","sourcesContent":["// Flag parsing over the command's argv (everything after the command name).\nexport const getArgValue = (argv: string[], flag: string): string | undefined => {\n const eq = argv.find((a) => a.startsWith(`${flag}=`));\n if (eq) return eq.slice(`${flag}=`.length);\n const idx = argv.indexOf(flag);\n return idx >= 0 ? argv[idx + 1] : undefined;\n};\n\n// Positional args = non-flag args, skipping values consumed by known flags.\nexport const getPositionalArgs = (argv: string[], valueFlags: string[]): string[] =>\n argv.filter((arg, index) => {\n if (arg.startsWith('--')) return false;\n const previous = argv[index - 1];\n return !(previous && valueFlags.includes(previous));\n });\n"]}
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../../src/lib/args.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAc,EAAE,IAAY,EAAsB,EAAE;IAC9E,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;IACtD,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC,CAAC;AAEF,wEAAwE;AACxE,6EAA6E;AAC7E,mCAAmC;AACnC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAc,EAAE,IAAY,EAAW,EAAE;IAClE,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;IACtD,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC;IAEvD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAc,EAAE,UAAoB,EAAY,EAAE,CAClF,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;IACzB,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IACjC,OAAO,CAAC,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC","sourcesContent":["// Flag parsing over the command's argv (everything after the command name).\nexport const getArgValue = (argv: string[], flag: string): string | undefined => {\n const eq = argv.find((a) => a.startsWith(`${flag}=`));\n if (eq) return eq.slice(`${flag}=`.length);\n const idx = argv.indexOf(flag);\n return idx >= 0 ? argv[idx + 1] : undefined;\n};\n\n// A presence-only flag: `--foo`. `--foo=false` is honoured as off, so a\n// wrapper script can pass the flag through with a computed value rather than\n// having to conditionally omit it.\nexport const hasArgFlag = (argv: string[], flag: string): boolean => {\n const eq = argv.find((a) => a.startsWith(`${flag}=`));\n if (eq) return eq.slice(`${flag}=`.length) !== 'false';\n\n return argv.includes(flag);\n};\n\n// Positional args = non-flag args, skipping values consumed by known flags.\nexport const getPositionalArgs = (argv: string[], valueFlags: string[]): string[] =>\n argv.filter((arg, index) => {\n if (arg.startsWith('--')) return false;\n const previous = argv[index - 1];\n return !(previous && valueFlags.includes(previous));\n });\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const KEEP_OTHER_DEV_SERVERS_FLAG = "--keep-other-dev-servers";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Opt out of the pre-start sweep that kills anything already holding the dev
|
|
2
|
+
// ports, including a dev server belonging to a different checkout of the same
|
|
3
|
+
// repo. Off by default, so the existing behaviour is unchanged.
|
|
4
|
+
//
|
|
5
|
+
// One flag rather than one per command: `go:dev` hands the same argv to both
|
|
6
|
+
// `go:dev:api` and `go:dev:web`, so declaring it once covers all three.
|
|
7
|
+
export const KEEP_OTHER_DEV_SERVERS_FLAG = '--keep-other-dev-servers';
|
|
8
|
+
//# sourceMappingURL=keepOtherDevServersFlag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keepOtherDevServersFlag.js","sourceRoot":"","sources":["../../../src/lib/keepOtherDevServersFlag.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8EAA8E;AAC9E,gEAAgE;AAChE,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,MAAM,CAAC,MAAM,2BAA2B,GAAG,0BAA0B,CAAC","sourcesContent":["// Opt out of the pre-start sweep that kills anything already holding the dev\n// ports, including a dev server belonging to a different checkout of the same\n// repo. Off by default, so the existing behaviour is unchanged.\n//\n// One flag rather than one per command: `go:dev` hands the same argv to both\n// `go:dev:api` and `go:dev:web`, so declaring it once covers all three.\nexport const KEEP_OTHER_DEV_SERVERS_FLAG = '--keep-other-dev-servers';\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChildProcess } from 'child_process';
|
|
2
|
+
/**
|
|
3
|
+
* SIGTERM the child, resolve once it has actually exited, and SIGKILL it if it
|
|
4
|
+
* has not gone within the grace window.
|
|
5
|
+
*
|
|
6
|
+
* Resolves rather than rejects on escalation: the caller's next move is the
|
|
7
|
+
* same either way (start the replacement), and a rejection would only give
|
|
8
|
+
* every call site a catch to write.
|
|
9
|
+
*/
|
|
10
|
+
export declare const killChildWithEscalation: (child: ChildProcess, graceMs?: number) => Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Above the dev server's 5s worst-case shutdown budget, below docker's 10s
|
|
2
|
+
// default stop grace, so a container stop still exits cleanly rather than
|
|
3
|
+
// being SIGKILLed by docker mid-escalation.
|
|
4
|
+
const DEFAULT_KILL_GRACE_MS = 6000;
|
|
5
|
+
/**
|
|
6
|
+
* SIGTERM the child, resolve once it has actually exited, and SIGKILL it if it
|
|
7
|
+
* has not gone within the grace window.
|
|
8
|
+
*
|
|
9
|
+
* Resolves rather than rejects on escalation: the caller's next move is the
|
|
10
|
+
* same either way (start the replacement), and a rejection would only give
|
|
11
|
+
* every call site a catch to write.
|
|
12
|
+
*/
|
|
13
|
+
export const killChildWithEscalation = (child, graceMs = DEFAULT_KILL_GRACE_MS) => {
|
|
14
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const timer = setTimeout(() => {
|
|
19
|
+
console.warn(`Dev server did not exit within ${graceMs}ms — sending SIGKILL.`);
|
|
20
|
+
child.kill('SIGKILL');
|
|
21
|
+
}, graceMs);
|
|
22
|
+
child.once('exit', () => {
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
resolve();
|
|
25
|
+
});
|
|
26
|
+
child.kill('SIGTERM');
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=killChildWithEscalation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"killChildWithEscalation.js","sourceRoot":"","sources":["../../../src/lib/killChildWithEscalation.ts"],"names":[],"mappings":"AAWA,2EAA2E;AAC3E,0EAA0E;AAC1E,4CAA4C;AAC5C,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAmB,EAAE,OAAO,GAAG,qBAAqB,EAAiB,EAAE;IAC7G,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QACzD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,OAAO,CAAC,IAAI,CAAC,kCAAkC,OAAO,uBAAuB,CAAC,CAAC;YAC/E,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE;YACtB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["// Stopping the dev server child, with a hard backstop.\n//\n// The dev server now runs an ordered shutdown on SIGTERM (drain in-flight\n// work, then checkpoint the stores) instead of dying instantly. That is the\n// point - it is what stops a save-triggered restart eating a queue message\n// mid-story - but it means a bare `child.kill()` followed by waiting for exit\n// can now wait forever if a teardown wedges. Without escalation this would\n// trade a data-loss bug for a hung-restart bug, and the next launch would find\n// its ports still held.\nimport { ChildProcess } from 'child_process';\n\n// Above the dev server's 5s worst-case shutdown budget, below docker's 10s\n// default stop grace, so a container stop still exits cleanly rather than\n// being SIGKILLed by docker mid-escalation.\nconst DEFAULT_KILL_GRACE_MS = 6000;\n\n/**\n * SIGTERM the child, resolve once it has actually exited, and SIGKILL it if it\n * has not gone within the grace window.\n *\n * Resolves rather than rejects on escalation: the caller's next move is the\n * same either way (start the replacement), and a rejection would only give\n * every call site a catch to write.\n */\nexport const killChildWithEscalation = (child: ChildProcess, graceMs = DEFAULT_KILL_GRACE_MS): Promise<void> => {\n if (child.exitCode !== null || child.signalCode !== null) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve) => {\n const timer = setTimeout(() => {\n console.warn(`Dev server did not exit within ${graceMs}ms — sending SIGKILL.`);\n child.kill('SIGKILL');\n }, graceMs);\n\n child.once('exit', () => {\n clearTimeout(timer);\n resolve();\n });\n\n child.kill('SIGTERM');\n });\n};\n"]}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
export declare const isQpqCliCommand: (command: string) => boolean;
|
|
2
2
|
export declare const killOtherQpqDevProcesses: (root: string) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Say what is holding these ports, without touching it.
|
|
5
|
+
*
|
|
6
|
+
* The other half of --keep-other-dev-servers: sparing a sibling checkout's dev
|
|
7
|
+
* server means this one cannot bind, and an unexplained EADDRINUSE is a worse
|
|
8
|
+
* experience than the silent kill it replaces. Naming the pid and the command
|
|
9
|
+
* turns "it just died" into something you can act on.
|
|
10
|
+
*
|
|
11
|
+
* Worded as a prediction, not a fact, because it IS one: this runs before the
|
|
12
|
+
* bundle step, so by the time anything binds - seconds later - the holder may
|
|
13
|
+
* well have gone. Stating "port in use" and then starting cleanly reads like
|
|
14
|
+
* the warning was wrong.
|
|
15
|
+
*/
|
|
16
|
+
export declare const reportPortHolders: (ports: number[]) => void;
|
|
3
17
|
export declare const killStaleListeners: (ports: number[], isOurs: (command: string) => boolean) => void;
|
|
@@ -33,17 +33,36 @@ export const isQpqCliCommand = (command) => command
|
|
|
33
33
|
// one (a real child can sit as a zombie answering `kill(pid, 0)` until this
|
|
34
34
|
// process's own event loop reaps it, which a tight sync loop would starve;
|
|
35
35
|
// doesn't apply to a process we didn't spawn).
|
|
36
|
-
|
|
36
|
+
//
|
|
37
|
+
// The default covers the dev server's graceful shutdown (drain in-flight work,
|
|
38
|
+
// then checkpoint the stores) with room to spare — it used to be 3s, which was
|
|
39
|
+
// fine when the server died instantly and is not now. Returns whether the pid
|
|
40
|
+
// actually went, because a caller about to bind these ports has to escalate
|
|
41
|
+
// rather than hope: giving up while the old server still holds 8080 is exactly
|
|
42
|
+
// the EADDRINUSE this file exists to prevent.
|
|
43
|
+
const waitForPidGone = (pid, timeoutMs = 8000) => {
|
|
37
44
|
const deadline = Date.now() + timeoutMs;
|
|
38
45
|
while (Date.now() < deadline) {
|
|
39
46
|
try {
|
|
40
47
|
process.kill(pid, 0);
|
|
41
48
|
}
|
|
42
49
|
catch {
|
|
43
|
-
return; // throws once the pid no longer exists
|
|
50
|
+
return true; // throws once the pid no longer exists
|
|
44
51
|
}
|
|
45
52
|
execSync('sleep 0.05');
|
|
46
53
|
}
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
56
|
+
// Last resort for a process that ignored, or wedged during, its graceful stop.
|
|
57
|
+
const killPidHard = (pid) => {
|
|
58
|
+
console.warn(`Process ${pid} did not exit gracefully — sending SIGKILL.`);
|
|
59
|
+
try {
|
|
60
|
+
process.kill(pid, 'SIGKILL');
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return; // raced us and exited after all
|
|
64
|
+
}
|
|
65
|
+
waitForPidGone(pid, 2000);
|
|
47
66
|
};
|
|
48
67
|
// realpath'd: lsof reports the canonical path (e.g. /private/tmp on macOS,
|
|
49
68
|
// where /tmp is a symlink), so comparing against a caller-supplied root
|
|
@@ -121,36 +140,66 @@ export const killOtherQpqDevProcesses = (root) => {
|
|
|
121
140
|
continue;
|
|
122
141
|
console.log(`Killing other qpq dev process for this repo (pid ${pid}): ${command}`);
|
|
123
142
|
process.kill(pid, 'SIGINT');
|
|
124
|
-
waitForPidGone(pid)
|
|
143
|
+
if (!waitForPidGone(pid)) {
|
|
144
|
+
killPidHard(pid);
|
|
145
|
+
}
|
|
125
146
|
}
|
|
126
147
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
148
|
+
// Whatever is currently listening on a port, as pid + command line. Empty when
|
|
149
|
+
// the port is free, or when lsof is unavailable.
|
|
150
|
+
const getPortListeners = (port) => {
|
|
151
|
+
let pids = [];
|
|
152
|
+
try {
|
|
153
|
+
pids = execSync(`lsof -t -iTCP:${port} -sTCP:LISTEN`, {
|
|
154
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
155
|
+
})
|
|
156
|
+
.toString()
|
|
157
|
+
.split('\n')
|
|
158
|
+
.map((line) => Number(line.trim()))
|
|
159
|
+
.filter(Boolean);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return []; // lsof exits non-zero when nothing is listening
|
|
163
|
+
}
|
|
164
|
+
return pids.flatMap((pid) => {
|
|
130
165
|
try {
|
|
131
|
-
|
|
132
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
133
|
-
})
|
|
134
|
-
.toString()
|
|
135
|
-
.split('\n')
|
|
136
|
-
.map((line) => Number(line.trim()))
|
|
137
|
-
.filter(Boolean);
|
|
166
|
+
return [{ pid, command: execSync(`ps -p ${pid} -o command=`).toString().trim() }];
|
|
138
167
|
}
|
|
139
168
|
catch {
|
|
140
|
-
|
|
169
|
+
return []; // already gone
|
|
141
170
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Say what is holding these ports, without touching it.
|
|
175
|
+
*
|
|
176
|
+
* The other half of --keep-other-dev-servers: sparing a sibling checkout's dev
|
|
177
|
+
* server means this one cannot bind, and an unexplained EADDRINUSE is a worse
|
|
178
|
+
* experience than the silent kill it replaces. Naming the pid and the command
|
|
179
|
+
* turns "it just died" into something you can act on.
|
|
180
|
+
*
|
|
181
|
+
* Worded as a prediction, not a fact, because it IS one: this runs before the
|
|
182
|
+
* bundle step, so by the time anything binds - seconds later - the holder may
|
|
183
|
+
* well have gone. Stating "port in use" and then starting cleanly reads like
|
|
184
|
+
* the warning was wrong.
|
|
185
|
+
*/
|
|
186
|
+
export const reportPortHolders = (ports) => {
|
|
187
|
+
for (const port of ports) {
|
|
188
|
+
for (const { pid, command } of getPortListeners(port)) {
|
|
189
|
+
console.warn(`Port ${port} is currently held by pid ${pid}: ${command}`);
|
|
190
|
+
console.warn(` Starting anyway. If it still holds port ${port} once this server binds, startup will fail with EADDRINUSE.`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
export const killStaleListeners = (ports, isOurs) => {
|
|
195
|
+
for (const port of ports) {
|
|
196
|
+
for (const { pid, command } of getPortListeners(port)) {
|
|
150
197
|
if (isOurs(command)) {
|
|
151
198
|
console.log(`Killing stale dev server on port ${port} (pid ${pid})`);
|
|
152
199
|
process.kill(pid);
|
|
153
|
-
waitForPidGone(pid)
|
|
200
|
+
if (!waitForPidGone(pid)) {
|
|
201
|
+
killPidHard(pid);
|
|
202
|
+
}
|
|
154
203
|
}
|
|
155
204
|
else {
|
|
156
205
|
console.warn(`Port ${port} is in use by an unrelated process (pid ${pid}: ${command}) — not killing it.`);
|