@ms-cloudpack/api-server 0.65.14 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import type { ApiParams } from '../types/ApiParams.js';
3
3
  /**
4
4
  * Adds an override to the Cloudpack config.
5
5
  */
6
- export declare function addPackageOverride(params: ApiParams<OverrideOptions, 'bus' | 'packageHashes' | 'packages' | 'taskRunner' | 'telemetryClient', 'config' | 'incrementTargetVersion' | 'resolveMap' | 'sequence'>): Promise<boolean>;
6
+ export declare function addPackageOverride(params: ApiParams<OverrideOptions, 'bus' | 'packageHashes' | 'packages' | 'taskRunner' | 'telemetryClient', 'config' | 'incrementTargetVersion' | 'resolveMap' | 'sequence' | 'importMap' | 'packageImportPaths'>): Promise<boolean>;
7
7
  export declare namespace addPackageOverride {
8
8
  var procedure: import("@trpc/server").TRPCMutationProcedure<{
9
9
  input: OverrideOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"addPackageOverride.d.ts","sourceRoot":"","sources":["../../src/apis/addPackageOverride.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAgBvD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,SAAS,CACf,eAAe,EACf,KAAK,GAAG,eAAe,GAAG,UAAU,GAAG,YAAY,GAAG,iBAAiB,EACvE,QAAQ,GAAG,wBAAwB,GAAG,YAAY,GAAG,UAAU,CAChE,GACA,OAAO,CAAC,OAAO,CAAC,CAkClB;yBAxCqB,kBAAkB"}
1
+ {"version":3,"file":"addPackageOverride.d.ts","sourceRoot":"","sources":["../../src/apis/addPackageOverride.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAgBvD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,SAAS,CACf,eAAe,EACf,KAAK,GAAG,eAAe,GAAG,UAAU,GAAG,YAAY,GAAG,iBAAiB,EACvE,QAAQ,GAAG,wBAAwB,GAAG,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,oBAAoB,CACrG,GACA,OAAO,CAAC,OAAO,CAAC,CAkClB;yBAxCqB,kBAAkB"}
@@ -38,7 +38,7 @@ export async function addPackageOverride(params) {
38
38
  // We can clear the error message now that the override has been added.
39
39
  bus.publish(errorEntrySource, '');
40
40
  }
41
- await notifyHost({ reason: 'add-package-override', packagePath, definition: await packages.get(packagePath) }, { bus, session, telemetryClient });
41
+ await notifyHost({ reason: 'add-package-override', packageEntry: entry, definition: await packages.get(packagePath) }, { bus, session, telemetryClient });
42
42
  }
43
43
  return addedOverride;
44
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"addPackageOverride.js","sourceRoot":"","sources":["../../src/apis/addPackageOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,MAAM,0BAA0B,GAAG,iBAAiB,CAAkB;IACpE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC/B,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAA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C;YACpC,CAAC;YACD,MAAM,UAAU,CACd,EAAE,MAAM,EAAE,sBAAsB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAC5F,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,CAClC,CAAC;QACJ,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC,CACF,CAAC;AACJ,CAAC;AAED,kBAAkB,CAAC,SAAS,GAAG,iBAAiB,CAC9C,kBAAkB,EAClB,0BAA0B,EAC1B,CAAC,CAAC,OAAO,EAAE,CACZ,CAAC","sourcesContent":["import { z } from 'zod/v4-mini';\nimport { mutationProcedure } from '../trpc/common.js';\nimport { addOverride } from '../utilities/addOverride.js';\nimport type { OverrideOptions } from '../types/OverrideOptions.js';\nimport type { ApiParams } from '../types/ApiParams.js';\nimport { errorEntrySource } from '../data/busSources.js';\nimport { matchingZodObject } from '../utilities/matchingZodObject.js';\nimport { notifyHost } from '../utilities/notifyHost.js';\n\nconst ZodAddPackageOverrideInput = matchingZodObject<OverrideOptions>({\n packageName: z.string(),\n importPath: z.string(),\n version: z.optional(z.string()),\n issuerUrl: z.optional(z.string()),\n initiatedBy: z.literal(['autoUpdateEntries', 'user']),\n});\n\n// TODO: consider whether this should be hardcoded or not\nconst targetEnvironment = 'browser';\n\n/**\n * Adds an override to the Cloudpack config.\n */\nexport async function addPackageOverride(\n params: ApiParams<\n OverrideOptions,\n 'bus' | 'packageHashes' | 'packages' | 'taskRunner' | 'telemetryClient',\n 'config' | 'incrementTargetVersion' | 'resolveMap' | 'sequence'\n >,\n): Promise<boolean> {\n const { input, ctx } = params;\n const { session, bus, packages, taskRunner, packageHashes, telemetryClient } = ctx;\n const { packageName, initiatedBy } = input;\n\n return telemetryClient.tracer.startActiveSpan(\n 'ADD_PACKAGE_OVERRIDE',\n { attributes: { packageName, initiatedBy } },\n async () => {\n const { addedOverride, entry } = await addOverride(input, { session, packages });\n if (entry && addedOverride) {\n const packagePath = entry.path;\n // The import map hash needs to be recalculated to ensure that the client is up to date.\n await packageHashes.get({\n packagePath,\n isSourceHashingEnabled: false,\n shouldRecalculate: true,\n targetEnvironment,\n });\n await taskRunner.clearResult(packagePath);\n // Incrementing the target version will cause the import map to be recalculated.\n session.incrementTargetVersion(packagePath);\n if (session.config.features?.autoUpdateEntries) {\n // We can clear the error message now that the override has been added.\n bus.publish(errorEntrySource, '');\n }\n await notifyHost(\n { reason: 'add-package-override', packagePath, definition: await packages.get(packagePath) },\n { bus, session, telemetryClient },\n );\n }\n return addedOverride;\n },\n );\n}\n\naddPackageOverride.procedure = mutationProcedure<OverrideOptions, boolean>(\n addPackageOverride,\n ZodAddPackageOverrideInput,\n z.boolean(),\n);\n"]}
1
+ {"version":3,"file":"addPackageOverride.js","sourceRoot":"","sources":["../../src/apis/addPackageOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,MAAM,0BAA0B,GAAG,iBAAiB,CAAkB;IACpE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC/B,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;CACtD,CAAC,CAA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MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EACpG,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,CAClC,CAAC;QACJ,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC,CACF,CAAC;AACJ,CAAC;AAED,kBAAkB,CAAC,SAAS,GAAG,iBAAiB,CAC9C,kBAAkB,EAClB,0BAA0B,EAC1B,CAAC,CAAC,OAAO,EAAE,CACZ,CAAC","sourcesContent":["import { z } from 'zod/v4-mini';\nimport { mutationProcedure } from '../trpc/common.js';\nimport { addOverride } from '../utilities/addOverride.js';\nimport type { OverrideOptions } from '../types/OverrideOptions.js';\nimport type { ApiParams } from '../types/ApiParams.js';\nimport { errorEntrySource } from '../data/busSources.js';\nimport { matchingZodObject } from '../utilities/matchingZodObject.js';\nimport { notifyHost } from '../utilities/notifyHost.js';\n\nconst ZodAddPackageOverrideInput = matchingZodObject<OverrideOptions>({\n packageName: z.string(),\n importPath: z.string(),\n version: z.optional(z.string()),\n issuerUrl: z.optional(z.string()),\n initiatedBy: z.literal(['autoUpdateEntries', 'user']),\n});\n\n// TODO: consider whether this should be hardcoded or not\nconst targetEnvironment = 'browser';\n\n/**\n * Adds an override to the Cloudpack config.\n */\nexport async function addPackageOverride(\n params: ApiParams<\n OverrideOptions,\n 'bus' | 'packageHashes' | 'packages' | 'taskRunner' | 'telemetryClient',\n 'config' | 'incrementTargetVersion' | 'resolveMap' | 'sequence' | 'importMap' | 'packageImportPaths'\n >,\n): Promise<boolean> {\n const { input, ctx } = params;\n const { session, bus, packages, taskRunner, packageHashes, telemetryClient } = ctx;\n const { packageName, initiatedBy } = input;\n\n return telemetryClient.tracer.startActiveSpan(\n 'ADD_PACKAGE_OVERRIDE',\n { attributes: { packageName, initiatedBy } },\n async () => {\n const { addedOverride, entry } = await addOverride(input, { session, packages });\n if (entry && addedOverride) {\n const packagePath = entry.path;\n // The import map hash needs to be recalculated to ensure that the client is up to date.\n await packageHashes.get({\n packagePath,\n isSourceHashingEnabled: false,\n shouldRecalculate: true,\n targetEnvironment,\n });\n await taskRunner.clearResult(packagePath);\n // Incrementing the target version will cause the import map to be recalculated.\n session.incrementTargetVersion(packagePath);\n if (session.config.features?.autoUpdateEntries) {\n // We can clear the error message now that the override has been added.\n bus.publish(errorEntrySource, '');\n }\n await notifyHost(\n { reason: 'add-package-override', packageEntry: entry, definition: await packages.get(packagePath) },\n { bus, session, telemetryClient },\n );\n }\n return addedOverride;\n },\n );\n}\n\naddPackageOverride.procedure = mutationProcedure<OverrideOptions, boolean>(\n addPackageOverride,\n ZodAddPackageOverrideInput,\n z.boolean(),\n);\n"]}
@@ -124,9 +124,9 @@ async function ensurePackageBundledInternal(params, ctx) {
124
124
  };
125
125
  const onPackageChange = async () => {
126
126
  const watchedResult = await taskRunner.add(task, { rerun: true });
127
- // If the result was successful, notify potential clients for reload.
127
+ // If the result was successful, notify clients about the package update (HMR or full reload)
128
128
  if (watchedResult.result?.errors?.length === 0) {
129
- await notifyHost({ reason: 'on-package-change', packagePath: packageEntry.path, hash: watchedResult.result.hash }, { bus, session, telemetryClient });
129
+ await notifyHost({ reason: 'on-package-change', packageEntry, hash: watchedResult.result.hash }, { bus, session, telemetryClient });
130
130
  }
131
131
  };
132
132
  await watcher.watch(watchOptions, (changedPaths) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ensurePackageBundled.js","sourceRoot":"","sources":["../../src/apis/ensurePackageBundled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAElF,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAuExD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAgC,EAChC,GAAgC;IAEhC,MAAM,OAAO,GAAiC,EAA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M,EAAE,sBAAsB,EAAE,CAAC;KACnD,CAAC;AACJ,CAAC;AAED,kGAAkG","sourcesContent":["import { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\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';\nimport { notifyHost } from '../utilities/notifyHost.js';\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 ${version ? `${name}@${version}` : 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(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(task, { rerun: true });\n\n // If the result was successful, notify potential clients for reload.\n if (watchedResult.result?.errors?.length === 0) {\n await notifyHost(\n { reason: 'on-package-change', packagePath: packageEntry.path, hash: watchedResult.result.hash },\n { bus, session, telemetryClient },\n );\n }\n };\n await watcher.watch(watchOptions, (changedPaths) => {\n // Filter out the configPaths, we don't want to re-bundle on config changes. CLI will restart it instead.\n const filteredPaths = changedPaths.filter((p) => !config.configPaths?.appConfigPaths.includes(p));\n if (filteredPaths.length > 0) {\n void onPackageChange();\n }\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;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAElF,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAuExD;;;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,OAAO,EAAE,EAAE;QACzE,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CAAC,IAAI,CAAC;gBACpB,IAAI,EAAE,cAAc;gBACpB,OAAO,EAAE,iBAAiB;gBAC1B,WAAW;gBACX,mBAAmB;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM,EAAE;YACN,OAAO;YACP,IAAI;YACJ,UAAU;YACV,GAAG,MAAM;SACV;QACD,gBAAgB;KACjB,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAgC,EAAE,KAAc;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 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';\nimport { notifyHost } from '../utilities/notifyHost.js';\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 ${version ? `${name}@${version}` : 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(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(task, { rerun: true });\n\n // If the result was successful, notify clients about the package update (HMR or full reload)\n if (watchedResult.result?.errors?.length === 0) {\n await notifyHost(\n { reason: 'on-package-change', packageEntry, hash: watchedResult.result.hash },\n { bus, session, telemetryClient },\n );\n }\n };\n await watcher.watch(watchOptions, (changedPaths) => {\n // Filter out the configPaths, we don't want to re-bundle on config changes. CLI will restart it instead.\n const filteredPaths = changedPaths.filter((p) => !config.configPaths?.appConfigPaths.includes(p));\n if (filteredPaths.length > 0) {\n void onPackageChange();\n }\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"]}
@@ -38,4 +38,9 @@ export declare const linkDoneSource: import("@ms-cloudpack/data-bus").DataBusPat
38
38
  export declare const linkDisconnectedSource: import("@ms-cloudpack/data-bus").DataBusPath<z.ZodMiniObject<{
39
39
  reason: z.ZodMiniLiteral<"lost" | "unreachable">;
40
40
  }, z.core.$strip>>;
41
+ /**
42
+ * Used for HMR - notifies browser when a package has been rebuilt.
43
+ * The bundleUrl in each entry point already contains the updated hash.
44
+ */
45
+ export declare const packageUpdateSource: import("@ms-cloudpack/data-bus").DataBusPath<z.ZodMiniObject<import("../utilities/matchingZodObject.js").MatchingZodShape<import("../index.browser.js").PackageUpdatePayload>, z.core.$strip>>;
41
46
  //# sourceMappingURL=busSources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"busSources.d.ts","sourceRoot":"","sources":["../../src/data/busSources.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAQhC;;GAEG;AACH,eAAO,MAAM,iBAAiB,uEAG5B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,qLAG1B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,oLAGzB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,gBAAgB,uEAG3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB,iMAG3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB,sMAG3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,yLAG1B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,kLAGzB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,sBAAsB;;kBAGjC,CAAC"}
1
+ {"version":3,"file":"busSources.d.ts","sourceRoot":"","sources":["../../src/data/busSources.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAShC;;GAEG;AACH,eAAO,MAAM,iBAAiB,uEAG5B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,qLAG1B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,oLAGzB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,gBAAgB,uEAG3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB,iMAG3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,gBAAgB,sMAG3B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,yLAG1B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,kLAGzB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,sBAAsB;;kBAGjC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,gMAG9B,CAAC"}
@@ -7,6 +7,7 @@ import { createDataPath } from '@ms-cloudpack/data-bus';
7
7
  import { ZodNotifyLinkChangeInput } from '../types/NotifyLinkChangeInput.js';
8
8
  import { ZodLinkPathInput, ZodLinkPathOutput } from '../types/LinkPath.js';
9
9
  import { ZodGetLinkConfigOutput } from '../types/GetLinkConfigOutput.js';
10
+ import { ZodPackageUpdatePayload } from '../types/PackageUpdatePayload.js';
10
11
  /**
11
12
  * Used for tracking the reload count.
12
13
  */
@@ -71,4 +72,12 @@ export const linkDisconnectedSource = createDataPath({
71
72
  path: ['link', 'disconnected'],
72
73
  type: z.object({ reason: z.literal(['lost', 'unreachable']) }),
73
74
  });
75
+ /**
76
+ * Used for HMR - notifies browser when a package has been rebuilt.
77
+ * The bundleUrl in each entry point already contains the updated hash.
78
+ */
79
+ export const packageUpdateSource = createDataPath({
80
+ path: ['package', 'update'],
81
+ type: ZodPackageUpdatePayload,
82
+ });
74
83
  //# sourceMappingURL=busSources.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"busSources.js","sourceRoot":"","sources":["../../src/data/busSources.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,wGAAwG;AACxG,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;IAC9C,IAAI,EAAE,CAAC,SAAS,EAAE,SAAS,CAAU;IACrC,IAAI,EAAE,CAAC,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,EAAE,cAAc,CAAU;IACvC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC;CAC/D,CAAC,CAAC","sourcesContent":["// This file is used in the browser,\n// so it must only import types (ts and zod) to not trigger a trpc server error due to bad tree shaking.\nimport { z } from 'zod/v4-mini';\nimport { ZodTaskStats } from '../types/TaskStats.js';\nimport { ZodTaskList } from '../types/TaskList.js';\nimport { createDataPath } from '@ms-cloudpack/data-bus';\nimport { ZodNotifyLinkChangeInput } from '../types/NotifyLinkChangeInput.js';\nimport { ZodLinkPathInput, ZodLinkPathOutput } from '../types/LinkPath.js';\nimport { ZodGetLinkConfigOutput } from '../types/GetLinkConfigOutput.js';\n\n/**\n * Used for tracking the reload count.\n */\nexport const reloadCountSource = createDataPath({\n path: ['session', 'version'] as const,\n type: z.number(),\n});\n\n/**\n * Used for tracking the task stats displayed in the badge.\n */\nexport const taskStatsSource = createDataPath({\n path: ['task', 'stats'] as const,\n type: ZodTaskStats,\n});\n\n/**\n * Used for tracking the list of tasks.\n */\nexport const taskListSource = createDataPath({\n path: ['task', 'list'] as const,\n type: ZodTaskList,\n});\n\n/**\n * Used for tracking entry errors: `Failed to resolve module specifier \"${packageName}@${version}${filePath}\".`\n * This is used to display errors in the UI and to notify the user of the error when autoUpdateEntries is enabled.\n */\nexport const errorEntrySource = createDataPath({\n path: ['error', 'entry'] as const,\n type: z.string(),\n});\n\n/**\n * Used for tracking link updates.\n */\nexport const linkUpdateSource = createDataPath({\n path: ['link', 'update'] as const,\n type: ZodNotifyLinkChangeInput,\n});\n\n/**\n * Used for fetching the host configuration.\n */\nexport const linkConfigSource = createDataPath({\n path: ['link', 'config'] as const,\n type: ZodGetLinkConfigOutput,\n});\n\n/**\n * Used for tracking linked paths.\n */\nexport const linkPathsSource = createDataPath({\n path: ['link', 'paths'] as const,\n type: ZodLinkPathInput,\n});\n\n/**\n * Used for tracking when linking is done.\n */\nexport const linkDoneSource = createDataPath({\n path: ['link', 'done'] as const,\n type: ZodLinkPathOutput,\n});\n\n/**\n * Used for detecting host disconnection on link.\n */\nexport const linkDisconnectedSource = createDataPath({\n path: ['link', 'disconnected'] as const,\n type: z.object({ reason: z.literal(['lost', 'unreachable']) }),\n});\n"]}
1
+ {"version":3,"file":"busSources.js","sourceRoot":"","sources":["../../src/data/busSources.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,wGAAwG;AACxG,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAE3E;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;IAC9C,IAAI,EAAE,CAAC,SAAS,EAAE,SAAS,CAAU;IACrC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACjB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAC;IAC5C,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,CAAU;IAChC,IAAI,EAAE,YAAY;CACnB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC;IAC3C,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAU;IAC/B,IAAI,EAAE,WAAW;CAClB,CAAC,CAAC;AAEH;;;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ser,\n// so it must only import types (ts and zod) to not trigger a trpc server error due to bad tree shaking.\nimport { z } from 'zod/v4-mini';\nimport { ZodTaskStats } from '../types/TaskStats.js';\nimport { ZodTaskList } from '../types/TaskList.js';\nimport { createDataPath } from '@ms-cloudpack/data-bus';\nimport { ZodNotifyLinkChangeInput } from '../types/NotifyLinkChangeInput.js';\nimport { ZodLinkPathInput, ZodLinkPathOutput } from '../types/LinkPath.js';\nimport { ZodGetLinkConfigOutput } from '../types/GetLinkConfigOutput.js';\nimport { ZodPackageUpdatePayload } from '../types/PackageUpdatePayload.js';\n\n/**\n * Used for tracking the reload count.\n */\nexport const reloadCountSource = createDataPath({\n path: ['session', 'version'] as const,\n type: z.number(),\n});\n\n/**\n * Used for tracking the task stats displayed in the badge.\n */\nexport const taskStatsSource = createDataPath({\n path: ['task', 'stats'] as const,\n type: ZodTaskStats,\n});\n\n/**\n * Used for tracking the list of tasks.\n */\nexport const taskListSource = createDataPath({\n path: ['task', 'list'] as const,\n type: ZodTaskList,\n});\n\n/**\n * Used for tracking entry errors: `Failed to resolve module specifier \"${packageName}@${version}${filePath}\".`\n * This is used to display errors in the UI and to notify the user of the error when autoUpdateEntries is enabled.\n */\nexport const errorEntrySource = createDataPath({\n path: ['error', 'entry'] as const,\n type: z.string(),\n});\n\n/**\n * Used for tracking link updates.\n */\nexport const linkUpdateSource = createDataPath({\n path: ['link', 'update'] as const,\n type: ZodNotifyLinkChangeInput,\n});\n\n/**\n * Used for fetching the host configuration.\n */\nexport const linkConfigSource = createDataPath({\n path: ['link', 'config'] as const,\n type: ZodGetLinkConfigOutput,\n});\n\n/**\n * Used for tracking linked paths.\n */\nexport const linkPathsSource = createDataPath({\n path: ['link', 'paths'] as const,\n type: ZodLinkPathInput,\n});\n\n/**\n * Used for tracking when linking is done.\n */\nexport const linkDoneSource = createDataPath({\n path: ['link', 'done'] as const,\n type: ZodLinkPathOutput,\n});\n\n/**\n * Used for detecting host disconnection on link.\n */\nexport const linkDisconnectedSource = createDataPath({\n path: ['link', 'disconnected'] as const,\n type: z.object({ reason: z.literal(['lost', 'unreachable']) }),\n});\n\n/**\n * Used for HMR - notifies browser when a package has been rebuilt.\n * The bundleUrl in each entry point already contains the updated hash.\n */\nexport const packageUpdateSource = createDataPath({\n path: ['package', 'update'] as const,\n type: ZodPackageUpdatePayload,\n});\n"]}
@@ -3,8 +3,9 @@ export type { TaskDescription } from './types/TaskDescription.js';
3
3
  export type { TaskMessage } from './types/TaskMessage.js';
4
4
  export type { TaskList } from './types/TaskList.js';
5
5
  export { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';
6
- export { taskListSource, taskStatsSource, reloadCountSource, errorEntrySource, linkUpdateSource, linkConfigSource, linkPathsSource, linkDoneSource, linkDisconnectedSource, } from './data/busSources.js';
6
+ export { taskListSource, taskStatsSource, reloadCountSource, errorEntrySource, linkUpdateSource, linkConfigSource, linkPathsSource, linkDoneSource, linkDisconnectedSource, packageUpdateSource, } from './data/busSources.js';
7
7
  export type { NotifyLinkChangeInput } from './types/NotifyLinkChangeInput.js';
8
8
  export type { LinkPathInput } from './types/LinkPath.js';
9
9
  export type { GetLinkConfigOutput } from './types/GetLinkConfigOutput.js';
10
+ export type { PackageUpdatePayload } from './types/PackageUpdatePayload.js';
10
11
  //# sourceMappingURL=index.browser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAE9F,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAE9F,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAC9E,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -1,3 +1,3 @@
1
1
  export { createCloudpackClient } from './trpc/createCloudpackClient.js';
2
- export { taskListSource, taskStatsSource, reloadCountSource, errorEntrySource, linkUpdateSource, linkConfigSource, linkPathsSource, linkDoneSource, linkDisconnectedSource, } from './data/busSources.js';
2
+ export { taskListSource, taskStatsSource, reloadCountSource, errorEntrySource, linkUpdateSource, linkConfigSource, linkPathsSource, linkDoneSource, linkDisconnectedSource, packageUpdateSource, } from './data/busSources.js';
3
3
  //# sourceMappingURL=index.browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAE9F,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,GACvB,MAAM,sBAAsB,CAAC","sourcesContent":["export type { TaskStats } from './types/TaskStats.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskList } from './types/TaskList.js';\n\nexport { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';\n\nexport {\n taskListSource,\n taskStatsSource,\n reloadCountSource,\n errorEntrySource,\n linkUpdateSource,\n linkConfigSource,\n linkPathsSource,\n linkDoneSource,\n linkDisconnectedSource,\n} from './data/busSources.js';\n\n// Link proxy required types\nexport type { NotifyLinkChangeInput } from './types/NotifyLinkChangeInput.js';\nexport type { LinkPathInput } from './types/LinkPath.js';\nexport type { GetLinkConfigOutput } from './types/GetLinkConfigOutput.js';\n"]}
1
+ {"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAE9F,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC","sourcesContent":["export type { TaskStats } from './types/TaskStats.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskList } from './types/TaskList.js';\n\nexport { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';\n\nexport {\n taskListSource,\n taskStatsSource,\n reloadCountSource,\n errorEntrySource,\n linkUpdateSource,\n linkConfigSource,\n linkPathsSource,\n linkDoneSource,\n linkDisconnectedSource,\n packageUpdateSource,\n} from './data/busSources.js';\n\n// Link proxy required types\nexport type { NotifyLinkChangeInput } from './types/NotifyLinkChangeInput.js';\nexport type { LinkPathInput } from './types/LinkPath.js';\nexport type { GetLinkConfigOutput } from './types/GetLinkConfigOutput.js';\nexport type { PackageUpdatePayload } from './types/PackageUpdatePayload.js';\n"]}
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod/v4-mini';
2
+ /**
3
+ * Payload for notifying the server about package updates, including entry points and their bundle URLs.
4
+ */
5
+ export interface PackageUpdatePayload {
6
+ packageName: string;
7
+ version: string;
8
+ entryPoints: Array<{
9
+ importPath: string;
10
+ bundleUrl: string;
11
+ }>;
12
+ }
13
+ export declare const ZodPackageUpdatePayload: z.ZodMiniObject<import("../utilities/matchingZodObject.js").MatchingZodShape<PackageUpdatePayload>, z.core.$strip>;
14
+ //# sourceMappingURL=PackageUpdatePayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageUpdatePayload.d.ts","sourceRoot":"","sources":["../../src/types/PackageUpdatePayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAGhC;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,KAAK,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;CACJ;AAED,eAAO,MAAM,uBAAuB,oHASlC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod/v4-mini';
2
+ import { matchingZodObject } from '../utilities/matchingZodObject.js';
3
+ export const ZodPackageUpdatePayload = matchingZodObject({
4
+ packageName: z.string(),
5
+ version: z.string(),
6
+ entryPoints: z.array(z.object({
7
+ importPath: z.string(),
8
+ bundleUrl: z.string(),
9
+ })),
10
+ });
11
+ //# sourceMappingURL=PackageUpdatePayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageUpdatePayload.js","sourceRoot":"","sources":["../../src/types/PackageUpdatePayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AActE,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAuB;IAC7E,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,WAAW,EAAE,CAAC,CAAC,KAAK,CAClB,CAAC,CAAC,MAAM,CAAC;QACP,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;KACtB,CAAC,CACH;CACF,CAAC,CAAC","sourcesContent":["import { z } from 'zod/v4-mini';\nimport { matchingZodObject } from '../utilities/matchingZodObject.js';\n\n/**\n * Payload for notifying the server about package updates, including entry points and their bundle URLs.\n */\nexport interface PackageUpdatePayload {\n packageName: string;\n version: string;\n entryPoints: Array<{\n importPath: string;\n bundleUrl: string;\n }>;\n}\n\nexport const ZodPackageUpdatePayload = matchingZodObject<PackageUpdatePayload>({\n packageName: z.string(),\n version: z.string(),\n entryPoints: z.array(\n z.object({\n importPath: z.string(),\n bundleUrl: z.string(),\n }),\n ),\n});\n"]}
@@ -123,6 +123,7 @@ async function bundleTaskInternal(options, context) {
123
123
  bundlerCapabilities,
124
124
  unsafeCjsExportNames,
125
125
  dedupeAliases,
126
+ hmr: !!config.features?.hmr,
126
127
  };
127
128
  const bundleInternalResult = await bundle(bundleOptions, { config });
128
129
  bundleRequest.result = {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AAa,EAAE,CAAC;YACzB,8DAA8D;YAC9D,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,EAAE,UAAU,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { bundle } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { SpanStatusCode } from '@ms-cloudpack/telemetry';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\nimport { formatBundleTaskResult } from './formatBundleTaskResult.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { writeStubForDensityEntries } from './writeStubForDensityEntries.js';\nimport { getExternalsFromPackage } from './getExternalsFromPackage.js';\nimport { getEntriesMapFromPackage } from './getEntriesMapFromPackage.js';\n\n/**\n * Options for a bundle task.\n */\nexport interface BundleTaskOptions {\n /** Force a bundle to be rerun */\n force?: boolean;\n /** Hash to avoid re-computing */\n hash?: string;\n /** Source hash to avoid recomputing */\n sourceHash?: string;\n /** Retry count for the task */\n retryCount?: number;\n bundleRequest: BundleRequest;\n}\n\nexport type BundleTaskContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient' | 'remoteCacheClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath' | 'dedupeAliases'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest, retryCount } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, session } = context;\n const { sequence } = session;\n\n const task = reporter.addTask(\n `Bundle ${formatPackageName({ name: packageName, version })}${retryCount ? ` (retry ${retryCount})` : ''}`,\n );\n\n try {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\n await bundleTaskInternal(options, context);\n\n span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n packageName: bundleRequest.packageName,\n packageVersion: bundleRequest.version,\n bundleSource: bundleRequest.result?.bundleSource,\n bundler: bundleRequest.result?.bundler,\n bundlerVersion: bundleRequest.result?.bundlerVersion,\n ...(retryCount !== undefined && { retryCount }),\n });\n\n if (bundleRequest.result?.errors?.length) {\n // Set the status to `ERROR`\n span.setStatus({ code: SpanStatusCode.ERROR });\n }\n });\n } catch (err) {\n // If an unexpected error is thrown, add it to the result.\n // This ensures consistent handling of either actual bundler errors or exceptions.\n bundleRequest.result ??= {};\n bundleRequest.result.errors ??= [];\n bundleRequest.result.errors.push({\n text: `Unexpected exception while bundling: ${(err as Error).stack || String(err)}`,\n source: 'bundleTask',\n });\n }\n\n task.complete(formatBundleTaskResult(bundleRequest, reporter));\n}\n\n/**\n * Actually read the result from the cache or call `bundle()`.\n * NOTE: The result is returned by mutating `options.bundleRequest.result`.\n */\nasync function bundleTaskInternal(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version, targetEnvironment } = bundleRequest;\n const { packageHashes, packages, session } = context;\n const { config, dedupeAliases } = session;\n const { mode } = config;\n\n // If force is set, dispose the existing result.\n if (force && bundleRequest.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, targetEnvironment, shouldRecalculate: force, hash }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(\n { packageName, version, inputPath: packagePath, outputPath, targetEnvironment },\n context,\n );\n }\n\n const cacheValidationHash = !isExternal\n ? sourceHash ||\n (await packageHashes.get({\n packagePath,\n targetEnvironment,\n isSourceHashingEnabled: true,\n shouldRecalculate: true,\n }))\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n unsafeCjsExportNames,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n // We need the package name without transforms to ensure we get the original name.\n packageName: (await packages.get(packagePath, { disableTransforms: true })).name,\n bundler,\n minify: mode === 'production',\n targetEnvironment,\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath, targetEnvironment }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n unsafeCjsExportNames,\n dedupeAliases,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n bundleSource: 'bundler',\n };\n\n if (bundlerCapabilities?.density) {\n // Get export maps that need to be written as stubs for density.\n // If there are density exports, write stubs for them.\n const densityResult = await writeStubForDensityEntries({\n options: {\n packageName,\n packagePath,\n result: bundleInternalResult,\n densityOptions: bundlerCapabilities.density,\n },\n context: { packages, config },\n });\n\n // Add errors and warnings to the appropriate arrays\n if (densityResult.errors.length > 0) {\n bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityResult.errors];\n }\n\n if (densityResult.warnings.length > 0) {\n bundleRequest.result.warnings = [...(bundleRequest.result.warnings ?? []), ...densityResult.warnings];\n }\n }\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, { packages, config });\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n packagePath,\n });\n\n bundleRequest.result.info = bundleInfo;\n\n if (config.logBundleInfo) {\n // Write to cache for future use. (Ignore the promise result.)\n void writeJson(path.join(outputPath, 'bundle-info.json'), bundleInfo);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACh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AG,aAAa,CAAC,MAAM,CAAC,CAAC;gBAClG,CAAC;gBAED,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtC,aAAa,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;gBACxG,CAAC;YACH,CAAC;QACH,CAAC;QAED,4BAA4B;QAC5B,MAAM,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,4DAA4D;IAC5D,IAAI,mBAAmB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;QAC9G,+EAA+E;QAC/E,iFAAiF;QACjF,2EAA2E;QAC3E,8CAA8C;QAC9C,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAE9E,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC;YACrC,UAAU;YACV,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,WAAW;YAC7C,UAAU;YACV,UAAU;YACV,WAAW;SACZ,CAAC,CAAC;QAEH,aAAa,CAAC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC;QAEvC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;YACzB,8DAA8D;YAC9D,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,EAAE,UAAU,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { bundle } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { SpanStatusCode } from '@ms-cloudpack/telemetry';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\nimport { formatBundleTaskResult } from './formatBundleTaskResult.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { writeStubForDensityEntries } from './writeStubForDensityEntries.js';\nimport { getExternalsFromPackage } from './getExternalsFromPackage.js';\nimport { getEntriesMapFromPackage } from './getEntriesMapFromPackage.js';\n\n/**\n * Options for a bundle task.\n */\nexport interface BundleTaskOptions {\n /** Force a bundle to be rerun */\n force?: boolean;\n /** Hash to avoid re-computing */\n hash?: string;\n /** Source hash to avoid recomputing */\n sourceHash?: string;\n /** Retry count for the task */\n retryCount?: number;\n bundleRequest: BundleRequest;\n}\n\nexport type BundleTaskContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient' | 'remoteCacheClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath' | 'dedupeAliases'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest, retryCount } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, session } = context;\n const { sequence } = session;\n\n const task = reporter.addTask(\n `Bundle ${formatPackageName({ name: packageName, version })}${retryCount ? ` (retry ${retryCount})` : ''}`,\n );\n\n try {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\n await bundleTaskInternal(options, context);\n\n span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n packageName: bundleRequest.packageName,\n packageVersion: bundleRequest.version,\n bundleSource: bundleRequest.result?.bundleSource,\n bundler: bundleRequest.result?.bundler,\n bundlerVersion: bundleRequest.result?.bundlerVersion,\n ...(retryCount !== undefined && { retryCount }),\n });\n\n if (bundleRequest.result?.errors?.length) {\n // Set the status to `ERROR`\n span.setStatus({ code: SpanStatusCode.ERROR });\n }\n });\n } catch (err) {\n // If an unexpected error is thrown, add it to the result.\n // This ensures consistent handling of either actual bundler errors or exceptions.\n bundleRequest.result ??= {};\n bundleRequest.result.errors ??= [];\n bundleRequest.result.errors.push({\n text: `Unexpected exception while bundling: ${(err as Error).stack || String(err)}`,\n source: 'bundleTask',\n });\n }\n\n task.complete(formatBundleTaskResult(bundleRequest, reporter));\n}\n\n/**\n * Actually read the result from the cache or call `bundle()`.\n * NOTE: The result is returned by mutating `options.bundleRequest.result`.\n */\nasync function bundleTaskInternal(options: BundleTaskOptions, context: BundleTaskContext): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version, targetEnvironment } = bundleRequest;\n const { packageHashes, packages, session } = context;\n const { config, dedupeAliases } = session;\n const { mode } = config;\n\n // If force is set, dispose the existing result.\n if (force && bundleRequest.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, targetEnvironment, shouldRecalculate: force, hash }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(\n { packageName, version, inputPath: packagePath, outputPath, targetEnvironment },\n context,\n );\n }\n\n const cacheValidationHash = !isExternal\n ? sourceHash ||\n (await packageHashes.get({\n packagePath,\n targetEnvironment,\n isSourceHashingEnabled: true,\n shouldRecalculate: true,\n }))\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n unsafeCjsExportNames,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n // We need the package name without transforms to ensure we get the original name.\n packageName: (await packages.get(packagePath, { disableTransforms: true })).name,\n bundler,\n minify: mode === 'production',\n targetEnvironment,\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath, targetEnvironment }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n unsafeCjsExportNames,\n dedupeAliases,\n hmr: !!config.features?.hmr,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n bundleSource: 'bundler',\n };\n\n if (bundlerCapabilities?.density) {\n // Get export maps that need to be written as stubs for density.\n // If there are density exports, write stubs for them.\n const densityResult = await writeStubForDensityEntries({\n options: {\n packageName,\n packagePath,\n result: bundleInternalResult,\n densityOptions: bundlerCapabilities.density,\n },\n context: { packages, config },\n });\n\n // Add errors and warnings to the appropriate arrays\n if (densityResult.errors.length > 0) {\n bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityResult.errors];\n }\n\n if (densityResult.warnings.length > 0) {\n bundleRequest.result.warnings = [...(bundleRequest.result.warnings ?? []), ...densityResult.warnings];\n }\n }\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, { packages, config });\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n packagePath,\n });\n\n bundleRequest.result.info = bundleInfo;\n\n if (config.logBundleInfo) {\n // Write to cache for future use. (Ignore the promise result.)\n void writeJson(path.join(outputPath, 'bundle-info.json'), bundleInfo);\n }\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { ResolveMapEntry } from '@ms-cloudpack/common-types';
2
+ import type { PartialContext } from '../types/Context.js';
3
+ import type { PackageUpdatePayload } from '../types/PackageUpdatePayload.js';
4
+ /**
5
+ * Creates a package update payload for HMR (Hot Module Replacement) updates.
6
+ *
7
+ * This function generates updated bundle URLs for all entry points of a package by replacing
8
+ * the old hash with a new HMR hash that includes a timestamp to prevent ESM module caching issues.
9
+ *
10
+ * @param params - Configuration object
11
+ * @param params.input - Package information including entry, name, version, and hash
12
+ * @param params.context - Partial context containing session with import map and package import paths
13
+ * @returns Package update payload with updated entry point URLs, or undefined if no import map exists
14
+ */
15
+ export declare function createPackageUpdatePayload(params: {
16
+ input: {
17
+ packageEntry: Pick<ResolveMapEntry, 'path' | 'name' | 'version'>;
18
+ hash: string;
19
+ };
20
+ context: PartialContext<'session', 'importMap' | 'packageImportPaths'>;
21
+ }): PackageUpdatePayload | undefined;
22
+ //# sourceMappingURL=createPackageUpdatePayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPackageUpdatePayload.d.ts","sourceRoot":"","sources":["../../src/utilities/createPackageUpdatePayload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,KAAK,EAAE;QAAE,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1F,OAAO,EAAE,cAAc,CAAC,SAAS,EAAE,WAAW,GAAG,oBAAoB,CAAC,CAAC;CACxE,GAAG,oBAAoB,GAAG,SAAS,CAuEnC"}
@@ -0,0 +1,76 @@
1
+ import { addHashUrl } from '@ms-cloudpack/path-string-parsing';
2
+ /**
3
+ * Creates a package update payload for HMR (Hot Module Replacement) updates.
4
+ *
5
+ * This function generates updated bundle URLs for all entry points of a package by replacing
6
+ * the old hash with a new HMR hash that includes a timestamp to prevent ESM module caching issues.
7
+ *
8
+ * @param params - Configuration object
9
+ * @param params.input - Package information including entry, name, version, and hash
10
+ * @param params.context - Partial context containing session with import map and package import paths
11
+ * @returns Package update payload with updated entry point URLs, or undefined if no import map exists
12
+ */
13
+ export function createPackageUpdatePayload(params) {
14
+ // Extract the package entry metadata (name, version, path) and the new content hash
15
+ const { packageEntry, hash } = params.input;
16
+ const { session } = params.context;
17
+ // The import map is required to update module URLs
18
+ // If it doesn't exist, we can't proceed with creating the update payload
19
+ if (!session.importMap) {
20
+ return undefined;
21
+ }
22
+ // Get all import paths (entry points) for this package
23
+ // Example: ['@mypackage/lib', '@mypackage/utils'] for a package with multiple exports
24
+ const importPaths = session.packageImportPaths.get(packageEntry.path) || [];
25
+ // The imports object maps import paths to their bundle URLs
26
+ // Example: { '@mypackage/lib': '/h-abc123/mypackage-lib.js' }
27
+ const imports = session.importMap.imports;
28
+ // Create a unique HMR hash by appending a timestamp to the content hash
29
+ // This ensures each HMR update gets a unique URL, even if the content hash is the same
30
+ //
31
+ // Why we need the timestamp:
32
+ // - ESM modules are cached by URL in the browser
33
+ // - If code changes from A -> B -> A, the content hash might be the same for the first and third state
34
+ // - Without the timestamp, the browser would serve the cached version instead of re-evaluating
35
+ // - The timestamp ensures every HMR update triggers a fresh module load
36
+ //
37
+ // Example: hash='abc123' becomes hmrHash='abc123-1704067200000'
38
+ const hmrHash = `${hash}-${Date.now()}`;
39
+ // Transform each import path into an entry point with an updated bundle URL
40
+ const entryPoints = importPaths
41
+ .map((importPath) => {
42
+ // Look up the current bundle URL for this import path
43
+ // Example: importPath='mypackage/lib' -> oldBundleUrl='/h-old123/mypackage-lib.js'
44
+ const oldBundleUrl = imports[importPath];
45
+ // If there's no existing URL mapping, skip this import path
46
+ // This can happen if the package was recently added or hasn't been bundled yet
47
+ if (!oldBundleUrl) {
48
+ return null;
49
+ }
50
+ // Replace the hash segment in the URL with the new HMR hash
51
+ // Uses addHashUrl to safely replace the hash by finding the package@version location
52
+ // This avoids collision risks with other 'h-' segments that might appear in paths
53
+ //
54
+ // Example transformation:
55
+ // Old URL: 'http://localhost:8080/mypackage@1.0.0/h-old123/bundled/lib.js'
56
+ // New URL: 'http://localhost:8080/mypackage@1.0.0/h-abc123-1704067200000/bundled/lib.js'
57
+ const newBundleUrl = addHashUrl({
58
+ url: oldBundleUrl,
59
+ packageName: packageEntry.name,
60
+ version: packageEntry.version,
61
+ hash: hmrHash,
62
+ });
63
+ // Return an entry point object with the import path and its new bundle URL
64
+ return { importPath, bundleUrl: newBundleUrl };
65
+ })
66
+ // Remove any null entries (import paths that didn't have existing URLs)
67
+ .filter((entry) => entry !== null);
68
+ // Return the complete payload with package metadata and updated entry points
69
+ // This payload will be sent to clients to notify them of the package update
70
+ return {
71
+ packageName: packageEntry.name,
72
+ version: packageEntry.version,
73
+ entryPoints,
74
+ };
75
+ }
76
+ //# sourceMappingURL=createPackageUpdatePayload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPackageUpdatePayload.js","sourceRoot":"","sources":["../../src/utilities/createPackageUpdatePayload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAI/D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAG1C;IACC,oFAAoF;IACpF,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC;IAC5C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC;IAEnC,mDAAmD;IACnD,yEAAyE;IACzE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,uDAAuD;IACvD,sFAAsF;IACtF,MAAM,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAE5E,4DAA4D;IAC5D,8DAA8D;IAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC;IAE1C,wEAAwE;IACxE,uFAAuF;IACvF,EAAE;IACF,6BAA6B;IAC7B,iDAAiD;IACjD,uGAAuG;IACvG,+FAA+F;IAC/F,wEAAwE;IACxE,EAAE;IACF,gEAAgE;IAChE,MAAM,OAAO,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAExC,4EAA4E;IAC5E,MAAM,WAAW,GAAG,WAAW;SAC5B,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAClB,sDAAsD;QACtD,mFAAmF;QACnF,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QAEzC,4DAA4D;QAC5D,+EAA+E;QAC/E,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,4DAA4D;QAC5D,qFAAqF;QACrF,kFAAkF;QAClF,EAAE;QACF,0BAA0B;QAC1B,2EAA2E;QAC3E,yFAAyF;QACzF,MAAM,YAAY,GAAG,UAAU,CAAC;YAC9B,GAAG,EAAE,YAAY;YACjB,WAAW,EAAE,YAAY,CAAC,IAAI;YAC9B,OAAO,EAAE,YAAY,CAAC,OAAO;YAC7B,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;QAEH,2EAA2E;QAC3E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IACjD,CAAC,CAAC;QACF,wEAAwE;SACvE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;IAErC,6EAA6E;IAC7E,4EAA4E;IAC5E,OAAO;QACL,WAAW,EAAE,YAAY,CAAC,IAAI;QAC9B,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,WAAW;KACZ,CAAC;AACJ,CAAC","sourcesContent":["import type { ResolveMapEntry } from '@ms-cloudpack/common-types';\nimport { addHashUrl } from '@ms-cloudpack/path-string-parsing';\nimport type { PartialContext } from '../types/Context.js';\nimport type { PackageUpdatePayload } from '../types/PackageUpdatePayload.js';\n\n/**\n * Creates a package update payload for HMR (Hot Module Replacement) updates.\n *\n * This function generates updated bundle URLs for all entry points of a package by replacing\n * the old hash with a new HMR hash that includes a timestamp to prevent ESM module caching issues.\n *\n * @param params - Configuration object\n * @param params.input - Package information including entry, name, version, and hash\n * @param params.context - Partial context containing session with import map and package import paths\n * @returns Package update payload with updated entry point URLs, or undefined if no import map exists\n */\nexport function createPackageUpdatePayload(params: {\n input: { packageEntry: Pick<ResolveMapEntry, 'path' | 'name' | 'version'>; hash: string };\n context: PartialContext<'session', 'importMap' | 'packageImportPaths'>;\n}): PackageUpdatePayload | undefined {\n // Extract the package entry metadata (name, version, path) and the new content hash\n const { packageEntry, hash } = params.input;\n const { session } = params.context;\n\n // The import map is required to update module URLs\n // If it doesn't exist, we can't proceed with creating the update payload\n if (!session.importMap) {\n return undefined;\n }\n\n // Get all import paths (entry points) for this package\n // Example: ['@mypackage/lib', '@mypackage/utils'] for a package with multiple exports\n const importPaths = session.packageImportPaths.get(packageEntry.path) || [];\n\n // The imports object maps import paths to their bundle URLs\n // Example: { '@mypackage/lib': '/h-abc123/mypackage-lib.js' }\n const imports = session.importMap.imports;\n\n // Create a unique HMR hash by appending a timestamp to the content hash\n // This ensures each HMR update gets a unique URL, even if the content hash is the same\n //\n // Why we need the timestamp:\n // - ESM modules are cached by URL in the browser\n // - If code changes from A -> B -> A, the content hash might be the same for the first and third state\n // - Without the timestamp, the browser would serve the cached version instead of re-evaluating\n // - The timestamp ensures every HMR update triggers a fresh module load\n //\n // Example: hash='abc123' becomes hmrHash='abc123-1704067200000'\n const hmrHash = `${hash}-${Date.now()}`;\n\n // Transform each import path into an entry point with an updated bundle URL\n const entryPoints = importPaths\n .map((importPath) => {\n // Look up the current bundle URL for this import path\n // Example: importPath='mypackage/lib' -> oldBundleUrl='/h-old123/mypackage-lib.js'\n const oldBundleUrl = imports[importPath];\n\n // If there's no existing URL mapping, skip this import path\n // This can happen if the package was recently added or hasn't been bundled yet\n if (!oldBundleUrl) {\n return null;\n }\n\n // Replace the hash segment in the URL with the new HMR hash\n // Uses addHashUrl to safely replace the hash by finding the package@version location\n // This avoids collision risks with other 'h-' segments that might appear in paths\n //\n // Example transformation:\n // Old URL: 'http://localhost:8080/mypackage@1.0.0/h-old123/bundled/lib.js'\n // New URL: 'http://localhost:8080/mypackage@1.0.0/h-abc123-1704067200000/bundled/lib.js'\n const newBundleUrl = addHashUrl({\n url: oldBundleUrl,\n packageName: packageEntry.name,\n version: packageEntry.version,\n hash: hmrHash,\n });\n\n // Return an entry point object with the import path and its new bundle URL\n return { importPath, bundleUrl: newBundleUrl };\n })\n // Remove any null entries (import paths that didn't have existing URLs)\n .filter((entry) => entry !== null);\n\n // Return the complete payload with package metadata and updated entry points\n // This payload will be sent to clients to notify them of the package update\n return {\n packageName: packageEntry.name,\n version: packageEntry.version,\n entryPoints,\n };\n}\n"]}
@@ -1,8 +1,19 @@
1
1
  import type { NotifyLinkChangeInput } from '../types/NotifyLinkChangeInput.js';
2
2
  import type { PartialContext } from '../types/Context.js';
3
3
  import { type NotifyReloadOptions } from './notifyReload.js';
4
+ import type { ResolveMapEntry } from '@ms-cloudpack/common-types';
5
+ type NotifyHostOptions = Omit<NotifyLinkChangeInput, 'packagePath'> & NotifyReloadOptions & {
6
+ packageEntry: Pick<ResolveMapEntry, 'path' | 'name' | 'version'>;
7
+ };
4
8
  /**
5
9
  * Notifies clients that a reload is needed and notifies the host of link changes.
10
+ *
11
+ * If HMR is enabled and the package has entry points in the import map, publishes an HMR update
12
+ * with all entry points for the browser to handle. The browser-side code determines whether React
13
+ * components were updated and either performs fast refresh or falls back to full page reload.
14
+ *
15
+ * Always publishes link updates and reload notifications for backward compatibility and telemetry.
6
16
  */
7
- export declare function notifyHost(options: NotifyLinkChangeInput & NotifyReloadOptions, context: PartialContext<'bus' | 'telemetryClient', 'sequence'>): Promise<void>;
17
+ export declare function notifyHost(options: NotifyHostOptions, context: PartialContext<'bus' | 'telemetryClient' | 'session', 'sequence' | 'importMap' | 'packageImportPaths' | 'config'>): Promise<void>;
18
+ export {};
8
19
  //# sourceMappingURL=notifyHost.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"notifyHost.d.ts","sourceRoot":"","sources":["../../src/utilities/notifyHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,qBAAqB,GAAG,mBAAmB,EACpD,OAAO,EAAE,cAAc,CAAC,KAAK,GAAG,iBAAiB,EAAE,UAAU,CAAC,GAC7D,OAAO,CAAC,IAAI,CAAC,CAKf"}
1
+ {"version":3,"file":"notifyHost.d.ts","sourceRoot":"","sources":["../../src/utilities/notifyHost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE,KAAK,iBAAiB,GAAG,IAAI,CAAC,qBAAqB,EAAE,aAAa,CAAC,GACjE,mBAAmB,GAAG;IACpB,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;CAClE,CAAC;AAEJ;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,cAAc,CACrB,KAAK,GAAG,iBAAiB,GAAG,SAAS,EACrC,UAAU,GAAG,WAAW,GAAG,oBAAoB,GAAG,QAAQ,CAC3D,GACA,OAAO,CAAC,IAAI,CAAC,CAkBf"}
@@ -1,12 +1,28 @@
1
- import { linkUpdateSource } from '../data/busSources.js';
1
+ import { linkUpdateSource, packageUpdateSource } from '../data/busSources.js';
2
2
  import { notifyReload } from './notifyReload.js';
3
+ import { createPackageUpdatePayload } from './createPackageUpdatePayload.js';
3
4
  /**
4
5
  * Notifies clients that a reload is needed and notifies the host of link changes.
6
+ *
7
+ * If HMR is enabled and the package has entry points in the import map, publishes an HMR update
8
+ * with all entry points for the browser to handle. The browser-side code determines whether React
9
+ * components were updated and either performs fast refresh or falls back to full page reload.
10
+ *
11
+ * Always publishes link updates and reload notifications for backward compatibility and telemetry.
5
12
  */
6
13
  export async function notifyHost(options, context) {
7
- const { reason, ...input } = options;
8
- const { bus } = context;
9
- bus.publish(linkUpdateSource, input);
10
- await notifyReload(options, context);
14
+ const { reason, packageEntry, hash, ...input } = options;
15
+ const { bus, session } = context;
16
+ // Always publish link updates
17
+ bus.publish(linkUpdateSource, { packagePath: packageEntry.path, hash, ...input });
18
+ // HMR: Publish package update with all entry points (if HMR is enabled)
19
+ const packageUpdatePayload = session.config.features?.hmr && hash
20
+ ? createPackageUpdatePayload({ input: { packageEntry, hash }, context })
21
+ : undefined;
22
+ if (packageUpdatePayload) {
23
+ bus.publish(packageUpdateSource.path, packageUpdatePayload);
24
+ return;
25
+ }
26
+ await notifyReload({ reason }, context);
11
27
  }
12
28
  //# sourceMappingURL=notifyHost.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notifyHost.js","sourceRoot":"","sources":["../../src/utilities/notifyHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAA4B,MAAM,mBAAmB,CAAC;AAE3E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAoD,EACpD,OAA8D;IAE9D,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IACrC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACxB,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { linkUpdateSource } from '../data/busSources.js';\nimport type { NotifyLinkChangeInput } from '../types/NotifyLinkChangeInput.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { notifyReload, type NotifyReloadOptions } from './notifyReload.js';\n\n/**\n * Notifies clients that a reload is needed and notifies the host of link changes.\n */\nexport async function notifyHost(\n options: NotifyLinkChangeInput & NotifyReloadOptions,\n context: PartialContext<'bus' | 'telemetryClient', 'sequence'>,\n): Promise<void> {\n const { reason, ...input } = options;\n const { bus } = context;\n bus.publish(linkUpdateSource, input);\n await notifyReload(options, context);\n}\n"]}
1
+ {"version":3,"file":"notifyHost.js","sourceRoot":"","sources":["../../src/utilities/notifyHost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG9E,OAAO,EAAE,YAAY,EAA4B,MAAM,mBAAmB,CAAC;AAE3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAO7E;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAA0B,EAC1B,OAGC;IAED,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IACzD,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEjC,8BAA8B;IAC9B,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,WAAW,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;IAElF,wEAAwE;IACxE,MAAM,oBAAoB,GACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,IAAI,IAAI;QAClC,CAAC,CAAC,0BAA0B,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC;QACxE,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,oBAAoB,EAAE,CAAC;QACzB,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;QAC5D,OAAO;IACT,CAAC;IAED,MAAM,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import { linkUpdateSource, packageUpdateSource } from '../data/busSources.js';\nimport type { NotifyLinkChangeInput } from '../types/NotifyLinkChangeInput.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { notifyReload, type NotifyReloadOptions } from './notifyReload.js';\nimport type { ResolveMapEntry } from '@ms-cloudpack/common-types';\nimport { createPackageUpdatePayload } from './createPackageUpdatePayload.js';\n\ntype NotifyHostOptions = Omit<NotifyLinkChangeInput, 'packagePath'> &\n NotifyReloadOptions & {\n packageEntry: Pick<ResolveMapEntry, 'path' | 'name' | 'version'>;\n };\n\n/**\n * Notifies clients that a reload is needed and notifies the host of link changes.\n *\n * If HMR is enabled and the package has entry points in the import map, publishes an HMR update\n * with all entry points for the browser to handle. The browser-side code determines whether React\n * components were updated and either performs fast refresh or falls back to full page reload.\n *\n * Always publishes link updates and reload notifications for backward compatibility and telemetry.\n */\nexport async function notifyHost(\n options: NotifyHostOptions,\n context: PartialContext<\n 'bus' | 'telemetryClient' | 'session',\n 'sequence' | 'importMap' | 'packageImportPaths' | 'config'\n >,\n): Promise<void> {\n const { reason, packageEntry, hash, ...input } = options;\n const { bus, session } = context;\n\n // Always publish link updates\n bus.publish(linkUpdateSource, { packagePath: packageEntry.path, hash, ...input });\n\n // HMR: Publish package update with all entry points (if HMR is enabled)\n const packageUpdatePayload =\n session.config.features?.hmr && hash\n ? createPackageUpdatePayload({ input: { packageEntry, hash }, context })\n : undefined;\n if (packageUpdatePayload) {\n bus.publish(packageUpdateSource.path, packageUpdatePayload);\n return;\n }\n\n await notifyReload({ reason }, context);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/api-server",
3
- "version": "0.65.14",
3
+ "version": "0.66.0",
4
4
  "description": "Internal API server for Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,23 +35,23 @@
35
35
  "test": "cloudpack-scripts test"
36
36
  },
37
37
  "dependencies": {
38
- "@ms-cloudpack/bundler": "^0.27.4",
39
- "@ms-cloudpack/common-types": "^0.33.1",
40
- "@ms-cloudpack/config": "^0.38.22",
41
- "@ms-cloudpack/create-express-app": "^1.10.66",
38
+ "@ms-cloudpack/bundler": "^0.27.5",
39
+ "@ms-cloudpack/common-types": "^0.33.2",
40
+ "@ms-cloudpack/config": "^0.38.23",
41
+ "@ms-cloudpack/create-express-app": "^1.10.67",
42
42
  "@ms-cloudpack/data-bus": "^0.5.1",
43
43
  "@ms-cloudpack/environment": "^0.1.1",
44
- "@ms-cloudpack/esm-stub-utilities": "^0.15.35",
45
- "@ms-cloudpack/file-watcher": "^0.4.24",
46
- "@ms-cloudpack/import-map": "^0.10.63",
44
+ "@ms-cloudpack/esm-stub-utilities": "^0.15.36",
45
+ "@ms-cloudpack/file-watcher": "^0.4.25",
46
+ "@ms-cloudpack/import-map": "^0.10.64",
47
47
  "@ms-cloudpack/json-utilities": "^0.1.11",
48
- "@ms-cloudpack/package-hashes": "^0.8.47",
49
- "@ms-cloudpack/package-utilities": "^13.2.5",
50
- "@ms-cloudpack/path-string-parsing": "^1.2.7",
51
- "@ms-cloudpack/path-utilities": "^3.2.2",
52
- "@ms-cloudpack/remote-cache": "^0.11.57",
48
+ "@ms-cloudpack/package-hashes": "^0.8.48",
49
+ "@ms-cloudpack/package-utilities": "^13.2.6",
50
+ "@ms-cloudpack/path-string-parsing": "^1.3.0",
51
+ "@ms-cloudpack/path-utilities": "^3.2.3",
52
+ "@ms-cloudpack/remote-cache": "^0.11.58",
53
53
  "@ms-cloudpack/task-reporter": "^0.17.4",
54
- "@ms-cloudpack/telemetry": "^0.11.57",
54
+ "@ms-cloudpack/telemetry": "^0.11.58",
55
55
  "@trpc/client": "^11.1.1",
56
56
  "@trpc/server": "^11.1.1",
57
57
  "cors": "^2.8.5",