@ms-cloudpack/cli 0.47.10 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACxF,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,kCAAkC,CAAC;AAKnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAMnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,MAAM,EACN,QAAQ,GACT,EAAE;IACD,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,WAAW,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;CACnC,QAwEA"}
1
+ {"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AACxF,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,kCAAkC,CAAC;AAKnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAMnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAC3B,GAAG,EACH,GAAG,EACH,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,MAAM,EACN,QAAQ,GACT,EAAE;IACD,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,WAAW,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;CACnC,QAqEA"}
@@ -42,13 +42,13 @@ export function createRoutes({ app, url, session, definition, bundleServer, apiS
42
42
  const entryScript =
43
43
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44
44
  route.exportEntry && importMap.imports[slash(path.join(definition.name, route.exportEntry))];
45
- // Set the apppropriate Cloudpack headers/cookies in the response.
45
+ // Set the appropriate Cloudpack headers/cookies in the response.
46
46
  // TODO: setting the headers here prohibits cases where the page rendering is owned by existing server code
47
47
  // that can only accept changing the scripts. We should consider moving to a model where an initial script
48
48
  // fetch loads the import map and sets Cloudpack settings in local storage rather than headers/cookies.
49
49
  setHeaders({ res, session, apiServer, bundleServer });
50
50
  const inlineScripts = await getInlineScripts();
51
- const { html, statusCode } = await getHtmlResponse({
51
+ const { content, statusCode, contentType } = await getHtmlResponse({
52
52
  route,
53
53
  baseUrl: url,
54
54
  importMap,
@@ -60,8 +60,7 @@ export function createRoutes({ app, url, session, definition, bundleServer, apiS
60
60
  req,
61
61
  res,
62
62
  });
63
- // Send the result.
64
- res.status(statusCode).send(html).end();
63
+ res.type(contentType).status(statusCode).send(content).end();
65
64
  log(`App server: Request: ${requestPath}, ext: ${requestExt}`);
66
65
  })().catch((err) => {
67
66
  console.error(err?.stack || err);
@@ -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,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,EACN,QAAQ,GAUT;IACC,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;IACrD,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC;IAE3F,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,CAAC,IAAI,CAAC;YACV,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,GAAG;SACjB,CAAC,CAAC;KACJ;IAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,IAAI,KAAK,CAAC,UAAU,EAAE;YACpB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,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AAgB,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;wBACb,GAAG;wBACH,GAAG;qBACJ,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 { PackageDefinitionsCache, 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/BundleServer.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 packages,\n}: {\n app: Express;\n url: string;\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\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(\n {\n resolveMap: session.resolveMap,\n bundleServerUrl: bundleServer.url,\n sessionVersion,\n targetVersions: session.targetVersions,\n },\n { packages },\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, bundleServer });\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 req,\n res,\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
+ {"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,EACN,QAAQ,GAUT;IACC,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;IACrD,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC;IAE3F,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,CAAC,IAAI,CAAC;YACV,KAAK,EAAE,GAAG;YACV,WAAW,EAAE,GAAG;SACjB,CAAC,CAAC;KACJ;IAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,IAAI,KAAK,CAAC,UAAU,EAAE;YACpB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,K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MAAM,gBAAgB,EAAE,CAAC;oBAC/C,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,eAAe,CAAC;wBACjE,KAAK;wBACL,OAAO,EAAE,GAAG;wBACZ,SAAS;wBACT,aAAa;wBACb,WAAW;wBACX,OAAO;wBACP,UAAU;wBACV,aAAa;wBACb,GAAG;wBACH,GAAG;qBACJ,CAAC,CAAC;oBAEH,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;oBAE7D,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 { PackageDefinitionsCache, 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/BundleServer.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 packages,\n}: {\n app: Express;\n url: string;\n session: Session;\n definition: PackageJson;\n bundleServer: BundleServer;\n apiServer: ApiServer;\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\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(\n {\n resolveMap: session.resolveMap,\n bundleServerUrl: bundleServer.url,\n sessionVersion,\n targetVersions: session.targetVersions,\n },\n { packages },\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 // Set the appropriate 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, bundleServer });\n const inlineScripts = await getInlineScripts();\n const { content, statusCode, contentType } = await getHtmlResponse({\n route,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n session,\n definition,\n inlineScripts,\n req,\n res,\n });\n\n res.type(contentType).status(statusCode).send(content).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,6 +1,6 @@
1
- import type { CreateHtmlResult, CustomHtmlResult, CreateHtmlOptions } from '@ms-cloudpack/api-server';
1
+ import type { CreateHtmlResult, CreateHtmlOptions } from '@ms-cloudpack/api-server';
2
2
  /**
3
3
  * Get the HTML response for the given route. If the route has a custom render script, use that.
4
4
  */
5
- export declare function getHtmlResponse(options: CreateHtmlOptions): Promise<Exclude<CreateHtmlResult, string | CustomHtmlResult>>;
5
+ export declare function getHtmlResponse(options: CreateHtmlOptions): Promise<Required<Exclude<CreateHtmlResult, string>>>;
6
6
  //# sourceMappingURL=getHtmlResponse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getHtmlResponse.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/getHtmlResponse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAUlC;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAyF/D"}
1
+ {"version":3,"file":"getHtmlResponse.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/getHtmlResponse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAKlC;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC,CAwFtD"}
@@ -3,10 +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
- function isCustomHtmlResult(result) {
7
- const customResult = result;
8
- return (customResult.type === 'static-html' || customResult.type === 'js') && !!customResult.content;
9
- }
10
6
  /**
11
7
  * Get the HTML response for the given route. If the route has a custom render script, use that.
12
8
  */
@@ -43,24 +39,22 @@ export async function getHtmlResponse(options) {
43
39
  console.error(`The render script at "${renderScriptPath}" does not export a default function.`);
44
40
  }
45
41
  }
46
- let html = '';
47
- let resultType = 'html';
42
+ let content;
43
+ let contentType = 'html';
48
44
  let statusCode = 200;
49
- const htmlResult = await createHtml(options);
50
- if (typeof htmlResult === 'string') {
51
- html = htmlResult;
52
- }
53
- else if (isCustomHtmlResult(htmlResult)) {
54
- html = htmlResult.content;
55
- resultType = htmlResult.type;
45
+ const result = await createHtml(options);
46
+ if (typeof result === 'string') {
47
+ content = result;
56
48
  }
57
49
  else {
58
- html = htmlResult.html;
59
- statusCode = htmlResult.statusCode;
50
+ content = result.content;
51
+ contentType = result.contentType ?? contentType;
52
+ statusCode = result.statusCode ?? statusCode;
60
53
  }
61
- if (resultType === 'html') {
54
+ // endsWith('html') covers: 'html', '.html', and 'text/html'
55
+ if (contentType.endsWith('html')) {
62
56
  try {
63
- const htmlDocument = new JSDOM(html);
57
+ const htmlDocument = new JSDOM(content);
64
58
  const { document } = htmlDocument.window;
65
59
  // inject the import map.
66
60
  if (entryScript || overlayScript) {
@@ -79,15 +73,16 @@ export async function getHtmlResponse(options) {
79
73
  addScript(document.head, overlayScript);
80
74
  // inject the entry script.
81
75
  addScript(document.head, entryScript);
82
- html = htmlDocument.serialize();
76
+ content = htmlDocument.serialize();
83
77
  }
84
78
  catch (e) {
85
79
  console.error(`Error parsing html response for rendering route "${route.match}"`, e);
86
80
  }
87
81
  }
88
82
  return {
89
- html,
83
+ content,
90
84
  statusCode,
85
+ contentType,
91
86
  };
92
87
  }
93
88
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"getHtmlResponse.js","sourceRoot":"","sources":["../../../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ChC,yDAAyD;IACzD,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AAC/D,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,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 {\n CreateHtmlScript,\n CreateHtmlFunction,\n CreateHtmlResult,\n CustomHtmlResult,\n CreateHtmlOptions,\n} from '@ms-cloudpack/api-server';\nimport { getDefaultHtmlResponse } from './getDefaultHtmlResponse.js';\nimport { JSDOM } from 'jsdom';\nimport fsPromises from 'fs/promises';\n\nfunction isCustomHtmlResult(result: CreateHtmlResult): result is CustomHtmlResult {\n const customResult = result as CustomHtmlResult;\n return (customResult.type === 'static-html' || customResult.type === 'js') && !!customResult.content;\n}\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(\n options: CreateHtmlOptions,\n): Promise<Exclude<CreateHtmlResult, string | CustomHtmlResult>> {\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 let html = '';\n let resultType = 'html';\n let statusCode = 200;\n\n const htmlResult = await createHtml(options);\n\n if (typeof htmlResult === 'string') {\n html = htmlResult;\n } else if (isCustomHtmlResult(htmlResult)) {\n html = htmlResult.content;\n resultType = htmlResult.type;\n } else {\n html = htmlResult.html;\n statusCode = htmlResult.statusCode;\n }\n\n if (resultType === 'html') {\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\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(scriptPath: string): boolean {\n // path has an .htm or .html extension; case insensitive.\n return scriptPath.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"]}
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;AAOpC,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,CACnC,OAA0B;IAE1B,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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,GAAG,EAAE;QACP,MAAM,MAAM,GAAG,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAEnE,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;QACvB,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;QACjB,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;KACnC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,UAAkB;IAChC,yDAAyD;IACzD,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AAC/D,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,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 {\n CreateHtmlScript,\n CreateHtmlFunction,\n CreateHtmlResult,\n CreateHtmlOptions,\n} from '@ms-cloudpack/api-server';\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(\n options: CreateHtmlOptions,\n): Promise<Required<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 let content;\n let contentType = 'html';\n let statusCode = 200;\n\n const result = await createHtml(options);\n if (typeof result === 'string') {\n content = result;\n } else {\n content = result.content;\n contentType = result.contentType ?? contentType;\n statusCode = result.statusCode ?? statusCode;\n }\n\n // endsWith('html') covers: 'html', '.html', and 'text/html'\n if (contentType.endsWith('html')) {\n try {\n const htmlDocument = new JSDOM(content);\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 content = htmlDocument.serialize();\n } catch (e) {\n console.error(`Error parsing html response for rendering route \"${route.match}\"`, e);\n }\n }\n\n return {\n content,\n statusCode,\n contentType,\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(scriptPath: string): boolean {\n // path has an .htm or .html extension; case insensitive.\n return scriptPath.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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"setHeaders.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/setHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,GAAG,EAAE,QAAQ,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;CAC5B,QAYA"}
1
+ {"version":3,"file":"setHeaders.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/setHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,GAAG,EAAE,QAAQ,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;CAC5B,QAWA"}
@@ -4,7 +4,6 @@ import { cookieNames, getCloudpackSessionVersionCookie } from './cookieNames.js'
4
4
  */
5
5
  export function setHeaders(params) {
6
6
  const { res, session, apiServer, bundleServer } = params;
7
- res.header('Content-Type', 'text/html');
8
7
  res.header('Cache-Control', 'no-cache');
9
8
  res.header('Access-Control-Allow-Origin', '*');
10
9
  res.cookie(cookieNames.sessionId, session.id);
@@ -1 +1 @@
1
- {"version":3,"file":"setHeaders.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/setHeaders.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEjF;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAK1B;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEzD,GAAG,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAE/C,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC9C,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1D,GAAG,CAAC,MAAM,CAAC,gCAAgC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC/F,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9C,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type { Response } from '@ms-cloudpack/create-express-app';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport type { BundleServer } from '../../../types/BundleServer.js';\nimport { cookieNames, getCloudpackSessionVersionCookie } from './cookieNames.js';\n\n/**\n * Set the Cloudpack headers and cookies in the response.\n */\nexport function setHeaders(params: {\n res: Response;\n session: Session;\n apiServer: ApiServer;\n bundleServer: BundleServer;\n}) {\n const { res, session, apiServer, bundleServer } = params;\n\n res.header('Content-Type', 'text/html');\n res.header('Cache-Control', 'no-cache');\n res.header('Access-Control-Allow-Origin', '*');\n\n res.cookie(cookieNames.sessionId, session.id);\n res.cookie(cookieNames.sessionSequence, session.sequence);\n res.cookie(getCloudpackSessionVersionCookie(session.projectName), session.getSessionVersion());\n res.cookie(cookieNames.apiUrl, apiServer.url);\n res.cookie(cookieNames.bundleServerUrl, bundleServer.url);\n}\n"]}
1
+ {"version":3,"file":"setHeaders.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/setHeaders.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEjF;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAK1B;IACC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAEzD,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAE/C,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC9C,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1D,GAAG,CAAC,MAAM,CAAC,gCAAgC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC/F,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9C,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type { Response } from '@ms-cloudpack/create-express-app';\nimport type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport type { BundleServer } from '../../../types/BundleServer.js';\nimport { cookieNames, getCloudpackSessionVersionCookie } from './cookieNames.js';\n\n/**\n * Set the Cloudpack headers and cookies in the response.\n */\nexport function setHeaders(params: {\n res: Response;\n session: Session;\n apiServer: ApiServer;\n bundleServer: BundleServer;\n}) {\n const { res, session, apiServer, bundleServer } = params;\n\n res.header('Cache-Control', 'no-cache');\n res.header('Access-Control-Allow-Origin', '*');\n\n res.cookie(cookieNames.sessionId, session.id);\n res.cookie(cookieNames.sessionSequence, session.sequence);\n res.cookie(getCloudpackSessionVersionCookie(session.projectName), session.getSessionVersion());\n res.cookie(cookieNames.apiUrl, apiServer.url);\n res.cookie(cookieNames.bundleServerUrl, bundleServer.url);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/cli",
3
- "version": "0.47.10",
3
+ "version": "0.48.0",
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",
@@ -11,11 +11,11 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@lage-run/target-graph": "^0.8.7",
14
- "@ms-cloudpack/api-server": "^0.20.3",
15
- "@ms-cloudpack/config": "^0.12.7",
14
+ "@ms-cloudpack/api-server": "^0.21.0",
15
+ "@ms-cloudpack/config": "^0.13.0",
16
16
  "@ms-cloudpack/create-express-app": "^1.3.11",
17
17
  "@ms-cloudpack/json-utilities": "^0.0.7",
18
- "@ms-cloudpack/overlay": "^0.16.1",
18
+ "@ms-cloudpack/overlay": "^0.16.2",
19
19
  "@ms-cloudpack/package-utilities": "^5.1.9",
20
20
  "@ms-cloudpack/path-string-parsing": "^1.1.0",
21
21
  "@ms-cloudpack/path-utilities": "^2.3.4",