@qpqjs/cli 0.3.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.
Files changed (292) hide show
  1. package/lib/commonjs/cli/commandMenu.js +5 -4
  2. package/lib/commonjs/cli/commandMenu.js.map +1 -1
  3. package/lib/commonjs/cli/runCli.js +15 -7
  4. package/lib/commonjs/cli/runCli.js.map +1 -1
  5. package/lib/commonjs/commands/checkCircular.js +15 -7
  6. package/lib/commonjs/commands/checkCircular.js.map +1 -1
  7. package/lib/commonjs/commands/clearResources.js +8 -14
  8. package/lib/commonjs/commands/clearResources.js.map +1 -1
  9. package/lib/commonjs/commands/go.js +3 -7
  10. package/lib/commonjs/commands/go.js.map +1 -1
  11. package/lib/commonjs/commands/goDev.js +4 -2
  12. package/lib/commonjs/commands/goDev.js.map +1 -1
  13. package/lib/commonjs/commands/goDevApi.js +27 -23
  14. package/lib/commonjs/commands/goDevApi.js.map +1 -1
  15. package/lib/commonjs/commands/goDevWeb.js +14 -9
  16. package/lib/commonjs/commands/goDevWeb.js.map +1 -1
  17. package/lib/commonjs/commands/goDocker.js +10 -13
  18. package/lib/commonjs/commands/goDocker.js.map +1 -1
  19. package/lib/commonjs/commands/hooks.js +4 -2
  20. package/lib/commonjs/commands/hooks.js.map +1 -1
  21. package/lib/commonjs/commands/migrate.js +11 -9
  22. package/lib/commonjs/commands/migrate.js.map +1 -1
  23. package/lib/commonjs/commands/prep.js +4 -2
  24. package/lib/commonjs/commands/prep.js.map +1 -1
  25. package/lib/commonjs/commands/publish.js +4 -7
  26. package/lib/commonjs/commands/publish.js.map +1 -1
  27. package/lib/commonjs/commands/scriptBuild.js +7 -5
  28. package/lib/commonjs/commands/scriptBuild.js.map +1 -1
  29. package/lib/commonjs/commands/scriptBuilderLayer.js +6 -4
  30. package/lib/commonjs/commands/scriptBuilderLayer.js.map +1 -1
  31. package/lib/commonjs/commands/scriptNew.js +7 -5
  32. package/lib/commonjs/commands/scriptNew.js.map +1 -1
  33. package/lib/commonjs/commands/setup.js +14 -22
  34. package/lib/commonjs/commands/setup.js.map +1 -1
  35. package/lib/commonjs/commands/synth.js +16 -20
  36. package/lib/commonjs/commands/synth.js.map +1 -1
  37. package/lib/commonjs/commands/teardown.js +8 -14
  38. package/lib/commonjs/commands/teardown.js.map +1 -1
  39. package/lib/commonjs/lib/CliError.d.ts +4 -0
  40. package/lib/commonjs/lib/CliError.js +14 -0
  41. package/lib/commonjs/lib/CliError.js.map +1 -0
  42. package/lib/commonjs/lib/Output.d.ts +12 -0
  43. package/lib/commonjs/lib/Output.js +3 -0
  44. package/lib/commonjs/lib/Output.js.map +1 -0
  45. package/lib/commonjs/lib/circularImports.d.ts +0 -1
  46. package/lib/commonjs/lib/circularImports.js +5 -6
  47. package/lib/commonjs/lib/circularImports.js.map +1 -1
  48. package/lib/commonjs/lib/clearResourcesPlan.d.ts +0 -1
  49. package/lib/commonjs/lib/clearResourcesPlan.js +12 -13
  50. package/lib/commonjs/lib/clearResourcesPlan.js.map +1 -1
  51. package/lib/commonjs/lib/createOutput.d.ts +2 -0
  52. package/lib/commonjs/lib/createOutput.js +39 -0
  53. package/lib/commonjs/lib/createOutput.js.map +1 -0
  54. package/lib/commonjs/lib/deployPrompts.d.ts +2 -1
  55. package/lib/commonjs/lib/deployPrompts.js +16 -16
  56. package/lib/commonjs/lib/deployPrompts.js.map +1 -1
  57. package/lib/commonjs/lib/devServerEntry.js +5 -4
  58. package/lib/commonjs/lib/devServerEntry.js.map +1 -1
  59. package/lib/commonjs/lib/devServerPorts.js +2 -4
  60. package/lib/commonjs/lib/devServerPorts.js.map +1 -1
  61. package/lib/commonjs/lib/discovery.d.ts +0 -2
  62. package/lib/commonjs/lib/discovery.js +11 -44
  63. package/lib/commonjs/lib/discovery.js.map +1 -1
  64. package/lib/commonjs/lib/hooks.js +5 -3
  65. package/lib/commonjs/lib/hooks.js.map +1 -1
  66. package/lib/commonjs/lib/killChildWithEscalation.js +3 -1
  67. package/lib/commonjs/lib/killChildWithEscalation.js.map +1 -1
  68. package/lib/commonjs/lib/killStaleListeners.js +24 -37
  69. package/lib/commonjs/lib/killStaleListeners.js.map +1 -1
  70. package/lib/commonjs/lib/prompts.d.ts +1 -0
  71. package/lib/commonjs/lib/prompts.js +15 -2
  72. package/lib/commonjs/lib/prompts.js.map +1 -1
  73. package/lib/commonjs/lib/qpqConfigs.d.ts +1 -0
  74. package/lib/commonjs/lib/qpqConfigs.js +11 -6
  75. package/lib/commonjs/lib/qpqConfigs.js.map +1 -1
  76. package/lib/commonjs/lib/requireDriverCapability.d.ts +7 -0
  77. package/lib/commonjs/lib/requireDriverCapability.js +17 -0
  78. package/lib/commonjs/lib/requireDriverCapability.js.map +1 -0
  79. package/lib/commonjs/lib/resolveAppSelection.d.ts +1 -0
  80. package/lib/commonjs/lib/resolveAppSelection.js +19 -12
  81. package/lib/commonjs/lib/resolveAppSelection.js.map +1 -1
  82. package/lib/commonjs/lib/resolveCommandContext.d.ts +12 -0
  83. package/lib/commonjs/lib/resolveCommandContext.js +26 -0
  84. package/lib/commonjs/lib/resolveCommandContext.js.map +1 -0
  85. package/lib/commonjs/lib/resolveDeployment.d.ts +0 -1
  86. package/lib/commonjs/lib/resolveDeployment.js +15 -10
  87. package/lib/commonjs/lib/resolveDeployment.js.map +1 -1
  88. package/lib/commonjs/lib/runCommand.d.ts +20 -0
  89. package/lib/commonjs/lib/runCommand.js +64 -34
  90. package/lib/commonjs/lib/runCommand.js.map +1 -1
  91. package/lib/commonjs/lib/runTasks.js +8 -4
  92. package/lib/commonjs/lib/runTasks.js.map +1 -1
  93. package/lib/commonjs/lib/timing.js +5 -3
  94. package/lib/commonjs/lib/timing.js.map +1 -1
  95. package/lib/commonjs/lib/typeWatcher.d.ts +2 -1
  96. package/lib/commonjs/lib/typeWatcher.js +6 -13
  97. package/lib/commonjs/lib/typeWatcher.js.map +1 -1
  98. package/lib/commonjs/lib/userScriptBuilderLayer.d.ts +0 -2
  99. package/lib/commonjs/lib/userScriptBuilderLayer.js +7 -8
  100. package/lib/commonjs/lib/userScriptBuilderLayer.js.map +1 -1
  101. package/lib/commonjs/lib/views.js +3 -2
  102. package/lib/commonjs/lib/views.js.map +1 -1
  103. package/lib/commonjs/lib/webAddressingEnv.d.ts +0 -2
  104. package/lib/commonjs/lib/webAddressingEnv.js +4 -4
  105. package/lib/commonjs/lib/webAddressingEnv.js.map +1 -1
  106. package/lib/commonjs/platforms/aws/awsCredentials.js +3 -1
  107. package/lib/commonjs/platforms/aws/awsCredentials.js.map +1 -1
  108. package/lib/commonjs/platforms/aws/cdkApp.js +1 -1
  109. package/lib/commonjs/platforms/aws/cdkApp.js.map +1 -1
  110. package/lib/commonjs/platforms/aws/clearResources.js +17 -26
  111. package/lib/commonjs/platforms/aws/clearResources.js.map +1 -1
  112. package/lib/commonjs/platforms/aws/getDeployEnv.d.ts +1 -0
  113. package/lib/commonjs/platforms/aws/getDeployEnv.js +12 -0
  114. package/lib/commonjs/platforms/aws/getDeployEnv.js.map +1 -0
  115. package/lib/commonjs/platforms/aws/go.js +17 -15
  116. package/lib/commonjs/platforms/aws/go.js.map +1 -1
  117. package/lib/commonjs/platforms/aws/goDocker.js +29 -26
  118. package/lib/commonjs/platforms/aws/goDocker.js.map +1 -1
  119. package/lib/commonjs/platforms/aws/goDockerManifest.js +6 -1
  120. package/lib/commonjs/platforms/aws/goDockerManifest.js.map +1 -1
  121. package/lib/commonjs/platforms/aws/publish.js +13 -11
  122. package/lib/commonjs/platforms/aws/publish.js.map +1 -1
  123. package/lib/commonjs/platforms/aws/remote.js +8 -7
  124. package/lib/commonjs/platforms/aws/remote.js.map +1 -1
  125. package/lib/commonjs/platforms/aws/setup/buildBucketNamesStep.js +4 -4
  126. package/lib/commonjs/platforms/aws/setup/buildBucketNamesStep.js.map +1 -1
  127. package/lib/commonjs/platforms/aws/setup/buildGithubDeployRoleStep.js +4 -3
  128. package/lib/commonjs/platforms/aws/setup/buildGithubDeployRoleStep.js.map +1 -1
  129. package/lib/commonjs/platforms/aws/stacks.d.ts +0 -1
  130. package/lib/commonjs/platforms/aws/stacks.js +17 -33
  131. package/lib/commonjs/platforms/aws/stacks.js.map +1 -1
  132. package/lib/commonjs/platforms/aws/teardown.js +9 -7
  133. package/lib/commonjs/platforms/aws/teardown.js.map +1 -1
  134. package/lib/commonjs/platforms/aws/viewsSync.js +23 -11
  135. package/lib/commonjs/platforms/aws/viewsSync.js.map +1 -1
  136. package/lib/commonjs/platforms/docker/go.js +20 -18
  137. package/lib/commonjs/platforms/docker/go.js.map +1 -1
  138. package/lib/commonjs/platforms/docker/index.js +5 -4
  139. package/lib/commonjs/platforms/docker/index.js.map +1 -1
  140. package/lib/commonjs/platforms/docker/parseMounts.js +3 -2
  141. package/lib/commonjs/platforms/docker/parseMounts.js.map +1 -1
  142. package/lib/commonjs/platforms/index.js +4 -2
  143. package/lib/commonjs/platforms/index.js.map +1 -1
  144. package/lib/commonjs/platforms/types.d.ts +2 -2
  145. package/lib/commonjs/platforms/types.js.map +1 -1
  146. package/lib/esm/cli/commandMenu.js +5 -4
  147. package/lib/esm/cli/commandMenu.js.map +1 -1
  148. package/lib/esm/cli/runCli.js +15 -7
  149. package/lib/esm/cli/runCli.js.map +1 -1
  150. package/lib/esm/commands/checkCircular.js +15 -7
  151. package/lib/esm/commands/checkCircular.js.map +1 -1
  152. package/lib/esm/commands/clearResources.js +8 -14
  153. package/lib/esm/commands/clearResources.js.map +1 -1
  154. package/lib/esm/commands/go.js +3 -7
  155. package/lib/esm/commands/go.js.map +1 -1
  156. package/lib/esm/commands/goDev.js +4 -2
  157. package/lib/esm/commands/goDev.js.map +1 -1
  158. package/lib/esm/commands/goDevApi.js +24 -21
  159. package/lib/esm/commands/goDevApi.js.map +1 -1
  160. package/lib/esm/commands/goDevWeb.js +13 -9
  161. package/lib/esm/commands/goDevWeb.js.map +1 -1
  162. package/lib/esm/commands/goDocker.js +10 -13
  163. package/lib/esm/commands/goDocker.js.map +1 -1
  164. package/lib/esm/commands/hooks.js +4 -2
  165. package/lib/esm/commands/hooks.js.map +1 -1
  166. package/lib/esm/commands/migrate.js +9 -7
  167. package/lib/esm/commands/migrate.js.map +1 -1
  168. package/lib/esm/commands/prep.js +4 -2
  169. package/lib/esm/commands/prep.js.map +1 -1
  170. package/lib/esm/commands/publish.js +4 -7
  171. package/lib/esm/commands/publish.js.map +1 -1
  172. package/lib/esm/commands/scriptBuild.js +7 -5
  173. package/lib/esm/commands/scriptBuild.js.map +1 -1
  174. package/lib/esm/commands/scriptBuilderLayer.js +6 -4
  175. package/lib/esm/commands/scriptBuilderLayer.js.map +1 -1
  176. package/lib/esm/commands/scriptNew.js +7 -5
  177. package/lib/esm/commands/scriptNew.js.map +1 -1
  178. package/lib/esm/commands/setup.js +14 -22
  179. package/lib/esm/commands/setup.js.map +1 -1
  180. package/lib/esm/commands/synth.js +18 -22
  181. package/lib/esm/commands/synth.js.map +1 -1
  182. package/lib/esm/commands/teardown.js +8 -14
  183. package/lib/esm/commands/teardown.js.map +1 -1
  184. package/lib/esm/lib/CliError.d.ts +4 -0
  185. package/lib/esm/lib/CliError.js +11 -0
  186. package/lib/esm/lib/CliError.js.map +1 -0
  187. package/lib/esm/lib/Output.d.ts +12 -0
  188. package/lib/esm/lib/Output.js +2 -0
  189. package/lib/esm/lib/Output.js.map +1 -0
  190. package/lib/esm/lib/circularImports.d.ts +0 -1
  191. package/lib/esm/lib/circularImports.js +4 -4
  192. package/lib/esm/lib/circularImports.js.map +1 -1
  193. package/lib/esm/lib/clearResourcesPlan.d.ts +0 -1
  194. package/lib/esm/lib/clearResourcesPlan.js +12 -12
  195. package/lib/esm/lib/clearResourcesPlan.js.map +1 -1
  196. package/lib/esm/lib/createOutput.d.ts +2 -0
  197. package/lib/esm/lib/createOutput.js +35 -0
  198. package/lib/esm/lib/createOutput.js.map +1 -0
  199. package/lib/esm/lib/deployPrompts.d.ts +2 -1
  200. package/lib/esm/lib/deployPrompts.js +17 -17
  201. package/lib/esm/lib/deployPrompts.js.map +1 -1
  202. package/lib/esm/lib/devServerEntry.js +5 -4
  203. package/lib/esm/lib/devServerEntry.js.map +1 -1
  204. package/lib/esm/lib/devServerPorts.js +2 -3
  205. package/lib/esm/lib/devServerPorts.js.map +1 -1
  206. package/lib/esm/lib/discovery.d.ts +0 -2
  207. package/lib/esm/lib/discovery.js +10 -38
  208. package/lib/esm/lib/discovery.js.map +1 -1
  209. package/lib/esm/lib/hooks.js +5 -3
  210. package/lib/esm/lib/hooks.js.map +1 -1
  211. package/lib/esm/lib/killChildWithEscalation.js +3 -1
  212. package/lib/esm/lib/killChildWithEscalation.js.map +1 -1
  213. package/lib/esm/lib/killStaleListeners.js +24 -37
  214. package/lib/esm/lib/killStaleListeners.js.map +1 -1
  215. package/lib/esm/lib/prompts.d.ts +1 -0
  216. package/lib/esm/lib/prompts.js +13 -1
  217. package/lib/esm/lib/prompts.js.map +1 -1
  218. package/lib/esm/lib/qpqConfigs.d.ts +1 -0
  219. package/lib/esm/lib/qpqConfigs.js +9 -5
  220. package/lib/esm/lib/qpqConfigs.js.map +1 -1
  221. package/lib/esm/lib/requireDriverCapability.d.ts +7 -0
  222. package/lib/esm/lib/requireDriverCapability.js +13 -0
  223. package/lib/esm/lib/requireDriverCapability.js.map +1 -0
  224. package/lib/esm/lib/resolveAppSelection.d.ts +1 -0
  225. package/lib/esm/lib/resolveAppSelection.js +17 -11
  226. package/lib/esm/lib/resolveAppSelection.js.map +1 -1
  227. package/lib/esm/lib/resolveCommandContext.d.ts +12 -0
  228. package/lib/esm/lib/resolveCommandContext.js +12 -0
  229. package/lib/esm/lib/resolveCommandContext.js.map +1 -0
  230. package/lib/esm/lib/resolveDeployment.d.ts +0 -1
  231. package/lib/esm/lib/resolveDeployment.js +13 -8
  232. package/lib/esm/lib/resolveDeployment.js.map +1 -1
  233. package/lib/esm/lib/runCommand.d.ts +20 -0
  234. package/lib/esm/lib/runCommand.js +52 -31
  235. package/lib/esm/lib/runCommand.js.map +1 -1
  236. package/lib/esm/lib/runTasks.js +8 -4
  237. package/lib/esm/lib/runTasks.js.map +1 -1
  238. package/lib/esm/lib/timing.js +5 -3
  239. package/lib/esm/lib/timing.js.map +1 -1
  240. package/lib/esm/lib/typeWatcher.d.ts +2 -1
  241. package/lib/esm/lib/typeWatcher.js +6 -13
  242. package/lib/esm/lib/typeWatcher.js.map +1 -1
  243. package/lib/esm/lib/userScriptBuilderLayer.d.ts +0 -2
  244. package/lib/esm/lib/userScriptBuilderLayer.js +5 -5
  245. package/lib/esm/lib/userScriptBuilderLayer.js.map +1 -1
  246. package/lib/esm/lib/views.js +3 -2
  247. package/lib/esm/lib/views.js.map +1 -1
  248. package/lib/esm/lib/webAddressingEnv.d.ts +0 -2
  249. package/lib/esm/lib/webAddressingEnv.js +1 -1
  250. package/lib/esm/lib/webAddressingEnv.js.map +1 -1
  251. package/lib/esm/platforms/aws/awsCredentials.js +3 -1
  252. package/lib/esm/platforms/aws/awsCredentials.js.map +1 -1
  253. package/lib/esm/platforms/aws/cdkApp.js +1 -1
  254. package/lib/esm/platforms/aws/cdkApp.js.map +1 -1
  255. package/lib/esm/platforms/aws/clearResources.js +18 -26
  256. package/lib/esm/platforms/aws/clearResources.js.map +1 -1
  257. package/lib/esm/platforms/aws/getDeployEnv.d.ts +1 -0
  258. package/lib/esm/platforms/aws/getDeployEnv.js +8 -0
  259. package/lib/esm/platforms/aws/getDeployEnv.js.map +1 -0
  260. package/lib/esm/platforms/aws/go.js +17 -15
  261. package/lib/esm/platforms/aws/go.js.map +1 -1
  262. package/lib/esm/platforms/aws/goDocker.js +29 -26
  263. package/lib/esm/platforms/aws/goDocker.js.map +1 -1
  264. package/lib/esm/platforms/aws/goDockerManifest.js +6 -1
  265. package/lib/esm/platforms/aws/goDockerManifest.js.map +1 -1
  266. package/lib/esm/platforms/aws/publish.js +13 -11
  267. package/lib/esm/platforms/aws/publish.js.map +1 -1
  268. package/lib/esm/platforms/aws/remote.js +9 -7
  269. package/lib/esm/platforms/aws/remote.js.map +1 -1
  270. package/lib/esm/platforms/aws/setup/buildBucketNamesStep.js +2 -2
  271. package/lib/esm/platforms/aws/setup/buildBucketNamesStep.js.map +1 -1
  272. package/lib/esm/platforms/aws/setup/buildGithubDeployRoleStep.js +4 -3
  273. package/lib/esm/platforms/aws/setup/buildGithubDeployRoleStep.js.map +1 -1
  274. package/lib/esm/platforms/aws/stacks.d.ts +0 -1
  275. package/lib/esm/platforms/aws/stacks.js +20 -32
  276. package/lib/esm/platforms/aws/stacks.js.map +1 -1
  277. package/lib/esm/platforms/aws/teardown.js +9 -7
  278. package/lib/esm/platforms/aws/teardown.js.map +1 -1
  279. package/lib/esm/platforms/aws/viewsSync.js +22 -10
  280. package/lib/esm/platforms/aws/viewsSync.js.map +1 -1
  281. package/lib/esm/platforms/docker/go.js +21 -19
  282. package/lib/esm/platforms/docker/go.js.map +1 -1
  283. package/lib/esm/platforms/docker/index.js +5 -4
  284. package/lib/esm/platforms/docker/index.js.map +1 -1
  285. package/lib/esm/platforms/docker/parseMounts.js +3 -2
  286. package/lib/esm/platforms/docker/parseMounts.js.map +1 -1
  287. package/lib/esm/platforms/index.js +4 -2
  288. package/lib/esm/platforms/index.js.map +1 -1
  289. package/lib/esm/platforms/types.d.ts +2 -2
  290. package/lib/esm/platforms/types.js.map +1 -1
  291. package/package.json +28 -15
  292. package/templates/user-script/README.md +1 -1
@@ -9,35 +9,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.resolveDeployment = exports.DEPLOYMENT_FLAG = void 0;
12
+ exports.resolveDeployment = void 0;
13
13
  const config_aws_1 = require("@qpqjs/config-aws");
14
14
  const core_1 = require("@qpqjs/core");
15
15
  const platforms_1 = require("../platforms");
16
16
  const args_1 = require("./args");
17
+ const CliError_1 = require("./CliError");
18
+ const createOutput_1 = require("./createOutput");
17
19
  const discovery_1 = require("./discovery");
18
20
  const prompts_1 = require("./prompts");
19
- exports.DEPLOYMENT_FLAG = '--deployment';
21
+ const out = (0, createOutput_1.createOutput)('resolve-deployment');
22
+ const DEPLOYMENT_FLAG = '--deployment';
20
23
  // Which entry to use: the flag, then DEPLOY_NAME (set by a parent qpq command or CI: a
21
24
  // selector, never a value), then the sole entry, then a prompt. Headless with several
22
25
  // entries and no selection is an error rather than a guess.
23
26
  const selectDeploymentName = (argv, appName, configuredNames) => __awaiter(void 0, void 0, void 0, function* () {
24
- const requested = (0, args_1.getArgValue)(argv, exports.DEPLOYMENT_FLAG) || process.env[core_1.QpqDeployEnvVar.deployName];
27
+ const requested = (0, args_1.getArgValue)(argv, DEPLOYMENT_FLAG) || process.env[core_1.QpqDeployEnvVar.deployName];
25
28
  if (requested) {
26
29
  if (!configuredNames.includes(requested)) {
27
- console.error(`Unknown deployment '${requested}' in ${(0, config_aws_1.getQpqAppDeployConfigPath)((0, discovery_1.getRoot)(), appName)}. Configured: ${configuredNames.join(', ')}`);
28
- process.exit(1);
30
+ throw new CliError_1.CliError(`Unknown deployment '${requested}' in ${(0, config_aws_1.getQpqAppDeployConfigPath)((0, discovery_1.getRoot)(), appName)}. Configured: ${configuredNames.join(', ')}`);
29
31
  }
30
32
  return requested;
31
33
  }
32
- if (configuredNames.length === 1) {
33
- console.log(`Using deployment: ${configuredNames[0]}`);
34
- return configuredNames[0];
34
+ const [onlyName] = configuredNames;
35
+ if (configuredNames.length === 1 && onlyName !== undefined) {
36
+ out.log(`Using deployment: ${onlyName}`);
37
+ return onlyName;
35
38
  }
36
39
  if (process.stdin.isTTY) {
37
40
  return (0, prompts_1.promptSelect)('Select deployment', configuredNames);
38
41
  }
39
- console.error(`No deployment selected. Pass ${exports.DEPLOYMENT_FLAG} <name>. Configured: ${configuredNames.join(', ')}`);
40
- return process.exit(1);
42
+ throw new CliError_1.CliError(`No deployment selected. Pass ${DEPLOYMENT_FLAG} <name>. Configured: ${configuredNames.join(', ')}`);
41
43
  });
42
44
  /**
43
45
  * Selects an entry of the app's deploy.config.json and writes it into process.env
@@ -50,6 +52,9 @@ const resolveDeployment = (argv, appName) => __awaiter(void 0, void 0, void 0, f
50
52
  const { deployments } = (0, config_aws_1.getQpqAppDeployConfig)((0, discovery_1.getRoot)(), appName);
51
53
  const deploymentName = yield selectDeploymentName(argv, appName, Object.keys(deployments));
52
54
  const deployment = deployments[deploymentName];
55
+ if (!deployment) {
56
+ throw new Error(`Deployment [${deploymentName}] is not in ${appName}'s deploy.config.json`);
57
+ }
53
58
  (0, config_aws_1.primeDeploymentEnv)(appName, deploymentName, deployment);
54
59
  (0, platforms_1.getPlatformDriver)(deployment.platform).prepareDeployment(deploymentName, deployment);
55
60
  return { deploymentName, deployment };
@@ -1 +1 @@
1
- {"version":3,"file":"resolveDeployment.js","sourceRoot":"","sources":["../../../src/lib/resolveDeployment.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAyG;AACzG,sCAAgE;AAEhE,4CAAiD;AACjD,iCAAqC;AACrC,2CAAsC;AACtC,uCAAyC;AAE5B,QAAA,eAAe,GAAG,cAAc,CAAC;AAO9C,uFAAuF;AACvF,sFAAsF;AACtF,4DAA4D;AAC5D,MAAM,oBAAoB,GAAG,CAAO,IAAc,EAAE,OAAe,EAAE,eAAyB,EAAmB,EAAE;IACjH,MAAM,SAAS,GAAG,IAAA,kBAAW,EAAC,IAAI,EAAE,uBAAe,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAe,CAAC,UAAU,CAAC,CAAC;IAEhG,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,OAAO,CAAC,KAAK,CAAC,uBAAuB,SAAS,QAAQ,IAAA,sCAAyB,EAAC,IAAA,mBAAO,GAAE,EAAE,OAAO,CAAC,iBAAiB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClJ,OAAO,CAAC,IAAI,CAAC,CAAC,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, primeDeploymentEnv } from '@qpqjs/config-aws';\nimport { QpqAppDeployment, QpqDeployEnvVar } from '@qpqjs/core';\n\nimport { getPlatformDriver } from '../platforms';\nimport { getArgValue } from './args';\nimport { getRoot } from './discovery';\nimport { promptSelect } from './prompts';\n\nexport const DEPLOYMENT_FLAG = '--deployment';\n\nexport type ResolvedDeployment = {\n deploymentName: string;\n deployment: QpqAppDeployment;\n};\n\n// Which entry to use: the flag, then DEPLOY_NAME (set by a parent qpq command or CI: a\n// selector, never a value), then the sole entry, then a prompt. Headless with several\n// entries and no selection is an error rather than a guess.\nconst selectDeploymentName = async (argv: string[], appName: string, configuredNames: string[]): Promise<string> => {\n const requested = getArgValue(argv, DEPLOYMENT_FLAG) || process.env[QpqDeployEnvVar.deployName];\n\n if (requested) {\n if (!configuredNames.includes(requested)) {\n console.error(`Unknown deployment '${requested}' in ${getQpqAppDeployConfigPath(getRoot(), appName)}. Configured: ${configuredNames.join(', ')}`);\n process.exit(1);\n }\n return requested;\n }\n\n if (configuredNames.length === 1) {\n console.log(`Using deployment: ${configuredNames[0]}`);\n return configuredNames[0];\n }\n\n if (process.stdin.isTTY) {\n return promptSelect('Select deployment', configuredNames);\n }\n\n console.error(`No deployment selected. Pass ${DEPLOYMENT_FLAG} <name>. Configured: ${configuredNames.join(', ')}`);\n return process.exit(1);\n};\n\n/**\n * Selects an entry of the app's deploy.config.json and writes it into process.env\n * (identity, environment, feature, settings) before any service config is loaded.\n * The file is the source of truth: nothing in the shell overrides a value in it.\n * The platform driver validates its own settings, so an aws entry missing its\n * account or region fails here, not inside cdk.\n */\nexport const resolveDeployment = async (argv: string[], appName: string): Promise<ResolvedDeployment> => {\n const { deployments } = getQpqAppDeployConfig(getRoot(), appName);\n const deploymentName = await selectDeploymentName(argv, appName, Object.keys(deployments));\n const deployment = deployments[deploymentName];\n\n primeDeploymentEnv(appName, deploymentName, deployment);\n getPlatformDriver(deployment.platform).prepareDeployment(deploymentName, deployment);\n\n return { deploymentName, deployment };\n};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,CAAC;IAC5D,CAAC;IAED,MAAM,IAAI,mBAAQ,CAAC,gCAAgC,eAAe,wBAAwB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1H,CAAC,CAAA,CAAC;AAEF;;;;;;GAMG;AACI,MAAM,iBAAiB,GAAG,CAAO,IAAc,EAAE,OAAe,EAA+B,EAAE;IACtG,MAAM,EAAE,WAAW,EAAE,GAAG,IAAA,kCAAqB,EAAC,IAAA,mBAAO,GAAE,EAAE,OAAO,CAAC,CAAC;IAClE,MAAM,cAAc,GAAG,MAAM,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAC3F,MAAM,UAAU,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,eAAe,cAAc,eAAe,OAAO,uBAAuB,CAAC,CAAC;IAC9F,CAAC;IAED,IAAA,+BAAkB,EAAC,OAAO,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;IACxD,IAAA,6BAAiB,EAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,iBAAiB,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAErF,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC;AACxC,CAAC,CAAA,CAAC;AAZW,QAAA,iBAAiB,qBAY5B","sourcesContent":["import { getQpqAppDeployConfig, getQpqAppDeployConfigPath, primeDeploymentEnv } from '@qpqjs/config-aws';\nimport { QpqAppDeployment, QpqDeployEnvVar } from '@qpqjs/core';\n\nimport { getPlatformDriver } from '../platforms';\nimport { getArgValue } from './args';\nimport { CliError } from './CliError';\nimport { createOutput } from './createOutput';\nimport { getRoot } from './discovery';\nimport { promptSelect } from './prompts';\n\nconst out = createOutput('resolve-deployment');\n\nconst DEPLOYMENT_FLAG = '--deployment';\n\nexport type ResolvedDeployment = {\n deploymentName: string;\n deployment: QpqAppDeployment;\n};\n\n// Which entry to use: the flag, then DEPLOY_NAME (set by a parent qpq command or CI: a\n// selector, never a value), then the sole entry, then a prompt. Headless with several\n// entries and no selection is an error rather than a guess.\nconst selectDeploymentName = async (argv: string[], appName: string, configuredNames: string[]): Promise<string> => {\n const requested = getArgValue(argv, DEPLOYMENT_FLAG) || process.env[QpqDeployEnvVar.deployName];\n\n if (requested) {\n if (!configuredNames.includes(requested)) {\n throw new CliError(\n `Unknown deployment '${requested}' in ${getQpqAppDeployConfigPath(getRoot(), appName)}. Configured: ${configuredNames.join(', ')}`,\n );\n }\n return requested;\n }\n\n const [onlyName] = configuredNames;\n if (configuredNames.length === 1 && onlyName !== undefined) {\n out.log(`Using deployment: ${onlyName}`);\n return onlyName;\n }\n\n if (process.stdin.isTTY) {\n return promptSelect('Select deployment', configuredNames);\n }\n\n throw new CliError(`No deployment selected. Pass ${DEPLOYMENT_FLAG} <name>. Configured: ${configuredNames.join(', ')}`);\n};\n\n/**\n * Selects an entry of the app's deploy.config.json and writes it into process.env\n * (identity, environment, feature, settings) before any service config is loaded.\n * The file is the source of truth: nothing in the shell overrides a value in it.\n * The platform driver validates its own settings, so an aws entry missing its\n * account or region fails here, not inside cdk.\n */\nexport const resolveDeployment = async (argv: string[], appName: string): Promise<ResolvedDeployment> => {\n const { deployments } = getQpqAppDeployConfig(getRoot(), appName);\n const deploymentName = await selectDeploymentName(argv, appName, Object.keys(deployments));\n const deployment = deployments[deploymentName];\n if (!deployment) {\n throw new Error(`Deployment [${deploymentName}] is not in ${appName}'s deploy.config.json`);\n }\n\n primeDeploymentEnv(appName, deploymentName, deployment);\n getPlatformDriver(deployment.platform).prepareDeployment(deploymentName, deployment);\n\n return { deploymentName, deployment };\n};\n"]}
@@ -1,8 +1,28 @@
1
+ import { ChildProcess, StdioOptions } from 'child_process';
1
2
  export type RunCommandOptions = {
2
3
  env?: Record<string, string>;
3
4
  cwd?: string;
4
5
  logCommand?: boolean;
5
6
  };
7
+ export type SpawnCommandOptions = RunCommandOptions & {
8
+ stdio?: StdioOptions;
9
+ };
10
+ /**
11
+ * Starts a long-running child (a dev server, a watcher) and hands back its handle; the caller
12
+ * owns its lifetime. Every process the cli starts goes through here or one of the runners
13
+ * below, so the shell and env rules are in one place.
14
+ */
15
+ export declare const spawnCommand: (command: string, args: string[], options?: SpawnCommandOptions) => ChildProcess;
16
+ /** Runs a command to completion, inheriting stdio; throws on a non-zero exit. For code that cannot await. */
17
+ export declare const runCommandSync: (command: string, args: string[], options?: RunCommandOptions) => void;
18
+ /**
19
+ * Runs a command to completion and returns its stdout (stderr is dropped); throws when it
20
+ * cannot start or exits non-zero. For the short probes (`ps`, `lsof`, `npm --version`) whose
21
+ * output decides what the cli does next.
22
+ */
23
+ export declare const runCommandCaptureSync: (command: string, args: string[], options?: RunCommandOptions) => string;
24
+ /** Blocks the current thread for `ms`; only for the short polls in synchronous cleanup code. */
25
+ export declare const sleepSync: (ms: number) => void;
6
26
  export declare const runCommand: (command: string, args: string[], options?: RunCommandOptions) => Promise<void>;
7
27
  export declare const runCommandBestEffort: (command: string, args: string[], options?: RunCommandOptions) => Promise<void>;
8
28
  export type RunCommandPrefixedOptions = {
@@ -1,25 +1,69 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runCommandPrefixed = exports.nextPrefixColor = exports.runCommandBestEffort = exports.runCommand = void 0;
3
+ exports.runCommandPrefixed = exports.nextPrefixColor = exports.runCommandBestEffort = exports.runCommand = exports.sleepSync = exports.runCommandCaptureSync = exports.runCommandSync = exports.spawnCommand = void 0;
4
4
  const child_process_1 = require("child_process");
5
+ const createOutput_1 = require("./createOutput");
6
+ const out = (0, createOutput_1.createOutput)('run-command');
7
+ // Shell only on Windows (to resolve npm/aws/cdk .cmd shims). On posix, run without a shell so
8
+ // the already-array args are passed straight to the program and can't be re-interpreted by
9
+ // `sh -c`, no command injection via interpolated values (stack names, CI-supplied env, etc.).
10
+ const useShell = process.platform === 'win32';
11
+ const toSpawnOptions = (options) => {
12
+ var _a, _b;
13
+ return ({
14
+ shell: useShell,
15
+ cwd: (_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd(),
16
+ env: Object.assign(Object.assign({}, process.env), ((_b = options.env) !== null && _b !== void 0 ? _b : {})),
17
+ });
18
+ };
19
+ /**
20
+ * Starts a long-running child (a dev server, a watcher) and hands back its handle; the caller
21
+ * owns its lifetime. Every process the cli starts goes through here or one of the runners
22
+ * below, so the shell and env rules are in one place.
23
+ */
24
+ const spawnCommand = (command, args, options = {}) => {
25
+ var _a;
26
+ return (0, child_process_1.spawn)(command, args.filter((a) => !!a), Object.assign({ stdio: (_a = options.stdio) !== null && _a !== void 0 ? _a : 'inherit' }, toSpawnOptions(options)));
27
+ };
28
+ exports.spawnCommand = spawnCommand;
29
+ /** Runs a command to completion, inheriting stdio; throws on a non-zero exit. For code that cannot await. */
30
+ const runCommandSync = (command, args, options = {}) => {
31
+ const validArgs = args.filter((a) => !!a);
32
+ const result = (0, child_process_1.spawnSync)(command, validArgs, Object.assign({ stdio: 'inherit' }, toSpawnOptions(options)));
33
+ if (result.error)
34
+ throw result.error;
35
+ if (result.status)
36
+ throw new Error(`${command} ${validArgs.join(' ')} exited with code ${result.status}`);
37
+ };
38
+ exports.runCommandSync = runCommandSync;
39
+ /**
40
+ * Runs a command to completion and returns its stdout (stderr is dropped); throws when it
41
+ * cannot start or exits non-zero. For the short probes (`ps`, `lsof`, `npm --version`) whose
42
+ * output decides what the cli does next.
43
+ */
44
+ const runCommandCaptureSync = (command, args, options = {}) => {
45
+ const validArgs = args.filter((a) => !!a);
46
+ const result = (0, child_process_1.spawnSync)(command, validArgs, Object.assign({ stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }, toSpawnOptions(options)));
47
+ if (result.error)
48
+ throw result.error;
49
+ if (result.status)
50
+ throw new Error(`${command} ${validArgs.join(' ')} exited with code ${result.status}`);
51
+ return result.stdout;
52
+ };
53
+ exports.runCommandCaptureSync = runCommandCaptureSync;
54
+ /** Blocks the current thread for `ms`; only for the short polls in synchronous cleanup code. */
55
+ const sleepSync = (ms) => {
56
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
57
+ };
58
+ exports.sleepSync = sleepSync;
5
59
  // Spawn a command, inheriting stdio, resolving on success. A non-zero exit
6
60
  // REJECTS so a failed build/deploy stops the run.
7
61
  const runCommand = (command, args, options = {}) => new Promise((resolve, reject) => {
8
- var _a, _b;
9
62
  const validArgs = args.filter((a) => !!a);
10
63
  if (options.logCommand) {
11
- console.log(`Running command: ${command} ${validArgs.join(' ')}`);
64
+ out.log(`Running command: ${command} ${validArgs.join(' ')}`);
12
65
  }
13
- const child = (0, child_process_1.spawn)(command, validArgs, {
14
- stdio: 'inherit',
15
- // Shell only on Windows (to resolve npm/aws/cdk .cmd shims). On posix, run
16
- // without a shell so the already-array args are passed straight to the
17
- // program and can't be re-interpreted by `sh -c` — no command injection via
18
- // interpolated values (stack names, CI-supplied env, etc.).
19
- shell: process.platform === 'win32',
20
- cwd: (_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd(),
21
- env: Object.assign(Object.assign({}, process.env), ((_b = options.env) !== null && _b !== void 0 ? _b : {})),
22
- });
66
+ const child = (0, exports.spawnCommand)(command, validArgs, options);
23
67
  child.on('error', (error) => reject(error));
24
68
  child.on('exit', (code, signal) => {
25
69
  if (signal)
@@ -31,18 +75,12 @@ const runCommand = (command, args, options = {}) => new Promise((resolve, reject
31
75
  });
32
76
  exports.runCommand = runCommand;
33
77
  // Run a command for its side effect only, swallowing both its output and its
34
- // exit code — for best-effort cleanup steps (e.g. `docker rm -f` of a container
78
+ // exit code, for best-effort cleanup steps (e.g. `docker rm -f` of a container
35
79
  // that may not exist) that must never fail the run. Without a shell there's no
36
80
  // `>/dev/null 2>&1 || true`, so quieting and non-failing happen here instead.
37
81
  const runCommandBestEffort = (command, args, options = {}) => new Promise((resolve) => {
38
- var _a, _b;
39
82
  const validArgs = args.filter((a) => !!a);
40
- const child = (0, child_process_1.spawn)(command, validArgs, {
41
- stdio: 'ignore',
42
- shell: process.platform === 'win32',
43
- cwd: (_a = options.cwd) !== null && _a !== void 0 ? _a : process.cwd(),
44
- env: Object.assign(Object.assign({}, process.env), ((_b = options.env) !== null && _b !== void 0 ? _b : {})),
45
- });
83
+ const child = (0, exports.spawnCommand)(command, validArgs, Object.assign(Object.assign({}, options), { stdio: 'ignore' }));
46
84
  child.on('error', () => resolve());
47
85
  child.on('exit', () => resolve());
48
86
  });
@@ -52,28 +90,20 @@ let colorIndex = 0;
52
90
  // Hand each concurrent task a distinct prefix color so interleaved output is
53
91
  // scannable.
54
92
  const nextPrefixColor = () => {
55
- const color = PREFIX_COLORS[colorIndex % PREFIX_COLORS.length];
93
+ var _a;
94
+ const color = (_a = PREFIX_COLORS[colorIndex % PREFIX_COLORS.length]) !== null && _a !== void 0 ? _a : 0;
56
95
  colorIndex += 1;
57
96
  return color;
58
97
  };
59
98
  exports.nextPrefixColor = nextPrefixColor;
60
99
  // Like runCommand, but pipes output and prefixes every line with a colored
61
- // [label] — for running many commands concurrently without unreadable
100
+ // [label], for running many commands concurrently without unreadable
62
101
  // interleaving. Rejects on non-zero exit.
63
102
  const runCommandPrefixed = (label, command, args, options = {}) => new Promise((resolve, reject) => {
64
- var _a, _b, _c;
103
+ var _a;
65
104
  const validArgs = args.filter((a) => !!a);
66
105
  const prefix = `\x1b[${(_a = options.color) !== null && _a !== void 0 ? _a : 36}m[${label}]\x1b[0m `;
67
- const child = (0, child_process_1.spawn)(command, validArgs, {
68
- stdio: ['ignore', 'pipe', 'pipe'],
69
- // Shell only on Windows (to resolve npm/aws/cdk .cmd shims). On posix, run
70
- // without a shell so the already-array args are passed straight to the
71
- // program and can't be re-interpreted by `sh -c` — no command injection via
72
- // interpolated values (stack names, CI-supplied env, etc.).
73
- shell: process.platform === 'win32',
74
- cwd: (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd(),
75
- env: Object.assign(Object.assign({}, process.env), ((_c = options.env) !== null && _c !== void 0 ? _c : {})),
76
- });
106
+ const child = (0, exports.spawnCommand)(command, validArgs, Object.assign(Object.assign({}, options), { stdio: ['ignore', 'pipe', 'pipe'] }));
77
107
  const attach = (stream, out) => {
78
108
  let buffered = '';
79
109
  stream.on('data', (chunk) => {
@@ -1 +1 @@
1
- {"version":3,"file":"runCommand.js","sourceRoot":"","sources":["../../../src/lib/runCommand.ts"],"names":[],"mappings":";;;AAAA,iDAAsC;AAYtC,2EAA2E;AAC3E,kDAAkD;AAC3C,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,IAAc,EAAE,UAA6B,EAAE,EAAiB,EAAE,CAC5G,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;;IAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1C,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,oBAAoB,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,SAAS,EAAE;QACtC,KAAK,EAAE,SAAS;QAChB,2EAA2E;QAC3E,uEAAuE;QACvE,4EAA4E;QAC5E,4DAA4D;QAC5D,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;QACnC,GAAG,EAAE,MAAA,OAAO,CAAC,GAAG,mCAAI,OAAO,CAAC,GAAG,EAAE;QACjC,GAAG,kCAAO,OAAO,CAAC,GAAG,GAAK,CAAC,MAAA,OAAO,CAAC,GAAG,mCAAI,EAAE,CAAC,CAAE;KAChD,CAAC,CAAC;IAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM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K,CAAC,IAAI,KAAK,KAAK,OAAO,2BAA2B,MAAM,EAAE,CAAC,CAAC,CAAC;QAC/F,IAAI,IAAI;YAAE,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,OAAO,qBAAqB,IAAI,EAAE,CAAC,CAAC,CAAC;QACrF,OAAO,OAAO,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAvCQ,QAAA,kBAAkB,sBAuC1B","sourcesContent":["import { spawn } from 'child_process';\nimport type { Readable } from 'stream';\n\nexport type RunCommandOptions = {\n // Extra environment variables merged over the parent process env.\n env?: Record<string, string>;\n // Working directory for the child (defaults to cwd).\n cwd?: string;\n // Echo the command before running it.\n logCommand?: boolean;\n};\n\n// Spawn a command, inheriting stdio, resolving on success. A non-zero exit\n// REJECTS so a failed build/deploy stops the run.\nexport const runCommand = (command: string, args: string[], options: RunCommandOptions = {}): Promise<void> =>\n new Promise((resolve, reject) => {\n const validArgs = args.filter((a) => !!a);\n\n if (options.logCommand) {\n console.log(`Running command: ${command} ${validArgs.join(' ')}`);\n }\n\n const child = spawn(command, validArgs, {\n stdio: 'inherit',\n // Shell only on Windows (to resolve npm/aws/cdk .cmd shims). On posix, run\n // without a shell so the already-array args are passed straight to the\n // program and can't be re-interpreted by `sh -c` — no command injection via\n // interpolated values (stack names, CI-supplied env, etc.).\n shell: process.platform === 'win32',\n cwd: options.cwd ?? process.cwd(),\n env: { ...process.env, ...(options.env ?? {}) },\n });\n\n child.on('error', (error) => reject(error));\n\n child.on('exit', (code, signal) => {\n if (signal) return reject(new Error(`${command} was killed with signal ${signal}`));\n if (code) return reject(new Error(`${command} ${validArgs.join(' ')} exited with code ${code}`));\n return resolve();\n });\n });\n\n// Run a command for its side effect only, swallowing both its output and its\n// exit code — for best-effort cleanup steps (e.g. `docker rm -f` of a container\n// that may not exist) that must never fail the run. Without a shell there's no\n// `>/dev/null 2>&1 || true`, so quieting and non-failing happen here instead.\nexport const runCommandBestEffort = (command: string, args: string[], options: RunCommandOptions = {}): Promise<void> =>\n new Promise((resolve) => {\n const validArgs = args.filter((a) => !!a);\n\n const child = spawn(command, validArgs, {\n stdio: 'ignore',\n shell: process.platform === 'win32',\n cwd: options.cwd ?? process.cwd(),\n env: { ...process.env, ...(options.env ?? {}) },\n });\n\n child.on('error', () => resolve());\n child.on('exit', () => resolve());\n });\n\nexport type RunCommandPrefixedOptions = {\n env?: Record<string, string>;\n cwd?: string;\n // ANSI color code for the prefix (see nextPrefixColor).\n color?: number;\n};\n\nconst PREFIX_COLORS = [36, 32, 33, 35, 34, 96, 92, 93, 95, 94];\nlet colorIndex = 0;\n\n// Hand each concurrent task a distinct prefix color so interleaved output is\n// scannable.\nexport const nextPrefixColor = (): number => {\n const color = PREFIX_COLORS[colorIndex % PREFIX_COLORS.length];\n colorIndex += 1;\n return color;\n};\n\n// Like runCommand, but pipes output and prefixes every line with a colored\n// [label] — for running many commands concurrently without unreadable\n// interleaving. Rejects on non-zero exit.\nexport const runCommandPrefixed = (label: string, command: string, args: string[], options: RunCommandPrefixedOptions = {}): Promise<void> =>\n new Promise((resolve, reject) => {\n const validArgs = args.filter((a) => !!a);\n const prefix = `\\x1b[${options.color ?? 36}m[${label}]\\x1b[0m `;\n\n const child = spawn(command, validArgs, {\n stdio: ['ignore', 'pipe', 'pipe'],\n // Shell only on Windows (to resolve npm/aws/cdk .cmd shims). On posix, run\n // without a shell so the already-array args are passed straight to the\n // program and can't be re-interpreted by `sh -c` — no command injection via\n // interpolated values (stack names, CI-supplied env, etc.).\n shell: process.platform === 'win32',\n cwd: options.cwd ?? process.cwd(),\n env: { ...process.env, ...(options.env ?? {}) },\n });\n\n const attach = (stream: Readable, out: NodeJS.WriteStream): void => {\n let buffered = '';\n stream.on('data', (chunk: Buffer) => {\n buffered += chunk.toString();\n const lines = buffered.split('\\n');\n buffered = lines.pop() ?? '';\n lines.forEach((line) => out.write(`${prefix}${line}\\n`));\n });\n stream.on('end', () => {\n if (buffered) out.write(`${prefix}${buffered}\\n`);\n });\n };\n\n attach(child.stdout as Readable, process.stdout);\n attach(child.stderr as Readable, process.stderr);\n\n child.on('error', (error) => reject(error));\n\n child.on('exit', (code, signal) => {\n if (signal) return reject(new Error(`[${label}] ${command} was killed with signal ${signal}`));\n if (code) return reject(new Error(`[${label}] ${command} exited with code ${code}`));\n return resolve();\n });\n });\n"]}
1
+ {"version":3,"file":"runCommand.js","sourceRoot":"","sources":["../../../src/lib/runCommand.ts"],"names":[],"mappings":";;;AAAA,iDAA6E;AAG7E,iDAA8C;AAE9C,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,aAAa,CAAC,CAAC;AAgBxC,8FAA8F;AAC9F,2FAA2F;AAC3F,8FAA8F;AAC9F,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAE9C,MAAM,cAAc,GAAG,CAAC,OAA4B,EAAE,EAAE;;IAAC,OAAA,CAAC;QACxD,KAAK,EAAE,QAAQ;QACf,GAAG,EAAE,MAAA,OAAO,CAAC,GAAG,mCAAI,OAAO,CAAC,GAAG,EAAE;QACjC,GAAG,kCAAO,OAAO,CAAC,GAAG,GAAK,CAAC,MAAA,OAAO,CAAC,GAAG,mCAAI,EAAE,CAAC,CAAE;KAChD,CAAC,CAAA;CAAA,CAAC;AAEH;;;;GAIG;AACI,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,IAAc,EAAE,UAA+B,EAAE,EAAgB,EAAE;;IAC/G,OAAA,IAAA,qBAAK,EACH,OAAO,EACP,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,kBACrB,KAAK,EAAE,MAAA,OAAO,CAAC,KAAK,mCAAI,SAAS,IAAK,cAAc,CAAC,OAAO,CAAC,EAChE,CAAA;CAAA,CAAC;AALS,QAAA,YAAY,gBAKrB;AAEJ,6GAA6G;AACtG,MAAM,cAAc,GAAG,CAAC,OAAe,EA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CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,MAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,CAAC,KAAK,CAAC,MAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAE5C,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;QAChC,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,OAAO,2BAA2B,MAAM,EAAE,CAAC,CAAC,CAAC;QAC/F,IAAI,IAAI;YAAE,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,OAAO,qBAAqB,IAAI,EAAE,CAAC,CAAC,CAAC;QACrF,OAAO,OAAO,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AA9BQ,QAAA,kBAAkB,sBA8B1B","sourcesContent":["import { ChildProcess, spawn, spawnSync, StdioOptions } from 'child_process';\nimport type { Readable } from 'stream';\n\nimport { createOutput } from './createOutput';\n\nconst out = createOutput('run-command');\n\nexport type RunCommandOptions = {\n // Extra environment variables merged over the parent process env.\n env?: Record<string, string>;\n // Working directory for the child (defaults to cwd).\n cwd?: string;\n // Echo the command before running it.\n logCommand?: boolean;\n};\n\nexport type SpawnCommandOptions = RunCommandOptions & {\n // Defaults to inheriting the parent's stdio.\n stdio?: StdioOptions;\n};\n\n// Shell only on Windows (to resolve npm/aws/cdk .cmd shims). On posix, run without a shell so\n// the already-array args are passed straight to the program and can't be re-interpreted by\n// `sh -c`, no command injection via interpolated values (stack names, CI-supplied env, etc.).\nconst useShell = process.platform === 'win32';\n\nconst toSpawnOptions = (options: SpawnCommandOptions) => ({\n shell: useShell,\n cwd: options.cwd ?? process.cwd(),\n env: { ...process.env, ...(options.env ?? {}) },\n});\n\n/**\n * Starts a long-running child (a dev server, a watcher) and hands back its handle; the caller\n * owns its lifetime. Every process the cli starts goes through here or one of the runners\n * below, so the shell and env rules are in one place.\n */\nexport const spawnCommand = (command: string, args: string[], options: SpawnCommandOptions = {}): ChildProcess =>\n spawn(\n command,\n args.filter((a) => !!a),\n { stdio: options.stdio ?? 'inherit', ...toSpawnOptions(options) },\n );\n\n/** Runs a command to completion, inheriting stdio; throws on a non-zero exit. For code that cannot await. */\nexport const runCommandSync = (command: string, args: string[], options: RunCommandOptions = {}): void => {\n const validArgs = args.filter((a) => !!a);\n const result = spawnSync(command, validArgs, { stdio: 'inherit', ...toSpawnOptions(options) });\n\n if (result.error) throw result.error;\n if (result.status) throw new Error(`${command} ${validArgs.join(' ')} exited with code ${result.status}`);\n};\n\n/**\n * Runs a command to completion and returns its stdout (stderr is dropped); throws when it\n * cannot start or exits non-zero. For the short probes (`ps`, `lsof`, `npm --version`) whose\n * output decides what the cli does next.\n */\nexport const runCommandCaptureSync = (command: string, args: string[], options: RunCommandOptions = {}): string => {\n const validArgs = args.filter((a) => !!a);\n const result = spawnSync(command, validArgs, { stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8', ...toSpawnOptions(options) });\n\n if (result.error) throw result.error;\n if (result.status) throw new Error(`${command} ${validArgs.join(' ')} exited with code ${result.status}`);\n\n return result.stdout;\n};\n\n/** Blocks the current thread for `ms`; only for the short polls in synchronous cleanup code. */\nexport const sleepSync = (ms: number): void => {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);\n};\n\n// Spawn a command, inheriting stdio, resolving on success. A non-zero exit\n// REJECTS so a failed build/deploy stops the run.\nexport const runCommand = (command: string, args: string[], options: RunCommandOptions = {}): Promise<void> =>\n new Promise((resolve, reject) => {\n const validArgs = args.filter((a) => !!a);\n\n if (options.logCommand) {\n out.log(`Running command: ${command} ${validArgs.join(' ')}`);\n }\n\n const child = spawnCommand(command, validArgs, options);\n\n child.on('error', (error) => reject(error));\n\n child.on('exit', (code, signal) => {\n if (signal) return reject(new Error(`${command} was killed with signal ${signal}`));\n if (code) return reject(new Error(`${command} ${validArgs.join(' ')} exited with code ${code}`));\n return resolve();\n });\n });\n\n// Run a command for its side effect only, swallowing both its output and its\n// exit code, for best-effort cleanup steps (e.g. `docker rm -f` of a container\n// that may not exist) that must never fail the run. Without a shell there's no\n// `>/dev/null 2>&1 || true`, so quieting and non-failing happen here instead.\nexport const runCommandBestEffort = (command: string, args: string[], options: RunCommandOptions = {}): Promise<void> =>\n new Promise((resolve) => {\n const validArgs = args.filter((a) => !!a);\n\n const child = spawnCommand(command, validArgs, { ...options, stdio: 'ignore' });\n\n child.on('error', () => resolve());\n child.on('exit', () => resolve());\n });\n\nexport type RunCommandPrefixedOptions = {\n env?: Record<string, string>;\n cwd?: string;\n // ANSI color code for the prefix (see nextPrefixColor).\n color?: number;\n};\n\nconst PREFIX_COLORS = [36, 32, 33, 35, 34, 96, 92, 93, 95, 94];\nlet colorIndex = 0;\n\n// Hand each concurrent task a distinct prefix color so interleaved output is\n// scannable.\nexport const nextPrefixColor = (): number => {\n const color = PREFIX_COLORS[colorIndex % PREFIX_COLORS.length] ?? 0;\n colorIndex += 1;\n return color;\n};\n\n// Like runCommand, but pipes output and prefixes every line with a colored\n// [label], for running many commands concurrently without unreadable\n// interleaving. Rejects on non-zero exit.\nexport const runCommandPrefixed = (label: string, command: string, args: string[], options: RunCommandPrefixedOptions = {}): Promise<void> =>\n new Promise((resolve, reject) => {\n const validArgs = args.filter((a) => !!a);\n const prefix = `\\x1b[${options.color ?? 36}m[${label}]\\x1b[0m `;\n\n const child = spawnCommand(command, validArgs, { ...options, stdio: ['ignore', 'pipe', 'pipe'] });\n\n const attach = (stream: Readable, out: NodeJS.WriteStream): void => {\n let buffered = '';\n stream.on('data', (chunk: Buffer) => {\n buffered += chunk.toString();\n const lines = buffered.split('\\n');\n buffered = lines.pop() ?? '';\n lines.forEach((line) => out.write(`${prefix}${line}\\n`));\n });\n stream.on('end', () => {\n if (buffered) out.write(`${prefix}${buffered}\\n`);\n });\n };\n\n attach(child.stdout as Readable, process.stdout);\n attach(child.stderr as Readable, process.stderr);\n\n child.on('error', (error) => reject(error));\n\n child.on('exit', (code, signal) => {\n if (signal) return reject(new Error(`[${label}] ${command} was killed with signal ${signal}`));\n if (code) return reject(new Error(`[${label}] ${command} exited with code ${code}`));\n return resolve();\n });\n });\n"]}
@@ -10,7 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.assertNoFailures = exports.runDependencyTasks = exports.runTasks = void 0;
13
- // Run tasks with at most `limit` in flight; never rejects — failures come back
13
+ const createOutput_1 = require("./createOutput");
14
+ const out = (0, createOutput_1.createOutput)('run-tasks');
15
+ // Run tasks with at most `limit` in flight; never rejects, failures come back
14
16
  // labelled so a whole wave can finish before we report what broke.
15
17
  const runTasks = (tasks, limit) => __awaiter(void 0, void 0, void 0, function* () {
16
18
  const failures = [];
@@ -20,6 +22,8 @@ const runTasks = (tasks, limit) => __awaiter(void 0, void 0, void 0, function* (
20
22
  while (nextIndex < tasks.length) {
21
23
  const task = tasks[nextIndex];
22
24
  nextIndex += 1;
25
+ if (!task)
26
+ continue;
23
27
  try {
24
28
  yield task.run();
25
29
  }
@@ -87,7 +91,7 @@ const runDependencyTasks = (tasks, limit) => __awaiter(void 0, void 0, void 0, f
87
91
  if (task.deps.some((dep) => failed.has(dep))) {
88
92
  started.add(task.id);
89
93
  failed.add(task.id); // cascade so transitive dependents skip too
90
- console.log(`Skipping ${task.label} (a dependency failed)`);
94
+ out.log(`Skipping ${task.label} (a dependency failed)`);
91
95
  changed = true;
92
96
  }
93
97
  else if (task.deps.every((dep) => succeeded.has(dep))) {
@@ -115,8 +119,8 @@ exports.runDependencyTasks = runDependencyTasks;
115
119
  const assertNoFailures = (phaseName, failures) => {
116
120
  if (failures.length === 0)
117
121
  return;
118
- console.error(`\n${phaseName} failed for:`);
119
- failures.forEach((failure) => console.error(` ${failure.label}: ${failure.error.message}`));
122
+ out.error(`\n${phaseName} failed for:`);
123
+ failures.forEach((failure) => out.error(` ${failure.label}: ${failure.error.message}`));
120
124
  throw new Error(`${phaseName}: ${failures.length} task(s) failed`);
121
125
  };
122
126
  exports.assertNoFailures = assertNoFailures;
@@ -1 +1 @@
1
- {"version":3,"file":"runTasks.js","sourceRoot":"","sources":["../../../src/lib/runTasks.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,+EAA+E;AAC/E,mEAAmE;AAC5D,MAAM,QAAQ,GAAG,CAAO,KAAa,EAAE,KAAa,EAA0B,EAAE;IACrF,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/D,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,GAAS,EAAE;QAC7C,OAAO,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;YAC9B,SAAS,IAAI,CAAC,CAAC;YACf,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YACnB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAc,EAAE,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;IACH,CAAC,CAAA,CAAC,CACH,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA,CAAC;A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AO,GAAG,IAAI,CAAC;gBACjB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,WAAW,EAAE,CAAC;IACd,yEAAyE;IACzE,8EAA8E;IAC9E,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,+BAA+B,CAAC,EAAE,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA,CAAC;AA7EW,QAAA,kBAAkB,sBA6E7B;AAEK,MAAM,gBAAgB,GAAG,CAAC,SAAiB,EAAE,QAAuB,EAAQ,EAAE;IACnF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAClC,OAAO,CAAC,KAAK,CAAC,KAAK,SAAS,cAAc,CAAC,CAAC;IAC5C,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7F,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,KAAK,QAAQ,CAAC,MAAM,iBAAiB,CAAC,CAAC;AACrE,CAAC,CAAC;AALW,QAAA,gBAAgB,oBAK3B","sourcesContent":["export type Task = { label: string; run: () => Promise<void> };\nexport type TaskFailure = { label: string; error: Error };\n\n// Run tasks with at most `limit` in flight; never rejects — failures come back\n// labelled so a whole wave can finish before we report what broke.\nexport const runTasks = async (tasks: Task[], limit: number): Promise<TaskFailure[]> => {\n const failures: TaskFailure[] = [];\n let nextIndex = 0;\n\n const workerCount = Math.max(1, Math.min(limit, tasks.length));\n await Promise.all(\n Array.from({ length: workerCount }, async () => {\n while (nextIndex < tasks.length) {\n const task = tasks[nextIndex];\n nextIndex += 1;\n try {\n await task.run();\n } catch (error) {\n failures.push({ label: task.label, error: error as Error });\n }\n }\n }),\n );\n\n return failures;\n};\n\nexport type DependencyTask = Task & {\n // Unique id other tasks reference in `deps` (e.g. a package name).\n id: string;\n // Ids of tasks that must succeed before this one starts. Ids not present in\n // the task list should be filtered out by the caller.\n deps: string[];\n};\n\n// Run tasks with at most `limit` in flight, but a task only starts once every\n// task in its `deps` has succeeded. A failure doesn't stop unrelated tasks;\n// dependents of the failed task are skipped (logged, not returned as failures,\n// the root cause already is). Never rejects. Tasks left unstartable by a\n// dependency cycle come back as failures.\nexport const runDependencyTasks = async (tasks: DependencyTask[], limit: number): Promise<TaskFailure[]> => {\n const failures: TaskFailure[] = [];\n const succeeded = new Set<string>();\n const failed = new Set<string>();\n const started = new Set<string>();\n const pipelines: Array<Promise<void>> = [];\n\n let slots = Math.max(1, limit);\n const waiting: Array<() => void> = [];\n\n const acquire = async (): Promise<void> => {\n if (slots > 0) {\n slots -= 1;\n return;\n }\n await new Promise<void>((resolve) => waiting.push(resolve));\n };\n\n const release = (): void => {\n const next = waiting.shift();\n if (next) {\n next();\n } else {\n slots += 1;\n }\n };\n\n const runOne = async (task: DependencyTask): Promise<void> => {\n await acquire();\n try {\n await task.run();\n succeeded.add(task.id);\n } catch (error) {\n failed.add(task.id);\n failures.push({ label: task.label, error: error as Error });\n } finally {\n release();\n }\n launchReady();\n };\n\n // Repeatedly sweep until stable: launching one task or cascading one skip can\n // unblock (or block) tasks earlier in the list.\n const launchReady = (): void => {\n let changed = true;\n while (changed) {\n changed = false;\n for (const task of tasks) {\n if (started.has(task.id)) continue;\n if (task.deps.some((dep) => failed.has(dep))) {\n started.add(task.id);\n failed.add(task.id); // cascade so transitive dependents skip too\n console.log(`Skipping ${task.label} (a dependency failed)`);\n changed = true;\n } else if (task.deps.every((dep) => succeeded.has(dep))) {\n started.add(task.id);\n pipelines.push(runOne(task));\n changed = true;\n }\n }\n }\n };\n\n launchReady();\n // runOne re-invokes launchReady as tasks finish, pushing newly unblocked\n // pipelines while earlier ones are being awaited; drain until it stays empty.\n while (pipelines.length > 0) {\n await Promise.all(pipelines.splice(0, pipelines.length));\n }\n\n for (const task of tasks) {\n if (!started.has(task.id)) {\n failures.push({ label: task.label, error: new Error('unstartable: dependency cycle') });\n }\n }\n\n return failures;\n};\n\nexport const assertNoFailures = (phaseName: string, failures: TaskFailure[]): void => {\n if (failures.length === 0) return;\n console.error(`\\n${phaseName} failed for:`);\n failures.forEach((failure) => console.error(` ${failure.label}: ${failure.error.message}`));\n throw new Error(`${phaseName}: ${failures.length} task(s) failed`);\n};\n"]}
1
+ {"version":3,"file":"runTasks.js","sourceRoot":"","sources":["../../../src/lib/runTasks.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA8C;AAE9C,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,WAAW,CAAC,CAAC;AAItC,8EAA8E;AAC9E,mEAAmE;AAC5D,MAAM,QAAQ,GAAG,CAAO,KAAa,EAAE,KAAa,EAA0B,EAAE;IACrF,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/D,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,GAAS,EAAE;QAC7C,OAAO,SAAS,GAAG,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AAM,KAAK,CAAC;QAAE,OAAO;IAClC,GAAG,CAAC,KAAK,CAAC,KAAK,SAAS,cAAc,CAAC,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACzF,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,KAAK,QAAQ,CAAC,MAAM,iBAAiB,CAAC,CAAC;AACrE,CAAC,CAAC;AALW,QAAA,gBAAgB,oBAK3B","sourcesContent":["import { createOutput } from './createOutput';\n\nconst out = createOutput('run-tasks');\nexport type Task = { label: string; run: () => Promise<void> };\nexport type TaskFailure = { label: string; error: Error };\n\n// Run tasks with at most `limit` in flight; never rejects, failures come back\n// labelled so a whole wave can finish before we report what broke.\nexport const runTasks = async (tasks: Task[], limit: number): Promise<TaskFailure[]> => {\n const failures: TaskFailure[] = [];\n let nextIndex = 0;\n\n const workerCount = Math.max(1, Math.min(limit, tasks.length));\n await Promise.all(\n Array.from({ length: workerCount }, async () => {\n while (nextIndex < tasks.length) {\n const task = tasks[nextIndex];\n nextIndex += 1;\n if (!task) continue;\n try {\n await task.run();\n } catch (error) {\n failures.push({ label: task.label, error: error as Error });\n }\n }\n }),\n );\n\n return failures;\n};\n\nexport type DependencyTask = Task & {\n // Unique id other tasks reference in `deps` (e.g. a package name).\n id: string;\n // Ids of tasks that must succeed before this one starts. Ids not present in\n // the task list should be filtered out by the caller.\n deps: string[];\n};\n\n// Run tasks with at most `limit` in flight, but a task only starts once every\n// task in its `deps` has succeeded. A failure doesn't stop unrelated tasks;\n// dependents of the failed task are skipped (logged, not returned as failures,\n// the root cause already is). Never rejects. Tasks left unstartable by a\n// dependency cycle come back as failures.\nexport const runDependencyTasks = async (tasks: DependencyTask[], limit: number): Promise<TaskFailure[]> => {\n const failures: TaskFailure[] = [];\n const succeeded = new Set<string>();\n const failed = new Set<string>();\n const started = new Set<string>();\n const pipelines: Array<Promise<void>> = [];\n\n let slots = Math.max(1, limit);\n const waiting: Array<() => void> = [];\n\n const acquire = async (): Promise<void> => {\n if (slots > 0) {\n slots -= 1;\n return;\n }\n await new Promise<void>((resolve) => waiting.push(resolve));\n };\n\n const release = (): void => {\n const next = waiting.shift();\n if (next) {\n next();\n } else {\n slots += 1;\n }\n };\n\n const runOne = async (task: DependencyTask): Promise<void> => {\n await acquire();\n try {\n await task.run();\n succeeded.add(task.id);\n } catch (error) {\n failed.add(task.id);\n failures.push({ label: task.label, error: error as Error });\n } finally {\n release();\n }\n launchReady();\n };\n\n // Repeatedly sweep until stable: launching one task or cascading one skip can\n // unblock (or block) tasks earlier in the list.\n const launchReady = (): void => {\n let changed = true;\n while (changed) {\n changed = false;\n for (const task of tasks) {\n if (started.has(task.id)) continue;\n if (task.deps.some((dep) => failed.has(dep))) {\n started.add(task.id);\n failed.add(task.id); // cascade so transitive dependents skip too\n out.log(`Skipping ${task.label} (a dependency failed)`);\n changed = true;\n } else if (task.deps.every((dep) => succeeded.has(dep))) {\n started.add(task.id);\n pipelines.push(runOne(task));\n changed = true;\n }\n }\n }\n };\n\n launchReady();\n // runOne re-invokes launchReady as tasks finish, pushing newly unblocked\n // pipelines while earlier ones are being awaited; drain until it stays empty.\n while (pipelines.length > 0) {\n await Promise.all(pipelines.splice(0, pipelines.length));\n }\n\n for (const task of tasks) {\n if (!started.has(task.id)) {\n failures.push({ label: task.label, error: new Error('unstartable: dependency cycle') });\n }\n }\n\n return failures;\n};\n\nexport const assertNoFailures = (phaseName: string, failures: TaskFailure[]): void => {\n if (failures.length === 0) return;\n out.error(`\\n${phaseName} failed for:`);\n failures.forEach((failure) => out.error(` ${failure.label}: ${failure.error.message}`));\n throw new Error(`${phaseName}: ${failures.length} task(s) failed`);\n};\n"]}
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logTimeEnd = exports.logTimeStart = void 0;
4
- const logTimeStart = (name) => console.time(name);
4
+ const createOutput_1 = require("./createOutput");
5
+ const out = (0, createOutput_1.createOutput)('timing');
6
+ const logTimeStart = (name) => out.time(name);
5
7
  exports.logTimeStart = logTimeStart;
6
8
  const logTimeEnd = (name) => {
7
- console.log('When:', new Date().toLocaleTimeString());
8
- console.timeEnd(name);
9
+ out.log('When:', new Date().toLocaleTimeString());
10
+ out.timeEnd(name);
9
11
  };
10
12
  exports.logTimeEnd = logTimeEnd;
11
13
  //# sourceMappingURL=timing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timing.js","sourceRoot":"","sources":["../../../src/lib/timing.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,CAAC,IAAY,EAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAA1D,QAAA,YAAY,gBAA8C;AAEhE,MAAM,UAAU,GAAG,CAAC,IAAY,EAAQ,EAAE;IAC/C,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACtD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB","sourcesContent":["export const logTimeStart = (name: string): void => console.time(name);\n\nexport const logTimeEnd = (name: string): void => {\n console.log('When:', new Date().toLocaleTimeString());\n console.timeEnd(name);\n};\n"]}
1
+ {"version":3,"file":"timing.js","sourceRoot":"","sources":["../../../src/lib/timing.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,QAAQ,CAAC,CAAC;AAC5B,MAAM,YAAY,GAAG,CAAC,IAAY,EAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAtD,QAAA,YAAY,gBAA0C;AAE5D,MAAM,UAAU,GAAG,CAAC,IAAY,EAAQ,EAAE;IAC/C,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAClD,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACpB,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB","sourcesContent":["import { createOutput } from './createOutput';\n\nconst out = createOutput('timing');\nexport const logTimeStart = (name: string): void => out.time(name);\n\nexport const logTimeEnd = (name: string): void => {\n out.log('When:', new Date().toLocaleTimeString());\n out.timeEnd(name);\n};\n"]}
@@ -1,2 +1,3 @@
1
+ import { Nullable } from '@qpqjs/core';
1
2
  import { ChildProcess } from 'child_process';
2
- export declare const startTypeWatcher: (root: string) => ChildProcess | null;
3
+ export declare const startTypeWatcher: (root: string) => Nullable<ChildProcess>;
@@ -4,18 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.startTypeWatcher = void 0;
7
- // Keeps workspace packages' declaration output (dist/*.d.ts) fresh while
8
- // `qpq go:dev` runs. The rspack dev builds bundle workspace source directly,
9
- // so this watcher only feeds the editor and validate-ts, which resolve
10
- // cross-package types through each package's built declarations.
11
- //
12
- // One `tsc -b --watch` over every workspace package that ships types; routine
13
- // watch chatter is dropped so only real compile errors reach the shared
14
- // terminal. Opt out with `--no-types`.
15
7
  const deploy_rspack_1 = require("@qpqjs/deploy-rspack");
16
- const child_process_1 = require("child_process");
17
8
  const fs_1 = __importDefault(require("fs"));
18
9
  const path_1 = __importDefault(require("path"));
10
+ const createOutput_1 = require("./createOutput");
11
+ const runCommand_1 = require("./runCommand");
12
+ const out = (0, createOutput_1.createOutput)('type-watcher');
19
13
  // Routine tsc watch status lines; everything else is worth showing.
20
14
  const routineTscPatterns = [/Starting compilation in watch mode/, /File change detected/, /Found 0 errors/];
21
15
  const isRoutineTscLine = (line) => routineTscPatterns.some((pattern) => pattern.test(line));
@@ -25,7 +19,7 @@ const forwardTscOutput = (chunk) => {
25
19
  if (line.trim().length === 0 || isRoutineTscLine(line)) {
26
20
  continue;
27
21
  }
28
- console.log(`[types] ${line}`);
22
+ out.log(`[types] ${line}`);
29
23
  }
30
24
  };
31
25
  // A workspace package wants declaration watching when it has a tsconfig and
@@ -45,14 +39,13 @@ const startTypeWatcher = (root) => {
45
39
  return null;
46
40
  }
47
41
  const relativeDirs = projectDirs.map((dir) => path_1.default.relative(root, dir));
48
- const child = (0, child_process_1.spawn)('npx', ['tsc', '-b', ...relativeDirs, '--watch', '--preserveWatchOutput', '--pretty'], {
42
+ const child = (0, runCommand_1.spawnCommand)('npx', ['tsc', '-b', ...relativeDirs, '--watch', '--preserveWatchOutput', '--pretty'], {
49
43
  cwd: root,
50
44
  stdio: ['ignore', 'pipe', 'pipe'],
51
- shell: process.platform === 'win32',
52
45
  });
53
46
  (_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', forwardTscOutput);
54
47
  (_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', forwardTscOutput);
55
- console.log(`Type watcher: tsc -b --watch over ${relativeDirs.length} workspace packages (disable with --no-types).`);
48
+ out.log(`Type watcher: tsc -b --watch over ${relativeDirs.length} workspace packages (disable with --no-types).`);
56
49
  return child;
57
50
  };
58
51
  exports.startTypeWatcher = startTypeWatcher;
@@ -1 +1 @@
1
- {"version":3,"file":"typeWatcher.js","sourceRoot":"","sources":["../../../src/lib/typeWatcher.ts"],"names":[],"mappings":";;;;;;AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,uEAAuE;AACvE,iEAAiE;AACjE,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,uCAAuC;AACvC,wDAA+D;AAE/D,iDAAoD;AACpD,4CAAoB;AACpB,gDAAwB;AAExB,oEAAoE;AACpE,MAAM,kBAAkB,GAAG,CAAC,oCAAoC,EAAE,sBAAsB,EAAE,gBAAgB,CAAC,CAAC;AAE5G,MAAM,gBAAgB,GAAG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AC;IACd,CAAC;IAED,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,SAAS,EAAE,uBAAuB,EAAE,UAAU,CAAC,EAAE;QACzG,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;QACjC,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;KACpC,CAAC,CAAC;IAEH,MAAA,KAAK,CAAC,MAAM,0CAAE,EAAE,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC3C,MAAA,KAAK,CAAC,MAAM,0CAAE,EAAE,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAE3C,OAAO,CAAC,GAAG,CAAC,qCAAqC,YAAY,CAAC,MAAM,gDAAgD,CAAC,CAAC;IAEtH,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAnBW,QAAA,gBAAgB,oBAmB3B","sourcesContent":["// Keeps workspace packages' declaration output (dist/*.d.ts) fresh while\n// `qpq go:dev` runs. The rspack dev builds bundle workspace source directly,\n// so this watcher only feeds the editor and validate-ts, which resolve\n// cross-package types through each package's built declarations.\n//\n// One `tsc -b --watch` over every workspace package that ships types; routine\n// watch chatter is dropped so only real compile errors reach the shared\n// terminal. Opt out with `--no-types`.\nimport { getWorkspacePackageDirs } from '@qpqjs/deploy-rspack';\n\nimport { ChildProcess, spawn } from 'child_process';\nimport fs from 'fs';\nimport path from 'path';\n\n// Routine tsc watch status lines; everything else is worth showing.\nconst routineTscPatterns = [/Starting compilation in watch mode/, /File change detected/, /Found 0 errors/];\n\nconst isRoutineTscLine = (line: string): boolean => routineTscPatterns.some((pattern) => pattern.test(line));\n\n// Forwards non-routine tsc output line by line under a [types] prefix.\nconst forwardTscOutput = (chunk: Buffer): void => {\n for (const line of chunk.toString().split('\\n')) {\n if (line.trim().length === 0 || isRoutineTscLine(line)) {\n continue;\n }\n console.log(`[types] ${line}`);\n }\n};\n\n// A workspace package wants declaration watching when it has a tsconfig and\n// publishes types from its build output. Packages bundled by rspack (views,\n// service handlers) don't ship types and are skipped.\nconst isTypedWorkspacePackage = (dir: string): boolean => {\n if (!fs.existsSync(path.join(dir, 'tsconfig.json'))) {\n return false;\n }\n\n const packageJson = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));\n return !!(packageJson.types || packageJson.typings);\n};\n\nexport const startTypeWatcher = (root: string): ChildProcess | null => {\n const projectDirs = getWorkspacePackageDirs(root).filter(isTypedWorkspacePackage);\n if (projectDirs.length === 0) {\n return null;\n }\n\n const relativeDirs = projectDirs.map((dir) => path.relative(root, dir));\n const child = spawn('npx', ['tsc', '-b', ...relativeDirs, '--watch', '--preserveWatchOutput', '--pretty'], {\n cwd: root,\n stdio: ['ignore', 'pipe', 'pipe'],\n shell: process.platform === 'win32',\n });\n\n child.stdout?.on('data', forwardTscOutput);\n child.stderr?.on('data', forwardTscOutput);\n\n console.log(`Type watcher: tsc -b --watch over ${relativeDirs.length} workspace packages (disable with --no-types).`);\n\n return child;\n};\n"]}
1
+ {"version":3,"file":"typeWatcher.js","sourceRoot":"","sources":["../../../src/lib/typeWatcher.ts"],"names":[],"mappings":";;;;;;AASA,wDAA+D;AAG/D,4CAAoB;AACpB,gDAAwB;AAExB,iDAA8C;AAC9C,6CAA4C;AAE5C,MAAM,GAAG,GAAG,IAAA,2BAAY,EAAC,cAAc,CAAC,CAAC;AAEzC,oEAAoE;AACpE,MAAM,kBAAkB,GAAG,CAAC,oCAAoC,EAAE,sBAAsB,EAAE,gBAAgB,CAAC,CAAC;AAE5G,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,kBAAkB,CAA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,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACxE,MAAM,KAAK,GAAG,IAAA,yBAAY,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,SAAS,EAAE,uBAAuB,EAAE,UAAU,CAAC,EAAE;QAChH,GAAG,EAAE,IAAI;QACT,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;KAClC,CAAC,CAAC;IAEH,MAAA,KAAK,CAAC,MAAM,0CAAE,EAAE,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC3C,MAAA,KAAK,CAAC,MAAM,0CAAE,EAAE,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAE3C,GAAG,CAAC,GAAG,CAAC,qCAAqC,YAAY,CAAC,MAAM,gDAAgD,CAAC,CAAC;IAElH,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAlBW,QAAA,gBAAgB,oBAkB3B","sourcesContent":["// Keeps workspace packages' declaration output (dist/*.d.ts) fresh while\n// `qpq go:dev` runs. The rspack dev builds bundle workspace source directly,\n// so this watcher only feeds the editor and validate-ts, which resolve\n// cross-package types through each package's built declarations.\n//\n// One `tsc -b --watch` over every workspace package that ships types; routine\n// watch chatter is dropped so only real compile errors reach the shared\n// terminal. Opt out with `--no-types`.\nimport { Nullable } from '@qpqjs/core';\nimport { getWorkspacePackageDirs } from '@qpqjs/deploy-rspack';\n\nimport { ChildProcess } from 'child_process';\nimport fs from 'fs';\nimport path from 'path';\n\nimport { createOutput } from './createOutput';\nimport { spawnCommand } from './runCommand';\n\nconst out = createOutput('type-watcher');\n\n// Routine tsc watch status lines; everything else is worth showing.\nconst routineTscPatterns = [/Starting compilation in watch mode/, /File change detected/, /Found 0 errors/];\n\nconst isRoutineTscLine = (line: string): boolean => routineTscPatterns.some((pattern) => pattern.test(line));\n\n// Forwards non-routine tsc output line by line under a [types] prefix.\nconst forwardTscOutput = (chunk: Buffer): void => {\n for (const line of chunk.toString().split('\\n')) {\n if (line.trim().length === 0 || isRoutineTscLine(line)) {\n continue;\n }\n out.log(`[types] ${line}`);\n }\n};\n\n// A workspace package wants declaration watching when it has a tsconfig and\n// publishes types from its build output. Packages bundled by rspack (views,\n// service handlers) don't ship types and are skipped.\nconst isTypedWorkspacePackage = (dir: string): boolean => {\n if (!fs.existsSync(path.join(dir, 'tsconfig.json'))) {\n return false;\n }\n\n const packageJson = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));\n return !!(packageJson.types || packageJson.typings);\n};\n\nexport const startTypeWatcher = (root: string): Nullable<ChildProcess> => {\n const projectDirs = getWorkspacePackageDirs(root).filter(isTypedWorkspacePackage);\n if (projectDirs.length === 0) {\n return null;\n }\n\n const relativeDirs = projectDirs.map((dir) => path.relative(root, dir));\n const child = spawnCommand('npx', ['tsc', '-b', ...relativeDirs, '--watch', '--preserveWatchOutput', '--pretty'], {\n cwd: root,\n stdio: ['ignore', 'pipe', 'pipe'],\n });\n\n child.stdout?.on('data', forwardTscOutput);\n child.stderr?.on('data', forwardTscOutput);\n\n out.log(`Type watcher: tsc -b --watch over ${relativeDirs.length} workspace packages (disable with --no-types).`);\n\n return child;\n};\n"]}
@@ -4,8 +4,6 @@ export type BuilderLayerInstallOptions = {
4
4
  architecture: JavascriptRuntimeArchitecture;
5
5
  rspackVersion: string;
6
6
  };
7
- /** The npm cpu name for a lambda architecture. */
8
- export declare const getBuilderLayerCpu: (architecture: JavascriptRuntimeArchitecture) => "arm64" | "x64";
9
7
  /**
10
8
  * The npm argv that installs rspack for linux and the lambda's cpu into the layer's
11
9
  * nodejs directory. Pure, so the exact invocation is testable without running npm.
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildUserScriptBuilderLayer = exports.getBuilderLayerInstallArgs = exports.getBuilderLayerCpu = void 0;
6
+ exports.buildUserScriptBuilderLayer = exports.getBuilderLayerInstallArgs = void 0;
7
7
  const core_1 = require("@qpqjs/core");
8
8
  const user_script_1 = require("@qpqjs/user-script");
9
- const child_process_1 = require("child_process");
10
9
  const fs_1 = __importDefault(require("fs"));
11
10
  const path_1 = __importDefault(require("path"));
11
+ const runCommand_1 = require("./runCommand");
12
12
  const MIN_NPM_MAJOR = 9;
13
13
  // Lambda's layer layout: /opt/nodejs/node_modules is on the function's module path.
14
14
  const LAYER_NODE_DIR = 'nodejs';
@@ -18,7 +18,6 @@ const npmCpuByArchitecture = {
18
18
  };
19
19
  /** The npm cpu name for a lambda architecture. */
20
20
  const getBuilderLayerCpu = (architecture) => npmCpuByArchitecture[architecture];
21
- exports.getBuilderLayerCpu = getBuilderLayerCpu;
22
21
  /**
23
22
  * The npm argv that installs rspack for linux and the lambda's cpu into the layer's
24
23
  * nodejs directory. Pure, so the exact invocation is testable without running npm.
@@ -28,7 +27,7 @@ const getBuilderLayerInstallArgs = ({ outDir, architecture, rspackVersion }) =>
28
27
  '--prefix',
29
28
  path_1.default.join(outDir, LAYER_NODE_DIR),
30
29
  '--os=linux',
31
- `--cpu=${(0, exports.getBuilderLayerCpu)(architecture)}`,
30
+ `--cpu=${getBuilderLayerCpu(architecture)}`,
32
31
  '--libc=glibc',
33
32
  '--omit=dev',
34
33
  '--no-save',
@@ -38,11 +37,11 @@ const getBuilderLayerInstallArgs = ({ outDir, architecture, rspackVersion }) =>
38
37
  `@rspack/core@${rspackVersion}`,
39
38
  ];
40
39
  exports.getBuilderLayerInstallArgs = getBuilderLayerInstallArgs;
41
- const parseMajor = (version) => parseInt(version.split('.')[0], 10);
40
+ const parseMajor = (version) => { var _a; return parseInt((_a = version.split('.')[0]) !== null && _a !== void 0 ? _a : '', 10); };
42
41
  const defaultRunners = {
43
- getNpmVersion: () => (0, child_process_1.execFileSync)('npm', ['--version'], { encoding: 'utf8' }).trim(),
42
+ getNpmVersion: () => (0, runCommand_1.runCommandCaptureSync)('npm', ['--version']).trim(),
44
43
  runNpm: (args) => {
45
- (0, child_process_1.execFileSync)('npm', args, { stdio: 'inherit' });
44
+ (0, runCommand_1.runCommandSync)('npm', args);
46
45
  },
47
46
  };
48
47
  /**
@@ -60,7 +59,7 @@ const buildUserScriptBuilderLayer = (options, runners = defaultRunners) => {
60
59
  fs_1.default.mkdirSync(nodeDir, { recursive: true });
61
60
  fs_1.default.writeFileSync(path_1.default.join(nodeDir, 'package.json'), JSON.stringify({ name: 'user-script-builder-layer', private: true }, null, 2));
62
61
  runners.runNpm((0, exports.getBuilderLayerInstallArgs)(options));
63
- const bindingDir = path_1.default.join(nodeDir, 'node_modules', '@rspack', `binding-linux-${(0, exports.getBuilderLayerCpu)(options.architecture)}-gnu`);
62
+ const bindingDir = path_1.default.join(nodeDir, 'node_modules', '@rspack', `binding-linux-${getBuilderLayerCpu(options.architecture)}-gnu`);
64
63
  if (!fs_1.default.existsSync(bindingDir)) {
65
64
  throw new Error(`script:builder-layer: expected the rspack binding at [${bindingDir}] after install; the layer would not load on lambda`);
66
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"userScriptBuilderLayer.js","sourceRoot":"","sources":["../../../src/lib/userScriptBuilderLayer.ts"],"names":[],"mappings":";;;;;;AAAA,sCAA4D;AAC5D,oDAAuE;AAEvE,iDAA6C;AAC7C,4CAAoB;AACpB,gDAAwB;AAExB,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB,oFAAoF;AACpF,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC,MAAM,oBAAoB,GAA2D;IACnF,CAAC,oCAA6B,CAAC,KAAK,CAAC,EAAE,OAAO;IAC9C,CAAC,oCAA6B,CAAC,MAAM,CAAC,EAAE,KAAK;CAC9C,CAAC;AAQF,kDAAkD;AAC3C,MAAM,kBAAkB,GAAG,CAAC,YAA2C,EAAmB,EAA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,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5J,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAxBW,QAAA,2BAA2B,+BAwBtC","sourcesContent":["import { JavascriptRuntimeArchitecture } from '@qpqjs/core';\nimport { USER_SCRIPT_BUILDER_LAYER_MODULES } from '@qpqjs/user-script';\n\nimport { execFileSync } from 'child_process';\nimport fs from 'fs';\nimport path from 'path';\n\nconst MIN_NPM_MAJOR = 9;\n\n// Lambda's layer layout: /opt/nodejs/node_modules is on the function's module path.\nconst LAYER_NODE_DIR = 'nodejs';\n\nconst npmCpuByArchitecture: Record<JavascriptRuntimeArchitecture, 'arm64' | 'x64'> = {\n [JavascriptRuntimeArchitecture.Arm64]: 'arm64',\n [JavascriptRuntimeArchitecture.X86_64]: 'x64',\n};\n\nexport type BuilderLayerInstallOptions = {\n outDir: string;\n architecture: JavascriptRuntimeArchitecture;\n rspackVersion: string;\n};\n\n/** The npm cpu name for a lambda architecture. */\nexport const getBuilderLayerCpu = (architecture: JavascriptRuntimeArchitecture): 'arm64' | 'x64' => npmCpuByArchitecture[architecture];\n\n/**\n * The npm argv that installs rspack for linux and the lambda's cpu into the layer's\n * nodejs directory. Pure, so the exact invocation is testable without running npm.\n */\nexport const getBuilderLayerInstallArgs = ({ outDir, architecture, rspackVersion }: BuilderLayerInstallOptions): string[] => [\n 'install',\n '--prefix',\n path.join(outDir, LAYER_NODE_DIR),\n '--os=linux',\n `--cpu=${getBuilderLayerCpu(architecture)}`,\n '--libc=glibc',\n '--omit=dev',\n '--no-save',\n '--no-package-lock',\n '--no-audit',\n '--no-fund',\n `@rspack/core@${rspackVersion}`,\n];\n\nconst parseMajor = (version: string): number => parseInt(version.split('.')[0], 10);\n\nexport type BuilderLayerRunners = {\n getNpmVersion: () => string;\n runNpm: (args: string[]) => void;\n};\n\nconst defaultRunners: BuilderLayerRunners = {\n getNpmVersion: () => execFileSync('npm', ['--version'], { encoding: 'utf8' }).trim(),\n runNpm: (args) => {\n execFileSync('npm', args, { stdio: 'inherit' });\n },\n};\n\n/**\n * Produces the user-script builder layer directory: `<outDir>/nodejs/node_modules` holding\n * rspack and its linux binding for the lambda's cpu. Empties `outDir` first and verifies\n * the binding landed. Needs npm 9 or later for the `--os`/`--cpu` flags.\n */\nexport const buildUserScriptBuilderLayer = (options: BuilderLayerInstallOptions, runners: BuilderLayerRunners = defaultRunners): string => {\n const npmVersion = runners.getNpmVersion();\n if (parseMajor(npmVersion) < MIN_NPM_MAJOR) {\n throw new Error(`script:builder-layer needs npm ${MIN_NPM_MAJOR} or later for --os/--cpu installs; found ${npmVersion}`);\n }\n\n const nodeDir = path.join(options.outDir, LAYER_NODE_DIR);\n fs.rmSync(options.outDir, { recursive: true, force: true });\n fs.mkdirSync(nodeDir, { recursive: true });\n fs.writeFileSync(path.join(nodeDir, 'package.json'), JSON.stringify({ name: 'user-script-builder-layer', private: true }, null, 2));\n\n runners.runNpm(getBuilderLayerInstallArgs(options));\n\n const bindingDir = path.join(nodeDir, 'node_modules', '@rspack', `binding-linux-${getBuilderLayerCpu(options.architecture)}-gnu`);\n if (!fs.existsSync(bindingDir)) {\n throw new Error(`script:builder-layer: expected the rspack binding at [${bindingDir}] after install; the layer would not load on lambda`);\n }\n\n const installed = USER_SCRIPT_BUILDER_LAYER_MODULES.filter((name) => fs.existsSync(path.join(nodeDir, 'node_modules', name)));\n if (installed.length !== USER_SCRIPT_BUILDER_LAYER_MODULES.length) {\n throw new Error(`script:builder-layer: the layer is missing ${USER_SCRIPT_BUILDER_LAYER_MODULES.filter((name) => !installed.includes(name)).join(', ')}`);\n }\n\n return nodeDir;\n};\n"]}
1
+ {"version":3,"file":"userScriptBuilderLayer.js","sourceRoot":"","sources":["../../../src/lib/userScriptBuilderLayer.ts"],"names":[],"mappings":";;;;;;AAAA,sCAA4D;AAC5D,oDAAuE;AAEvE,4CAAoB;AACpB,gDAAwB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,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9H,IAAI,SAAS,CAAC,MAAM,KAAK,+CAAiC,CAAC,MAAM,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CACb,8CAA8C,+CAAiC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACzI,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AA1BW,QAAA,2BAA2B,+BA0BtC","sourcesContent":["import { JavascriptRuntimeArchitecture } from '@qpqjs/core';\nimport { USER_SCRIPT_BUILDER_LAYER_MODULES } from '@qpqjs/user-script';\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport { runCommandCaptureSync, runCommandSync } from './runCommand';\n\nconst MIN_NPM_MAJOR = 9;\n\n// Lambda's layer layout: /opt/nodejs/node_modules is on the function's module path.\nconst LAYER_NODE_DIR = 'nodejs';\n\nconst npmCpuByArchitecture: Record<JavascriptRuntimeArchitecture, 'arm64' | 'x64'> = {\n [JavascriptRuntimeArchitecture.Arm64]: 'arm64',\n [JavascriptRuntimeArchitecture.X86_64]: 'x64',\n};\n\nexport type BuilderLayerInstallOptions = {\n outDir: string;\n architecture: JavascriptRuntimeArchitecture;\n rspackVersion: string;\n};\n\n/** The npm cpu name for a lambda architecture. */\nconst getBuilderLayerCpu = (architecture: JavascriptRuntimeArchitecture): 'arm64' | 'x64' => npmCpuByArchitecture[architecture];\n\n/**\n * The npm argv that installs rspack for linux and the lambda's cpu into the layer's\n * nodejs directory. Pure, so the exact invocation is testable without running npm.\n */\nexport const getBuilderLayerInstallArgs = ({ outDir, architecture, rspackVersion }: BuilderLayerInstallOptions): string[] => [\n 'install',\n '--prefix',\n path.join(outDir, LAYER_NODE_DIR),\n '--os=linux',\n `--cpu=${getBuilderLayerCpu(architecture)}`,\n '--libc=glibc',\n '--omit=dev',\n '--no-save',\n '--no-package-lock',\n '--no-audit',\n '--no-fund',\n `@rspack/core@${rspackVersion}`,\n];\n\nconst parseMajor = (version: string): number => parseInt(version.split('.')[0] ?? '', 10);\n\nexport type BuilderLayerRunners = {\n getNpmVersion: () => string;\n runNpm: (args: string[]) => void;\n};\n\nconst defaultRunners: BuilderLayerRunners = {\n getNpmVersion: () => runCommandCaptureSync('npm', ['--version']).trim(),\n runNpm: (args) => {\n runCommandSync('npm', args);\n },\n};\n\n/**\n * Produces the user-script builder layer directory: `<outDir>/nodejs/node_modules` holding\n * rspack and its linux binding for the lambda's cpu. Empties `outDir` first and verifies\n * the binding landed. Needs npm 9 or later for the `--os`/`--cpu` flags.\n */\nexport const buildUserScriptBuilderLayer = (options: BuilderLayerInstallOptions, runners: BuilderLayerRunners = defaultRunners): string => {\n const npmVersion = runners.getNpmVersion();\n if (parseMajor(npmVersion) < MIN_NPM_MAJOR) {\n throw new Error(`script:builder-layer needs npm ${MIN_NPM_MAJOR} or later for --os/--cpu installs; found ${npmVersion}`);\n }\n\n const nodeDir = path.join(options.outDir, LAYER_NODE_DIR);\n fs.rmSync(options.outDir, { recursive: true, force: true });\n fs.mkdirSync(nodeDir, { recursive: true });\n fs.writeFileSync(path.join(nodeDir, 'package.json'), JSON.stringify({ name: 'user-script-builder-layer', private: true }, null, 2));\n\n runners.runNpm(getBuilderLayerInstallArgs(options));\n\n const bindingDir = path.join(nodeDir, 'node_modules', '@rspack', `binding-linux-${getBuilderLayerCpu(options.architecture)}-gnu`);\n if (!fs.existsSync(bindingDir)) {\n throw new Error(`script:builder-layer: expected the rspack binding at [${bindingDir}] after install; the layer would not load on lambda`);\n }\n\n const installed = USER_SCRIPT_BUILDER_LAYER_MODULES.filter((name) => fs.existsSync(path.join(nodeDir, 'node_modules', name)));\n if (installed.length !== USER_SCRIPT_BUILDER_LAYER_MODULES.length) {\n throw new Error(\n `script:builder-layer: the layer is missing ${USER_SCRIPT_BUILDER_LAYER_MODULES.filter((name) => !installed.includes(name)).join(', ')}`,\n );\n }\n\n return nodeDir;\n};\n"]}