@ms-cloudpack/cli 0.47.5 → 0.47.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/lib/commands/init/init.d.ts.map +1 -1
  2. package/lib/commands/init/init.js +46 -46
  3. package/lib/commands/init/init.js.map +1 -1
  4. package/lib/commands/start/appServer/cookieNames.d.ts +8 -0
  5. package/lib/commands/start/appServer/cookieNames.d.ts.map +1 -0
  6. package/lib/commands/start/appServer/cookieNames.js +9 -0
  7. package/lib/commands/start/appServer/cookieNames.js.map +1 -0
  8. package/lib/commands/start/appServer/handleSessionVersion.d.ts.map +1 -1
  9. package/lib/commands/start/appServer/handleSessionVersion.js +2 -1
  10. package/lib/commands/start/appServer/handleSessionVersion.js.map +1 -1
  11. package/lib/commands/start/appServer/inlineScripts/errorHandler.inline.js +1 -0
  12. package/lib/commands/start/appServer/inlineScripts/errorHandler.inline.js.map +1 -1
  13. package/lib/commands/start/appServer/inlineScripts/getBrowserCacheRatio.inline.d.ts +2 -0
  14. package/lib/commands/start/appServer/inlineScripts/getBrowserCacheRatio.inline.d.ts.map +1 -0
  15. package/lib/commands/start/appServer/inlineScripts/{getBrowserCacheRatio.js → getBrowserCacheRatio.inline.js} +11 -6
  16. package/lib/commands/start/appServer/inlineScripts/getBrowserCacheRatio.inline.js.map +1 -0
  17. package/lib/commands/start/appServer/inlineScripts/getInlineScripts.d.ts.map +1 -1
  18. package/lib/commands/start/appServer/inlineScripts/getInlineScripts.js +2 -1
  19. package/lib/commands/start/appServer/inlineScripts/getInlineScripts.js.map +1 -1
  20. package/lib/commands/start/appServer/inlineScripts/getPageLoadTime.inline.d.ts +2 -0
  21. package/lib/commands/start/appServer/inlineScripts/getPageLoadTime.inline.d.ts.map +1 -0
  22. package/lib/commands/start/appServer/inlineScripts/{getPageLoadTime.js → getPageLoadTime.inline.js} +7 -5
  23. package/lib/commands/start/appServer/inlineScripts/getPageLoadTime.inline.js.map +1 -0
  24. package/lib/commands/start/appServer/setHeaders.d.ts +1 -1
  25. package/lib/commands/start/appServer/setHeaders.d.ts.map +1 -1
  26. package/lib/commands/start/appServer/setHeaders.js +8 -6
  27. package/lib/commands/start/appServer/setHeaders.js.map +1 -1
  28. package/lib/commands/start/execute.d.ts.map +1 -1
  29. package/lib/commands/start/execute.js +11 -6
  30. package/lib/commands/start/execute.js.map +1 -1
  31. package/lib/commands/start/index.d.ts.map +1 -1
  32. package/lib/commands/start/index.js +1 -0
  33. package/lib/commands/start/index.js.map +1 -1
  34. package/lib/commands/start/startBundleServer.js +27 -25
  35. package/lib/commands/start/startBundleServer.js.map +1 -1
  36. package/lib/commands/start/types/StartOptions.d.ts +2 -0
  37. package/lib/commands/start/types/StartOptions.d.ts.map +1 -1
  38. package/lib/commands/start/types/StartOptions.js.map +1 -1
  39. package/lib/index.d.ts.map +1 -1
  40. package/lib/index.js +2 -1
  41. package/lib/index.js.map +1 -1
  42. package/lib/utilities/dynamicImportExtension.d.ts +6 -0
  43. package/lib/utilities/dynamicImportExtension.d.ts.map +1 -0
  44. package/lib/utilities/dynamicImportExtension.js +8 -0
  45. package/lib/utilities/dynamicImportExtension.js.map +1 -0
  46. package/package.json +8 -8
  47. package/lib/commands/start/appServer/inlineScripts/cloudpackWindowVariable.inline.d.ts +0 -2
  48. package/lib/commands/start/appServer/inlineScripts/cloudpackWindowVariable.inline.d.ts.map +0 -1
  49. package/lib/commands/start/appServer/inlineScripts/cloudpackWindowVariable.inline.js +0 -7
  50. package/lib/commands/start/appServer/inlineScripts/cloudpackWindowVariable.inline.js.map +0 -1
  51. package/lib/commands/start/appServer/inlineScripts/getBrowserCacheRatio.d.ts +0 -2
  52. package/lib/commands/start/appServer/inlineScripts/getBrowserCacheRatio.d.ts.map +0 -1
  53. package/lib/commands/start/appServer/inlineScripts/getBrowserCacheRatio.js.map +0 -1
  54. package/lib/commands/start/appServer/inlineScripts/getPageLoadTime.d.ts +0 -2
  55. package/lib/commands/start/appServer/inlineScripts/getPageLoadTime.d.ts.map +0 -1
  56. package/lib/commands/start/appServer/inlineScripts/getPageLoadTime.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAO1D;;GAEG;AACH,wBAAsB,IAAI,CAAC,UAAU,EAAE;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;IACxB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,EAAE,eAAe,CAAC;CAClC,GAAG,OAAO,CAAC,WAAW,CAAC,CAyGvB"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAO1D;;GAEG;AACH,wBAAsB,IAAI,CAAC,UAAU,EAAE;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;IACxB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,EAAE,eAAe,CAAC;CAClC,GAAG,OAAO,CAAC,WAAW,CAAC,CA2GvB"}
@@ -30,7 +30,7 @@ export async function init(parameters) {
30
30
  const generatedConfig = config.generated;
31
31
  // Ensure generatedConfig.packageSettings is initialized.
32
32
  generatedConfig.packageSettings ??= [];
33
- return new Promise((resolve, reject) => {
33
+ const summary = await new Promise((resolve, reject) => {
34
34
  let pending = 0;
35
35
  const visitedSet = new Set();
36
36
  // Create a function to enqueue more paths.
@@ -40,57 +40,57 @@ export async function init(parameters) {
40
40
  }
41
41
  // Iterate through the given paths.
42
42
  for (const path of newPaths) {
43
- if (!visitedSet.has(path)) {
44
- const shouldForce = refreshPaths.delete(path);
45
- visitedSet.add(path);
46
- pending++;
47
- // Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.
48
- evaluatePath({
49
- packagePath: path,
50
- generatedConfig,
51
- telemetryClient,
52
- resolveMap,
53
- shouldForce,
54
- initOptions: options,
55
- summaryData,
56
- ctx,
57
- })
58
- .then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {
59
- pending--;
60
- if (shouldExit) {
61
- isExitingPrematurely = true;
62
- }
63
- if (!isExitingPrematurely && pathsToEvaluate?.size) {
64
- // If there are paths that need to be rebuilt, add them to the refresh set so that on re-enqueuing
65
- // we pass the `shouldRerun` flag through
66
- pathsToRefresh?.forEach((refreshPath) => {
67
- refreshPaths.add(refreshPath);
68
- visitedSet.delete(refreshPath);
69
- });
70
- // Try to enqueue the new paths.
71
- enqueuePaths(Array.from(pathsToEvaluate));
72
- }
73
- // If nothing is pending after this call, we're complete.
74
- if (!pending) {
75
- resolve(summaryData.summarize());
76
- }
77
- })
78
- .catch((error) => {
79
- reject(error);
80
- });
43
+ if (visitedSet.has(path)) {
44
+ continue;
81
45
  }
46
+ const shouldForce = refreshPaths.delete(path);
47
+ visitedSet.add(path);
48
+ pending++;
49
+ // Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.
50
+ evaluatePath({
51
+ packagePath: path,
52
+ generatedConfig,
53
+ telemetryClient,
54
+ resolveMap,
55
+ shouldForce,
56
+ initOptions: options,
57
+ summaryData,
58
+ ctx,
59
+ })
60
+ .then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {
61
+ pending--;
62
+ if (shouldExit) {
63
+ isExitingPrematurely = true;
64
+ }
65
+ if (!isExitingPrematurely && pathsToEvaluate?.size) {
66
+ // If there are paths that need to be rebuilt, add them to the refresh set so that on re-enqueuing
67
+ // we pass the `shouldRerun` flag through
68
+ pathsToRefresh?.forEach((refreshPath) => {
69
+ refreshPaths.add(refreshPath);
70
+ visitedSet.delete(refreshPath);
71
+ });
72
+ // Try to enqueue the new paths.
73
+ enqueuePaths(Array.from(pathsToEvaluate));
74
+ }
75
+ // If nothing is pending after this call, we're complete.
76
+ if (!pending) {
77
+ resolve(summaryData.summarize());
78
+ }
79
+ })
80
+ .catch((error) => {
81
+ reject(error);
82
+ });
82
83
  }
83
84
  }
84
85
  // Start with the app path.
85
86
  enqueuePaths([appPath]);
86
- }).then(async (summary) => {
87
- const { totalChanges } = summary;
88
- if (!options.check && totalChanges && generatedConfig.packageSettings?.length) {
89
- sortExportKeys(generatedConfig);
90
- await writeGeneratedConfig(generatedConfig, appPath);
91
- }
92
- return summary;
93
87
  });
88
+ const { totalChanges } = summary;
89
+ if (!options.check && totalChanges && generatedConfig.packageSettings?.length) {
90
+ sortExportKeys(generatedConfig);
91
+ await writeGeneratedConfig(generatedConfig, appPath);
92
+ }
93
+ return summary;
94
94
  }
95
95
  function sortExportKeys({ packageSettings = [] }) {
96
96
  for (const settings of packageSettings) {
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","source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udpackConfig, GeneratedConfig } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { AutoDispose } from '../../types/AutoDispose.js';\nimport type { InitOptions } from './types/InitOptions.js';\nimport type { InitSummary } from './types/InitSummary.js';\n\nimport { createPartialApiContext } from '@ms-cloudpack/api-server/apis';\nimport { writeGeneratedConfig } from '@ms-cloudpack/config';\nimport { InitSummaryData } from './InitSummaryData.js';\nimport { evaluatePath } from './evaluatePath.js';\n\n/**\n * Init execution function.\n */\nexport async function init(parameters: {\n options: InitOptions;\n appPath: string;\n config: CloudpackConfig;\n autoDispose: AutoDispose;\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n}): Promise<InitSummary> {\n const { options, appPath, config, reporter, autoDispose, telemetryClient } = parameters;\n let isExitingPrematurely = false;\n\n // Don't allow --check and --reset together.\n if (options.check && options.reset) {\n throw Error('Cannot use --check and --reset together.');\n }\n\n // If --reset is specified, reset the generated config.\n if (options.reset) {\n config.generated = {};\n }\n\n const summaryData = new InitSummaryData();\n const [ctx] = autoDispose(\n await createPartialApiContext({\n appPath,\n config,\n reporter,\n telemetryClient,\n items: ['bus', 'taskRunner', 'watcher', 'packages', 'session'],\n }),\n );\n const { session } = ctx;\n const { resolveMap } = session;\n const refreshPaths = new Set<string>();\n const generatedConfig = config.generated;\n\n // Ensure generatedConfig.packageSettings is initialized.\n generatedConfig.packageSettings ??= [];\n\n return new Promise<InitSummary>((resolve, reject) => {\n let pending = 0;\n const visitedSet = new Set<string>();\n\n // Create a function to enqueue more paths.\n function enqueuePaths(newPaths: string[]) {\n if (isExitingPrematurely) {\n return;\n }\n\n // Iterate through the given paths.\n for (const path of newPaths) {\n if (!visitedSet.has(path)) {\n const shouldForce = refreshPaths.delete(path);\n\n visitedSet.add(path);\n pending++;\n\n // Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.\n evaluatePath({\n packagePath: path,\n generatedConfig,\n telemetryClient,\n resolveMap,\n shouldForce,\n initOptions: options,\n summaryData,\n ctx,\n })\n .then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {\n pending--;\n\n if (shouldExit) {\n isExitingPrematurely = true;\n }\n\n if (!isExitingPrematurely && pathsToEvaluate?.size) {\n // If there are paths that need to be rebuilt, add them to the refresh set so that on re-enqueuing\n // we pass the `shouldRerun` flag through\n pathsToRefresh?.forEach((refreshPath) => {\n refreshPaths.add(refreshPath);\n visitedSet.delete(refreshPath);\n });\n\n // Try to enqueue the new paths.\n enqueuePaths(Array.from(pathsToEvaluate));\n }\n\n // If nothing is pending after this call, we're complete.\n if (!pending) {\n resolve(summaryData.summarize());\n }\n })\n .catch((error) => {\n reject(error);\n });\n }\n }\n }\n\n // Start with the app path.\n enqueuePaths([appPath]);\n }).then(async (summary: InitSummary) => {\n const { totalChanges } = summary;\n\n if (!options.check && totalChanges && generatedConfig.packageSettings?.length) {\n sortExportKeys(generatedConfig);\n\n await writeGeneratedConfig(generatedConfig, appPath);\n }\n\n return summary;\n });\n}\n\nfunction sortExportKeys({ packageSettings = [] }: GeneratedConfig) {\n for (const settings of packageSettings) {\n if (settings.exports) {\n const unsortedExports = settings.exports as Record<string, PackageJsonExportsValue>;\n const sortedKeys = Object.keys(settings.exports).sort();\n\n settings.exports = sortedKeys.reduce((p, n) => {\n p[n] = unsortedExports[n];\n return p;\n }, {} as PackageJsonExportsObject);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI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CAAC,CAAC;IAEH,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,YAAY,IAAI,eAAe,CAAC,eAAe,EAAE,MAAM,EAAE;QAC7E,cAAc,CAAC,eAAe,CAAC,CAAC;QAEhC,MAAM,oBAAoB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;KACtD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,cAAc,CAAC,EAAE,eAAe,GAAG,EAAE,EAAmB;IAC/D,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE;QACtC,IAAI,QAAQ,CAAC,OAAO,EAAE;YACpB,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAkD,CAAC;YACpF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;YAExD,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;gBAC5C,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;gBAC1B,OAAO,CAAC,CAAC;YACX,CAAC,EAAE,EAA8B,CAAC,CAAC;SACpC;KACF;AACH,CAAC","sourcesContent":["import type { PackageJsonExportsObject, PackageJsonExportsValue } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig, GeneratedConfig } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { AutoDispose } from '../../types/AutoDispose.js';\nimport type { InitOptions } from './types/InitOptions.js';\nimport type { InitSummary } from './types/InitSummary.js';\n\nimport { createPartialApiContext } from '@ms-cloudpack/api-server/apis';\nimport { writeGeneratedConfig } from '@ms-cloudpack/config';\nimport { InitSummaryData } from './InitSummaryData.js';\nimport { evaluatePath } from './evaluatePath.js';\n\n/**\n * Init execution function.\n */\nexport async function init(parameters: {\n options: InitOptions;\n appPath: string;\n config: CloudpackConfig;\n autoDispose: AutoDispose;\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n}): Promise<InitSummary> {\n const { options, appPath, config, reporter, autoDispose, telemetryClient } = parameters;\n let isExitingPrematurely = false;\n\n // Don't allow --check and --reset together.\n if (options.check && options.reset) {\n throw Error('Cannot use --check and --reset together.');\n }\n\n // If --reset is specified, reset the generated config.\n if (options.reset) {\n config.generated = {};\n }\n\n const summaryData = new InitSummaryData();\n const [ctx] = autoDispose(\n await createPartialApiContext({\n appPath,\n config,\n reporter,\n telemetryClient,\n items: ['bus', 'taskRunner', 'watcher', 'packages', 'session'],\n }),\n );\n const { session } = ctx;\n const { resolveMap } = session;\n const refreshPaths = new Set<string>();\n const generatedConfig = config.generated;\n\n // Ensure generatedConfig.packageSettings is initialized.\n generatedConfig.packageSettings ??= [];\n\n const summary = await new Promise<InitSummary>((resolve, reject) => {\n let pending = 0;\n const visitedSet = new Set<string>();\n\n // Create a function to enqueue more paths.\n function enqueuePaths(newPaths: string[]) {\n if (isExitingPrematurely) {\n return;\n }\n\n // Iterate through the given paths.\n for (const path of newPaths) {\n if (visitedSet.has(path)) {\n continue;\n }\n\n const shouldForce = refreshPaths.delete(path);\n\n visitedSet.add(path);\n pending++;\n\n // Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.\n evaluatePath({\n packagePath: path,\n generatedConfig,\n telemetryClient,\n resolveMap,\n shouldForce,\n initOptions: options,\n summaryData,\n ctx,\n })\n .then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {\n pending--;\n\n if (shouldExit) {\n isExitingPrematurely = true;\n }\n\n if (!isExitingPrematurely && pathsToEvaluate?.size) {\n // If there are paths that need to be rebuilt, add them to the refresh set so that on re-enqueuing\n // we pass the `shouldRerun` flag through\n pathsToRefresh?.forEach((refreshPath) => {\n refreshPaths.add(refreshPath);\n visitedSet.delete(refreshPath);\n });\n\n // Try to enqueue the new paths.\n enqueuePaths(Array.from(pathsToEvaluate));\n }\n\n // If nothing is pending after this call, we're complete.\n if (!pending) {\n resolve(summaryData.summarize());\n }\n })\n .catch((error) => {\n reject(error);\n });\n }\n }\n\n // Start with the app path.\n enqueuePaths([appPath]);\n });\n\n const { totalChanges } = summary;\n\n if (!options.check && totalChanges && generatedConfig.packageSettings?.length) {\n sortExportKeys(generatedConfig);\n\n await writeGeneratedConfig(generatedConfig, appPath);\n }\n\n return summary;\n}\n\nfunction sortExportKeys({ packageSettings = [] }: GeneratedConfig) {\n for (const settings of packageSettings) {\n if (settings.exports) {\n const unsortedExports = settings.exports as Record<string, PackageJsonExportsValue>;\n const sortedKeys = Object.keys(settings.exports).sort();\n\n settings.exports = sortedKeys.reduce((p, n) => {\n p[n] = unsortedExports[n];\n return p;\n }, {} as PackageJsonExportsObject);\n }\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export declare const cookieNames: {
2
+ readonly bundleServerUrl: "cloudpack-bundle-server-url";
3
+ readonly sessionId: string;
4
+ readonly sessionSequence: string;
5
+ readonly apiUrl: string;
6
+ };
7
+ export declare function getCloudpackSessionVersionCookie(projectName: string): string;
8
+ //# sourceMappingURL=cookieNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookieNames.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/cookieNames.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW;;;;;CAGd,CAAC;AAEX,wBAAgB,gCAAgC,CAAC,WAAW,EAAE,MAAM,UAEnE"}
@@ -0,0 +1,9 @@
1
+ import { cookieNames as overlayCookieNames } from '@ms-cloudpack/overlay/constants';
2
+ export const cookieNames = {
3
+ ...overlayCookieNames,
4
+ bundleServerUrl: 'cloudpack-bundle-server-url',
5
+ };
6
+ export function getCloudpackSessionVersionCookie(projectName) {
7
+ return 'cloudpack-sessionVersion-' + projectName;
8
+ }
9
+ //# sourceMappingURL=cookieNames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookieNames.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/cookieNames.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAEpF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,kBAAkB;IACrB,eAAe,EAAE,6BAA6B;CACtC,CAAC;AAEX,MAAM,UAAU,gCAAgC,CAAC,WAAmB;IAClE,OAAO,2BAA2B,GAAG,WAAW,CAAC;AACnD,CAAC","sourcesContent":["import { cookieNames as overlayCookieNames } from '@ms-cloudpack/overlay/constants';\n\nexport const cookieNames = {\n ...overlayCookieNames,\n bundleServerUrl: 'cloudpack-bundle-server-url',\n} as const;\n\nexport function getCloudpackSessionVersionCookie(projectName: string) {\n return 'cloudpack-sessionVersion-' + projectName;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"handleSessionVersion.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/handleSessionVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,UASlE"}
1
+ {"version":3,"file":"handleSessionVersion.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/appServer/handleSessionVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAGxD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,UASlE"}
@@ -1,10 +1,11 @@
1
+ import { getCloudpackSessionVersionCookie } from './cookieNames.js';
1
2
  /**
2
3
  * Get the latest refresh version either from the cookie in request or from the session.
3
4
  * Update the session with the latest refresh version.
4
5
  */
5
6
  export function handleSessionVersion(session, req) {
6
7
  const lastSessionVersion = Number(req.headers.cookie
7
- ?.match('(^|;)\\s*' + `cloudpack-sessionVersion-${session.projectName}` + '\\s*=\\s*([^;]+)')
8
+ ?.match('(^|;)\\s*' + getCloudpackSessionVersionCookie(session.projectName) + '\\s*=\\s*([^;]+)')
8
9
  ?.pop() || '0');
9
10
  session.incrementSessionVersion(lastSessionVersion);
10
11
  return session.getSessionVersion();
@@ -1 +1 @@
1
- {"version":3,"file":"handleSessionVersion.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/handleSessionVersion.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,GAAY;IACjE,MAAM,kBAAkB,GAAG,MAAM,CAC/B,GAAG,CAAC,OAAO,CAAC,MAAM;QAChB,EAAE,KAAK,CAAC,WAAW,GAAG,4BAA4B,OAAO,CAAC,WAAW,EAAE,GAAG,kBAAkB,CAAC;QAC7F,EAAE,GAAG,EAAE,IAAI,GAAG,CACjB,CAAC;IACF,OAAO,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IAEpD,OAAO,OAAO,CAAC,iBAAiB,EAAE,CAAC;AACrC,CAAC","sourcesContent":["import type { Request } from '@ms-cloudpack/create-express-app';\nimport type { Session } from '@ms-cloudpack/api-server';\n\n/**\n * Get the latest refresh version either from the cookie in request or from the session.\n * Update the session with the latest refresh version.\n */\nexport function handleSessionVersion(session: Session, req: Request) {\n const lastSessionVersion = Number(\n req.headers.cookie\n ?.match('(^|;)\\\\s*' + `cloudpack-sessionVersion-${session.projectName}` + '\\\\s*=\\\\s*([^;]+)')\n ?.pop() || '0',\n );\n session.incrementSessionVersion(lastSessionVersion);\n\n return session.getSessionVersion();\n}\n"]}
1
+ {"version":3,"file":"handleSessionVersion.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/handleSessionVersion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,GAAY;IACjE,MAAM,kBAAkB,GAAG,MAAM,CAC/B,GAAG,CAAC,OAAO,CAAC,MAAM;QAChB,EAAE,KAAK,CAAC,WAAW,GAAG,gCAAgC,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,kBAAkB,CAAC;QACjG,EAAE,GAAG,EAAE,IAAI,GAAG,CACjB,CAAC;IACF,OAAO,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IAEpD,OAAO,OAAO,CAAC,iBAAiB,EAAE,CAAC;AACrC,CAAC","sourcesContent":["import type { Request } from '@ms-cloudpack/create-express-app';\nimport type { Session } from '@ms-cloudpack/api-server';\nimport { getCloudpackSessionVersionCookie } from './cookieNames.js';\n\n/**\n * Get the latest refresh version either from the cookie in request or from the session.\n * Update the session with the latest refresh version.\n */\nexport function handleSessionVersion(session: Session, req: Request) {\n const lastSessionVersion = Number(\n req.headers.cookie\n ?.match('(^|;)\\\\s*' + getCloudpackSessionVersionCookie(session.projectName) + '\\\\s*=\\\\s*([^;]+)')\n ?.pop() || '0',\n );\n session.incrementSessionVersion(lastSessionVersion);\n\n return session.getSessionVersion();\n}\n"]}
@@ -1,3 +1,4 @@
1
+ // This file must NOT import other files, because they won't be resolved at runtime.
1
2
  const pageErrors = (window.__pageErrors = {
2
3
  uncaughtErrors: [],
3
4
  uncaughtRejections: [],
@@ -1 +1 @@
1
- {"version":3,"file":"errorHandler.inline.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/errorHandler.inline.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG;IACxC,cAAc,EAAE,EAAkB;IAClC,kBAAkB,EAAE,EAA6B;IACjD,UAAU,EAAE,GAAG,EAAE;QACf,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACjD,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;IACpE,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,WAAW,CAAC,KAAiB;IACpC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,eAAe,CAAC,KAA4B;IACnD,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC9C,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC","sourcesContent":["const pageErrors = (window.__pageErrors = {\n uncaughtErrors: [] as ErrorEvent[],\n uncaughtRejections: [] as PromiseRejectionEvent[],\n unregister: () => {\n window.removeEventListener('error', handleError);\n window.removeEventListener('unhandledrejection', handleRejection);\n },\n});\n\nfunction handleError(event: ErrorEvent) {\n pageErrors.uncaughtErrors.push(event);\n}\n\nfunction handleRejection(event: PromiseRejectionEvent) {\n pageErrors.uncaughtRejections.push(event);\n}\n\nwindow.addEventListener('error', handleError);\nwindow.addEventListener('unhandledrejection', handleRejection);\n"]}
1
+ {"version":3,"file":"errorHandler.inline.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/errorHandler.inline.ts"],"names":[],"mappings":"AAAA,oFAAoF;AAEpF,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG;IACxC,cAAc,EAAE,EAAkB;IAClC,kBAAkB,EAAE,EAA6B;IACjD,UAAU,EAAE,GAAG,EAAE;QACf,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACjD,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;IACpE,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,WAAW,CAAC,KAAiB;IACpC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,eAAe,CAAC,KAA4B;IACnD,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC9C,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC","sourcesContent":["// This file must NOT import other files, because they won't be resolved at runtime.\n\nconst pageErrors = (window.__pageErrors = {\n uncaughtErrors: [] as ErrorEvent[],\n uncaughtRejections: [] as PromiseRejectionEvent[],\n unregister: () => {\n window.removeEventListener('error', handleError);\n window.removeEventListener('unhandledrejection', handleRejection);\n },\n});\n\nfunction handleError(event: ErrorEvent) {\n pageErrors.uncaughtErrors.push(event);\n}\n\nfunction handleRejection(event: PromiseRejectionEvent) {\n pageErrors.uncaughtRejections.push(event);\n}\n\nwindow.addEventListener('error', handleError);\nwindow.addEventListener('unhandledrejection', handleRejection);\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getBrowserCacheRatio.inline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBrowserCacheRatio.inline.d.ts","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getBrowserCacheRatio.inline.ts"],"names":[],"mappings":""}
@@ -1,16 +1,18 @@
1
+ // This file must NOT import other files (except types), because they won't be resolved at runtime.
2
+ // Typing hack to ensure this name is correct while working around the limitation on runtime imports
3
+ const cloudpackBundleServerUrlCookie = 'cloudpack-bundle-server-url';
1
4
  const scriptLoadResults = {};
2
5
  function getCookie(cname) {
3
6
  const decodedCookies = decodeURIComponent(document.cookie);
4
7
  const cookies = decodedCookies.split(';');
5
8
  const keyValues = cookies.map((cookie) => cookie.split('='));
6
- const cookie = keyValues.find(([key]) => key === cname);
9
+ const cookie = keyValues.find(([key]) => key.trim() === cname);
7
10
  if (!cookie) {
8
11
  throw new Error(`Cookie ${cname} not found`);
9
12
  }
10
- const value = cookie[1].trim();
11
- return value;
13
+ return cookie[1].trim();
12
14
  }
13
- const bundleServerUrl = getCookie('cloudpack-bundle-server-url');
15
+ const bundleServerUrl = getCookie(cloudpackBundleServerUrlCookie);
14
16
  function isPerformanceResourceTiming(entry) {
15
17
  return entry.entryType === 'resource';
16
18
  }
@@ -30,9 +32,12 @@ for (const entry of performance.getEntriesByType('resource')) {
30
32
  }
31
33
  // Observe all resources that are loaded after this script
32
34
  perfObserver.observe({ type: 'resource', buffered: true });
33
- export function getBrowserCacheRatio() {
35
+ function getBrowserCacheRatio() {
34
36
  const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;
35
37
  const ratio = cacheCount / Object.keys(scriptLoadResults).length;
36
38
  return ratio;
37
39
  }
38
- //# sourceMappingURL=getBrowserCacheRatio.js.map
40
+ window.__cloudpack ??= {};
41
+ window.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;
42
+ export {};
43
+ //# sourceMappingURL=getBrowserCacheRatio.inline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBrowserCacheRatio.inline.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getBrowserCacheRatio.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAInG,oGAAoG;AACpG,MAAM,8BAA8B,GAA4C,6BAA6B,CAAC;AAE9G,MAAM,iBAAiB,GAAwC,EAAE,CAAC;AAElE,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,cAAc,GAAG,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC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,CAAC;AAE3D,SAAS,oBAAoB;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,MAAM,CAAC;IACjG,MAAM,KAAK,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC;IAEjE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,WAAW,KAAK,EAA+B,CAAC;AACvD,MAAM,CAAC,WAAW,CAAC,oBAAoB,GAAG,oBAAoB,CAAC","sourcesContent":["// This file must NOT import other files (except types), because they won't be resolved at runtime.\n\nimport type { cookieNames } from '../cookieNames.js';\n\n// Typing hack to ensure this name is correct while working around the limitation on runtime imports\nconst cloudpackBundleServerUrlCookie: (typeof cookieNames)['bundleServerUrl'] = 'cloudpack-bundle-server-url';\n\nconst scriptLoadResults: Record<string, 'cache' | 'network'> = {};\n\nfunction getCookie(cname: string) {\n const decodedCookies = decodeURIComponent(document.cookie);\n const cookies = decodedCookies.split(';');\n const keyValues = cookies.map((cookie) => cookie.split('='));\n const cookie = keyValues.find(([key]) => key.trim() === cname);\n if (!cookie) {\n throw new Error(`Cookie ${cname} not found`);\n }\n\n return cookie[1].trim();\n}\n\nconst bundleServerUrl = getCookie(cloudpackBundleServerUrlCookie);\n\nfunction isPerformanceResourceTiming(entry: PerformanceEntry): entry is PerformanceResourceTiming {\n return entry.entryType === 'resource';\n}\n\nfunction handlePerformanceEntry(item: PerformanceEntry) {\n if (isPerformanceResourceTiming(item) && item.name.startsWith(bundleServerUrl)) {\n scriptLoadResults[item.name] = item.transferSize === 0 ? 'cache' : 'network';\n }\n}\n\nconst perfObserver = new PerformanceObserver((list) => {\n for (const item of list.getEntries()) {\n handlePerformanceEntry(item);\n }\n});\n\n// Get all the resources that were loaded before this script\nfor (const entry of performance.getEntriesByType('resource')) {\n handlePerformanceEntry(entry);\n}\n\n// Observe all resources that are loaded after this script\nperfObserver.observe({ type: 'resource', buffered: true });\n\nfunction getBrowserCacheRatio() {\n const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;\n const ratio = cacheCount / Object.keys(scriptLoadResults).length;\n\n return ratio;\n}\n\nwindow.__cloudpack ??= {} as typeof window.__cloudpack;\nwindow.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getInlineScripts.d.ts","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAWA,wBAAsB,gBAAgB,sBAQrC"}
1
+ {"version":3,"file":"getInlineScripts.d.ts","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAcA,wBAAsB,gBAAgB,sBAQrC"}
@@ -1,10 +1,11 @@
1
1
  import fsPromises from 'fs/promises';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
+ import { dynamicImportExtension } from '../../../../utilities/dynamicImportExtension.js';
4
5
  const currentPath = fileURLToPath(path.dirname(import.meta.url));
5
6
  let inlineScripts;
6
7
  // List of files that we will load on demand.
7
- const inlineScriptFiles = ['errorHandler.inline.js', 'cloudpackWindowVariable.inline.ts'];
8
+ const inlineScriptFiles = ['errorHandler', 'getBrowserCacheRatio', 'getPageLoadTime'].map((file) => `${file}.inline${dynamicImportExtension}`);
8
9
  export async function getInlineScripts() {
9
10
  if (!inlineScripts) {
10
11
  inlineScripts = await Promise.all(inlineScriptFiles.map((filename) => fsPromises.readFile(path.join(currentPath, filename), 'utf-8')));
@@ -1 +1 @@
1
- {"version":3,"file":"getInlineScripts.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEjE,IAAI,aAAmC,CAAC;AAExC,6CAA6C;AAC7C,MAAM,iBAAiB,GAAG,CAAC,wBAAwB,EAAE,mCAAmC,CAAC,CAAC;AAE1F,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,aAAa,EAAE;QAClB,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,iBAAiB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CACpG,CAAC;KACH;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst currentPath = fileURLToPath(path.dirname(import.meta.url));\n\nlet inlineScripts: string[] | undefined;\n\n// List of files that we will load on demand.\nconst inlineScriptFiles = ['errorHandler.inline.js', 'cloudpackWindowVariable.inline.ts'];\n\nexport async function getInlineScripts() {\n if (!inlineScripts) {\n inlineScripts = await Promise.all(\n inlineScriptFiles.map((filename) => fsPromises.readFile(path.join(currentPath, filename), 'utf-8')),\n );\n }\n\n return inlineScripts;\n}\n"]}
1
+ {"version":3,"file":"getInlineScripts.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iDAAiD,CAAC;AAEzF,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEjE,IAAI,aAAmC,CAAC;AAExC,6CAA6C;AAC7C,MAAM,iBAAiB,GAAG,CAAC,cAAc,EAAE,sBAAsB,EAAE,iBAAiB,CAAC,CAAC,GAAG,CACvF,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,UAAU,sBAAsB,EAAE,CACpD,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,aAAa,EAAE;QAClB,aAAa,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,iBAAiB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CACpG,CAAC;KACH;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { dynamicImportExtension } from '../../../../utilities/dynamicImportExtension.js';\n\nconst currentPath = fileURLToPath(path.dirname(import.meta.url));\n\nlet inlineScripts: string[] | undefined;\n\n// List of files that we will load on demand.\nconst inlineScriptFiles = ['errorHandler', 'getBrowserCacheRatio', 'getPageLoadTime'].map(\n (file) => `${file}.inline${dynamicImportExtension}`,\n);\n\nexport async function getInlineScripts() {\n if (!inlineScripts) {\n inlineScripts = await Promise.all(\n inlineScriptFiles.map((filename) => fsPromises.readFile(path.join(currentPath, filename), 'utf-8')),\n );\n }\n\n return inlineScripts;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getPageLoadTime.inline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPageLoadTime.inline.d.ts","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getPageLoadTime.inline.ts"],"names":[],"mappings":""}
@@ -1,4 +1,6 @@
1
- import { overlayRootDivId } from '@ms-cloudpack/overlay';
1
+ // This file must NOT import other files (except types), because they won't be resolved at runtime.
2
+ // Typing hack to ensure this ID is correct while working around the limitation on runtime imports
3
+ const overlayRootDivId = 'cloudpack-overlay-root';
2
4
  /**
3
5
  * Performance mark name for page load time.
4
6
  * This makes it easier to see the page load time in the performance tab in dev tools
@@ -56,7 +58,7 @@ const pageLoadTimePromise = new Promise((resolve) => {
56
58
  childList: true,
57
59
  });
58
60
  });
59
- export function getPageLoadTime() {
60
- return pageLoadTimePromise;
61
- }
62
- //# sourceMappingURL=getPageLoadTime.js.map
61
+ window.__cloudpack ??= {};
62
+ window.__cloudpack.getPageLoadTime = () => pageLoadTimePromise;
63
+ export {};
64
+ //# sourceMappingURL=getPageLoadTime.inline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPageLoadTime.inline.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getPageLoadTime.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAInG,kGAAkG;AAClG,MAAM,gBAAgB,GAAgC,wBAAwB,CAAC;AAE/E;;;GAGG;AACH,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,8DAA8D;AAC9D,MAAM,WAAW,GAAa,CAAC,gBAAgB,CAAC,CAAC;AAIjD,SAAS,QAAQ,CAAsB,IAAqB,EAAE,IAAY;IACxE,IAAI,OAA6C,CAAC;IAElD,OAAO,UAAU,GAAG,IAAO;QACzB,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAChB,CAAC,CAAC;QAEF,IAAI,OAAO,EAAE;YACX,YAAY,CAAC,OAAO,CAAC,CAAC;SACvB;QACD,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;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AC9B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,WAAW,KAAK,EAA+B,CAAC;AACvD,MAAM,CAAC,WAAW,CAAC,eAAe,GAAG,GAAG,EAAE,CAAC,mBAAmB,CAAC","sourcesContent":["// This file must NOT import other files (except types), because they won't be resolved at runtime.\n\nimport type { overlayRootDivId as overlayRootDivIdType } from '@ms-cloudpack/overlay/constants';\n\n// Typing hack to ensure this ID is correct while working around the limitation on runtime imports\nconst overlayRootDivId: typeof overlayRootDivIdType = 'cloudpack-overlay-root';\n\n/**\n * Performance mark name for page load time.\n * This makes it easier to see the page load time in the performance tab in dev tools\n */\nconst pageLoadMarker = 'CLOUDPACK_PAGE_LOAD_TIME';\n\n// The below dom elements will be ignored by mutation observer\nconst excludedIds: string[] = [overlayRootDivId];\n\ntype DebounceFunc<T extends unknown[]> = (...args: T) => void;\n\nfunction debounce<T extends unknown[]>(func: DebounceFunc<T>, wait: number): DebounceFunc<T> {\n let timeout: ReturnType<typeof setTimeout> | null;\n\n return function (...args: T) {\n const later = () => {\n timeout = null;\n func(...args);\n };\n\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(later, wait);\n };\n}\n\nfunction hasMutationNonExcludedNodes(mutation: MutationRecord) {\n return [...mutation.addedNodes].some((node) => {\n const id = (node as { id?: string }).id;\n\n if (id) {\n return !excludedIds.includes(id);\n }\n\n return true;\n });\n}\n\nconst pageLoadTimePromise = new Promise<number>((resolve) => {\n const observer = new MutationObserver(domChanged);\n\n function reportLastAnimationTime(time: number) {\n // Stop observing the DOM\n observer.disconnect();\n\n // Resolve the promise with the page load time\n resolve(time);\n }\n\n const debouncedReportLastAnimationTime = debounce(reportLastAnimationTime, 2000 /* wait ms */);\n\n function domChanged(mutations: MutationRecord[]) {\n const shouldProcess = mutations.filter(hasMutationNonExcludedNodes).length > 0;\n\n if (shouldProcess) {\n requestAnimationFrame(() => {\n // Get the current time in ms since the time when navigation has started in window\n const time = performance.now();\n\n // Clear previous marks\n performance.clearMarks(pageLoadMarker);\n\n // Mark the page load time\n performance.mark(pageLoadMarker);\n\n // Report the page load time\n debouncedReportLastAnimationTime(time);\n });\n }\n }\n\n observer.observe(document.body, {\n childList: true,\n });\n});\n\nwindow.__cloudpack ??= {} as typeof window.__cloudpack;\nwindow.__cloudpack.getPageLoadTime = () => pageLoadTimePromise;\n"]}
@@ -4,7 +4,7 @@ import type { BundleServer } from '../../../types/BundleServer.js';
4
4
  /**
5
5
  * Set the Cloudpack headers and cookies in the response.
6
6
  */
7
- export declare function setHeaders({ res, session, apiServer, bundleServer, }: {
7
+ export declare function setHeaders(params: {
8
8
  res: Response;
9
9
  session: Session;
10
10
  apiServer: ApiServer;
@@ -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;AAEnE;;GAEG;AACH,wBAAgB,UAAU,CAAC,EACzB,GAAG,EACH,OAAO,EACP,SAAS,EACT,YAAY,GACb,EAAE;IACD,GAAG,EAAE,QAAQ,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;CAC5B,QAUA"}
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,14 +1,16 @@
1
+ import { cookieNames, getCloudpackSessionVersionCookie } from './cookieNames.js';
1
2
  /**
2
3
  * Set the Cloudpack headers and cookies in the response.
3
4
  */
4
- export function setHeaders({ res, session, apiServer, bundleServer, }) {
5
+ export function setHeaders(params) {
6
+ const { res, session, apiServer, bundleServer } = params;
5
7
  res.header('Content-Type', 'text/html');
6
8
  res.header('Cache-Control', 'no-cache');
7
9
  res.header('Access-Control-Allow-Origin', '*');
8
- res.cookie('cloudpack-session-id', session.id);
9
- res.cookie('cloudpack-session-sequence', session.sequence);
10
- res.cookie(`cloudpack-sessionVersion-${session.projectName}`, session.getSessionVersion());
11
- res.cookie('cloudpack-api-url', apiServer.url);
12
- res.cookie('cloudpack-bundle-server-url', bundleServer.url);
10
+ res.cookie(cookieNames.sessionId, session.id);
11
+ res.cookie(cookieNames.sessionSequence, session.sequence);
12
+ res.cookie(getCloudpackSessionVersionCookie(session.projectName), session.getSessionVersion());
13
+ res.cookie(cookieNames.apiUrl, apiServer.url);
14
+ res.cookie(cookieNames.bundleServerUrl, bundleServer.url);
13
15
  }
14
16
  //# sourceMappingURL=setHeaders.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setHeaders.js","sourceRoot":"","sources":["../../../../src/commands/start/appServer/setHeaders.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,GAAG,EACH,OAAO,EACP,SAAS,EACT,YAAY,GAMb;IACC,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,sBAAsB,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/C,GAAG,CAAC,MAAM,CAAC,4BAA4B,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3D,GAAG,CAAC,MAAM,CAAC,4BAA4B,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC3F,GAAG,CAAC,MAAM,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IAC/C,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;AAC9D,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';\n\n/**\n * Set the Cloudpack headers and cookies in the response.\n */\nexport function setHeaders({\n res,\n session,\n apiServer,\n bundleServer,\n}: {\n res: Response;\n session: Session;\n apiServer: ApiServer;\n bundleServer: BundleServer;\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('cloudpack-session-id', session.id);\n res.cookie('cloudpack-session-sequence', session.sequence);\n res.cookie(`cloudpack-sessionVersion-${session.projectName}`, session.getSessionVersion());\n res.cookie('cloudpack-api-url', apiServer.url);\n res.cookie('cloudpack-bundle-server-url', 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,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 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAiB5D,wDAAwD;AACxD,wBAAsB,WAAW,kBAKhC;AAqBD;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,YAAY,CAwH/C,CAAC"}
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAiB5D,wDAAwD;AACxD,wBAAsB,WAAW,kBAKhC;AAqBD;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,YAAY,CA6H/C,CAAC"}
@@ -118,14 +118,19 @@ export const execute = async ({ options, cwd, initialize, reporter, autoDispose
118
118
  dispose: cleanup,
119
119
  });
120
120
  cleanupFunctions.push(cleanup);
121
- // Open the browser.
122
121
  const url = appServer.url;
123
122
  performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);
124
- openBrowser(url).catch((err) => {
125
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
126
- console.warn('Error opening browser:', err?.stack || err);
127
- console.warn('Please open the browser manually to:', url);
128
- });
123
+ // Open the browser.
124
+ if (options.open !== false) {
125
+ openBrowser(url).catch((err) => {
126
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
127
+ console.warn('Error opening browser:', err?.stack || err);
128
+ console.warn('Please open the browser manually to:', url);
129
+ });
130
+ }
131
+ else {
132
+ console.log('Please open the browser manually to:', url);
133
+ }
129
134
  };
130
135
  // cspell:ignore Prereqs
131
136
  //# sourceMappingURL=execute.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC1G,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,IAAI,gBAAgB,GAA+B,EAAE,CAAC;AAEtD,wDAAwD;AACxD,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,KAAK,MAAM,IAAI,IAAI,gBAAgB,EAAE;QACnC,MAAM,IAAI,EAAE,CAAC;KACd;IACD,gBAAgB,GAAG,EAAE,CAAC;AACxB,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,OAAgC,EAChC,OAAyF;IAEzF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC5B,MAAM,YAAY,GAAG,mBAAmB,CAAC;QACvC,WAAW;QACX,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,CAAC,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EAAE,GAAG,CAAC,CAAC;aAC5C;QACH,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,WAAW,CAAC;QACV,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE/B,oBAAoB;IACpB,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC;IAE1B,WAAW,CAAC,OAAO,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;IACpE,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7B,sEAAsE;QACtE,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,wBAAwB","sourcesContent":["import type { Session } from '@ms-cloudpack/api-server';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport type { StartOptions } from './types/StartOptions.js';\n\nimport { createBundleRequestForPackage, createBundleTask, createSession } from '@ms-cloudpack/api-server';\nimport { createPackageDefinitions } from '@ms-cloudpack/config';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { findResolveMapEntry, resolve } from '@ms-cloudpack/package-utilities';\nimport { yellow } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport { getStartingAppPath } from './getStartingAppPath.js';\nimport { mergeFeatures } from './mergeFeatures.js';\nimport { openBrowser } from './openBrowser.js';\nimport { runPrereqs } from './runPrereqs.js';\n\nlet cleanupFunctions: Array<() => Promise<void>> = [];\n\n/** Stop all started cloudpack instances, for testing */\nexport async function stopServers() {\n for (const func of cleanupFunctions) {\n await func();\n }\n cleanupFunctions = [];\n}\n\nasync function createAppBundleTask(\n options: { packageName: string },\n context: { session: Session; config: CloudpackConfig; packages: PackageDefinitionsCache },\n) {\n const { packageName } = options;\n const { session } = context;\n const packageEntry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${packageName} in the resolve map.`);\n }\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, context);\n\n return createBundleTask(bundleRequest);\n}\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async ({ options, cwd, initialize, reporter, autoDispose }) => {\n const appPath = await getStartingAppPath(cwd, options.app);\n const { config, telemetryClient } = await initialize(appPath);\n\n console.log('App path:', yellow(appPath));\n\n process.chdir(appPath);\n\n runPrereqs(config, appPath);\n\n // Merge in any additional features from the command line.\n config.features = mergeFeatures({\n configFeatures: config.features,\n commandLineFeatures: options.features,\n });\n\n const enabledFeatureNames = Object.entries(config.features)\n .filter(([, value]) => value)\n .map(([key]) => key);\n\n if (enabledFeatureNames.length) {\n console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);\n }\n\n // Initialize package overrides.\n const packages = createPackageDefinitions({ config });\n\n // Make sure the package has a valid definition.\n const definition = await packages.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(\n {\n appPath,\n config,\n overlayPath: await resolve('@ms-cloudpack/overlay', path.dirname(fileURLToPath(import.meta.url))),\n },\n { reporter, packages },\n );\n\n // Set shared telemetry attributes which will be sent with all telemetry events.\n telemetryClient.setSharedSpanAttribute('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 const { startApiServer } = await import('@ms-cloudpack/api-server');\n\n // Start api server for tracking status and handling remote requests.\n const apiServer = await startApiServer({\n session,\n telemetryClient,\n reporter,\n packages,\n });\n\n // Kick off bundling app package as soon as api server is ready.\n void apiServer.addTask(await createAppBundleTask({ packageName: definition.name }, { session, config, packages }));\n\n // Then start bundle and app servers for hosting the app.\n const { startBundleServer } = await import('./startBundleServer.js');\n const bundleServer = await startBundleServer({ apiServer, session, reporter, packages });\n\n // Finally start the app server.\n const { startAppServer } = await import('./appServer/startAppServer.js');\n const appServer = await startAppServer({\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n reporter,\n packages,\n });\n\n const cleanup = async () => {\n const servers = [\n ['appServer', appServer] as const,\n ['apiServer', apiServer] as const,\n ['bundleServer', bundleServer] as const,\n ];\n\n await Promise.all(\n servers.map(async ([name, server]) => {\n console.info(`Closing ${name}: ${server.url}`);\n try {\n await server.close();\n console.info(`Closed ${name}: ${server.url}`);\n } catch (err) {\n console.warn('Error closing server:', err);\n }\n }),\n );\n };\n\n autoDispose({\n dispose: cleanup,\n });\n\n cleanupFunctions.push(cleanup);\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};\n\n// cspell:ignore Prereqs\n"]}
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC1G,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,mBAAmB,E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IACpB,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE;QAC1B,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;SAAM;QACL,OAAO,CAAC,GAAG,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;KAC1D;AACH,CAAC,CAAC;AAEF,wBAAwB","sourcesContent":["import type { Session } from '@ms-cloudpack/api-server';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport type { StartOptions } from './types/StartOptions.js';\n\nimport { createBundleRequestForPackage, createBundleTask, createSession } from '@ms-cloudpack/api-server';\nimport { createPackageDefinitions } from '@ms-cloudpack/config';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { findResolveMapEntry, resolve } from '@ms-cloudpack/package-utilities';\nimport { yellow } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport { getStartingAppPath } from './getStartingAppPath.js';\nimport { mergeFeatures } from './mergeFeatures.js';\nimport { openBrowser } from './openBrowser.js';\nimport { runPrereqs } from './runPrereqs.js';\n\nlet cleanupFunctions: Array<() => Promise<void>> = [];\n\n/** Stop all started cloudpack instances, for testing */\nexport async function stopServers() {\n for (const func of cleanupFunctions) {\n await func();\n }\n cleanupFunctions = [];\n}\n\nasync function createAppBundleTask(\n options: { packageName: string },\n context: { session: Session; config: CloudpackConfig; packages: PackageDefinitionsCache },\n) {\n const { packageName } = options;\n const { session } = context;\n const packageEntry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${packageName} in the resolve map.`);\n }\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, context);\n\n return createBundleTask(bundleRequest);\n}\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async ({ options, cwd, initialize, reporter, autoDispose }) => {\n const appPath = await getStartingAppPath(cwd, options.app);\n const { config, telemetryClient } = await initialize(appPath);\n\n console.log('App path:', yellow(appPath));\n\n process.chdir(appPath);\n\n runPrereqs(config, appPath);\n\n // Merge in any additional features from the command line.\n config.features = mergeFeatures({\n configFeatures: config.features,\n commandLineFeatures: options.features,\n });\n\n const enabledFeatureNames = Object.entries(config.features)\n .filter(([, value]) => value)\n .map(([key]) => key);\n\n if (enabledFeatureNames.length) {\n console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);\n }\n\n // Initialize package overrides.\n const packages = createPackageDefinitions({ config });\n\n // Make sure the package has a valid definition.\n const definition = await packages.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(\n {\n appPath,\n config,\n overlayPath: await resolve('@ms-cloudpack/overlay', path.dirname(fileURLToPath(import.meta.url))),\n },\n { reporter, packages },\n );\n\n // Set shared telemetry attributes which will be sent with all telemetry events.\n telemetryClient.setSharedSpanAttribute('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 const { startApiServer } = await import('@ms-cloudpack/api-server');\n\n // Start api server for tracking status and handling remote requests.\n const apiServer = await startApiServer({\n session,\n telemetryClient,\n reporter,\n packages,\n });\n\n // Kick off bundling app package as soon as api server is ready.\n void apiServer.addTask(await createAppBundleTask({ packageName: definition.name }, { session, config, packages }));\n\n // Then start bundle and app servers for hosting the app.\n const { startBundleServer } = await import('./startBundleServer.js');\n const bundleServer = await startBundleServer({ apiServer, session, reporter, packages });\n\n // Finally start the app server.\n const { startAppServer } = await import('./appServer/startAppServer.js');\n const appServer = await startAppServer({\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n reporter,\n packages,\n });\n\n const cleanup = async () => {\n const servers = [\n ['appServer', appServer] as const,\n ['apiServer', apiServer] as const,\n ['bundleServer', bundleServer] as const,\n ];\n\n await Promise.all(\n servers.map(async ([name, server]) => {\n console.info(`Closing ${name}: ${server.url}`);\n try {\n await server.close();\n console.info(`Closed ${name}: ${server.url}`);\n } catch (err) {\n console.warn('Error closing server:', err);\n }\n }),\n );\n };\n\n autoDispose({\n dispose: cleanup,\n });\n\n cleanupFunctions.push(cleanup);\n\n const url = appServer.url;\n\n performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n // Open the browser.\n if (options.open !== false) {\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 } else {\n console.log('Please open the browser manually to:', url);\n }\n};\n\n// cspell:ignore Prereqs\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,eAAO,MAAM,IAAI,EAAE,eAYlB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,eAAO,MAAM,IAAI,EAAE,eAalB,CAAC"}
@@ -6,6 +6,7 @@ export const init = (command, createAction) => {
6
6
  .option('--log-resolve-map', 'Logs the resolve map to "resolve-map.json" for diagnostics.')
7
7
  .option('--features <featureName> [featureNames...]', 'Enable experimental features.')
8
8
  .option('--app <appPackageName>', 'Run Cloudpack targeting a specific app.')
9
+ .option('--no-open', 'Do not open the browser.')
9
10
  .action(createAction(() => ({
10
11
  execute: import('./execute.js'),
11
12
  })));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAEA,+BAA+B;AAC/B,MAAM,CAAC,MAAM,IAAI,GAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE;IAC7D,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,mBAAmB,EAAE,6DAA6D,CAAC;SAC1F,MAAM,CAAC,4CAA4C,EAAE,+BAA+B,CAAC;SACrF,MAAM,CAAC,wBAAwB,EAAE,yCAAyC,CAAC;SAC3E,MAAM,CACL,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC;KAChC,CAAC,CAAC,CACJ,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { CommandFunction } from '../../types/CommandFunction.js';\n\n/* Defines the \"start\" verb. */\nexport const init: CommandFunction = (command, createAction) => {\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 .option('--features <featureName> [featureNames...]', 'Enable experimental features.')\n .option('--app <appPackageName>', 'Run Cloudpack targeting a specific app.')\n .action(\n createAction(() => ({\n execute: import('./execute.js'),\n })),\n );\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAEA,+BAA+B;AAC/B,MAAM,CAAC,MAAM,IAAI,GAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE;IAC7D,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,mBAAmB,EAAE,6DAA6D,CAAC;SAC1F,MAAM,CAAC,4CAA4C,EAAE,+BAA+B,CAAC;SACrF,MAAM,CAAC,wBAAwB,EAAE,yCAAyC,CAAC;SAC3E,MAAM,CAAC,WAAW,EAAE,0BAA0B,CAAC;SAC/C,MAAM,CACL,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC;KAChC,CAAC,CAAC,CACJ,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { CommandFunction } from '../../types/CommandFunction.js';\n\n/* Defines the \"start\" verb. */\nexport const init: CommandFunction = (command, createAction) => {\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 .option('--features <featureName> [featureNames...]', 'Enable experimental features.')\n .option('--app <appPackageName>', 'Run Cloudpack targeting a specific app.')\n .option('--no-open', 'Do not open the browser.')\n .action(\n createAction(() => ({\n execute: import('./execute.js'),\n })),\n );\n};\n"]}
@@ -5,7 +5,7 @@ import { isFolder } from '@ms-cloudpack/path-utilities';
5
5
  import path from 'path';
6
6
  import { createBundleTask, createBundleRequestForPackage, parseRequestInfo } from '@ms-cloudpack/api-server';
7
7
  import { fileURLToPath } from 'url';
8
- const currentPath = fileURLToPath(import.meta.url);
8
+ const currentFolder = path.dirname(fileURLToPath(import.meta.url));
9
9
  /**
10
10
  * The bundle server handles package requests and returns bundled resources.
11
11
  * Resources are bundled on demand and cached locally to avoid re-bundling
@@ -67,46 +67,43 @@ async function handleRequest(options, context) {
67
67
  if (fullPath.length < packageEntry.path.length) {
68
68
  console.debug(`Response (400): "${packageName}@${version}${filePath}"`);
69
69
  res.status(400).send(`Invalid file path.`);
70
- return;
71
70
  }
72
- console.debug(`Unbundled response returning: "${packageName}@${version}${filePath}"`);
73
- // If the package is external, set cache headers.
74
- if (isExternalPackage(packageEntry.path)) {
75
- res.setHeader('Cache-Control', 'public, max-age=31536000');
71
+ else {
72
+ console.debug(`Unbundled response returning: "${packageName}@${version}${filePath}"`);
73
+ // If the package is external, set cache headers.
74
+ if (isExternalPackage(packageEntry.path)) {
75
+ res.setHeader('Cache-Control', 'public, max-age=31536000');
76
+ }
77
+ res.sendFile(path.join(packageEntry.path, filePath));
76
78
  }
77
- res.sendFile(path.join(packageEntry.path, filePath));
78
79
  return;
79
80
  }
80
81
  const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages });
81
82
  // Set up for bundling.
82
- const rerun = !(await isFolder(bundleRequest.outputPath)) || force;
83
+ const rerun = force || !(await isFolder(bundleRequest.outputPath));
84
+ let hasError = false;
83
85
  if (features.enableLage) {
84
86
  console.debug(`Trying to bundle "${packageName}@${version}" with lage task scheduler`);
85
87
  try {
86
88
  await apiServer.scheduleTask(bundleRequest, {
87
- // TODO: we may want to have away to let users add more types of tasks here
88
- bundle: path.resolve(currentPath, '../../../tasks/bundleTaskWorker.js'),
89
+ // TODO: we may want to have a way to let users add more types of tasks here
90
+ bundle: path.resolve(currentFolder, '../../tasks/bundleTaskWorker.js'),
89
91
  }, { rerun });
90
- console.debug(`Bundle returning: "${packageName}@${version}${filePath}"`);
91
- // Try to return the result.
92
- if (bundleRequest.isExternal) {
93
- res.setHeader('Cache-Control', 'public, max-age=31536000');
94
- }
95
- return res.sendFile(path.join(bundleRequest.outputPath, filePath));
96
92
  }
97
93
  catch (err) {
98
- return res.status(500).type('json').send(bundleRequest);
94
+ console.error(`Error bundling "${packageName}@${version}": ${err}`);
95
+ hasError = true;
99
96
  }
100
97
  }
101
- console.debug(`Trying to bundle "${packageName}@${version}"`);
102
- const bundleTask = createBundleTask(bundleRequest, { force }, reporter);
103
- await apiServer.addTask(bundleTask, { rerun });
104
- // At this point we should have a Task completed.
105
- if ((bundleRequest.result?.errors?.length || 0) > 0) {
106
- res.status(500).type('json').send(bundleRequest);
107
- }
108
98
  else {
109
- if (features.enqueueDependencies && bundleRequest.result?.imports) {
99
+ console.debug(`Trying to bundle "${packageName}@${version}"`);
100
+ const bundleTask = createBundleTask(bundleRequest, { force }, reporter);
101
+ await apiServer.addTask(bundleTask, { rerun });
102
+ // At this point we should have a Task completed.
103
+ if (bundleRequest.result?.errors?.length) {
104
+ hasError = true;
105
+ }
106
+ else if (features.enqueueDependencies && bundleRequest.result?.imports) {
110
107
  // Enqueue all dependencies to be bundled.
111
108
  for (const dependency of Object.keys(bundleRequest.result.imports)) {
112
109
  const dependencyBundleRequest = await createBundleRequestForPackage({ packageEntry: resolveMap[dependency] }, { ...context, config });
@@ -114,6 +111,11 @@ async function handleRequest(options, context) {
114
111
  void apiServer.addTask(createBundleTask(dependencyBundleRequest, { force }, reporter));
115
112
  }
116
113
  }
114
+ }
115
+ if (hasError) {
116
+ res.status(500).type('json').send(bundleRequest);
117
+ }
118
+ else {
117
119
  console.debug(`Bundle returning: "${packageName}@${version}${filePath}"`);
118
120
  // Try to return the result.
119
121
  if (bundleRequest.isExternal) {
@@ -1 +1 @@
1
- {"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC7G,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAIpC,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,C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B,CACjE,EAAE,YAAY,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,EACxC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CACvB,CAAC;gBAEF,yEAAyE;gBACzE,KAAK,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;aACxF;SACF;QAED,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;QAC1E,4BAA4B;QAC5B,IAAI,aAAa,CAAC,UAAU,EAAE;YAC5B,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;SAC5D;QAED,4EAA4E;QAC5E,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;QAE1C,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KAC7D;AACH,CAAC","sourcesContent":["import type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport { createExpressApp, type Express, type Request, type Response } from '@ms-cloudpack/create-express-app';\nimport { isExternalPackage, findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport type { BundleServer } from '../../types/BundleServer.js';\nimport { createBundleTask, createBundleRequestForPackage, parseRequestInfo } from '@ms-cloudpack/api-server';\nimport { fileURLToPath } from 'url';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nconst currentPath = fileURLToPath(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(options: {\n apiServer: ApiServer;\n session: Session;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n}): Promise<BundleServer> {\n const { apiServer, session, reporter, packages } = options;\n const { config } = session;\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, reporter, packages }).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(\n options: {\n req: Request;\n res: Response;\n },\n context: {\n session: Session;\n apiServer: ApiServer;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n },\n) {\n const { req, res } = options;\n const { session, apiServer, reporter, packages } = context;\n const { resolveMap, config } = session;\n const { features = {} } = config;\n const requestPath = slash(req.path.substring(1));\n const force = req.query.force !== undefined;\n const { packageName, version, bundled, filePath } = parseRequestInfo(requestPath);\n const packageEntry = findResolveMapEntry({ packageName, version, resolveMap });\n\n if (!packageEntry) {\n // If the package is missing, invalid arguments.\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\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 res.redirect(`/${packageName}@${packageEntry.version}${filePath}`);\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(packageEntry.path, filePath);\n\n if (fullPath.length < packageEntry.path.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(packageEntry.path)) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(packageEntry.path, filePath));\n return;\n }\n\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages });\n\n // Set up for bundling.\n const rerun = !(await isFolder(bundleRequest.outputPath)) || force;\n\n if (features.enableLage) {\n console.debug(`Trying to bundle \"${packageName}@${version}\" with lage task scheduler`);\n\n try {\n await apiServer.scheduleTask(\n bundleRequest,\n {\n // TODO: we may want to have away to let users add more types of tasks here\n bundle: path.resolve(currentPath, '../../../tasks/bundleTaskWorker.js'),\n },\n { rerun },\n );\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (bundleRequest.isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n return res.sendFile(path.join(bundleRequest.outputPath, filePath));\n } catch (err) {\n return res.status(500).type('json').send(bundleRequest);\n }\n }\n\n console.debug(`Trying to bundle \"${packageName}@${version}\"`);\n\n const bundleTask = createBundleTask(bundleRequest, { force }, reporter);\n await apiServer.addTask(bundleTask, { rerun });\n\n // At this point we should have a Task completed.\n if ((bundleRequest.result?.errors?.length || 0) > 0) {\n res.status(500).type('json').send(bundleRequest);\n } else {\n if (features.enqueueDependencies && bundleRequest.result?.imports) {\n // Enqueue all dependencies to be bundled.\n for (const dependency of Object.keys(bundleRequest.result.imports)) {\n const dependencyBundleRequest = await createBundleRequestForPackage(\n { packageEntry: resolveMap[dependency] },\n { ...context, config },\n );\n\n // No need to await, we don't want to wait until the bundle is completed.\n void apiServer.addTask(createBundleTask(dependencyBundleRequest, { force }, reporter));\n }\n }\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (bundleRequest.isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n // The below header is need to be able to track the browser cache hit ratio.\n res.setHeader('Timing-Allow-Origin', '*');\n\n res.sendFile(path.join(bundleRequest.outputPath, filePath));\n }\n}\n"]}
1
+ {"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC7G,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAIpC,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAKvC;IACC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC;QAClD,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;QACnC,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM;QAClC,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK;QACnC,aAAa,EAAE,CAAC,GAAY,EAAE,EAAE;YAC9B,iCAAiC;YACjC,GAAG,CAAC,GAAG,CAAC,GAAG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AE,MAAM,EAAE;YACxC,QAAQ,GAAG,IAAI,CAAC;SACjB;aAAM,IAAI,QAAQ,CAAC,mBAAmB,IAAI,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE;YACxE,0CAA0C;YAC1C,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;gBAClE,MAAM,uBAAuB,GAAG,MAAM,6BAA6B,CACjE,EAAE,YAAY,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,EACxC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CACvB,CAAC;gBAEF,yEAAyE;gBACzE,KAAK,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;aACxF;SACF;KACF;IAED,IAAI,QAAQ,EAAE;QACZ,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KAClD;SAAM;QACL,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;QAC1E,4BAA4B;QAC5B,IAAI,aAAa,CAAC,UAAU,EAAE;YAC5B,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;SAC5D;QAED,4EAA4E;QAC5E,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;QAE1C,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KAC7D;AACH,CAAC","sourcesContent":["import type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport { createExpressApp, type Express, type Request, type Response } from '@ms-cloudpack/create-express-app';\nimport { isExternalPackage, findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport type { BundleServer } from '../../types/BundleServer.js';\nimport { createBundleTask, createBundleRequestForPackage, parseRequestInfo } from '@ms-cloudpack/api-server';\nimport { fileURLToPath } from 'url';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nconst currentFolder = path.dirname(fileURLToPath(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(options: {\n apiServer: ApiServer;\n session: Session;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n}): Promise<BundleServer> {\n const { apiServer, session, reporter, packages } = options;\n const { config } = session;\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, reporter, packages }).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(\n options: {\n req: Request;\n res: Response;\n },\n context: {\n session: Session;\n apiServer: ApiServer;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n },\n) {\n const { req, res } = options;\n const { session, apiServer, reporter, packages } = context;\n const { resolveMap, config } = session;\n const { features = {} } = config;\n const requestPath = slash(req.path.substring(1));\n const force = req.query.force !== undefined;\n const { packageName, version, bundled, filePath } = parseRequestInfo(requestPath);\n const packageEntry = findResolveMapEntry({ packageName, version, resolveMap });\n\n if (!packageEntry) {\n // If the package is missing, invalid arguments.\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\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 res.redirect(`/${packageName}@${packageEntry.version}${filePath}`);\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(packageEntry.path, filePath);\n\n if (fullPath.length < packageEntry.path.length) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Invalid file path.`);\n } else {\n console.debug(`Unbundled response returning: \"${packageName}@${version}${filePath}\"`);\n // If the package is external, set cache headers.\n if (isExternalPackage(packageEntry.path)) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(packageEntry.path, filePath));\n }\n return;\n }\n\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages });\n\n // Set up for bundling.\n const rerun = force || !(await isFolder(bundleRequest.outputPath));\n let hasError = false;\n\n if (features.enableLage) {\n console.debug(`Trying to bundle \"${packageName}@${version}\" with lage task scheduler`);\n\n try {\n await apiServer.scheduleTask(\n bundleRequest,\n {\n // TODO: we may want to have a way to let users add more types of tasks here\n bundle: path.resolve(currentFolder, '../../tasks/bundleTaskWorker.js'),\n },\n { rerun },\n );\n } catch (err) {\n console.error(`Error bundling \"${packageName}@${version}\": ${err}`);\n hasError = true;\n }\n } else {\n console.debug(`Trying to bundle \"${packageName}@${version}\"`);\n\n const bundleTask = createBundleTask(bundleRequest, { force }, reporter);\n await apiServer.addTask(bundleTask, { rerun });\n\n // At this point we should have a Task completed.\n if (bundleRequest.result?.errors?.length) {\n hasError = true;\n } else if (features.enqueueDependencies && bundleRequest.result?.imports) {\n // Enqueue all dependencies to be bundled.\n for (const dependency of Object.keys(bundleRequest.result.imports)) {\n const dependencyBundleRequest = await createBundleRequestForPackage(\n { packageEntry: resolveMap[dependency] },\n { ...context, config },\n );\n\n // No need to await, we don't want to wait until the bundle is completed.\n void apiServer.addTask(createBundleTask(dependencyBundleRequest, { force }, reporter));\n }\n }\n }\n\n if (hasError) {\n res.status(500).type('json').send(bundleRequest);\n } else {\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (bundleRequest.isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n // The below header is need to be able to track the browser cache hit ratio.\n res.setHeader('Timing-Allow-Origin', '*');\n\n res.sendFile(path.join(bundleRequest.outputPath, filePath));\n }\n}\n"]}
@@ -3,5 +3,7 @@ export interface StartOptions {
3
3
  sourcemap?: boolean;
4
4
  features?: string[];
5
5
  app?: string;
6
+ /** Whether to open the browser (default true) */
7
+ open?: boolean;
6
8
  }
7
9
  //# sourceMappingURL=StartOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StartOptions.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/types/StartOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd"}
1
+ {"version":3,"file":"StartOptions.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/types/StartOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB"}
@@ -1 +1 @@
1
- {"version":3,"file":"StartOptions.js","sourceRoot":"","sources":["../../../../src/commands/start/types/StartOptions.ts"],"names":[],"mappings":"","sourcesContent":["export interface StartOptions {\n logResolveMap?: boolean;\n sourcemap?: boolean;\n features?: string[];\n app?: string;\n}\n"]}
1
+ {"version":3,"file":"StartOptions.js","sourceRoot":"","sources":["../../../../src/commands/start/types/StartOptions.ts"],"names":[],"mappings":"","sourcesContent":["export interface StartOptions {\n logResolveMap?: boolean;\n sourcemap?: boolean;\n features?: string[];\n app?: string;\n /** Whether to open the browser (default true) */\n open?: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAM3D;;;GAGG;AACH,wBAAsB,IAAI,CAAC,WAAW,CAAC,EAAE;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAChD,iBA2CA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAO3D;;;GAGG;AACH,wBAAsB,IAAI,CAAC,WAAW,CAAC,EAAE;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAChD,iBA2CA"}
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ import { fileURLToPath, pathToFileURL } from 'url';
6
6
  import { PerfMarkerCliEntry } from './performance/markers.js';
7
7
  import { TaskReporter } from '@ms-cloudpack/task-reporter';
8
8
  import { createCommandActionFunction } from './common/createCommandActionFunction.js';
9
+ import { dynamicImportExtension } from './utilities/dynamicImportExtension.js';
9
10
  const currentFilePath = fileURLToPath(import.meta.url);
10
11
  const currentPath = path.dirname(currentFilePath);
11
12
  /**
@@ -22,7 +23,7 @@ export async function main(testOptions) {
22
23
  const version = getVersion(import.meta.url);
23
24
  program.name('cloudpack').version(version).usage('<command> [options]');
24
25
  // Ensure the glob works in tests
25
- const commandsGlob = `commands/*/index${path.extname(currentFilePath)}`;
26
+ const commandsGlob = `commands/*/index${dynamicImportExtension}`;
26
27
  const commands = glob.sync(commandsGlob, { cwd: currentPath });
27
28
  if (!commands.length) {
28
29
  // There was an issue with the glob above not working in tests, so make sure that doesn't happen again
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAEtF,MAAM,eAAe,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvD,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,WAK1B;IACC,WA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C;KAC7C;IAED,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,mEAAmE,CAAC,CAAC;IACrG,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,kEAAkE,CAAC,CAAC;IAClG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,gDAAgD,CAAC,CAAC;IAEnF,WAAW,EAAE,iBAAiB,EAAE,CAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAE/B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7B,OAAO,CAAC,IAAI,EAAE,CAAC;KAChB;AACH,CAAC","sourcesContent":["import { getVersion } from '@ms-cloudpack/package-utilities';\nimport { Command } from 'commander';\nimport glob from 'glob';\nimport path from 'path';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport { PerfMarkerCliEntry } from './performance/markers.js';\nimport type { CommandFunction } from './types/CommandFunction.js';\nimport { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { createCommandActionFunction } from './common/createCommandActionFunction.js';\n\nconst currentFilePath = fileURLToPath(import.meta.url);\nconst currentPath = path.dirname(currentFilePath);\n\n/**\n * Entry point for the cloudpack CLI.\n * Resolves all commands defined within the \"./commands\" folder.\n */\nexport async function main(testOptions?: {\n appPath: string;\n argv: string[];\n reporter: TaskReporter;\n preParseOverrides?: (program: Command) => void;\n}) {\n performance.mark(PerfMarkerCliEntry);\n\n const argv = testOptions?.argv || process.argv;\n const cwd = testOptions?.appPath || process.cwd();\n const reporter = testOptions?.reporter || new TaskReporter();\n\n const abortController = new AbortController();\n\n const program = new Command();\n const version = getVersion(import.meta.url);\n\n program.name('cloudpack').version(version).usage('<command> [options]');\n\n // Ensure the glob works in tests\n const commandsGlob = `commands/*/index${path.extname(currentFilePath)}`;\n const commands = glob.sync(commandsGlob, { cwd: currentPath });\n if (!commands.length) {\n // There was an issue with the glob above not working in tests, so make sure that doesn't happen again\n throw new Error(`No commands found under \"${currentPath}\".`);\n }\n\n const createAction = createCommandActionFunction({ cwd, reporter, abortController });\n\n for (const commandPath of commands) {\n const commandFunction = (await import(pathToFileURL(path.join(currentPath, commandPath)).toString())) as {\n init: CommandFunction;\n };\n\n commandFunction.init(program, createAction);\n }\n\n program.option('-v, --verbose', 'Show additional details about the running tasks. (default: false)');\n program.option('-d, --debug', 'Show debug information (superset of --verbose). (default: false)');\n program.option('-n, --no-color', 'Disable colors in the output. (default: false)');\n\n testOptions?.preParseOverrides?.(program);\n\n await program.parseAsync(argv);\n\n if (program.args.length === 0) {\n program.help();\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,MAAM,eAAe,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvD,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,WAK1B;IACC,WAAW,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAErC,MAAM,IAAI,GAAG,WAAW,EAAE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAC/C,MAA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AAM,CAAC,gBAAgB,EAAE,gDAAgD,CAAC,CAAC;IAEnF,WAAW,EAAE,iBAAiB,EAAE,CAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAE/B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7B,OAAO,CAAC,IAAI,EAAE,CAAC;KAChB;AACH,CAAC","sourcesContent":["import { getVersion } from '@ms-cloudpack/package-utilities';\nimport { Command } from 'commander';\nimport glob from 'glob';\nimport path from 'path';\nimport { fileURLToPath, pathToFileURL } from 'url';\nimport { PerfMarkerCliEntry } from './performance/markers.js';\nimport type { CommandFunction } from './types/CommandFunction.js';\nimport { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { createCommandActionFunction } from './common/createCommandActionFunction.js';\nimport { dynamicImportExtension } from './utilities/dynamicImportExtension.js';\n\nconst currentFilePath = fileURLToPath(import.meta.url);\nconst currentPath = path.dirname(currentFilePath);\n\n/**\n * Entry point for the cloudpack CLI.\n * Resolves all commands defined within the \"./commands\" folder.\n */\nexport async function main(testOptions?: {\n appPath: string;\n argv: string[];\n reporter: TaskReporter;\n preParseOverrides?: (program: Command) => void;\n}) {\n performance.mark(PerfMarkerCliEntry);\n\n const argv = testOptions?.argv || process.argv;\n const cwd = testOptions?.appPath || process.cwd();\n const reporter = testOptions?.reporter || new TaskReporter();\n\n const abortController = new AbortController();\n\n const program = new Command();\n const version = getVersion(import.meta.url);\n\n program.name('cloudpack').version(version).usage('<command> [options]');\n\n // Ensure the glob works in tests\n const commandsGlob = `commands/*/index${dynamicImportExtension}`;\n const commands = glob.sync(commandsGlob, { cwd: currentPath });\n if (!commands.length) {\n // There was an issue with the glob above not working in tests, so make sure that doesn't happen again\n throw new Error(`No commands found under \"${currentPath}\".`);\n }\n\n const createAction = createCommandActionFunction({ cwd, reporter, abortController });\n\n for (const commandPath of commands) {\n const commandFunction = (await import(pathToFileURL(path.join(currentPath, commandPath)).toString())) as {\n init: CommandFunction;\n };\n\n commandFunction.init(program, createAction);\n }\n\n program.option('-v, --verbose', 'Show additional details about the running tasks. (default: false)');\n program.option('-d, --debug', 'Show debug information (superset of --verbose). (default: false)');\n program.option('-n, --no-color', 'Disable colors in the output. (default: false)');\n\n testOptions?.preParseOverrides?.(program);\n\n await program.parseAsync(argv);\n\n if (program.args.length === 0) {\n program.help();\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Correct file extension (`.js` or `.ts`) depending on the context the code is running in:
3
+ * compiled (`.js`) or Jest test in this package (`.ts`).
4
+ */
5
+ export declare const dynamicImportExtension: string;
6
+ //# sourceMappingURL=dynamicImportExtension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamicImportExtension.d.ts","sourceRoot":"","sources":["../../src/utilities/dynamicImportExtension.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,sBAAsB,QAA+C,CAAC"}
@@ -0,0 +1,8 @@
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ /**
4
+ * Correct file extension (`.js` or `.ts`) depending on the context the code is running in:
5
+ * compiled (`.js`) or Jest test in this package (`.ts`).
6
+ */
7
+ export const dynamicImportExtension = path.extname(fileURLToPath(import.meta.url));
8
+ //# sourceMappingURL=dynamicImportExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamicImportExtension.js","sourceRoot":"","sources":["../../src/utilities/dynamicImportExtension.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\n\n/**\n * Correct file extension (`.js` or `.ts`) depending on the context the code is running in:\n * compiled (`.js`) or Jest test in this package (`.ts`).\n */\nexport const dynamicImportExtension = path.extname(fileURLToPath(import.meta.url));\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/cli",
3
- "version": "0.47.5",
3
+ "version": "0.47.7",
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,14 +11,14 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@lage-run/target-graph": "^0.8.7",
14
- "@ms-cloudpack/api-server": "^0.19.1",
15
- "@ms-cloudpack/config": "^0.12.5",
16
- "@ms-cloudpack/create-express-app": "^1.3.9",
14
+ "@ms-cloudpack/api-server": "^0.20.0",
15
+ "@ms-cloudpack/config": "^0.12.6",
16
+ "@ms-cloudpack/create-express-app": "^1.3.10",
17
17
  "@ms-cloudpack/json-utilities": "^0.0.7",
18
- "@ms-cloudpack/overlay": "^0.14.23",
19
- "@ms-cloudpack/package-utilities": "^5.1.7",
20
- "@ms-cloudpack/path-string-parsing": "^1.0.3",
21
- "@ms-cloudpack/path-utilities": "^2.3.2",
18
+ "@ms-cloudpack/overlay": "^0.15.1",
19
+ "@ms-cloudpack/package-utilities": "^5.1.8",
20
+ "@ms-cloudpack/path-string-parsing": "^1.1.0",
21
+ "@ms-cloudpack/path-utilities": "^2.3.3",
22
22
  "@ms-cloudpack/task-reporter": "^0.8.0",
23
23
  "@ms-cloudpack/telemetry": "^0.3.8",
24
24
  "commander": "^11.0.0",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=cloudpackWindowVariable.inline.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloudpackWindowVariable.inline.d.ts","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/cloudpackWindowVariable.inline.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- import { getPageLoadTime } from './getPageLoadTime.js';
2
- import { getBrowserCacheRatio } from './getBrowserCacheRatio.js';
3
- window.__cloudpack = {
4
- getBrowserCacheRatio,
5
- getPageLoadTime,
6
- };
7
- //# sourceMappingURL=cloudpackWindowVariable.inline.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cloudpackWindowVariable.inline.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/cloudpackWindowVariable.inline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,WAAW,GAAG;IACnB,oBAAoB;IACpB,eAAe;CAChB,CAAC","sourcesContent":["import { getPageLoadTime } from './getPageLoadTime.js';\nimport { getBrowserCacheRatio } from './getBrowserCacheRatio.js';\n\nwindow.__cloudpack = {\n getBrowserCacheRatio,\n getPageLoadTime,\n};\n"]}
@@ -1,2 +0,0 @@
1
- export declare function getBrowserCacheRatio(): number;
2
- //# sourceMappingURL=getBrowserCacheRatio.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBrowserCacheRatio.d.ts","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getBrowserCacheRatio.ts"],"names":[],"mappings":"AA0CA,wBAAgB,oBAAoB,WAKnC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBrowserCacheRatio.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getBrowserCacheRatio.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAwC,EAAE,CAAC;AAElE,SAAS,SAAS,CAAC,KAAa;IAC9B,MAAM,cAAc,GAAG,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MA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,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAE3D,MAAM,UAAU,oBAAoB;IAClC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,MAAM,CAAC;IACjG,MAAM,KAAK,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC;IAEjE,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["const scriptLoadResults: Record<string, 'cache' | 'network'> = {};\n\nfunction getCookie(cname: string) {\n const decodedCookies = decodeURIComponent(document.cookie);\n const cookies = decodedCookies.split(';');\n const keyValues = cookies.map((cookie) => cookie.split('='));\n const cookie = keyValues.find(([key]) => key === cname);\n if (!cookie) {\n throw new Error(`Cookie ${cname} not found`);\n }\n\n const value = cookie[1].trim();\n\n return value;\n}\n\nconst bundleServerUrl = getCookie('cloudpack-bundle-server-url');\n\nfunction isPerformanceResourceTiming(entry: PerformanceEntry): entry is PerformanceResourceTiming {\n return entry.entryType === 'resource';\n}\n\nfunction handlePerformanceEntry(item: PerformanceEntry) {\n if (isPerformanceResourceTiming(item) && item.name.startsWith(bundleServerUrl)) {\n scriptLoadResults[item.name] = item.transferSize === 0 ? 'cache' : 'network';\n }\n}\n\nconst perfObserver = new PerformanceObserver((list) => {\n for (const item of list.getEntries()) {\n handlePerformanceEntry(item);\n }\n});\n\n// Get all the resources that were loaded before this script\nfor (const entry of performance.getEntriesByType('resource')) {\n handlePerformanceEntry(entry);\n}\n\n// Observe all resources that are loaded after this script\nperfObserver.observe({ type: 'resource', buffered: true });\n\nexport function getBrowserCacheRatio() {\n const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;\n const ratio = cacheCount / Object.keys(scriptLoadResults).length;\n\n return ratio;\n}\n"]}
@@ -1,2 +0,0 @@
1
- export declare function getPageLoadTime(): Promise<number>;
2
- //# sourceMappingURL=getPageLoadTime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPageLoadTime.d.ts","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getPageLoadTime.ts"],"names":[],"mappings":"AA+EA,wBAAgB,eAAe,oBAE9B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPageLoadTime.js","sourceRoot":"","sources":["../../../../../src/commands/start/appServer/inlineScripts/getPageLoadTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;GAGG;AACH,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,8DAA8D;AAC9D,MAAM,WAAW,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAIvC,SAAS,QAAQ,CAAsB,IAAqB,EAAE,IAAY;IACxE,IAAI,OAA6C,CAAC;IAElD,OAAO,UAAU,GAAG,IAAO;QACzB,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAChB,CAAC,CAAC;QAEF,IAAI,OAAO,EAAE;YACX,YAAY,CAAC,OAAO,CAAC,CAAC;SACvB;QACD,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,QAAwB;IAC3D,OAAO,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,MAAM,EAAE,GAAI,IAAwB,CAAC,EAAE,CAAC;QAExC,IAAI,EAAE,EAAE;YACN,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;SAClC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,mBAAmB,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;IAC1D,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAElD,SAAS,uBAAuB,CAAC,IAAY;QAC3C,yBAAyB;QACzB,QAAQ,CAAC,UAAU,EAAE,CAAC;QAEtB,8CAA8C;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,MAAM,gCAAgC,GAAG,QAAQ,CAAC,uBAAuB,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAE/F,SAAS,UAAU,CAAC,SAA2B;QAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAE/E,IAAI,aAAa,EAAE;YACjB,qBAAqB,CAAC,GAAG,EAAE;gBACzB,kFAAkF;gBAClF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBAE/B,uBAAuB;gBACvB,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;gBAEvC,0BAA0B;gBAC1B,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAEjC,4BAA4B;gBAC5B,gCAAgC,CAAC,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE;QAC9B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,eAAe;IAC7B,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import { overlayRootDivId } from '@ms-cloudpack/overlay';\n\n/**\n * Performance mark name for page load time.\n * This makes it easier to see the page load time in the performance tab in dev tools\n */\nconst pageLoadMarker = 'CLOUDPACK_PAGE_LOAD_TIME';\n\n// The below dom elements will be ignored by mutation observer\nconst excludedIds = [overlayRootDivId];\n\ntype DebounceFunc<T extends unknown[]> = (...args: T) => void;\n\nfunction debounce<T extends unknown[]>(func: DebounceFunc<T>, wait: number): DebounceFunc<T> {\n let timeout: ReturnType<typeof setTimeout> | null;\n\n return function (...args: T) {\n const later = () => {\n timeout = null;\n func(...args);\n };\n\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(later, wait);\n };\n}\n\nfunction hasMutationNonExcludedNodes(mutation: MutationRecord) {\n return [...mutation.addedNodes].some((node) => {\n const id = (node as { id?: string }).id;\n\n if (id) {\n return !excludedIds.includes(id);\n }\n\n return true;\n });\n}\n\nconst pageLoadTimePromise = new Promise<number>((resolve) => {\n const observer = new MutationObserver(domChanged);\n\n function reportLastAnimationTime(time: number) {\n // Stop observing the DOM\n observer.disconnect();\n\n // Resolve the promise with the page load time\n resolve(time);\n }\n\n const debouncedReportLastAnimationTime = debounce(reportLastAnimationTime, 2000 /* wait ms */);\n\n function domChanged(mutations: MutationRecord[]) {\n const shouldProcess = mutations.filter(hasMutationNonExcludedNodes).length > 0;\n\n if (shouldProcess) {\n requestAnimationFrame(() => {\n // Get the current time in ms since the time when navigation has started in window\n const time = performance.now();\n\n // Clear previous marks\n performance.clearMarks(pageLoadMarker);\n\n // Mark the page load time\n performance.mark(pageLoadMarker);\n\n // Report the page load time\n debouncedReportLastAnimationTime(time);\n });\n }\n }\n\n observer.observe(document.body, {\n childList: true,\n });\n});\n\nexport function getPageLoadTime() {\n return pageLoadTimePromise;\n}\n"]}