@ms-cloudpack/cli 0.72.11 → 0.72.13

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 (59) hide show
  1. package/lib/commands/bundle/execute.d.ts.map +1 -1
  2. package/lib/commands/bundle/execute.js +6 -7
  3. package/lib/commands/bundle/execute.js.map +1 -1
  4. package/lib/commands/cache/clean.d.ts.map +1 -1
  5. package/lib/commands/cache/clean.js +6 -11
  6. package/lib/commands/cache/clean.js.map +1 -1
  7. package/lib/commands/config/delete.js +4 -4
  8. package/lib/commands/config/delete.js.map +1 -1
  9. package/lib/commands/config/get.js +5 -5
  10. package/lib/commands/config/get.js.map +1 -1
  11. package/lib/commands/config/list.js +5 -5
  12. package/lib/commands/config/list.js.map +1 -1
  13. package/lib/commands/config/set.js +4 -4
  14. package/lib/commands/config/set.js.map +1 -1
  15. package/lib/commands/info/lockFile/execute.d.ts.map +1 -1
  16. package/lib/commands/info/lockFile/execute.js +10 -14
  17. package/lib/commands/info/lockFile/execute.js.map +1 -1
  18. package/lib/commands/info/nonSemverDeps/execute.d.ts.map +1 -1
  19. package/lib/commands/info/nonSemverDeps/execute.js +8 -10
  20. package/lib/commands/info/nonSemverDeps/execute.js.map +1 -1
  21. package/lib/commands/init/execute.js +4 -4
  22. package/lib/commands/init/execute.js.map +1 -1
  23. package/lib/commands/link/execute.d.ts.map +1 -1
  24. package/lib/commands/link/execute.js +8 -4
  25. package/lib/commands/link/execute.js.map +1 -1
  26. package/lib/commands/link/getSessionToLink.d.ts +5 -4
  27. package/lib/commands/link/getSessionToLink.d.ts.map +1 -1
  28. package/lib/commands/link/getSessionToLink.js +36 -20
  29. package/lib/commands/link/getSessionToLink.js.map +1 -1
  30. package/lib/commands/setup/execute.js +2 -2
  31. package/lib/commands/setup/execute.js.map +1 -1
  32. package/lib/commands/start/execute.d.ts.map +1 -1
  33. package/lib/commands/start/execute.js +23 -17
  34. package/lib/commands/start/execute.js.map +1 -1
  35. package/lib/commands/sync/execute.d.ts.map +1 -1
  36. package/lib/commands/sync/execute.js +12 -13
  37. package/lib/commands/sync/execute.js.map +1 -1
  38. package/lib/commands/unlink/execute.d.ts.map +1 -1
  39. package/lib/commands/unlink/execute.js +8 -4
  40. package/lib/commands/unlink/execute.js.map +1 -1
  41. package/lib/types/CommandAction.d.ts +6 -8
  42. package/lib/types/CommandAction.d.ts.map +1 -1
  43. package/lib/types/CommandAction.js.map +1 -1
  44. package/lib/utilities/CommandExecutor.d.ts +6 -4
  45. package/lib/utilities/CommandExecutor.d.ts.map +1 -1
  46. package/lib/utilities/CommandExecutor.js +42 -30
  47. package/lib/utilities/CommandExecutor.js.map +1 -1
  48. package/lib/utilities/parseMatch.d.ts.map +1 -1
  49. package/lib/utilities/parseMatch.js +5 -0
  50. package/lib/utilities/parseMatch.js.map +1 -1
  51. package/package.json +13 -13
  52. package/lib/commands/link/getSessionFromUser.d.ts +0 -9
  53. package/lib/commands/link/getSessionFromUser.d.ts.map +0 -1
  54. package/lib/commands/link/getSessionFromUser.js +0 -26
  55. package/lib/commands/link/getSessionFromUser.js.map +0 -1
  56. package/lib/utilities/stopServers.d.ts +0 -13
  57. package/lib/utilities/stopServers.d.ts.map +0 -1
  58. package/lib/utilities/stopServers.js +0 -18
  59. package/lib/utilities/stopServers.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"getSessionToLink.js","sourceRoot":"","sources":["../../../src/commands/link/getSessionToLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAKtC;IACC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAEnC,qCAAqC;IACrC,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACxD,MAAM,eAAe,GAAG,MAAM,iBAAiB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;IAEzE,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,CAAC;YACT,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,kFAAkF;SAC5F,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,qBAAqB,eAAe,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAE9F,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAChC,eAAe,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/B,OAAO,CAAC,EAAE;QACV;YACE,KAAK,EAAE,OAAO,CAAC,WAAW;YAC1B,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,GAAG,OAAO,CAAC,EAAE;YACtD,KAAK,EAAE,OAAO;SACf;KACF,CAAC,CACH,CAAC;IAEF,qCAAqC;IACrC,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;IAC7D,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAE/C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QAC5B,8CAA8C;QAC9C,MAAM,IAAI,CAAC;YACT,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,uDAAuD;SACjE,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAuC,CAAC;AACjD,CAAC","sourcesContent":["import type { CommandActionParams } from '../../types/CommandAction.js';\nimport { getActiveSessions } from './getActiveSessions.js';\nimport { getSessionFromUser } from './getSessionFromUser.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { Session } from '@ms-cloudpack/api-server';\nimport { getCachePath } from '@ms-cloudpack/config';\n\ntype SessionWithRequiredApiServer = Session & { urls: { apiServer: string } };\n\n/**\n * Get a single active session to link packages.\n * The session must have an API server URL.\n */\nexport async function getSessionToLink(options: {\n reporter: TaskReporter;\n exit: CommandActionParams<object>['exit'];\n /** Cache path from CLI options */\n cachePath: string | undefined;\n}): Promise<SessionWithRequiredApiServer> {\n const { reporter, exit } = options;\n\n // Find the list of running sessions.\n const cachePath = await getCachePath(options.cachePath);\n const runningSessions = await getActiveSessions({ reporter, cachePath });\n\n if (runningSessions.length === 0) {\n await exit({\n exitCode: 1,\n message: 'No running sessions found. Please start a session using `cloudpack start` first.',\n });\n }\n\n console.debug(`Running sessions: ${runningSessions.map((session) => session.id).join(', ')}`);\n\n const runningSessionsMap = new Map(\n runningSessions.map((session) => [\n session.id,\n {\n title: session.projectName,\n description: session.config.appPath + ' ' + session.id,\n value: session,\n },\n ]),\n );\n\n // Select a session to link packages.\n const session = await getSessionFromUser(runningSessionsMap);\n console.debug('Selected session:', session.id);\n\n if (!session.urls.apiServer) {\n // We should never get here, but just in case.\n await exit({\n exitCode: 1,\n message: 'The selected session does not have an API server URL.',\n });\n }\n\n return session as SessionWithRequiredApiServer;\n}\n"]}
1
+ {"version":3,"file":"getSessionToLink.js","sourceRoot":"","sources":["../../../src/commands/link/getSessionToLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAI3D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAItC;IACC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,qCAAqC;IACrC,MAAM,SAAS,GAAG,MAAM,YAAY,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E,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAE/C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QAC5B,8CAA8C;QAC9C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,uDAAuD,EAAE,CAAC;IAC/F,CAAC;IAED,OAAO;QACL,OAAO,EAAE,OAAuC;QAChD,OAAO,EAAE,EAAE,EAAE,oCAAoC;KAClD,CAAC;AACJ,CAAC","sourcesContent":["import type { Session } from '@ms-cloudpack/api-server';\nimport { getCachePath } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport prompts from 'prompts';\nimport type { CommandExitParams } from '../../types/CommandAction.js';\nimport { getActiveSessions } from './getActiveSessions.js';\n\ntype SessionWithRequiredApiServer = Session & { urls: { apiServer: string } };\n\n/**\n * Get a single active session to link packages.\n * The session must have an API server URL.\n */\nexport async function getSessionToLink(options: {\n reporter: TaskReporter;\n /** Cache path from CLI options */\n cachePath: string | undefined;\n}): Promise<CommandExitParams & { session?: SessionWithRequiredApiServer }> {\n const { reporter } = options;\n\n // Find the list of running sessions.\n const cachePath = await getCachePath(options.cachePath);\n const runningSessions = await getActiveSessions({ reporter, cachePath });\n\n if (runningSessions.length === 0) {\n return {\n hasErrors: true,\n message: 'No running sessions found. Please start a session using `cloudpack start` first.',\n };\n }\n\n console.debug(`Running sessions: ${runningSessions.map((session) => session.id).join(', ')}`);\n\n // Select a session to link packages.\n let session: Session | undefined;\n\n if (runningSessions.length === 1) {\n // Only one session, so use it automatically.\n session = runningSessions[0];\n } else {\n // Prompt the user to select a session.\n const response = await prompts({\n type: 'select',\n name: 'value',\n message: 'Select the app you want to link',\n choices: runningSessions\n .map((s) => ({\n title: s.projectName,\n description: s.config.appPath + ' ' + s.id,\n value: s,\n }))\n .sort((s1, s2) => s1.title.localeCompare(s2.title)),\n });\n\n // value will be undefined if the user presses Ctrl+C\n session = response.value as Session | undefined;\n }\n\n if (!session) {\n return { message: 'Aborting...' };\n }\n\n console.debug('Selected session:', session.id);\n\n if (!session.urls.apiServer) {\n // We should never get here, but just in case.\n return { hasErrors: true, message: 'The selected session does not have an API server URL.' };\n }\n\n return {\n session: session as SessionWithRequiredApiServer,\n message: '', // required by the type but not used\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { setup } from '@ms-cloudpack/setup-utilities';
2
2
  /** Executor for the "setup" verb */
3
3
  export const execute = async (params) => {
4
- const { cwd, initialize, exit } = params;
4
+ const { cwd, initialize } = params;
5
5
  const { config } = await initialize({ appPath: cwd });
6
6
  const { server = {} } = config;
7
7
  const { domain, https } = server;
@@ -12,6 +12,6 @@ export const execute = async (params) => {
12
12
  cwd,
13
13
  });
14
14
  }
15
- await exit({ message: 'Setup complete.' });
15
+ return { message: 'Setup complete.' };
16
16
  };
17
17
  //# sourceMappingURL=execute.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/setup/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAMtD,oCAAoC;AACpC,MAAM,CAAC,MAAM,OAAO,GAAgC,KAAK,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACzC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IACtD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QACpB,MAAM,KAAK,CAAC;YACV,MAAM;YACN,uBAAuB,EAAE,KAAK,KAAK,IAAI;YACvC,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,CAAC,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAC7C,CAAC,CAAC","sourcesContent":["import type { CommandAction } from '../../types/CommandAction.js';\nimport { setup } from '@ms-cloudpack/setup-utilities';\n\nexport interface SetupOptions {\n force?: boolean;\n}\n\n/** Executor for the \"setup\" verb */\nexport const execute: CommandAction<SetupOptions> = async (params) => {\n const { cwd, initialize, exit } = params;\n const { config } = await initialize({ appPath: cwd });\n const { server = {} } = config;\n const { domain, https } = server;\n\n if (domain || https) {\n await setup({\n domain,\n shouldCreateCertificate: https === true,\n cwd,\n });\n }\n\n await exit({ message: 'Setup complete.' });\n};\n"]}
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/setup/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAMtD,oCAAoC;AACpC,MAAM,CAAC,MAAM,OAAO,GAAgC,KAAK,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACnC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IACtD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QACpB,MAAM,KAAK,CAAC;YACV,MAAM;YACN,uBAAuB,EAAE,KAAK,KAAK,IAAI;YACvC,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import type { CommandAction } from '../../types/CommandAction.js';\nimport { setup } from '@ms-cloudpack/setup-utilities';\n\nexport interface SetupOptions {\n force?: boolean;\n}\n\n/** Executor for the \"setup\" verb */\nexport const execute: CommandAction<SetupOptions> = async (params) => {\n const { cwd, initialize } = params;\n const { config } = await initialize({ appPath: cwd });\n const { server = {} } = config;\n const { domain, https } = server;\n\n if (domain || https) {\n await setup({\n domain,\n shouldCreateCertificate: https === true,\n cwd,\n });\n }\n\n return { message: 'Setup complete.' };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAKlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAI5D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,YAAY,CA6G/C,CAAC"}
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAKlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,YAAY,CA6G/C,CAAC"}
@@ -11,13 +11,11 @@ import { getStartingAppPath } from './getStartingAppPath.js';
11
11
  import { openBrowser } from './openBrowser.js';
12
12
  import { trackSession } from './trackSession.js';
13
13
  import { getCertificate } from '@ms-cloudpack/setup-utilities';
14
- import { setStopServersFunction } from '../../utilities/stopServers.js';
15
14
  /**
16
15
  * Defines the "start" verb entry point.
17
16
  */
18
17
  export const execute = async (params) => {
19
- const { options, cwd, initialize, autoDispose, exit } = params;
20
- setStopServersFunction(exit);
18
+ const { options, cwd, initialize, autoDispose } = params;
21
19
  const appPath = await getStartingAppPath(cwd, options.app);
22
20
  const apiContextOptions = await initialize({ appPath, configOptions: { mode: options.mode } });
23
21
  const { config } = apiContextOptions;
@@ -49,12 +47,11 @@ export const execute = async (params) => {
49
47
  await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);
50
48
  }
51
49
  // Start api server for tracking status and handling remote requests.
52
- const serverOrError = await createApiServer(options, apiContext);
53
- if (typeof serverOrError === 'string') {
54
- await exit({ exitCode: 1, message: serverOrError });
55
- return;
50
+ const apiServerResult = await createApiServer(options, apiContext);
51
+ if (apiServerResult.hasErrors) {
52
+ return apiServerResult;
56
53
  }
57
- const apiServer = serverOrError;
54
+ const { apiServer } = apiServerResult;
58
55
  // Kick off bundling app package as soon as api server is ready.
59
56
  void ensurePackageBundled({
60
57
  input: { name: definition.name, version: definition.version },
@@ -100,6 +97,7 @@ export const execute = async (params) => {
100
97
  else {
101
98
  console.log('Please open the browser manually to:', defaultUrl);
102
99
  }
100
+ return null; // the command should keep running
103
101
  };
104
102
  /**
105
103
  * Create the API server, or return an error message if the server could not be created.
@@ -110,22 +108,30 @@ async function createApiServer(options, apiContext) {
110
108
  const { server, appPath } = config;
111
109
  // If a cert is needed, check that it exists.
112
110
  if (server?.https === true && !(await getCertificate({ domain: server?.domain, cwd: appPath }))) {
113
- return (`The local site is configured to use https in cloudpack.config.json, but is missing a cert.\n\n` +
114
- `Run "${cyan(bold('cloudpack setup'))}" to create the required certificate and try start again.\n`);
111
+ return {
112
+ hasErrors: true,
113
+ message: `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\n\n` +
114
+ `Run "${cyan(bold('cloudpack setup'))}" to create the required certificate and try start again.\n`,
115
+ };
115
116
  }
116
117
  const { createCloudpackServer } = await import('@ms-cloudpack/api-server');
117
118
  try {
118
- return await createCloudpackServer({ port: options.apiServerPort }, apiContext);
119
+ const apiServer = await createCloudpackServer({ port: options.apiServerPort }, apiContext);
120
+ return { hasErrors: false, apiServer };
119
121
  }
120
122
  catch (err) {
121
- const error = err;
122
- if (error.code === 'EADDRNOTAVAIL' && server?.domain) {
123
+ let message;
124
+ if (err.code === 'EADDRNOTAVAIL' && server?.domain) {
123
125
  const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];
124
- return (`The domain "${cyan(bold(primaryDomain))}" in cloudpack.config.json is not resolvable.\n\n` +
125
- `Run "${cyan(bold('cloudpack setup'))}" to add the appropriate entries to your hosts file and ` +
126
- `try start again.\n`);
126
+ message =
127
+ `The domain "${cyan(bold(primaryDomain))}" in cloudpack.config.json is not resolvable.\n\n` +
128
+ `Run "${cyan(bold('cloudpack setup'))}" to add the appropriate entries to your hosts file and ` +
129
+ `try start again.\n`;
127
130
  }
128
- return `Error creating API server: ${err.stack || err}`;
131
+ else {
132
+ message = `Error creating API server: ${err.stack || err}`;
133
+ }
134
+ return { hasErrors: true, message };
129
135
  }
130
136
  }
131
137
  // cspell:ignore Prereqs
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,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G,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC;QACH,OAAO,MAAM,qBAAqB,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE,EAAE,UAAU,CAAC,CAAC;IAClF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,GAAuB,CAAC;QAEtC,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;YACrD,MAAM,aAAa,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAE1F,OAAO,CACL,eAAe,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,mDAAmD;gBAC3F,QAAQ,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,0DAA0D;gBAC/F,oBAAoB,CACrB,CAAC;QACJ,CAAC;QAED,OAAO,8BAA+B,GAAa,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;IACrE,CAAC;AACH,CAAC;AAED,wBAAwB","sourcesContent":["import {\n createPartialApiContext,\n ensurePackageBundled,\n type CloudpackServer,\n type Context,\n} from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/package-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { cyan, yellow, bold } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { getStartingAppPath } from './getStartingAppPath.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCertificate } from '@ms-cloudpack/setup-utilities';\nimport { setStopServersFunction } from '../../utilities/stopServers.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { options, cwd, initialize, autoDispose, exit } = params;\n setStopServersFunction(exit);\n\n const appPath = await getStartingAppPath(cwd, options.app);\n const apiContextOptions = await initialize({ appPath, configOptions: { mode: options.mode } });\n const { config } = apiContextOptions;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n runPrerequisites(apiContextOptions);\n\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n const cliPath = await resolve('@ms-cloudpack/cli', currentDir);\n overlayPath = cliPath ? path.join(cliPath, 'node_modules', '@ms-cloudpack/overlay') : undefined;\n }\n\n const [apiContext] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'watcher', 'taskRunner', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n overlayPath,\n }),\n );\n const { packages, session } = apiContext;\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const serverOrError = await createApiServer(options, apiContext);\n if (typeof serverOrError === 'string') {\n await exit({ exitCode: 1, message: serverOrError });\n return;\n }\n const apiServer = serverOrError;\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: definition.name, version: definition.version },\n ctx: apiContext,\n });\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n\n const cleanup = async () => {\n // Stop tracking the session.\n await sessionTracker.close();\n\n await Promise.all(\n Object.entries({ apiServer, ...servers }).map(async ([name, server]) => {\n if (!server) return;\n\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n }),\n );\n };\n\n autoDispose({ dispose: cleanup });\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', session.urls.appServer).href;\n\n performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n // Open the browser.\n if (options.open !== false) {\n openBrowser(defaultUrl).catch((err) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n console.warn('Error opening browser:', err?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n } else {\n console.log('Please open the browser manually to:', defaultUrl);\n }\n};\n\n/**\n * Create the API server, or return an error message if the server could not be created.\n */\nasync function createApiServer(options: StartOptions, apiContext: Context): Promise<CloudpackServer | string> {\n const { session } = apiContext;\n const { config } = session;\n const { server, appPath } = config;\n\n // If a cert is needed, check that it exists.\n if (server?.https === true && !(await getCertificate({ domain: server?.domain, cwd: appPath }))) {\n return (\n `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to create the required certificate and try start again.\\n`\n );\n }\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n try {\n return await createCloudpackServer({ port: options.apiServerPort }, apiContext);\n } catch (err) {\n const error = err as { code: string };\n\n if (error.code === 'EADDRNOTAVAIL' && server?.domain) {\n const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];\n\n return (\n `The domain \"${cyan(bold(primaryDomain))}\" in cloudpack.config.json is not resolvable.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to add the appropriate entries to your hosts file and ` +\n `try start again.\\n`\n );\n }\n\n return `Error creating API server: ${(err as Error).stack || err}`;\n }\n}\n\n// cspell:ignore Prereqs\n"]}
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAgC,KAAK,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAEzD,MAAM,OAAO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AC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1F,OAAO;gBACL,eAAe,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,mDAAmD;oBAC3F,QAAQ,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,0DAA0D;oBAC/F,oBAAoB,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,8BAA+B,GAAa,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACtC,CAAC;AACH,CAAC;AAED,wBAAwB","sourcesContent":["import {\n createPartialApiContext,\n ensurePackageBundled,\n type CloudpackServer,\n type Context,\n} from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/package-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { cyan, yellow, bold } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { getStartingAppPath } from './getStartingAppPath.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCertificate } from '@ms-cloudpack/setup-utilities';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { options, cwd, initialize, autoDispose } = params;\n\n const appPath = await getStartingAppPath(cwd, options.app);\n const apiContextOptions = await initialize({ appPath, configOptions: { mode: options.mode } });\n const { config } = apiContextOptions;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n runPrerequisites(apiContextOptions);\n\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n const cliPath = await resolve('@ms-cloudpack/cli', currentDir);\n overlayPath = cliPath ? path.join(cliPath, 'node_modules', '@ms-cloudpack/overlay') : undefined;\n }\n\n const [apiContext] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'watcher', 'taskRunner', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n overlayPath,\n }),\n );\n const { packages, session } = apiContext;\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const apiServerResult = await createApiServer(options, apiContext);\n if (apiServerResult.hasErrors) {\n return apiServerResult;\n }\n const { apiServer } = apiServerResult;\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: definition.name, version: definition.version },\n ctx: apiContext,\n });\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n\n const cleanup = async () => {\n // Stop tracking the session.\n await sessionTracker.close();\n\n await Promise.all(\n Object.entries({ apiServer, ...servers }).map(async ([name, server]) => {\n if (!server) return;\n\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n }),\n );\n };\n\n autoDispose({ dispose: cleanup });\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', session.urls.appServer).href;\n\n performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n // Open the browser.\n if (options.open !== false) {\n openBrowser(defaultUrl).catch((err) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n console.warn('Error opening browser:', err?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n } else {\n console.log('Please open the browser manually to:', defaultUrl);\n }\n\n return null; // the command should keep running\n};\n\n/**\n * Create the API server, or return an error message if the server could not be created.\n */\nasync function createApiServer(\n options: StartOptions,\n apiContext: Context,\n): Promise<{ hasErrors: false; apiServer: CloudpackServer } | { hasErrors: true; message: string }> {\n const { session } = apiContext;\n const { config } = session;\n const { server, appPath } = config;\n\n // If a cert is needed, check that it exists.\n if (server?.https === true && !(await getCertificate({ domain: server?.domain, cwd: appPath }))) {\n return {\n hasErrors: true,\n message:\n `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to create the required certificate and try start again.\\n`,\n };\n }\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n try {\n const apiServer = await createCloudpackServer({ port: options.apiServerPort }, apiContext);\n return { hasErrors: false, apiServer };\n } catch (err) {\n let message: string;\n if ((err as { code: string }).code === 'EADDRNOTAVAIL' && server?.domain) {\n const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];\n message =\n `The domain \"${cyan(bold(primaryDomain))}\" in cloudpack.config.json is not resolvable.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to add the appropriate entries to your hosts file and ` +\n `try start again.\\n`;\n } else {\n message = `Error creating API server: ${(err as Error).stack || err}`;\n }\n return { hasErrors: true, message };\n }\n}\n\n// cspell:ignore Prereqs\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAUrH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,WAAW,CAkF9C,CAAC"}
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAUrH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,WAAW,CAiF9C,CAAC"}
@@ -7,24 +7,23 @@ function checkErrorCode(error, code) {
7
7
  return error instanceof Error && 'code' in error && error.code === code;
8
8
  }
9
9
  export const execute = async (params) => {
10
- const { options, cwd, initialize, exit, autoDispose } = params;
10
+ const { options, cwd, initialize, autoDispose } = params;
11
11
  const { login, upload } = options;
12
12
  const apiContextOptions = await initialize({ appPath: cwd });
13
13
  const { config, telemetryClient } = apiContextOptions;
14
14
  if (!config.features?.syncBundles) {
15
- await exit({ message: 'Sync is disabled' });
16
- return;
15
+ return { message: 'Sync is disabled' };
17
16
  }
18
17
  if (isSyncDisabledByUser()) {
19
18
  telemetryClient.rootSpan.setAttribute('syncDisabled', true);
20
- return exit({ message: 'CLOUDPACK_SYNC environment variable is set. Sync is disabled by the user.' });
19
+ return { message: 'CLOUDPACK_SYNC environment variable is set. Sync is disabled by the user.' };
21
20
  }
22
21
  try {
23
22
  const remoteCacheConfig = config.remoteCache;
24
23
  if (!remoteCacheConfig) {
25
- return exit({
24
+ return {
26
25
  message: 'Remote cache is not configured. Please add remoteCache to your cloudpack.config.json file to use this feature.',
27
- });
26
+ };
28
27
  }
29
28
  const input = {
30
29
  loginMethod: login,
@@ -44,29 +43,29 @@ export const execute = async (params) => {
44
43
  }));
45
44
  await syncDownload({ input, ctx });
46
45
  }
47
- return exit({ message: 'Sync complete' });
46
+ return { message: 'Sync complete' };
48
47
  }
49
48
  catch (error) {
50
49
  if (error instanceof Error) {
51
50
  telemetryClient.rootSpan.recordException(error);
52
51
  if (error.name === 'AuthenticationRequiredError' && error.message.includes('CrossPlatformLockError')) {
53
- return exit({
52
+ return {
54
53
  message: red(`Cloudpack encountered an issue acquiring authentication lock. It seems Cloudpack Sync may already be active in another process. Please wait for the current process to complete and then try again`),
55
54
  exitCode: ExitCodeGenericError,
56
- });
55
+ };
57
56
  }
58
57
  if (error.name === 'AuthenticationRequiredError' ||
59
58
  ('statusCode' in error && (error.statusCode === '401' || error.statusCode === '403'))) {
60
- return exit({
59
+ return {
61
60
  message: red('Authentication error. Please check your credentials and try again.'),
62
61
  exitCode: ExitCodeAuthenticationError,
63
- });
62
+ };
64
63
  }
65
64
  if (checkErrorCode(error, 'REQUEST_SEND_ERROR')) {
66
- return exit({
65
+ return {
67
66
  message: red('Connection error. Please check your connection and try again.'),
68
67
  exitCode: ExitCodeGenericError,
69
- });
68
+ };
70
69
  }
71
70
  }
72
71
  throw error;
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAsB,MAAM,8BAA8B,CAAC;AACrH,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAElD,SAAS,cAAc,CAAC,KAAc,EA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,CAAC;YACL,CAAC;YAED,IAAI,cAAc,CAAC,KAAK,EAAE,oBAAoB,CAAC,EAAE,CAAC;gBAChD,OAAO,IAAI,CAAC;oBACV,OAAO,EAAE,GAAG,CAAC,+DAA+D,CAAC;oBAC7E,QAAQ,EAAE,oBAAoB;iBAC/B,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { SyncOptions } from './types/SyncOptions.js';\nimport { ExitCodeAuthenticationError, ExitCodeGenericError, type CommandAction } from '../../types/CommandAction.js';\nimport { createPartialApiContext, syncDownload, syncUpload } from '@ms-cloudpack/api-server';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { isSyncDisabledByUser } from './isSyncDisabledByUser.js';\nimport { red } from '@ms-cloudpack/task-reporter';\n\nfunction checkErrorCode(error: unknown, code: string) {\n return error instanceof Error && 'code' in error && error.code === code;\n}\n\nexport const execute: CommandAction<SyncOptions> = async (params) => {\n const { options, cwd, initialize, exit, autoDispose } = params;\n const { login, upload } = options;\n const apiContextOptions = await initialize({ appPath: cwd });\n const { config, telemetryClient } = apiContextOptions;\n\n if (!config.features?.syncBundles) {\n await exit({ message: 'Sync is disabled' });\n return;\n }\n\n if (isSyncDisabledByUser()) {\n telemetryClient.rootSpan.setAttribute('syncDisabled', true);\n return exit({ message: 'CLOUDPACK_SYNC environment variable is set. Sync is disabled by the user.' });\n }\n\n try {\n const remoteCacheConfig = config.remoteCache;\n if (!remoteCacheConfig) {\n return exit({\n message:\n 'Remote cache is not configured. Please add remoteCache to your cloudpack.config.json file to use this feature.',\n });\n }\n\n const input = {\n loginMethod: login,\n };\n\n if (upload) {\n runPrerequisites(apiContextOptions);\n\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'taskRunner', 'watcher', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n }),\n );\n await syncUpload({ input, ctx });\n } else {\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['packages', 'session', 'packageHashes'],\n }),\n );\n await syncDownload({ input, ctx });\n }\n\n return exit({ message: 'Sync complete' });\n } catch (error) {\n if (error instanceof Error) {\n telemetryClient.rootSpan.recordException(error);\n\n if (error.name === 'AuthenticationRequiredError' && error.message.includes('CrossPlatformLockError')) {\n return exit({\n message: red(\n `Cloudpack encountered an issue acquiring authentication lock. It seems Cloudpack Sync may already be active in another process. Please wait for the current process to complete and then try again`,\n ),\n exitCode: ExitCodeGenericError,\n });\n }\n if (\n error.name === 'AuthenticationRequiredError' ||\n ('statusCode' in error && (error.statusCode === '401' || error.statusCode === '403'))\n ) {\n return exit({\n message: red('Authentication error. Please check your credentials and try again.'),\n exitCode: ExitCodeAuthenticationError,\n });\n }\n\n if (checkErrorCode(error, 'REQUEST_SEND_ERROR')) {\n return exit({\n message: red('Connection error. Please check your connection and try again.'),\n exitCode: ExitCodeGenericError,\n });\n }\n }\n\n throw error;\n }\n};\n"]}
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAsB,MAAM,8BAA8B,CAAC;AACrH,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAElD,SAAS,cAAc,CAAC,KAAc,EAAE,IAAY;IAClD,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC1E,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAA+B,KAAK,EAAE,MAAM,EAAE,EAAE;IAClE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eGenericError, type CommandAction } from '../../types/CommandAction.js';\nimport { createPartialApiContext, syncDownload, syncUpload } from '@ms-cloudpack/api-server';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { isSyncDisabledByUser } from './isSyncDisabledByUser.js';\nimport { red } from '@ms-cloudpack/task-reporter';\n\nfunction checkErrorCode(error: unknown, code: string) {\n return error instanceof Error && 'code' in error && error.code === code;\n}\n\nexport const execute: CommandAction<SyncOptions> = async (params) => {\n const { options, cwd, initialize, autoDispose } = params;\n const { login, upload } = options;\n const apiContextOptions = await initialize({ appPath: cwd });\n const { config, telemetryClient } = apiContextOptions;\n\n if (!config.features?.syncBundles) {\n return { message: 'Sync is disabled' };\n }\n\n if (isSyncDisabledByUser()) {\n telemetryClient.rootSpan.setAttribute('syncDisabled', true);\n return { message: 'CLOUDPACK_SYNC environment variable is set. Sync is disabled by the user.' };\n }\n\n try {\n const remoteCacheConfig = config.remoteCache;\n if (!remoteCacheConfig) {\n return {\n message:\n 'Remote cache is not configured. Please add remoteCache to your cloudpack.config.json file to use this feature.',\n };\n }\n\n const input = {\n loginMethod: login,\n };\n\n if (upload) {\n runPrerequisites(apiContextOptions);\n\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'taskRunner', 'watcher', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n }),\n );\n await syncUpload({ input, ctx });\n } else {\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['packages', 'session', 'packageHashes'],\n }),\n );\n await syncDownload({ input, ctx });\n }\n\n return { message: 'Sync complete' };\n } catch (error) {\n if (error instanceof Error) {\n telemetryClient.rootSpan.recordException(error);\n\n if (error.name === 'AuthenticationRequiredError' && error.message.includes('CrossPlatformLockError')) {\n return {\n message: red(\n `Cloudpack encountered an issue acquiring authentication lock. It seems Cloudpack Sync may already be active in another process. Please wait for the current process to complete and then try again`,\n ),\n exitCode: ExitCodeGenericError,\n };\n }\n if (\n error.name === 'AuthenticationRequiredError' ||\n ('statusCode' in error && (error.statusCode === '401' || error.statusCode === '403'))\n ) {\n return {\n message: red('Authentication error. Please check your credentials and try again.'),\n exitCode: ExitCodeAuthenticationError,\n };\n }\n\n if (checkErrorCode(error, 'REQUEST_SEND_ERROR')) {\n return {\n message: red('Connection error. Please check your connection and try again.'),\n exitCode: ExitCodeGenericError,\n };\n }\n }\n\n throw error;\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAO9D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,aAAa,CAsChD,CAAC"}
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAO9D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,aAAa,CA0ChD,CAAC"}
@@ -8,11 +8,15 @@ import path from 'path';
8
8
  */
9
9
  export const execute = async (params) => {
10
10
  // Use the current directory as the default package path.
11
- const { options, cwd: appPath, reporter, initialize, exit } = params;
11
+ const { options, cwd: appPath, reporter, initialize } = params;
12
12
  const { logResolveMap, cachePath } = options;
13
13
  await initialize({ appPath });
14
14
  console.debug('Unlinking packages...');
15
- const session = await getSessionToLink({ reporter, exit, cachePath });
15
+ const sessionResult = await getSessionToLink({ reporter, cachePath });
16
+ if (!sessionResult.session) {
17
+ return sessionResult;
18
+ }
19
+ const { session } = sessionResult;
16
20
  const client = await createCloudpackClient({ url: session.urls.apiServer, reporter });
17
21
  const message = `Unlinking paths for ${session.projectName} at "${appPath}"`;
18
22
  const task = reporter.addTask(message);
@@ -26,7 +30,7 @@ export const execute = async (params) => {
26
30
  if (linkedPaths.some((p) => p.path === appPath)) {
27
31
  // Close down with an error.
28
32
  task.complete({ status: 'fail', message: `Failed to unlink paths.`, forceShow: true });
29
- await exit({ exitCode: 1, message: 'Failed to unlink paths.' });
33
+ return { hasErrors: true, message: 'Failed to unlink paths.' };
30
34
  }
31
35
  if (logResolveMap) {
32
36
  // Write the unlinked resolve map to disk.
@@ -35,6 +39,6 @@ export const execute = async (params) => {
35
39
  // Close down successfully.
36
40
  task.complete({ status: 'complete', message: `Unlinked paths`, forceShow: true });
37
41
  const linkSummary = formatLinkSummary({ session, resolveMap, linkedPaths });
38
- await exit({ exitCode: 0, message: linkSummary });
42
+ return { message: linkSummary };
39
43
  };
40
44
  //# sourceMappingURL=execute.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAiC,KAAK,EAAE,MAAM,EAAE,EAAE;IACpE,yDAAyD;IACzD,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACrE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC7C,MAAM,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAE9B,OAAO,CAAC,KAAK,CAAC,uBA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I,EAAE,CAAC,CAAC;IAClF,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IAE5E,MAAM,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC","sourcesContent":["import type { CommandAction } from '../../types/CommandAction.js';\nimport type { UnlinkOptions } from './types/UnlinkOptions.js';\nimport { getSessionToLink } from '../link/getSessionToLink.js';\nimport { createCloudpackClient } from '@ms-cloudpack/api-server';\nimport { formatLinkSummary } from '../link/formatLinkSummary.js';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\n\n/**\n * Defines the \"unlink\" verb entry point.\n */\nexport const execute: CommandAction<UnlinkOptions> = async (params) => {\n // Use the current directory as the default package path.\n const { options, cwd: appPath, reporter, initialize, exit } = params;\n const { logResolveMap, cachePath } = options;\n await initialize({ appPath });\n\n console.debug('Unlinking packages...');\n\n const session = await getSessionToLink({ reporter, exit, cachePath });\n const client = await createCloudpackClient({ url: session.urls.apiServer, reporter });\n\n const message = `Unlinking paths for ${session.projectName} at \"${appPath}\"`;\n const task = reporter.addTask(message);\n\n // Send request to api server to link paths.\n const { resolveMap, linkedPaths } = await client.unlinkPath.query({\n linkedPath: {\n path: appPath,\n },\n });\n await client.close();\n\n if (linkedPaths.some((p) => p.path === appPath)) {\n // Close down with an error.\n task.complete({ status: 'fail', message: `Failed to unlink paths.`, forceShow: true });\n await exit({ exitCode: 1, message: 'Failed to unlink paths.' });\n }\n\n if (logResolveMap) {\n // Write the unlinked resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map-unlinked.json'), resolveMap);\n }\n\n // Close down successfully.\n task.complete({ status: 'complete', message: `Unlinked paths`, forceShow: true });\n const linkSummary = formatLinkSummary({ session, resolveMap, linkedPaths });\n\n await exit({ exitCode: 0, message: linkSummary });\n};\n"]}
1
+ {"version":3,"file":"execute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AC,UAAU,CAAC,KAAK,CAAC;QAChE,UAAU,EAAE;YACV,IAAI,EAAE,OAAO;SACd;KACF,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IAErB,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,CAAC;QAChD,4BAA4B;QAC5B,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvF,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC;IACjE,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,0CAA0C;QAC1C,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,2BAA2B,CAAC,EAAE,UAAU,CAAC,CAAC;IAC/E,CAAC;IAED,2BAA2B;IAC3B,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClF,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IAE5E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC","sourcesContent":["import type { CommandAction } from '../../types/CommandAction.js';\nimport type { UnlinkOptions } from './types/UnlinkOptions.js';\nimport { getSessionToLink } from '../link/getSessionToLink.js';\nimport { createCloudpackClient } from '@ms-cloudpack/api-server';\nimport { formatLinkSummary } from '../link/formatLinkSummary.js';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\n\n/**\n * Defines the \"unlink\" verb entry point.\n */\nexport const execute: CommandAction<UnlinkOptions> = async (params) => {\n // Use the current directory as the default package path.\n const { options, cwd: appPath, reporter, initialize } = params;\n const { logResolveMap, cachePath } = options;\n await initialize({ appPath });\n\n console.debug('Unlinking packages...');\n\n const sessionResult = await getSessionToLink({ reporter, cachePath });\n if (!sessionResult.session) {\n return sessionResult;\n }\n const { session } = sessionResult;\n const client = await createCloudpackClient({ url: session.urls.apiServer, reporter });\n\n const message = `Unlinking paths for ${session.projectName} at \"${appPath}\"`;\n const task = reporter.addTask(message);\n\n // Send request to api server to link paths.\n const { resolveMap, linkedPaths } = await client.unlinkPath.query({\n linkedPath: {\n path: appPath,\n },\n });\n await client.close();\n\n if (linkedPaths.some((p) => p.path === appPath)) {\n // Close down with an error.\n task.complete({ status: 'fail', message: `Failed to unlink paths.`, forceShow: true });\n return { hasErrors: true, message: 'Failed to unlink paths.' };\n }\n\n if (logResolveMap) {\n // Write the unlinked resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map-unlinked.json'), resolveMap);\n }\n\n // Close down successfully.\n task.complete({ status: 'complete', message: `Unlinked paths`, forceShow: true });\n const linkSummary = formatLinkSummary({ session, resolveMap, linkedPaths });\n\n return { message: linkSummary };\n};\n"]}
@@ -62,21 +62,19 @@ export interface CommandActionParams<TOptions extends object> {
62
62
  appPaths: string[];
63
63
  }): Promise<AppCommandContext[]>;
64
64
  };
65
- /**
66
- * This should be called at the end of the action to dispose resources, log completion,
67
- * and exit the program. (See `CommandExecutor._exit` for implementation.)
68
- */
69
- exit: (result: CommandExitParams) => Promise<void>;
70
65
  /**
71
66
  * Set a callback to get the message to display if ctrl+C is pressed.
72
67
  */
73
68
  setInterruptMessageHandler: (getMessage: () => string) => void;
74
69
  }
75
70
  /**
76
- * Command action function. This is the type of the `execute` function which should be exported
77
- * from each command's `src/commands/<name>/execute.ts` module.
71
+ * Command action function (executor). This is the type of the `execute` function which should
72
+ * be exported from each command's `src/commands/<name>/execute.ts` module.
73
+ *
74
+ * If it returns an object, the command wrapper will call the exit handler with that object.
75
+ * If it returns null, it's assumed that this command is meant to keep running, such as `start`.
78
76
  */
79
- export type CommandAction<TOptions> = (params: CommandActionParams<TOptions & SharedOptions>) => Promise<void>;
77
+ export type CommandAction<TOptions> = (params: CommandActionParams<TOptions & SharedOptions>) => Promise<CommandExitParams | null>;
80
78
  export type CommandActionModule<TOptions> = {
81
79
  execute: CommandAction<TOptions>;
82
80
  };
@@ -1 +1 @@
1
- {"version":3,"file":"CommandAction.d.ts","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,qBAAqB,EACrB,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,iBAAiB,CACpE,CAAC;AAEF,8CAA8C;AAC9C,MAAM,WAAW,wBAAwB;IACvC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAED,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,MAAM,MAAM,QAAQ,GAAG,OAAO,kBAAkB,GAAG,OAAO,oBAAoB,GAAG,OAAO,2BAA2B,CAAC;AAEpH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB,CAAC,QAAQ,SAAS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EAAE,CAAA;SAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;KACtG,CAAC;IAEF;;OAEG;IACH,0BAA0B,EAAE,CAAC,UAAU,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;CAChE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,CAAC,QAAQ,IAAI,CACpC,MAAM,EAAE,mBAAmB,CAAC,QAAQ,GAAG,aAAa,CAAC,KAClD,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;AAEvC,MAAM,MAAM,mBAAmB,CAAC,QAAQ,IAAI;IAC1C,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;CAClC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandAction.js","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC","sourcesContent":["import type { LazyApiContextOptions } from '@ms-cloudpack/api-server';\nimport type { ReadConfigOptions } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\n\n/**\n * Context for running a command in a specific app (after initialization).\n * For convenience, this can be passed/spread directly to `createPartialApiContext`.\n */\nexport type AppCommandContext = Pick<\n LazyApiContextOptions,\n 'appPath' | 'cachePath' | 'config' | 'reporter' | 'telemetryClient'\n>;\n\n/** Initialize options excluding `appPaths` */\nexport interface CommandInitializeOptions {\n /** Additional options to merge in while reading the config. */\n configOptions?: ReadConfigOptions;\n}\n\nexport const ExitCodeSuccessful = 0;\nexport const ExitCodeGenericError = 1;\nexport const ExitCodeAuthenticationError = 2;\nexport type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError;\n\nexport interface CommandExitParams {\n message: string;\n hasErrors?: boolean;\n exitCode?: ExitCode;\n}\n\nexport interface CommandActionParams<TOptions extends object> {\n /**\n * Initial working directory (usually `process.cwd()` except in tests).\n * Note that this may differ from the `appPath` used by individual commands.\n */\n cwd: string;\n\n /**\n * Command-specific options, parsed from `process.argv`.\n * Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.\n * The command line options are defined in each command's `src/commands/<name>/index.ts` module.\n */\n options: TOptions;\n\n /**\n * Command-specific arguments. Arguments in commander are positional arguments that are not options.\n * For example, in `echo somestring`, `somestring` is an argument.\n */\n args: string[];\n\n reporter: TaskReporter;\n\n abortSignal: AbortSignal;\n\n /**\n * Function that can be called with any `Disposable`s that should be cleaned up automatically\n * when the program exits. (See `AutoDisposableList.add` for implementation.)\n */\n autoDispose: AutoDispose;\n\n /**\n * This should be called at or near the beginning of the action to initialize the config,\n * telemetry, and reporting. (See `CommandExecutor._initialize` for implementation.)\n * `initialize` can be called with either a single string, `appPath` or an a string[], `appPaths`.\n *\n * If it is called with a single string, it returns `Promise<AppCommandContext>`\n * If it is called with a string[], it returns `Promise<AppCommandContext[]>`\n */\n initialize: {\n (initializeOptions: CommandInitializeOptions & { appPath: string }): Promise<AppCommandContext>;\n (initializeOptions: CommandInitializeOptions & { appPaths: string[] }): Promise<AppCommandContext[]>;\n };\n\n /**\n * This should be called at the end of the action to dispose resources, log completion,\n * and exit the program. (See `CommandExecutor._exit` for implementation.)\n */\n exit: (result: CommandExitParams) => Promise<void>;\n\n /**\n * Set a callback to get the message to display if ctrl+C is pressed.\n */\n setInterruptMessageHandler: (getMessage: () => string) => void;\n}\n\n/**\n * Command action function. This is the type of the `execute` function which should be exported\n * from each command's `src/commands/<name>/execute.ts` module.\n */\nexport type CommandAction<TOptions> = (params: CommandActionParams<TOptions & SharedOptions>) => Promise<void>;\n\nexport type CommandActionModule<TOptions> = {\n execute: CommandAction<TOptions>;\n};\n"]}
1
+ {"version":3,"file":"CommandAction.js","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC","sourcesContent":["import type { LazyApiContextOptions } from '@ms-cloudpack/api-server';\nimport type { ReadConfigOptions } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\n\n/**\n * Context for running a command in a specific app (after initialization).\n * For convenience, this can be passed/spread directly to `createPartialApiContext`.\n */\nexport type AppCommandContext = Pick<\n LazyApiContextOptions,\n 'appPath' | 'cachePath' | 'config' | 'reporter' | 'telemetryClient'\n>;\n\n/** Initialize options excluding `appPaths` */\nexport interface CommandInitializeOptions {\n /** Additional options to merge in while reading the config. */\n configOptions?: ReadConfigOptions;\n}\n\nexport const ExitCodeSuccessful = 0;\nexport const ExitCodeGenericError = 1;\nexport const ExitCodeAuthenticationError = 2;\nexport type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError;\n\nexport interface CommandExitParams {\n message: string;\n hasErrors?: boolean;\n exitCode?: ExitCode;\n}\n\nexport interface CommandActionParams<TOptions extends object> {\n /**\n * Initial working directory (usually `process.cwd()` except in tests).\n * Note that this may differ from the `appPath` used by individual commands.\n */\n cwd: string;\n\n /**\n * Command-specific options, parsed from `process.argv`.\n * Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.\n * The command line options are defined in each command's `src/commands/<name>/index.ts` module.\n */\n options: TOptions;\n\n /**\n * Command-specific arguments. Arguments in commander are positional arguments that are not options.\n * For example, in `echo somestring`, `somestring` is an argument.\n */\n args: string[];\n\n reporter: TaskReporter;\n\n abortSignal: AbortSignal;\n\n /**\n * Function that can be called with any `Disposable`s that should be cleaned up automatically\n * when the program exits. (See `AutoDisposableList.add` for implementation.)\n */\n autoDispose: AutoDispose;\n\n /**\n * This should be called at or near the beginning of the action to initialize the config,\n * telemetry, and reporting. (See `CommandExecutor._initialize` for implementation.)\n * `initialize` can be called with either a single string, `appPath` or an a string[], `appPaths`.\n *\n * If it is called with a single string, it returns `Promise<AppCommandContext>`\n * If it is called with a string[], it returns `Promise<AppCommandContext[]>`\n */\n initialize: {\n (initializeOptions: CommandInitializeOptions & { appPath: string }): Promise<AppCommandContext>;\n (initializeOptions: CommandInitializeOptions & { appPaths: string[] }): Promise<AppCommandContext[]>;\n };\n\n /**\n * Set a callback to get the message to display if ctrl+C is pressed.\n */\n setInterruptMessageHandler: (getMessage: () => string) => void;\n}\n\n/**\n * Command action function (executor). This is the type of the `execute` function which should\n * be exported from each command's `src/commands/<name>/execute.ts` module.\n *\n * If it returns an object, the command wrapper will call the exit handler with that object.\n * If it returns null, it's assumed that this command is meant to keep running, such as `start`.\n */\nexport type CommandAction<TOptions> = (\n params: CommandActionParams<TOptions & SharedOptions>,\n) => Promise<CommandExitParams | null>;\n\nexport type CommandActionModule<TOptions> = {\n execute: CommandAction<TOptions>;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import type { CommandAction } from '../types/CommandAction.js';
1
+ import type { CommandAction, CommandExitParams } from '../types/CommandAction.js';
2
2
  import type { ProgramOptions } from '../types/ProgramOptions.js';
3
3
  import type { SharedOptions } from '../types/SharedOptions.js';
4
4
  /**
@@ -15,6 +15,8 @@ export declare class CommandExecutor<TOptions extends SharedOptions> {
15
15
  private _hasCalledExit;
16
16
  private _args;
17
17
  private _getMessageOnInterrupt;
18
+ private static _activeInstances;
19
+ static exitAll(params: CommandExitParams): Promise<void>;
18
20
  constructor(params: {
19
21
  /** Command-specific arguments */
20
22
  args: string[];
@@ -38,9 +40,9 @@ export declare class CommandExecutor<TOptions extends SharedOptions> {
38
40
  private _initialize;
39
41
  private _initTelemetry;
40
42
  /**
41
- * This is the `exit` function passed to the command's execute function.
42
- * (It must be an arrow function to ensure the correct `this` context.)
43
+ * Exit function called with the result returned by the command's execute function,
44
+ * or manually via `CommandExecutor.exitAll()` in tests.
43
45
  */
44
- private _exit;
46
+ protected _exit(params: CommandExitParams): Promise<void>;
45
47
  }
46
48
  //# sourceMappingURL=CommandExecutor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CommandExecutor.d.ts","sourceRoot":"","sources":["../../src/utilities/CommandExecutor.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,aAAa,EAId,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAQ/D;;GAEG;AACH,qBAAa,eAAe,CAAC,QAAQ,SAAS,aAAa;IACzD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,SAAS,CAAe;IAChC,OAAO,CAAC,mBAAmB,CAAqB;IAChD,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,sBAAsB,CAA+B;gBAEjD,MAAM,EAAE;QAClB,iCAAiC;QACjC,IAAI,EAAE,MAAM,EAAE,CAAC;QACf,2CAA2C;QAC3C,OAAO,EAAE,QAAQ,CAAC;QAClB,uCAAuC;QACvC,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjC,0CAA0C;QAC1C,cAAc,EAAE,cAAc,CAAC;QAC/B,sDAAsD;QACtD,IAAI,EAAE,MAAM,CAAC;KACd;IAWD,uBAAuB;IAEV,OAAO;IA4CpB;;;;;OAKG;YACW,WAAW;YAuGX,cAAc;IAwE5B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37 +14,16 @@ import { mergeFeatures } from './mergeFeatures.js';
14
14
  * This class manages orchestration and shared state while executing a command.
15
15
  */
16
16
  export class CommandExecutor {
17
+ static async exitAll(params) {
18
+ // There should only be one instance at a time, but we assume multiple instances for safety.
19
+ for (const instance of CommandExecutor._activeInstances) {
20
+ await instance._exit(params);
21
+ }
22
+ CommandExecutor._activeInstances = [];
23
+ }
17
24
  constructor(params) {
18
25
  this._hasCalledExit = false;
19
26
  this._getMessageOnInterrupt = () => `Interrupted by user`;
20
- /**
21
- * This is the `exit` function passed to the command's execute function.
22
- * (It must be an arrow function to ensure the correct `this` context.)
23
- */
24
- this._exit = async (params) => {
25
- const { message, hasErrors = this._reporter.hasErrors(), exitCode = hasErrors ? 1 : 0 } = params;
26
- if (this._hasCalledExit) {
27
- // Skip most of the operations if exit() was called multiple times.
28
- // But only use the error message if not in a test, due to the way we're mocking process.exit.
29
- if (!process.env.JEST_WORKER_ID) {
30
- const prettyParams = Object.entries(params)
31
- .map(([key, value]) => `${key}="${value}"`)
32
- .join(', ');
33
- console.warn(`exit() was called multiple times. This call's options: ${prettyParams}.`);
34
- }
35
- }
36
- else {
37
- this._hasCalledExit = true;
38
- // Let the execute function know that we are exiting.
39
- this._abortController.abort();
40
- // Dispose all registered disposables.
41
- await this._autoDisposableList.dispose();
42
- const exitWithError = exitCode !== 0;
43
- // Show the summary message (this will throw if called twice).
44
- this._reporter.complete(hasErrors ? red(message) : message, exitWithError);
45
- }
46
- process.exit(exitCode);
47
- };
48
27
  this._args = params.args;
49
28
  this._options = params.options;
50
29
  this._execute = params.execute;
@@ -57,6 +36,7 @@ export class CommandExecutor {
57
36
  /** Run the command. */
58
37
  // This has to be a separate method because constructors can't be async.
59
38
  async execute() {
39
+ CommandExecutor._activeInstances.push(this);
60
40
  try {
61
41
  // Setup cleanup and close things on completion.
62
42
  let sigintCount = 0;
@@ -74,7 +54,7 @@ export class CommandExecutor {
74
54
  });
75
55
  // Call the execute function which is the real command logic
76
56
  // (ie: real init command logic, real start command logic, etc.)
77
- await this._execute({
57
+ const result = await this._execute({
78
58
  args: this._args,
79
59
  options: this._options,
80
60
  cwd: this._programOptions.cwd,
@@ -82,11 +62,13 @@ export class CommandExecutor {
82
62
  initialize: this._initialize.bind(this),
83
63
  abortSignal: this._abortController.signal,
84
64
  autoDispose: (disposable) => this._autoDisposableList.add(disposable),
85
- exit: this._exit,
86
65
  setInterruptMessageHandler: (getMessage) => {
87
66
  this._getMessageOnInterrupt = getMessage;
88
67
  },
89
68
  });
69
+ if (result) {
70
+ await this._exit(result);
71
+ }
90
72
  }
91
73
  catch (error) {
92
74
  // If an error occurs, exit the process with a non-zero exit code.
@@ -229,5 +211,35 @@ export class CommandExecutor {
229
211
  });
230
212
  return telemetryClient;
231
213
  }
214
+ /**
215
+ * Exit function called with the result returned by the command's execute function,
216
+ * or manually via `CommandExecutor.exitAll()` in tests.
217
+ */
218
+ async _exit(params) {
219
+ const { message, hasErrors = this._reporter.hasErrors(), exitCode = hasErrors ? 1 : 0 } = params;
220
+ if (this._hasCalledExit) {
221
+ // Skip most of the operations if exit() was called multiple times.
222
+ // But only use the error message if not in a test, due to the way we're mocking process.exit.
223
+ if (!process.env.JEST_WORKER_ID) {
224
+ const prettyParams = Object.entries(params)
225
+ .map(([key, value]) => `${key}="${value}"`)
226
+ .join(', ');
227
+ console.warn(`exit() was called multiple times. This call's options: ${prettyParams}.`);
228
+ }
229
+ }
230
+ else {
231
+ this._hasCalledExit = true;
232
+ // Let the execute function know that we are exiting.
233
+ this._abortController.abort();
234
+ // Dispose all registered disposables.
235
+ await this._autoDisposableList.dispose();
236
+ const exitWithError = exitCode !== 0;
237
+ // Show the summary message (this will throw if called twice).
238
+ this._reporter.complete(hasErrors ? red(message) : message, exitWithError);
239
+ }
240
+ process.exit(exitCode);
241
+ }
232
242
  }
243
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- options type isn't used
244
+ CommandExecutor._activeInstances = [];
233
245
  //# sourceMappingURL=CommandExecutor.js.map