@ms-cloudpack/cli 0.34.0 → 0.35.1

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.
@@ -2,7 +2,6 @@ import { express } from '@ms-cloudpack/create-express-app';
2
2
  import { createImportMap } from '@ms-cloudpack/package-utilities';
3
3
  import { slash } from '@ms-cloudpack/path-string-parsing';
4
4
  import path from 'path';
5
- import { error } from './error.js';
6
5
  import { getHtmlResponse } from './getHtmlResponse.js';
7
6
  import { getInlineScripts } from './inlineScripts/getInlineScripts.js';
8
7
  import { handleSessionVersion } from './handleSessionVersion.js';
@@ -61,7 +60,7 @@ export function createRoutes({ app, url, session, definition, bundleServer, apiS
61
60
  res.status(statusCode).send(html).end();
62
61
  log(`App server: Request: ${requestPath}, ext: ${requestExt}`);
63
62
  })().catch((err) => {
64
- error(err?.stack || err);
63
+ console.error(err?.stack || err);
65
64
  res.status(500).send(`Error loading app: ${err}`);
66
65
  });
67
66
  });
@@ -1 +1 @@
1
- {"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/createRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C;;GAEG;AACH,MAAM,UA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;AACH,CAAC","sourcesContent":["import type { PackageJson } from '@ms-cloudpack/bundler-types';\nimport type { Express, Request, Response } from '@ms-cloudpack/create-express-app';\nimport { express } from '@ms-cloudpack/create-express-app';\nimport { createImportMap } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport type { BundleServer } from '../../../types.js';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport { error } from './error.js';\nimport { getHtmlResponse } from './getHtmlResponse.js';\nimport { getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { handleSessionVersion } from './handleSessionVersion.js';\nimport { log } from './log.js';\nimport { setHeaders } from './setHeaders.js';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\n\n/**\n * Creates the routes for the express app, considering how the config is defined.\n */\nexport function createRoutes({\n app,\n url,\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n}: {\n app: Express;\n url: string;\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n}) {\n const routes = [...(config.devServer?.routes || [])];\n const hasDefaultRoute = routes.some((route) => route.match === '*' || route.match === '/');\n\n if (!hasDefaultRoute) {\n routes.push({\n match: '*',\n exportEntry: '.',\n });\n }\n\n for (const route of routes) {\n if (route.staticPath) {\n app.use(route.match, express.static(path.resolve(session.appPath, route.staticPath)));\n } else {\n app.get(route.match, (req: Request, res: Response) => {\n (async () => {\n // Build the import map if it hasn't been built yet for this session version.\n const sessionVersion = handleSessionVersion(session, req);\n const importMap =\n session.getImportMap() ||\n session.setImportMap(\n await createImportMap(session.resolveMap, bundleServer.url, {\n sessionVersion,\n targetVersions: session.targetVersions,\n }),\n );\n\n // Parse the request path, extension, grab the overlay script path.\n const requestPath = slash(req.path.substring(1));\n const requestExt = path.extname(requestPath);\n const overlayScript = importMap.imports['@ms-cloudpack/overlay'];\n const entryScript =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n route.exportEntry && importMap.imports[slash(path.join(definition.name!, route.exportEntry))];\n\n // Set the apppropriate Cloudpack headers/cookies in the response.\n // TODO: setting the headers here prohibits cases where the page rendering is owned by existing server code\n // that can only accept changing the scripts. We should consider moving to a model where an initial script\n // fetch loads the import map and sets Cloudpack settings in local storage rather than headers/cookies.\n setHeaders({ res, session, apiServer });\n\n const inlineScripts = await getInlineScripts();\n const { html, statusCode } = await getHtmlResponse({\n route,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n session,\n definition,\n inlineScripts,\n });\n\n // Send the result.\n res.status(statusCode).send(html).end();\n\n log(`App server: Request: ${requestPath}, ext: ${requestExt}`);\n })().catch((err) => {\n error((err as Error)?.stack || err);\n res.status(500).send(`Error loading app: ${err}`);\n });\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/createRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,GAAG,EACH,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,MAAM,GASP;IACC,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,CAAC,C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AAC;oBACjE,MAAM,WAAW;oBACf,oEAAoE;oBACpE,KAAK,CAAC,WAAW,IAAI,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAK,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;oBAEhG,kEAAkE;oBAClE,2GAA2G;oBAC3G,0GAA0G;oBAC1G,uGAAuG;oBACvG,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;oBAExC,MAAM,aAAa,GAAG,MAAM,gBAAgB,EAAE,CAAC;oBAC/C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,eAAe,CAAC;wBACjD,KAAK;wBACL,OAAO,EAAE,GAAG;wBACZ,SAAS;wBACT,aAAa;wBACb,WAAW;wBACX,OAAO;wBACP,UAAU;wBACV,aAAa;qBACd,CAAC,CAAC;oBAEH,mBAAmB;oBACnB,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;oBAExC,GAAG,CAAC,wBAAwB,WAAW,UAAU,UAAU,EAAE,CAAC,CAAC;gBACjE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACjB,OAAO,CAAC,KAAK,CAAE,GAAa,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;oBAC5C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;gBACpD,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;KACF;AACH,CAAC","sourcesContent":["import type { PackageJson } from '@ms-cloudpack/bundler-types';\nimport type { Express, Request, Response } from '@ms-cloudpack/create-express-app';\nimport { express } from '@ms-cloudpack/create-express-app';\nimport { createImportMap } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport type { BundleServer } from '../../../types.js';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport { getHtmlResponse } from './getHtmlResponse.js';\nimport { getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { handleSessionVersion } from './handleSessionVersion.js';\nimport { log } from './log.js';\nimport { setHeaders } from './setHeaders.js';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\n\n/**\n * Creates the routes for the express app, considering how the config is defined.\n */\nexport function createRoutes({\n app,\n url,\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n}: {\n app: Express;\n url: string;\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n}) {\n const routes = [...(config.devServer?.routes || [])];\n const hasDefaultRoute = routes.some((route) => route.match === '*' || route.match === '/');\n\n if (!hasDefaultRoute) {\n routes.push({\n match: '*',\n exportEntry: '.',\n });\n }\n\n for (const route of routes) {\n if (route.staticPath) {\n app.use(route.match, express.static(path.resolve(session.appPath, route.staticPath)));\n } else {\n app.get(route.match, (req: Request, res: Response) => {\n (async () => {\n // Build the import map if it hasn't been built yet for this session version.\n const sessionVersion = handleSessionVersion(session, req);\n const importMap =\n session.getImportMap() ||\n session.setImportMap(\n await createImportMap(session.resolveMap, bundleServer.url, {\n sessionVersion,\n targetVersions: session.targetVersions,\n }),\n );\n\n // Parse the request path, extension, grab the overlay script path.\n const requestPath = slash(req.path.substring(1));\n const requestExt = path.extname(requestPath);\n const overlayScript = importMap.imports['@ms-cloudpack/overlay'];\n const entryScript =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n route.exportEntry && importMap.imports[slash(path.join(definition.name!, route.exportEntry))];\n\n // Set the apppropriate Cloudpack headers/cookies in the response.\n // TODO: setting the headers here prohibits cases where the page rendering is owned by existing server code\n // that can only accept changing the scripts. We should consider moving to a model where an initial script\n // fetch loads the import map and sets Cloudpack settings in local storage rather than headers/cookies.\n setHeaders({ res, session, apiServer });\n\n const inlineScripts = await getInlineScripts();\n const { html, statusCode } = await getHtmlResponse({\n route,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n session,\n definition,\n inlineScripts,\n });\n\n // Send the result.\n res.status(statusCode).send(html).end();\n\n log(`App server: Request: ${requestPath}, ext: ${requestExt}`);\n })().catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error loading app: ${err}`);\n });\n });\n }\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- import { error } from './error.js';
2
1
  /**
3
2
  * Report the error and exit if the port is already in use.
4
3
  */
@@ -8,7 +7,7 @@ export function exitIfPortUnavailable(err, projectName, ports) {
8
7
  const portNeedsPrivileges = portRange.some((port) => port < 1024)
9
8
  ? '\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'
10
9
  : '';
11
- error(`Cloudpack could not start "${projectName}" because no port from the allowed list was available: ${portRange.join(', ')}. Close other programs and try again.`, portNeedsPrivileges);
10
+ console.error(`Cloudpack could not start "${projectName}" because no port from the allowed list was available: ${portRange.join(', ')}. Close other programs and try again.`, portNeedsPrivileges);
12
11
  process.exit(1);
13
12
  }
14
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"exitIfPortUnavailable.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/exitIfPortUnavailable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY,EAAE,WAAmB,EAAE,KAAwB;IAC/F,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,KAAK,8BAA8B,EAAE;QAC1E,MAAM,mBAAmB,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;YAC/D,CAAC,CAAC,iKAAiK;YACnK,CAAC,CAAC,EAAE,CAAC;QACP,KAAK,CACH,8BAA8B,WAAW,0DAA0D,SAAS,CAAC,IAAI,CAC/G,IAAI,CACL,uCAAuC,EACxC,mBAAmB,CACpB,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC","sourcesContent":["import { error } from './error.js';\n\n/**\n * Report the error and exit if the port is already in use.\n */\nexport function exitIfPortUnavailable(err: unknown, projectName: string, ports: number | number[]) {\n const portRange = typeof ports === 'number' ? [ports] : ports;\n if (err instanceof Error && err.message === 'Specified port not available') {\n const portNeedsPrivileges = portRange.some((port) => port < 1024)\n ? '\\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'\n : '';\n error(\n `Cloudpack could not start \"${projectName}\" because no port from the allowed list was available: ${portRange.join(\n ', ',\n )}. Close other programs and try again.`,\n portNeedsPrivileges,\n );\n\n process.exit(1);\n }\n}\n"]}
1
+ {"version":3,"file":"exitIfPortUnavailable.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/exitIfPortUnavailable.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY,EAAE,WAAmB,EAAE,KAAwB;IAC/F,MAAM,SAAS,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9D,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,KAAK,8BAA8B,EAAE;QAC1E,MAAM,mBAAmB,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;YAC/D,CAAC,CAAC,iKAAiK;YACnK,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,CAAC,KAAK,CACX,8BAA8B,WAAW,0DAA0D,SAAS,CAAC,IAAI,CAC/G,IAAI,CACL,uCAAuC,EACxC,mBAAmB,CACpB,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC","sourcesContent":["/**\n * Report the error and exit if the port is already in use.\n */\nexport function exitIfPortUnavailable(err: unknown, projectName: string, ports: number | number[]) {\n const portRange = typeof ports === 'number' ? [ports] : ports;\n if (err instanceof Error && err.message === 'Specified port not available') {\n const portNeedsPrivileges = portRange.some((port) => port < 1024)\n ? '\\nNote: for Mac/Linux/WSL users, you may need to run Cloudpack with elevated privileges to use port numbers less than 1024. Try running `sudo cloudpack start`.'\n : '';\n console.error(\n `Cloudpack could not start \"${projectName}\" because no port from the allowed list was available: ${portRange.join(\n ', ',\n )}. Close other programs and try again.`,\n portNeedsPrivileges,\n );\n\n process.exit(1);\n }\n}\n"]}
@@ -3,7 +3,6 @@ import { pathToFileURL } from 'url';
3
3
  import { getDefaultHtmlResponse } from './getDefaultHtmlResponse.js';
4
4
  import { JSDOM } from 'jsdom';
5
5
  import fsPromises from 'fs/promises';
6
- import { error } from './error.js';
7
6
  /**
8
7
  * Get the HTML response for the given route. If the route has a custom render script, use that.
9
8
  */
@@ -33,11 +32,11 @@ export async function getHtmlResponse(options) {
33
32
  createHtml = (await import(renderScriptUrl + cacheBreakerQueryParam)).default;
34
33
  }
35
34
  catch (e) {
36
- error(`Error importing render script at "${renderScriptUrl}":`, e);
35
+ console.error(`Error importing render script at "${renderScriptUrl}":`, e);
37
36
  }
38
37
  }
39
38
  if (!createHtml) {
40
- error(`The render script at "${renderScriptPath}" does not export a default function.`);
39
+ console.error(`The render script at "${renderScriptPath}" does not export a default function.`);
41
40
  }
42
41
  }
43
42
  const htmlResult = await createHtml(options);
@@ -66,7 +65,7 @@ export async function getHtmlResponse(options) {
66
65
  html = htmlDocument.serialize();
67
66
  }
68
67
  catch (e) {
69
- error(`Error parsing html response for rendering route "${route.match}"`, e);
68
+ console.error(`Error parsing html response for rendering route "${route.match}"`, e);
70
69
  }
71
70
  return {
72
71
  html,
@@ -97,7 +96,7 @@ async function readStaticHtml(options) {
97
96
  html = (await fsPromises.readFile(htmlPath, 'utf8')) || '';
98
97
  }
99
98
  catch (e) {
100
- error(`Error reading HTML file at "${htmlPath}".`, e);
99
+ console.error(`Error reading HTML file at "${htmlPath}".`, e);
101
100
  }
102
101
  }
103
102
  return html;
@@ -1 +1 @@
1
- {"version":3,"file":"getHtmlResponse.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/getHtmlResponse.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA0B;IAC9D,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAC9E,IAAI,UAAU,GAAuB,sBAAsB,CAAC;IAE5D,IAAI,KAAK,CAAC,YAAY,EAAE;QACtB,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAC3E,IAAI,sBAAsB,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAEhD,IAAI;YACF,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO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W,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AACzD,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,OAA0B;IACtD,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1B,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,IAAI,KAAK,CAAC,YAAY,EAAE;QACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAE3E,IAAI;YACF,IAAI,GAAG,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5D;QAAC,OAAO,CAAC,EAAE;YACV,KAAK,CAAC,+BAA+B,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;SACvD;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import path from 'path';\nimport { pathToFileURL } from 'url';\nimport type { CreateHtmlOptions, CreateHtmlResult, CreateHtmlFunction, CreateHtmlScript } from '../../../types.js';\nimport { getDefaultHtmlResponse } from './getDefaultHtmlResponse.js';\nimport { JSDOM } from 'jsdom';\nimport fsPromises from 'fs/promises';\nimport { error } from './error.js';\n\n/**\n * Get the HTML response for the given route. If the route has a custom render script, use that.\n */\nexport async function getHtmlResponse(options: CreateHtmlOptions): Promise<Exclude<CreateHtmlResult, string>> {\n const { route, session, overlayScript, entryScript, inlineScripts } = options;\n let createHtml: CreateHtmlFunction = getDefaultHtmlResponse;\n\n if (route.renderScript) {\n const renderScriptPath = path.resolve(session.appPath, route.renderScript);\n let cacheBreakerQueryParam = `?t=${Date.now()}`;\n\n try {\n const { mtime } = await fsPromises.stat(path.resolve(session.appPath, route.renderScript));\n\n cacheBreakerQueryParam = `?t=${mtime.getTime()}`;\n } catch {\n /* no-op */\n }\n\n if (isHtml(renderScriptPath)) {\n createHtml = readStaticHtml;\n } else {\n // Get the html factory function from a script default export.\n const renderScriptUrl = pathToFileURL(renderScriptPath).toString();\n\n // Note: because there isn't a way to purge the require cache, we need to add a cache breaker query param to the\n // script path to ensure we get the latest version of the script. This could be improved by using the git hash of\n // the file if it exists, or a hash of the content, or even the timestamp of the file.\n try {\n createHtml = ((await import(renderScriptUrl + cacheBreakerQueryParam)) as CreateHtmlScript).default;\n } catch (e) {\n error(`Error importing render script at \"${renderScriptUrl}\":`, e);\n }\n }\n\n if (!createHtml) {\n error(`The render script at \"${renderScriptPath}\" does not export a default function.`);\n }\n }\n\n const htmlResult = await createHtml(options);\n let html = typeof htmlResult === 'string' ? htmlResult : htmlResult.html;\n const statusCode = typeof htmlResult === 'string' ? 200 : htmlResult.statusCode || 200;\n\n try {\n const htmlDocument = new JSDOM(html);\n const { document } = htmlDocument.window;\n\n // inject the import map.\n if (entryScript || overlayScript) {\n const script = document.createElement('script');\n script.type = 'importmap';\n script.innerHTML = JSON.stringify(session.getImportMap(), null, 2);\n document.head.prepend(script);\n }\n\n for (const inlineScript of inlineScripts) {\n const script = document.createElement('script');\n script.type = 'module';\n script.innerHTML = inlineScript;\n document.head.appendChild(script);\n }\n\n // inject the overlay script.\n addScript(document.head, overlayScript);\n\n // inject the entry script.\n addScript(document.head, entryScript);\n\n html = htmlDocument.serialize();\n } catch (e) {\n error(`Error parsing html response for rendering route \"${route.match}\"`, e);\n }\n\n return {\n html,\n statusCode,\n };\n}\n\n/**\n * Helper function to add a script to the document.\n */\nfunction addScript(parentElement: HTMLElement, url: string | undefined) {\n if (url) {\n const script = parentElement.ownerDocument.createElement('script');\n\n script.type = 'module';\n script.src = url;\n parentElement.appendChild(script);\n }\n}\n\nfunction isHtml(path: string): boolean {\n // path has an .htm or .html extension; case insensitive.\n return path.toLowerCase().match(/\\.htm(l)?$/) !== null;\n}\n\nasync function readStaticHtml(options: CreateHtmlOptions): Promise<string> {\n const { route } = options;\n let html = '';\n\n if (route.renderScript) {\n const htmlPath = path.resolve(options.session.appPath, route.renderScript);\n\n try {\n html = (await fsPromises.readFile(htmlPath, 'utf8')) || '';\n } catch (e) {\n error(`Error reading HTML file at \"${htmlPath}\".`, e);\n }\n }\n\n return html;\n}\n"]}
1
+ {"version":3,"file":"getHtmlResponse.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/getHtmlResponse.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAA0B;IAC9D,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAC9E,IAAI,UAAU,GAAuB,sBAAsB,CAAC;IAE5D,IAAI,KAAK,CAAC,YAAY,EAAE;QACtB,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAC3E,IAAI,sBAAsB,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAEhD,IAAI;YACF,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YAE3F,sBAAsB,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;SAClD;QAAC,MAAM;YACN,WAAW;SACZ;QAED,IAAI,MAAM,CAAC,gBAAgB,CAAC,EAAE;YAC5B,UAAU,GAAG,cAAc,CAAC;SAC7B;aAAM;YACL,8DAA8D;YAC9D,M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AAY,EAAE;QACtB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAE3E,IAAI;YACF,IAAI,GAAG,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5D;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,+BAA+B,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC;SAC/D;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import path from 'path';\nimport { pathToFileURL } from 'url';\nimport type { CreateHtmlOptions, CreateHtmlResult, CreateHtmlFunction, CreateHtmlScript } from '../../../types.js';\nimport { getDefaultHtmlResponse } from './getDefaultHtmlResponse.js';\nimport { JSDOM } from 'jsdom';\nimport fsPromises from 'fs/promises';\n\n/**\n * Get the HTML response for the given route. If the route has a custom render script, use that.\n */\nexport async function getHtmlResponse(options: CreateHtmlOptions): Promise<Exclude<CreateHtmlResult, string>> {\n const { route, session, overlayScript, entryScript, inlineScripts } = options;\n let createHtml: CreateHtmlFunction = getDefaultHtmlResponse;\n\n if (route.renderScript) {\n const renderScriptPath = path.resolve(session.appPath, route.renderScript);\n let cacheBreakerQueryParam = `?t=${Date.now()}`;\n\n try {\n const { mtime } = await fsPromises.stat(path.resolve(session.appPath, route.renderScript));\n\n cacheBreakerQueryParam = `?t=${mtime.getTime()}`;\n } catch {\n /* no-op */\n }\n\n if (isHtml(renderScriptPath)) {\n createHtml = readStaticHtml;\n } else {\n // Get the html factory function from a script default export.\n const renderScriptUrl = pathToFileURL(renderScriptPath).toString();\n\n // Note: because there isn't a way to purge the require cache, we need to add a cache breaker query param to the\n // script path to ensure we get the latest version of the script. This could be improved by using the git hash of\n // the file if it exists, or a hash of the content, or even the timestamp of the file.\n try {\n createHtml = ((await import(renderScriptUrl + cacheBreakerQueryParam)) as CreateHtmlScript).default;\n } catch (e) {\n console.error(`Error importing render script at \"${renderScriptUrl}\":`, e);\n }\n }\n\n if (!createHtml) {\n console.error(`The render script at \"${renderScriptPath}\" does not export a default function.`);\n }\n }\n\n const htmlResult = await createHtml(options);\n let html = typeof htmlResult === 'string' ? htmlResult : htmlResult.html;\n const statusCode = typeof htmlResult === 'string' ? 200 : htmlResult.statusCode || 200;\n\n try {\n const htmlDocument = new JSDOM(html);\n const { document } = htmlDocument.window;\n\n // inject the import map.\n if (entryScript || overlayScript) {\n const script = document.createElement('script');\n script.type = 'importmap';\n script.innerHTML = JSON.stringify(session.getImportMap(), null, 2);\n document.head.prepend(script);\n }\n\n for (const inlineScript of inlineScripts) {\n const script = document.createElement('script');\n script.type = 'module';\n script.innerHTML = inlineScript;\n document.head.appendChild(script);\n }\n\n // inject the overlay script.\n addScript(document.head, overlayScript);\n\n // inject the entry script.\n addScript(document.head, entryScript);\n\n html = htmlDocument.serialize();\n } catch (e) {\n console.error(`Error parsing html response for rendering route \"${route.match}\"`, e);\n }\n\n return {\n html,\n statusCode,\n };\n}\n\n/**\n * Helper function to add a script to the document.\n */\nfunction addScript(parentElement: HTMLElement, url: string | undefined) {\n if (url) {\n const script = parentElement.ownerDocument.createElement('script');\n\n script.type = 'module';\n script.src = url;\n parentElement.appendChild(script);\n }\n}\n\nfunction isHtml(path: string): boolean {\n // path has an .htm or .html extension; case insensitive.\n return path.toLowerCase().match(/\\.htm(l)?$/) !== null;\n}\n\nasync function readStaticHtml(options: CreateHtmlOptions): Promise<string> {\n const { route } = options;\n let html = '';\n\n if (route.renderScript) {\n const htmlPath = path.resolve(options.session.appPath, route.renderScript);\n\n try {\n html = (await fsPromises.readFile(htmlPath, 'utf8')) || '';\n } catch (e) {\n console.error(`Error reading HTML file at \"${htmlPath}\".`, e);\n }\n }\n\n return html;\n}\n"]}
@@ -3,6 +3,7 @@ export function init(command) {
3
3
  command
4
4
  .command('start')
5
5
  .description('Starts a web inner-loop from the current package folder.')
6
+ .option('--unstable-lage', 'Uses the unstable lage task scheduler.')
6
7
  .option('--log-resolve-map', 'Logs the resolve map to "resolve-map.json" for diagnostics.')
7
8
  .action(async (options) => (await import('./start.js')).start(options));
8
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAGA,+BAA+B;AAC/B,MAAM,UAAU,IAAI,CAAC,OAAgB;IACnC,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,mBAAmB,EAAE,6DAA6D,CAAC;SAC1F,MAAM,CAAC,KAAK,EAAE,OAAqB,EAAE,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["import type { Command } from 'commander';\nimport type { StartOptions } from './types.js';\n\n/* Defines the \"start\" verb. */\nexport function init(command: Command) {\n command\n .command('start')\n .description('Starts a web inner-loop from the current package folder.')\n .option('--log-resolve-map', 'Logs the resolve map to \"resolve-map.json\" for diagnostics.')\n .action(async (options: StartOptions) => (await import('./start.js')).start(options));\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAGA,+BAA+B;AAC/B,MAAM,UAAU,IAAI,CAAC,OAAgB;IACnC,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,iBAAiB,EAAE,wCAAwC,CAAC;SACnE,MAAM,CAAC,mBAAmB,EAAE,6DAA6D,CAAC;SAC1F,MAAM,CAAC,KAAK,EAAE,OAAqB,EAAE,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["import type { Command } from 'commander';\nimport type { StartOptions } from './types.js';\n\n/* Defines the \"start\" verb. */\nexport function init(command: Command) {\n command\n .command('start')\n .description('Starts a web inner-loop from the current package folder.')\n .option('--unstable-lage', 'Uses the unstable lage task scheduler.')\n .option('--log-resolve-map', 'Logs the resolve map to \"resolve-map.json\" for diagnostics.')\n .action(async (options: StartOptions) => (await import('./start.js')).start(options));\n}\n"]}
@@ -40,7 +40,7 @@ export async function start(options) {
40
40
  // Start api server for tracking status and handling remote requests.
41
41
  const apiServer = await startApiServer({ session, config, rootSpan });
42
42
  // Then start bundle and app servers for hosting the app.
43
- const bundleServer = await startBundleServer({ session, apiServer, config });
43
+ const bundleServer = await startBundleServer({ session, apiServer, config, useLage: options.unstableLage });
44
44
  const appServer = await startAppServer({
45
45
  session,
46
46
  definition,
@@ -1 +1 @@
1
- {"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/commands/start/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,8BAA8B,EAAE,MAAM,gDAAgD,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC9F,OAAO,EAAE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,GAAG,CAAC;QAE1B,WAAW,CAAC,OAAO,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;QACpE,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7B,sEAAsE;YACtE,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;YAC1D,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;KACJ;IAAC,OAAO,GAAG,EAAE;QACZ,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC","sourcesContent":["import { writeJson } from '@ms-cloudpack/json-utilities';\nimport { PackageDefinitions } from '@ms-cloudpack/package-utilities';\nimport path from 'path';\nimport { createPackageOverrideTransform } from '../../common/createPackageOverrideTransform.js';\nimport { startAppServer } from './appServer/startAppServer.js';\nimport { createSession } from './createSession.js';\nimport { openBrowser } from './openBrowser.js';\nimport { startApiServer } from '@ms-cloudpack/api-server';\nimport { startBundleServer } from './startBundleServer.js';\nimport type { StartOptions } from './types.js';\nimport { reporter } from '../../reporter.js';\nimport { readConfig } from '@ms-cloudpack/config';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport { setSharedTelemetryAttribute, stopTelemetry, rootSpan } from '../../initTelemetry.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport async function start(options: StartOptions) {\n const appPath = process.cwd();\n\n try {\n // Parse config if it exists.\n const config = await readConfig(appPath);\n\n // Initialize package overrides.\n PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(config));\n\n // Make sure the package has a valid definition.\n const definition = await PackageDefinitions.getInstance().get(appPath);\n\n if (!definition) {\n throw new Error(`There was no package.json located at \"${appPath}\".`);\n }\n\n if (!definition.name || !definition.version) {\n throw new Error(`The package.json at \"${appPath}\" did not have a name and/or version.`);\n }\n\n // Initialize session definition.\n const session = await createSession({ appPath, config });\n\n // Set shared telemetry attributes which will be sent with all telemetry events.\n setSharedTelemetryAttribute('sessionId', session.id);\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 apiServer = await startApiServer({ session, config, rootSpan });\n\n // Then start bundle and app servers for hosting the app.\n const bundleServer = await startBundleServer({ session, apiServer, config });\n\n const appServer = await startAppServer({\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n });\n\n const cleanup = async () => {\n for (const [name, server] of [\n ['appServer', appServer] as const,\n ['apiServer', apiServer] as const,\n ['bundleServer', bundleServer] as const,\n ]) {\n console.info(`Closing ${name}: ${server.url}`);\n try {\n await server.close();\n } catch (err) {\n console.warn('Error closing server:', err);\n }\n }\n\n // Complete the reporting and list pending tasks as aborted.\n reporter.complete();\n\n // Flush and close telemetry.\n await stopTelemetry();\n };\n\n // Setup cleanup and close things on completion.\n let sigintCount = 0;\n\n process.on('SIGINT', () => {\n sigintCount++;\n if (sigintCount > 1) {\n console.debug('Forcing exit');\n process.exit(1);\n }\n\n cleanup().finally(() => {\n process.exit(0);\n });\n });\n\n // Open the browser.\n const url = appServer.url;\n\n performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n openBrowser(url).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:', url);\n });\n } catch (err) {\n reporter.complete();\n process.exit(1);\n }\n}\n"]}
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/commands/start/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,IAAI,MAA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AC,QAAQ,EAAE,CAAC;YAEpB,6BAA6B;YAC7B,MAAM,aAAa,EAAE,CAAC;QACxB,CAAC,CAAC;QAEF,gDAAgD;QAChD,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACxB,WAAW,EAAE,CAAC;YACd,IAAI,WAAW,GAAG,CAAC,EAAE;gBACnB,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;gBAC9B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,OAAO,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;gBACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,oBAAoB;QACpB,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC;QAE1B,WAAW,CAAC,OAAO,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;QACpE,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7B,sEAAsE;YACtE,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;YAC1D,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;KACJ;IAAC,OAAO,GAAG,EAAE;QACZ,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC","sourcesContent":["import { writeJson } from '@ms-cloudpack/json-utilities';\nimport { PackageDefinitions } from '@ms-cloudpack/package-utilities';\nimport path from 'path';\nimport { createPackageOverrideTransform } from '../../common/createPackageOverrideTransform.js';\nimport { startAppServer } from './appServer/startAppServer.js';\nimport { createSession } from './createSession.js';\nimport { openBrowser } from './openBrowser.js';\nimport { startApiServer } from '@ms-cloudpack/api-server';\nimport { startBundleServer } from './startBundleServer.js';\nimport type { StartOptions } from './types.js';\nimport { reporter } from '../../reporter.js';\nimport { readConfig } from '@ms-cloudpack/config';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport { setSharedTelemetryAttribute, stopTelemetry, rootSpan } from '../../initTelemetry.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport async function start(options: StartOptions) {\n const appPath = process.cwd();\n\n try {\n // Parse config if it exists.\n const config = await readConfig(appPath);\n\n // Initialize package overrides.\n PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(config));\n\n // Make sure the package has a valid definition.\n const definition = await PackageDefinitions.getInstance().get(appPath);\n\n if (!definition) {\n throw new Error(`There was no package.json located at \"${appPath}\".`);\n }\n\n if (!definition.name || !definition.version) {\n throw new Error(`The package.json at \"${appPath}\" did not have a name and/or version.`);\n }\n\n // Initialize session definition.\n const session = await createSession({ appPath, config });\n\n // Set shared telemetry attributes which will be sent with all telemetry events.\n setSharedTelemetryAttribute('sessionId', session.id);\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 apiServer = await startApiServer({ session, config, rootSpan });\n\n // Then start bundle and app servers for hosting the app.\n const bundleServer = await startBundleServer({ session, apiServer, config, useLage: options.unstableLage });\n\n const appServer = await startAppServer({\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n });\n\n const cleanup = async () => {\n for (const [name, server] of [\n ['appServer', appServer] as const,\n ['apiServer', apiServer] as const,\n ['bundleServer', bundleServer] as const,\n ]) {\n console.info(`Closing ${name}: ${server.url}`);\n try {\n await server.close();\n } catch (err) {\n console.warn('Error closing server:', err);\n }\n }\n\n // Complete the reporting and list pending tasks as aborted.\n reporter.complete();\n\n // Flush and close telemetry.\n await stopTelemetry();\n };\n\n // Setup cleanup and close things on completion.\n let sigintCount = 0;\n\n process.on('SIGINT', () => {\n sigintCount++;\n if (sigintCount > 1) {\n console.debug('Forcing exit');\n process.exit(1);\n }\n\n cleanup().finally(() => {\n process.exit(0);\n });\n });\n\n // Open the browser.\n const url = appServer.url;\n\n performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n openBrowser(url).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:', url);\n });\n } catch (err) {\n reporter.complete();\n process.exit(1);\n }\n}\n"]}
@@ -6,8 +6,9 @@ import type { CloudpackConfig } from '@ms-cloudpack/config';
6
6
  * Resources are bundled on demand and cached locally to avoid re-bundling
7
7
  * on each request.
8
8
  */
9
- export declare function startBundleServer({ session, apiServer, config, }: {
9
+ export declare function startBundleServer({ session, apiServer, config, useLage, }: {
10
10
  session: Session;
11
11
  apiServer: ApiServer;
12
12
  config: CloudpackConfig;
13
+ useLage: boolean | undefined;
13
14
  }): Promise<BundleServer>;
@@ -6,12 +6,14 @@ import { parseRequestInfo } from './parseRequestInfo.js';
6
6
  import { createBundleTask } from './createBundleTask.js';
7
7
  import { getBundleDetails } from '../../common/getBundleDetails.js';
8
8
  import { isExternalPackage } from '@ms-cloudpack/package-utilities';
9
+ import { createRequire } from 'node:module';
10
+ const require = createRequire(import.meta.url);
9
11
  /**
10
12
  * The bundle server handles package requests and returns bundled resources.
11
13
  * Resources are bundled on demand and cached locally to avoid re-bundling
12
14
  * on each request.
13
15
  */
14
- export async function startBundleServer({ session, apiServer, config = {}, }) {
16
+ export async function startBundleServer({ session, apiServer, config = {}, useLage = false, }) {
15
17
  const { port, close, url } = await createExpressApp({
16
18
  portRange: [5500, 5501, 5502, 5503],
17
19
  hostname: config.devServer?.domain,
@@ -19,7 +21,7 @@ export async function startBundleServer({ session, apiServer, config = {}, }) {
19
21
  setupCallback: (app) => {
20
22
  // Set up the express app routes.
21
23
  app.get('*', (req, res) => {
22
- handleRequest(req, res, session, apiServer).catch((err) => {
24
+ handleRequest(req, res, session, apiServer, useLage).catch((err) => {
23
25
  console.error(err?.stack || err);
24
26
  res.status(500).send(`Error bundling: ${err}`);
25
27
  });
@@ -32,7 +34,7 @@ export async function startBundleServer({ session, apiServer, config = {}, }) {
32
34
  url,
33
35
  };
34
36
  }
35
- async function handleRequest(req, res, session, apiServer) {
37
+ async function handleRequest(req, res, session, apiServer, useLage) {
36
38
  const { resolveMap } = session;
37
39
  const requestPath = slash(req.path.substring(1));
38
40
  const { packageName, version, bundled, filePath } = parseRequestInfo(requestPath);
@@ -93,6 +95,24 @@ async function handleRequest(req, res, session, apiServer) {
93
95
  isExternal,
94
96
  disableSourceMaps: session.config.features?.disableSourceMaps,
95
97
  };
98
+ if (useLage) {
99
+ console.debug(`Trying to bundle "${packageName}@${version}" with lage task scheduler`);
100
+ try {
101
+ await apiServer.scheduleTask(taskResult, {
102
+ // TODO: we may want to have away to let users add more types of tasks here
103
+ bundle: require.resolve('../../tasks/bundleTaskWorker.js'),
104
+ }, { rerun });
105
+ console.debug(`Bundle returning: "${packageName}@${version}${filePath}"`);
106
+ // Try to return the result.
107
+ if (isExternal) {
108
+ res.setHeader('Cache-Control', 'public, max-age=31536000');
109
+ }
110
+ return res.sendFile(path.join(outputPath, filePath));
111
+ }
112
+ catch (err) {
113
+ return res.status(500).type('json').send(taskResult);
114
+ }
115
+ }
96
116
  console.debug(`Trying to bundle "${packageName}@${version}"`);
97
117
  const bundleTask = createBundleTask(taskResult, { force });
98
118
  await apiServer.addTask(bundleTask, { rerun });
@@ -1 +1 @@
1
- {"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,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AC,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC;IACrD,MAAM,UAAU,GAAkB;QAChC,EAAE,EAAE,QAAQ;QACZ,WAAW;QACX,OAAO;QACP,WAAW;QACX,UAAU;QACV,UAAU;QACV,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB;KAC9D,CAAC;IAEF,OAAO,CAAC,KAAK,CAAC,qBAAqB,WAAW,IAAI,OAAO,GAAG,CAAC,CAAC;IAE9D,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAE/C,iDAAiD;IACjD,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE;QAChD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KAC/C;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;QAC1E,4BAA4B;QAC5B,IAAI,UAAU,EAAE;YACd,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;SAC5D;QAED,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KAC/C;AACH,CAAC","sourcesContent":["import { createExpressApp, type Express, type Request, type Response } from '@ms-cloudpack/create-express-app';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport { parseRequestInfo } from './parseRequestInfo.js';\nimport { createBundleTask } from './createBundleTask.js';\nimport type { BundleRequest, BundleServer } from '../../types.js';\nimport { getBundleDetails } from '../../common/getBundleDetails.js';\nimport { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\n\n/**\n * The bundle server handles package requests and returns bundled resources.\n * Resources are bundled on demand and cached locally to avoid re-bundling\n * on each request.\n */\nexport async function startBundleServer({\n session,\n apiServer,\n config = {} as CloudpackConfig,\n}: {\n session: Session;\n apiServer: ApiServer;\n config: CloudpackConfig;\n}): Promise<BundleServer> {\n const { port, close, url } = await createExpressApp({\n portRange: [5500, 5501, 5502, 5503],\n hostname: config.devServer?.domain,\n sslOptions: config.devServer?.https,\n setupCallback: (app: Express) => {\n // Set up the express app routes.\n app.get('*', (req, res) => {\n handleRequest(req, res, session, apiServer).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error bundling: ${err}`);\n });\n });\n },\n });\n\n return {\n close,\n port,\n url,\n };\n}\n\nasync function handleRequest(req: Request, res: Response, session: Session, apiServer: ApiServer) {\n const { resolveMap } = session;\n const requestPath = slash(req.path.substring(1));\n const { packageName, version, bundled, filePath } = parseRequestInfo(requestPath);\n const packageEntry = resolveMap[packageName];\n const packagePath =\n version && packageEntry?.version === version ? packageEntry?.path : packageEntry?.scopedVersions?.[version]?.path;\n const force = req.query.force !== undefined;\n\n console.debug(`Request: \"${packageName}@${version}${filePath}\"`);\n\n // If the package is missing, invalid arguments.\n if (!requestPath || !packageName) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Requests must be in the format \"/{packageName}@{version}/{type}/path/file.ext\".`);\n return;\n }\n\n // If the version is missing, redirect to the primary version.\n if (!version) {\n const resolvedPackage = resolveMap[packageName];\n\n if (!resolvedPackage) {\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\n\n res.redirect(`/${packageName}@${resolvedPackage.version}${filePath}`);\n return;\n }\n\n // If it's an unrecognized package, 404.\n if (!packagePath) {\n console.debug(`Response (404): \"${packageName}@${version}${filePath}\"`);\n\n res\n .status(404)\n .send(`The requested package \"${packageName}@${version}${filePath}\" was not found in the resolve map.`);\n\n return;\n }\n\n // If we are accessing a non-bundled asset, return the file directly.\n if (!bundled) {\n const fullPath = path.join(packagePath, filePath);\n\n if (fullPath.length < packagePath.length) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Invalid file path.`);\n return;\n }\n\n console.debug(`Unbundled response returning: \"${packageName}@${version}${filePath}\"`);\n // If the package is external, set cache headers.\n if (isExternalPackage(packagePath)) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(packagePath, filePath));\n return;\n }\n\n const { isExternal, bundleId, outputPath } = await getBundleDetails(packagePath);\n\n // Set up for bundling.\n const rerun = !(await isFolder(outputPath)) || force;\n const taskResult: BundleRequest = {\n id: bundleId,\n packageName,\n version,\n packagePath,\n outputPath,\n isExternal,\n disableSourceMaps: session.config.features?.disableSourceMaps,\n };\n\n console.debug(`Trying to bundle \"${packageName}@${version}\"`);\n\n const bundleTask = createBundleTask(taskResult, { force });\n await apiServer.addTask(bundleTask, { rerun });\n\n // At this point we should have a Task completed.\n if ((taskResult.result?.errors?.length || 0) > 0) {\n res.status(500).type('json').send(taskResult);\n } else {\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(outputPath, filePath));\n }\n}\n"]}
1
+ {"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,C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,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAE/C,iDAAiD;IACjD,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE;QAChD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KAC/C;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;QAC1E,4BAA4B;QAC5B,IAAI,UAAU,EAAE;YACd,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;SAC5D;QAED,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KAC/C;AACH,CAAC","sourcesContent":["import { createExpressApp, type Express, type Request, type Response } from '@ms-cloudpack/create-express-app';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport { parseRequestInfo } from './parseRequestInfo.js';\nimport { createBundleTask } from './createBundleTask.js';\nimport type { BundleRequest, BundleServer } from '../../types.js';\nimport { getBundleDetails } from '../../common/getBundleDetails.js';\nimport { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\n\nimport { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\n\n/**\n * The bundle server handles package requests and returns bundled resources.\n * Resources are bundled on demand and cached locally to avoid re-bundling\n * on each request.\n */\nexport async function startBundleServer({\n session,\n apiServer,\n config = {} as CloudpackConfig,\n useLage = false,\n}: {\n session: Session;\n apiServer: ApiServer;\n config: CloudpackConfig;\n useLage: boolean | undefined;\n}): Promise<BundleServer> {\n const { port, close, url } = await createExpressApp({\n portRange: [5500, 5501, 5502, 5503],\n hostname: config.devServer?.domain,\n sslOptions: config.devServer?.https,\n setupCallback: (app: Express) => {\n // Set up the express app routes.\n app.get('*', (req, res) => {\n handleRequest(req, res, session, apiServer, useLage).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error bundling: ${err}`);\n });\n });\n },\n });\n\n return {\n close,\n port,\n url,\n };\n}\n\nasync function handleRequest(req: Request, res: Response, session: Session, apiServer: ApiServer, useLage: boolean) {\n const { resolveMap } = session;\n const requestPath = slash(req.path.substring(1));\n const { packageName, version, bundled, filePath } = parseRequestInfo(requestPath);\n const packageEntry = resolveMap[packageName];\n const packagePath =\n version && packageEntry?.version === version ? packageEntry?.path : packageEntry?.scopedVersions?.[version]?.path;\n const force = req.query.force !== undefined;\n\n console.debug(`Request: \"${packageName}@${version}${filePath}\"`);\n\n // If the package is missing, invalid arguments.\n if (!requestPath || !packageName) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Requests must be in the format \"/{packageName}@{version}/{type}/path/file.ext\".`);\n return;\n }\n\n // If the version is missing, redirect to the primary version.\n if (!version) {\n const resolvedPackage = resolveMap[packageName];\n\n if (!resolvedPackage) {\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\n\n res.redirect(`/${packageName}@${resolvedPackage.version}${filePath}`);\n return;\n }\n\n // If it's an unrecognized package, 404.\n if (!packagePath) {\n console.debug(`Response (404): \"${packageName}@${version}${filePath}\"`);\n\n res\n .status(404)\n .send(`The requested package \"${packageName}@${version}${filePath}\" was not found in the resolve map.`);\n\n return;\n }\n\n // If we are accessing a non-bundled asset, return the file directly.\n if (!bundled) {\n const fullPath = path.join(packagePath, filePath);\n\n if (fullPath.length < packagePath.length) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Invalid file path.`);\n return;\n }\n\n console.debug(`Unbundled response returning: \"${packageName}@${version}${filePath}\"`);\n // If the package is external, set cache headers.\n if (isExternalPackage(packagePath)) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(packagePath, filePath));\n return;\n }\n\n const { isExternal, bundleId, outputPath } = await getBundleDetails(packagePath);\n\n // Set up for bundling.\n const rerun = !(await isFolder(outputPath)) || force;\n const taskResult: BundleRequest = {\n id: bundleId,\n packageName,\n version,\n packagePath,\n outputPath,\n isExternal,\n disableSourceMaps: session.config.features?.disableSourceMaps,\n };\n\n if (useLage) {\n console.debug(`Trying to bundle \"${packageName}@${version}\" with lage task scheduler`);\n\n try {\n await apiServer.scheduleTask(\n taskResult,\n {\n // TODO: we may want to have away to let users add more types of tasks here\n bundle: require.resolve('../../tasks/bundleTaskWorker.js'),\n },\n { rerun },\n );\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n return res.sendFile(path.join(outputPath, filePath));\n } catch (err) {\n return res.status(500).type('json').send(taskResult);\n }\n }\n\n console.debug(`Trying to bundle \"${packageName}@${version}\"`);\n\n const bundleTask = createBundleTask(taskResult, { force });\n await apiServer.addTask(bundleTask, { rerun });\n\n // At this point we should have a Task completed.\n if ((taskResult.result?.errors?.length || 0) > 0) {\n res.status(500).type('json').send(taskResult);\n } else {\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(outputPath, filePath));\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export interface StartOptions {
2
2
  logResolveMap?: boolean;
3
+ unstableLage?: boolean;
3
4
  sourcemap?: boolean;
4
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/commands/start/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface StartOptions {\n logResolveMap?: boolean;\n sourcemap?: boolean;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/commands/start/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface StartOptions {\n logResolveMap?: boolean;\n unstableLage?: boolean;\n sourcemap?: boolean;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { Target } from '@lage-run/target-graph';
2
+ export default function run(data: {
3
+ target: Target;
4
+ }): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { bundleTask } from './bundleTask.js';
2
+ export default async function run(data) {
3
+ const { target } = data;
4
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
5
+ await bundleTask({ bundleRequest: target.options?.bundleRequest });
6
+ }
7
+ //# sourceMappingURL=bundleTaskWorker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundleTaskWorker.js","sourceRoot":"","sources":["../../src/tasks/bundleTaskWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,GAAG,CAAC,IAAwB;IACxD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAExB,mEAAmE;IACnE,MAAM,UAAU,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { bundleTask } from './bundleTask.js';\nimport type { Target } from '@lage-run/target-graph';\n\nexport default async function run(data: { target: Target }) {\n const { target } = data;\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n await bundleTask({ bundleRequest: target.options?.bundleRequest });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/cli",
3
- "version": "0.34.0",
3
+ "version": "0.35.1",
4
4
  "description": "The Cloudpack command line interface - a tool for managing fast inner and outer looping in web apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,9 +16,9 @@
16
16
  "cloudpack": "./bin/cloudpack.js"
17
17
  },
18
18
  "dependencies": {
19
- "@ms-cloudpack/api-server": "^0.4.0",
20
- "@ms-cloudpack/bundler": "^0.11.24",
21
- "@ms-cloudpack/config": "^0.4.0",
19
+ "@ms-cloudpack/api-server": "^0.5.0",
20
+ "@ms-cloudpack/bundler": "^0.11.26",
21
+ "@ms-cloudpack/config": "^0.5.0",
22
22
  "@ms-cloudpack/create-express-app": "^1.3.3",
23
23
  "@ms-cloudpack/data-bus": "^0.1.1",
24
24
  "@ms-cloudpack/json-utilities": "^0.0.6",
@@ -1 +0,0 @@
1
- export declare function error(...messages: unknown[]): void;
@@ -1,4 +0,0 @@
1
- export function error(...messages) {
2
- console.error(`AppServer:`, ...messages);
3
- }
4
- //# sourceMappingURL=error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/error.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,GAAG,QAAmB;IAC1C,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["export function error(...messages: unknown[]) {\n console.error(`AppServer:`, ...messages);\n}\n"]}