@ms-cloudpack/api-server 0.5.15 → 0.5.17

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 (102) hide show
  1. package/lib/TaskRunner.d.ts +2 -1
  2. package/lib/TaskRunner.d.ts.map +1 -1
  3. package/lib/TaskRunner.js.map +1 -1
  4. package/lib/TaskScheduler.d.ts +1 -1
  5. package/lib/TaskScheduler.d.ts.map +1 -1
  6. package/lib/TaskScheduler.js.map +1 -1
  7. package/lib/addOverride.d.ts +1 -1
  8. package/lib/addOverride.d.ts.map +1 -1
  9. package/lib/addOverride.js.map +1 -1
  10. package/lib/common/findPackageOverride.d.ts +1 -1
  11. package/lib/common/findPackageOverride.d.ts.map +1 -1
  12. package/lib/common/findPackageOverride.js.map +1 -1
  13. package/lib/index.d.ts +11 -1
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.js.map +1 -1
  16. package/lib/startApiServer.d.ts +2 -1
  17. package/lib/startApiServer.d.ts.map +1 -1
  18. package/lib/startApiServer.js.map +1 -1
  19. package/lib/startWatcher.d.ts +2 -1
  20. package/lib/startWatcher.d.ts.map +1 -1
  21. package/lib/startWatcher.js.map +1 -1
  22. package/lib/tsdoc-metadata.json +11 -11
  23. package/lib/types/ApiServer.d.ts +14 -0
  24. package/lib/types/ApiServer.d.ts.map +1 -0
  25. package/lib/types/ApiServer.js +2 -0
  26. package/lib/types/ApiServer.js.map +1 -0
  27. package/lib/types/BundleRequest.d.ts +10 -0
  28. package/lib/types/BundleRequest.d.ts.map +1 -0
  29. package/lib/types/BundleRequest.js +2 -0
  30. package/lib/types/BundleRequest.js.map +1 -0
  31. package/lib/types/CreateHtmlFunction.d.ts +7 -0
  32. package/lib/types/CreateHtmlFunction.d.ts.map +1 -0
  33. package/lib/types/CreateHtmlFunction.js +2 -0
  34. package/lib/types/CreateHtmlFunction.js.map +1 -0
  35. package/lib/types/CreateHtmlOptions.d.ts +18 -0
  36. package/lib/types/CreateHtmlOptions.d.ts.map +1 -0
  37. package/lib/types/CreateHtmlOptions.js +2 -0
  38. package/lib/types/CreateHtmlOptions.js.map +1 -0
  39. package/lib/types/CreateHtmlResult.d.ts +8 -0
  40. package/lib/types/CreateHtmlResult.d.ts.map +1 -0
  41. package/lib/types/CreateHtmlResult.js +5 -0
  42. package/lib/types/CreateHtmlResult.js.map +1 -0
  43. package/lib/types/CreateHtmlScript.d.ts +8 -0
  44. package/lib/types/CreateHtmlScript.d.ts.map +1 -0
  45. package/lib/types/CreateHtmlScript.js +2 -0
  46. package/lib/types/CreateHtmlScript.js.map +1 -0
  47. package/lib/types/DevServer.d.ts +33 -0
  48. package/lib/types/DevServer.d.ts.map +1 -0
  49. package/lib/types/DevServer.js +2 -0
  50. package/lib/types/DevServer.js.map +1 -0
  51. package/lib/types/PackageOverride.d.ts +8 -0
  52. package/lib/types/PackageOverride.d.ts.map +1 -0
  53. package/lib/types/PackageOverride.js +2 -0
  54. package/lib/types/PackageOverride.js.map +1 -0
  55. package/lib/types/Route.d.ts +23 -0
  56. package/lib/types/Route.d.ts.map +1 -0
  57. package/lib/types/Route.js +2 -0
  58. package/lib/types/Route.js.map +1 -0
  59. package/lib/types/Session.d.ts +70 -0
  60. package/lib/types/Session.d.ts.map +1 -0
  61. package/lib/types/Session.js +2 -0
  62. package/lib/types/Session.js.map +1 -0
  63. package/lib/types/SessionStats.d.ts +8 -0
  64. package/lib/types/SessionStats.d.ts.map +1 -0
  65. package/lib/types/SessionStats.js +2 -0
  66. package/lib/types/SessionStats.js.map +1 -0
  67. package/lib/types/Task.d.ts +17 -0
  68. package/lib/types/Task.d.ts.map +1 -0
  69. package/lib/types/Task.js +2 -0
  70. package/lib/types/Task.js.map +1 -0
  71. package/lib/types/TaskDescription.d.ts +9 -0
  72. package/lib/types/TaskDescription.d.ts.map +1 -0
  73. package/lib/types/TaskDescription.js +2 -0
  74. package/lib/types/TaskDescription.js.map +1 -0
  75. package/lib/types/TaskEndDescription.d.ts +7 -0
  76. package/lib/types/TaskEndDescription.d.ts.map +1 -0
  77. package/lib/types/TaskEndDescription.js +2 -0
  78. package/lib/types/TaskEndDescription.js.map +1 -0
  79. package/lib/types/TaskError.d.ts +9 -0
  80. package/lib/types/TaskError.d.ts.map +1 -0
  81. package/lib/types/TaskError.js +2 -0
  82. package/lib/types/TaskError.js.map +1 -0
  83. package/lib/types/TaskOptions.d.ts +5 -0
  84. package/lib/types/TaskOptions.d.ts.map +1 -0
  85. package/lib/types/TaskOptions.js +2 -0
  86. package/lib/types/TaskOptions.js.map +1 -0
  87. package/lib/types/TaskStartDescription.d.ts +7 -0
  88. package/lib/types/TaskStartDescription.d.ts.map +1 -0
  89. package/lib/types/TaskStartDescription.js +2 -0
  90. package/lib/types/TaskStartDescription.js.map +1 -0
  91. package/lib/types/TelemetryConfig.d.ts +7 -0
  92. package/lib/types/TelemetryConfig.d.ts.map +1 -0
  93. package/lib/types/TelemetryConfig.js +2 -0
  94. package/lib/types/TelemetryConfig.js.map +1 -0
  95. package/lib/validateOverride.d.ts +1 -1
  96. package/lib/validateOverride.d.ts.map +1 -1
  97. package/lib/validateOverride.js.map +1 -1
  98. package/package.json +4 -5
  99. package/lib/types.d.ts +0 -234
  100. package/lib/types.d.ts.map +0 -1
  101. package/lib/types.js +0 -2
  102. package/lib/types.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import type { Task, TaskOptions } from './types.js';
1
+ import type { TaskOptions } from './types/TaskOptions.js';
2
+ import type { Task } from './types/Task.js';
2
3
  /**
3
4
  * TaskRunner class manages the state of Tasks.
4
5
  * This class is to be called by the api server.
@@ -1 +1 @@
1
- {"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../src/TaskRunner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAOpD;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;;IAU3C;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAoE1E;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS5C;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAYzB"}
1
+ {"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../src/TaskRunner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAO5C;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;;IAU3C;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAoE1E;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS5C;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAYzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../src/TaskRunner.ts"],"names":[],"mappings":"AAAA,OAAO,MAA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eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAEhC,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAU,EAAU;QACvB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChB,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;SAC1C;QACD,OAAyB,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAU;QACf,IAAI,CAAC,UAAU;aACZ,GAAG,CAAC,EAAE,CAAC;YACR,EAAE,OAAO,EAAE,EAAE;aACZ,KAAK,CAAC,GAAG,EAAE;YACV,GAAG,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACL,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACnC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;CACF","sourcesContent":["import PQueue from 'p-queue';\nimport type { Task, TaskOptions } from './types.js';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst log = (...messages: unknown[]) => {\n // console.log(`TaskRunner:`, ...messages);\n};\n\n/**\n * TaskRunner class manages the state of Tasks.\n * This class is to be called by the api server.\n */\nexport class TaskRunner {\n private _queue: PQueue;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _pendingTasks: Map<string, Promise<any>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _completedTasks: Map<string, any>;\n private _requiresRerun: Set<string>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _prevTasks: Map<string, Task<any>>;\n\n constructor() {\n this._queue = new PQueue({ concurrency: 10 });\n this._pendingTasks = new Map();\n this._completedTasks = new Map();\n this._requiresRerun = new Set();\n this._prevTasks = new Map();\n }\n\n /**\n * The add method enqueues a Task and returns its Promise.\n * If a Task with the same id has already been processed,\n * it returns either the result or the promise.\n * Rerun flag forces the Task to be run again.\n */\n add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn> {\n const { name, id, execute } = task;\n const { rerun, watch } = options || {};\n\n watch?.();\n\n if (!this._prevTasks.get(id)) {\n this._prevTasks.set(id, task);\n }\n\n // Check if we are already completed the task with that id.\n const action = this._completedTasks.get(id) as TReturn | undefined;\n if (action !== undefined && !rerun) {\n log(`Previous action found, returning: \"${name}:${id}\"`);\n return Promise.resolve(action);\n }\n\n // Check if we are already running the task with that id.\n const pending = this._pendingTasks.get(id) as Promise<TReturn> | undefined;\n if (pending !== undefined) {\n if (rerun) {\n this._requiresRerun.add(id);\n }\n log(`Previous action found, waiting: \"${name}:${id}\"`);\n return pending;\n }\n\n const resultPromise = (async () => {\n let taskResult: TReturn | undefined;\n let taskError: unknown;\n let completed = false;\n\n do {\n // Delete from rerun list (if present).\n this._requiresRerun.delete(id);\n try {\n // TODO: possibly remove cast once this issue is resolved\n // https://github.com/sindresorhus/p-queue/issues/175\n taskResult = (await this._queue.add(execute)) as TReturn | undefined;\n completed = true;\n } catch (err) {\n // Save the error--it will be thrown later if a rerun was not requested.\n taskError = err;\n }\n } while (this._requiresRerun.has(id));\n\n log(`Task finished: \"${name}:${id}\"`);\n\n // Delete from pending list.\n this._pendingTasks.delete(id);\n\n if (completed) {\n // Update finished Tasks.\n this._completedTasks.set(id, taskResult);\n // Resolve the promise.\n return taskResult as TReturn;\n }\n\n // If the task never completed successfully, throw the error from earlier.\n throw taskError;\n })();\n\n this._pendingTasks.set(id, resultPromise);\n this._completedTasks.delete(id);\n\n return resultPromise;\n }\n\n /**\n * The reset method removes a task from the TaskRunner\n * and then adds it again through a previous execute function.\n *\n * This is useful for when a task needs to be forcibly rerun.\n *\n * It is intented to be used by the api server\n * to rerun a task when it is stuck or it failed.\n */\n reset<TReturn>(id: string): Promise<TReturn> {\n this.remove(id);\n const prevTask = this._prevTasks.get(id);\n if (prevTask === undefined) {\n throw new Error(`Task not found: ${id}`);\n }\n return <Promise<TReturn>>this.add(prevTask, { rerun: true });\n }\n\n /**\n * The remove method disposes a task if available\n * and then removes it from the TaskRunner.\n *\n * This is useful when the state of a task needs to be cleared.\n *\n * It is intented to be used by the api server\n * to clear the TaskRunner's state before reloading the page.\n */\n remove(id: string): void {\n this._prevTasks\n .get(id)\n ?.dispose?.()\n .catch(() => {\n log(`Error disposing task: ${id}`);\n });\n this._prevTasks.get(id)?.clear?.();\n this._requiresRerun.delete(id);\n this._pendingTasks.delete(id);\n this._completedTasks.delete(id);\n }\n}\n"]}
1
+ {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../src/TaskRunner.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAI7B,6DAA6D;AAC7D,MAAM,GAAG,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE;IACrC,2CAA2C;AAC7C,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,UAAU;IAUrB;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,GAA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/D,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAU;QACf,IAAI,CAAC,UAAU;aACZ,GAAG,CAAC,EAAE,CAAC;YACR,EAAE,OAAO,EAAE,EAAE;aACZ,KAAK,CAAC,GAAG,EAAE;YACV,GAAG,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACL,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACnC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;CACF","sourcesContent":["import PQueue from 'p-queue';\nimport type { TaskOptions } from './types/TaskOptions.js';\nimport type { Task } from './types/Task.js';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst log = (...messages: unknown[]) => {\n // console.log(`TaskRunner:`, ...messages);\n};\n\n/**\n * TaskRunner class manages the state of Tasks.\n * This class is to be called by the api server.\n */\nexport class TaskRunner {\n private _queue: PQueue;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _pendingTasks: Map<string, Promise<any>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _completedTasks: Map<string, any>;\n private _requiresRerun: Set<string>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _prevTasks: Map<string, Task<any>>;\n\n constructor() {\n this._queue = new PQueue({ concurrency: 10 });\n this._pendingTasks = new Map();\n this._completedTasks = new Map();\n this._requiresRerun = new Set();\n this._prevTasks = new Map();\n }\n\n /**\n * The add method enqueues a Task and returns its Promise.\n * If a Task with the same id has already been processed,\n * it returns either the result or the promise.\n * Rerun flag forces the Task to be run again.\n */\n add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn> {\n const { name, id, execute } = task;\n const { rerun, watch } = options || {};\n\n watch?.();\n\n if (!this._prevTasks.get(id)) {\n this._prevTasks.set(id, task);\n }\n\n // Check if we are already completed the task with that id.\n const action = this._completedTasks.get(id) as TReturn | undefined;\n if (action !== undefined && !rerun) {\n log(`Previous action found, returning: \"${name}:${id}\"`);\n return Promise.resolve(action);\n }\n\n // Check if we are already running the task with that id.\n const pending = this._pendingTasks.get(id) as Promise<TReturn> | undefined;\n if (pending !== undefined) {\n if (rerun) {\n this._requiresRerun.add(id);\n }\n log(`Previous action found, waiting: \"${name}:${id}\"`);\n return pending;\n }\n\n const resultPromise = (async () => {\n let taskResult: TReturn | undefined;\n let taskError: unknown;\n let completed = false;\n\n do {\n // Delete from rerun list (if present).\n this._requiresRerun.delete(id);\n try {\n // TODO: possibly remove cast once this issue is resolved\n // https://github.com/sindresorhus/p-queue/issues/175\n taskResult = (await this._queue.add(execute)) as TReturn | undefined;\n completed = true;\n } catch (err) {\n // Save the error--it will be thrown later if a rerun was not requested.\n taskError = err;\n }\n } while (this._requiresRerun.has(id));\n\n log(`Task finished: \"${name}:${id}\"`);\n\n // Delete from pending list.\n this._pendingTasks.delete(id);\n\n if (completed) {\n // Update finished Tasks.\n this._completedTasks.set(id, taskResult);\n // Resolve the promise.\n return taskResult as TReturn;\n }\n\n // If the task never completed successfully, throw the error from earlier.\n throw taskError;\n })();\n\n this._pendingTasks.set(id, resultPromise);\n this._completedTasks.delete(id);\n\n return resultPromise;\n }\n\n /**\n * The reset method removes a task from the TaskRunner\n * and then adds it again through a previous execute function.\n *\n * This is useful for when a task needs to be forcibly rerun.\n *\n * It is intented to be used by the api server\n * to rerun a task when it is stuck or it failed.\n */\n reset<TReturn>(id: string): Promise<TReturn> {\n this.remove(id);\n const prevTask = this._prevTasks.get(id);\n if (prevTask === undefined) {\n throw new Error(`Task not found: ${id}`);\n }\n return <Promise<TReturn>>this.add(prevTask, { rerun: true });\n }\n\n /**\n * The remove method disposes a task if available\n * and then removes it from the TaskRunner.\n *\n * This is useful when the state of a task needs to be cleared.\n *\n * It is intented to be used by the api server\n * to clear the TaskRunner's state before reloading the page.\n */\n remove(id: string): void {\n this._prevTasks\n .get(id)\n ?.dispose?.()\n .catch(() => {\n log(`Error disposing task: ${id}`);\n });\n this._prevTasks.get(id)?.clear?.();\n this._requiresRerun.delete(id);\n this._pendingTasks.delete(id);\n this._completedTasks.delete(id);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { BundleRequest } from './types.js';
1
+ import type { BundleRequest } from './types/BundleRequest.js';
2
2
  import type { TaskReporter } from '@ms-cloudpack/task-reporter';
3
3
  interface TaskSchedulerOptions {
4
4
  reporter: TaskReporter;
@@ -1 +1 @@
1
- {"version":3,"file":"TaskScheduler.d.ts","sourceRoot":"","sources":["../src/TaskScheduler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,6BAA6B,CAAC;AAKlF,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,aAAa;;gBAMZ,OAAO,EAAE,oBAAoB;IAgGnC,YAAY,CAAC,CAAC,SAAS,aAAa,EACxC,aAAa,EAAE,CAAC,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAiCJ"}
1
+ {"version":3,"file":"TaskScheduler.d.ts","sourceRoot":"","sources":["../src/TaskScheduler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,6BAA6B,CAAC;AAKlF,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,aAAa;;gBAMZ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CAAC,WAAW,CAAC;QACtC,MAAM,MAAM,GAAW;YACrB,EAAE,EAAE,aAAa,CAAC,EAAE;YACpB,KAAK,EAAE,GAAG,aAAa,CAAC,WAAW,SAAS;YAC5C,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,QAAQ;YACd,GAAG,EAAE,aAAa,CAAC,WAAW;YAC9B,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE;gBACP,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;gBAC5B,aAAa;aACd;SACF,CAAC;QAEF,uBAAA,IAAI,yCAAoB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAE3C,MAAM,KAAK,GAAG,uBAAA,IAAI,yCAAoB,CAAC,KAAK,EAAE,CAAC;QAE/C,IAAI;YACF,MAAM,uBAAA,IAAI,gCAAW,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;SACtD;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,YAAY,KAAK,EAAE;gBACtB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;aACxB;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1B;SACF;IACH,CAAC;CACF","sourcesContent":["import { Logger, LogLevel } from '@lage-run/logger';\nimport scheduler from '@lage-run/scheduler';\nimport targetGraph, { type Target } from '@lage-run/target-graph';\nimport os from 'os';\nimport type { BundleRequest } from './types.js';\nimport type { TaskReporter, TaskReporterTask } from '@ms-cloudpack/task-reporter';\n\nimport { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\n\ninterface TaskSchedulerOptions {\n reporter: TaskReporter;\n}\n\n/**\n * A class to abstract the creation of the lage scheduler and scheduling tasks\n */\nexport class TaskScheduler {\n #scheduler: scheduler.SimpleScheduler;\n #targetGraphBuilder: targetGraph.TargetGraphBuilder;\n\n #reporterTasks = new Map<string, TaskReporterTask>();\n\n constructor(options: TaskSchedulerOptions) {\n const { reporter } = options;\n const logger = new Logger();\n\n const reporterTasks = this.#reporterTasks;\n\n logger.addReporter({\n log(entry) {\n if (entry.msg && entry.level <= LogLevel.warn && entry.data?.target) {\n const target = entry.data?.target as Target;\n if (reporterTasks.has(target.id)) {\n reporterTasks.get(target.id)!.message += entry.msg;\n }\n return;\n }\n\n if (entry.data && entry.data.status) {\n const { status } = entry.data;\n const target = entry.data.target as Target;\n\n // Ensure task is in the reporterTasks map\n const task = reporterTasks.has(target.id)\n ? reporterTasks.get(target.id)!\n : reporter.addTask(target.label, true);\n\n reporterTasks.set(target.id, task);\n\n switch (status) {\n case 'running':\n task.start();\n break;\n\n case 'success':\n task.complete({ status: 'complete' });\n break;\n\n case 'skipped':\n task.complete({ status: 'skip' });\n break;\n\n case 'failed':\n task.complete({ status: 'fail' });\n break;\n\n case 'aborted':\n task.complete({ status: 'abort' });\n break;\n }\n return;\n }\n\n if (entry.msg) {\n const logLevelToConsoleFnMap = {\n [LogLevel.error]: console.error,\n [LogLevel.warn]: console.warn,\n [LogLevel.info]: console.info,\n [LogLevel.verbose]: console.debug,\n [LogLevel.silly]: console.debug,\n };\n\n logLevelToConsoleFnMap[entry.level](entry.msg);\n return;\n }\n },\n\n summarize() {\n // noop\n },\n });\n\n const runners = {\n worker: {\n script: require.resolve('@lage-run/scheduler/lib/runners/WorkerRunner.js'),\n options: {},\n },\n noop: {\n script: require.resolve('@lage-run/scheduler/lib/runners/NoOpRunner.js'),\n options: {},\n },\n };\n\n this.#targetGraphBuilder = new targetGraph.TargetGraphBuilder();\n this.#scheduler = new scheduler.SimpleScheduler({\n concurrency: 10,\n continueOnError: true,\n logger,\n maxWorkersPerTask: new Map(),\n runners,\n shouldCache: true,\n shouldResetCache: false,\n workerIdleMemoryLimit: os.totalmem(),\n });\n }\n\n // Schedules task to be run according to the bundle request that came through from the bundler server\n // TODO: from a bundle request, we should be able to determine if we need to auto add several targets into the graph\n async scheduleTask<T extends BundleRequest>(\n bundleRequest: T,\n scripts: Record<string, string>,\n options: {\n rerun?: boolean;\n },\n ) {\n const cwd = bundleRequest.packagePath;\n const target: Target = {\n id: bundleRequest.id,\n label: `${bundleRequest.packageName} bundle`,\n task: 'bundle',\n type: 'worker',\n cwd: bundleRequest.packagePath,\n dependencies: [],\n dependents: [],\n depSpecs: [],\n options: {\n script: scripts.bundle ?? '',\n bundleRequest,\n },\n };\n\n this.#targetGraphBuilder.addTarget(target);\n\n const graph = this.#targetGraphBuilder.build();\n\n try {\n await this.#scheduler.run(cwd, graph, options.rerun);\n } catch (e) {\n if (e instanceof Error) {\n console.error(e.message);\n console.error(e.stack);\n } else {\n console.error(String(e));\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"TaskScheduler.js","sourceRoot":"","sources":["../src/TaskScheduler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,WAAW,EAAE,EAAe,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAM/C;;GAEG;AACH,MAAM,OAAO,aAAa;IAMxB,YAAY,OAA6B;QALzC,2CAAsC;QACtC,oDAAoD;QAEpD,uCAAiB,IAAI,GAAG,EAA4B,EAAC;QAGnD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QAE5B,MAAM,aAAa,GAAG,uBAAA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AC,CAAC;aAC1B;SACF;IACH,CAAC;CACF","sourcesContent":["import { Logger, LogLevel } from '@lage-run/logger';\nimport scheduler from '@lage-run/scheduler';\nimport targetGraph, { type Target } from '@lage-run/target-graph';\nimport os from 'os';\nimport type { BundleRequest } from './types/BundleRequest.js';\nimport type { TaskReporter, TaskReporterTask } from '@ms-cloudpack/task-reporter';\n\nimport { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\n\ninterface TaskSchedulerOptions {\n reporter: TaskReporter;\n}\n\n/**\n * A class to abstract the creation of the lage scheduler and scheduling tasks\n */\nexport class TaskScheduler {\n #scheduler: scheduler.SimpleScheduler;\n #targetGraphBuilder: targetGraph.TargetGraphBuilder;\n\n #reporterTasks = new Map<string, TaskReporterTask>();\n\n constructor(options: TaskSchedulerOptions) {\n const { reporter } = options;\n const logger = new Logger();\n\n const reporterTasks = this.#reporterTasks;\n\n logger.addReporter({\n log(entry) {\n if (entry.msg && entry.level <= LogLevel.warn && entry.data?.target) {\n const target = entry.data?.target as Target;\n if (reporterTasks.has(target.id)) {\n reporterTasks.get(target.id)!.message += entry.msg;\n }\n return;\n }\n\n if (entry.data && entry.data.status) {\n const { status } = entry.data;\n const target = entry.data.target as Target;\n\n // Ensure task is in the reporterTasks map\n const task = reporterTasks.has(target.id)\n ? reporterTasks.get(target.id)!\n : reporter.addTask(target.label, true);\n\n reporterTasks.set(target.id, task);\n\n switch (status) {\n case 'running':\n task.start();\n break;\n\n case 'success':\n task.complete({ status: 'complete' });\n break;\n\n case 'skipped':\n task.complete({ status: 'skip' });\n break;\n\n case 'failed':\n task.complete({ status: 'fail' });\n break;\n\n case 'aborted':\n task.complete({ status: 'abort' });\n break;\n }\n return;\n }\n\n if (entry.msg) {\n const logLevelToConsoleFnMap = {\n [LogLevel.error]: console.error,\n [LogLevel.warn]: console.warn,\n [LogLevel.info]: console.info,\n [LogLevel.verbose]: console.debug,\n [LogLevel.silly]: console.debug,\n };\n\n logLevelToConsoleFnMap[entry.level](entry.msg);\n return;\n }\n },\n\n summarize() {\n // noop\n },\n });\n\n const runners = {\n worker: {\n script: require.resolve('@lage-run/scheduler/lib/runners/WorkerRunner.js'),\n options: {},\n },\n noop: {\n script: require.resolve('@lage-run/scheduler/lib/runners/NoOpRunner.js'),\n options: {},\n },\n };\n\n this.#targetGraphBuilder = new targetGraph.TargetGraphBuilder();\n this.#scheduler = new scheduler.SimpleScheduler({\n concurrency: 10,\n continueOnError: true,\n logger,\n maxWorkersPerTask: new Map(),\n runners,\n shouldCache: true,\n shouldResetCache: false,\n workerIdleMemoryLimit: os.totalmem(),\n });\n }\n\n // Schedules task to be run according to the bundle request that came through from the bundler server\n // TODO: from a bundle request, we should be able to determine if we need to auto add several targets into the graph\n async scheduleTask<T extends BundleRequest>(\n bundleRequest: T,\n scripts: Record<string, string>,\n options: {\n rerun?: boolean;\n },\n ) {\n const cwd = bundleRequest.packagePath;\n const target: Target = {\n id: bundleRequest.id,\n label: `${bundleRequest.packageName} bundle`,\n task: 'bundle',\n type: 'worker',\n cwd: bundleRequest.packagePath,\n dependencies: [],\n dependents: [],\n depSpecs: [],\n options: {\n script: scripts.bundle ?? '',\n bundleRequest,\n },\n };\n\n this.#targetGraphBuilder.addTarget(target);\n\n const graph = this.#targetGraphBuilder.build();\n\n try {\n await this.#scheduler.run(cwd, graph, options.rerun);\n } catch (e) {\n if (e instanceof Error) {\n console.error(e.message);\n console.error(e.stack);\n } else {\n console.error(String(e));\n }\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Session } from './types.js';
1
+ import type { Session } from './types/Session.js';
2
2
  /**
3
3
  * The addOverride method is triggered by a user action in the overlay, when we detect new usage of an import path
4
4
  * that isn't recognized. When the user trigers this override, we should write it to the cloudpack config, rather
@@ -1 +1 @@
1
- {"version":3,"file":"addOverride.d.ts","sourceRoot":"","sources":["../src/addOverride.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,YAAY,CAAC;AAO3D;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,GACT,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,iBAkEA"}
1
+ {"version":3,"file":"addOverride.d.ts","sourceRoot":"","sources":["../src/addOverride.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAOlD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,EAChC,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,GACT,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,iBAkEA"}
@@ -1 +1 @@
1
- {"version":3,"file":"addOverride.js","sourceRoot":"","sources":["../src/addOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAChC,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,GAMT;IACC,IAAI,UAAU,GAAG,SAAS,CAAC;IAE3B,IAAI,QAAQ,EAAE;QACZ,MA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;YACL,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SACxC;KACF,CAAC,gBAAgB;IAClB,MAAM,oBAAoB,CACxB;QACE,gBAAgB;KACjB,EACD,OAAO,CAAC,OAAO,CAChB,CAAC;IAEF,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,sBAAsB,CAAC,CAAC;IAEvE,MAAM,QAAQ,GAAoB;QAChC,gBAAgB,EAAE,CAAC,eAAe,CAAC;KACpC,CAAC;IAEF,gCAAgC;IAChC,kBAAkB,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC,8BAA8B,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["import { createPackageOverrideTransform } from './common/createPackageOverrideTransform.js';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n getExportsMap,\n PackageDefinitions,\n} from '@ms-cloudpack/package-utilities';\nimport type { Session, PackageOverride } from './types.js';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { parseRequestInfo } from './parseRequestInfo.js';\nimport { readConfig, writeGeneratedConfig } from '@ms-cloudpack/config';\nimport { findPackageOverride } from './common/findPackageOverride.js';\n\n/**\n * The addOverride method is triggered by a user action in the overlay, when we detect new usage of an import path\n * that isn't recognized. When the user trigers this override, we should write it to the cloudpack config, rather\n * than overrides which could get \"reset\" on `init --reset`.\n */\nexport async function addOverride({\n session,\n packageName,\n importPath,\n filename,\n}: {\n session: Session;\n packageName: string;\n importPath: string;\n filename?: string;\n}) {\n let definition = undefined;\n\n if (filename) {\n const requestPath = slash(new URL(filename).pathname);\n const { packageName: name, version } = parseRequestInfo(requestPath);\n definition = { name, version };\n }\n\n const entry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n definition,\n });\n\n if (entry === undefined) {\n console.error(`Could not find entry of package ${packageName} in resolve map`);\n return;\n }\n\n const exports = (await getExportsMap(entry.path)) as Record<string, Record<string, string>>;\n\n await addExportsMapEntry({\n exports,\n packagePath: entry.path,\n importPath,\n });\n\n const packageOverride: PackageOverride = {\n name: packageName,\n versionRequirement: `^${entry.version}`,\n overrides: {\n exports,\n },\n };\n\n // Parse config if it exists.\n const { packageOverrides = [] } = await readConfig(session.appPath);\n\n // Add package override to config.\n if (!packageOverrides.length) {\n packageOverrides.push(packageOverride);\n } else {\n const existingOverride = findPackageOverride(packageOverrides, packageName, entry.version);\n\n if (existingOverride) {\n existingOverride.overrides = packageOverride.overrides;\n } else {\n packageOverrides.push(packageOverride);\n }\n } // Write config.\n await writeGeneratedConfig(\n {\n packageOverrides,\n },\n session.appPath,\n );\n\n console.debug(`Added override for ${packageName} to cloudpack config`);\n\n const override: CloudpackConfig = {\n packageOverrides: [packageOverride],\n };\n\n // Initialize package overrides.\n PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(override));\n}\n"]}
1
+ {"version":3,"file":"addOverride.js","sourceRoot":"","sources":["../src/addOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAIzC,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAChC,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,GAMT;IACC,IAAI,UAAU,GAAG,SAAS,CAAC;IAE3B,IAAI,QAAQ,EAAE;QACZ,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,QA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gBAAgB;IAClB,MAAM,oBAAoB,CACxB;QACE,gBAAgB;KACjB,EACD,OAAO,CAAC,OAAO,CAChB,CAAC;IAEF,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,sBAAsB,CAAC,CAAC;IAEvE,MAAM,QAAQ,GAAoB;QAChC,gBAAgB,EAAE,CAAC,eAAe,CAAC;KACpC,CAAC;IAEF,gCAAgC;IAChC,kBAAkB,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC,8BAA8B,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["import { createPackageOverrideTransform } from './common/createPackageOverrideTransform.js';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n getExportsMap,\n PackageDefinitions,\n} from '@ms-cloudpack/package-utilities';\nimport type { PackageOverride } from './types/PackageOverride.js';\nimport type { Session } from './types/Session.js';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { parseRequestInfo } from './parseRequestInfo.js';\nimport { readConfig, writeGeneratedConfig } from '@ms-cloudpack/config';\nimport { findPackageOverride } from './common/findPackageOverride.js';\n\n/**\n * The addOverride method is triggered by a user action in the overlay, when we detect new usage of an import path\n * that isn't recognized. When the user trigers this override, we should write it to the cloudpack config, rather\n * than overrides which could get \"reset\" on `init --reset`.\n */\nexport async function addOverride({\n session,\n packageName,\n importPath,\n filename,\n}: {\n session: Session;\n packageName: string;\n importPath: string;\n filename?: string;\n}) {\n let definition = undefined;\n\n if (filename) {\n const requestPath = slash(new URL(filename).pathname);\n const { packageName: name, version } = parseRequestInfo(requestPath);\n definition = { name, version };\n }\n\n const entry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n definition,\n });\n\n if (entry === undefined) {\n console.error(`Could not find entry of package ${packageName} in resolve map`);\n return;\n }\n\n const exports = (await getExportsMap(entry.path)) as Record<string, Record<string, string>>;\n\n await addExportsMapEntry({\n exports,\n packagePath: entry.path,\n importPath,\n });\n\n const packageOverride: PackageOverride = {\n name: packageName,\n versionRequirement: `^${entry.version}`,\n overrides: {\n exports,\n },\n };\n\n // Parse config if it exists.\n const { packageOverrides = [] } = await readConfig(session.appPath);\n\n // Add package override to config.\n if (!packageOverrides.length) {\n packageOverrides.push(packageOverride);\n } else {\n const existingOverride = findPackageOverride(packageOverrides, packageName, entry.version);\n\n if (existingOverride) {\n existingOverride.overrides = packageOverride.overrides;\n } else {\n packageOverrides.push(packageOverride);\n }\n } // Write config.\n await writeGeneratedConfig(\n {\n packageOverrides,\n },\n session.appPath,\n );\n\n console.debug(`Added override for ${packageName} to cloudpack config`);\n\n const override: CloudpackConfig = {\n packageOverrides: [packageOverride],\n };\n\n // Initialize package overrides.\n PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(override));\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { PackageOverride } from '../types.js';
1
+ import type { PackageOverride } from '../types/PackageOverride.js';
2
2
  /**
3
3
  * Given a set of package overrides, finds the overrides for the given package name and version.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"findPackageOverride.d.ts","sourceRoot":"","sources":["../../src/common/findPackageOverride.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,eAAe,EAAE,EACnC,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACrB,eAAe,GAAG,SAAS,CAI7B"}
1
+ {"version":3,"file":"findPackageOverride.d.ts","sourceRoot":"","sources":["../../src/common/findPackageOverride.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,eAAe,EAAE,EACnC,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACrB,eAAe,GAAG,SAAS,CAI7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"findPackageOverride.js","sourceRoot":"","sources":["../../src/common/findPackageOverride.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,gBAAmC,EACnC,WAAmB,EACnB,cAAsB;IAEtB,OAAO,gBAAgB,CAAC,IAAI,CAC1B,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,WAAW,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAC7G,CAAC;AACJ,CAAC","sourcesContent":["import semver from 'semver';\nimport type { PackageOverride } from '../types.js';\n\n/**\n * Given a set of package overrides, finds the overrides for the given package name and version.\n */\nexport function findPackageOverride(\n packageOverrides: PackageOverride[],\n packageName: string,\n packageVersion: string,\n): PackageOverride | undefined {\n return packageOverrides.find(\n (override) => override.name === packageName && semver.satisfies(packageVersion, override.versionRequirement),\n );\n}\n"]}
1
+ {"version":3,"file":"findPackageOverride.js","sourceRoot":"","sources":["../../src/common/findPackageOverride.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,gBAAmC,EACnC,WAAmB,EACnB,cAAsB;IAEtB,OAAO,gBAAgB,CAAC,IAAI,CAC1B,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,WAAW,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAC7G,CAAC;AACJ,CAAC","sourcesContent":["import semver from 'semver';\nimport type { PackageOverride } from '../types/PackageOverride.js';\n\n/**\n * Given a set of package overrides, finds the overrides for the given package name and version.\n */\nexport function findPackageOverride(\n packageOverrides: PackageOverride[],\n packageName: string,\n packageVersion: string,\n): PackageOverride | undefined {\n return packageOverrides.find(\n (override) => override.name === packageName && semver.satisfies(packageVersion, override.versionRequirement),\n );\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,13 @@
1
1
  export { startApiServer } from './startApiServer.js';
2
- export type { ApiServer, DevServer, PackageOverride, Session, SessionStats, Task, TaskDescription, TaskEndDescription, TaskError, TaskOptions, TaskStartDescription, } from './types.js';
2
+ export type { ApiServer } from './types/ApiServer.js';
3
+ export type { DevServer } from './types/DevServer.js';
4
+ export type { PackageOverride } from './types/PackageOverride.js';
5
+ export type { Session } from './types/Session.js';
6
+ export type { SessionStats } from './types/SessionStats.js';
7
+ export type { Task } from './types/Task.js';
8
+ export type { TaskDescription } from './types/TaskDescription.js';
9
+ export type { TaskEndDescription } from './types/TaskEndDescription.js';
10
+ export type { TaskError } from './types/TaskError.js';
11
+ export type { TaskOptions } from './types/TaskOptions.js';
12
+ export type { TaskStartDescription } from './types/TaskStartDescription.js';
3
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,YAAY,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,OAAO,EACP,YAAY,EACZ,IAAI,EACJ,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,YAAY,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC"}
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export { startApiServer } from './startApiServer.js';\n\nexport type {\n ApiServer,\n DevServer,\n PackageOverride,\n Session,\n SessionStats,\n Task,\n TaskDescription,\n TaskEndDescription,\n TaskError,\n TaskOptions,\n TaskStartDescription,\n} from './types.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export { startApiServer } from './startApiServer.js';\nexport type { ApiServer } from './types/ApiServer.js';\nexport type { DevServer } from './types/DevServer.js';\nexport type { PackageOverride } from './types/PackageOverride.js';\nexport type { Session } from './types/Session.js';\nexport type { SessionStats } from './types/SessionStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskError } from './types/TaskError.js';\nexport type { TaskOptions } from './types/TaskOptions.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\n"]}
@@ -1,4 +1,5 @@
1
- import type { ApiServer, Session } from './types.js';
1
+ import type { ApiServer } from './types/ApiServer.js';
2
+ import type { Session } from './types/Session.js';
2
3
  import type { CloudpackConfig } from '@ms-cloudpack/config';
3
4
  import type { Span } from '@ms-cloudpack/telemetry';
4
5
  import type { TaskReporter } from '@ms-cloudpack/task-reporter';
@@ -1 +1 @@
1
- {"version":3,"file":"startApiServer.d.ts","sourceRoot":"","sources":["../src/startApiServer.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EAKR,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAO5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,GACR,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,GAAG,OAAO,CAAC,SAAS,CAAC,CA4XrB"}
1
+ {"version":3,"file":"startApiServer.d.ts","sourceRoot":"","sources":["../src/startApiServer.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAO5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,EACnC,OAAO,EACP,MAAM,EACN,QAAQ,EACR,QAAQ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G,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC,CAAC;KACL,CAAC;AACJ,CAAC","sourcesContent":["import os from 'os';\nimport getPort from 'get-port';\nimport path from 'path';\nimport http from 'http';\nimport https from 'https';\nimport WebSocket, { WebSocketServer } from 'ws';\nimport { createDataBus } from '@ms-cloudpack/data-bus';\nimport { execSync } from 'child_process';\nimport { TaskRunner } from './TaskRunner.js';\nimport { getCachePath } from './common/getCachePath.js';\nimport fsExtra from 'fs-extra';\nimport { startWatcher } from './startWatcher.js';\nimport type {\n ApiServer,\n Session,\n SessionStats,\n TaskDescription,\n TaskEndDescription,\n TaskStartDescription,\n} from './types.js';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport { PackageDefinitions } from '@ms-cloudpack/package-utilities';\nimport { createPackageOverrideTransform } from './common/createPackageOverrideTransform.js';\nimport { readConfigSync } from '@ms-cloudpack/config';\nimport { addOverride } from './addOverride.js';\nimport { validateOverride } from './validateOverride.js';\nimport { parseHttpsConfig } from '@ms-cloudpack/create-express-app';\nimport type { Span } from '@ms-cloudpack/telemetry';\nimport { editCloudpackConfig } from './editCloudpackConfig.js';\nimport type { TaskScheduler } from './TaskScheduler.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\n\n/**\n * The api server handles the data pub/sub (for things like reporting build status)\n * and hosting the dashboard verb backend (for executing actions like loading vscode,\n * changing dependencies, connecting new projects to the running session, etc.)\n *\n * Each time `cloudpack start` is run, an api server will start up for that session. The\n * hosted web page will have a \"cloudpack-api-server\" header which points\n * to the websocket server.\n *\n * The bundle server will call the api server to publish build status updates.\n *\n * The app server will burn the api server url on the host html, so that client-side\n * javascript can connect and subscribe to page changes.\n */\nexport async function startApiServer({\n session,\n config,\n rootSpan,\n reporter,\n useLage,\n}: {\n session: Session;\n config: CloudpackConfig;\n rootSpan: Span | undefined;\n reporter: TaskReporter;\n useLage: boolean | undefined;\n}): Promise<ApiServer> {\n const host = config?.devServer?.domain || 'localhost';\n const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n const bus = createDataBus();\n const sessionStats: SessionStats = {\n status: 'idle',\n\n remainingTasks: 0,\n totalTasks: 0,\n\n totalErrors: 0,\n totalWarnings: 0,\n };\n\n const allTasks: Map<string, TaskDescription> = new Map();\n const taskRunner = new TaskRunner();\n\n function reportStart(taskStart: TaskStartDescription): void {\n const previousResult = allTasks.get(taskStart.id);\n const now = new Date().getTime();\n\n if (!previousResult) {\n sessionStats.totalTasks++;\n }\n\n if (previousResult?.status === 'complete') {\n sessionStats.totalErrors -= previousResult.errors?.length || 0;\n sessionStats.totalWarnings -= previousResult.warnings?.length || 0;\n }\n\n sessionStats.remainingTasks++;\n sessionStats.status = 'pending';\n\n allTasks.set(taskStart.id, {\n ...taskStart,\n status: 'pending',\n startTime: now,\n });\n\n bus.publish([session.id, 'status'], sessionStats);\n bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });\n }\n\n function reportEnd(taskEnd: TaskEndDescription): void {\n const previousResult = allTasks.get(taskEnd.id);\n const now = new Date().getTime();\n\n if (previousResult) {\n sessionStats.remainingTasks--;\n sessionStats.totalErrors += taskEnd.errors?.length || 0;\n sessionStats.totalWarnings += taskEnd.warnings?.length || 0;\n\n allTasks.set(taskEnd.id, {\n ...previousResult,\n ...taskEnd,\n status: 'complete',\n durationMilliseconds: now - previousResult.startTime,\n lastUpdated: now,\n });\n\n if (sessionStats.remainingTasks === 0) {\n sessionStats.status = 'idle';\n }\n\n bus.publish([session.id, 'status'], sessionStats);\n bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });\n }\n }\n\n bus.publish([session.id, 'status'], sessionStats);\n\n const addTask: ApiServer['addTask'] = (task, options) => {\n if (task.watch) {\n options = options || {};\n options.watch = () => {\n watcher.watch(task, { onSuccess: notifyReload });\n };\n }\n\n return taskRunner.add(\n {\n ...task,\n execute: async () => {\n reportStart({\n ...task.getStartDescription?.(),\n id: task.id,\n });\n\n let taskResult;\n\n try {\n taskResult = await task.execute();\n } catch (err) {\n // no-op\n }\n\n reportEnd({\n ...task.getEndDescription?.(taskResult),\n id: task.id,\n } as TaskEndDescription);\n\n return taskResult;\n },\n },\n options,\n );\n };\n\n const watcher = startWatcher(addTask);\n\n // Create a node http(s) server.\n let server: http.Server | https.Server;\n const httpsConfig = config?.devServer?.https;\n const protocol = httpsConfig ? 'wss' : 'ws';\n\n if (httpsConfig) {\n const { key, cert, passphrase } = parseHttpsConfig(httpsConfig);\n\n if (!key || !cert) {\n console.error('Invalid https config in cloudpack.config.js. Make sure key and cert are valid.');\n\n throw new Error('Invalid https config.');\n }\n\n server = https\n .createServer(\n {\n key,\n cert,\n passphrase,\n },\n () => {\n /* no-op */\n },\n )\n .listen(port, host);\n } else {\n server = http.createServer().listen(port, host);\n }\n\n // Create a websocket server which listens for subscriptions and verb requests,\n // and broadcasts the data to all connected clients.\n const socketServer = new WebSocketServer({ server }, () => {\n // console.log(`ApiServer: Started on port ${port}`);\n }).on('connection', (socket: WebSocket) => {\n const disposables = new Map<number, () => void>();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function sendMessage(message: any) {\n socket.send(JSON.stringify(message, null, 2));\n }\n\n socket.send(\n JSON.stringify({\n type: 'sequence',\n sequence: session.sequence,\n }),\n );\n\n socket\n .on('message', (rawData) => {\n try {\n const request = JSON.parse(rawData.toString()) as {\n type: string;\n requestId?: string;\n data: Record<string, unknown>;\n };\n\n switch (request.type) {\n /**\n * Subscribe to a data subscription.\n */\n case 'subscribe': {\n const { path: subscriptionPath, id } = request.data;\n\n disposables.set(\n id as number,\n bus.subscribe(\n subscriptionPath as string[],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment\n (data: any) => sendMessage({ type: 'notify', id, path: subscriptionPath, data }),\n ),\n );\n\n break;\n }\n\n /**\n * Unsubscribe from a data subscription.\n */\n case 'unsubscribe': {\n const id = request.data.id as number | undefined;\n if (id) {\n const dispose = disposables.get(id);\n\n if (dispose) {\n dispose();\n disposables.delete(id);\n }\n }\n\n break;\n }\n\n /**\n * Open a file in VSCode.\n */\n case 'openSource': {\n const { rootPath, relativePath = '', line, column } = request.data;\n const fullPath = path.join(rootPath as string, relativePath as string);\n\n console.log(`Opening VSCode with path: ${fullPath}`);\n execSync(`code --goto ${fullPath}:${line}:${column}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Open a file or folder in the OS's default file manager.\n */\n case 'open': {\n const { rootPath, relativePath = '' } = request.data;\n const fullPath = path.join(rootPath as string, relativePath as string);\n\n console.log(`Opening path: ${fullPath}`);\n const openCommand = os.platform() == 'win32' ? 'start' : 'open';\n\n execSync(`${openCommand} ${fullPath}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Opens the cloudpack config in VSCode for the user to manually edit. If the file doesn't exist,\n * it will be created.\n */\n case 'editConfig': {\n editCloudpackConfig().catch(() => {\n /* no-op */\n });\n break;\n }\n\n /**\n * Adds an override to the cloudpack config.\n */\n case 'addOverride': {\n // TODO: Send filename from request data to findResolveMapEntry when chromium Issue 1371551 is fixed.\n const { packageName, importPath } = request.data as Record<string, string>;\n (async () => {\n await addOverride({ session, packageName, importPath });\n session.incrementSessionVersion();\n notifyReload();\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'validateOverride': {\n // TODO: Get filename from request data when chromium Issue 1371551 is fixed.\n const { requestId, data } = request as { requestId: string; data: Record<string, string> };\n const { packageName, importPath } = data;\n (async () => {\n const fixable = await validateOverride({ session, packageName, importPath });\n sendMessage({ type: 'validateOverride', requestId, data: { fixable } });\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'restartAllTasks': {\n console.log('ApiServer: Restarting all tasks');\n\n // Clear entire local cache.\n fsExtra.emptyDirSync(getCachePath());\n\n // All tasks can be removed as notifyReload()\n // will cause the client to add the tasks again.\n allTasks.forEach((_, id) => {\n taskRunner.remove(id);\n });\n\n // Parse config if it exists.\n const cloudpackConfig = readConfigSync();\n\n // Initialize package overrides.\n PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(cloudpackConfig));\n\n // Update session version.\n session.incrementSessionVersion();\n\n notifyReload();\n break;\n }\n\n case 'restartTask': {\n const { id, inputPath } = request.data as Record<string, string>;\n console.log(`ApiServer: Restarting task ${id}`);\n taskRunner.remove(id);\n session.incrementTargetVersion(inputPath);\n notifyReload();\n break;\n }\n\n case 'reportMetric': {\n const { metric, value } = request.data as { metric: string; value: number };\n console.debug(`ApiServer: Received metric: ${metric}, value: ${value}`);\n rootSpan?.addEvent(metric, value);\n break;\n }\n }\n } catch (err) {\n console.error('ApiServer: error handling message');\n console.error('Error:', err);\n console.error('Message:', rawData.toString());\n }\n })\n .on('close', () => {\n for (const d of disposables.values()) {\n d();\n }\n });\n });\n\n const notifyReload = () => {\n session.sequence++;\n socketServer.clients.forEach((socket: WebSocket) => {\n if (socket.readyState === WebSocket.OPEN) {\n socket.send(\n JSON.stringify({\n type: 'reload',\n data: { sessionId: session.id },\n }),\n );\n }\n });\n };\n\n let scheduler: TaskScheduler | undefined;\n if (useLage) {\n const { TaskScheduler } = await import('./TaskScheduler.js');\n scheduler = new TaskScheduler({ reporter });\n }\n\n return {\n url: `${protocol}://${host}:${port}`,\n port,\n\n notifyReload,\n\n addTask: (task, options) => {\n return addTask(task, options);\n },\n\n scheduleTask: async (bundleRequest, scripts, options) => {\n if (!scheduler) {\n throw new Error('Cannot schedule task when not using lage');\n }\n\n reportStart({\n id: bundleRequest.id,\n inputPath: bundleRequest.packagePath,\n outputPath: bundleRequest.outputPath,\n name: bundleRequest.packageName,\n });\n\n await scheduler.scheduleTask(bundleRequest, scripts, options);\n\n reportEnd({\n id: bundleRequest.id,\n });\n },\n\n close: () =>\n new Promise<void>((resolve, reject) => {\n socketServer.clients.forEach((socket: WebSocket) => socket.terminate());\n socketServer.close((err) => (err ? reject(err) : resolve()));\n server.close();\n }),\n };\n}\n"]}
1
+ {"version":3,"file":"startApiServer.js","sourceRoot":"","sources":["../src/startApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAQjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAI/D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,GAOR;IACC,MAAM,IAAI,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,IAAI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,CAAC","sourcesContent":["import os from 'os';\nimport getPort from 'get-port';\nimport path from 'path';\nimport http from 'http';\nimport https from 'https';\nimport WebSocket, { WebSocketServer } from 'ws';\nimport { createDataBus } from '@ms-cloudpack/data-bus';\nimport { execSync } from 'child_process';\nimport { TaskRunner } from './TaskRunner.js';\nimport { getCachePath } from './common/getCachePath.js';\nimport fsExtra from 'fs-extra';\nimport { startWatcher } from './startWatcher.js';\nimport type { TaskDescription } from './types/TaskDescription.js';\nimport type { TaskEndDescription } from './types/TaskEndDescription.js';\nimport type { TaskStartDescription } from './types/TaskStartDescription.js';\nimport type { ApiServer } from './types/ApiServer.js';\nimport type { SessionStats } from './types/SessionStats.js';\nimport type { Session } from './types/Session.js';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport { PackageDefinitions } from '@ms-cloudpack/package-utilities';\nimport { createPackageOverrideTransform } from './common/createPackageOverrideTransform.js';\nimport { readConfigSync } from '@ms-cloudpack/config';\nimport { addOverride } from './addOverride.js';\nimport { validateOverride } from './validateOverride.js';\nimport { parseHttpsConfig } from '@ms-cloudpack/create-express-app';\nimport type { Span } from '@ms-cloudpack/telemetry';\nimport { editCloudpackConfig } from './editCloudpackConfig.js';\nimport type { TaskScheduler } from './TaskScheduler.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\n\n/**\n * The api server handles the data pub/sub (for things like reporting build status)\n * and hosting the dashboard verb backend (for executing actions like loading vscode,\n * changing dependencies, connecting new projects to the running session, etc.)\n *\n * Each time `cloudpack start` is run, an api server will start up for that session. The\n * hosted web page will have a \"cloudpack-api-server\" header which points\n * to the websocket server.\n *\n * The bundle server will call the api server to publish build status updates.\n *\n * The app server will burn the api server url on the host html, so that client-side\n * javascript can connect and subscribe to page changes.\n */\nexport async function startApiServer({\n session,\n config,\n rootSpan,\n reporter,\n useLage,\n}: {\n session: Session;\n config: CloudpackConfig;\n rootSpan: Span | undefined;\n reporter: TaskReporter;\n useLage: boolean | undefined;\n}): Promise<ApiServer> {\n const host = config?.devServer?.domain || 'localhost';\n const port = await getPort({ port: [9890, 9891, 9892, 9893] });\n const bus = createDataBus();\n const sessionStats: SessionStats = {\n status: 'idle',\n\n remainingTasks: 0,\n totalTasks: 0,\n\n totalErrors: 0,\n totalWarnings: 0,\n };\n\n const allTasks: Map<string, TaskDescription> = new Map();\n const taskRunner = new TaskRunner();\n\n function reportStart(taskStart: TaskStartDescription): void {\n const previousResult = allTasks.get(taskStart.id);\n const now = new Date().getTime();\n\n if (!previousResult) {\n sessionStats.totalTasks++;\n }\n\n if (previousResult?.status === 'complete') {\n sessionStats.totalErrors -= previousResult.errors?.length || 0;\n sessionStats.totalWarnings -= previousResult.warnings?.length || 0;\n }\n\n sessionStats.remainingTasks++;\n sessionStats.status = 'pending';\n\n allTasks.set(taskStart.id, {\n ...taskStart,\n status: 'pending',\n startTime: now,\n });\n\n bus.publish([session.id, 'status'], sessionStats);\n bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });\n }\n\n function reportEnd(taskEnd: TaskEndDescription): void {\n const previousResult = allTasks.get(taskEnd.id);\n const now = new Date().getTime();\n\n if (previousResult) {\n sessionStats.remainingTasks--;\n sessionStats.totalErrors += taskEnd.errors?.length || 0;\n sessionStats.totalWarnings += taskEnd.warnings?.length || 0;\n\n allTasks.set(taskEnd.id, {\n ...previousResult,\n ...taskEnd,\n status: 'complete',\n durationMilliseconds: now - previousResult.startTime,\n lastUpdated: now,\n });\n\n if (sessionStats.remainingTasks === 0) {\n sessionStats.status = 'idle';\n }\n\n bus.publish([session.id, 'status'], sessionStats);\n bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });\n }\n }\n\n bus.publish([session.id, 'status'], sessionStats);\n\n const addTask: ApiServer['addTask'] = (task, options) => {\n if (task.watch) {\n options = options || {};\n options.watch = () => {\n watcher.watch(task, { onSuccess: notifyReload });\n };\n }\n\n return taskRunner.add(\n {\n ...task,\n execute: async () => {\n reportStart({\n ...task.getStartDescription?.(),\n id: task.id,\n });\n\n let taskResult;\n\n try {\n taskResult = await task.execute();\n } catch (err) {\n // no-op\n }\n\n reportEnd({\n ...task.getEndDescription?.(taskResult),\n id: task.id,\n } as TaskEndDescription);\n\n return taskResult;\n },\n },\n options,\n );\n };\n\n const watcher = startWatcher(addTask);\n\n // Create a node http(s) server.\n let server: http.Server | https.Server;\n const httpsConfig = config?.devServer?.https;\n const protocol = httpsConfig ? 'wss' : 'ws';\n\n if (httpsConfig) {\n const { key, cert, passphrase } = parseHttpsConfig(httpsConfig);\n\n if (!key || !cert) {\n console.error('Invalid https config in cloudpack.config.js. Make sure key and cert are valid.');\n\n throw new Error('Invalid https config.');\n }\n\n server = https\n .createServer(\n {\n key,\n cert,\n passphrase,\n },\n () => {\n /* no-op */\n },\n )\n .listen(port, host);\n } else {\n server = http.createServer().listen(port, host);\n }\n\n // Create a websocket server which listens for subscriptions and verb requests,\n // and broadcasts the data to all connected clients.\n const socketServer = new WebSocketServer({ server }, () => {\n // console.log(`ApiServer: Started on port ${port}`);\n }).on('connection', (socket: WebSocket) => {\n const disposables = new Map<number, () => void>();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function sendMessage(message: any) {\n socket.send(JSON.stringify(message, null, 2));\n }\n\n socket.send(\n JSON.stringify({\n type: 'sequence',\n sequence: session.sequence,\n }),\n );\n\n socket\n .on('message', (rawData) => {\n try {\n const request = JSON.parse(rawData.toString()) as {\n type: string;\n requestId?: string;\n data: Record<string, unknown>;\n };\n\n switch (request.type) {\n /**\n * Subscribe to a data subscription.\n */\n case 'subscribe': {\n const { path: subscriptionPath, id } = request.data;\n\n disposables.set(\n id as number,\n bus.subscribe(\n subscriptionPath as string[],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment\n (data: any) => sendMessage({ type: 'notify', id, path: subscriptionPath, data }),\n ),\n );\n\n break;\n }\n\n /**\n * Unsubscribe from a data subscription.\n */\n case 'unsubscribe': {\n const id = request.data.id as number | undefined;\n if (id) {\n const dispose = disposables.get(id);\n\n if (dispose) {\n dispose();\n disposables.delete(id);\n }\n }\n\n break;\n }\n\n /**\n * Open a file in VSCode.\n */\n case 'openSource': {\n const { rootPath, relativePath = '', line, column } = request.data;\n const fullPath = path.join(rootPath as string, relativePath as string);\n\n console.log(`Opening VSCode with path: ${fullPath}`);\n execSync(`code --goto ${fullPath}:${line}:${column}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Open a file or folder in the OS's default file manager.\n */\n case 'open': {\n const { rootPath, relativePath = '' } = request.data;\n const fullPath = path.join(rootPath as string, relativePath as string);\n\n console.log(`Opening path: ${fullPath}`);\n const openCommand = os.platform() == 'win32' ? 'start' : 'open';\n\n execSync(`${openCommand} ${fullPath}`, { cwd: process.cwd() });\n break;\n }\n\n /**\n * Opens the cloudpack config in VSCode for the user to manually edit. If the file doesn't exist,\n * it will be created.\n */\n case 'editConfig': {\n editCloudpackConfig().catch(() => {\n /* no-op */\n });\n break;\n }\n\n /**\n * Adds an override to the cloudpack config.\n */\n case 'addOverride': {\n // TODO: Send filename from request data to findResolveMapEntry when chromium Issue 1371551 is fixed.\n const { packageName, importPath } = request.data as Record<string, string>;\n (async () => {\n await addOverride({ session, packageName, importPath });\n session.incrementSessionVersion();\n notifyReload();\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'validateOverride': {\n // TODO: Get filename from request data when chromium Issue 1371551 is fixed.\n const { requestId, data } = request as { requestId: string; data: Record<string, string> };\n const { packageName, importPath } = data;\n (async () => {\n const fixable = await validateOverride({ session, packageName, importPath });\n sendMessage({ type: 'validateOverride', requestId, data: { fixable } });\n })().catch(() => {\n // no-op\n });\n break;\n }\n\n case 'restartAllTasks': {\n console.log('ApiServer: Restarting all tasks');\n\n // Clear entire local cache.\n fsExtra.emptyDirSync(getCachePath());\n\n // All tasks can be removed as notifyReload()\n // will cause the client to add the tasks again.\n allTasks.forEach((_, id) => {\n taskRunner.remove(id);\n });\n\n // Parse config if it exists.\n const cloudpackConfig = readConfigSync();\n\n // Initialize package overrides.\n PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(cloudpackConfig));\n\n // Update session version.\n session.incrementSessionVersion();\n\n notifyReload();\n break;\n }\n\n case 'restartTask': {\n const { id, inputPath } = request.data as Record<string, string>;\n console.log(`ApiServer: Restarting task ${id}`);\n taskRunner.remove(id);\n session.incrementTargetVersion(inputPath);\n notifyReload();\n break;\n }\n\n case 'reportMetric': {\n const { metric, value } = request.data as { metric: string; value: number };\n console.debug(`ApiServer: Received metric: ${metric}, value: ${value}`);\n rootSpan?.addEvent(metric, value);\n break;\n }\n }\n } catch (err) {\n console.error('ApiServer: error handling message');\n console.error('Error:', err);\n console.error('Message:', rawData.toString());\n }\n })\n .on('close', () => {\n for (const d of disposables.values()) {\n d();\n }\n });\n });\n\n const notifyReload = () => {\n session.sequence++;\n socketServer.clients.forEach((socket: WebSocket) => {\n if (socket.readyState === WebSocket.OPEN) {\n socket.send(\n JSON.stringify({\n type: 'reload',\n data: { sessionId: session.id },\n }),\n );\n }\n });\n };\n\n let scheduler: TaskScheduler | undefined;\n if (useLage) {\n const { TaskScheduler } = await import('./TaskScheduler.js');\n scheduler = new TaskScheduler({ reporter });\n }\n\n return {\n url: `${protocol}://${host}:${port}`,\n port,\n\n notifyReload,\n\n addTask: (task, options) => {\n return addTask(task, options);\n },\n\n scheduleTask: async (bundleRequest, scripts, options) => {\n if (!scheduler) {\n throw new Error('Cannot schedule task when not using lage');\n }\n\n reportStart({\n id: bundleRequest.id,\n inputPath: bundleRequest.packagePath,\n outputPath: bundleRequest.outputPath,\n name: bundleRequest.packageName,\n });\n\n await scheduler.scheduleTask(bundleRequest, scripts, options);\n\n reportEnd({\n id: bundleRequest.id,\n });\n },\n\n close: () =>\n new Promise<void>((resolve, reject) => {\n socketServer.clients.forEach((socket: WebSocket) => socket.terminate());\n socketServer.close((err) => (err ? reject(err) : resolve()));\n server.close();\n }),\n };\n}\n"]}
@@ -1,4 +1,5 @@
1
- import type { ApiServer, Task } from './types.js';
1
+ import type { Task } from './types/Task.js';
2
+ import type { ApiServer } from './types/ApiServer.js';
2
3
  export declare function startWatcher(addTask: ApiServer['addTask']): {
3
4
  watch: <TReturn>(task: Task<TReturn>, options?: {
4
5
  onSuccess?: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"startWatcher.d.ts","sourceRoot":"","sources":["../src/startWatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElD,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC;oDAIN;QAAE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE;EAiDrG"}
1
+ {"version":3,"file":"startWatcher.d.ts","sourceRoot":"","sources":["../src/startWatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC;oDAIN;QAAE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE;EAiDrG"}
@@ -1 +1 @@
1
- {"version":3,"file":"startWatcher.js","sourceRoot":"","sources":["../src/startWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAGhC,MAAM,UAAU,YAAY,CAAC,OAA6B;IACxD,MAAM,OAAO,GAAgB,IAAI,GAAG,EAAE,CAAC;IAEvC,OAAO;QACL,KAAK,EAAE,CAAU,IAAmB,EAAE,OAA4D,EAAE,EAAE;YACpG,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;YAC/B,4CAA4C;YAC5C,IA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,OAAO,GAAG,KAAK,IAAI,EAAE;gBACxB,IAAI;oBACF,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;iBACvB;gBAAC,MAAM;oBACN,SAAS;iBACV;gBAED,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;gBAEnB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACrB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import chokidar from 'chokidar';\nimport type { ApiServer, Task } from './types.js';\n\nexport function startWatcher(addTask: ApiServer['addTask']) {\n const watched: Set<string> = new Set();\n\n return {\n watch: <TReturn>(task: Task<TReturn>, options?: { onSuccess?: () => void; onDispose?: () => void }) => {\n const { id, name, dir } = task;\n // Have a single watcher per bundle request.\n if (watched.has(id) || !dir) {\n return;\n }\n\n watched.add(id);\n\n console.debug(`Initializing file watcher for ${name}`);\n\n // TODO: This is a bit of a hack. We should be able to use the watch API, but it doesn't seem to work.\n const watcher = chokidar.watch(dir).on('change', (event: string) => {\n console.debug(`Detected change \"${event}\", rebuilding \"${name}\"`);\n\n (async () => {\n // Start tracking work.\n let rebuilt = false;\n try {\n await addTask(task, { rerun: true });\n rebuilt = true;\n } catch (err) {\n console.error(`Error rebuilding \"${name}\":`, (err as Error)?.stack || err);\n }\n const errors = task.getErrors?.();\n if (rebuilt && !errors?.length) {\n console.debug(`Notifying rebuild: ${name}`);\n options?.onSuccess?.();\n } else if (errors) {\n console.debug(`${name} ${errors.length} errors`);\n }\n })().catch(() => {\n // no-op\n });\n });\n\n task.dispose = async () => {\n try {\n await watcher.close();\n } catch {\n // ignore\n }\n\n task.onDispose?.();\n\n watched.delete(id);\n };\n },\n };\n}\n"]}
1
+ {"version":3,"file":"startWatcher.js","sourceRoot":"","sources":["../src/startWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC,MAAM,UAAU,YAAY,CAAC,OAA6B;IACxD,MAAM,OAAO,GAAgB,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AG,IAAI,IAAI,MAAM,CAAC,MAAM,SAAS,CAAC,CAAC;qBAClD;gBACH,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;oBACd,QAAQ;gBACV,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;gBACxB,IAAI;oBACF,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;iBACvB;gBAAC,MAAM;oBACN,SAAS;iBACV;gBAED,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;gBAEnB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACrB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import chokidar from 'chokidar';\nimport type { Task } from './types/Task.js';\nimport type { ApiServer } from './types/ApiServer.js';\n\nexport function startWatcher(addTask: ApiServer['addTask']) {\n const watched: Set<string> = new Set();\n\n return {\n watch: <TReturn>(task: Task<TReturn>, options?: { onSuccess?: () => void; onDispose?: () => void }) => {\n const { id, name, dir } = task;\n // Have a single watcher per bundle request.\n if (watched.has(id) || !dir) {\n return;\n }\n\n watched.add(id);\n\n console.debug(`Initializing file watcher for ${name}`);\n\n // TODO: This is a bit of a hack. We should be able to use the watch API, but it doesn't seem to work.\n const watcher = chokidar.watch(dir).on('change', (event: string) => {\n console.debug(`Detected change \"${event}\", rebuilding \"${name}\"`);\n\n (async () => {\n // Start tracking work.\n let rebuilt = false;\n try {\n await addTask(task, { rerun: true });\n rebuilt = true;\n } catch (err) {\n console.error(`Error rebuilding \"${name}\":`, (err as Error)?.stack || err);\n }\n const errors = task.getErrors?.();\n if (rebuilt && !errors?.length) {\n console.debug(`Notifying rebuild: ${name}`);\n options?.onSuccess?.();\n } else if (errors) {\n console.debug(`${name} ${errors.length} errors`);\n }\n })().catch(() => {\n // no-op\n });\n });\n\n task.dispose = async () => {\n try {\n await watcher.close();\n } catch {\n // ignore\n }\n\n task.onDispose?.();\n\n watched.delete(id);\n };\n },\n };\n}\n"]}
@@ -1,11 +1,11 @@
1
- // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
- // It should be published with your NPM package. It should not be tracked by Git.
3
- {
4
- "tsdocVersion": "0.12",
5
- "toolPackages": [
6
- {
7
- "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.34.4"
9
- }
10
- ]
11
- }
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.34.7"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,14 @@
1
+ import type { BundleRequest } from './BundleRequest.js';
2
+ import type { TaskOptions } from './TaskOptions.js';
3
+ import type { Task } from './Task.js';
4
+ export interface ApiServer {
5
+ url: string;
6
+ port: number;
7
+ notifyReload: () => void;
8
+ addTask: <TReturn>(task: Task<TReturn>, options?: TaskOptions) => Promise<TReturn>;
9
+ scheduleTask: <T extends BundleRequest>(bundleRequest: T, scripts: Record<string, string>, options: {
10
+ rerun?: boolean;
11
+ }) => Promise<void>;
12
+ close: () => Promise<void>;
13
+ }
14
+ //# sourceMappingURL=ApiServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiServer.d.ts","sourceRoot":"","sources":["../../src/types/ApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,EAAE,MAAM,IAAI,CAAC;IAEzB,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnF,YAAY,EAAE,CAAC,CAAC,SAAS,aAAa,EACpC,aAAa,EAAE,CAAC,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,KACzB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ApiServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiServer.js","sourceRoot":"","sources":["../../src/types/ApiServer.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleRequest } from './BundleRequest.js';\nimport type { TaskOptions } from './TaskOptions.js';\nimport type { Task } from './Task.js';\n\nexport interface ApiServer {\n url: string;\n port: number;\n\n notifyReload: () => void;\n\n addTask: <TReturn>(task: Task<TReturn>, options?: TaskOptions) => Promise<TReturn>;\n\n scheduleTask: <T extends BundleRequest>(\n bundleRequest: T,\n scripts: Record<string, string>,\n options: { rerun?: boolean },\n ) => Promise<void>;\n\n close: () => Promise<void>;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export interface BundleRequest {
2
+ id: string;
3
+ packageName: string;
4
+ version: string;
5
+ packagePath: string;
6
+ outputPath: string;
7
+ isExternal: boolean;
8
+ disableSourceMaps?: boolean;
9
+ }
10
+ //# sourceMappingURL=BundleRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=BundleRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["export interface BundleRequest {\n id: string;\n packageName: string;\n version: string;\n packagePath: string;\n outputPath: string;\n isExternal: boolean;\n disableSourceMaps?: boolean;\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { CreateHtmlOptions } from './CreateHtmlOptions.js';
2
+ import type { CreateHtmlResult } from './CreateHtmlResult.js';
3
+ /**
4
+ * A custom server render function that can be used to override the default HTML response.
5
+ */
6
+ export type CreateHtmlFunction = (options: CreateHtmlOptions) => Promise<CreateHtmlResult> | CreateHtmlResult;
7
+ //# sourceMappingURL=CreateHtmlFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlFunction.d.ts","sourceRoot":"","sources":["../../src/types/CreateHtmlFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;GAEG;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CreateHtmlFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlFunction.js","sourceRoot":"","sources":["../../src/types/CreateHtmlFunction.ts"],"names":[],"mappings":"","sourcesContent":["import type { CreateHtmlOptions } from './CreateHtmlOptions.js';\nimport type { CreateHtmlResult } from './CreateHtmlResult.js';\n\n/**\n * A custom server render function that can be used to override the default HTML response.\n */\n\nexport type CreateHtmlFunction = (options: CreateHtmlOptions) => Promise<CreateHtmlResult> | CreateHtmlResult;\n"]}
@@ -0,0 +1,18 @@
1
+ import type { ImportMap } from '@ms-cloudpack/package-utilities';
2
+ import type { PackageJson } from '@ms-cloudpack/bundler-types';
3
+ import type { Session } from './Session.js';
4
+ import type { Route } from './Route.js';
5
+ /**
6
+ * The input options for a createHtml custom server render function.
7
+ */
8
+ export type CreateHtmlOptions = {
9
+ session: Session;
10
+ route: Route;
11
+ baseUrl: string;
12
+ definition: PackageJson;
13
+ importMap: ImportMap;
14
+ overlayScript: string | undefined;
15
+ entryScript: string | undefined;
16
+ inlineScripts: string[];
17
+ };
18
+ //# sourceMappingURL=CreateHtmlOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlOptions.d.ts","sourceRoot":"","sources":["../../src/types/CreateHtmlOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;GAEG;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,WAAW,CAAC;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CreateHtmlOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlOptions.js","sourceRoot":"","sources":["../../src/types/CreateHtmlOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap } from '@ms-cloudpack/package-utilities';\nimport type { PackageJson } from '@ms-cloudpack/bundler-types';\nimport type { Session } from './Session.js';\nimport type { Route } from './Route.js';\n\n/**\n * The input options for a createHtml custom server render function.\n */\n\nexport type CreateHtmlOptions = {\n session: Session;\n route: Route;\n baseUrl: string;\n definition: PackageJson;\n importMap: ImportMap;\n overlayScript: string | undefined;\n entryScript: string | undefined;\n inlineScripts: string[];\n};\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The expected result of the createHtml custom server render function.
3
+ */
4
+ export type CreateHtmlResult = string | {
5
+ html: string;
6
+ statusCode: number;
7
+ };
8
+ //# sourceMappingURL=CreateHtmlResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlResult.d.ts","sourceRoot":"","sources":["../../src/types/CreateHtmlResult.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The expected result of the createHtml custom server render function.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=CreateHtmlResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlResult.js","sourceRoot":"","sources":["../../src/types/CreateHtmlResult.ts"],"names":[],"mappings":"AAAA;;GAEG","sourcesContent":["/**\n * The expected result of the createHtml custom server render function.\n */\n\nexport type CreateHtmlResult =\n | string\n | {\n html: string;\n statusCode: number;\n };\n"]}
@@ -0,0 +1,8 @@
1
+ import type { CreateHtmlFunction } from './CreateHtmlFunction.js';
2
+ /**
3
+ * The expected shape of the createHtml custom server render function script.
4
+ */
5
+ export type CreateHtmlScript = {
6
+ default: CreateHtmlFunction;
7
+ };
8
+ //# sourceMappingURL=CreateHtmlScript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlScript.d.ts","sourceRoot":"","sources":["../../src/types/CreateHtmlScript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;GAEG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAAE,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CreateHtmlScript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateHtmlScript.js","sourceRoot":"","sources":["../../src/types/CreateHtmlScript.ts"],"names":[],"mappings":"","sourcesContent":["import type { CreateHtmlFunction } from './CreateHtmlFunction.js';\n\n/**\n * The expected shape of the createHtml custom server render function script.\n */\n\nexport type CreateHtmlScript = { default: CreateHtmlFunction };\n"]}