@ms-cloudpack/api-server 0.61.4 → 0.61.5

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 (35) hide show
  1. package/lib/apis/ensurePackageBundled.js +0 -1
  2. package/lib/apis/ensurePackageBundled.js.map +1 -1
  3. package/lib/common/createMockContext.d.ts +35 -0
  4. package/lib/common/createMockContext.d.ts.map +1 -0
  5. package/lib/common/createMockContext.js +87 -0
  6. package/lib/common/createMockContext.js.map +1 -0
  7. package/lib/common/createMockSession.d.ts +26 -0
  8. package/lib/common/createMockSession.d.ts.map +1 -0
  9. package/lib/common/createMockSession.js +49 -0
  10. package/lib/common/createMockSession.js.map +1 -0
  11. package/lib/index.d.ts +2 -0
  12. package/lib/index.d.ts.map +1 -1
  13. package/lib/index.js +2 -0
  14. package/lib/index.js.map +1 -1
  15. package/lib/task-scheduler/TaskScheduler.js +3 -16
  16. package/lib/task-scheduler/TaskScheduler.js.map +1 -1
  17. package/lib/trpc/common.d.ts +6 -14
  18. package/lib/trpc/common.d.ts.map +1 -1
  19. package/lib/trpc/connectBusToClient.d.ts +3 -3
  20. package/lib/trpc/connectBusToClient.d.ts.map +1 -1
  21. package/lib/trpc/connectBusToClient.js +7 -9
  22. package/lib/trpc/connectBusToClient.js.map +1 -1
  23. package/lib/trpc/createCloudpackClient.d.ts +2 -2
  24. package/lib/trpc/createCloudpackClient.d.ts.map +1 -1
  25. package/lib/trpc/createCloudpackClient.js +6 -7
  26. package/lib/trpc/createCloudpackClient.js.map +1 -1
  27. package/lib/types/BundleRequest.d.ts +1 -1
  28. package/lib/types/BundleRequest.d.ts.map +1 -1
  29. package/lib/types/BundleRequest.js.map +1 -1
  30. package/lib/utilities/TaskRunner.js +8 -0
  31. package/lib/utilities/TaskRunner.js.map +1 -1
  32. package/lib/utilities/createBundleTask.d.ts.map +1 -1
  33. package/lib/utilities/createBundleTask.js +6 -1
  34. package/lib/utilities/createBundleTask.js.map +1 -1
  35. package/package.json +4 -4
@@ -90,7 +90,6 @@ async function ensurePackageBundledInternal(params, ctx) {
90
90
  }
91
91
  }
92
92
  const bundleRequest = {
93
- // TODO: David had this as follows--think about what it should be
94
93
  id: hash ?? `${packageEntry.path}--env:${targetEnvironment}`,
95
94
  packagePath: packageEntry.path,
96
95
  packageName: name,
@@ -1 +1 @@
1
- {"version":3,"file":"ensurePackageBundled.js","sourceRoot":"","sources":["../../src/apis/ensurePackageBundled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAwElF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAgC,EAChC,GAAgC;IAEhC,MAAM,OAAO,GAAiC,EAAE,CAAC;IACjD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEjD,4BAA4B;IAC5B,IAAI,MAAkC,CAAC;IACvC,IAAI,gBAA6C,CAAC;IAClD,IAAI,CAAC;QACH,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,MAAM,4BAA4B,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACpH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC;YAClC,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;SAClC,CAAC;IACJ,CAAC;IAED,4BAA4B;IAC5B,qGAAqG;IACrG,uDAAuD;IACvD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,MAAM,YAAY,GAAG,IAAI,OAAO,CAA+B,CAAC,O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AK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IAC7G,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,kGAAkG","sourcesContent":["import { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { notifyReload } from '../utilities/notifyReload.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { createBundleTask } from '../utilities/createBundleTask.js';\nimport type { Context } from '../types/Context.js';\nimport type { WatchOptions } from '@ms-cloudpack/file-watcher';\nimport { getConsumedDependencies } from '../utilities/getConsumedDependencies.js';\nimport type { TargetEnvironment, WithOptional } from '@ms-cloudpack/common-types';\n\n/**\n * Input for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledInput\n extends Pick<BundleRequest, 'outputPath' | 'version' | 'disableSourceMaps' | 'shouldGetBundleInfo'> {\n /** Package name */\n name: string;\n /**\n * Target environment for the bundle.\n * @default 'browser'\n */\n targetEnvironment?: TargetEnvironment;\n /** Whether to also ensure dependencies are bundled */\n enqueueDependencies?: boolean;\n /** Whether to re-run the bundle task */\n shouldRerun?: boolean;\n /**\n * Whether to watch for changes (internal packages only).\n * NOTE: requires `ctx.bus` and `ctx.watcher` to be set.\n */\n shouldWatch?: boolean;\n /** Whether to force re-bundling */\n shouldForce?: boolean;\n /** Whether to disable caching. */\n disableCache?: boolean;\n /** Whether to support incremental rebuilds. Defaults to true for internal libraries. */\n isIncremental?: boolean;\n /**\n * Whether to use a hash as the bundle id instead of the path.\n * Reduces performance when used with shouldForce as it hashes twice,\n * but eliminates task cache artifacts when handling many apps.\n */\n useHashAsId?: boolean;\n /** Priority for bundling. Greater priority will be scheduled first (defaults to 0). */\n priority?: number;\n}\n\n/**\n * Result of ensuring a single package is bundled.\n */\nexport interface EnsurePackageBundledResult\n extends Omit<NonNullable<BundleRequest['result']>, 'rebuild' | 'dispose' | 'bundlerName' | 'inputPath'> {\n /** Package name */\n name: string;\n /** Package version */\n version: string;\n /** Package dependency names (prod and peer) */\n dependencies?: string[];\n /** Whether the package is external (not defined in this repo). Unset if it's not found. */\n isExternal?: boolean;\n /** Absolute path of the package. Will be unset if the package couldn't be found. */\n inputPath?: string;\n}\n\n/**\n * Complete output for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledOutput {\n /** Result of bundling this package */\n result: EnsurePackageBundledResult;\n /** Results of bundling dependencies */\n dependencies: Promise<EnsurePackageBundledResult[]>;\n}\n\n/**\n * Context for `ensurePackageBundled`. `bus` and `watcher` are only needed if `shouldWatch` is true.\n */\nexport type EnsurePackageBundledContext = WithOptional<Context, 'bus' | 'watcher'>;\n\n/**\n * Checks if the package is bundled or needs bundling, and returns the result.\n * For internal packages, we also notify the watcher to monitor for code changes.\n */\nexport async function ensurePackageBundled(\n input: EnsurePackageBundledInput,\n ctx: EnsurePackageBundledContext,\n): Promise<EnsurePackageBundledOutput> {\n const results: EnsurePackageBundledResult[] = [];\n const visited = new Set<`${string}@${string}`>();\n\n // Bundle the package itself\n let result: EnsurePackageBundledResult;\n let mainDependencies: EnsurePackageBundledInput[];\n try {\n ({ result, dependencyInputs: mainDependencies } = await ensurePackageBundledInternal({ ...input, visited }, ctx));\n } catch (err) {\n return {\n result: getErrorResult(input, err),\n dependencies: Promise.resolve([]),\n };\n }\n\n // Enqueue main dependencies\n // TODO: should processing this queue have a rate limit? right now if enqueueDependencies is enabled,\n // `await dependencies` will fire off all deps at once.\n let pending = 0;\n const dependencies = new Promise<EnsurePackageBundledResult[]>((resolve) => {\n const enqueue = (dependencyInputs: EnsurePackageBundledInput[]) => {\n for (const dependencyInput of dependencyInputs) {\n pending++;\n\n void ensurePackageBundledInternal({ ...dependencyInput, visited }, ctx)\n .then((dependencyBundleResult) => {\n // Save result and enqueue this dep's deps\n results.push(dependencyBundleResult.result);\n enqueue(dependencyBundleResult.dependencyInputs);\n })\n .catch((err) => {\n // If there's an error (most likely that the dependency wasn't found in the resolve map),\n // save it in a result instead of throwing. This generally gives better logging.\n results.push(getErrorResult(dependencyInput, err));\n })\n .then(() => {\n pending--;\n if (!pending) {\n resolve(results);\n }\n });\n }\n };\n\n enqueue(mainDependencies);\n });\n\n return {\n result,\n dependencies,\n };\n}\n\nasync function ensurePackageBundledInternal(\n params: EnsurePackageBundledInput & {\n visited: Set<`${string}@${string}`>;\n },\n ctx: EnsurePackageBundledContext,\n): Promise<{ result: EnsurePackageBundledResult; dependencyInputs: EnsurePackageBundledInput[] }> {\n const { taskRunner, session, watcher, packageHashes, bus, telemetryClient } = ctx;\n const { resolveMap, config } = session;\n const {\n name,\n version,\n shouldWatch,\n disableSourceMaps = config.features?.disableSourceMaps,\n enqueueDependencies = config.features?.enqueueDependencies,\n outputPath,\n shouldGetBundleInfo,\n shouldRerun,\n shouldForce,\n disableCache,\n isIncremental,\n useHashAsId,\n priority,\n targetEnvironment = 'browser',\n visited,\n } = params;\n\n const dependencyInputs: EnsurePackageBundledInput[] = [];\n\n visited.add(`${name}@${version}`);\n\n // First, we find the resolve map entry. This helps us resolve the physical location of the package\n // according to the resolveMap used in the session. (This can change based on linking.)\n const packageEntry = findResolveMapEntry({ packageName: name, version, resolveMap });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${name} in the resolve map.`);\n }\n\n const isExternal = !!packageEntry.isExternal;\n\n let hash: string | undefined;\n let sourceHash: string | undefined;\n\n if (useHashAsId) {\n // If we are using the hash as the task id, we need to calculate it once and pass it to the task\n // to prevent a race condition in which we get a different hash than the one used in the task id.\n hash = await packageHashes.get({\n packagePath: packageEntry.path,\n isSourceHashingEnabled: false,\n shouldRecalculate: true,\n targetEnvironment,\n });\n\n if (!packageEntry.isExternal) {\n // We only need the source hash for internal packages for cache validation.\n sourceHash = await packageHashes.get({\n packagePath: packageEntry.path,\n isSourceHashingEnabled: true,\n shouldRecalculate: true,\n targetEnvironment,\n });\n }\n }\n\n const bundleRequest: BundleRequest = {\n // TODO: David had this as follows--think about what it should be\n id: hash ?? `${packageEntry.path}--env:${targetEnvironment}`,\n packagePath: packageEntry.path,\n packageName: name,\n targetEnvironment,\n isExternal,\n isIncremental,\n outputPath,\n version,\n disableSourceMaps,\n shouldGetBundleInfo: shouldGetBundleInfo || enqueueDependencies,\n disableCache,\n mode: config.mode,\n };\n\n // Make priority negative to have retry count set to positive values.\n const retryCount = priority ? -1 * priority : undefined;\n\n const task = createBundleTask({ bundleRequest, force: shouldForce, hash, sourceHash, retryCount }, ctx);\n\n // TODO: Add lage scheduling back.\n const { result } = await taskRunner.add<BundleRequest>(task, { rerun: shouldRerun, priority });\n\n if (!result) {\n throw new Error('Bundle failed, no result');\n }\n\n // For internal packages, make sure we're watching the source to re-trigger bundling.\n if (shouldWatch && !isExternal) {\n if (!bus || !watcher) {\n throw new Error('bus and watcher must be provided in context if shouldWatch is true (this is a bug).');\n }\n\n const definition = await ctx.packages.get(packageEntry.path);\n const watchOptions: WatchOptions = {\n id: bundleRequest.id,\n path: packageEntry.path,\n watchPaths: definition.cloudpack?.inputPaths,\n };\n\n const onPackageChange = async () => {\n const watchedResult = await taskRunner.add<BundleRequest>(task, { rerun: true });\n\n // If the result was successful, notify potential clients for reload.\n if (watchedResult.result?.errors?.length === 0) {\n await notifyReload({ reason: 'on-package-change' }, { bus, session, telemetryClient });\n }\n };\n watcher.watch(watchOptions, () => {\n void onPackageChange();\n });\n }\n\n // If enabled, enqueue dependencies.\n if (enqueueDependencies && result.info) {\n for (const dependencyName of getConsumedDependencies(result.info)) {\n const dependencyVersion = packageEntry.dependencies[dependencyName];\n\n // If we've already visited this package from another package, skip it.\n if (visited.has(`${dependencyName}@${dependencyVersion}`)) {\n continue;\n }\n\n dependencyInputs.push({\n name: dependencyName,\n version: dependencyVersion,\n shouldWatch,\n enqueueDependencies,\n });\n }\n }\n\n return {\n result: {\n version,\n name,\n isExternal,\n ...result,\n },\n dependencyInputs,\n };\n}\n\nfunction getErrorResult(input: EnsurePackageBundledInput, error: unknown): EnsurePackageBundledResult {\n const text = `Error thrown while bundling: ${error instanceof Error ? error.stack || error.message : error}`;\n return {\n name: input.name,\n version: input.version,\n errors: [{ text, source: 'ensurePackageBundled' }],\n };\n}\n\n// This function doesn't have an attached procedure because it's never called via the TRPC server.\n"]}
1
+ {"version":3,"file":"ensurePackageBundled.js","sourceRoot":"","sources":["../../src/apis/ensurePackageBundled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAwElF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAgC,EAChC,GAAgC;IAEhC,MAAM,OAAO,GAAiC,EAAE,CAAC;IACjD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IAEjD,4BAA4B;IAC5B,IAAI,MAAkC,CAAC;IACvC,IAAI,gBAA6C,CAAC;IAClD,IAAI,CAAC;QACH,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,MAAM,4BAA4B,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACpH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC;YAClC,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;SAClC,CAAC;IACJ,CAAC;IAED,4BAA4B;IAC5B,qGAAqG;IACrG,uDAAuD;IACvD,IAAI,OAAO,GAA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Ac;IACtE,MAAM,IAAI,GAAG,gCAAgC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IAC7G,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,kGAAkG","sourcesContent":["import { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { notifyReload } from '../utilities/notifyReload.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { createBundleTask } from '../utilities/createBundleTask.js';\nimport type { Context } from '../types/Context.js';\nimport type { WatchOptions } from '@ms-cloudpack/file-watcher';\nimport { getConsumedDependencies } from '../utilities/getConsumedDependencies.js';\nimport type { TargetEnvironment, WithOptional } from '@ms-cloudpack/common-types';\n\n/**\n * Input for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledInput\n extends Pick<BundleRequest, 'outputPath' | 'version' | 'disableSourceMaps' | 'shouldGetBundleInfo'> {\n /** Package name */\n name: string;\n /**\n * Target environment for the bundle.\n * @default 'browser'\n */\n targetEnvironment?: TargetEnvironment;\n /** Whether to also ensure dependencies are bundled */\n enqueueDependencies?: boolean;\n /** Whether to re-run the bundle task */\n shouldRerun?: boolean;\n /**\n * Whether to watch for changes (internal packages only).\n * NOTE: requires `ctx.bus` and `ctx.watcher` to be set.\n */\n shouldWatch?: boolean;\n /** Whether to force re-bundling */\n shouldForce?: boolean;\n /** Whether to disable caching. */\n disableCache?: boolean;\n /** Whether to support incremental rebuilds. Defaults to true for internal libraries. */\n isIncremental?: boolean;\n /**\n * Whether to use a hash as the bundle id instead of the path.\n * Reduces performance when used with shouldForce as it hashes twice,\n * but eliminates task cache artifacts when handling many apps.\n */\n useHashAsId?: boolean;\n /** Priority for bundling. Greater priority will be scheduled first (defaults to 0). */\n priority?: number;\n}\n\n/**\n * Result of ensuring a single package is bundled.\n */\nexport interface EnsurePackageBundledResult\n extends Omit<NonNullable<BundleRequest['result']>, 'rebuild' | 'dispose' | 'bundlerName' | 'inputPath'> {\n /** Package name */\n name: string;\n /** Package version */\n version: string;\n /** Package dependency names (prod and peer) */\n dependencies?: string[];\n /** Whether the package is external (not defined in this repo). Unset if it's not found. */\n isExternal?: boolean;\n /** Absolute path of the package. Will be unset if the package couldn't be found. */\n inputPath?: string;\n}\n\n/**\n * Complete output for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledOutput {\n /** Result of bundling this package */\n result: EnsurePackageBundledResult;\n /** Results of bundling dependencies */\n dependencies: Promise<EnsurePackageBundledResult[]>;\n}\n\n/**\n * Context for `ensurePackageBundled`. `bus` and `watcher` are only needed if `shouldWatch` is true.\n */\nexport type EnsurePackageBundledContext = WithOptional<Context, 'bus' | 'watcher'>;\n\n/**\n * Checks if the package is bundled or needs bundling, and returns the result.\n * For internal packages, we also notify the watcher to monitor for code changes.\n */\nexport async function ensurePackageBundled(\n input: EnsurePackageBundledInput,\n ctx: EnsurePackageBundledContext,\n): Promise<EnsurePackageBundledOutput> {\n const results: EnsurePackageBundledResult[] = [];\n const visited = new Set<`${string}@${string}`>();\n\n // Bundle the package itself\n let result: EnsurePackageBundledResult;\n let mainDependencies: EnsurePackageBundledInput[];\n try {\n ({ result, dependencyInputs: mainDependencies } = await ensurePackageBundledInternal({ ...input, visited }, ctx));\n } catch (err) {\n return {\n result: getErrorResult(input, err),\n dependencies: Promise.resolve([]),\n };\n }\n\n // Enqueue main dependencies\n // TODO: should processing this queue have a rate limit? right now if enqueueDependencies is enabled,\n // `await dependencies` will fire off all deps at once.\n let pending = 0;\n const dependencies = new Promise<EnsurePackageBundledResult[]>((resolve) => {\n const enqueue = (dependencyInputs: EnsurePackageBundledInput[]) => {\n for (const dependencyInput of dependencyInputs) {\n pending++;\n\n void ensurePackageBundledInternal({ ...dependencyInput, visited }, ctx)\n .then((dependencyBundleResult) => {\n // Save result and enqueue this dep's deps\n results.push(dependencyBundleResult.result);\n enqueue(dependencyBundleResult.dependencyInputs);\n })\n .catch((err) => {\n // If there's an error (most likely that the dependency wasn't found in the resolve map),\n // save it in a result instead of throwing. This generally gives better logging.\n results.push(getErrorResult(dependencyInput, err));\n })\n .then(() => {\n pending--;\n if (!pending) {\n resolve(results);\n }\n });\n }\n };\n\n enqueue(mainDependencies);\n });\n\n return {\n result,\n dependencies,\n };\n}\n\nasync function ensurePackageBundledInternal(\n params: EnsurePackageBundledInput & {\n visited: Set<`${string}@${string}`>;\n },\n ctx: EnsurePackageBundledContext,\n): Promise<{ result: EnsurePackageBundledResult; dependencyInputs: EnsurePackageBundledInput[] }> {\n const { taskRunner, session, watcher, packageHashes, bus, telemetryClient } = ctx;\n const { resolveMap, config } = session;\n const {\n name,\n version,\n shouldWatch,\n disableSourceMaps = config.features?.disableSourceMaps,\n enqueueDependencies = config.features?.enqueueDependencies,\n outputPath,\n shouldGetBundleInfo,\n shouldRerun,\n shouldForce,\n disableCache,\n isIncremental,\n useHashAsId,\n priority,\n targetEnvironment = 'browser',\n visited,\n } = params;\n\n const dependencyInputs: EnsurePackageBundledInput[] = [];\n\n visited.add(`${name}@${version}`);\n\n // First, we find the resolve map entry. This helps us resolve the physical location of the package\n // according to the resolveMap used in the session. (This can change based on linking.)\n const packageEntry = findResolveMapEntry({ packageName: name, version, resolveMap });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${name} in the resolve map.`);\n }\n\n const isExternal = !!packageEntry.isExternal;\n\n let hash: string | undefined;\n let sourceHash: string | undefined;\n\n if (useHashAsId) {\n // If we are using the hash as the task id, we need to calculate it once and pass it to the task\n // to prevent a race condition in which we get a different hash than the one used in the task id.\n hash = await packageHashes.get({\n packagePath: packageEntry.path,\n isSourceHashingEnabled: false,\n shouldRecalculate: true,\n targetEnvironment,\n });\n\n if (!packageEntry.isExternal) {\n // We only need the source hash for internal packages for cache validation.\n sourceHash = await packageHashes.get({\n packagePath: packageEntry.path,\n isSourceHashingEnabled: true,\n shouldRecalculate: true,\n targetEnvironment,\n });\n }\n }\n\n const bundleRequest: BundleRequest = {\n id: hash ?? `${packageEntry.path}--env:${targetEnvironment}`,\n packagePath: packageEntry.path,\n packageName: name,\n targetEnvironment,\n isExternal,\n isIncremental,\n outputPath,\n version,\n disableSourceMaps,\n shouldGetBundleInfo: shouldGetBundleInfo || enqueueDependencies,\n disableCache,\n mode: config.mode,\n };\n\n // Make priority negative to have retry count set to positive values.\n const retryCount = priority ? -1 * priority : undefined;\n\n const task = createBundleTask({ bundleRequest, force: shouldForce, hash, sourceHash, retryCount }, ctx);\n\n // TODO: Add lage scheduling back.\n const { result } = await taskRunner.add<BundleRequest>(task, { rerun: shouldRerun, priority });\n\n if (!result) {\n throw new Error('Bundle failed, no result');\n }\n\n // For internal packages, make sure we're watching the source to re-trigger bundling.\n if (shouldWatch && !isExternal) {\n if (!bus || !watcher) {\n throw new Error('bus and watcher must be provided in context if shouldWatch is true (this is a bug).');\n }\n\n const definition = await ctx.packages.get(packageEntry.path);\n const watchOptions: WatchOptions = {\n id: bundleRequest.id,\n path: packageEntry.path,\n watchPaths: definition.cloudpack?.inputPaths,\n };\n\n const onPackageChange = async () => {\n const watchedResult = await taskRunner.add<BundleRequest>(task, { rerun: true });\n\n // If the result was successful, notify potential clients for reload.\n if (watchedResult.result?.errors?.length === 0) {\n await notifyReload({ reason: 'on-package-change' }, { bus, session, telemetryClient });\n }\n };\n watcher.watch(watchOptions, () => {\n void onPackageChange();\n });\n }\n\n // If enabled, enqueue dependencies.\n if (enqueueDependencies && result.info) {\n for (const dependencyName of getConsumedDependencies(result.info)) {\n const dependencyVersion = packageEntry.dependencies[dependencyName];\n\n // If we've already visited this package from another package, skip it.\n if (visited.has(`${dependencyName}@${dependencyVersion}`)) {\n continue;\n }\n\n dependencyInputs.push({\n name: dependencyName,\n version: dependencyVersion,\n shouldWatch,\n enqueueDependencies,\n });\n }\n }\n\n return {\n result: {\n version,\n name,\n isExternal,\n ...result,\n },\n dependencyInputs,\n };\n}\n\nfunction getErrorResult(input: EnsurePackageBundledInput, error: unknown): EnsurePackageBundledResult {\n const text = `Error thrown while bundling: ${error instanceof Error ? error.stack || error.message : error}`;\n return {\n name: input.name,\n version: input.version,\n errors: [{ text, source: 'ensurePackageBundled' }],\n };\n}\n\n// This function doesn't have an attached procedure because it's never called via the TRPC server.\n"]}
@@ -0,0 +1,35 @@
1
+ import type { Context, PartialContext } from '../types/Context.js';
2
+ import { type CreateSessionOptions } from './createSession.js';
3
+ import { type TelemetryClient } from '@ms-cloudpack/telemetry';
4
+ import type { Session, WithOptional } from '@ms-cloudpack/common-types';
5
+ import { type CreateMockSessionOptions } from './createMockSession.js';
6
+ /**
7
+ * Create a mock context using info from the real filesystem.
8
+ * This is suitable for most tests using `ensurePackageBundled` and other scenarios.
9
+ * It will never include a file watcher, and only includes a data bus if `createDataBus` is true.
10
+ */
11
+ export declare function createMockContext(params: {
12
+ appPath: string;
13
+ sessionOptions?: Partial<Omit<CreateSessionOptions, 'config'>>;
14
+ /** No-op telemetry client. You might want to create this only once and pass it in. */
15
+ telemetryClient?: TelemetryClient;
16
+ /** If true, create a data bus and connect it to the task runner. */
17
+ dataBus?: boolean;
18
+ }): Promise<WithOptional<Context, 'bus' | 'watcher' | 'dispose' | 'remoteCacheClient'>>;
19
+ type AllowedContextKeys = Exclude<keyof Context, 'watcher' | 'dispose' | 'remoteCacheClient'>;
20
+ /**
21
+ * Initialize only the requested context keys (plus `'session'`) using info from the real filesystem.
22
+ *
23
+ * The returned `Session` object contains:
24
+ * - `config` from the filesystem (with defaults if there is no config)
25
+ * - `cachePath` set to `appPath/.cache` to prevent interference with the real cache or other tests
26
+ * - `resolveMap` will be an empty object unless `params.createResolveMap` is true
27
+ * - Basic mocks of other properties which can be updated as needed
28
+ */
29
+ export declare function createPartialMockContext<TContextKeys extends AllowedContextKeys>(params: CreateMockSessionOptions & {
30
+ context: TContextKeys[];
31
+ /** No-op telemetry client. You might want to create this only once and pass it in. */
32
+ telemetryClient?: TelemetryClient;
33
+ }): Promise<PartialContext<TContextKeys, keyof Session>>;
34
+ export {};
35
+ //# sourceMappingURL=createMockContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMockContext.d.ts","sourceRoot":"","sources":["../../src/common/createMockContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI1F,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,EAAqB,KAAK,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE1F;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/D,sFAAsF;IACtF,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oEAAoE;IACpE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,GAAG,SAAS,GAAG,SAAS,GAAG,mBAAmB,CAAC,CAAC,CAuBtF;AAED,KAAK,kBAAkB,GAAG,OAAO,CAAC,MAAM,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,mBAAmB,CAAC,CAAC;AAE9F;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAAC,YAAY,SAAS,kBAAkB,EACpF,MAAM,EAAE,wBAAwB,GAAG;IACjC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,sFAAsF;IACtF,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,GACA,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,OAAO,CAAC,CAAC,CAgDtD"}
@@ -0,0 +1,87 @@
1
+ import { createPackageDefinitions, readConfig } from '@ms-cloudpack/config';
2
+ import { createSession } from './createSession.js';
3
+ import { createNoOpTelemetryClient } from '@ms-cloudpack/telemetry';
4
+ import { noLoggingConfig, TaskReporter } from '@ms-cloudpack/task-reporter';
5
+ import { TaskRunner } from '../utilities/TaskRunner.js';
6
+ import { PackageHashes } from '@ms-cloudpack/package-hashes';
7
+ import { createDataBus } from '@ms-cloudpack/data-bus';
8
+ import path from 'path';
9
+ import { createMockSession } from './createMockSession.js';
10
+ /**
11
+ * Create a mock context using info from the real filesystem.
12
+ * This is suitable for most tests using `ensurePackageBundled` and other scenarios.
13
+ * It will never include a file watcher, and only includes a data bus if `createDataBus` is true.
14
+ */
15
+ export async function createMockContext(params) {
16
+ const { appPath, sessionOptions, telemetryClient = createNoOpTelemetryClient() } = params;
17
+ const config = await readConfig(appPath);
18
+ const packages = createPackageDefinitions({ config });
19
+ const reporter = new TaskReporter(noLoggingConfig);
20
+ const session = await createSession({ config, cachePath: path.join(appPath, '.cache'), ...sessionOptions }, { reporter, packages, telemetryClient });
21
+ const taskRunner = new TaskRunner();
22
+ const packageHashes = new PackageHashes({
23
+ cwd: appPath,
24
+ context: { config, packages, resolveMap: session.resolveMap },
25
+ });
26
+ let bus;
27
+ if (params.dataBus) {
28
+ bus = createDataBus();
29
+ taskRunner.connectToBus(bus);
30
+ }
31
+ return { reporter, taskRunner, telemetryClient, packageHashes, packages, session, bus };
32
+ }
33
+ /**
34
+ * Initialize only the requested context keys (plus `'session'`) using info from the real filesystem.
35
+ *
36
+ * The returned `Session` object contains:
37
+ * - `config` from the filesystem (with defaults if there is no config)
38
+ * - `cachePath` set to `appPath/.cache` to prevent interference with the real cache or other tests
39
+ * - `resolveMap` will be an empty object unless `params.createResolveMap` is true
40
+ * - Basic mocks of other properties which can be updated as needed
41
+ */
42
+ export async function createPartialMockContext(params) {
43
+ const { appPath } = params;
44
+ const contextKeys = params.context;
45
+ const config = await readConfig(appPath);
46
+ const packages = createPackageDefinitions({ config });
47
+ // Pass through the real config and package definitions when creating the session,
48
+ // to allow creating a real resolve map if needed.
49
+ const session = await createMockSession(params, { config, packages });
50
+ // Only create a reporter (which overrides console logging) if requested
51
+ const reporter = contextKeys.includes('reporter') ? new TaskReporter(noLoggingConfig) : undefined;
52
+ const context = { session };
53
+ for (const key of contextKeys) {
54
+ switch (key) {
55
+ case 'bus':
56
+ context.taskRunner ??= new TaskRunner();
57
+ context.bus = createDataBus();
58
+ context.taskRunner.connectToBus(context.bus);
59
+ break;
60
+ case 'reporter':
61
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
+ context.reporter = reporter;
63
+ break;
64
+ case 'taskRunner':
65
+ context.taskRunner ??= new TaskRunner();
66
+ break;
67
+ case 'packageHashes':
68
+ context.packageHashes = new PackageHashes({
69
+ cwd: appPath,
70
+ context: { config, packages, resolveMap: session.resolveMap },
71
+ });
72
+ break;
73
+ case 'packages':
74
+ context.packages = packages;
75
+ break;
76
+ case 'telemetryClient':
77
+ context.telemetryClient = params.telemetryClient || createNoOpTelemetryClient();
78
+ break;
79
+ case 'session':
80
+ break;
81
+ default:
82
+ throw new Error(`Unsupported context key: ${key}`);
83
+ }
84
+ }
85
+ return context;
86
+ }
87
+ //# sourceMappingURL=createMockContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMockContext.js","sourceRoot":"","sources":["../../src/common/createMockContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAwB,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,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ClB,OAAO,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC;oBACxC,GAAG,EAAE,OAAO;oBACZ,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE;iBAC9D,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,UAAU;gBACb,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBAC5B,MAAM;YACR,KAAK,iBAAiB;gBACpB,OAAO,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,yBAAyB,EAAE,CAAC;gBAChF,MAAM;YACR,KAAK,SAAS;gBACZ,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { createPackageDefinitions, readConfig } from '@ms-cloudpack/config';\nimport type { Context, PartialContext } from '../types/Context.js';\nimport { createSession, type CreateSessionOptions } from './createSession.js';\nimport { createNoOpTelemetryClient, type TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { noLoggingConfig, TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { TaskRunner } from '../utilities/TaskRunner.js';\nimport { PackageHashes } from '@ms-cloudpack/package-hashes';\nimport type { Session, WithOptional } from '@ms-cloudpack/common-types';\nimport { createDataBus, type DataBus } from '@ms-cloudpack/data-bus';\nimport path from 'path';\nimport { createMockSession, type CreateMockSessionOptions } from './createMockSession.js';\n\n/**\n * Create a mock context using info from the real filesystem.\n * This is suitable for most tests using `ensurePackageBundled` and other scenarios.\n * It will never include a file watcher, and only includes a data bus if `createDataBus` is true.\n */\nexport async function createMockContext(params: {\n appPath: string;\n sessionOptions?: Partial<Omit<CreateSessionOptions, 'config'>>;\n /** No-op telemetry client. You might want to create this only once and pass it in. */\n telemetryClient?: TelemetryClient;\n /** If true, create a data bus and connect it to the task runner. */\n dataBus?: boolean;\n}): Promise<WithOptional<Context, 'bus' | 'watcher' | 'dispose' | 'remoteCacheClient'>> {\n const { appPath, sessionOptions, telemetryClient = createNoOpTelemetryClient() } = params;\n\n const config = await readConfig(appPath);\n const packages = createPackageDefinitions({ config });\n const reporter = new TaskReporter(noLoggingConfig);\n const session = await createSession(\n { config, cachePath: path.join(appPath, '.cache'), ...sessionOptions },\n { reporter, packages, telemetryClient },\n );\n const taskRunner = new TaskRunner();\n const packageHashes = new PackageHashes({\n cwd: appPath,\n context: { config, packages, resolveMap: session.resolveMap },\n });\n\n let bus: DataBus | undefined;\n if (params.dataBus) {\n bus = createDataBus();\n taskRunner.connectToBus(bus);\n }\n\n return { reporter, taskRunner, telemetryClient, packageHashes, packages, session, bus };\n}\n\ntype AllowedContextKeys = Exclude<keyof Context, 'watcher' | 'dispose' | 'remoteCacheClient'>;\n\n/**\n * Initialize only the requested context keys (plus `'session'`) using info from the real filesystem.\n *\n * The returned `Session` object contains:\n * - `config` from the filesystem (with defaults if there is no config)\n * - `cachePath` set to `appPath/.cache` to prevent interference with the real cache or other tests\n * - `resolveMap` will be an empty object unless `params.createResolveMap` is true\n * - Basic mocks of other properties which can be updated as needed\n */\nexport async function createPartialMockContext<TContextKeys extends AllowedContextKeys>(\n params: CreateMockSessionOptions & {\n context: TContextKeys[];\n /** No-op telemetry client. You might want to create this only once and pass it in. */\n telemetryClient?: TelemetryClient;\n },\n): Promise<PartialContext<TContextKeys, keyof Session>> {\n const { appPath } = params;\n const contextKeys = params.context as AllowedContextKeys[];\n\n const config = await readConfig(appPath);\n const packages = createPackageDefinitions({ config });\n // Pass through the real config and package definitions when creating the session,\n // to allow creating a real resolve map if needed.\n const session = await createMockSession(params, { config, packages });\n // Only create a reporter (which overrides console logging) if requested\n const reporter = contextKeys.includes('reporter' as TContextKeys) ? new TaskReporter(noLoggingConfig) : undefined;\n\n const context = { session } as Pick<Context, AllowedContextKeys>;\n\n for (const key of contextKeys) {\n switch (key) {\n case 'bus':\n context.taskRunner ??= new TaskRunner();\n context.bus = createDataBus();\n context.taskRunner.connectToBus(context.bus);\n break;\n case 'reporter':\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n context.reporter = reporter!;\n break;\n case 'taskRunner':\n context.taskRunner ??= new TaskRunner();\n break;\n case 'packageHashes':\n context.packageHashes = new PackageHashes({\n cwd: appPath,\n context: { config, packages, resolveMap: session.resolveMap },\n });\n break;\n case 'packages':\n context.packages = packages;\n break;\n case 'telemetryClient':\n context.telemetryClient = params.telemetryClient || createNoOpTelemetryClient();\n break;\n case 'session':\n break;\n default:\n throw new Error(`Unsupported context key: ${key}`);\n }\n }\n\n return context;\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { CloudpackConfig, PackageDefinitionsCache, Session } from '@ms-cloudpack/common-types';
2
+ export interface CreateMockSessionOptions {
3
+ appPath: string;
4
+ /** Custom cache path. Defaults to `appPath/.cache`. */
5
+ cachePath?: string;
6
+ /** Whether to create a real resolve map. */
7
+ createResolveMap?: boolean;
8
+ /** Session ID. Defaults to a random UUID. */
9
+ sessionId?: string;
10
+ }
11
+ /**
12
+ * Create a mock session without reading anything from the filesystem.
13
+ */
14
+ export declare function createMockSessionNoFS(params: Omit<CreateMockSessionOptions, 'resolveMap'>): Session;
15
+ /**
16
+ * Create a mock session. The returned object contains:
17
+ * - `config` from the filesystem (with defaults if there is no config)
18
+ * - `cachePath` set to `appPath/.cache` to prevent interference with the real cache or other tests
19
+ * - `resolveMap` will be an empty object unless `params.createResolveMap` is true
20
+ * - Basic mocks of other properties which can be updated as needed
21
+ */
22
+ export declare function createMockSession(params: CreateMockSessionOptions, context?: {
23
+ config?: CloudpackConfig;
24
+ packages?: PackageDefinitionsCache;
25
+ }): Promise<Session>;
26
+ //# sourceMappingURL=createMockSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMockSession.d.ts","sourceRoot":"","sources":["../../src/common/createMockSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAMpG,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,wBAAwB,EAAE,YAAY,CAAC,GAAG,OAAO,CAqBnG;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,QAAQ,CAAC,EAAE,uBAAuB,CAAC;CACpC,GACA,OAAO,CAAC,OAAO,CAAC,CAWlB"}
@@ -0,0 +1,49 @@
1
+ import { readConfig } from '@ms-cloudpack/config';
2
+ import { createResolveMap } from '@ms-cloudpack/package-utilities';
3
+ import { randomUUID } from 'crypto';
4
+ import path from 'path';
5
+ /**
6
+ * Create a mock session without reading anything from the filesystem.
7
+ */
8
+ export function createMockSessionNoFS(params) {
9
+ const { appPath, sessionId = randomUUID(), cachePath = path.join(appPath, '.cache') } = params;
10
+ const session = {
11
+ id: sessionId,
12
+ cachePath,
13
+ config: { appPath, mode: 'library', generated: {} },
14
+ projectName: path.basename(appPath),
15
+ resolveMap: {},
16
+ sequence: 0,
17
+ urls: {},
18
+ targetVersions: {},
19
+ sessionVersion: 1,
20
+ incrementSessionVersion: () => { },
21
+ incrementTargetVersion: () => { },
22
+ importMap: undefined,
23
+ packageImportPaths: new Map(),
24
+ linkedPaths: [],
25
+ addLinkedPath: () => Promise.resolve(session),
26
+ removeLinkedPath: () => Promise.resolve(session),
27
+ };
28
+ return session;
29
+ }
30
+ /**
31
+ * Create a mock session. The returned object contains:
32
+ * - `config` from the filesystem (with defaults if there is no config)
33
+ * - `cachePath` set to `appPath/.cache` to prevent interference with the real cache or other tests
34
+ * - `resolveMap` will be an empty object unless `params.createResolveMap` is true
35
+ * - Basic mocks of other properties which can be updated as needed
36
+ */
37
+ export async function createMockSession(params, context) {
38
+ const { appPath } = params;
39
+ const session = createMockSessionNoFS(params);
40
+ session.config = context?.config || (await readConfig(appPath));
41
+ if (params.createResolveMap) {
42
+ if (!context?.packages) {
43
+ throw new Error('Cannot create a real resolve map without packages');
44
+ }
45
+ session.resolveMap = await createResolveMap({ appPath, rootPath: appPath }, { packages: context.packages });
46
+ }
47
+ return session;
48
+ }
49
+ //# sourceMappingURL=createMockSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMockSession.js","sourceRoot":"","sources":["../../src/common/createMockSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AAYxB;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAoD;IACxF,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,UAAU,EAAE,EAAE,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,GAAG,MAAM,CAAC;IAC/F,MAAM,OAAO,GAAY;QACvB,EAAE,EAAE,SAAS;QACb,SAAS;QACT,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE;QACnD,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QACnC,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,CAAC;QACX,IAAI,EAAE,EAAE;QACR,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,CAAC;QACjB,uBAAuB,EAAE,GAAG,EAAE,GAAE,CAAC;QACjC,sBAAsB,EAAE,GAAG,EAAE,GAAE,CAAC;QAChC,SAAS,EAAE,SAAS;QACpB,kBAAkB,EAAE,IAAI,GAAG,EAAE;QAC7B,WAAW,EAAE,EAAE;QACf,aAAa,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;QAC7C,gBAAgB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;KACjD,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAgC,EAChC,OAGC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAC3B,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC9C,OAAO,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAChE,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,CAAC,UAAU,GAAG,MAAM,gBAAgB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9G,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, Session } from '@ms-cloudpack/common-types';\nimport { readConfig } from '@ms-cloudpack/config';\nimport { createResolveMap } from '@ms-cloudpack/package-utilities';\nimport { randomUUID } from 'crypto';\nimport path from 'path';\n\nexport interface CreateMockSessionOptions {\n appPath: string;\n /** Custom cache path. Defaults to `appPath/.cache`. */\n cachePath?: string;\n /** Whether to create a real resolve map. */\n createResolveMap?: boolean;\n /** Session ID. Defaults to a random UUID. */\n sessionId?: string;\n}\n\n/**\n * Create a mock session without reading anything from the filesystem.\n */\nexport function createMockSessionNoFS(params: Omit<CreateMockSessionOptions, 'resolveMap'>): Session {\n const { appPath, sessionId = randomUUID(), cachePath = path.join(appPath, '.cache') } = params;\n const session: Session = {\n id: sessionId,\n cachePath,\n config: { appPath, mode: 'library', generated: {} },\n projectName: path.basename(appPath),\n resolveMap: {},\n sequence: 0,\n urls: {},\n targetVersions: {},\n sessionVersion: 1,\n incrementSessionVersion: () => {},\n incrementTargetVersion: () => {},\n importMap: undefined,\n packageImportPaths: new Map(),\n linkedPaths: [],\n addLinkedPath: () => Promise.resolve(session),\n removeLinkedPath: () => Promise.resolve(session),\n };\n return session;\n}\n\n/**\n * Create a mock session. The returned object contains:\n * - `config` from the filesystem (with defaults if there is no config)\n * - `cachePath` set to `appPath/.cache` to prevent interference with the real cache or other tests\n * - `resolveMap` will be an empty object unless `params.createResolveMap` is true\n * - Basic mocks of other properties which can be updated as needed\n */\nexport async function createMockSession(\n params: CreateMockSessionOptions,\n context?: {\n config?: CloudpackConfig;\n packages?: PackageDefinitionsCache;\n },\n): Promise<Session> {\n const { appPath } = params;\n const session = createMockSessionNoFS(params);\n session.config = context?.config || (await readConfig(appPath));\n if (params.createResolveMap) {\n if (!context?.packages) {\n throw new Error('Cannot create a real resolve map without packages');\n }\n session.resolveMap = await createResolveMap({ appPath, rootPath: appPath }, { packages: context.packages });\n }\n return session;\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -16,6 +16,8 @@ export { getActiveSessionsPath } from './utilities/getActiveSessionsPath.js';
16
16
  export { getConsumedDependencies } from './utilities/getConsumedDependencies.js';
17
17
  export { getConsumedPaths } from './utilities/getConsumedPaths.js';
18
18
  export { createApiContext, createPartialApiContext, type CreateApiContextOptions } from './common/createApiContext.js';
19
+ export { createMockContext, createPartialMockContext } from './common/createMockContext.js';
20
+ export { createMockSession, createMockSessionNoFS } from './common/createMockSession.js';
19
21
  export { addPackageOverride } from './apis/addPackageOverride.js';
20
22
  export { ensurePackageBundled } from './apis/ensurePackageBundled.js';
21
23
  export { syncDownload } from './apis/syncDownload.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC9F,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,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,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,YAAY,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAE9G,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,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,CAA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e,EAAE,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;AAGnE,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,KAAK,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvH,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAGzF,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;AAClD,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
package/lib/index.js CHANGED
@@ -7,6 +7,8 @@ export { getConsumedDependencies } from './utilities/getConsumedDependencies.js'
7
7
  export { getConsumedPaths } from './utilities/getConsumedPaths.js';
8
8
  // Utilities
9
9
  export { createApiContext, createPartialApiContext } from './common/createApiContext.js';
10
+ export { createMockContext, createPartialMockContext } from './common/createMockContext.js';
11
+ export { createMockSession, createMockSessionNoFS } from './common/createMockSession.js';
10
12
  // API methods directly used outside this package
11
13
  export { addPackageOverride } from './apis/addPackageOverride.js';
12
14
  export { ensurePackageBundled } from './apis/ensurePackageBundled.js';
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACzF,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 { 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 { TaskList } from './types/TaskList.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 { taskListSource, taskStatsSource, 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
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACzF,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;AACvH,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEzF,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 { 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 { TaskList } from './types/TaskList.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 { taskListSource, taskStatsSource, 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';\nexport { createMockContext, createPartialMockContext } from './common/createMockContext.js';\nexport { createMockSession, createMockSessionNoFS } from './common/createMockSession.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,15 +1,3 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _TaskScheduler_scheduler;
13
1
  import targetGraph from '@lage-run/target-graph';
14
2
  import { createRequire } from 'node:module';
15
3
  import { createSimpleScheduler } from './createSimpleScheduler.js';
@@ -19,9 +7,9 @@ export const require = createRequire(import.meta.url);
19
7
  * A class to abstract the creation of the lage scheduler and scheduling tasks
20
8
  */
21
9
  export class TaskScheduler {
10
+ #scheduler;
22
11
  constructor(options) {
23
- _TaskScheduler_scheduler.set(this, void 0);
24
- __classPrivateFieldSet(this, _TaskScheduler_scheduler, createSimpleScheduler(options), "f");
12
+ this.#scheduler = createSimpleScheduler(options);
25
13
  }
26
14
  // Schedules task to be run according to the bundle request that came through from the bundler server
27
15
  // TODO: from a bundle request, we should be able to determine if we need to auto add several targets into the graph
@@ -31,12 +19,11 @@ export class TaskScheduler {
31
19
  targetGraphBuilder.addTarget(target);
32
20
  const graph = targetGraphBuilder.build();
33
21
  try {
34
- await __classPrivateFieldGet(this, _TaskScheduler_scheduler, "f").run(target.cwd, graph, options.rerun);
22
+ await this.#scheduler.run(target.cwd, graph, options.rerun);
35
23
  }
36
24
  catch (e) {
37
25
  console.error(e.stack || e);
38
26
  }
39
27
  }
40
28
  }
41
- _TaskScheduler_scheduler = new WeakMap();
42
29
  //# sourceMappingURL=TaskScheduler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TaskScheduler.js","sourceRoot":"","sources":["../../src/task-scheduler/TaskScheduler.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAOtD;;GAEG;AACH,MAAM,OAAO,aAAa;IAGxB,YAAY,OAA6B;QAFzC,2CAA4B;QAG1B,uBAAA,IAAI,4BAAc,qBAAqB,CAAC,OAAO,CAAC,MAAA,CAAC;IACnD,CAAC;IAED,qGAAqG;IACrG,oHAAoH;IACpH,KAAK,CAAC,YAAY,CAChB,aAAgB,EAChB,OAA+B,EAC/B,OAEC;QAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAE1D,MAAM,kBAAkB,GAAG,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAC;QAChE,kBAAkB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAEzC,IAAI,CAAC;YACH,MAAM,uBAAA,IAAI,gCAAW,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAE,CAAW,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { SimpleScheduler } from '@lage-run/scheduler';\nimport targetGraph from '@lage-run/target-graph';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { BundleRequest } from '../types/BundleRequest.js';\n\nimport { createRequire } from 'node:module';\nimport { createSimpleScheduler } from './createSimpleScheduler.js';\nimport { createBundleTarget } from './createBundleTarget.js';\n\nexport const require = createRequire(import.meta.url);\n\ninterface TaskSchedulerOptions {\n reporter: TaskReporter;\n root: string;\n}\n\n/**\n * A class to abstract the creation of the lage scheduler and scheduling tasks\n */\nexport class TaskScheduler {\n #scheduler: SimpleScheduler;\n\n constructor(options: TaskSchedulerOptions) {\n this.#scheduler = createSimpleScheduler(options);\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 ): Promise<void> {\n const target = createBundleTarget(scripts, bundleRequest);\n\n const targetGraphBuilder = new targetGraph.TargetGraphBuilder();\n targetGraphBuilder.addTarget(target);\n const graph = targetGraphBuilder.build();\n\n try {\n await this.#scheduler.run(target.cwd, graph, options.rerun);\n } catch (e) {\n console.error((e as Error).stack || e);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"TaskScheduler.js","sourceRoot":"","sources":["../../src/task-scheduler/TaskScheduler.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAOtD;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,UAAU,CAAkB;IAE5B,YAAY,OAA6B;QACvC,IAAI,CAAC,UAAU,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,qGAAqG;IACrG,oHAAoH;IACpH,KAAK,CAAC,YAAY,CAChB,aAAgB,EAChB,OAA+B,EAC/B,OAEC;QAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAE1D,MAAM,kBAAkB,GAAG,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAC;QAChE,kBAAkB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAEzC,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAE,CAAW,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { SimpleScheduler } from '@lage-run/scheduler';\nimport targetGraph from '@lage-run/target-graph';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { BundleRequest } from '../types/BundleRequest.js';\n\nimport { createRequire } from 'node:module';\nimport { createSimpleScheduler } from './createSimpleScheduler.js';\nimport { createBundleTarget } from './createBundleTarget.js';\n\nexport const require = createRequire(import.meta.url);\n\ninterface TaskSchedulerOptions {\n reporter: TaskReporter;\n root: string;\n}\n\n/**\n * A class to abstract the creation of the lage scheduler and scheduling tasks\n */\nexport class TaskScheduler {\n #scheduler: SimpleScheduler;\n\n constructor(options: TaskSchedulerOptions) {\n this.#scheduler = createSimpleScheduler(options);\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 ): Promise<void> {\n const target = createBundleTarget(scripts, bundleRequest);\n\n const targetGraphBuilder = new targetGraph.TargetGraphBuilder();\n targetGraphBuilder.addTarget(target);\n const graph = targetGraphBuilder.build();\n\n try {\n await this.#scheduler.run(target.cwd, graph, options.rerun);\n } catch (e) {\n console.error((e as Error).stack || e);\n }\n }\n}\n"]}
@@ -1,20 +1,12 @@
1
1
  import type { Context } from '../types/Context.js';
2
2
  export type CreateContext = () => Promise<Context>;
3
3
  /** Reusable TRPC router helper. */
4
- export declare const createRouter: {
5
- <TInput extends import("@trpc/server").RouterRecord>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
6
- ctx: Context;
7
- meta: object;
8
- errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
9
- transformer: false;
10
- }, TInput>;
11
- <TInput extends import("@trpc/server/unstable-core-do-not-import").CreateRouterOptions>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
12
- ctx: Context;
13
- meta: object;
14
- errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
15
- transformer: false;
16
- }, import("@trpc/server/unstable-core-do-not-import").DecorateCreateRouterOptions<TInput>>;
17
- };
4
+ export declare const createRouter: <TInput extends import("@trpc/server/unstable-core-do-not-import").CreateRouterOptions>(input: TInput) => import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
5
+ ctx: Context;
6
+ meta: object;
7
+ errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
8
+ transformer: false;
9
+ }, import("@trpc/server/unstable-core-do-not-import").DecorateCreateRouterOptions<TInput>>;
18
10
  /** Reusable TRPC procedure helper. */
19
11
  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>;
20
12
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
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
+ {"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,yBAI85E,0CAAU;;;;;0FAJ75E,CAAC;AAErC,sCAAsC;AACtC,eAAO,MAAM,eAAe,iYAAc,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import type { DataBus } from '@ms-cloudpack/data-bus';
2
- import type { CreateTRPCClient } from '@trpc/client';
2
+ import type { TRPCClient } from '@trpc/client';
3
3
  import type { AppRouter } from '../types/AppRouter.js';
4
- export declare function connectBusToClient({ bus, client }: {
4
+ export declare function connectBusToClient(params: {
5
5
  bus: DataBus;
6
- client: CreateTRPCClient<AppRouter>;
6
+ client: TRPCClient<AppRouter>;
7
7
  }): void;
8
8
  //# sourceMappingURL=connectBusToClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectBusToClient.d.ts","sourceRoot":"","sources":["../../src/trpc/connectBusToClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,wBAAgB,kBAAkB,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;CAAE,GAAG,IAAI,CAgC/G"}
1
+ {"version":3,"file":"connectBusToClient.d.ts","sourceRoot":"","sources":["../../src/trpc/connectBusToClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;CAAE,GAAG,IAAI,CA4BhG"}
@@ -1,22 +1,20 @@
1
- export function connectBusToClient({ bus, client }) {
1
+ export function connectBusToClient(params) {
2
+ const { bus, client } = params;
2
3
  const subIds = {};
3
4
  bus.addProvider({
4
5
  path: [],
5
6
  onActivate: ({ path }) => {
6
7
  const id = path.join('/');
8
+ const onData = (value) => {
9
+ bus.publish(path, value);
10
+ };
7
11
  client.getData
8
12
  .query({ path })
9
- .then((value) => {
10
- bus.publish(path, value);
11
- })
13
+ .then(onData)
12
14
  .catch(() => {
13
15
  /* no-op */
14
16
  });
15
- subIds[id] = client.onDataChanged.subscribe({ path }, {
16
- onData(value) {
17
- bus.publish(path, value);
18
- },
19
- });
17
+ subIds[id] = client.onDataChanged.subscribe({ path }, { onData });
20
18
  },
21
19
  onDeactivate: ({ path }) => {
22
20
  const id = path.join('/');
@@ -1 +1 @@
1
- {"version":3,"file":"connectBusToClient.js","sourceRoot":"","sources":["../../src/trpc/connectBusToClient.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,kBAAkB,CAAC,EAAE,GAAG,EAAE,MAAM,EAAyD;IACvG,MAAM,MAAM,GAAmC,EAAE,CAAC;IAElD,GAAG,CAAC,WAAW,CAAC;QACd,IAAI,EAAE,EAAE;QACR,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YACvB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAE1B,MAAM,CAAC,OAAO;iBACX,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;iBACf,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBACd,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC3B,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE;gBACV,WAAW;YACb,CAAC,CAAC,CAAC;YAEL,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,SAAS,CACzC,EAAE,IAAI,EAAE,EACR;gBACE,MAAM,CAAC,KAAK;oBACV,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC3B,CAAC;aACF,CACF,CAAC;QACJ,CAAC;QACD,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DataBus } from '@ms-cloudpack/data-bus';\nimport type { CreateTRPCClient } from '@trpc/client';\nimport type { Unsubscribable } from '@trpc/server/observable';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport function connectBusToClient({ bus, client }: { bus: DataBus; client: CreateTRPCClient<AppRouter> }): void {\n const subIds: Record<string, Unsubscribable> = {};\n\n bus.addProvider({\n path: [],\n onActivate: ({ path }) => {\n const id = path.join('/');\n\n client.getData\n .query({ path })\n .then((value) => {\n bus.publish(path, value);\n })\n .catch(() => {\n /* no-op */\n });\n\n subIds[id] = client.onDataChanged.subscribe(\n { path },\n {\n onData(value) {\n bus.publish(path, value);\n },\n },\n );\n },\n onDeactivate: ({ path }) => {\n const id = path.join('/');\n subIds[id].unsubscribe();\n delete subIds[id];\n },\n });\n}\n"]}
1
+ {"version":3,"file":"connectBusToClient.js","sourceRoot":"","sources":["../../src/trpc/connectBusToClient.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,kBAAkB,CAAC,MAAuD;IACxF,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,MAAM,GAAmC,EAAE,CAAC;IAElD,GAAG,CAAC,WAAW,CAAC;QACd,IAAI,EAAE,EAAE;QACR,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YACvB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAE1B,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE;gBAChC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC3B,CAAC,CAAC;YAEF,MAAM,CAAC,OAAO;iBACX,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;iBACf,IAAI,CAAC,MAAM,CAAC;iBACZ,KAAK,CAAC,GAAG,EAAE;gBACV,WAAW;YACb,CAAC,CAAC,CAAC;YAEL,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YACzB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC;QACpB,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DataBus } from '@ms-cloudpack/data-bus';\nimport type { TRPCClient } from '@trpc/client';\nimport type { Unsubscribable } from '@trpc/server/observable';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport function connectBusToClient(params: { bus: DataBus; client: TRPCClient<AppRouter> }): void {\n const { bus, client } = params;\n const subIds: Record<string, Unsubscribable> = {};\n\n bus.addProvider({\n path: [],\n onActivate: ({ path }) => {\n const id = path.join('/');\n\n const onData = (value: unknown) => {\n bus.publish(path, value);\n };\n\n client.getData\n .query({ path })\n .then(onData)\n .catch(() => {\n /* no-op */\n });\n\n subIds[id] = client.onDataChanged.subscribe({ path }, { onData });\n },\n onDeactivate: ({ path }) => {\n const id = path.join('/');\n subIds[id].unsubscribe();\n delete subIds[id];\n },\n });\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { TaskReporter } from '@ms-cloudpack/task-reporter';
2
- import type { CreateTRPCClient } from '@trpc/client';
2
+ import type { TRPCClient } from '@trpc/client';
3
3
  import type { AppRouter } from '../types/AppRouter.js';
4
- export type CloudpackClient = CreateTRPCClient<AppRouter> & {
4
+ export type CloudpackClient = TRPCClient<AppRouter> & {
5
5
  close: () => Promise<void>;
6
6
  };
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"createCloudpackClient.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAC,SAAS,CAAC,GAAG;IAC1D,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,GAAG,OAAO,CAAC,eAAe,CAAC,CAmD3B"}
1
+ {"version":3,"file":"createCloudpackClient.d.ts","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,SAAS,CAAC,GAAG;IACpD,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,GAAG,OAAO,CAAC,eAAe,CAAC,CAgD3B"}
@@ -10,7 +10,6 @@ export async function createCloudpackClient(options) {
10
10
  await ensureWebsocketDefined();
11
11
  ignoreSelfSignedCertErrors({ reporter: options.reporter });
12
12
  // Create the client.
13
- // eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109
14
13
  const wsClient = createWSClient(options);
15
14
  const tempUrl = makeUrl(options.url);
16
15
  // Replace the protocol with http so that we can use the same url for http requests.
@@ -23,7 +22,6 @@ export async function createCloudpackClient(options) {
23
22
  condition(op) {
24
23
  return op.type === 'subscription';
25
24
  },
26
- // eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109
27
25
  true: wsLink({
28
26
  client: wsClient,
29
27
  }),
@@ -33,12 +31,13 @@ export async function createCloudpackClient(options) {
33
31
  }),
34
32
  ],
35
33
  });
34
+ const close = async () => {
35
+ await wsClient.close();
36
+ };
36
37
  // Ugh. This is a hack to get around the fact that the client is a proxy.
37
- return new Proxy({
38
- close: () => {
39
- wsClient.close();
40
- },
41
- }, {
38
+ // Make another proxy which defines the close method and passes through everything else
39
+ // to the original client.
40
+ return new Proxy({ close }, {
42
41
  get(target, prop) {
43
42
  // eslint-disable-next-line no-prototype-builtins
44
43
  if (target.hasOwnProperty(prop)) {
@@ -1 +1 @@
1
- {"version":3,"file":"createCloudpackClient.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAOxF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAG3C;IACC,4CAA4C;IAC5C,MAAM,sBAAsB,EAAE,CAAC;IAE/B,0BAA0B,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE3D,qBAAqB;IACrB,6FAA6F;IAC7F,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAErC,oFAAoF;IACpF,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,MAAM,CAAC;IAC1C,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAE9C,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,gBAAgB,CAAY;QACzC,KAAK,EAAE;YACL,SAAS,CAAC;gBACR,SAAS,CAAC,EAAE;oBACV,OAAO,EAAE,CAAC,IAAI,KAAK,cAAc,CAAC;gBACpC,CAAC;gBACD,6FAA6F;gBAC7F,IAAI,EAAE,MAAM,CAAC;oBACX,MAAM,EAAE,QAAQ;iBACjB,CAAC;gBACF,KAAK,EAAE,aAAa,CAAC;oBACnB,GAAG;iBACJ,CAAC;aACH,CAAC;SACH;KACF,CAA+B,CAAC;IAEjC,yEAAyE;IACzE,OAAO,IAAI,KAAK,CACd;QACE,KAAK,EAAE,GAAG,EAAE;YACV,QAAQ,CAAC,KAAK,EAAE,CAAC;QACnB,CAAC;KACF,EACD;QACE,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,iDAAiD;YACjD,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChC,OAAO,MAAM,CAAC,IAA2B,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO,MAAM,CAAC,IAA6B,CAAC,CAAC;QAC/C,CAAC;KACF,CACiB,CAAC;AACvB,CAAC","sourcesContent":["import { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { CreateTRPCClient } from '@trpc/client';\nimport { createTRPCClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';\nimport { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';\nimport { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport type CloudpackClient = CreateTRPCClient<AppRouter> & {\n close: () => Promise<void>;\n};\n\n/**\n * Creates a cloudpack client that can be used to communicate with the cloudpack server using trpc.\n */\nexport async function createCloudpackClient(options: {\n url: string;\n reporter?: TaskReporter;\n}): Promise<CloudpackClient> {\n // We polyfill websocket in node conditions.\n await ensureWebsocketDefined();\n\n ignoreSelfSignedCertErrors({ reporter: options.reporter });\n\n // Create the client.\n // eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109\n const wsClient = createWSClient(options);\n const tempUrl = makeUrl(options.url);\n\n // Replace the protocol with http so that we can use the same url for http requests.\n const isSSL = tempUrl.protocol === 'wss:';\n tempUrl.protocol = isSSL ? 'https:' : 'http:';\n\n const url = tempUrl.toString().replace(/\\/$/, '');\n const client = createTRPCClient<AppRouter>({\n links: [\n splitLink({\n condition(op) {\n return op.type === 'subscription';\n },\n // eslint-disable-next-line etc/no-deprecated -- see https://github.com/trpc/trpc/issues/6109\n true: wsLink({\n client: wsClient,\n }),\n false: httpBatchLink({\n url,\n }),\n }),\n ],\n }) as unknown as CloudpackClient;\n\n // Ugh. This is a hack to get around the fact that the client is a proxy.\n return new Proxy(\n {\n close: () => {\n wsClient.close();\n },\n },\n {\n get(target, prop) {\n // eslint-disable-next-line no-prototype-builtins\n if (target.hasOwnProperty(prop)) {\n return target[prop as keyof typeof target];\n }\n\n return client[prop as keyof CloudpackClient];\n },\n },\n ) as CloudpackClient;\n}\n"]}
1
+ {"version":3,"file":"createCloudpackClient.js","sourceRoot":"","sources":["../../src/trpc/createCloudpackClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAG5D,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAOxF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAG3C;IACC,4CAA4C;IAC5C,MAAM,sBAAsB,EAAE,CAAC;IAE/B,0BAA0B,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE3D,qBAAqB;IACrB,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAErC,oFAAoF;IACpF,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,MAAM,CAAC;IAC1C,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAE9C,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,gBAAgB,CAAY;QACzC,KAAK,EAAE;YACL,SAAS,CAAC;gBACR,SAAS,CAAC,EAAE;oBACV,OAAO,EAAE,CAAC,IAAI,KAAK,cAAc,CAAC;gBACpC,CAAC;gBACD,IAAI,EAAE,MAAM,CAAC;oBACX,MAAM,EAAE,QAAQ;iBACjB,CAAC;gBACF,KAAK,EAAE,aAAa,CAAC;oBACnB,GAAG;iBACJ,CAAC;aACH,CAAC;SACH;KACF,CAAC,CAAC;IAEH,MAAM,KAAK,GAA6B,KAAK,IAAI,EAAE;QACjD,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC;IAEF,yEAAyE;IACzE,uFAAuF;IACvF,0BAA0B;IAC1B,OAAO,IAAI,KAAK,CAAkB,EAAE,KAAK,EAAqB,EAAE;QAC9D,GAAG,CAAC,MAAM,EAAE,IAAI;YACd,iDAAiD;YACjD,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChC,OAAO,MAAM,CAAC,IAA2B,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO,MAAM,CAAC,IAA+C,CAAC,CAAC;QACjE,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TRPCClient } from '@trpc/client';\nimport { createTRPCClient, createWSClient, httpBatchLink, splitLink, wsLink } from '@trpc/client';\nimport { ensureWebsocketDefined } from '../utilities/ensureWebsocketDefined.js';\nimport { ignoreSelfSignedCertErrors } from '../utilities/ignoreSelfSignedCertErrors.js';\nimport type { AppRouter } from '../types/AppRouter.js';\n\nexport type CloudpackClient = TRPCClient<AppRouter> & {\n close: () => Promise<void>;\n};\n\n/**\n * Creates a cloudpack client that can be used to communicate with the cloudpack server using trpc.\n */\nexport async function createCloudpackClient(options: {\n url: string;\n reporter?: TaskReporter;\n}): Promise<CloudpackClient> {\n // We polyfill websocket in node conditions.\n await ensureWebsocketDefined();\n\n ignoreSelfSignedCertErrors({ reporter: options.reporter });\n\n // Create the client.\n const wsClient = createWSClient(options);\n const tempUrl = makeUrl(options.url);\n\n // Replace the protocol with http so that we can use the same url for http requests.\n const isSSL = tempUrl.protocol === 'wss:';\n tempUrl.protocol = isSSL ? 'https:' : 'http:';\n\n const url = tempUrl.toString().replace(/\\/$/, '');\n const client = createTRPCClient<AppRouter>({\n links: [\n splitLink({\n condition(op) {\n return op.type === 'subscription';\n },\n true: wsLink({\n client: wsClient,\n }),\n false: httpBatchLink({\n url,\n }),\n }),\n ],\n });\n\n const close: CloudpackClient['close'] = async () => {\n await wsClient.close();\n };\n\n // Ugh. This is a hack to get around the fact that the client is a proxy.\n // Make another proxy which defines the close method and passes through everything else\n // to the original client.\n return new Proxy<CloudpackClient>({ close } as CloudpackClient, {\n get(target, prop) {\n // eslint-disable-next-line no-prototype-builtins\n if (target.hasOwnProperty(prop)) {\n return target[prop as keyof typeof target];\n }\n\n return client[prop as Exclude<keyof CloudpackClient, 'close'>];\n },\n });\n}\n"]}
@@ -18,7 +18,7 @@ export interface BundleRequest {
18
18
  isExternal: boolean;
19
19
  /** Whether we should force the incremental flag. */
20
20
  isIncremental?: boolean;
21
- /** Bundle mode */
21
+ /** Bundle mode (copied from the config) */
22
22
  mode: BundleMode;
23
23
  /** Target environment for the bundle. */
24
24
  targetEnvironment: TargetEnvironment;
@@ -1 +1 @@
1
- {"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],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Y,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,2CAA2C;IAC3C,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, 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"]}
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 (copied from the config) */\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"]}
@@ -8,6 +8,14 @@ import { taskListSource, taskStatsSource } from '../index.browser.js';
8
8
  * `createApiContext` does this with the `taskRunner` passed in.
9
9
  */
10
10
  export class TaskRunner {
11
+ _bus;
12
+ _queue;
13
+ _taskStats;
14
+ _pendingTasks;
15
+ _completedTasks;
16
+ _requiresRerun;
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ _prevTasks;
11
19
  constructor() {
12
20
  this._queue = new PQueue({ concurrency: 10 });
13
21
  this._taskStats = getDefaultTaskStats();
@@ -1 +1 @@
1
- {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAwB,MAAM,qBAAqB,CAAC;AAG5F;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IAUrB;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,GAAG,mBAAmB,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,IAAI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CAAC,UAAU,CAAC,CAAC;YAC9C,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF;AAED,MAAM,mBAAmB,GAAoB,GAAG,EAAE,CAAC,CAAC;IAClD,MAAM,EAAE,MAAM;IACd,cAAc,EAAE,CAAC;IACjB,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;CACjB,CAAC,CAAC","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 { 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\nconst getDefaultTaskStats: () => TaskStats = () => ({\n status: 'idle',\n remainingTasks: 0,\n totalTasks: 0,\n totalErrors: 0,\n totalWarnings: 0,\n});\n"]}
1
+ {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/utilities/TaskRunner.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAwB,MAAM,qBAAqB,CAAC;AAG5F;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IACb,IAAI,CAAsB;IAC1B,MAAM,CAAS;IACf,UAAU,CAAY;IACtB,aAAa,CAAgC;IAC7C,eAAe,CAAuB;IACtC,cAAc,CAAc;IACpC,8DAA8D;IACtD,UAAU,CAAyB;IAE3C;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,GAAG,mBAAmB,EAAE,CAAC;QACxC,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,GAAG,IAAI,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,GAAY;QAC9B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC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d,cAAc,EAAE,CAAC;IACjB,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;CACjB,CAAC,CAAC","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 { 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\nconst getDefaultTaskStats: () => TaskStats = () => ({\n status: 'idle',\n remainingTasks: 0,\n totalTasks: 0,\n totalErrors: 0,\n totalWarnings: 0,\n});\n"]}
@@ -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,EAAE,MAAM,iBAAiB,CAAC,SAAS,CAAC,GAAG,WAAW,GAAG,oBAAoB,GAAG,MAAM,CAAC,GAClH,IAAI,CAAC,aAAa,CAAC,CA4DrB"}
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,CAkErB"}
@@ -40,7 +40,12 @@ export function createBundleTask(options, context) {
40
40
  return;
41
41
  }
42
42
  bundleRequest.result.dispose?.();
43
- fs.rmSync(bundleRequest.result.outputPath, { recursive: true, force: true });
43
+ try {
44
+ fs.rmSync(bundleRequest.result.outputPath, { recursive: true, force: true });
45
+ }
46
+ catch {
47
+ console.warn(`Error clearing bundle output path (likely due to a file lock): ${bundleRequest.result.outputPath}`);
48
+ }
44
49
  bundleRequest.result = undefined;
45
50
  },
46
51
  onDispose: () => {
@@ -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,iBAAiB,EAAE,GAAG,aAAa,CAAC;IAC/F,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC3C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACrC,MAAM,IAAI,GAAG,UAAU,WAAW,IAAI,OAAO,EAAE,CAAC;IAEhD,OAAO;QACL,gCAAgC;QAChC,IAAI;QACJ,EAAE;QACF,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK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AE,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, targetEnvironment } = 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 if (session.importMap && session.urls.bundleServer && session.urls.appServer) {\n const importMapHash =\n sourceHash ||\n hash ||\n (await packageHashes.get({ packagePath, isSourceHashingEnabled: !isExternal, targetEnvironment }));\n addImportMapHash({ packageName, version, hash: importMapHash }, context);\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,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,iBAAiB,EAAE,GAAG,aAAa,CAAC;IAC/F,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC3C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACrC,MAAM,IAAI,GAAG,UAAU,WAAW,IAAI,OAAO,EAA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AM,CAAC;gBACP,OAAO,CAAC,IAAI,CACV,kEAAkE,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,CACpG,CAAC;YACJ,CAAC;YAED,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, targetEnvironment } = 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 if (session.importMap && session.urls.bundleServer && session.urls.appServer) {\n const importMapHash =\n sourceHash ||\n hash ||\n (await packageHashes.get({ packagePath, isSourceHashingEnabled: !isExternal, targetEnvironment }));\n addImportMapHash({ packageName, version, hash: importMapHash }, context);\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 try {\n fs.rmSync(bundleRequest.result.outputPath, { recursive: true, force: true });\n } catch {\n console.warn(\n `Error clearing bundle output path (likely due to a file lock): ${bundleRequest.result.outputPath}`,\n );\n }\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/api-server",
3
- "version": "0.61.4",
3
+ "version": "0.61.5",
4
4
  "description": "An implementation of the API server that does interacts with a task scheduler.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "@lage-run/logger": "^1.3.0",
28
28
  "@lage-run/scheduler": "^1.2.1",
29
29
  "@lage-run/target-graph": "^0.11.0",
30
- "@ms-cloudpack/bundler": "^0.24.3",
30
+ "@ms-cloudpack/bundler": "^0.24.4",
31
31
  "@ms-cloudpack/common-types": "^0.24.10",
32
32
  "@ms-cloudpack/config": "^0.33.19",
33
33
  "@ms-cloudpack/create-express-app": "^1.10.22",
@@ -43,8 +43,8 @@
43
43
  "@ms-cloudpack/remote-cache": "^0.10.15",
44
44
  "@ms-cloudpack/task-reporter": "^0.15.1",
45
45
  "@ms-cloudpack/telemetry": "^0.10.18",
46
- "@trpc/client": "11.0.0-rc.682",
47
- "@trpc/server": "11.0.0-rc.682",
46
+ "@trpc/client": "11.0.0-rc.814",
47
+ "@trpc/server": "11.0.0-rc.814",
48
48
  "cors": "^2.8.5",
49
49
  "es-module-lexer": "^1.4.1",
50
50
  "filenamify": "^6.0.0",