@qpqjs/cli 0.4.0 → 0.5.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/lib/commonjs/cli/runCli.js +2 -2
- package/lib/commonjs/cli/runCli.js.map +1 -1
- package/lib/commonjs/commands/checkCircular.js +2 -2
- package/lib/commonjs/commands/checkCircular.js.map +1 -1
- package/lib/commonjs/commands/goDev.js +2 -2
- package/lib/commonjs/commands/goDev.js.map +1 -1
- package/lib/commonjs/commands/goDevApi.js +6 -5
- package/lib/commonjs/commands/goDevApi.js.map +1 -1
- package/lib/commonjs/commands/goDevWeb.js +3 -3
- package/lib/commonjs/commands/goDevWeb.js.map +1 -1
- package/lib/commonjs/commands/goDocker.js +2 -2
- package/lib/commonjs/commands/goDocker.js.map +1 -1
- package/lib/commonjs/commands/hooks.js +2 -2
- package/lib/commonjs/commands/hooks.js.map +1 -1
- package/lib/commonjs/commands/migrate.js +2 -2
- package/lib/commonjs/commands/migrate.js.map +1 -1
- package/lib/commonjs/commands/prep.js +2 -2
- package/lib/commonjs/commands/prep.js.map +1 -1
- package/lib/commonjs/commands/scriptBuild.js +2 -2
- package/lib/commonjs/commands/scriptBuild.js.map +1 -1
- package/lib/commonjs/commands/scriptBuilderLayer.js +2 -2
- package/lib/commonjs/commands/scriptBuilderLayer.js.map +1 -1
- package/lib/commonjs/commands/scriptNew.js +2 -2
- package/lib/commonjs/commands/scriptNew.js.map +1 -1
- package/lib/commonjs/commands/setup.js +2 -2
- package/lib/commonjs/commands/setup.js.map +1 -1
- package/lib/commonjs/commands/synth.js +2 -2
- package/lib/commonjs/commands/synth.js.map +1 -1
- package/lib/commonjs/lib/{out.d.ts → Output.d.ts} +2 -1
- package/lib/commonjs/lib/Output.js +3 -0
- package/lib/commonjs/lib/Output.js.map +1 -0
- package/lib/commonjs/lib/clearResourcesPlan.js +2 -2
- package/lib/commonjs/lib/clearResourcesPlan.js.map +1 -1
- package/lib/commonjs/lib/createOutput.d.ts +2 -0
- package/lib/commonjs/lib/{out.js → createOutput.js} +13 -4
- package/lib/commonjs/lib/createOutput.js.map +1 -0
- package/lib/commonjs/lib/deployPrompts.js +3 -3
- package/lib/commonjs/lib/deployPrompts.js.map +1 -1
- package/lib/commonjs/lib/hooks.js +2 -2
- package/lib/commonjs/lib/hooks.js.map +1 -1
- package/lib/commonjs/lib/killChildWithEscalation.js +2 -2
- package/lib/commonjs/lib/killChildWithEscalation.js.map +1 -1
- package/lib/commonjs/lib/killStaleListeners.js +3 -3
- package/lib/commonjs/lib/killStaleListeners.js.map +1 -1
- package/lib/commonjs/lib/prompts.js +2 -2
- package/lib/commonjs/lib/prompts.js.map +1 -1
- package/lib/commonjs/lib/qpqConfigs.d.ts +1 -0
- package/lib/commonjs/lib/qpqConfigs.js +9 -4
- package/lib/commonjs/lib/qpqConfigs.js.map +1 -1
- package/lib/commonjs/lib/requireDriverCapability.js +2 -2
- package/lib/commonjs/lib/requireDriverCapability.js.map +1 -1
- package/lib/commonjs/lib/resolveAppSelection.js +3 -3
- package/lib/commonjs/lib/resolveAppSelection.js.map +1 -1
- package/lib/commonjs/lib/resolveDeployment.js +3 -3
- package/lib/commonjs/lib/resolveDeployment.js.map +1 -1
- package/lib/commonjs/lib/runCommand.js +2 -2
- package/lib/commonjs/lib/runCommand.js.map +1 -1
- package/lib/commonjs/lib/runTasks.js +2 -2
- package/lib/commonjs/lib/runTasks.js.map +1 -1
- package/lib/commonjs/lib/timing.js +2 -2
- package/lib/commonjs/lib/timing.js.map +1 -1
- package/lib/commonjs/lib/typeWatcher.js +3 -3
- package/lib/commonjs/lib/typeWatcher.js.map +1 -1
- package/lib/commonjs/lib/userScriptBuilderLayer.js +1 -1
- package/lib/commonjs/lib/userScriptBuilderLayer.js.map +1 -1
- package/lib/commonjs/platforms/aws/awsCredentials.js +2 -2
- package/lib/commonjs/platforms/aws/awsCredentials.js.map +1 -1
- package/lib/commonjs/platforms/aws/clearResources.js +4 -3
- package/lib/commonjs/platforms/aws/clearResources.js.map +1 -1
- package/lib/commonjs/platforms/aws/go.js +2 -2
- package/lib/commonjs/platforms/aws/go.js.map +1 -1
- package/lib/commonjs/platforms/aws/goDocker.js +2 -2
- package/lib/commonjs/platforms/aws/goDocker.js.map +1 -1
- package/lib/commonjs/platforms/aws/publish.js +2 -2
- package/lib/commonjs/platforms/aws/publish.js.map +1 -1
- package/lib/commonjs/platforms/aws/remote.js +2 -2
- package/lib/commonjs/platforms/aws/remote.js.map +1 -1
- package/lib/commonjs/platforms/aws/setup/buildGithubDeployRoleStep.js +2 -2
- package/lib/commonjs/platforms/aws/setup/buildGithubDeployRoleStep.js.map +1 -1
- package/lib/commonjs/platforms/aws/stacks.js +4 -8
- package/lib/commonjs/platforms/aws/stacks.js.map +1 -1
- package/lib/commonjs/platforms/aws/teardown.js +2 -2
- package/lib/commonjs/platforms/aws/teardown.js.map +1 -1
- package/lib/commonjs/platforms/aws/viewsSync.js +2 -2
- package/lib/commonjs/platforms/aws/viewsSync.js.map +1 -1
- package/lib/commonjs/platforms/docker/go.js +2 -2
- package/lib/commonjs/platforms/docker/go.js.map +1 -1
- package/lib/commonjs/platforms/docker/index.js +2 -2
- package/lib/commonjs/platforms/docker/index.js.map +1 -1
- package/lib/commonjs/platforms/index.js +2 -2
- package/lib/commonjs/platforms/index.js.map +1 -1
- package/lib/esm/cli/runCli.js +1 -1
- package/lib/esm/cli/runCli.js.map +1 -1
- package/lib/esm/commands/checkCircular.js +1 -1
- package/lib/esm/commands/checkCircular.js.map +1 -1
- package/lib/esm/commands/goDev.js +1 -1
- package/lib/esm/commands/goDev.js.map +1 -1
- package/lib/esm/commands/goDevApi.js +4 -4
- package/lib/esm/commands/goDevApi.js.map +1 -1
- package/lib/esm/commands/goDevWeb.js +2 -2
- package/lib/esm/commands/goDevWeb.js.map +1 -1
- package/lib/esm/commands/goDocker.js +1 -1
- package/lib/esm/commands/goDocker.js.map +1 -1
- package/lib/esm/commands/hooks.js +1 -1
- package/lib/esm/commands/hooks.js.map +1 -1
- package/lib/esm/commands/migrate.js +1 -1
- package/lib/esm/commands/migrate.js.map +1 -1
- package/lib/esm/commands/prep.js +1 -1
- package/lib/esm/commands/prep.js.map +1 -1
- package/lib/esm/commands/scriptBuild.js +1 -1
- package/lib/esm/commands/scriptBuild.js.map +1 -1
- package/lib/esm/commands/scriptBuilderLayer.js +1 -1
- package/lib/esm/commands/scriptBuilderLayer.js.map +1 -1
- package/lib/esm/commands/scriptNew.js +1 -1
- package/lib/esm/commands/scriptNew.js.map +1 -1
- package/lib/esm/commands/setup.js +1 -1
- package/lib/esm/commands/setup.js.map +1 -1
- package/lib/esm/commands/synth.js +1 -1
- package/lib/esm/commands/synth.js.map +1 -1
- package/lib/esm/lib/{out.d.ts → Output.d.ts} +2 -1
- package/lib/esm/lib/Output.js +2 -0
- package/lib/esm/lib/Output.js.map +1 -0
- package/lib/esm/lib/clearResourcesPlan.js +1 -1
- package/lib/esm/lib/clearResourcesPlan.js.map +1 -1
- package/lib/esm/lib/createOutput.d.ts +2 -0
- package/lib/esm/lib/{out.js → createOutput.js} +13 -4
- package/lib/esm/lib/createOutput.js.map +1 -0
- package/lib/esm/lib/deployPrompts.js +2 -2
- package/lib/esm/lib/deployPrompts.js.map +1 -1
- package/lib/esm/lib/hooks.js +1 -1
- package/lib/esm/lib/hooks.js.map +1 -1
- package/lib/esm/lib/killChildWithEscalation.js +1 -1
- package/lib/esm/lib/killChildWithEscalation.js.map +1 -1
- package/lib/esm/lib/killStaleListeners.js +2 -2
- package/lib/esm/lib/killStaleListeners.js.map +1 -1
- package/lib/esm/lib/prompts.js +1 -1
- package/lib/esm/lib/prompts.js.map +1 -1
- package/lib/esm/lib/qpqConfigs.d.ts +1 -0
- package/lib/esm/lib/qpqConfigs.js +7 -3
- package/lib/esm/lib/qpqConfigs.js.map +1 -1
- package/lib/esm/lib/requireDriverCapability.js +1 -1
- package/lib/esm/lib/requireDriverCapability.js.map +1 -1
- package/lib/esm/lib/resolveAppSelection.js +2 -2
- package/lib/esm/lib/resolveAppSelection.js.map +1 -1
- package/lib/esm/lib/resolveDeployment.js +2 -2
- package/lib/esm/lib/resolveDeployment.js.map +1 -1
- package/lib/esm/lib/runCommand.js +1 -1
- package/lib/esm/lib/runCommand.js.map +1 -1
- package/lib/esm/lib/runTasks.js +1 -1
- package/lib/esm/lib/runTasks.js.map +1 -1
- package/lib/esm/lib/timing.js +1 -1
- package/lib/esm/lib/timing.js.map +1 -1
- package/lib/esm/lib/typeWatcher.js +2 -2
- package/lib/esm/lib/typeWatcher.js.map +1 -1
- package/lib/esm/lib/userScriptBuilderLayer.js +1 -1
- package/lib/esm/lib/userScriptBuilderLayer.js.map +1 -1
- package/lib/esm/platforms/aws/awsCredentials.js +1 -1
- package/lib/esm/platforms/aws/awsCredentials.js.map +1 -1
- package/lib/esm/platforms/aws/clearResources.js +3 -2
- package/lib/esm/platforms/aws/clearResources.js.map +1 -1
- package/lib/esm/platforms/aws/go.js +1 -1
- package/lib/esm/platforms/aws/go.js.map +1 -1
- package/lib/esm/platforms/aws/goDocker.js +1 -1
- package/lib/esm/platforms/aws/goDocker.js.map +1 -1
- package/lib/esm/platforms/aws/publish.js +1 -1
- package/lib/esm/platforms/aws/publish.js.map +1 -1
- package/lib/esm/platforms/aws/remote.js +1 -1
- package/lib/esm/platforms/aws/remote.js.map +1 -1
- package/lib/esm/platforms/aws/setup/buildGithubDeployRoleStep.js +1 -1
- package/lib/esm/platforms/aws/setup/buildGithubDeployRoleStep.js.map +1 -1
- package/lib/esm/platforms/aws/stacks.js +5 -9
- package/lib/esm/platforms/aws/stacks.js.map +1 -1
- package/lib/esm/platforms/aws/teardown.js +1 -1
- package/lib/esm/platforms/aws/teardown.js.map +1 -1
- package/lib/esm/platforms/aws/viewsSync.js +1 -1
- package/lib/esm/platforms/aws/viewsSync.js.map +1 -1
- package/lib/esm/platforms/docker/go.js +1 -1
- package/lib/esm/platforms/docker/go.js.map +1 -1
- package/lib/esm/platforms/docker/index.js +1 -1
- package/lib/esm/platforms/docker/index.js.map +1 -1
- package/lib/esm/platforms/index.js +1 -1
- package/lib/esm/platforms/index.js.map +1 -1
- package/package.json +11 -11
- package/lib/commonjs/lib/out.js.map +0 -1
- package/lib/esm/lib/out.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/commands/setup.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,sCAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/commands/setup.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,sCAA0C;AAC1C,sDAAmD;AACnD,4CAAgD;AAChD,wEAAqE;AAGrE,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,OAAO,CAAC,CAAC;AAIlC,MAAM,WAAW,GAAG,CAAC,MAAkC,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;AAE5H,MAAM,cAAc,GAAG,CAAC,OAAsB,EAAQ,EAAE;IACtD,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1D,GAAG,CAAC,GAAG,CAAC,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC,CAAC;IACxE,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAO,KAAkB,EAA0B,EAAE;IACpE,MAAM,OAAO,GAAkB,EA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G,CAAC,qEAAqE,OAAO,iBAAiB,cAAc,EAAE,CAAC,CAAC;AACzH,CAAC,CAAA,CAAC;AAlCW,QAAA,YAAY,gBAkCvB","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 deployment'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 { Nullable } from '@qpqjs/core';\n\nimport { getArgValue } from '../lib/args';\nimport { createOutput } from '../lib/createOutput';\nimport { promptCheckbox } from '../lib/prompts';\nimport { resolveCommandContext } from '../lib/resolveCommandContext';\nimport { SetupCheckResult, SetupStep } from '../lib/setupStep';\n\nconst out = createOutput('setup');\n\ntype CheckedStep = { step: SetupStep; result: Nullable<SetupCheckResult> };\n\nconst statusLabel = (result: Nullable<SetupCheckResult>): 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 out.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[]): Nullable<SetupStep[]> => {\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 out.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, deploymentName, deployment, driver } = await resolveCommandContext(argv);\n\n // Nothing to set up is a normal outcome here, not a refused command.\n if (!driver.setupSteps) {\n out.log(`The '${deployment.platform}' platform has nothing to set up for deployment '${deploymentName}'.`);\n return;\n }\n\n const steps = await driver.setupSteps(appName, deploymentName);\n\n out.log(`\\nSetup for app '${appName}', deployment '${deploymentName}' (${deployment.platform})\\n`);\n const checked = await checkAll(steps);\n printChecklist(checked);\n out.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 out.log('Nothing selected.');\n return;\n }\n\n for (const step of toRun) {\n out.log(`\\n== ${step.name}\\n`);\n await step.run();\n }\n\n out.log('\\nSetup complete. Final state:\\n');\n printChecklist(await checkAll(steps));\n out.log(`\\nNext: deploy the services with npx qpq go:docker all all --app ${appName} --deployment ${deploymentName}`);\n};\n"]}
|
|
@@ -23,12 +23,12 @@ const core_1 = require("@qpqjs/core");
|
|
|
23
23
|
const fs_1 = __importDefault(require("fs"));
|
|
24
24
|
const path_1 = __importDefault(require("path"));
|
|
25
25
|
const args_1 = require("../lib/args");
|
|
26
|
+
const createOutput_1 = require("../lib/createOutput");
|
|
26
27
|
const discovery_1 = require("../lib/discovery");
|
|
27
|
-
const out_1 = require("../lib/out");
|
|
28
28
|
const qpqConfigs_1 = require("../lib/qpqConfigs");
|
|
29
29
|
const resolveAppSelection_1 = require("../lib/resolveAppSelection");
|
|
30
30
|
const resolveDeployment_1 = require("../lib/resolveDeployment");
|
|
31
|
-
const out = (0,
|
|
31
|
+
const out = (0, createOutput_1.createOutput)('synth');
|
|
32
32
|
const processConfig = (folderName, appName) => {
|
|
33
33
|
out.log(`Processing infrastructure: [${folderName}] for app [${appName}]`);
|
|
34
34
|
const qpqConfig = (0, qpqConfigs_1.loadServiceQpqConfig)(appName, folderName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synth.js","sourceRoot":"","sources":["../../../src/commands/synth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0EAA0E;AAC1E,uDAAuD;AACvD,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,6EAA6E;AAC7E,sCAAyF;AAEzF,4CAAoB;AACpB,gDAAwB;AAExB,sCAAgD;AAChD,gDAAwF;AACxF,
|
|
1
|
+
{"version":3,"file":"synth.js","sourceRoot":"","sources":["../../../src/commands/synth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0EAA0E;AAC1E,uDAAuD;AACvD,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,6EAA6E;AAC7E,sCAAyF;AAEzF,4CAAoB;AACpB,gDAAwB;AAExB,sCAAgD;AAChD,sDAAmD;AACnD,gDAAwF;AACxF,kDAAyD;AACzD,oEAAsF;AACtF,gEAA6D;AAE7D,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,OAAO,CAAC,CAAC;AAElC,MAAM,aAAa,GAAG,CAAC,UAAkB,EAAE,OAAe,EAAQ,EAAE;IAClE,GAAG,CAAC,GAAG,CAAC,+BAA+B,UAAU,cAAc,OAAO,GAAG,CAAC,CAAC;IAC3E,MAAM,SAAS,GAAG,IAAA,iCAAoB,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,mBAAY,CAAC,wBAAwB,CAAC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AAC;AACH,CAAC,CAAA,CAAC;AA9CW,QAAA,YAAY,gBA8CvB","sourcesContent":["// `qpq synth [service]`, synthesizes each backend service's QPQ config to\n// dist/apps/<app>/infrastructure/<module>-config.json.\n//\n// Runs with ts-node hooks registered (see runCli), which transpiles each\n// service's infrastructure.ts on require. Cross-package `@scope/*` imports\n// resolve through the workspace node_modules symlinks to already-built dist.\nimport { getInfrastructureConfigPath, qpqCoreUtils, QpqDeployEnvVar } from '@qpqjs/core';\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { getPositionalArgs } from '../lib/args';\nimport { createOutput } from '../lib/createOutput';\nimport { getAvailableApps, getRoot, getServiceNamesWithSubdir } from '../lib/discovery';\nimport { loadServiceQpqConfig } from '../lib/qpqConfigs';\nimport { getRequestedAppName, resolveAppSelection } from '../lib/resolveAppSelection';\nimport { resolveDeployment } from '../lib/resolveDeployment';\n\nconst out = createOutput('synth');\n\nconst processConfig = (folderName: string, appName: string): void => {\n out.log(`Processing infrastructure: [${folderName}] for app [${appName}]`);\n const qpqConfig = loadServiceQpqConfig(appName, folderName);\n const moduleName = qpqCoreUtils.getApplicationModuleName(qpqConfig);\n\n const directoryPath = getInfrastructureConfigPath(getRoot(), appName);\n fs.mkdirSync(directoryPath, { recursive: true });\n fs.writeFileSync(path.join(directoryPath, `${moduleName}-config.json`), JSON.stringify(qpqConfig, null, 2));\n out.log(` -> ${appName}/infrastructure/${moduleName}-config.json`);\n};\n\nexport const synthCommand = async (argv: string[]): Promise<void> => {\n const [specifiedServiceName] = getPositionalArgs(argv, ['--app', '--deployment']);\n\n let appNames: string[];\n if (specifiedServiceName && !getRequestedAppName(argv, QpqDeployEnvVar.deployAppName)) {\n // A bare service name is unambiguous, synth it in whichever app owns it.\n const appWithService = getAvailableApps().find((appName) => getServiceNamesWithSubdir(appName, 'service').includes(specifiedServiceName));\n if (!appWithService) {\n out.error(`Service '${specifiedServiceName}' not found in any app`);\n process.exit(1);\n }\n appNames = [appWithService];\n } else {\n const selection = await resolveAppSelection({ argv, envVar: QpqDeployEnvVar.deployAppName, allowAll: true });\n appNames = selection === 'all' ? getAvailableApps() : [selection];\n }\n\n out.log(`QPQ synthesizing apps: ${appNames.join(', ')}`);\n\n for (const appName of appNames) {\n // Service configs read the deployment env vars at require time, so the\n // deployment is resolved (and primed) before any infrastructure.ts loads.\n await resolveDeployment(argv, appName);\n\n // Validate a specified service against the app's discovered services before it\n // reaches loadServiceQpqConfig -> require, exactly as the bare-service-name branch\n // above does: an unchecked typo hits a cryptic module-resolution error and a `../`\n // value normalizes into an arbitrary require target.\n const appServices = getServiceNamesWithSubdir(appName, 'service');\n if (specifiedServiceName && !appServices.includes(specifiedServiceName)) {\n out.error(`Service '${specifiedServiceName}' not found in app '${appName}'`);\n process.exitCode = 1;\n continue;\n }\n\n const serviceNames = specifiedServiceName ? [specifiedServiceName] : appServices;\n\n for (const folderName of serviceNames) {\n try {\n processConfig(folderName, appName);\n } catch (error) {\n out.error(`Failed to process ${folderName} in ${appName}:`, error);\n process.exitCode = 1;\n }\n }\n }\n};\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
type Print = (...parts: unknown[]) => void;
|
|
2
|
+
/** The prefixed console every cli command prints through. */
|
|
2
3
|
export type Output = {
|
|
3
4
|
log: Print;
|
|
4
5
|
info: Print;
|
|
@@ -6,6 +7,6 @@ export type Output = {
|
|
|
6
7
|
error: Print;
|
|
7
8
|
time: (label: string) => void;
|
|
8
9
|
timeEnd: (label: string) => void;
|
|
10
|
+
rewriteLineAbove: (linesUp: number, text: string) => void;
|
|
9
11
|
};
|
|
10
|
-
export declare const createOutput: (area: string) => Output;
|
|
11
12
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Output.js","sourceRoot":"","sources":["../../../src/lib/Output.ts"],"names":[],"mappings":"","sourcesContent":["type Print = (...parts: unknown[]) => void;\n\n/** The prefixed console every cli command prints through. */\nexport type Output = {\n log: Print;\n info: Print;\n warn: Print;\n error: Print;\n // A named stopwatch, printed on end.\n time: (label: string) => void;\n timeEnd: (label: string) => void;\n // Rewrites a line printed `linesUp` rows above the cursor in place (a status chip appended to a row that is\n // already on screen), prefixed like every other line. Terminal only: the caller falls back to a plain line otherwise.\n rewriteLineAbove: (linesUp: number, text: string) => void;\n};\n"]}
|
|
@@ -18,12 +18,12 @@ exports.promptClearResourcesPlan = void 0;
|
|
|
18
18
|
// table every service declares against one owner) appears exactly once, on
|
|
19
19
|
// the service that owns it.
|
|
20
20
|
const core_1 = require("@qpqjs/core");
|
|
21
|
+
const createOutput_1 = require("./createOutput");
|
|
21
22
|
const discovery_1 = require("./discovery");
|
|
22
23
|
const getDeployTargetLabel_1 = require("./getDeployTargetLabel");
|
|
23
24
|
const prompts_1 = require("./prompts");
|
|
24
25
|
const qpqConfigs_1 = require("./qpqConfigs");
|
|
25
|
-
const
|
|
26
|
-
const out = (0, out_1.createOutput)('clear-resources-plan');
|
|
26
|
+
const out = (0, createOutput_1.createOutput)('clear-resources-plan');
|
|
27
27
|
// Every owned data resource across the app's services, in service order.
|
|
28
28
|
const getClearableResources = (appName) => {
|
|
29
29
|
const resources = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clearResourcesPlan.js","sourceRoot":"","sources":["../../../src/lib/clearResourcesPlan.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,yEAAyE;AACzE,yEAAyE;AACzE,6EAA6E;AAC7E,2EAA2E;AAC3E,4BAA4B;AAC5B,sCAA2C;AAE3C,2CAA8C;AAC9C,iEAA8D;AAC9D,uCAAkF;AAClF,6CAAoD;
|
|
1
|
+
{"version":3,"file":"clearResourcesPlan.js","sourceRoot":"","sources":["../../../src/lib/clearResourcesPlan.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,yEAAyE;AACzE,yEAAyE;AACzE,6EAA6E;AAC7E,2EAA2E;AAC3E,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,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,IAAA,sBAAY,EAAC,0CAA0C,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;IAEvG,MAAM,SAAS,GAAG,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC;IAEzG,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,GAAG,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACtC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC/B,CAAC;IAED,GAAG,CAAC,GAAG,CAAC,mDAAmD,SAAS,CAAC,MAAM,oBAAoB,UAAU,IAAI,CAAC,CAAC;IAC/G,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,OAAO,MAAM,QAAQ,CAAC,YAAY,KAAK,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC;IACzH,CAAC;IAED,IAAI,CAAC,CAAC,MAAM,IAAA,iCAAuB,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACnD,CAAC,CAAA,CAAC;AA7BW,QAAA,wBAAwB,4BA6BnC","sourcesContent":["// The question flow for `qpq clear-resources`: enumerate every service's OWNED\n// data resources (storage drives -> buckets, key value stores -> tables) from\n// its live qpq config, multi-select which to empty, then type the deploy\n// target back to confirm - emptying deletes stored data, so a y/n prompt\n// isn't enough friction. Owned-only so a cross-module ref (e.g. a membership\n// table every service declares against one owner) appears exactly once, on\n// the service that owns it.\nimport { qpqCoreUtils } from '@qpqjs/core';\n\nimport { createOutput } from './createOutput';\nimport { getServiceNames } from './discovery';\nimport { getDeployTargetLabel } from './getDeployTargetLabel';\nimport { promptCheckbox, promptSelect, promptTypedConfirmation } from './prompts';\nimport { loadServiceQpqConfig } from './qpqConfigs';\n\nconst out = createOutput('clear-resources-plan');\n\nexport type ClearableResourceKind = 'storageDrive' | 'keyValueStore';\n\nexport type ClearableResource = {\n service: string;\n kind: ClearableResourceKind;\n // The config-level resource name (e.g. 'templateTestAssets', 'userTenantLinks');\n // the platform driver resolves it to the concrete runtime name (bucket/table).\n resourceName: string;\n};\n\nexport type ClearResourcesPlan =\n | { kind: 'cancelled' }\n // Empty (not destroy) the selected resources' stored data.\n | { kind: 'resources'; appName: string; resources: ClearableResource[] };\n\n// Every owned data resource across the app's services, in service order.\nconst getClearableResources = (appName: string): ClearableResource[] => {\n const resources: ClearableResource[] = [];\n\n for (const service of getServiceNames(appName)) {\n const qpqConfig = loadServiceQpqConfig(appName, service);\n\n for (const drive of qpqCoreUtils.getOwnedStorageDriveConfigs(qpqConfig)) {\n resources.push({ service, kind: 'storageDrive', resourceName: drive.storageDrive });\n }\n\n for (const store of qpqCoreUtils.getOwnedKeyValueStoreConfigs(qpqConfig)) {\n resources.push({ service, kind: 'keyValueStore', resourceName: store.keyValueStoreName });\n }\n }\n\n return resources;\n};\n\nconst BY_SERVICE = 'By service — empty everything the selected services own';\nconst BY_RESOURCE = 'By resource — pick individual buckets/tables';\n\n// Service mode: pick services, take every resource each one owns.\nconst pickByService = async (clearable: ClearableResource[]): Promise<ClearableResource[]> => {\n const services = [...new Set(clearable.map((resource) => resource.service))];\n\n const countFor = (service: string) => clearable.filter((resource) => resource.service === service).length;\n\n const picked = await promptCheckbox(\n 'Select services to EMPTY (every bucket/table the service owns)',\n services.map((service) => ({ name: `${service} (${countFor(service)} resources)`, value: service })),\n );\n\n return clearable.filter((resource) => picked.includes(resource.service));\n};\n\n// Resource mode: pick individual buckets/tables.\nconst pickByResource = (clearable: ClearableResource[]): Promise<ClearableResource[]> =>\n promptCheckbox(\n 'Select resources to EMPTY (all stored data will be deleted)',\n clearable.map((resource) => ({\n name: `${resource.service} — ${resource.resourceName} (${resource.kind === 'storageDrive' ? 'bucket' : 'table'})`,\n value: resource,\n })),\n );\n\nexport const promptClearResourcesPlan = async (appName: string): Promise<ClearResourcesPlan> => {\n const deployInfo = getDeployTargetLabel();\n\n const clearable = getClearableResources(appName);\n\n if (clearable.length === 0) {\n out.log('No storage drives or key value stores found in this app.');\n return { kind: 'cancelled' };\n }\n\n const mode = await promptSelect('How do you want to select what to empty?', [BY_SERVICE, BY_RESOURCE]);\n\n const resources = mode === BY_SERVICE ? await pickByService(clearable) : await pickByResource(clearable);\n\n if (resources.length === 0) {\n out.log('Nothing selected. Exiting!');\n return { kind: 'cancelled' };\n }\n\n out.log(`\\nThis will EMPTY (delete all stored data from) ${resources.length} resource(s) in [${deployInfo}]:`);\n for (const resource of resources) {\n out.log(` ${resource.service} — ${resource.resourceName} (${resource.kind === 'storageDrive' ? 'bucket' : 'table'})`);\n }\n\n if (!(await promptTypedConfirmation(deployInfo))) {\n return { kind: 'cancelled' };\n }\n\n return { kind: 'resources', appName, resources };\n};\n"]}
|
|
@@ -5,14 +5,20 @@ exports.createOutput = void 0;
|
|
|
5
5
|
// commands reads as one program. This is the only place the cli touches the console.
|
|
6
6
|
const createOutput = (area) => {
|
|
7
7
|
const prefix = `[qpq:${area}]`;
|
|
8
|
-
//
|
|
9
|
-
//
|
|
8
|
+
// Every line of a leading string gets the prefix, and a blank line stays blank, so a message with leading or
|
|
9
|
+
// embedded newlines reads as prefixed lines rather than a lone prefix followed by bare text.
|
|
10
|
+
const prefixLines = (text) => text
|
|
11
|
+
.split('\n')
|
|
12
|
+
.map((line) => (line === '' ? '' : `${prefix} ${line}`))
|
|
13
|
+
.join('\n');
|
|
14
|
+
// A leading string is prefixed line by line; anything else (an error, an object) is printed
|
|
15
|
+
// after the prefix as its own argument so the console keeps formatting it. The console method is
|
|
10
16
|
// looked up per call, not captured, so a test can spy on it after this module loads.
|
|
11
17
|
const withPrefix = (method) => {
|
|
12
18
|
return (...parts) => {
|
|
13
19
|
const [first, ...rest] = parts;
|
|
14
20
|
if (typeof first === 'string') {
|
|
15
|
-
return console[method](
|
|
21
|
+
return console[method](prefixLines(first), ...rest);
|
|
16
22
|
}
|
|
17
23
|
return console[method](prefix, ...parts);
|
|
18
24
|
};
|
|
@@ -24,7 +30,10 @@ const createOutput = (area) => {
|
|
|
24
30
|
error: withPrefix('error'),
|
|
25
31
|
time: (label) => console.time(`${prefix} ${label}`),
|
|
26
32
|
timeEnd: (label) => console.timeEnd(`${prefix} ${label}`),
|
|
33
|
+
rewriteLineAbove: (linesUp, text) => {
|
|
34
|
+
process.stdout.write(`\x1b[${linesUp}F\x1b[2K${prefixLines(text)}\x1b[${linesUp}E`);
|
|
35
|
+
},
|
|
27
36
|
};
|
|
28
37
|
};
|
|
29
38
|
exports.createOutput = createOutput;
|
|
30
|
-
//# sourceMappingURL=
|
|
39
|
+
//# sourceMappingURL=createOutput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOutput.js","sourceRoot":"","sources":["../../../src/lib/createOutput.ts"],"names":[],"mappings":";;;AAEA,6FAA6F;AAC7F,qFAAqF;AAC9E,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE;IACnD,MAAM,MAAM,GAAG,QAAQ,IAAI,GAAG,CAAC;IAE/B,6GAA6G;IAC7G,6FAA6F;IAC7F,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAC3C,IAAI;SACD,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC;SACvD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhB,4FAA4F;IAC5F,iGAAiG;IACjG,qFAAqF;IACrF,MAAM,UAAU,GAAG,CAAC,MAAyC,EAAyB,EAAE;QACtF,OAAO,CAAC,GAAG,KAAK,EAAE,EAAE;YAClB,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC;YAE/B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;YACtD,CAAC;YAED,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,EAAE,UAAU,CAAC,KAAK,CAAC;QACtB,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;QACxB,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;QACxB,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;QAC1B,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;QACnD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;QACzD,gBAAgB,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE;YAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,OAAO,WAAW,WAAW,CAAC,IAAI,CAAC,QAAQ,OAAO,GAAG,CAAC,CAAC;QACtF,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AArCW,QAAA,YAAY,gBAqCvB","sourcesContent":["import { Output } from './Output';\n\n// Every line the cli prints carries `[qpq:<area>]`, so output from the concurrent and nested\n// commands reads as one program. This is the only place the cli touches the console.\nexport const createOutput = (area: string): Output => {\n const prefix = `[qpq:${area}]`;\n\n // Every line of a leading string gets the prefix, and a blank line stays blank, so a message with leading or\n // embedded newlines reads as prefixed lines rather than a lone prefix followed by bare text.\n const prefixLines = (text: string): string =>\n text\n .split('\\n')\n .map((line) => (line === '' ? '' : `${prefix} ${line}`))\n .join('\\n');\n\n // A leading string is prefixed line by line; anything else (an error, an object) is printed\n // after the prefix as its own argument so the console keeps formatting it. The console method is\n // looked up per call, not captured, so a test can spy on it after this module loads.\n const withPrefix = (method: 'log' | 'info' | 'warn' | 'error'): Output[typeof method] => {\n return (...parts) => {\n const [first, ...rest] = parts;\n\n if (typeof first === 'string') {\n return console[method](prefixLines(first), ...rest);\n }\n\n return console[method](prefix, ...parts);\n };\n };\n\n return {\n log: withPrefix('log'),\n info: withPrefix('info'),\n warn: withPrefix('warn'),\n error: withPrefix('error'),\n time: (label) => console.time(`${prefix} ${label}`),\n timeEnd: (label) => console.timeEnd(`${prefix} ${label}`),\n rewriteLineAbove: (linesUp, text) => {\n process.stdout.write(`\\x1b[${linesUp}F\\x1b[2K${prefixLines(text)}\\x1b[${linesUp}E`);\n },\n };\n};\n"]}
|
|
@@ -11,12 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.promptTeardownPlan = exports.promptDeployPlan = exports.buildDeployPlanFromArgs = void 0;
|
|
13
13
|
const args_1 = require("./args");
|
|
14
|
+
const CliError_1 = require("./CliError");
|
|
15
|
+
const createOutput_1 = require("./createOutput");
|
|
14
16
|
const discovery_1 = require("./discovery");
|
|
15
17
|
const getDeployTargetLabel_1 = require("./getDeployTargetLabel");
|
|
16
18
|
const prompts_1 = require("./prompts");
|
|
17
|
-
const
|
|
18
|
-
const out_1 = require("./out");
|
|
19
|
-
const out = (0, out_1.createOutput)('deploy-prompts');
|
|
19
|
+
const out = (0, createOutput_1.createOutput)('deploy-prompts');
|
|
20
20
|
const STACK_TYPES = ['all', 'inf', 'api', 'web', 'views'];
|
|
21
21
|
// Non-interactive deploy plan from positional args: `qpq go <services> [stacks]`.
|
|
22
22
|
// services: 'all' | comma-separated service names | 'account' | 'domain' | 'bootstrap'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployPrompts.js","sourceRoot":"","sources":["../../../src/lib/deployPrompts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,iCAA2C;AAC3C,2CAA8C;AAC9C,iEAA8D;AAC9D,uCAA+E;AAC/E,yCAAsC;AACtC,+BAAqC;AAErC,MAAM,GAAG,GAAG,IAAA,kBAAY,EAAC,gBAAgB,CAAC,CAAC;AAI3C,MAAM,WAAW,GAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAgBvE,kFAAkF;AAClF,yFAAyF;AACzF,yEAAyE;AACzE,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AACzE,MAAM,uBAAuB,GAAG,CAAC,OAAe,EAAE,IAAc,EAAwB,EAAE;IAC/F,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,IAAA,wBAAiB,EAAC,IAAI,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;IAEpF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IACtC,CAAC;IACD,IAAI,WAAW,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC7D,CAAC;IACD,IAAI,WAAW,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,EAAE,IAAI,E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AAC,CAAC,MAAM,IAAA,iCAAuB,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACjD,CAAC,CAAA,CAAC;AA3BW,QAAA,kBAAkB,sBA2B7B","sourcesContent":["// The interactive question flow shared by `qpq go` (sequential AWS deploy) and\n// a future dockerized variant: pick an app, confirm the target, pick services\n// (or domain/bootstrap), pick stacks. buildDeployPlanFromArgs is the\n// non-interactive shortcut (`qpq go all all`) that skips every prompt.\nimport { Nullable } from '@qpqjs/core';\n\nimport { getPositionalArgs } from './args';\nimport { getServiceNames } from './discovery';\nimport { getDeployTargetLabel } from './getDeployTargetLabel';\nimport { promptSelect, promptTypedConfirmation, promptYesNo } from './prompts';\nimport { CliError } from './CliError';\nimport { createOutput } from './out';\n\nconst out = createOutput('deploy-prompts');\n\nexport type StackType = 'all' | 'inf' | 'api' | 'web' | 'views';\n\nconst STACK_TYPES: StackType[] = ['all', 'inf', 'api', 'web', 'views'];\n\nexport type DeployPlan =\n | { kind: 'cancelled' }\n // Deploy only the account-level guardrails stack (one per AWS account).\n | { kind: 'account'; appName: string }\n // Deploy the bootstrap stack (and optionally the domain stack first).\n | { kind: 'bootstrap'; appName: string; includeDomain: boolean }\n // Deploy the selected stacks for the selected services.\n | {\n kind: 'services';\n appName: string;\n services: string[];\n stacks: StackType;\n };\n\n// Non-interactive deploy plan from positional args: `qpq go <services> [stacks]`.\n// services: 'all' | comma-separated service names | 'account' | 'domain' | 'bootstrap'\n// stacks: all | inf | api | web | views (defaults to 'all')\n// Returns null when no positional services token is given, so callers fall back\n// to the interactive promptDeployPlan. Passing args is an explicit opt-in to a\n// prompt-free deploy, so the \"Deploying to: [env]\" confirmation is skipped too.\nexport const buildDeployPlanFromArgs = (appName: string, argv: string[]): Nullable<DeployPlan> => {\n const [servicesArg, stacksArg] = getPositionalArgs(argv, ['--app', '--deployment']);\n\n if (!servicesArg) {\n return null;\n }\n\n if (servicesArg === 'account') {\n return { kind: 'account', appName };\n }\n if (servicesArg === 'domain') {\n return { kind: 'bootstrap', appName, includeDomain: true };\n }\n if (servicesArg === 'bootstrap') {\n return { kind: 'bootstrap', appName, includeDomain: false };\n }\n\n const allServices = getServiceNames(appName);\n const services =\n servicesArg === 'all'\n ? allServices\n : servicesArg\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n\n const unknownServices = services.filter((service) => !allServices.includes(service));\n if (unknownServices.length > 0) {\n throw new CliError(`Unknown service(s): ${unknownServices.join(', ')}. Valid services: ${allServices.join(', ')}`);\n }\n\n const stacks = (stacksArg ?? 'all') as StackType;\n if (!STACK_TYPES.includes(stacks)) {\n throw new CliError(`Unknown stacks '${stacksArg}'. Valid stacks: ${STACK_TYPES.join(', ')}`);\n }\n\n return { kind: 'services', appName, services: [...new Set(services)], stacks };\n};\n\nexport const promptDeployPlan = async (appName: string): Promise<DeployPlan> => {\n const deployInfo = getDeployTargetLabel();\n\n if (!(await promptYesNo(`Deploying to: [${deployInfo}]`))) {\n out.log('Exiting!');\n return { kind: 'cancelled' };\n }\n\n let services: string[] = [];\n\n do {\n const allServices = getServiceNames(appName);\n\n // Bracketed so the meta options can't be mistaken for actual services.\n const allText = '[ all ]';\n const accountText = '[ account ]';\n const domainEnvText = '[ domain ]';\n const bootstrapEnvText = '[ bootstrap environment ]';\n\n const service = await promptSelect('Select services to deploy', [allText, ...allServices, accountText, domainEnvText, bootstrapEnvText]);\n\n if (service === allText) {\n services = allServices;\n break;\n }\n if (service === accountText) {\n return { kind: 'account', appName };\n }\n if (service === domainEnvText) {\n return { kind: 'bootstrap', appName, includeDomain: true };\n }\n if (service === bootstrapEnvText) {\n return { kind: 'bootstrap', appName, includeDomain: false };\n }\n\n services.push(service);\n } while (await promptYesNo('Do you want to deploy another service?'));\n\n services = [...new Set(services)];\n\n const stacks = (await promptSelect('Stacks to deploy', ['all', 'inf', 'api', 'web', 'views'])) as StackType;\n\n return { kind: 'services', appName, services, stacks };\n};\n\nexport type TeardownPlan =\n | { kind: 'cancelled' }\n // Destroy the web, api and inf stacks for the selected services.\n | { kind: 'services'; appName: string; services: string[] };\n\n// The question flow for `qpq teardown`: pick services, then type the deploy\n// target back to confirm, destroying inf stacks takes user data (key value\n// stores, user directories) with it, so a y/n prompt isn't enough friction.\nexport const promptTeardownPlan = async (appName: string): Promise<TeardownPlan> => {\n const deployInfo = getDeployTargetLabel();\n\n let services: string[] = [];\n\n do {\n const allServices = getServiceNames(appName);\n const allText = '[ all ]';\n\n const service = await promptSelect('Select services to tear down', [allText, ...allServices]);\n\n if (service === allText) {\n services = allServices;\n break;\n }\n\n services.push(service);\n } while (await promptYesNo('Do you want to tear down another service?'));\n\n services = [...new Set(services)];\n\n out.log(`\\nThis will DESTROY the web, api and inf stacks (including all stored data) for: ${services.join(', ')}`);\n if (!(await promptTypedConfirmation(deployInfo))) {\n return { kind: 'cancelled' };\n }\n\n return { kind: 'services', appName, services };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"deployPrompts.js","sourceRoot":"","sources":["../../../src/lib/deployPrompts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,iCAA2C;AAC3C,yCAAsC;AACtC,iDAA8C;AAC9C,2CAA8C;AAC9C,iEAA8D;AAC9D,uCAA+E;AAE/E,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,gBAAgB,CAAC,CAAC;AAI3C,MAAM,WAAW,GAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAgBvE,kFAAkF;AAClF,yFAAyF;AACzF,yEAAyE;AACzE,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AACzE,MAAM,uBAAuB,GAAG,CAAC,OAAe,EAAE,IAAc,EAAwB,EAAE;IAC/F,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,GA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A,sBAAY,EAAC,8BAA8B,EAAE,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC;QAE9F,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;YACxB,QAAQ,GAAG,WAAW,CAAC;YACvB,MAAM;QACR,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC,QAAQ,MAAM,IAAA,qBAAW,EAAC,2CAA2C,CAAC,EAAE;IAEzE,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAElC,GAAG,CAAC,GAAG,CAAC,oFAAoF,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnH,IAAI,CAAC,CAAC,MAAM,IAAA,iCAAuB,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACjD,CAAC,CAAA,CAAC;AA3BW,QAAA,kBAAkB,sBA2B7B","sourcesContent":["// The interactive question flow shared by `qpq go` (sequential AWS deploy) and\n// a future dockerized variant: pick an app, confirm the target, pick services\n// (or domain/bootstrap), pick stacks. buildDeployPlanFromArgs is the\n// non-interactive shortcut (`qpq go all all`) that skips every prompt.\nimport { Nullable } from '@qpqjs/core';\n\nimport { getPositionalArgs } from './args';\nimport { CliError } from './CliError';\nimport { createOutput } from './createOutput';\nimport { getServiceNames } from './discovery';\nimport { getDeployTargetLabel } from './getDeployTargetLabel';\nimport { promptSelect, promptTypedConfirmation, promptYesNo } from './prompts';\n\nconst out = createOutput('deploy-prompts');\n\nexport type StackType = 'all' | 'inf' | 'api' | 'web' | 'views';\n\nconst STACK_TYPES: StackType[] = ['all', 'inf', 'api', 'web', 'views'];\n\nexport type DeployPlan =\n | { kind: 'cancelled' }\n // Deploy only the account-level guardrails stack (one per AWS account).\n | { kind: 'account'; appName: string }\n // Deploy the bootstrap stack (and optionally the domain stack first).\n | { kind: 'bootstrap'; appName: string; includeDomain: boolean }\n // Deploy the selected stacks for the selected services.\n | {\n kind: 'services';\n appName: string;\n services: string[];\n stacks: StackType;\n };\n\n// Non-interactive deploy plan from positional args: `qpq go <services> [stacks]`.\n// services: 'all' | comma-separated service names | 'account' | 'domain' | 'bootstrap'\n// stacks: all | inf | api | web | views (defaults to 'all')\n// Returns null when no positional services token is given, so callers fall back\n// to the interactive promptDeployPlan. Passing args is an explicit opt-in to a\n// prompt-free deploy, so the \"Deploying to: [env]\" confirmation is skipped too.\nexport const buildDeployPlanFromArgs = (appName: string, argv: string[]): Nullable<DeployPlan> => {\n const [servicesArg, stacksArg] = getPositionalArgs(argv, ['--app', '--deployment']);\n\n if (!servicesArg) {\n return null;\n }\n\n if (servicesArg === 'account') {\n return { kind: 'account', appName };\n }\n if (servicesArg === 'domain') {\n return { kind: 'bootstrap', appName, includeDomain: true };\n }\n if (servicesArg === 'bootstrap') {\n return { kind: 'bootstrap', appName, includeDomain: false };\n }\n\n const allServices = getServiceNames(appName);\n const services =\n servicesArg === 'all'\n ? allServices\n : servicesArg\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n\n const unknownServices = services.filter((service) => !allServices.includes(service));\n if (unknownServices.length > 0) {\n throw new CliError(`Unknown service(s): ${unknownServices.join(', ')}. Valid services: ${allServices.join(', ')}`);\n }\n\n const stacks = (stacksArg ?? 'all') as StackType;\n if (!STACK_TYPES.includes(stacks)) {\n throw new CliError(`Unknown stacks '${stacksArg}'. Valid stacks: ${STACK_TYPES.join(', ')}`);\n }\n\n return { kind: 'services', appName, services: [...new Set(services)], stacks };\n};\n\nexport const promptDeployPlan = async (appName: string): Promise<DeployPlan> => {\n const deployInfo = getDeployTargetLabel();\n\n if (!(await promptYesNo(`Deploying to: [${deployInfo}]`))) {\n out.log('Exiting!');\n return { kind: 'cancelled' };\n }\n\n let services: string[] = [];\n\n do {\n const allServices = getServiceNames(appName);\n\n // Bracketed so the meta options can't be mistaken for actual services.\n const allText = '[ all ]';\n const accountText = '[ account ]';\n const domainEnvText = '[ domain ]';\n const bootstrapEnvText = '[ bootstrap environment ]';\n\n const service = await promptSelect('Select services to deploy', [allText, ...allServices, accountText, domainEnvText, bootstrapEnvText]);\n\n if (service === allText) {\n services = allServices;\n break;\n }\n if (service === accountText) {\n return { kind: 'account', appName };\n }\n if (service === domainEnvText) {\n return { kind: 'bootstrap', appName, includeDomain: true };\n }\n if (service === bootstrapEnvText) {\n return { kind: 'bootstrap', appName, includeDomain: false };\n }\n\n services.push(service);\n } while (await promptYesNo('Do you want to deploy another service?'));\n\n services = [...new Set(services)];\n\n const stacks = (await promptSelect('Stacks to deploy', ['all', 'inf', 'api', 'web', 'views'])) as StackType;\n\n return { kind: 'services', appName, services, stacks };\n};\n\nexport type TeardownPlan =\n | { kind: 'cancelled' }\n // Destroy the web, api and inf stacks for the selected services.\n | { kind: 'services'; appName: string; services: string[] };\n\n// The question flow for `qpq teardown`: pick services, then type the deploy\n// target back to confirm, destroying inf stacks takes user data (key value\n// stores, user directories) with it, so a y/n prompt isn't enough friction.\nexport const promptTeardownPlan = async (appName: string): Promise<TeardownPlan> => {\n const deployInfo = getDeployTargetLabel();\n\n let services: string[] = [];\n\n do {\n const allServices = getServiceNames(appName);\n const allText = '[ all ]';\n\n const service = await promptSelect('Select services to tear down', [allText, ...allServices]);\n\n if (service === allText) {\n services = allServices;\n break;\n }\n\n services.push(service);\n } while (await promptYesNo('Do you want to tear down another service?'));\n\n services = [...new Set(services)];\n\n out.log(`\\nThis will DESTROY the web, api and inf stacks (including all stored data) for: ${services.join(', ')}`);\n if (!(await promptTypedConfirmation(deployInfo))) {\n return { kind: 'cancelled' };\n }\n\n return { kind: 'services', appName, services };\n};\n"]}
|
|
@@ -15,11 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.runHookForAppPackages = exports.runHookForAllPackages = exports.runAppHook = void 0;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const createOutput_1 = require("./createOutput");
|
|
18
19
|
const discovery_1 = require("./discovery");
|
|
19
20
|
const runCommand_1 = require("./runCommand");
|
|
20
21
|
const runTasks_1 = require("./runTasks");
|
|
21
|
-
const
|
|
22
|
-
const out = (0, out_1.createOutput)('hooks');
|
|
22
|
+
const out = (0, createOutput_1.createOutput)('hooks');
|
|
23
23
|
// App lifecycle hooks: apps/<app>/package.json scripts named `qpq:<hook>`
|
|
24
24
|
// (e.g. qpq:postinstall, qpq:prebuild). The CLI invokes them when present;
|
|
25
25
|
// apps without the hook are skipped silently.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/lib/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,2CAA2F;AAC3F,6CAA+E;AAC/E,yCAA6D;AAC7D,+BAAqC;AAErC,MAAM,GAAG,GAAG,IAAA,kBAAY,EAAC,OAAO,CAAC,CAAC;AAoBlC,0EAA0E;AAC1E,2EAA2E;AAC3E,8CAA8C;AACvC,MAAM,UAAU,GAAG,CAAO,OAAe,EAAE,IAAY,EAAoB,EAAE;;IAClF,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,IAAA,2BAAe,EAAC,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC;IAC5E,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1E,MAAM,UAAU,GAAG,OAAO,IAAI,EAAE,CAAC;IACjC,IAAI,CAAC,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AAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AADjD,QAAA,qBAAqB,yBAC4B","sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport { getAppDirectory, getAppsDirectory, getAvailableApps, getRoot } from './discovery';\nimport { nextPrefixColor, runCommand, runCommandPrefixed } from './runCommand';\nimport { runDependencyTasks, TaskFailure } from './runTasks';\nimport { createOutput } from './out';\n\nconst out = createOutput('hooks');\n\ntype HookPackageJson = {\n name?: string;\n scripts?: Record<string, string>;\n workspaces?: string[];\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n};\n\n// A directory whose package.json can carry qpq:<hook> scripts: either an app\n// (apps/<app>/package.json, which need not be an npm workspace) or any package\n// matched by the consumer root's `workspaces` globs.\ntype HookPackage = {\n dir: string;\n label: string; // app name or package name, for display\n pkg: HookPackageJson;\n};\n\n// App lifecycle hooks: apps/<app>/package.json scripts named `qpq:<hook>`\n// (e.g. qpq:postinstall, qpq:prebuild). The CLI invokes them when present;\n// apps without the hook are skipped silently.\nexport const runAppHook = async (appName: string, hook: string): Promise<boolean> => {\n const packageJsonPath = path.join(getAppDirectory(appName), 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));\n const scriptName = `qpq:${hook}`;\n if (!packageJson.scripts?.[scriptName]) {\n return false;\n }\n\n out.log(`Running ${scriptName} for [${appName}]`);\n await runCommand('npm', ['run', scriptName], { cwd: getAppDirectory(appName) });\n return true;\n};\n\nconst isDirectory = (candidate: string): boolean => fs.existsSync(candidate) && fs.statSync(candidate).isDirectory();\n\nconst listSubdirectories = (dir: string): string[] => {\n if (!isDirectory(dir)) {\n return [];\n }\n return fs\n .readdirSync(dir)\n .map((name) => path.join(dir, name))\n .filter(isDirectory);\n};\n\n// Expand one `workspaces` glob. Only literal segments and bare `*` are\n// supported, which covers the patterns qpq repos use (e.g.\n// \"apps/*/services/*/models\"); anything fancier (\"**\", braces) matches nothing.\nconst expandWorkspacePattern = (root: string, pattern: string): string[] => {\n let dirs = [root];\n for (const segment of pattern.split('/')) {\n if (segment === '*') {\n dirs = dirs.flatMap(listSubdirectories);\n } else {\n dirs = dirs.map((dir) => path.join(dir, segment)).filter(isDirectory);\n }\n }\n return dirs;\n};\n\nconst readPackageJson = (dir: string): HookPackageJson | undefined => {\n const packageJsonPath = path.join(dir, 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return undefined;\n }\n return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as HookPackageJson;\n};\n\n// Every directory that can carry hooks: app dirs plus all workspace packages,\n// deduped (an app dir could itself be a workspace).\nconst getHookPackages = (): HookPackage[] => {\n const root = getRoot();\n const rootPkg = readPackageJson(root);\n\n const appDirs = getAvailableApps().map((appName) => ({ dir: getAppDirectory(appName), fallbackLabel: appName }));\n const workspaceDirs = (rootPkg?.workspaces ?? [])\n .flatMap((pattern) => expandWorkspacePattern(root, pattern))\n .map((dir) => ({ dir, fallbackLabel: path.relative(root, dir) }));\n\n const packages: HookPackage[] = [];\n const seen = new Set<string>();\n for (const { dir, fallbackLabel } of [...appDirs, ...workspaceDirs]) {\n const resolved = path.resolve(dir);\n if (seen.has(resolved)) {\n continue;\n }\n seen.add(resolved);\n\n const pkg = readPackageJson(dir);\n if (pkg) {\n packages.push({ dir, label: pkg.name ?? fallbackLabel, pkg });\n }\n }\n\n return packages;\n};\n\n// The script a hook resolves to in one package: `qpq:<hook>` when defined,\n// otherwise the plain `<hook>` script. Empty-string scripts count as absent.\nconst resolveHookScript = (pkg: HookPackageJson, hook: string): string | undefined => {\n if (pkg.scripts?.[`qpq:${hook}`]) {\n return `qpq:${hook}`;\n }\n if (pkg.scripts?.[hook]) {\n return hook;\n }\n return undefined;\n};\n\nconst getDeclaredDependencyNames = (pkg: HookPackageJson): string[] =>\n Object.keys({ ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies });\n\n// True for a package inside apps/<some other app>/. Packages outside apps/\n// are shared, so they never count as another app's.\nconst isOtherAppPackage = (dir: string, appName: string): boolean => {\n const relative = path.relative(getAppsDirectory(), path.resolve(dir));\n if (relative === '' || relative.startsWith('..') || path.isAbsolute(relative)) {\n return false;\n }\n return relative.split(path.sep)[0] !== appName;\n};\n\n// The app's own packages and the shared ones, plus every package they depend\n// on wherever it lives, so a cross-app dependency still gets built.\nconst getAppHookPackages = (appName: string): HookPackage[] => {\n const allPackages = getHookPackages();\n const byName = new Map<string, HookPackage>();\n for (const hookPackage of allPackages) {\n if (hookPackage.pkg.name) {\n byName.set(hookPackage.pkg.name, hookPackage);\n }\n }\n\n const selected = new Set(allPackages.filter((hookPackage) => !isOtherAppPackage(hookPackage.dir, appName)));\n const pending = [...selected];\n for (let current = pending.pop(); current; current = pending.pop()) {\n for (const depName of getDeclaredDependencyNames(current.pkg)) {\n const dep = byName.get(depName);\n if (dep && !selected.has(dep)) {\n selected.add(dep);\n pending.push(dep);\n }\n }\n }\n\n return allPackages.filter((hookPackage) => selected.has(hookPackage));\n};\n\n// Run the hook's script in each of `candidates` that defines it (qpq:<hook>\n// preferred over a plain <hook> script), in dependency order (declared deps\n// resolved by package name), with up to `jobs` running concurrently. Packages\n// whose dependencies aren't part of this run don't wait on them.\nconst runHookForPackages = async (candidates: HookPackage[], hook: string, jobs: number): Promise<TaskFailure[]> => {\n const hookPackages = candidates\n .map((candidate) => ({ ...candidate, scriptName: resolveHookScript(candidate.pkg, hook) }))\n .filter((candidate): candidate is HookPackage & { scriptName: string } => candidate.scriptName !== undefined);\n\n if (hookPackages.length === 0) {\n out.log(`No app or workspace package defines a \"qpq:${hook}\" or \"${hook}\" script, nothing to run.`);\n return [];\n }\n\n // Dependency edges only count between packages that are part of this run:\n // a dep that doesn't define the hook has nothing to wait for.\n const runSetNames = new Set(hookPackages.map((hookPackage) => hookPackage.pkg.name).filter(Boolean));\n\n const tasks = hookPackages.map((hookPackage) => ({\n id: hookPackage.pkg.name ?? hookPackage.dir,\n label: hookPackage.label,\n deps: getDeclaredDependencyNames(hookPackage.pkg).filter((name) => runSetNames.has(name) && name !== hookPackage.pkg.name),\n run: () => runCommandPrefixed(hookPackage.label, 'npm', ['run', hookPackage.scriptName], { cwd: hookPackage.dir, color: nextPrefixColor() }),\n }));\n\n out.log(`Running ${hook} hooks in ${tasks.length} package(s) (${jobs} jobs, dependency ordered)`);\n return runDependencyTasks(tasks, jobs);\n};\n\n/** Runs a hook in every app and workspace package that defines it. Returns the failures; callers decide fatality. */\nexport const runHookForAllPackages = (hook: string, jobs: number): Promise<TaskFailure[]> => runHookForPackages(getHookPackages(), hook, jobs);\n\n/**\n * Runs a hook in one app's packages, the shared packages outside apps/, and anything those depend on.\n * Other apps' packages are skipped. Returns the failures; callers decide fatality.\n */\nexport const runHookForAppPackages = (hook: string, appName: string, jobs: number): Promise<TaskFailure[]> =>\n runHookForPackages(getAppHookPackages(appName), hook, jobs);\n"]}
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/lib/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,iDAA8C;AAC9C,2CAA2F;AAC3F,6CAA+E;AAC/E,yCAA6D;AAE7D,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,OAAO,CAAC,CAAC;AAoBlC,0EAA0E;AAC1E,2EAA2E;AAC3E,8CAA8C;AACvC,MAAM,UAAU,GAAG,CAAO,OAAe,EAAE,IAAY,EAAoB,EAAE;;IAClF,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,IAAA,2BAAe,EAAC,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC;IAC5E,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,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AC,CAAC;AAAlI,QAAA,qBAAqB,yBAA6G;AAE/I;;;GAGG;AACI,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,IAAY,EAA0B,EAAE,CAC3G,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AADjD,QAAA,qBAAqB,yBAC4B","sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport { createOutput } from './createOutput';\nimport { getAppDirectory, getAppsDirectory, getAvailableApps, getRoot } from './discovery';\nimport { nextPrefixColor, runCommand, runCommandPrefixed } from './runCommand';\nimport { runDependencyTasks, TaskFailure } from './runTasks';\n\nconst out = createOutput('hooks');\n\ntype HookPackageJson = {\n name?: string;\n scripts?: Record<string, string>;\n workspaces?: string[];\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n};\n\n// A directory whose package.json can carry qpq:<hook> scripts: either an app\n// (apps/<app>/package.json, which need not be an npm workspace) or any package\n// matched by the consumer root's `workspaces` globs.\ntype HookPackage = {\n dir: string;\n label: string; // app name or package name, for display\n pkg: HookPackageJson;\n};\n\n// App lifecycle hooks: apps/<app>/package.json scripts named `qpq:<hook>`\n// (e.g. qpq:postinstall, qpq:prebuild). The CLI invokes them when present;\n// apps without the hook are skipped silently.\nexport const runAppHook = async (appName: string, hook: string): Promise<boolean> => {\n const packageJsonPath = path.join(getAppDirectory(appName), 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));\n const scriptName = `qpq:${hook}`;\n if (!packageJson.scripts?.[scriptName]) {\n return false;\n }\n\n out.log(`Running ${scriptName} for [${appName}]`);\n await runCommand('npm', ['run', scriptName], { cwd: getAppDirectory(appName) });\n return true;\n};\n\nconst isDirectory = (candidate: string): boolean => fs.existsSync(candidate) && fs.statSync(candidate).isDirectory();\n\nconst listSubdirectories = (dir: string): string[] => {\n if (!isDirectory(dir)) {\n return [];\n }\n return fs\n .readdirSync(dir)\n .map((name) => path.join(dir, name))\n .filter(isDirectory);\n};\n\n// Expand one `workspaces` glob. Only literal segments and bare `*` are\n// supported, which covers the patterns qpq repos use (e.g.\n// \"apps/*/services/*/models\"); anything fancier (\"**\", braces) matches nothing.\nconst expandWorkspacePattern = (root: string, pattern: string): string[] => {\n let dirs = [root];\n for (const segment of pattern.split('/')) {\n if (segment === '*') {\n dirs = dirs.flatMap(listSubdirectories);\n } else {\n dirs = dirs.map((dir) => path.join(dir, segment)).filter(isDirectory);\n }\n }\n return dirs;\n};\n\nconst readPackageJson = (dir: string): HookPackageJson | undefined => {\n const packageJsonPath = path.join(dir, 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return undefined;\n }\n return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as HookPackageJson;\n};\n\n// Every directory that can carry hooks: app dirs plus all workspace packages,\n// deduped (an app dir could itself be a workspace).\nconst getHookPackages = (): HookPackage[] => {\n const root = getRoot();\n const rootPkg = readPackageJson(root);\n\n const appDirs = getAvailableApps().map((appName) => ({ dir: getAppDirectory(appName), fallbackLabel: appName }));\n const workspaceDirs = (rootPkg?.workspaces ?? [])\n .flatMap((pattern) => expandWorkspacePattern(root, pattern))\n .map((dir) => ({ dir, fallbackLabel: path.relative(root, dir) }));\n\n const packages: HookPackage[] = [];\n const seen = new Set<string>();\n for (const { dir, fallbackLabel } of [...appDirs, ...workspaceDirs]) {\n const resolved = path.resolve(dir);\n if (seen.has(resolved)) {\n continue;\n }\n seen.add(resolved);\n\n const pkg = readPackageJson(dir);\n if (pkg) {\n packages.push({ dir, label: pkg.name ?? fallbackLabel, pkg });\n }\n }\n\n return packages;\n};\n\n// The script a hook resolves to in one package: `qpq:<hook>` when defined,\n// otherwise the plain `<hook>` script. Empty-string scripts count as absent.\nconst resolveHookScript = (pkg: HookPackageJson, hook: string): string | undefined => {\n if (pkg.scripts?.[`qpq:${hook}`]) {\n return `qpq:${hook}`;\n }\n if (pkg.scripts?.[hook]) {\n return hook;\n }\n return undefined;\n};\n\nconst getDeclaredDependencyNames = (pkg: HookPackageJson): string[] =>\n Object.keys({ ...pkg.dependencies, ...pkg.devDependencies, ...pkg.peerDependencies });\n\n// True for a package inside apps/<some other app>/. Packages outside apps/\n// are shared, so they never count as another app's.\nconst isOtherAppPackage = (dir: string, appName: string): boolean => {\n const relative = path.relative(getAppsDirectory(), path.resolve(dir));\n if (relative === '' || relative.startsWith('..') || path.isAbsolute(relative)) {\n return false;\n }\n return relative.split(path.sep)[0] !== appName;\n};\n\n// The app's own packages and the shared ones, plus every package they depend\n// on wherever it lives, so a cross-app dependency still gets built.\nconst getAppHookPackages = (appName: string): HookPackage[] => {\n const allPackages = getHookPackages();\n const byName = new Map<string, HookPackage>();\n for (const hookPackage of allPackages) {\n if (hookPackage.pkg.name) {\n byName.set(hookPackage.pkg.name, hookPackage);\n }\n }\n\n const selected = new Set(allPackages.filter((hookPackage) => !isOtherAppPackage(hookPackage.dir, appName)));\n const pending = [...selected];\n for (let current = pending.pop(); current; current = pending.pop()) {\n for (const depName of getDeclaredDependencyNames(current.pkg)) {\n const dep = byName.get(depName);\n if (dep && !selected.has(dep)) {\n selected.add(dep);\n pending.push(dep);\n }\n }\n }\n\n return allPackages.filter((hookPackage) => selected.has(hookPackage));\n};\n\n// Run the hook's script in each of `candidates` that defines it (qpq:<hook>\n// preferred over a plain <hook> script), in dependency order (declared deps\n// resolved by package name), with up to `jobs` running concurrently. Packages\n// whose dependencies aren't part of this run don't wait on them.\nconst runHookForPackages = async (candidates: HookPackage[], hook: string, jobs: number): Promise<TaskFailure[]> => {\n const hookPackages = candidates\n .map((candidate) => ({ ...candidate, scriptName: resolveHookScript(candidate.pkg, hook) }))\n .filter((candidate): candidate is HookPackage & { scriptName: string } => candidate.scriptName !== undefined);\n\n if (hookPackages.length === 0) {\n out.log(`No app or workspace package defines a \"qpq:${hook}\" or \"${hook}\" script, nothing to run.`);\n return [];\n }\n\n // Dependency edges only count between packages that are part of this run:\n // a dep that doesn't define the hook has nothing to wait for.\n const runSetNames = new Set(hookPackages.map((hookPackage) => hookPackage.pkg.name).filter(Boolean));\n\n const tasks = hookPackages.map((hookPackage) => ({\n id: hookPackage.pkg.name ?? hookPackage.dir,\n label: hookPackage.label,\n deps: getDeclaredDependencyNames(hookPackage.pkg).filter((name) => runSetNames.has(name) && name !== hookPackage.pkg.name),\n run: () => runCommandPrefixed(hookPackage.label, 'npm', ['run', hookPackage.scriptName], { cwd: hookPackage.dir, color: nextPrefixColor() }),\n }));\n\n out.log(`Running ${hook} hooks in ${tasks.length} package(s) (${jobs} jobs, dependency ordered)`);\n return runDependencyTasks(tasks, jobs);\n};\n\n/** Runs a hook in every app and workspace package that defines it. Returns the failures; callers decide fatality. */\nexport const runHookForAllPackages = (hook: string, jobs: number): Promise<TaskFailure[]> => runHookForPackages(getHookPackages(), hook, jobs);\n\n/**\n * Runs a hook in one app's packages, the shared packages outside apps/, and anything those depend on.\n * Other apps' packages are skipped. Returns the failures; callers decide fatality.\n */\nexport const runHookForAppPackages = (hook: string, appName: string, jobs: number): Promise<TaskFailure[]> =>\n runHookForPackages(getAppHookPackages(appName), hook, jobs);\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.killChildWithEscalation = void 0;
|
|
4
|
-
const
|
|
5
|
-
const out = (0,
|
|
4
|
+
const createOutput_1 = require("./createOutput");
|
|
5
|
+
const out = (0, createOutput_1.createOutput)('kill-child-with-escalation');
|
|
6
6
|
// Above the dev server's 5s worst-case shutdown budget, below docker's 10s
|
|
7
7
|
// default stop grace, so a container stop still exits cleanly rather than
|
|
8
8
|
// being SIGKILLed by docker mid-escalation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"killChildWithEscalation.js","sourceRoot":"","sources":["../../../src/lib/killChildWithEscalation.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"killChildWithEscalation.js","sourceRoot":"","sources":["../../../src/lib/killChildWithEscalation.ts"],"names":[],"mappings":";;;AAWA,iDAA8C;AAE9C,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,4BAA4B,CAAC,CAAC;AAEvD,2EAA2E;AAC3E,0EAA0E;AAC1E,4CAA4C;AAC5C,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC;;;;;;;GAOG;AACI,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,GAAG,CAAC,IAAI,CAAC,kCAAkC,OAAO,uBAAuB,CAAC,CAAC;YAC3E,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;AAlBW,QAAA,uBAAuB,2BAkBlC","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\nimport { createOutput } from './createOutput';\n\nconst out = createOutput('kill-child-with-escalation');\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 out.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"]}
|
|
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.killStaleListeners = exports.reportPortHolders = exports.killOtherQpqDevProcesses = exports.isQpqCliCommand = void 0;
|
|
7
|
-
const runCommand_1 = require("./runCommand");
|
|
8
7
|
const fs_1 = __importDefault(require("fs"));
|
|
9
8
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const createOutput_1 = require("./createOutput");
|
|
10
|
+
const runCommand_1 = require("./runCommand");
|
|
11
|
+
const out = (0, createOutput_1.createOutput)('kill-stale-listeners');
|
|
12
12
|
// Matches any invocation of the qpq CLI itself, regardless of how it was
|
|
13
13
|
// launched: `node node_modules/.bin/qpq ...` (the npm-script shim, which has
|
|
14
14
|
// no .js extension), a direct `node .../lib/commonjs/bin/qpq.js` call, a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"killStaleListeners.js","sourceRoot":"","sources":["../../../src/lib/killStaleListeners.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAgE;AAShE,4CAAoB;AACpB,gDAAwB;AACxB,+BAAqC;AAErC,MAAM,GAAG,GAAG,IAAA,kBAAY,EAAC,sBAAsB,CAAC,CAAC;AAEjD,yEAAyE;AACzE,6EAA6E;AAC7E,yEAAyE;AACzE,6EAA6E;AAC7E,mEAAmE;AACnE,4DAA4D;AACrD,MAAM,eAAe,GAAG,CAAC,OAAe,EAAW,EAAE,CAC1D,OAAO;KACJ,IAAI,EAAE;KACN,KAAK,CAAC,KAAK,CAAC;KACZ,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;IACd,MAAM,IAAI,GAAG,cAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,OAAO,UAAU,KAAK,KAAK,CAAC;AAC9B,CAAC,CAAC,CAAC;AARM,QAAA,eAAe,mBAQrB;AAEP,yEAAyE;AACzE,2EAA2E;AAC3E,2EAA2E;AAC3E,sEAAsE;AACtE,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,uEAAuE;AACvE,4EAA4E;AAC5E,2EAA2E;AAC3E,+CAA+C;AAC/C,EAAE;AACF,+EAA+E;AAC/E,0EAA0E;AAC1E,4EAA4E;AAC5E,+EAA+E;AAC/E,8CAA8C;AAC9C,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,SAAS,GAAG,IAAI,EAAW,EAAE;IAChE,MAAM,QAAQ,GAA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AM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YACtD,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpB,GAAG,CAAC,GAAG,CAAC,oCAAoC,IAAI,SAAS,GAAG,GAAG,CAAC,CAAC;gBACjE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;oBACzB,WAAW,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,2CAA2C,GAAG,KAAK,OAAO,qBAAqB,CAAC,CAAC;YACxG,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B","sourcesContent":["import { runCommandCaptureSync, sleepSync } from './runCommand';\n// Pre-start sweep shared by the dev-server commands: a previous run whose\n// wrapper died without killing its listener (closed terminal, SIGKILL) leaves\n// an orphaned process holding a dev port, and the next launch dies with\n// EADDRINUSE. Before starting, kill any listener on the given ports whose\n// command line matches `isOurs`. Anything else on the ports is left alone\n// and reported, it's not ours.\nimport { Nullable } from '@qpqjs/core';\n\nimport fs from 'fs';\nimport path from 'path';\nimport { createOutput } from './out';\n\nconst out = createOutput('kill-stale-listeners');\n\n// Matches any invocation of the qpq CLI itself, regardless of how it was\n// launched: `node node_modules/.bin/qpq ...` (the npm-script shim, which has\n// no .js extension), a direct `node .../lib/commonjs/bin/qpq.js` call, a\n// global `qpq` shebang script, etc. Checks each whitespace-separated token's\n// basename (extension stripped) rather than a fixed substring like\n// 'bin/qpq.js', which only matches the last of those forms.\nexport const isQpqCliCommand = (command: string): boolean =>\n command\n .trim()\n .split(/\\s+/)\n .some((token) => {\n const base = path.basename(token);\n const withoutExt = base.endsWith('.js') ? base.slice(0, -3) : base;\n return withoutExt === 'qpq';\n });\n\n// SIGTERM only requests termination, the caller (about to bind this same\n// process's ports itself) needs it actually gone first. A stale dev server\n// can be mid-startup when killed (still resolving config, not yet bound to\n// every port it eventually binds) and keep running for a bit past the\n// signal, going on to bind a LATER port, waiting for just the one port that\n// matched isn't enough; wait for the whole pid to disappear so it can't bind\n// anything else afterward. Poll synchronously (this whole sweep runs before\n// anything async starts) via `kill(pid, 0)`, reliable and fast here because\n// these are unrelated processes orphaned earlier, not children of this\n// one (a real child can sit as a zombie answering `kill(pid, 0)` until this\n// process's own event loop reaps it, which a tight sync loop would starve;\n// doesn't apply to a process we didn't spawn).\n//\n// The default covers the dev server's graceful shutdown (drain in-flight work,\n// then checkpoint the stores) with room to spare. Returns whether the pid\n// actually went, because a caller about to bind these ports has to escalate\n// rather than hope: giving up while the old server still holds 8080 is exactly\n// the EADDRINUSE this file exists to prevent.\nconst waitForPidGone = (pid: number, timeoutMs = 8000): boolean => {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n try {\n process.kill(pid, 0);\n } catch {\n return true; // throws once the pid no longer exists\n }\n sleepSync(50);\n }\n\n return false;\n};\n\n// Last resort for a process that ignored, or wedged during, its graceful stop.\nconst killPidHard = (pid: number): void => {\n out.warn(`Process ${pid} did not exit gracefully — sending SIGKILL.`);\n try {\n process.kill(pid, 'SIGKILL');\n } catch {\n return; // raced us and exited after all\n }\n waitForPidGone(pid, 2000);\n};\n\n// realpath'd: lsof reports the canonical path (e.g. /private/tmp on macOS,\n// where /tmp is a symlink), so comparing against a caller-supplied root\n// verbatim would false-negative whenever any component of the repo path is\n// itself a symlink (a symlinked home directory, an NFS mount, etc).\nconst getProcessCwd = (pid: number): Nullable<string> => {\n try {\n const line = runCommandCaptureSync('lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn'])\n .split('\\n')\n .find((l) => l.startsWith('n'));\n return line ? fs.realpathSync(line.slice(1)) : null;\n } catch {\n return null; // pid gone, or we don't have permission to inspect it\n }\n};\n\n// The sweep below must never target this process's own wrappers: launched as\n// `npx qpq go:dev:api` (or via any shell whose -c string names qpq), the\n// ancestor chain (`sh -c \"npx ... qpq ...\"`, `npm exec qpq ...`) matches\n// isQpqCliCommand and shares our cwd, so excluding just process.pid isn't\n// enough, SIGINTing an ancestor tears down our own tree. Walk ppid to the\n// top and exclude the whole chain.\nconst getOwnAncestorPids = (): Set<number> => {\n const ancestors = new Set<number>();\n let pid = process.pid;\n while (pid > 1 && !ancestors.has(pid)) {\n ancestors.add(pid);\n try {\n pid = Number(runCommandCaptureSync('ps', ['-o', 'ppid=', '-p', String(pid)]).trim());\n } catch {\n break;\n }\n }\n return ancestors;\n};\n\n// killStaleListeners only sees processes currently BOUND to one of the given\n// ports, it can't catch a still-running `qpq go:dev*` watcher whose spawned\n// dev-server child already died (a crash, or us killing just the child):\n// the watcher itself holds no port at that moment, so it's invisible to a\n// port scan, yet it's still alive and can spawn a fresh child, and bind a\n// port, moments later, racing whatever we're about to start. Close that gap\n// by finding any OTHER qpq CLI process rooted in the same repo checkout\n// (matched by cwd, not by port or command-line args, which vary by how it\n// was invoked) and killing it outright, regardless of what it currently has\n// bound. SIGINT (not SIGTERM) so goDevApiCommand/goDevWebCommand's own\n// handler runs and tears down its child cleanly rather than orphaning it.\nexport const killOtherQpqDevProcesses = (root: string): void => {\n const resolvedRoot = fs.realpathSync(root);\n const ownPids = getOwnAncestorPids();\n\n let lines: string[] = [];\n try {\n lines = runCommandCaptureSync('ps', ['-axo', 'pid=,command=']).split('\\n');\n } catch {\n return;\n }\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n\n const spaceIndex = trimmed.indexOf(' ');\n if (spaceIndex === -1) continue;\n\n const pid = Number(trimmed.slice(0, spaceIndex));\n const command = trimmed.slice(spaceIndex + 1).trim();\n\n if (!pid || ownPids.has(pid) || !isQpqCliCommand(command)) continue;\n if (getProcessCwd(pid) !== resolvedRoot) continue;\n\n out.log(`Killing other qpq dev process for this repo (pid ${pid}): ${command}`);\n process.kill(pid, 'SIGINT');\n if (!waitForPidGone(pid)) {\n killPidHard(pid);\n }\n }\n};\n\n// Whatever is currently listening on a port, as pid + command line. Empty when\n// the port is free, or when lsof is unavailable.\nconst getPortListeners = (port: number): { pid: number; command: string }[] => {\n let pids: number[] = [];\n try {\n pids = runCommandCaptureSync('lsof', ['-t', `-iTCP:${port}`, '-sTCP:LISTEN'])\n .split('\\n')\n .map((line) => Number(line.trim()))\n .filter(Boolean);\n } catch {\n return []; // lsof exits non-zero when nothing is listening\n }\n\n return pids.flatMap((pid) => {\n try {\n return [{ pid, command: runCommandCaptureSync('ps', ['-p', String(pid), '-o', 'command=']).trim() }];\n } catch {\n return []; // already gone\n }\n });\n};\n\n/**\n * Say what is holding these ports, without touching it.\n *\n * The other half of --keep-other-dev-servers: sparing a sibling checkout's dev\n * server means this one cannot bind, and an unexplained EADDRINUSE is a worse\n * experience than the silent kill it replaces. Naming the pid and the command\n * turns \"it just died\" into something you can act on.\n *\n * Worded as a prediction, not a fact, because it IS one: this runs before the\n * bundle step, so by the time anything binds - seconds later - the holder may\n * well have gone. Stating \"port in use\" and then starting cleanly reads like\n * the warning was wrong.\n */\nexport const reportPortHolders = (ports: number[]): void => {\n for (const port of ports) {\n for (const { pid, command } of getPortListeners(port)) {\n out.warn(`Port ${port} is currently held by pid ${pid}: ${command}`);\n out.warn(` Starting anyway. If it still holds port ${port} once this server binds, startup will fail with EADDRINUSE.`);\n }\n }\n};\n\nexport const killStaleListeners = (ports: number[], isOurs: (command: string) => boolean): void => {\n for (const port of ports) {\n for (const { pid, command } of getPortListeners(port)) {\n if (isOurs(command)) {\n out.log(`Killing stale dev server on port ${port} (pid ${pid})`);\n process.kill(pid);\n if (!waitForPidGone(pid)) {\n killPidHard(pid);\n }\n } else {\n out.warn(`Port ${port} is in use by an unrelated process (pid ${pid}: ${command}) — not killing it.`);\n }\n }\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"killStaleListeners.js","sourceRoot":"","sources":["../../../src/lib/killSta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AAC,oCAAoC,IAAI,SAAS,GAAG,GAAG,CAAC,CAAC;gBACjE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;oBACzB,WAAW,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,2CAA2C,GAAG,KAAK,OAAO,qBAAqB,CAAC,CAAC;YACxG,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAdW,QAAA,kBAAkB,sBAc7B","sourcesContent":["// Pre-start sweep shared by the dev-server commands: a previous run whose\n// wrapper died without killing its listener (closed terminal, SIGKILL) leaves\n// an orphaned process holding a dev port, and the next launch dies with\n// EADDRINUSE. Before starting, kill any listener on the given ports whose\n// command line matches `isOurs`. Anything else on the ports is left alone\n// and reported, it's not ours.\nimport { Nullable } from '@qpqjs/core';\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { createOutput } from './createOutput';\nimport { runCommandCaptureSync, sleepSync } from './runCommand';\n\nconst out = createOutput('kill-stale-listeners');\n\n// Matches any invocation of the qpq CLI itself, regardless of how it was\n// launched: `node node_modules/.bin/qpq ...` (the npm-script shim, which has\n// no .js extension), a direct `node .../lib/commonjs/bin/qpq.js` call, a\n// global `qpq` shebang script, etc. Checks each whitespace-separated token's\n// basename (extension stripped) rather than a fixed substring like\n// 'bin/qpq.js', which only matches the last of those forms.\nexport const isQpqCliCommand = (command: string): boolean =>\n command\n .trim()\n .split(/\\s+/)\n .some((token) => {\n const base = path.basename(token);\n const withoutExt = base.endsWith('.js') ? base.slice(0, -3) : base;\n return withoutExt === 'qpq';\n });\n\n// SIGTERM only requests termination, the caller (about to bind this same\n// process's ports itself) needs it actually gone first. A stale dev server\n// can be mid-startup when killed (still resolving config, not yet bound to\n// every port it eventually binds) and keep running for a bit past the\n// signal, going on to bind a LATER port, waiting for just the one port that\n// matched isn't enough; wait for the whole pid to disappear so it can't bind\n// anything else afterward. Poll synchronously (this whole sweep runs before\n// anything async starts) via `kill(pid, 0)`, reliable and fast here because\n// these are unrelated processes orphaned earlier, not children of this\n// one (a real child can sit as a zombie answering `kill(pid, 0)` until this\n// process's own event loop reaps it, which a tight sync loop would starve;\n// doesn't apply to a process we didn't spawn).\n//\n// The default covers the dev server's graceful shutdown (drain in-flight work,\n// then checkpoint the stores) with room to spare. Returns whether the pid\n// actually went, because a caller about to bind these ports has to escalate\n// rather than hope: giving up while the old server still holds 8080 is exactly\n// the EADDRINUSE this file exists to prevent.\nconst waitForPidGone = (pid: number, timeoutMs = 8000): boolean => {\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n try {\n process.kill(pid, 0);\n } catch {\n return true; // throws once the pid no longer exists\n }\n sleepSync(50);\n }\n\n return false;\n};\n\n// Last resort for a process that ignored, or wedged during, its graceful stop.\nconst killPidHard = (pid: number): void => {\n out.warn(`Process ${pid} did not exit gracefully — sending SIGKILL.`);\n try {\n process.kill(pid, 'SIGKILL');\n } catch {\n return; // raced us and exited after all\n }\n waitForPidGone(pid, 2000);\n};\n\n// realpath'd: lsof reports the canonical path (e.g. /private/tmp on macOS,\n// where /tmp is a symlink), so comparing against a caller-supplied root\n// verbatim would false-negative whenever any component of the repo path is\n// itself a symlink (a symlinked home directory, an NFS mount, etc).\nconst getProcessCwd = (pid: number): Nullable<string> => {\n try {\n const line = runCommandCaptureSync('lsof', ['-a', '-p', String(pid), '-d', 'cwd', '-Fn'])\n .split('\\n')\n .find((l) => l.startsWith('n'));\n return line ? fs.realpathSync(line.slice(1)) : null;\n } catch {\n return null; // pid gone, or we don't have permission to inspect it\n }\n};\n\n// The sweep below must never target this process's own wrappers: launched as\n// `npx qpq go:dev:api` (or via any shell whose -c string names qpq), the\n// ancestor chain (`sh -c \"npx ... qpq ...\"`, `npm exec qpq ...`) matches\n// isQpqCliCommand and shares our cwd, so excluding just process.pid isn't\n// enough, SIGINTing an ancestor tears down our own tree. Walk ppid to the\n// top and exclude the whole chain.\nconst getOwnAncestorPids = (): Set<number> => {\n const ancestors = new Set<number>();\n let pid = process.pid;\n while (pid > 1 && !ancestors.has(pid)) {\n ancestors.add(pid);\n try {\n pid = Number(runCommandCaptureSync('ps', ['-o', 'ppid=', '-p', String(pid)]).trim());\n } catch {\n break;\n }\n }\n return ancestors;\n};\n\n// killStaleListeners only sees processes currently BOUND to one of the given\n// ports, it can't catch a still-running `qpq go:dev*` watcher whose spawned\n// dev-server child already died (a crash, or us killing just the child):\n// the watcher itself holds no port at that moment, so it's invisible to a\n// port scan, yet it's still alive and can spawn a fresh child, and bind a\n// port, moments later, racing whatever we're about to start. Close that gap\n// by finding any OTHER qpq CLI process rooted in the same repo checkout\n// (matched by cwd, not by port or command-line args, which vary by how it\n// was invoked) and killing it outright, regardless of what it currently has\n// bound. SIGINT (not SIGTERM) so goDevApiCommand/goDevWebCommand's own\n// handler runs and tears down its child cleanly rather than orphaning it.\nexport const killOtherQpqDevProcesses = (root: string): void => {\n const resolvedRoot = fs.realpathSync(root);\n const ownPids = getOwnAncestorPids();\n\n let lines: string[] = [];\n try {\n lines = runCommandCaptureSync('ps', ['-axo', 'pid=,command=']).split('\\n');\n } catch {\n return;\n }\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n\n const spaceIndex = trimmed.indexOf(' ');\n if (spaceIndex === -1) continue;\n\n const pid = Number(trimmed.slice(0, spaceIndex));\n const command = trimmed.slice(spaceIndex + 1).trim();\n\n if (!pid || ownPids.has(pid) || !isQpqCliCommand(command)) continue;\n if (getProcessCwd(pid) !== resolvedRoot) continue;\n\n out.log(`Killing other qpq dev process for this repo (pid ${pid}): ${command}`);\n process.kill(pid, 'SIGINT');\n if (!waitForPidGone(pid)) {\n killPidHard(pid);\n }\n }\n};\n\n// Whatever is currently listening on a port, as pid + command line. Empty when\n// the port is free, or when lsof is unavailable.\nconst getPortListeners = (port: number): { pid: number; command: string }[] => {\n let pids: number[] = [];\n try {\n pids = runCommandCaptureSync('lsof', ['-t', `-iTCP:${port}`, '-sTCP:LISTEN'])\n .split('\\n')\n .map((line) => Number(line.trim()))\n .filter(Boolean);\n } catch {\n return []; // lsof exits non-zero when nothing is listening\n }\n\n return pids.flatMap((pid) => {\n try {\n return [{ pid, command: runCommandCaptureSync('ps', ['-p', String(pid), '-o', 'command=']).trim() }];\n } catch {\n return []; // already gone\n }\n });\n};\n\n/**\n * Say what is holding these ports, without touching it.\n *\n * The other half of --keep-other-dev-servers: sparing a sibling checkout's dev\n * server means this one cannot bind, and an unexplained EADDRINUSE is a worse\n * experience than the silent kill it replaces. Naming the pid and the command\n * turns \"it just died\" into something you can act on.\n *\n * Worded as a prediction, not a fact, because it IS one: this runs before the\n * bundle step, so by the time anything binds - seconds later - the holder may\n * well have gone. Stating \"port in use\" and then starting cleanly reads like\n * the warning was wrong.\n */\nexport const reportPortHolders = (ports: number[]): void => {\n for (const port of ports) {\n for (const { pid, command } of getPortListeners(port)) {\n out.warn(`Port ${port} is currently held by pid ${pid}: ${command}`);\n out.warn(` Starting anyway. If it still holds port ${port} once this server binds, startup will fail with EADDRINUSE.`);\n }\n }\n};\n\nexport const killStaleListeners = (ports: number[], isOurs: (command: string) => boolean): void => {\n for (const port of ports) {\n for (const { pid, command } of getPortListeners(port)) {\n if (isOurs(command)) {\n out.log(`Killing stale dev server on port ${port} (pid ${pid})`);\n process.kill(pid);\n if (!waitForPidGone(pid)) {\n killPidHard(pid);\n }\n } else {\n out.warn(`Port ${port} is in use by an unrelated process (pid ${pid}: ${command}) — not killing it.`);\n }\n }\n }\n};\n"]}
|
|
@@ -43,8 +43,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.promptCheckbox = exports.promptTypedConfirmation = exports.promptText = exports.promptYesNo = exports.promptSelectDetailed = exports.promptSelect = void 0;
|
|
46
|
-
const
|
|
47
|
-
const out = (0,
|
|
46
|
+
const createOutput_1 = require("./createOutput");
|
|
47
|
+
const out = (0, createOutput_1.createOutput)('prompts');
|
|
48
48
|
// Present a single-choice list prompt and return the selected value.
|
|
49
49
|
// @inquirer/prompts is imported lazily so commands only pay for it when
|
|
50
50
|
// actually prompting.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/lib/prompts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/lib/prompts.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA8C;AAE9C,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,SAAS,CAAC,CAAC;AACpC,qEAAqE;AACrE,wEAAwE;AACxE,sBAAsB;AACf,MAAM,YAAY,GAAG,CAAO,OAAe,EAAE,OAAiB,EAAE,aAAsB,EAAmB,EAAE;IAChH,MAAM,EAAE,MAAM,EAAE,GAAG,wDAAa,mBAAmB,GAAC,CAAC;IACrD,OAAO,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;AAC9D,CAAC,CAAA,CAAC;AAHW,QAAA,YAAY,gBAGvB;AAEF,wEAAwE;AACxE,6EAA6E;AAC7E,gEAAgE;AACzD,MAAM,oBAAoB,GAAG,CAClC,OAAe,EACf,OAA2E,EAC/D,EAAE;IACd,MAAM,EAAE,MAAM,EAAE,GAAG,wDAAa,mBAAmB,GAAC,CAAC;IACrD,OAAO,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AACtC,CAAC,CAAA,CAAC;AANW,QAAA,oBAAoB,wBAM/B;AAEF,kDAAkD;AAC3C,MAAM,WAAW,GAAG,CAAO,OAAe,EAAoB,EAAE,kDAAC,OAAA,CAAC,MAAM,IAAA,oBAAY,EAAC,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAA,GAAA,CAAC;AAAlH,QAAA,WAAW,eAAuG;AAE/H,8EAA8E;AAC9E,2DAA2D;AACpD,MAAM,UAAU,GAAG,CAAO,OAAe,EAAmB,EAAE;IACnE,MAAM,EAAE,KAAK,EAAE,GAAG,wDAAa,mBAAmB,GAAC,CAAC;IACpD,OAAO,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5B,CAAC,CAAA,CAAC;AAHW,QAAA,UAAU,cAGrB;AAEF,2FAA2F;AAC3F,qFAAqF;AAC9E,MAAM,uBAAuB,GAAG,CAAO,MAAc,EAAoB,EAAE;IAChF,MAAM,YAAY,GAAG,MAAM,IAAA,kBAAU,EAAC,SAAS,MAAM,cAAc,CAAC,CAAC;IAErE,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;QAC5B,GAAG,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAA,CAAC;AATW,QAAA,uBAAuB,2BASlC;AAEF,sFAAsF;AAC/E,MAAM,cAAc,GAAG,CAC5B,OAAe,EACf,OAA8E,EAChE,EAAE;IAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,wDAAa,mBAAmB,GAAC,CAAC;IACvD,OAAO,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AACxC,CAAC,CAAA,CAAC;AANW,QAAA,cAAc,kBAMzB","sourcesContent":["import { createOutput } from './createOutput';\n\nconst out = createOutput('prompts');\n// Present a single-choice list prompt and return the selected value.\n// @inquirer/prompts is imported lazily so commands only pay for it when\n// actually prompting.\nexport const promptSelect = async (message: string, choices: string[], defaultChoice?: string): Promise<string> => {\n const { select } = await import('@inquirer/prompts');\n return select({ message, choices, default: defaultChoice });\n};\n\n// A single-choice list prompt over labelled values; a choice's optional\n// `short` replaces its name in the answer line once picked, and its optional\n// `description` renders under the list while it is highlighted.\nexport const promptSelectDetailed = async <T>(\n message: string,\n choices: { name: string; value: T; short?: string; description?: string }[],\n): Promise<T> => {\n const { select } = await import('@inquirer/prompts');\n return select({ message, choices });\n};\n\n// A yes/no list prompt, returning true for \"Yes\".\nexport const promptYesNo = async (message: string): Promise<boolean> => (await promptSelect(message, ['No', 'Yes'])) === 'Yes';\n\n// A free-text prompt, used where a y/n is too easy to fat-finger (destructive\n// confirmations that require typing the target name back).\nexport const promptText = async (message: string): Promise<string> => {\n const { input } = await import('@inquirer/prompts');\n return input({ message });\n};\n\n// The friction for destructive commands: the target has to be typed back exactly. Resolves\n// true when it was; prints why it stops otherwise, so callers only have to bail out.\nexport const promptTypedConfirmation = async (target: string): Promise<boolean> => {\n const confirmation = await promptText(`Type '${target}' to confirm`);\n\n if (confirmation !== target) {\n out.log('Confirmation did not match. Exiting!');\n return false;\n }\n\n return true;\n};\n\n// A multi-select checkbox prompt over labelled values; `checked` preselects a choice.\nexport const promptCheckbox = async <T>(\n message: string,\n choices: { name: string; value: T; checked?: boolean; description?: string }[],\n): Promise<T[]> => {\n const { checkbox } = await import('@inquirer/prompts');\n return checkbox({ message, choices });\n};\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type QPQConfig } from '@qpqjs/core';
|
|
2
2
|
export declare const loadServiceQpqConfig: (appName: string, service: string) => QPQConfig;
|
|
3
|
+
export declare const loadFirstServiceQpqConfig: (appName: string) => QPQConfig;
|
|
3
4
|
export declare const getAppPrefix: (appName: string) => string;
|
|
4
5
|
export declare const getServiceNamesWithFederation: (appName: string, serviceNames: string[]) => string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getServiceNamesWithFederation = exports.getAppPrefix = exports.loadServiceQpqConfig = void 0;
|
|
3
|
+
exports.getServiceNamesWithFederation = exports.getAppPrefix = exports.loadFirstServiceQpqConfig = exports.loadServiceQpqConfig = void 0;
|
|
4
4
|
const core_1 = require("@qpqjs/core");
|
|
5
5
|
const deploy_aws_1 = require("@qpqjs/deploy-aws");
|
|
6
6
|
const discovery_1 = require("./discovery");
|
|
@@ -9,12 +9,17 @@ const discovery_1 = require("./discovery");
|
|
|
9
9
|
// workspace symlinks).
|
|
10
10
|
const loadServiceQpqConfig = (appName, service) => (0, deploy_aws_1.getWorkspaceServiceQpqConfig)((0, discovery_1.getRoot)(), appName, service);
|
|
11
11
|
exports.loadServiceQpqConfig = loadServiceQpqConfig;
|
|
12
|
-
|
|
12
|
+
// App-wide facts (the application name, the domain stack) live on every service's config alike, so the first
|
|
13
|
+
// service found stands in for the app. An app with no services has no config to read and that is an error.
|
|
14
|
+
const loadFirstServiceQpqConfig = (appName) => {
|
|
13
15
|
const [firstService] = (0, discovery_1.getServiceNames)(appName);
|
|
14
|
-
if (firstService === undefined)
|
|
16
|
+
if (firstService === undefined) {
|
|
15
17
|
throw new Error(`No services found for app ${appName}`);
|
|
16
|
-
|
|
18
|
+
}
|
|
19
|
+
return (0, exports.loadServiceQpqConfig)(appName, firstService);
|
|
17
20
|
};
|
|
21
|
+
exports.loadFirstServiceQpqConfig = loadFirstServiceQpqConfig;
|
|
22
|
+
const getAppPrefix = (appName) => core_1.qpqCoreUtils.getApplicationName((0, exports.loadFirstServiceQpqConfig)(appName));
|
|
18
23
|
exports.getAppPrefix = getAppPrefix;
|
|
19
24
|
// The subset of the given services that opt into module-federation publishing,
|
|
20
25
|
// i.e. declare defineFederatedModuleStore(...). Federation is a config setting,
|