@ms-cloudpack/api-server 0.58.17 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/lib/apis/addPackageOverride.d.ts +1 -1
  2. package/lib/apis/addPackageOverride.d.ts.map +1 -1
  3. package/lib/apis/addPackageOverride.js.map +1 -1
  4. package/lib/apis/ensurePackageBundled.d.ts +18 -6
  5. package/lib/apis/ensurePackageBundled.d.ts.map +1 -1
  6. package/lib/apis/ensurePackageBundled.js +25 -20
  7. package/lib/apis/ensurePackageBundled.js.map +1 -1
  8. package/lib/apis/restartTask.d.ts +4 -0
  9. package/lib/apis/restartTask.d.ts.map +1 -1
  10. package/lib/apis/restartTask.js +4 -0
  11. package/lib/apis/restartTask.js.map +1 -1
  12. package/lib/apis/syncUpload.d.ts +5 -2
  13. package/lib/apis/syncUpload.d.ts.map +1 -1
  14. package/lib/apis/syncUpload.js +1 -0
  15. package/lib/apis/syncUpload.js.map +1 -1
  16. package/lib/common/createApiContext.d.ts +29 -0
  17. package/lib/common/createApiContext.d.ts.map +1 -0
  18. package/lib/common/createApiContext.js +62 -0
  19. package/lib/common/createApiContext.js.map +1 -0
  20. package/lib/common/createSession.d.ts +7 -0
  21. package/lib/common/createSession.d.ts.map +1 -1
  22. package/lib/common/createSession.js +1 -0
  23. package/lib/common/createSession.js.map +1 -1
  24. package/lib/index.d.ts +1 -2
  25. package/lib/index.d.ts.map +1 -1
  26. package/lib/index.js +1 -1
  27. package/lib/index.js.map +1 -1
  28. package/lib/trpc/common.d.ts +5 -3
  29. package/lib/trpc/common.d.ts.map +1 -1
  30. package/lib/trpc/common.js.map +1 -1
  31. package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
  32. package/lib/trpc/createCloudpackServer.js +1 -2
  33. package/lib/trpc/createCloudpackServer.js.map +1 -1
  34. package/lib/types/BundleRequest.d.ts +3 -1
  35. package/lib/types/BundleRequest.d.ts.map +1 -1
  36. package/lib/types/BundleRequest.js.map +1 -1
  37. package/lib/types/Context.d.ts +6 -5
  38. package/lib/types/Context.d.ts.map +1 -1
  39. package/lib/types/Context.js.map +1 -1
  40. package/lib/types/Task.d.ts +1 -0
  41. package/lib/types/Task.d.ts.map +1 -1
  42. package/lib/types/Task.js.map +1 -1
  43. package/lib/utilities/TaskRunner.d.ts +22 -11
  44. package/lib/utilities/TaskRunner.d.ts.map +1 -1
  45. package/lib/utilities/TaskRunner.js +24 -25
  46. package/lib/utilities/TaskRunner.js.map +1 -1
  47. package/lib/utilities/bundleTask.js +3 -2
  48. package/lib/utilities/bundleTask.js.map +1 -1
  49. package/lib/utilities/createBundleTask.d.ts +1 -1
  50. package/lib/utilities/createBundleTask.d.ts.map +1 -1
  51. package/lib/utilities/createBundleTask.js.map +1 -1
  52. package/lib/utilities/notifyReload.d.ts +2 -8
  53. package/lib/utilities/notifyReload.d.ts.map +1 -1
  54. package/lib/utilities/notifyReload.js.map +1 -1
  55. package/package.json +13 -13
  56. package/lib/common/createPartialApiContext.d.ts +0 -17
  57. package/lib/common/createPartialApiContext.d.ts.map +0 -1
  58. package/lib/common/createPartialApiContext.js +0 -170
  59. package/lib/common/createPartialApiContext.js.map +0 -1
  60. package/lib/trpc/createContextFactory.d.ts +0 -9
  61. package/lib/trpc/createContextFactory.d.ts.map +0 -1
  62. package/lib/trpc/createContextFactory.js +0 -17
  63. package/lib/trpc/createContextFactory.js.map +0 -1
  64. package/lib/types/TaskOptions.d.ts +0 -6
  65. package/lib/types/TaskOptions.d.ts.map +0 -1
  66. package/lib/types/TaskOptions.js +0 -2
  67. package/lib/types/TaskOptions.js.map +0 -1
  68. package/lib/types/TaskRunnerContext.d.ts +0 -3
  69. package/lib/types/TaskRunnerContext.d.ts.map +0 -1
  70. package/lib/types/TaskRunnerContext.js +0 -2
  71. package/lib/types/TaskRunnerContext.js.map +0 -1
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,YAAY;AACZ,OAAO,EAAE,uBAAuB,EAA8B,MAAM,qCAAqC,CAAC;AAE1G,iDAAiD;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export type { Context, PartialContext } from './types/Context.js';\nexport type { BundleInfo, BundleEntryInfo, BundleEntryConsumes } from './types/BundleInfo.js';\nexport type { Session } from '@ms-cloudpack/common-types';\nexport type { TaskStats } from './types/TaskStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskOptions } from './types/TaskOptions.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\nexport type { EnsurePackageBundledContext, EnsurePackageBundledResult } from './apis/ensurePackageBundled.js';\n\nexport { TaskRunner } from './utilities/TaskRunner.js';\nexport { errorEntrySource } from './data/busSources.js';\nexport { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';\nexport { createCloudpackServer, type CloudpackServer } from './trpc/createCloudpackServer.js';\nexport { getActiveSessionsPath } from './utilities/getActiveSessionsPath.js';\nexport { getConsumedDependencies } from './utilities/getConsumedDependencies.js';\nexport { getConsumedPaths } from './utilities/getConsumedPaths.js';\n\n// Utilities\nexport { createPartialApiContext, type LazyApiContextOptions } from './common/createPartialApiContext.js';\n\n// API methods directly used outside this package\nexport { addPackageOverride } from './apis/addPackageOverride.js';\nexport { ensurePackageBundled } from './apis/ensurePackageBundled.js';\nexport { syncDownload } from './apis/syncDownload.js';\nexport { syncUpload } from './apis/syncUpload.js';\nexport type { SyncResult } from './types/SyncResult.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,YAAY;AACZ,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAgC,MAAM,8BAA8B,CAAC;AAEvH,iDAAiD;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export type { Context, PartialContext } from './types/Context.js';\nexport type { BundleInfo, BundleEntryInfo, BundleEntryConsumes } from './types/BundleInfo.js';\nexport type { Session } from '@ms-cloudpack/common-types';\nexport type { TaskStats } from './types/TaskStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\nexport type { EnsurePackageBundledContext, EnsurePackageBundledResult } from './apis/ensurePackageBundled.js';\n\nexport { TaskRunner } from './utilities/TaskRunner.js';\nexport { errorEntrySource } from './data/busSources.js';\nexport { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';\nexport { createCloudpackServer, type CloudpackServer } from './trpc/createCloudpackServer.js';\nexport { getActiveSessionsPath } from './utilities/getActiveSessionsPath.js';\nexport { getConsumedDependencies } from './utilities/getConsumedDependencies.js';\nexport { getConsumedPaths } from './utilities/getConsumedPaths.js';\n\n// Utilities\nexport { createApiContext, createPartialApiContext, type CreateApiContextOptions } from './common/createApiContext.js';\n\n// API methods directly used outside this package\nexport { addPackageOverride } from './apis/addPackageOverride.js';\nexport { ensurePackageBundled } from './apis/ensurePackageBundled.js';\nexport { syncDownload } from './apis/syncDownload.js';\nexport { syncUpload } from './apis/syncUpload.js';\nexport type { SyncResult } from './types/SyncResult.js';\n"]}
@@ -1,18 +1,20 @@
1
+ import type { Context } from '../types/Context.js';
2
+ export type CreateContext = () => Promise<Context>;
1
3
  /** Reusable TRPC router helper. */
2
4
  export declare const createRouter: {
3
5
  <TInput extends import("@trpc/server").RouterRecord>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
4
- ctx: import("../index.js").Context;
6
+ ctx: Context;
5
7
  meta: object;
6
8
  errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
7
9
  transformer: false;
8
10
  }, TInput>;
9
11
  <TInput extends import("@trpc/server/unstable-core-do-not-import").CreateRouterOptions>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
10
- ctx: import("../index.js").Context;
12
+ ctx: Context;
11
13
  meta: object;
12
14
  errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
13
15
  transformer: false;
14
16
  }, import("@trpc/server/unstable-core-do-not-import").DecorateCreateRouterOptions<TInput>>;
15
17
  };
16
18
  /** Reusable TRPC procedure helper. */
17
- export declare const publicProcedure: import("@trpc/server/unstable-core-do-not-import").ProcedureBuilder<import("../index.js").Context, object, object, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, false>;
19
+ export declare const publicProcedure: import("@trpc/server/unstable-core-do-not-import").ProcedureBuilder<Context, object, object, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, false>;
18
20
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/trpc/common.ts"],"names":[],"mappings":"AAMA,mCAAmC;AACnC,eAAO,MAAM,YAAY;2BAIq9E,cAAU;;;;;;2BAAoa,0CAAU;;;;;;CAJl4F,CAAC;AAErC,sCAAsC;AACtC,eAAO,MAAM,eAAe,uZAAc,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/trpc/common.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAKnD,mCAAmC;AACnC,eAAO,MAAM,YAAY;2BAI46E,cAAU;;;;;;2BAAoa,0CAAU;;;;;;CAJz1F,CAAC;AAErC,sCAAsC;AACtC,eAAO,MAAM,eAAe,iYAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/trpc/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,wEAAwE;AACxE,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAiB,CAAC,MAAM,EAAE,CAAC;AAErD,mCAAmC;AACnC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;AAErC,sCAAsC;AACtC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,SAAS,CAAC","sourcesContent":["import { initTRPC } from '@trpc/server';\nimport type { CreateContext } from './createContextFactory.js';\n\n// Initialization of tRPC backend. Should be done only once per backend!\nconst t = initTRPC.context<CreateContext>().create();\n\n/** Reusable TRPC router helper. */\nexport const createRouter = t.router;\n\n/** Reusable TRPC procedure helper. */\nexport const publicProcedure = t.procedure;\n"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/trpc/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAKxC,wEAAwE;AACxE,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAiB,CAAC,MAAM,EAAE,CAAC;AAErD,mCAAmC;AACnC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;AAErC,sCAAsC;AACtC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,SAAS,CAAC","sourcesContent":["import { initTRPC } from '@trpc/server';\nimport type { Context } from '../types/Context.js';\n\nexport type CreateContext = () => Promise<Context>;\n\n// Initialization of tRPC backend. Should be done only once per backend!\nconst t = initTRPC.context<CreateContext>().create();\n\n/** Reusable TRPC router helper. */\nexport const createRouter = t.router;\n\n/** Reusable TRPC procedure helper. */\nexport const publicProcedure = t.procedure;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createCloudpackServer.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE;IACP,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B,EACD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,eAAe,CAAC,CAgD1B"}
1
+ {"version":3,"file":"createCloudpackServer.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE;IACP,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B,EACD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,eAAe,CAAC,CAgD1B"}
@@ -1,7 +1,6 @@
1
1
  import { applyWSSHandler } from '@trpc/server/adapters/ws';
2
2
  import getPort from 'get-port';
3
3
  import { WebSocketServer } from 'ws';
4
- import { createContextFactory } from './createContextFactory.js';
5
4
  import { createHTTPServer } from './httpAdapter.js';
6
5
  import cors from 'cors';
7
6
  import { getDomain } from '@ms-cloudpack/create-express-app';
@@ -16,7 +15,7 @@ export async function createCloudpackServer(options, context) {
16
15
  if (portArg && !portArg.includes(port)) {
17
16
  throw new Error(`No ports from range ${JSON.stringify(portArg)} are available`);
18
17
  }
19
- const createContext = await createContextFactory(context);
18
+ const createContext = () => Promise.resolve(context);
20
19
  const hostname = getDomain(context.session.config?.server?.domain);
21
20
  const https = context.session.config?.server?.https;
22
21
  const procedures = Object.fromEntries(Object.entries(apis).map(([name, api]) => [name, api.procedure]));
@@ -1 +1 @@
1
- {"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAGC,EACD,OAAgB;IAEhB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACvG,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1E,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,SAAS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AS,GAAG,GAAG,CAAC;IAErC,OAAO;QACL,GAAG;QACH,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC1C,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;gBACpD,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACpD,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { applyWSSHandler } from '@trpc/server/adapters/ws';\nimport getPort from 'get-port';\nimport { WebSocketServer } from 'ws';\nimport { createContextFactory } from './createContextFactory.js';\nimport { createHTTPServer } from './httpAdapter.js';\nimport cors from 'cors';\nimport { getDomain } from '@ms-cloudpack/create-express-app';\nimport type { Context } from '../types/Context.js';\nimport * as apis from '../apis/index.js';\nimport { createRouter } from './common.js';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport interface CloudpackServer {\n url: string;\n close: () => Promise<void>;\n}\n\n/**\n * Creates a cloudpack server that can be used to communicate with the cloudpack client using trpc.\n */\nexport async function createCloudpackServer(\n options: {\n /** Custom port(s) to try for the API server. */\n port?: number | number[];\n },\n context: Context,\n): Promise<CloudpackServer> {\n const portArg = Array.isArray(options.port) ? options.port : options.port ? [options.port] : undefined;\n const port = await getPort({ port: portArg || [9890, 9891, 9892, 9893] });\n if (portArg && !portArg.includes(port)) {\n throw new Error(`No ports from range ${JSON.stringify(portArg)} are available`);\n }\n\n const createContext = await createContextFactory(context);\n const hostname = getDomain(context.session.config?.server?.domain);\n const https = context.session.config?.server?.https;\n\n const procedures = Object.fromEntries(Object.entries(apis).map(([name, api]) => [name, api.procedure]));\n // AppRouter is the correct type, but doesn't get inferred correctly after Object.entries\n const router = createRouter(procedures) as unknown as AppRouter;\n\n const { server, listen } = await createHTTPServer({\n domain: hostname,\n middleware: cors(),\n router,\n createContext,\n https,\n cwd: context.session.config.appPath,\n });\n\n await listen(port, hostname);\n\n const wss = new WebSocketServer({ server });\n\n applyWSSHandler<AppRouter>({\n wss,\n router,\n createContext,\n });\n\n const webSocketProtocol = https ? 'wss' : 'ws';\n const url = `${webSocketProtocol}://${hostname}:${port}`;\n context.session.urls.apiServer = url;\n\n return {\n url,\n close: async () => {\n await new Promise<void>((resolve, reject) => {\n wss.clients.forEach((socket) => socket.terminate());\n wss.close((err) => (err ? reject(err) : resolve()));\n server.close();\n });\n },\n };\n}\n"]}
1
+ {"version":3,"file":"createCloudpackServer.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAGC,EACD,OAAgB;IAEhB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAA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,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAE5C,eAAe,CAAY;QACzB,GAAG;QACH,MAAM;QACN,aAAa;KACd,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,MAAM,GAAG,GAAG,GAAG,iBAAiB,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;IACzD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC;IAErC,OAAO;QACL,GAAG;QACH,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC1C,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;gBACpD,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACpD,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { applyWSSHandler } from '@trpc/server/adapters/ws';\nimport getPort from 'get-port';\nimport { WebSocketServer } from 'ws';\nimport { createHTTPServer } from './httpAdapter.js';\nimport cors from 'cors';\nimport { getDomain } from '@ms-cloudpack/create-express-app';\nimport type { Context } from '../types/Context.js';\nimport * as apis from '../apis/index.js';\nimport { createRouter } from './common.js';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport interface CloudpackServer {\n url: string;\n close: () => Promise<void>;\n}\n\n/**\n * Creates a cloudpack server that can be used to communicate with the cloudpack client using trpc.\n */\nexport async function createCloudpackServer(\n options: {\n /** Custom port(s) to try for the API server. */\n port?: number | number[];\n },\n context: Context,\n): Promise<CloudpackServer> {\n const portArg = Array.isArray(options.port) ? options.port : options.port ? [options.port] : undefined;\n const port = await getPort({ port: portArg || [9890, 9891, 9892, 9893] });\n if (portArg && !portArg.includes(port)) {\n throw new Error(`No ports from range ${JSON.stringify(portArg)} are available`);\n }\n\n const createContext = () => Promise.resolve(context);\n const hostname = getDomain(context.session.config?.server?.domain);\n const https = context.session.config?.server?.https;\n\n const procedures = Object.fromEntries(Object.entries(apis).map(([name, api]) => [name, api.procedure]));\n // AppRouter is the correct type, but doesn't get inferred correctly after Object.entries\n const router = createRouter(procedures) as unknown as AppRouter;\n\n const { server, listen } = await createHTTPServer({\n domain: hostname,\n middleware: cors(),\n router,\n createContext,\n https,\n cwd: context.session.config.appPath,\n });\n\n await listen(port, hostname);\n\n const wss = new WebSocketServer({ server });\n\n applyWSSHandler<AppRouter>({\n wss,\n router,\n createContext,\n });\n\n const webSocketProtocol = https ? 'wss' : 'ws';\n const url = `${webSocketProtocol}://${hostname}:${port}`;\n context.session.urls.apiServer = url;\n\n return {\n url,\n close: async () => {\n await new Promise<void>((resolve, reject) => {\n wss.clients.forEach((socket) => socket.terminate());\n wss.close((err) => (err ? reject(err) : resolve()));\n server.close();\n });\n },\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { BundleMode, BundleResult } from '@ms-cloudpack/common-types';
1
+ import type { BundleMode, BundleResult, TargetEnvironment } from '@ms-cloudpack/common-types';
2
2
  import type { BundleInfo } from './BundleInfo.js';
3
3
  /**
4
4
  * Tracks a given bundle request and its result.
@@ -20,6 +20,8 @@ export interface BundleRequest {
20
20
  isIncremental?: boolean;
21
21
  /** Bundle mode */
22
22
  mode: BundleMode;
23
+ /** Target environment for the bundle. */
24
+ targetEnvironment: TargetEnvironment;
23
25
  /** Result of bundling */
24
26
  result?: Omit<BundleResult, 'inputPath'> & {
25
27
  /** Input path. Will be unset if the package couldn't be found or had an unhandled error. */
@@ -1 +1 @@
1
- {"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0FAA0F;IAC1F,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,UAAU,EAAE,OAAO,CAAC;IACpB,oDAAoD;IACpD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB;IAClB,IAAI,EAAE,UAAU,CAAC;IACjB,yBAAyB;IACzB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;QACzC,4FAA4F;QAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,UAAU,CAAC;QAClB,YAAY,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,SAAS,CAAC;KAC3D,CAAC;IACF,2EAA2E;IAE3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,+DAA+D;IAC/D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iCAAiC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
1
+ {"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC9F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0FAA0F;IAC1F,EAAE,EAAE,MAAM,CAAC;IAEX,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IAEpB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAEhB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IAEpB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,4DAA4D;IAC5D,UAAU,EAAE,OAAO,CAAC;IAEpB,oDAAoD;IACpD,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,kBAAkB;IAClB,IAAI,EAAE,UAAU,CAAC;IAEjB,yCAAyC;IACzC,iBAAiB,EAAE,iBAAiB,CAAC;IAErC,yBAAyB;IACzB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;QACzC,4FAA4F;QAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,UAAU,CAAC;QAClB,YAAY,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,SAAS,CAAC;KAC3D,CAAC;IAEF,2EAA2E;IAE3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,+DAA+D;IAC/D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B,iCAAiC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleMode, BundleResult } from '@ms-cloudpack/common-types';\nimport type { BundleInfo } from './BundleInfo.js';\n\n/**\n * Tracks a given bundle request and its result.\n */\nexport interface BundleRequest {\n /** ID for the bundle. This will usually be the package path, or occasionally the hash. */\n id: string;\n /** Package name being bundled */\n packageName: string;\n /** Package version being bundled */\n version: string;\n /** Absolute path to the package */\n packagePath: string;\n /** Absolute path for the bundle output */\n outputPath?: string;\n /** Whether this is an external package (in node_modules) */\n isExternal: boolean;\n /** Whether we should force the incremental flag. */\n isIncremental?: boolean;\n /** Bundle mode */\n mode: BundleMode;\n /** Result of bundling */\n result?: Omit<BundleResult, 'inputPath'> & {\n /** Input path. Will be unset if the package couldn't be found or had an unhandled error. */\n inputPath?: string;\n hash?: string;\n info?: BundleInfo;\n bundleSource?: 'remote-cache' | 'local-cache' | 'bundler';\n };\n /** Whether the result was retrieved from the cache (set while bundling) */\n // TODO: this seems like it should be a property of the result?\n resultFromCache?: boolean;\n /** Whether to disable source maps */\n disableSourceMaps?: boolean;\n /** Whether to scan the bundled code for imports and exports */\n shouldGetBundleInfo?: boolean;\n /** Whether to disable caching */\n disableCache?: boolean;\n}\n"]}
1
+ {"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleMode, BundleResult, TargetEnvironment } from '@ms-cloudpack/common-types';\nimport type { BundleInfo } from './BundleInfo.js';\n\n/**\n * Tracks a given bundle request and its result.\n */\nexport interface BundleRequest {\n /** ID for the bundle. This will usually be the package path, or occasionally the hash. */\n id: string;\n\n /** Package name being bundled */\n packageName: string;\n\n /** Package version being bundled */\n version: string;\n\n /** Absolute path to the package */\n packagePath: string;\n\n /** Absolute path for the bundle output */\n outputPath?: string;\n\n /** Whether this is an external package (in node_modules) */\n isExternal: boolean;\n\n /** Whether we should force the incremental flag. */\n isIncremental?: boolean;\n\n /** Bundle mode */\n mode: BundleMode;\n\n /** Target environment for the bundle. */\n targetEnvironment: TargetEnvironment;\n\n /** Result of bundling */\n result?: Omit<BundleResult, 'inputPath'> & {\n /** Input path. Will be unset if the package couldn't be found or had an unhandled error. */\n inputPath?: string;\n hash?: string;\n info?: BundleInfo;\n bundleSource?: 'remote-cache' | 'local-cache' | 'bundler';\n };\n\n /** Whether the result was retrieved from the cache (set while bundling) */\n // TODO: this seems like it should be a property of the result?\n resultFromCache?: boolean;\n\n /** Whether to disable source maps */\n disableSourceMaps?: boolean;\n\n /** Whether to scan the bundled code for imports and exports */\n shouldGetBundleInfo?: boolean;\n\n /** Whether to disable caching */\n disableCache?: boolean;\n}\n"]}
@@ -4,21 +4,22 @@ import type { Watcher } from '@ms-cloudpack/file-watcher';
4
4
  import type { TaskReporter } from '@ms-cloudpack/task-reporter';
5
5
  import type { TelemetryClient } from '@ms-cloudpack/telemetry';
6
6
  import type { TaskRunner } from '../utilities/TaskRunner.js';
7
- import type { PackageImportPaths } from '@ms-cloudpack/import-map';
8
7
  import type { RemoteCacheClient } from '@ms-cloudpack/remote-cache';
9
- /** Context for Cloudpack API server procedures. */
8
+ /** Context for Cloudpack API server procedures and other APIs. */
10
9
  export interface Context {
11
10
  session: Session;
11
+ /** Data bus for sending notifications to the client. */
12
12
  bus: DataBus;
13
13
  telemetryClient: TelemetryClient;
14
14
  reporter: TaskReporter;
15
- watcher: Watcher;
15
+ /** Only used by `ensurePackageBundled`. */
16
+ watcher?: Watcher;
16
17
  packages: PackageDefinitionsCache;
17
18
  taskRunner: TaskRunner;
18
- packageImportPaths: PackageImportPaths;
19
19
  packageHashes: PackageHashesCache;
20
20
  remoteCacheClient?: RemoteCacheClient;
21
- dispose(): void | Promise<void>;
21
+ /** Only set if `watcher` is initialized. */
22
+ dispose?: () => void | Promise<void>;
22
23
  }
23
24
  /**
24
25
  * Helper for partial context and session objects.
@@ -1 +1 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACvG,OAAO,KAAK,E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,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,kEAAkE;AAClE,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,wDAAwD;IACxD,GAAG,EAAE,OAAO,CAAC;IACb,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,YAAY,CAAC;IACvB,2CAA2C;IAE3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,EAAE,kBAAkB,CAAC;IAClC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAED;;;;GAIG;AACH,MAAM,MAAM,cAAc,CACxB,YAAY,SAAS,MAAM,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EACnD,YAAY,SAAS,MAAM,OAAO,IAChC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG;IAChC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;CACtC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":"","sourcesContent":["import type { PackageDefinitionsCache, PackageHashesCache, Session } from '@ms-cloudpack/common-types';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\nimport type { Watcher } from '@ms-cloudpack/file-watcher';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { TaskRunner } from '../utilities/TaskRunner.js';\nimport type { PackageImportPaths } from '@ms-cloudpack/import-map';\nimport type { RemoteCacheClient } from '@ms-cloudpack/remote-cache';\n\n/** Context for Cloudpack API server procedures. */\nexport interface Context {\n session: Session;\n bus: DataBus;\n telemetryClient: TelemetryClient;\n reporter: TaskReporter;\n watcher: Watcher;\n packages: PackageDefinitionsCache;\n taskRunner: TaskRunner;\n packageImportPaths: PackageImportPaths;\n packageHashes: PackageHashesCache;\n remoteCacheClient?: RemoteCacheClient;\n // This typically returns a promise. Allow a non-promise for convenience for tests.\n dispose(): void | Promise<void>;\n}\n\n/**\n * Helper for partial context and session objects.\n * First param is context keys and second is session keys.\n * (This can make it easier to tell which properties are actually used where.)\n */\nexport type PartialContext<\n TContextKeys extends keyof Omit<Context, 'session'>,\n TSessionKeys extends keyof Session,\n> = Pick<Context, TContextKeys> & {\n session: Pick<Session, TSessionKeys>;\n};\n"]}
1
+ {"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/types/Context.ts"],"names":[],"mappings":"","sourcesContent":["import type { PackageDefinitionsCache, PackageHashesCache, Session } from '@ms-cloudpack/common-types';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\nimport type { Watcher } from '@ms-cloudpack/file-watcher';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { TaskRunner } from '../utilities/TaskRunner.js';\nimport type { RemoteCacheClient } from '@ms-cloudpack/remote-cache';\n\n/** Context for Cloudpack API server procedures and other APIs. */\nexport interface Context {\n session: Session;\n /** Data bus for sending notifications to the client. */\n bus: DataBus;\n telemetryClient: TelemetryClient;\n reporter: TaskReporter;\n /** Only used by `ensurePackageBundled`. */\n // TODO: split to a separate type for non-tRPC APIs\n watcher?: Watcher;\n packages: PackageDefinitionsCache;\n taskRunner: TaskRunner;\n packageHashes: PackageHashesCache;\n remoteCacheClient?: RemoteCacheClient;\n /** Only set if `watcher` is initialized. */\n dispose?: () => void | Promise<void>;\n}\n\n/**\n * Helper for partial context and session objects.\n * First param is context keys and second is session keys.\n * (This can make it easier to tell which properties are actually used where.)\n */\nexport type PartialContext<\n TContextKeys extends keyof Omit<Context, 'session'>,\n TSessionKeys extends keyof Session,\n> = Pick<Context, TContextKeys> & {\n session: Pick<Session, TSessionKeys>;\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { TaskStartDescription } from './TaskStartDescription.js';
2
2
  import type { TaskEndDescription } from './TaskEndDescription.js';
3
3
  import type { TaskMessage } from './TaskMessage.js';
4
+ /** Task for `TaskRunner`. */
4
5
  export interface Task<TReturn> {
5
6
  name: string;
6
7
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/types/Task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,IAAI,CAAC,OAAO;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,WAAW,EAAE,GAAG,SAAS,CAAC;IAC5C,mBAAmB,CAAC,EAAE,MAAM,oBAAoB,CAAC;IACjD,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,KAAK,kBAAkB,CAAC;CACzE"}
1
+ {"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../src/types/Task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,6BAA6B;AAC7B,MAAM,WAAW,IAAI,CAAC,OAAO;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,WAAW,EAAE,GAAG,SAAS,CAAC;IAC5C,mBAAmB,CAAC,EAAE,MAAM,oBAAoB,CAAC;IACjD,iBAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,KAAK,kBAAkB,CAAC;CACzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"Task.js","sourceRoot":"","sources":["../../src/types/Task.ts"],"names":[],"mappings":"","sourcesContent":["import type { TaskStartDescription } from './TaskStartDescription.js';\nimport type { TaskEndDescription } from './TaskEndDescription.js';\nimport type { TaskMessage } from './TaskMessage.js';\n\nexport interface Task<TReturn> {\n name: string;\n id: string;\n dir?: string;\n execute: () => Promise<TReturn | undefined>;\n clear?: () => void;\n watch?: boolean;\n dispose?: () => Promise<void>;\n onDispose?: () => void;\n getErrors?: () => TaskMessage[] | undefined;\n getStartDescription?: () => TaskStartDescription;\n getEndDescription?: (result: TReturn | undefined) => TaskEndDescription;\n}\n"]}
1
+ {"version":3,"file":"Task.js","sourceRoot":"","sources":["../../src/types/Task.ts"],"names":[],"mappings":"","sourcesContent":["import type { TaskStartDescription } from './TaskStartDescription.js';\nimport type { TaskEndDescription } from './TaskEndDescription.js';\nimport type { TaskMessage } from './TaskMessage.js';\n\n/** Task for `TaskRunner`. */\nexport interface Task<TReturn> {\n name: string;\n id: string;\n dir?: string;\n execute: () => Promise<TReturn | undefined>;\n clear?: () => void;\n watch?: boolean;\n dispose?: () => Promise<void>;\n onDispose?: () => void;\n getErrors?: () => TaskMessage[] | undefined;\n getStartDescription?: () => TaskStartDescription;\n getEndDescription?: (result: TReturn | undefined) => TaskEndDescription;\n}\n"]}
@@ -1,26 +1,37 @@
1
- import type { TaskOptions } from '../types/TaskOptions.js';
2
1
  import type { Task } from '../types/Task.js';
3
- import type { TaskRunnerContext } from '../types/TaskRunnerContext.js';
2
+ import type { DataBus } from '@ms-cloudpack/data-bus';
4
3
  /**
5
- * TaskRunner class manages the state of Tasks.
6
- * This class is to be called by the api server.
4
+ * TaskRunner tracks the status of tasks, manages concurrency, allows reusing task results,
5
+ * and sends notifications about task status to the data bus (currently just used for `start`).
6
+ *
7
+ * NOTE: To enable data bus notifications, you must call `connectToBus()`.
8
+ * `createApiContext` does this with the `taskRunner` passed in.
7
9
  */
8
10
  export declare class TaskRunner {
9
- private _context;
11
+ private _bus;
10
12
  private _queue;
11
13
  private _taskStats;
12
14
  private _pendingTasks;
13
15
  private _completedTasks;
14
16
  private _requiresRerun;
15
17
  private _prevTasks;
16
- constructor(context?: TaskRunnerContext);
18
+ constructor();
17
19
  /**
18
- * The add method enqueues a Task and returns its Promise.
19
- * If a Task with the same id has already been processed,
20
- * it returns either the result or the promise.
21
- * Rerun flag forces the Task to be run again.
20
+ * Connects the TaskRunner to the data bus. Tasks will still run without this, but they won't
21
+ * send any notifications to a client (which only matters if a client is listening, e.g.
22
+ * the browser while running `start`).
22
23
  */
23
- add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn>;
24
+ connectToBus(bus: DataBus): void;
25
+ /**
26
+ * Enqueue a task and return its result promise.
27
+ *
28
+ * If a task with the same `id` was already added, it returns either the previous result
29
+ * (if completed) or the promise (if pending). Pass `options.rerun` to force re-running.
30
+ */
31
+ add<TReturn>(task: Task<TReturn>, options?: {
32
+ rerun?: boolean;
33
+ priority?: number;
34
+ }): Promise<TReturn>;
24
35
  /**
25
36
  * The remove method disposes a task if available
26
37
  * and then removes it from the TaskRunner.
@@ -1 +1 @@
1
- {"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE;;;GAGG;AACH,qBAAa,UAAU;IAGrB,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAY;IAE9B,OAAO,CAAC,aAAa,CAA4B;IAEjD,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;gBAE/B,OAAO,CAAC,EAAE,iBAAiB;IAevC;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAmE1E;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAkBxB;;OAEG;IACH,KAAK,IAAI,IAAI;IAYb,2CAA2C;IAC3C,MAAM,IAAI,IAAI;IAId,sDAAsD;IACtD,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,CAAC,YAAY;IAmCpB;;OAEG;IACH,OAAO,CAAC,UAAU;CA6BnB"}
1
+ {"version":3,"file":"TaskRunner.d.ts","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAM7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAgC;IACrD,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,cAAc,CAAc;IAEpC,OAAO,CAAC,UAAU,CAAyB;;IAW3C;;;;OAIG;IACI,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI;IAIvC;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EACT,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EACnB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GACA,OAAO,CAAC,OAAO,CAAC;IAiEnB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAgBxB;;OAEG;IACH,KAAK,IAAI,IAAI;IASb,2CAA2C;IAC3C,MAAM,IAAI,IAAI;IAId,sDAAsD;IACtD,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,OAAO,CAAC,YAAY;IAoCpB;;OAEG;IACH,OAAO,CAAC,UAAU;CA8BnB"}
@@ -2,33 +2,38 @@ import PQueue from 'p-queue';
2
2
  import { getDefaultTaskStats } from './getDefaultTaskStats.js';
3
3
  import { taskListSource, taskStatsSource } from '../index.browser.js';
4
4
  /**
5
- * TaskRunner class manages the state of Tasks.
6
- * This class is to be called by the api server.
5
+ * TaskRunner tracks the status of tasks, manages concurrency, allows reusing task results,
6
+ * and sends notifications about task status to the data bus (currently just used for `start`).
7
+ *
8
+ * NOTE: To enable data bus notifications, you must call `connectToBus()`.
9
+ * `createApiContext` does this with the `taskRunner` passed in.
7
10
  */
8
11
  export class TaskRunner {
9
- constructor(context) {
10
- this._context = context;
12
+ constructor() {
11
13
  this._queue = new PQueue({ concurrency: 10 });
12
14
  this._taskStats = getDefaultTaskStats();
13
15
  this._pendingTasks = new Map();
14
16
  this._completedTasks = new Map();
15
17
  this._requiresRerun = new Set();
16
18
  this._prevTasks = new Map();
17
- if (this._context) {
18
- const { bus, session } = this._context;
19
- bus.publish([session.id, 'status'], this._taskStats);
20
- }
21
19
  }
22
20
  /**
23
- * The add method enqueues a Task and returns its Promise.
24
- * If a Task with the same id has already been processed,
25
- * it returns either the result or the promise.
26
- * Rerun flag forces the Task to be run again.
21
+ * Connects the TaskRunner to the data bus. Tasks will still run without this, but they won't
22
+ * send any notifications to a client (which only matters if a client is listening, e.g.
23
+ * the browser while running `start`).
24
+ */
25
+ connectToBus(bus) {
26
+ this._bus = bus;
27
+ }
28
+ /**
29
+ * Enqueue a task and return its result promise.
30
+ *
31
+ * If a task with the same `id` was already added, it returns either the previous result
32
+ * (if completed) or the promise (if pending). Pass `options.rerun` to force re-running.
27
33
  */
28
34
  add(task, options) {
29
35
  const { name, id, execute } = task;
30
- const { rerun, watch, priority } = options || {};
31
- watch?.();
36
+ const { rerun, priority } = options || {};
32
37
  if (!this._prevTasks.get(id)) {
33
38
  this._prevTasks.set(id, task);
34
39
  }
@@ -98,8 +103,6 @@ export class TaskRunner {
98
103
  if (this._pendingTasks.has(id)) {
99
104
  this._pendingTasks.delete(id);
100
105
  this._taskStats.remainingTasks = this._pendingTasks.size;
101
- const { bus, session } = this._context || {};
102
- bus && session && bus.publish([session.id, 'status'], this._taskStats);
103
106
  }
104
107
  this._completedTasks.delete(id);
105
108
  }
@@ -108,11 +111,7 @@ export class TaskRunner {
108
111
  */
109
112
  clear() {
110
113
  this._taskStats = getDefaultTaskStats();
111
- if (this._context) {
112
- const { bus, session } = this._context;
113
- bus.publish([session.id, 'status'], this._taskStats);
114
- bus.publish(taskListSource, { tasks: [] });
115
- }
114
+ this._bus?.publish(taskListSource, { tasks: [] });
116
115
  for (const id of this._prevTasks.keys()) {
117
116
  this.remove(id);
118
117
  }
@@ -129,9 +128,9 @@ export class TaskRunner {
129
128
  * Internal method to report the start of a task to the bus.
130
129
  */
131
130
  _reportStart(id, description) {
132
- if (!this._context)
131
+ if (!this._bus)
133
132
  return;
134
- const { bus } = this._context;
133
+ const bus = this._bus;
135
134
  const { tasks } = bus.getData(taskListSource.path) || { tasks: [] };
136
135
  const index = tasks.findIndex((t) => t.id === id);
137
136
  const previousDescription = tasks[index];
@@ -163,9 +162,9 @@ export class TaskRunner {
163
162
  * Internal method to report the end of a task to the bus.
164
163
  */
165
164
  _reportEnd(id, description) {
166
- if (!this._context)
165
+ if (!this._bus)
167
166
  return;
168
- const { bus } = this._context;
167
+ const bus = this._bus;
169
168
  const { tasks } = bus.getData(taskListSource.path) || { tasks: [] };
170
169
  const index = tasks.findIndex((t) => t.id === id);
171
170
  const previousDescription = tasks[index];
@@ -1 +1 @@
1
- {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAOA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAwB,MAAM,qBAAqB,CAAC;AAE5F;;;GAGG;AACH,MAAM,OAAO,UAAU;IAcrB,YAAY,OAA2B;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;Q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AAE,EAAE,CAAC;QAC9E,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,MAAM,mBAAmB,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAEjC,IAAI,mBAAmB,EAAE,CAAC;YACxB,IAAI,CAAC,UAAU,CAAC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACzD,IAAI,CAAC,UAAU,CAAC,WAAW,IAAI,WAAW,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC;YAChE,IAAI,CAAC,UAAU,CAAC,aAAa,IAAI,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;YAEpE,KAAK,CAAC,KAAK,CAAC,GAAG;gBACb,GAAG,mBAAmB;gBACtB,GAAG,WAAW;gBACd,MAAM,EAAE,UAAU;gBAClB,oBAAoB,EAAE,GAAG,GAAG,mBAAmB,CAAC,SAAS;gBACzD,WAAW,EAAE,GAAG;aACjB,CAAC;YAEF,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;gBACzC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC;YAClC,CAAC;YAED,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9C,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TaskStartDescription } from '../types/TaskStartDescription.js';\nimport type { TaskEndDescription } from '../types/TaskEndDescription.js';\nimport type { TaskOptions } from '../types/TaskOptions.js';\nimport type { Task } from '../types/Task.js';\nimport type { TaskRunnerContext } from '../types/TaskRunnerContext.js';\nimport type { TaskStats } from '../types/TaskStats.js';\nimport type { TaskList } from '../types/TaskList.js';\nimport PQueue from 'p-queue';\nimport { getDefaultTaskStats } from './getDefaultTaskStats.js';\nimport { taskListSource, taskStatsSource, type TaskDescription } from '../index.browser.js';\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 // Context is used to publish task status to the bus,\n // so it is optional, as it is not needed during init or testing.\n private _context: TaskRunnerContext | undefined;\n private _queue: PQueue;\n private _taskStats: TaskStats;\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(context?: TaskRunnerContext) {\n this._context = context;\n this._queue = new PQueue({ concurrency: 10 });\n this._taskStats = getDefaultTaskStats();\n this._pendingTasks = new Map();\n this._completedTasks = new Map();\n this._requiresRerun = new Set();\n this._prevTasks = new Map();\n\n if (this._context) {\n const { bus, session } = this._context;\n bus.publish([session.id, 'status'], this._taskStats);\n }\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, priority } = 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 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 return pending;\n }\n\n const resultPromise: Promise<TReturn> = (async () => {\n let taskResult: TReturn | undefined;\n\n do {\n // Delete from rerun list (if present).\n this._requiresRerun.delete(id);\n\n taskResult = await this._queue.add(\n execute,\n // Removes void from return type.\n // Read more on: https://github.com/sindresorhus/p-queue/issues/175\n { throwOnTimeout: true, priority },\n );\n } while (this._requiresRerun.has(id));\n\n // Delete from pending list.\n this._pendingTasks.delete(id);\n if (task.getEndDescription) {\n this._reportEnd(id, task.getEndDescription(taskResult));\n }\n\n // Extra check to ensure that the task returned a value.\n // It should never throw, if it does we have a bug.\n if (taskResult === undefined) {\n throw new Error(`Task \"${name}:${id}\" returned undefined, without throwing an error, which was unexpected.`);\n }\n\n // Update finished Tasks.\n this._completedTasks.set(id, taskResult);\n\n return taskResult;\n })();\n\n this._pendingTasks.set(id, resultPromise);\n this._completedTasks.delete(id);\n if (task.getStartDescription) {\n this._reportStart(id, task.getStartDescription());\n }\n\n return resultPromise;\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 intended 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 console.debug(`Error disposing task: ${id}`);\n });\n this._prevTasks.get(id)?.onDispose?.();\n this._prevTasks.delete(id);\n this._requiresRerun.delete(id);\n if (this._pendingTasks.has(id)) {\n this._pendingTasks.delete(id);\n this._taskStats.remainingTasks = this._pendingTasks.size;\n const { bus, session } = this._context || {};\n bus && session && bus.publish([session.id, 'status'], this._taskStats);\n }\n this._completedTasks.delete(id);\n }\n /**\n * The clear method disposes all tasks and clears the TaskRunner.\n */\n clear(): void {\n this._taskStats = getDefaultTaskStats();\n if (this._context) {\n const { bus, session } = this._context;\n bus.publish([session.id, 'status'], this._taskStats);\n bus.publish(taskListSource, { tasks: [] });\n }\n for (const id of this._prevTasks.keys()) {\n this.remove(id);\n }\n }\n\n /** Pauses the TaskRunner (for testing). */\n _pause(): void {\n this._queue.pause();\n }\n\n /** Starts or resumes the TaskRunner (for testing). */\n _start(): void {\n this._queue.start();\n }\n\n /**\n * Internal method to report the start of a task to the bus.\n */\n private _reportStart(id: string, description: TaskStartDescription): void {\n if (!this._context) return;\n const { bus } = this._context;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (!previousDescription) {\n this._taskStats.totalTasks++;\n }\n\n if (previousDescription?.status === 'complete') {\n this._taskStats.totalErrors -= previousDescription.errors?.length || 0;\n this._taskStats.totalWarnings -= previousDescription.warnings?.length || 0;\n }\n\n this._taskStats.remainingTasks = this._pendingTasks.size;\n this._taskStats.status = 'pending';\n\n const task: TaskDescription = {\n ...description,\n status: 'pending',\n startTime: now,\n };\n if (index === -1) {\n tasks.push(task);\n } else {\n tasks[index] = task;\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n\n /**\n * Internal method to report the end of a task to the bus.\n */\n private _reportEnd(id: string, description: TaskEndDescription): void {\n if (!this._context) return;\n const { bus } = this._context;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (previousDescription) {\n this._taskStats.remainingTasks = this._pendingTasks.size;\n this._taskStats.totalErrors += description?.errors?.length || 0;\n this._taskStats.totalWarnings += description?.warnings?.length || 0;\n\n tasks[index] = {\n ...previousDescription,\n ...description,\n status: 'complete',\n durationMilliseconds: now - previousDescription.startTime,\n lastUpdated: now,\n };\n\n if (this._taskStats.remainingTasks === 0) {\n this._taskStats.status = 'idle';\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":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C;YAChE,IAAI,CAAC,UAAU,CAAC,aAAa,IAAI,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;YAEpE,KAAK,CAAC,KAAK,CAAC,GAAG;gBACb,GAAG,mBAAmB;gBACtB,GAAG,WAAW;gBACd,MAAM,EAAE,UAAU;gBAClB,oBAAoB,EAAE,GAAG,GAAG,mBAAmB,CAAC,SAAS;gBACzD,WAAW,EAAE,GAAG;aACjB,CAAC;YAEF,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,KAAK,CAAC,EAAE,CAAC;gBACzC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC;YAClC,CAAC;YAED,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9C,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { TaskStartDescription } from '../types/TaskStartDescription.js';\nimport type { TaskEndDescription } from '../types/TaskEndDescription.js';\nimport type { Task } from '../types/Task.js';\nimport type { TaskStats } from '../types/TaskStats.js';\nimport type { TaskList } from '../types/TaskList.js';\nimport PQueue from 'p-queue';\nimport { getDefaultTaskStats } from './getDefaultTaskStats.js';\nimport { taskListSource, taskStatsSource, type TaskDescription } from '../index.browser.js';\nimport type { DataBus } from '@ms-cloudpack/data-bus';\n\n/**\n * TaskRunner tracks the status of tasks, manages concurrency, allows reusing task results,\n * and sends notifications about task status to the data bus (currently just used for `start`).\n *\n * NOTE: To enable data bus notifications, you must call `connectToBus()`.\n * `createApiContext` does this with the `taskRunner` passed in.\n */\nexport class TaskRunner {\n private _bus: DataBus | undefined;\n private _queue: PQueue;\n private _taskStats: TaskStats;\n private _pendingTasks: Map<string, Promise<unknown>>;\n private _completedTasks: Map<string, unknown>;\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._taskStats = getDefaultTaskStats();\n this._pendingTasks = new Map();\n this._completedTasks = new Map();\n this._requiresRerun = new Set();\n this._prevTasks = new Map();\n }\n\n /**\n * Connects the TaskRunner to the data bus. Tasks will still run without this, but they won't\n * send any notifications to a client (which only matters if a client is listening, e.g.\n * the browser while running `start`).\n */\n public connectToBus(bus: DataBus): void {\n this._bus = bus;\n }\n\n /**\n * Enqueue a task and return its result promise.\n *\n * If a task with the same `id` was already added, it returns either the previous result\n * (if completed) or the promise (if pending). Pass `options.rerun` to force re-running.\n */\n add<TReturn>(\n task: Task<TReturn>,\n options?: {\n rerun?: boolean;\n priority?: number;\n },\n ): Promise<TReturn> {\n const { name, id, execute } = task;\n const { rerun, priority } = options || {};\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 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 return pending;\n }\n\n const resultPromise: Promise<TReturn> = (async () => {\n let taskResult: TReturn | undefined;\n\n do {\n // Delete from rerun list (if present).\n this._requiresRerun.delete(id);\n\n taskResult = await this._queue.add(\n execute,\n // Removes void from return type.\n // Read more on: https://github.com/sindresorhus/p-queue/issues/175\n { throwOnTimeout: true, priority },\n );\n } while (this._requiresRerun.has(id));\n\n // Delete from pending list.\n this._pendingTasks.delete(id);\n if (task.getEndDescription) {\n this._reportEnd(id, task.getEndDescription(taskResult));\n }\n\n // Extra check to ensure that the task returned a value.\n // It should never throw, if it does we have a bug.\n if (taskResult === undefined) {\n throw new Error(`Task \"${name}:${id}\" returned undefined, without throwing an error, which was unexpected.`);\n }\n\n // Update finished Tasks.\n this._completedTasks.set(id, taskResult);\n\n return taskResult;\n })();\n\n this._pendingTasks.set(id, resultPromise);\n this._completedTasks.delete(id);\n if (task.getStartDescription) {\n this._reportStart(id, task.getStartDescription());\n }\n\n return resultPromise;\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 intended 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 console.debug(`Error disposing task: ${id}`);\n });\n this._prevTasks.get(id)?.onDispose?.();\n this._prevTasks.delete(id);\n this._requiresRerun.delete(id);\n if (this._pendingTasks.has(id)) {\n this._pendingTasks.delete(id);\n this._taskStats.remainingTasks = this._pendingTasks.size;\n }\n this._completedTasks.delete(id);\n }\n /**\n * The clear method disposes all tasks and clears the TaskRunner.\n */\n clear(): void {\n this._taskStats = getDefaultTaskStats();\n this._bus?.publish(taskListSource, { tasks: [] });\n\n for (const id of this._prevTasks.keys()) {\n this.remove(id);\n }\n }\n\n /** Pauses the TaskRunner (for testing). */\n _pause(): void {\n this._queue.pause();\n }\n\n /** Starts or resumes the TaskRunner (for testing). */\n _start(): void {\n this._queue.start();\n }\n\n /**\n * Internal method to report the start of a task to the bus.\n */\n private _reportStart(id: string, description: TaskStartDescription): void {\n if (!this._bus) return;\n\n const bus = this._bus;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (!previousDescription) {\n this._taskStats.totalTasks++;\n }\n\n if (previousDescription?.status === 'complete') {\n this._taskStats.totalErrors -= previousDescription.errors?.length || 0;\n this._taskStats.totalWarnings -= previousDescription.warnings?.length || 0;\n }\n\n this._taskStats.remainingTasks = this._pendingTasks.size;\n this._taskStats.status = 'pending';\n\n const task: TaskDescription = {\n ...description,\n status: 'pending',\n startTime: now,\n };\n if (index === -1) {\n tasks.push(task);\n } else {\n tasks[index] = task;\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n\n /**\n * Internal method to report the end of a task to the bus.\n */\n private _reportEnd(id: string, description: TaskEndDescription): void {\n if (!this._bus) return;\n\n const bus = this._bus;\n const { tasks } = bus.getData<TaskList>(taskListSource.path) || { tasks: [] };\n const index = tasks.findIndex((t) => t.id === id);\n const previousDescription = tasks[index];\n const now = new Date().getTime();\n\n if (previousDescription) {\n this._taskStats.remainingTasks = this._pendingTasks.size;\n this._taskStats.totalErrors += description?.errors?.length || 0;\n this._taskStats.totalWarnings += description?.warnings?.length || 0;\n\n tasks[index] = {\n ...previousDescription,\n ...description,\n status: 'complete',\n durationMilliseconds: now - previousDescription.startTime,\n lastUpdated: now,\n };\n\n if (this._taskStats.remainingTasks === 0) {\n this._taskStats.status = 'idle';\n }\n\n bus.publish(taskStatsSource, this._taskStats);\n bus.publish(taskListSource, { tasks });\n }\n }\n}\n"]}
@@ -54,7 +54,7 @@ export async function bundleTask(options, context) {
54
54
  */
55
55
  async function bundleTaskInternal(options, context) {
56
56
  const { bundleRequest, force, hash, sourceHash } = options;
57
- const { packageName, version } = bundleRequest;
57
+ const { packageName, version, targetEnvironment } = bundleRequest;
58
58
  const { packageHashes, packages, session } = context;
59
59
  const { config } = session;
60
60
  const { mode } = config;
@@ -94,12 +94,13 @@ async function bundleTaskInternal(options, context) {
94
94
  const bundleOptions = {
95
95
  bundler,
96
96
  minify: mode === 'production',
97
+ targetEnvironment,
97
98
  bundlerOptions,
98
99
  inputPath: packagePath,
99
100
  outputPath,
100
101
  incremental: isIncremental !== undefined ? isIncremental : false,
101
102
  sourcemap: !disableSourceMaps,
102
- entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),
103
+ entries: await getEntriesMapFromPackage({ inputPath: packagePath, targetEnvironment }, { packages, config }),
103
104
  inlined: inlinedDependencies,
104
105
  external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),
105
106
  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AAU,GAAG,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAE9E,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC;YACrC,UAAU;YACV,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,WAAW;YAC7C,UAAU;YACV,UAAU;YACV,WAAW;SACZ,CAAC,CAAC;QAEH,aAAa,CAAC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC;QAEvC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;YACzB,8DAA8D;YAC9D,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,EAAE,UAAU,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { bundle, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\nimport { formatBundleTaskResult } from './formatBundleTaskResult.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { writeStubForDensityEntries } from './writeStubForDensityEntries.js';\n\n/**\n * Options for a bundle task.\n */\nexport interface BundleTaskOptions {\n /** Force a bundle to be rerun */\n force?: boolean;\n /** Hash to avoid re-computing */\n hash?: string;\n /** Source hash to avoid recomputing */\n sourceHash?: string;\n /** Retry count for the task */\n retryCount?: number;\n bundleRequest: BundleRequest;\n}\n\nexport type BundleTaskContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient' | 'remoteCacheClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, session } = context;\n const { sequence } = session;\n const { retryCount } = options;\n\n const task = reporter.addTask(\n `Bundle ${formatPackageName({ name: packageName, version })}${retryCount ? ` (retry ${retryCount})` : ''}`,\n );\n\n try {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\n await bundleTaskInternal(options, context);\n\n span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n packageName: bundleRequest.packageName,\n packageVersion: bundleRequest.version,\n bundleSource: bundleRequest.result?.bundleSource,\n bundler: bundleRequest.result?.bundler,\n bundlerVersion: bundleRequest.result?.bundlerVersion,\n });\n });\n } catch (err) {\n // If an unexpected error is thrown, add it to the result.\n // This ensures consistent handling of either actual bundler errors or exceptions.\n bundleRequest.result ??= {};\n bundleRequest.result.errors ??= [];\n bundleRequest.result.errors.push({\n text: `Unexpected exception while bundling: ${(err as Error).stack || String(err)}`,\n source: 'bundleTask',\n });\n }\n\n task.complete(formatBundleTaskResult(bundleRequest));\n}\n\n/**\n * Actually read the result from the cache or call `bundle()`.\n * NOTE: The result is returned by mutating `options.bundleRequest.result`.\n */\nasync function bundleTaskInternal(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version } = bundleRequest;\n const { packageHashes, packages, session } = context;\n const { config } = session;\n const { mode } = config;\n\n // If force is set, dispose the existing result.\n if (force && bundleRequest.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(\n { packageName, version, inputPath: packagePath, outputPath },\n context,\n );\n }\n\n const cacheValidationHash = !isExternal\n ? sourceHash || (await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true }))\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n unsafeCjsExportNames,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n bundler,\n minify: mode === 'production',\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n unsafeCjsExportNames,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n bundleSource: 'bundler',\n };\n\n if (bundlerCapabilities?.density) {\n // Get export maps that need to be written as stubs for density.\n // If there are density exports, write stubs for them.\n const densityErrors = await writeStubForDensityEntries({\n options: {\n packageName,\n packagePath,\n result: bundleInternalResult,\n },\n context: { packages, config },\n });\n\n // Add any errors to the result.\n if (densityErrors.length > 0) {\n bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityErrors];\n }\n }\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, { packages, config });\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n packagePath,\n });\n\n bundleRequest.result.info = bundleInfo;\n\n if (config.logBundleInfo) {\n // Write to cache for future use. (Ignore the promise result.)\n void writeJson(path.join(outputPath, 'bundle-info.json'), bundleInfo);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,w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CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { bundle, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\nimport { formatBundleTaskResult } from './formatBundleTaskResult.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { writeStubForDensityEntries } from './writeStubForDensityEntries.js';\n\n/**\n * Options for a bundle task.\n */\nexport interface BundleTaskOptions {\n /** Force a bundle to be rerun */\n force?: boolean;\n /** Hash to avoid re-computing */\n hash?: string;\n /** Source hash to avoid recomputing */\n sourceHash?: string;\n /** Retry count for the task */\n retryCount?: number;\n bundleRequest: BundleRequest;\n}\n\nexport type BundleTaskContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient' | 'remoteCacheClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, session } = context;\n const { sequence } = session;\n const { retryCount } = options;\n\n const task = reporter.addTask(\n `Bundle ${formatPackageName({ name: packageName, version })}${retryCount ? ` (retry ${retryCount})` : ''}`,\n );\n\n try {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\n await bundleTaskInternal(options, context);\n\n span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n packageName: bundleRequest.packageName,\n packageVersion: bundleRequest.version,\n bundleSource: bundleRequest.result?.bundleSource,\n bundler: bundleRequest.result?.bundler,\n bundlerVersion: bundleRequest.result?.bundlerVersion,\n });\n });\n } catch (err) {\n // If an unexpected error is thrown, add it to the result.\n // This ensures consistent handling of either actual bundler errors or exceptions.\n bundleRequest.result ??= {};\n bundleRequest.result.errors ??= [];\n bundleRequest.result.errors.push({\n text: `Unexpected exception while bundling: ${(err as Error).stack || String(err)}`,\n source: 'bundleTask',\n });\n }\n\n task.complete(formatBundleTaskResult(bundleRequest));\n}\n\n/**\n * Actually read the result from the cache or call `bundle()`.\n * NOTE: The result is returned by mutating `options.bundleRequest.result`.\n */\nasync function bundleTaskInternal(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version, targetEnvironment } = bundleRequest;\n const { packageHashes, packages, session } = context;\n const { config } = session;\n const { mode } = config;\n\n // If force is set, dispose the existing result.\n if (force && bundleRequest.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(\n { packageName, version, inputPath: packagePath, outputPath },\n context,\n );\n }\n\n const cacheValidationHash = !isExternal\n ? sourceHash || (await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true }))\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n unsafeCjsExportNames,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n bundler,\n minify: mode === 'production',\n targetEnvironment,\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath, targetEnvironment }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n unsafeCjsExportNames,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n bundleSource: 'bundler',\n };\n\n if (bundlerCapabilities?.density) {\n // Get export maps that need to be written as stubs for density.\n // If there are density exports, write stubs for them.\n const densityErrors = await writeStubForDensityEntries({\n options: {\n packageName,\n packagePath,\n result: bundleInternalResult,\n },\n context: { packages, config },\n });\n\n // Add any errors to the result.\n if (densityErrors.length > 0) {\n bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityErrors];\n }\n }\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, { packages, config });\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n packagePath,\n });\n\n bundleRequest.result.info = bundleInfo;\n\n if (config.logBundleInfo) {\n // Write to cache for future use. (Ignore the promise result.)\n void writeJson(path.join(outputPath, 'bundle-info.json'), bundleInfo);\n }\n }\n}\n"]}
@@ -6,5 +6,5 @@ import type { PartialContext } from '../types/Context.js';
6
6
  * Create a bundle task (internally calls `bundleTask()`) that can be executed by the server's TaskRunner.
7
7
  * This allows active tasks to be tracked remotely (e.g. in the browser) and allows the user to cancel tasks.
8
8
  */
9
- export declare function createBundleTask(options: BundleTaskOptions, context: BundleTaskContext & PartialContext<'packageHashes' | 'packageImportPaths', keyof BundleTaskContext['session'] | 'importMap' | 'urls'>): Task<BundleRequest>;
9
+ export declare function createBundleTask(options: BundleTaskOptions, context: BundleTaskContext & PartialContext<'packageHashes', keyof BundleTaskContext['session'] | 'importMap' | 'packageImportPaths' | 'urls'>): Task<BundleRequest>;
10
10
  //# sourceMappingURL=createBundleTask.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createBundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAc,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,GACxB,cAAc,CAAC,eAAe,GAAG,oBAAoB,EAAE,MAAM,iBAAiB,CAAC,SAAS,CAAC,GAAG,WAAW,GAAG,MAAM,CAAC,GAClH,IAAI,CAAC,aAAa,CAAC,CAgErB"}
1
+ {"version":3,"file":"createBundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAc,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,GACxB,cAAc,CAAC,eAAe,EAAE,MAAM,iBAAiB,CAAC,SAAS,CAAC,GAAG,WAAW,GAAG,oBAAoB,GAAG,MAAM,CAAC,GAClH,IAAI,CAAC,aAAa,CAAC,CAgErB"}
@@ -1 +1 @@
1
- {"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,UAAU,EAAkD,MAAM,iBAAiB,CAAC;AAG7F;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA0B,EAC1B,OACmH;IAEnH,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IAC5E,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC3C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gBACtC,OAAO;YACT,CAAC;YAED,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YAEjC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAE7E,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC;QACnC,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC;QACpC,CAAC;QACD,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM;QAC7C,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC1B,EAAE;YACF,kCAAkC;YAClC,IAAI;YACJ,SAAS,EAAE,WAAW,IAAI,EAAE;SAC7B,CAAC;QACF,iBAAiB,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YAClC,EAAE;YACF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;YAClC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ;YACtC,UAAU,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,IAAI,EAAE;SACnD,CAAC;KACH,CAAC;AACJ,CAAC","sourcesContent":["import { addImportMapHash } from '@ms-cloudpack/import-map';\nimport fs from 'fs';\nimport path from 'path';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { Task } from '../types/Task.js';\nimport { bundleTask, type BundleTaskContext, type BundleTaskOptions } from './bundleTask.js';\nimport type { PartialContext } from '../types/Context.js';\n\n/**\n * Create a bundle task (internally calls `bundleTask()`) that can be executed by the server's TaskRunner.\n * This allows active tasks to be tracked remotely (e.g. in the browser) and allows the user to cancel tasks.\n */\nexport function createBundleTask(\n options: BundleTaskOptions,\n context: BundleTaskContext &\n PartialContext<'packageHashes' | 'packageImportPaths', keyof BundleTaskContext['session'] | 'importMap' | 'urls'>,\n): Task<BundleRequest> {\n const { bundleRequest } = options;\n const { id, packageName, version, packagePath, isExternal } = bundleRequest;\n const { packageHashes, session } = context;\n const { hash, sourceHash } = options;\n const name = `Bundle ${packageName}@${version}`;\n\n return {\n // Name for task runner logging.\n name,\n id,\n dir: `${path.join(packagePath, 'src')}`,\n watch: !isExternal,\n async execute(): Promise<BundleRequest> {\n await bundleTask(options, context);\n\n try {\n // Add a hash to the import map for this package.\n // (Read the session properties here rather than above because they might not be set yet.)\n const importMap = session.importMap;\n const { bundleServer, appServer } = session.urls;\n\n if (importMap && bundleServer && appServer) {\n const importMapHash =\n sourceHash || hash || (await packageHashes.get({ packagePath, isSourceHashingEnabled: !isExternal }));\n addImportMapHash(\n { packageName, version, hash: importMapHash },\n { ...context, ...session, importMap, urls: { bundleServer, appServer } },\n );\n }\n } catch (e) {\n console.error(`Error adding hash to import map for ${bundleRequest.packagePath}:`, (e as Error).stack || e);\n }\n\n return bundleRequest;\n },\n clear: () => {\n if (!bundleRequest.result?.outputPath) {\n return;\n }\n\n bundleRequest.result.dispose?.();\n\n fs.rmSync(bundleRequest.result.outputPath, { recursive: true, force: true });\n\n bundleRequest.result = undefined;\n },\n onDispose: () => {\n bundleRequest.result?.dispose?.();\n },\n getErrors: () => bundleRequest.result?.errors,\n getStartDescription: () => ({\n id,\n // Name to display in the overlay.\n name,\n inputPath: packagePath || '',\n }),\n getEndDescription: (taskResult) => ({\n id,\n errors: taskResult?.result?.errors,\n warnings: taskResult?.result?.warnings,\n outputPath: bundleRequest.result?.outputPath || '',\n }),\n };\n}\n"]}
1
+ {"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,UAAU,EAAkD,MAAM,iBAA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AC;YACH,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,uCAAuC,aAAa,CAAC,WAAW,GAAG,EAAG,CAAW,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;YAC9G,CAAC;YAED,OAAO,aAAa,CAAC;QACvB,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;gBACtC,OAAO;YACT,CAAC;YAED,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YAEjC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAE7E,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC;QACnC,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC;QACpC,CAAC;QACD,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM;QAC7C,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC1B,EAAE;YACF,kCAAkC;YAClC,IAAI;YACJ,SAAS,EAAE,WAAW,IAAI,EAAE;SAC7B,CAAC;QACF,iBAAiB,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YAClC,EAAE;YACF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;YAClC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ;YACtC,UAAU,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,IAAI,EAAE;SACnD,CAAC;KACH,CAAC;AACJ,CAAC","sourcesContent":["import { addImportMapHash } from '@ms-cloudpack/import-map';\nimport fs from 'fs';\nimport path from 'path';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { Task } from '../types/Task.js';\nimport { bundleTask, type BundleTaskContext, type BundleTaskOptions } from './bundleTask.js';\nimport type { PartialContext } from '../types/Context.js';\n\n/**\n * Create a bundle task (internally calls `bundleTask()`) that can be executed by the server's TaskRunner.\n * This allows active tasks to be tracked remotely (e.g. in the browser) and allows the user to cancel tasks.\n */\nexport function createBundleTask(\n options: BundleTaskOptions,\n context: BundleTaskContext &\n PartialContext<'packageHashes', keyof BundleTaskContext['session'] | 'importMap' | 'packageImportPaths' | 'urls'>,\n): Task<BundleRequest> {\n const { bundleRequest } = options;\n const { id, packageName, version, packagePath, isExternal } = bundleRequest;\n const { packageHashes, session } = context;\n const { hash, sourceHash } = options;\n const name = `Bundle ${packageName}@${version}`;\n\n return {\n // Name for task runner logging.\n name,\n id,\n dir: `${path.join(packagePath, 'src')}`,\n watch: !isExternal,\n async execute(): Promise<BundleRequest> {\n await bundleTask(options, context);\n\n try {\n // Add a hash to the import map for this package.\n // (Read the session properties here rather than above because they might not be set yet.)\n const importMap = session.importMap;\n const { bundleServer, appServer } = session.urls;\n\n if (importMap && bundleServer && appServer) {\n const importMapHash =\n sourceHash || hash || (await packageHashes.get({ packagePath, isSourceHashingEnabled: !isExternal }));\n addImportMapHash(\n { packageName, version, hash: importMapHash },\n { ...context, ...session, importMap, urls: { bundleServer, appServer } },\n );\n }\n } catch (e) {\n console.error(`Error adding hash to import map for ${bundleRequest.packagePath}:`, (e as Error).stack || e);\n }\n\n return bundleRequest;\n },\n clear: () => {\n if (!bundleRequest.result?.outputPath) {\n return;\n }\n\n bundleRequest.result.dispose?.();\n\n fs.rmSync(bundleRequest.result.outputPath, { recursive: true, force: true });\n\n bundleRequest.result = undefined;\n },\n onDispose: () => {\n bundleRequest.result?.dispose?.();\n },\n getErrors: () => bundleRequest.result?.errors,\n getStartDescription: () => ({\n id,\n // Name to display in the overlay.\n name,\n inputPath: packagePath || '',\n }),\n getEndDescription: (taskResult) => ({\n id,\n errors: taskResult?.result?.errors,\n warnings: taskResult?.result?.warnings,\n outputPath: bundleRequest.result?.outputPath || '',\n }),\n };\n}\n"]}