@ms-cloudpack/api-server 0.21.9 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/lib/apis/ensurePackageBundled.d.ts +17 -17
  2. package/lib/apis/ensurePackageBundled.d.ts.map +1 -1
  3. package/lib/apis/ensurePackageBundled.js +3 -4
  4. package/lib/apis/ensurePackageBundled.js.map +1 -1
  5. package/lib/apis/syncDownload.d.ts.map +1 -1
  6. package/lib/apis/syncDownload.js +1 -0
  7. package/lib/apis/syncDownload.js.map +1 -1
  8. package/lib/apis/syncUpload.d.ts +1 -1
  9. package/lib/apis/syncUpload.d.ts.map +1 -1
  10. package/lib/apis/syncUpload.js.map +1 -1
  11. package/lib/common/createPartialApiContext.d.ts.map +1 -1
  12. package/lib/common/createPartialApiContext.js +13 -2
  13. package/lib/common/createPartialApiContext.js.map +1 -1
  14. package/lib/index.d.ts +0 -1
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +0 -1
  17. package/lib/index.js.map +1 -1
  18. package/lib/startApiServer.d.ts +4 -2
  19. package/lib/startApiServer.d.ts.map +1 -1
  20. package/lib/startApiServer.js +6 -61
  21. package/lib/startApiServer.js.map +1 -1
  22. package/lib/trpc/createAppRouter.d.ts +8 -8
  23. package/lib/trpc/createCloudpackServer.d.ts +6 -4
  24. package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
  25. package/lib/trpc/createCloudpackServer.js.map +1 -1
  26. package/lib/trpc/createContextFactory.d.ts +2 -0
  27. package/lib/trpc/createContextFactory.d.ts.map +1 -1
  28. package/lib/trpc/createContextFactory.js +3 -1
  29. package/lib/trpc/createContextFactory.js.map +1 -1
  30. package/lib/types/ApiServer.d.ts +0 -7
  31. package/lib/types/ApiServer.d.ts.map +1 -1
  32. package/lib/types/ApiServer.js.map +1 -1
  33. package/lib/types/BundleRequest.d.ts +3 -2
  34. package/lib/types/BundleRequest.d.ts.map +1 -1
  35. package/lib/types/BundleRequest.js.map +1 -1
  36. package/lib/types/Context.d.ts +2 -0
  37. package/lib/types/Context.d.ts.map +1 -1
  38. package/lib/types/Context.js.map +1 -1
  39. package/lib/utilities/TaskRunner.d.ts +3 -1
  40. package/lib/utilities/TaskRunner.d.ts.map +1 -1
  41. package/lib/utilities/TaskRunner.js +23 -2
  42. package/lib/utilities/TaskRunner.js.map +1 -1
  43. package/lib/utilities/bundleTask.d.ts.map +1 -1
  44. package/lib/utilities/bundleTask.js +31 -13
  45. package/lib/utilities/bundleTask.js.map +1 -1
  46. package/lib/utilities/createBundleRequestForPackage.d.ts +1 -1
  47. package/lib/utilities/createBundleRequestForPackage.d.ts.map +1 -1
  48. package/lib/utilities/createBundleRequestForPackage.js +6 -7
  49. package/lib/utilities/createBundleRequestForPackage.js.map +1 -1
  50. package/lib/utilities/createBundleTask.d.ts +12 -1
  51. package/lib/utilities/createBundleTask.d.ts.map +1 -1
  52. package/lib/utilities/createBundleTask.js +23 -4
  53. package/lib/utilities/createBundleTask.js.map +1 -1
  54. package/lib/utilities/ensureRemoteCacheEnabled.d.ts +1 -0
  55. package/lib/utilities/ensureRemoteCacheEnabled.d.ts.map +1 -1
  56. package/lib/utilities/getBundleLocation.d.ts +10 -0
  57. package/lib/utilities/getBundleLocation.d.ts.map +1 -0
  58. package/lib/utilities/{getBundleDetails.js → getBundleLocation.js} +8 -13
  59. package/lib/utilities/getBundleLocation.js.map +1 -0
  60. package/lib/utilities/getPackagesToSync.d.ts.map +1 -1
  61. package/lib/utilities/getPackagesToSync.js +6 -5
  62. package/lib/utilities/getPackagesToSync.js.map +1 -1
  63. package/lib/utilities/isCachedResultValid.d.ts.map +1 -1
  64. package/lib/utilities/isCachedResultValid.js +5 -1
  65. package/lib/utilities/isCachedResultValid.js.map +1 -1
  66. package/lib/utilities/parseRequestInfo.d.ts +2 -0
  67. package/lib/utilities/parseRequestInfo.d.ts.map +1 -1
  68. package/lib/utilities/parseRequestInfo.js +5 -4
  69. package/lib/utilities/parseRequestInfo.js.map +1 -1
  70. package/package.json +6 -7
  71. package/lib/utilities/getBundleDetails.d.ts +0 -14
  72. package/lib/utilities/getBundleDetails.d.ts.map +0 -1
  73. package/lib/utilities/getBundleDetails.js.map +0 -1
  74. package/lib/utilities/startWatcher.d.ts +0 -9
  75. package/lib/utilities/startWatcher.d.ts.map +0 -1
  76. package/lib/utilities/startWatcher.js +0 -51
  77. package/lib/utilities/startWatcher.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,6BAA6B,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,mCAAmC,EAAE,MAAM,0CAA0C,CAAC;AAE/F,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAKhC;IACC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,EAAE,eAAe,E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6DAA6D;QAC7D,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;YAExG,OAAO,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,CAAC;YAEzC,8DAA8D;YAC9D,mEAAmE;YACnE,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;SACjC;QAED,aAAa,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvC,kEAAkE;QAClE,MAAM,eAAe,GAAG,aAAa,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;QAC7G,aAAa,CAAC,MAAM,CAAC,OAAO,GAAG,eAAe,IAAI,CAAC,MAAM,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC;KACxF;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { bundle as bundleInternal, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport { readJson, writeJson } from '@ms-cloudpack/json-utilities';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport {\n bulletedList,\n formatPackageName,\n type TaskReporter,\n type TaskReporterTaskResult,\n} from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { findImports } from './findImports.js';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { formatBundleErrors } from './formatBundleErrors.js';\nimport { getFileSizeSync } from './getFileSizeSync.js';\nimport { hashPackage } from './hashPackage.js';\nimport type { BundleOptions } from '@ms-cloudpack/bundler-types';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { diskCacheRatioMetricEventAggregator } from './diskCacheRatioMetricEventAggregator.js';\n\nexport async function bundleTask(params: {\n bundleRequest: BundleRequest;\n options?: BundleTaskOptions;\n reporter?: TaskReporter;\n telemetryClient?: TelemetryClient;\n}): Promise<BundleRequest> {\n const { bundleRequest, options = {}, reporter, telemetryClient } = params;\n const { packageName, version } = bundleRequest;\n const { force } = options || {};\n\n const { rebuild } = bundleRequest?.result || {};\n const taskName = `${rebuild ? `Re-bundle` : `Bundle`} ${formatPackageName({ name: packageName, version })}`;\n\n telemetryClient?.performance.registerAggregator(diskCacheRatioMetricEventAggregator);\n\n const executeBundle = async (): Promise<TaskReporterTaskResult> => {\n if (rebuild) {\n bundleRequest.result = await rebuild();\n bundleRequest.resultFromCache = false;\n } else {\n await bundle(bundleRequest, force);\n }\n\n diskCacheRatioMetricEventAggregator?.record({\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n });\n\n const result = (bundleRequest.result ??= {});\n\n result.outputFiles ??= [];\n result.errors ??= [];\n result.warnings ??= [];\n\n if (!result.outputFiles.length && !result.errors?.length) {\n result.warnings.push({\n text: `No output files were found for \"${packageName}\" in \"${bundleRequest.outputPath}\"`,\n });\n }\n\n return {\n status: result.errors.length ? 'fail' : 'complete',\n ...(result.errors?.length\n ? formatBundleErrors(result.errors)\n : {\n details: bulletedList([\n `Package: ${bundleRequest.packageName}@${bundleRequest.version}`,\n `Bundler: ${bundleRequest.result?.bundlerName || 'unknown'}`,\n `Input path: ${bundleRequest.packagePath}`,\n `Entries:`,\n Object.values(bundleRequest.result?.entries || {}),\n `Output path: ${bundleRequest.outputPath}`,\n bundleRequest.result?.outputFiles?.map(\n (file) =>\n `${safeRelativePath(path.relative(bundleRequest.outputPath, file.outputPath))} (${getFileSizeSync(\n path.resolve(bundleRequest.outputPath, file.outputPath),\n )})`,\n ),\n ]),\n }),\n };\n };\n\n if (reporter) {\n await reporter.runTask(taskName, executeBundle);\n } else {\n await executeBundle();\n }\n\n return bundleRequest;\n}\n\nasync function bundle(bundleRequest: BundleRequest, force?: boolean): Promise<BundleRequest> {\n const { packages, config } = bundleRequest;\n const context = { packages, 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, outputPath, isExternal, disableSourceMaps, enableFindImports, enableCacheInternalPackages } =\n bundleRequest;\n\n // Rehydrate the result if not incremental.\n if ((isExternal || enableCacheInternalPackages) && !force) {\n bundleRequest.result = await readJson(path.join(outputPath, 'result.json'));\n }\n\n const { userPackageSettings } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { bundlerType, bundlerOptions } = userPackageSettings || {};\n\n const bundleOptions: BundleOptions = {\n bundlerType: bundleRequest.bundlerType || bundlerType,\n overrideOptions: bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: !isExternal,\n sourcemap: disableSourceMaps ? undefined : 'linked',\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, context),\n external: await getExternalsFromPackage({ inputPath: packagePath }, context),\n };\n\n const hash =\n !isExternal && enableCacheInternalPackages\n ? await hashPackage({ packagePath, isExternal, additionalProperties: bundleOptions })\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash })) {\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 bundleRequest.result = await bundleInternal(bundleOptions);\n bundleRequest.result.hash = hash;\n\n // Write the result to disk.\n if (isExternal || enableCacheInternalPackages) {\n const result = { ...bundleRequest.result };\n\n // Clear the rawInput/output properties.\n result.rawInput = result.rawOutput = undefined;\n\n await writeJson(path.join(outputPath, 'result.json'), bundleRequest.result);\n }\n }\n\n if (enableFindImports && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const importsPath = path.join(outputPath, 'imports.json');\n let imports = await readJson<Record<string, string[]>>(importsPath);\n\n // If we couldn't rehydrate imports from cache, compute them.\n if (!imports) {\n const scriptPaths = bundleRequest.result.outputFiles.map((f) => path.resolve(outputPath, f.outputPath));\n\n imports = await findImports(scriptPaths);\n\n // Write to cache for future use. (Ignore the promise result.)\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n writeJson(importsPath, imports);\n }\n\n bundleRequest.result.imports = imports;\n\n // Find imports that are in the output files and set dependencies.\n const outputFilePaths = bundleRequest.result.outputFiles?.map((f) => path.resolve(outputPath, f.outputPath));\n bundleRequest.result.imports = outputFilePaths && (await findImports(outputFilePaths));\n }\n\n return bundleRequest;\n}\n"]}
1
+ {"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,6BAA6B,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAA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E,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;QAC7G,aAAa,CAAC,MAAM,CAAC,OAAO,GAAG,eAAe,IAAI,CAAC,MAAM,WAAW,CAAC,eAAe,CAAC,CAAC,CAAC;KACxF;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { bundle as bundleInternal, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport { readJson, writeJson } from '@ms-cloudpack/json-utilities';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport {\n bulletedList,\n formatPackageName,\n type TaskReporter,\n type TaskReporterTaskResult,\n} from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { findImports } from './findImports.js';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { formatBundleErrors } from './formatBundleErrors.js';\nimport { getFileSizeSync } from './getFileSizeSync.js';\nimport { hashPackage } from './hashPackage.js';\nimport type { BundleOptions } from '@ms-cloudpack/bundler-types';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { diskCacheRatioMetricEventAggregator } from './diskCacheRatioMetricEventAggregator.js';\nimport { getBundleLocation } from './getBundleLocation.js';\n\nexport async function bundleTask(params: {\n bundleRequest: BundleRequest;\n options?: BundleTaskOptions;\n reporter?: TaskReporter;\n telemetryClient?: TelemetryClient;\n}): Promise<BundleRequest> {\n const { bundleRequest, options = {}, reporter, telemetryClient } = params;\n const { packageName, version } = bundleRequest;\n const { force } = options || {};\n\n const bundleResult = bundleRequest.result;\n const taskName = `${bundleResult?.rebuild ? `Re-bundle` : `Bundle`} ${formatPackageName({\n name: packageName,\n version,\n })}`;\n\n telemetryClient?.performance.registerAggregator(diskCacheRatioMetricEventAggregator);\n\n const executeBundle = async (): Promise<TaskReporterTaskResult> => {\n if (bundleResult?.rebuild) {\n bundleRequest.result = {\n ...(await bundleResult.rebuild()),\n outputPath: bundleResult.outputPath,\n };\n bundleRequest.resultFromCache = false;\n } else {\n await bundle(bundleRequest, force);\n }\n\n diskCacheRatioMetricEventAggregator?.record({\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n });\n\n const { result } = bundleRequest;\n\n if (!result) {\n return {\n status: 'fail',\n details: `No result was found for \"${packageName}@${version}\"`,\n };\n }\n\n result.outputFiles ??= [];\n result.errors ??= [];\n result.warnings ??= [];\n\n if (!result.outputFiles.length && !result.errors?.length) {\n result.warnings.push({\n text: `No output files were found for \"${packageName}\" in \"${result.outputPath}\"`,\n });\n }\n\n return {\n status: result.errors.length ? 'fail' : 'complete',\n ...(result.errors?.length\n ? formatBundleErrors(result.errors)\n : {\n details: bulletedList([\n `Package: ${bundleRequest.packageName}@${bundleRequest.version}`,\n `Bundler: ${result.bundlerName || 'unknown'}`,\n `Input path: ${bundleRequest.packagePath}`,\n `Entries:`,\n Object.values(result.entries || {}),\n `Output path: ${result.outputPath}`,\n result.outputFiles?.map(\n (file) =>\n `${safeRelativePath(path.relative(result.outputPath, file.outputPath))} (${getFileSizeSync(\n path.resolve(result.outputPath, file.outputPath),\n )})`,\n ),\n ]),\n }),\n };\n };\n\n if (reporter) {\n await reporter.runTask(taskName, executeBundle);\n } else {\n await executeBundle();\n }\n\n return bundleRequest;\n}\n\nasync function bundle(bundleRequest: BundleRequest, force?: boolean): Promise<BundleRequest> {\n const { packages, config } = bundleRequest;\n const context = { packages, 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, disableSourceMaps, enableFindImports, enableCacheInternalPackages } = bundleRequest;\n\n const outputPath = bundleRequest.outputPath ?? (await getBundleLocation({ packagePath }, context)).path;\n\n // Rehydrate the result if not incremental.\n if ((isExternal || enableCacheInternalPackages) && !force) {\n bundleRequest.result = await readJson(path.join(outputPath, 'result.json'));\n }\n\n const { userPackageSettings } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { bundlerType, bundlerOptions } = userPackageSettings || {};\n\n const bundleOptions: BundleOptions = {\n bundlerType: bundleRequest.bundlerType || bundlerType,\n overrideOptions: bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: !isExternal,\n sourcemap: disableSourceMaps ? undefined : 'linked',\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, context),\n external: await getExternalsFromPackage({ inputPath: packagePath }, context),\n };\n\n const hash =\n !isExternal && enableCacheInternalPackages\n ? await hashPackage({ packagePath, isExternal, additionalProperties: bundleOptions })\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash })) {\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 const bundleInternalResult = await bundleInternal(bundleOptions);\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash,\n };\n\n // Write the result to disk.\n if (isExternal || enableCacheInternalPackages) {\n const result = { ...bundleRequest.result };\n\n // Clear the rawInput/output properties.\n result.rawInput = result.rawOutput = undefined;\n\n await writeJson(path.join(outputPath, 'result.json'), bundleRequest.result);\n }\n }\n\n if (enableFindImports && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const importsPath = path.join(outputPath, 'imports.json');\n let imports = await readJson<Record<string, string[]>>(importsPath);\n\n // If we couldn't rehydrate imports from cache, compute them.\n if (!imports) {\n const scriptPaths = bundleRequest.result.outputFiles.map((f) => path.resolve(outputPath, f.outputPath));\n\n imports = await findImports(scriptPaths);\n\n // Write to cache for future use. (Ignore the promise result.)\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n writeJson(importsPath, imports);\n }\n\n bundleRequest.result.imports = imports;\n\n // Find imports that are in the output files and set dependencies.\n const outputFilePaths = bundleRequest.result.outputFiles?.map((f) => path.resolve(outputPath, f.outputPath));\n bundleRequest.result.imports = outputFilePaths && (await findImports(outputFilePaths));\n }\n\n return bundleRequest;\n}\n"]}
@@ -11,5 +11,5 @@ export declare function createBundleRequestForPackage(options: {
11
11
  }, context: {
12
12
  config: CloudpackConfig;
13
13
  packages: PackageDefinitionsCache;
14
- }): Promise<BundleRequest>;
14
+ }): BundleRequest;
15
15
  //# sourceMappingURL=createBundleRequestForPackage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createBundleRequestForPackage.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,wBAAsB,6BAA6B,CACjD,OAAO,EAAE;IACP,YAAY,EAAE,eAAe,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IACP,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,aAAa,CAAC,CAoBxB"}
1
+ {"version":3,"file":"createBundleRequestForPackage.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE;IACP,YAAY,EAAE,eAAe,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IACP,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,aAAa,CAoBf"}
@@ -1,20 +1,19 @@
1
- import { getBundleDetails } from '../utilities/getBundleDetails.js';
2
- export async function createBundleRequestForPackage(options, context) {
1
+ export function createBundleRequestForPackage(options, context) {
3
2
  const { packageEntry } = options;
4
3
  const { config } = context;
5
4
  const { features = {} } = config;
6
- const { path, version, name } = packageEntry;
7
- const { bundleId, isExternal, outputLocation } = await getBundleDetails({ packagePath: path }, context);
5
+ const { path, version, name, isExternal } = packageEntry;
8
6
  return {
9
- id: bundleId,
7
+ id: path,
10
8
  packagePath: path,
11
9
  packageName: name,
12
- isExternal,
13
- outputPath: options.outputPath ?? outputLocation.path,
10
+ isExternal: !!isExternal,
11
+ outputPath: options.outputPath,
14
12
  version,
15
13
  disableSourceMaps: options.disableSourceMaps ?? features.disableSourceMaps,
16
14
  enableFindImports: options.enableFindImports ?? features.enqueueDependencies,
17
15
  enableCacheInternalPackages: features.cacheInternalPackages,
16
+ hashPackages: features.hashPackages,
18
17
  bundlerType: options.bundlerType,
19
18
  ...context,
20
19
  };
@@ -1 +1 @@
1
- {"version":3,"file":"createBundleRequestForPackage.js","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAGpE,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,OAMC,EACD,OAGC;IAED,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IACjC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC;IAC7C,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;IAExG,OAAO;QACL,EAAE,EAAE,QAAQ;QACZ,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,UAAU;QACV,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC,IAAI;QACrD,OAAO;QACP,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,QAAQ,CAAC,iBAAiB;QAC1E,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,QAAQ,CAAC,mBAAmB;QAC5E,2BAA2B,EAAE,QAAQ,CAAC,qBAAqB;QAC3D,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,OAAO;KACX,CAAC;AACJ,CAAC","sourcesContent":["import type { CloudpackConfig } from '@ms-cloudpack/config';\nimport type { ResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { getBundleDetails } from '../utilities/getBundleDetails.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\n\nexport async function createBundleRequestForPackage(\n options: {\n packageEntry: ResolveMapEntry;\n outputPath?: string;\n bundlerType?: string;\n disableSourceMaps?: boolean;\n enableFindImports?: boolean;\n },\n context: {\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\n },\n): Promise<BundleRequest> {\n const { packageEntry } = options;\n const { config } = context;\n const { features = {} } = config;\n const { path, version, name } = packageEntry;\n const { bundleId, isExternal, outputLocation } = await getBundleDetails({ packagePath: path }, context);\n\n return {\n id: bundleId,\n packagePath: path,\n packageName: name,\n isExternal,\n outputPath: options.outputPath ?? outputLocation.path,\n version,\n disableSourceMaps: options.disableSourceMaps ?? features.disableSourceMaps,\n enableFindImports: options.enableFindImports ?? features.enqueueDependencies,\n enableCacheInternalPackages: features.cacheInternalPackages,\n bundlerType: options.bundlerType,\n ...context,\n };\n}\n"]}
1
+ {"version":3,"file":"createBundleRequestForPackage.js","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,6BAA6B,CAC3C,OAMC,EACD,OAGC;IAED,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IACjC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,YAAY,CAAC;IAEzD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,OAAO;QACP,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,QAAQ,CAAC,iBAAiB;QAC1E,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,QAAQ,CAAC,mBAAmB;QAC5E,2BAA2B,EAAE,QAAQ,CAAC,qBAAqB;QAC3D,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,OAAO;KACX,CAAC;AACJ,CAAC","sourcesContent":["import type { CloudpackConfig } from '@ms-cloudpack/config';\nimport type { ResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { BundleRequest } from '../types/BundleRequest.js';\n\nexport function createBundleRequestForPackage(\n options: {\n packageEntry: ResolveMapEntry;\n outputPath?: string;\n bundlerType?: string;\n disableSourceMaps?: boolean;\n enableFindImports?: boolean;\n },\n context: {\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\n },\n): BundleRequest {\n const { packageEntry } = options;\n const { config } = context;\n const { features = {} } = config;\n const { path, version, name, isExternal } = packageEntry;\n\n return {\n id: path,\n packagePath: path,\n packageName: name,\n isExternal: !!isExternal,\n outputPath: options.outputPath,\n version,\n disableSourceMaps: options.disableSourceMaps ?? features.disableSourceMaps,\n enableFindImports: options.enableFindImports ?? features.enqueueDependencies,\n enableCacheInternalPackages: features.cacheInternalPackages,\n hashPackages: features.hashPackages,\n bundlerType: options.bundlerType,\n ...context,\n };\n}\n"]}
@@ -2,10 +2,21 @@ import type { BundleTaskOptions } from '../types/BundleTaskOptions.js';
2
2
  import type { BundleRequest } from '../types/BundleRequest.js';
3
3
  import type { Task } from '../types/Task.js';
4
4
  import type { TaskReporter } from '@ms-cloudpack/task-reporter';
5
+ import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
6
+ import type { CloudpackConfig } from '@ms-cloudpack/config';
7
+ import type { Session } from '../types/Session.js';
5
8
  import type { TelemetryClient } from '@ms-cloudpack/telemetry';
9
+ import type { PackageImportPaths } from '@ms-cloudpack/package-utilities';
6
10
  /**
7
11
  * Creates a bundle task tracked in the task runner of the api server. This allows active tasks to be tracked
8
12
  * remotely (e.g. in the browser) and allows the user to cancel tasks.
9
13
  */
10
- export declare function createBundleTask(bundleRequest: BundleRequest, options?: BundleTaskOptions, reporter?: TaskReporter, telemetryClient?: TelemetryClient): Task<BundleRequest>;
14
+ export declare function createBundleTask(bundleRequest: BundleRequest, context: {
15
+ packages: PackageDefinitionsCache;
16
+ packageImportPaths: PackageImportPaths;
17
+ config: CloudpackConfig;
18
+ session: Session;
19
+ reporter?: TaskReporter;
20
+ telemetryClient?: TelemetryClient;
21
+ }, options?: BundleTaskOptions): Task<BundleRequest>;
11
22
  //# sourceMappingURL=createBundleTask.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createBundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAK7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,iBAAiB,EAC3B,QAAQ,CAAC,EAAE,YAAY,EACvB,eAAe,CAAC,EAAE,eAAe,GAChC,IAAI,CAAC,aAAa,CAAC,CAoCrB"}
1
+ {"version":3,"file":"createBundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAK7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;IAClC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,EACD,OAAO,CAAC,EAAE,iBAAiB,GAC1B,IAAI,CAAC,aAAa,CAAC,CAuDrB"}
@@ -1,12 +1,14 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
3
  import { bundleTask } from './bundleTask.js';
4
+ import { addImportMapHash } from '@ms-cloudpack/package-utilities';
4
5
  /**
5
6
  * Creates a bundle task tracked in the task runner of the api server. This allows active tasks to be tracked
6
7
  * remotely (e.g. in the browser) and allows the user to cancel tasks.
7
8
  */
8
- export function createBundleTask(bundleRequest, options, reporter, telemetryClient) {
9
+ export function createBundleTask(bundleRequest, context, options) {
9
10
  const { id, packageName, version, outputPath, packagePath, isExternal } = bundleRequest;
11
+ const { packages, config, session, reporter, telemetryClient, packageImportPaths } = context;
10
12
  return {
11
13
  name: `Bundle ${packageName}@${version}`,
12
14
  id,
@@ -14,13 +16,30 @@ export function createBundleTask(bundleRequest, options, reporter, telemetryClie
14
16
  watch: !isExternal,
15
17
  async execute() {
16
18
  await bundleTask({ bundleRequest, options, reporter, telemetryClient });
19
+ if (config?.features?.hashPackages) {
20
+ if (!isExternal) {
21
+ packages.removeHash(packagePath);
22
+ }
23
+ try {
24
+ const hash = await packages.getHash(packagePath);
25
+ addImportMapHash(packageName, version, session.getImportMap(), session.resolveMap, hash, {
26
+ packageImportPaths,
27
+ });
28
+ }
29
+ catch (e) {
30
+ console.error(`Error adding hash to import map for ${bundleRequest.packagePath}`, e);
31
+ }
32
+ }
17
33
  return bundleRequest;
18
34
  },
19
35
  clear: () => {
20
- bundleRequest.result?.dispose?.();
21
- bundleRequest.result = undefined;
36
+ if (!bundleRequest.result) {
37
+ return;
38
+ }
39
+ bundleRequest.result.dispose?.();
22
40
  // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem -- this function can't be async
23
- fs.rmSync(outputPath, { recursive: true, force: true });
41
+ fs.rmSync(bundleRequest.result.outputPath, { recursive: true, force: true });
42
+ bundleRequest.result = undefined;
24
43
  },
25
44
  onDispose: () => {
26
45
  bundleRequest.result?.dispose?.();
@@ -1 +1 @@
1
- {"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7C;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,aAA4B,EAC5B,OAA2B,EAC3B,QAAuB,EACvB,eAAiC;IAEjC,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IAExF,OAAO;QACL,IAAI,EAAE,UAAU,WAAW,IAAI,OAAO,EAAE;QACxC,EAAE;QACF,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,EAAE;QACvC,KAAK,EAAE,CAAC,UAAU;QAClB,KAAK,CAAC,OAAO;YACX,MAAM,UAAU,CAAC,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,CAAC;YAExE,OAAO,aAAa,CAAC;QACvB,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC;YAClC,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC;YACjC,qGAAqG;YACrG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1D,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,IAAI,EAAE,UAAU,WAAW,IAAI,OAAO,EAAE;YACxC,SAAS,EAAE,WAAW,IAAI,EAAE;YAC5B,UAAU;SACX,CAAC;QACF,iBAAiB,EAAE,CAAC,UAAU,EAAE,EAAE,CAChC,CAAC;YACC,EAAE;YACF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;YAClC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ;SACvC,CAAuB;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { Task } from '../types/Task.js';\nimport type { TaskEndDescription } from '../types/TaskEndDescription.js';\nimport path from 'path';\nimport fs from 'fs';\nimport { bundleTask } from './bundleTask.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\n\n/**\n * Creates a bundle task tracked in the task runner of the api server. This allows active tasks to be tracked\n * remotely (e.g. in the browser) and allows the user to cancel tasks.\n */\nexport function createBundleTask(\n bundleRequest: BundleRequest,\n options?: BundleTaskOptions,\n reporter?: TaskReporter,\n telemetryClient?: TelemetryClient,\n): Task<BundleRequest> {\n const { id, packageName, version, outputPath, packagePath, isExternal } = bundleRequest;\n\n return {\n name: `Bundle ${packageName}@${version}`,\n id,\n dir: `${path.join(packagePath, 'src')}`,\n watch: !isExternal,\n async execute(): Promise<BundleRequest> {\n await bundleTask({ bundleRequest, options, reporter, telemetryClient });\n\n return bundleRequest;\n },\n clear: () => {\n bundleRequest.result?.dispose?.();\n bundleRequest.result = undefined;\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem -- this function can't be async\n fs.rmSync(outputPath, { recursive: true, force: true });\n },\n onDispose: () => {\n bundleRequest.result?.dispose?.();\n },\n getErrors: () => bundleRequest.result?.errors,\n getStartDescription: () => ({\n id,\n name: `Bundle ${packageName}@${version}`,\n inputPath: packagePath || '',\n outputPath,\n }),\n getEndDescription: (taskResult) =>\n ({\n id,\n errors: taskResult?.result?.errors,\n warnings: taskResult?.result?.warnings,\n }) as TaskEndDescription,\n };\n}\n"]}
1
+ {"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAKnE;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,aAA4B,EAC5B,OAOC,EACD,OAA2B;IAE3B,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IACxF,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC;IAE7F,OAAO;QACL,IAAI,EAAE,UAAU,WAAW,IAAI,OAAO,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AG,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM;QAC7C,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC1B,EAAE;YACF,IAAI,EAAE,UAAU,WAAW,IAAI,OAAO,EAAE;YACxC,SAAS,EAAE,WAAW,IAAI,EAAE;YAC5B,UAAU;SACX,CAAC;QACF,iBAAiB,EAAE,CAAC,UAAU,EAAE,EAAE,CAChC,CAAC;YACC,EAAE;YACF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;YAClC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ;SACvC,CAAuB;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { Task } from '../types/Task.js';\nimport type { TaskEndDescription } from '../types/TaskEndDescription.js';\nimport path from 'path';\nimport fs from 'fs';\nimport { bundleTask } from './bundleTask.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport { addImportMapHash } from '@ms-cloudpack/package-utilities';\nimport type { Session } from '../types/Session.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { PackageImportPaths } from '@ms-cloudpack/package-utilities';\n\n/**\n * Creates a bundle task tracked in the task runner of the api server. This allows active tasks to be tracked\n * remotely (e.g. in the browser) and allows the user to cancel tasks.\n */\nexport function createBundleTask(\n bundleRequest: BundleRequest,\n context: {\n packages: PackageDefinitionsCache;\n packageImportPaths: PackageImportPaths;\n config: CloudpackConfig;\n session: Session;\n reporter?: TaskReporter;\n telemetryClient?: TelemetryClient;\n },\n options?: BundleTaskOptions,\n): Task<BundleRequest> {\n const { id, packageName, version, outputPath, packagePath, isExternal } = bundleRequest;\n const { packages, config, session, reporter, telemetryClient, packageImportPaths } = context;\n\n return {\n name: `Bundle ${packageName}@${version}`,\n id,\n dir: `${path.join(packagePath, 'src')}`,\n watch: !isExternal,\n async execute(): Promise<BundleRequest> {\n await bundleTask({ bundleRequest, options, reporter, telemetryClient });\n if (config?.features?.hashPackages) {\n if (!isExternal) {\n packages.removeHash(packagePath);\n }\n try {\n const hash = await packages.getHash(packagePath);\n addImportMapHash(packageName, version, session.getImportMap(), session.resolveMap, hash, {\n packageImportPaths,\n });\n } catch (e) {\n console.error(`Error adding hash to import map for ${bundleRequest.packagePath}`, e);\n }\n }\n return bundleRequest;\n },\n clear: () => {\n if (!bundleRequest.result) {\n return;\n }\n\n bundleRequest.result.dispose?.();\n\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem -- this function can't be async\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: `Bundle ${packageName}@${version}`,\n inputPath: packagePath || '',\n outputPath,\n }),\n getEndDescription: (taskResult) =>\n ({\n id,\n errors: taskResult?.result?.errors,\n warnings: taskResult?.result?.warnings,\n }) as TaskEndDescription,\n };\n}\n"]}
@@ -7,5 +7,6 @@ import type { CloudpackConfig } from '@ms-cloudpack/config';
7
7
  export declare function ensureRemoteCacheEnabled({ remoteCache }: CloudpackConfig): {
8
8
  storageAccount: string;
9
9
  container: string;
10
+ tokenExpiresInMs?: number | undefined;
10
11
  };
11
12
  //# sourceMappingURL=ensureRemoteCacheEnabled.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ensureRemoteCacheEnabled.d.ts","sourceRoot":"","sources":["../../src/utilities/ensureRemoteCacheEnabled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,WAAW,EAAE,EAAE,eAAe;;;EAMxE"}
1
+ {"version":3,"file":"ensureRemoteCacheEnabled.d.ts","sourceRoot":"","sources":["../../src/utilities/ensureRemoteCacheEnabled.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,WAAW,EAAE,EAAE,eAAe;;;;EAMxE"}
@@ -0,0 +1,10 @@
1
+ import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
+ export declare function getBundleLocation(options: {
3
+ packagePath: string;
4
+ }, context: {
5
+ packages: PackageDefinitionsCache;
6
+ }): Promise<{
7
+ path: string;
8
+ folderName: string;
9
+ }>;
10
+ //# sourceMappingURL=getBundleLocation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBundleLocation.d.ts","sourceRoot":"","sources":["../../src/utilities/getBundleLocation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,wBAAsB,iBAAiB,CACrC,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,EAChC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE;;;GA+B/C"}
@@ -3,33 +3,28 @@ import hash from 'object-hash';
3
3
  import filenamify from 'filenamify';
4
4
  import path from 'path';
5
5
  import { getCachePath } from './getCachePath.js';
6
- export async function getBundleDetails(options, context) {
6
+ export async function getBundleLocation(options, context) {
7
7
  const { packagePath } = options;
8
8
  const { packages } = context;
9
9
  const definition = await packages.get(packagePath);
10
10
  if (!definition) {
11
11
  throw new Error(`Package definition (package.json) missing or invalid at "${packagePath}"`);
12
12
  }
13
- const { name: packageName, version } = definition;
14
- if (!packageName) {
13
+ if (!definition.name) {
15
14
  throw new Error(`Package definition (package.json) missing name at "${packagePath}"`);
16
15
  }
16
+ const { name, version } = definition;
17
17
  const isExternal = isExternalPackage(packagePath);
18
- const bundleId = hash({
19
- name: packageName,
18
+ const hashResult = hash({
20
19
  ...definition,
21
20
  version: (isExternal ? version : packagePath) || packagePath,
22
21
  });
23
22
  // Derive where the output should be.
24
- const folderName = `${filenamify(packageName)}-${version}-${bundleId}`;
23
+ const folderName = `${filenamify(name)}-${version}-${hashResult}`;
25
24
  const outputPath = path.join(getCachePath(), folderName);
26
25
  return {
27
- bundleId,
28
- isExternal,
29
- outputLocation: {
30
- path: outputPath,
31
- folderName,
32
- },
26
+ path: outputPath,
27
+ folderName,
33
28
  };
34
29
  }
35
- //# sourceMappingURL=getBundleDetails.js.map
30
+ //# sourceMappingURL=getBundleLocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBundleLocation.js","sourceRoot":"","sources":["../../src/utilities/getBundleLocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAgC,EAChC,OAA8C;IAE9C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAEnD,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,4DAA4D,WAAW,GAAG,CAAC,CAAC;KAC7F;IAED,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,sDAAsD,WAAW,GAAG,CAAC,CAAC;KACvF;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAErC,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAElD,MAAM,UAAU,GAAG,IAAI,CAAC;QACtB,GAAG,UAAU;QACb,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,WAAW;KAC7D,CAAC,CAAC;IAEH,qCAAqC;IACrC,MAAM,UAAU,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,OAAO,IAAI,UAAU,EAAE,CAAC;IAClE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,UAAU,CAAC,CAAC;IAEzD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["import { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport hash from 'object-hash';\nimport filenamify from 'filenamify';\nimport path from 'path';\nimport { getCachePath } from './getCachePath.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport async function getBundleLocation(\n options: { packagePath: string },\n context: { packages: PackageDefinitionsCache },\n) {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath);\n\n if (!definition) {\n throw new Error(`Package definition (package.json) missing or invalid at \"${packagePath}\"`);\n }\n\n if (!definition.name) {\n throw new Error(`Package definition (package.json) missing name at \"${packagePath}\"`);\n }\n\n const { name, version } = definition;\n\n const isExternal = isExternalPackage(packagePath);\n\n const hashResult = hash({\n ...definition,\n version: (isExternal ? version : packagePath) || packagePath,\n });\n\n // Derive where the output should be.\n const folderName = `${filenamify(name)}-${version}-${hashResult}`;\n const outputPath = path.join(getCachePath(), folderName);\n\n return {\n path: outputPath,\n folderName,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getPackagesToSync.d.ts","sourceRoot":"","sources":["../../src/utilities/getPackagesToSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAuB,KAAK,UAAU,EAAwB,MAAM,iCAAiC,CAAC;AAG7G,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAqB3B"}
1
+ {"version":3,"file":"getPackagesToSync.d.ts","sourceRoot":"","sources":["../../src/utilities/getPackagesToSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAGL,KAAK,UAAU,EAEhB,MAAM,iCAAiC,CAAC;AAGzC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAsB3B"}
@@ -1,5 +1,5 @@
1
- import { findResolveMapEntry } from '@ms-cloudpack/package-utilities';
2
- import { getBundleDetails } from './getBundleDetails.js';
1
+ import { findResolveMapEntry, isExternalPackage, } from '@ms-cloudpack/package-utilities';
2
+ import { getBundleLocation } from './getBundleLocation.js';
3
3
  export async function getPackagesToSync(options) {
4
4
  const { packages, resolveMap } = options;
5
5
  const list = [];
@@ -10,9 +10,10 @@ export async function getPackagesToSync(options) {
10
10
  }))
11
11
  .filter((item) => item);
12
12
  for (const { path: packagePath, name, version } of packageEntries) {
13
- const details = await getBundleDetails({ packagePath }, { packages });
14
- if (details.isExternal) {
15
- list.push({ ...details.outputLocation, friendlyName: `${name}@${version}` });
13
+ const isExternal = isExternalPackage(packagePath);
14
+ const outputLocation = await getBundleLocation({ packagePath }, { packages });
15
+ if (isExternal) {
16
+ list.push({ ...outputLocation, friendlyName: `${name}@${version}` });
16
17
  }
17
18
  }
18
19
  return list;
@@ -1 +1 @@
1
- {"version":3,"file":"getPackagesToSync.js","sourceRoot":"","sources":["../../src/utilities/getPackagesToSync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAyC,MAAM,iCAAiC,CAAC;AAC7G,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQzD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAGvC;IACC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,IAAI,GAAoB,EAAE,CAAC;IAEjC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;SAC3C,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CACnB,mBAAmB,CAAC;QAClB,WAAW;QACX,UAAU;KACX,CAAC,CACH;SACA,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAsB,CAAC;IAE/C,KAAK,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,cAAc,EAAE;QACjE,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACtE,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,YAAY,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE,EAAE,CAAC,CAAC;SAC9E;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { findResolveMapEntry, type ResolveMap, type ResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { getBundleDetails } from './getBundleDetails.js';\n\nexport interface PackageToSync {\n path: string;\n folderName: string;\n friendlyName: string;\n}\n\nexport async function getPackagesToSync(options: {\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n}): Promise<PackageToSync[]> {\n const { packages, resolveMap } = options;\n const list: PackageToSync[] = [];\n\n const packageEntries = Object.keys(resolveMap)\n .map((packageName) =>\n findResolveMapEntry({\n packageName,\n resolveMap,\n }),\n )\n .filter((item) => item) as ResolveMapEntry[];\n\n for (const { path: packagePath, name, version } of packageEntries) {\n const details = await getBundleDetails({ packagePath }, { packages });\n if (details.isExternal) {\n list.push({ ...details.outputLocation, friendlyName: `${name}@${version}` });\n }\n }\n\n return list;\n}\n"]}
1
+ {"version":3,"file":"getPackagesToSync.js","sourceRoot":"","sources":["../../src/utilities/getPackagesToSync.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAGlB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAQ3D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAGvC;IACC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,IAAI,GAAoB,EAAE,CAAC;IAEjC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;SAC3C,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CACnB,mBAAmB,CAAC;QAClB,WAAW;QACX,UAAU;KACX,CAAC,CACH;SACA,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAsB,CAAC;IAE/C,KAAK,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,cAAc,EAAE;QACjE,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAClD,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9E,IAAI,UAAU,EAAE;YACd,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,cAAc,EAAE,YAAY,EAAE,GAAG,IAAI,IAAI,OAAO,EAAE,EAAE,CAAC,CAAC;SACtE;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport {\n findResolveMapEntry,\n isExternalPackage,\n type ResolveMap,\n type ResolveMapEntry,\n} from '@ms-cloudpack/package-utilities';\nimport { getBundleLocation } from './getBundleLocation.js';\n\nexport interface PackageToSync {\n path: string;\n folderName: string;\n friendlyName: string;\n}\n\nexport async function getPackagesToSync(options: {\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n}): Promise<PackageToSync[]> {\n const { packages, resolveMap } = options;\n const list: PackageToSync[] = [];\n\n const packageEntries = Object.keys(resolveMap)\n .map((packageName) =>\n findResolveMapEntry({\n packageName,\n resolveMap,\n }),\n )\n .filter((item) => item) as ResolveMapEntry[];\n\n for (const { path: packagePath, name, version } of packageEntries) {\n const isExternal = isExternalPackage(packagePath);\n const outputLocation = await getBundleLocation({ packagePath }, { packages });\n if (isExternal) {\n list.push({ ...outputLocation, friendlyName: `${name}@${version}` });\n }\n }\n\n return list;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"isCachedResultValid.d.ts","sourceRoot":"","sources":["../../src/utilities/isCachedResultValid.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,UAAU,0BAA0B;IAClC,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAyBhF"}
1
+ {"version":3,"file":"isCachedResultValid.d.ts","sourceRoot":"","sources":["../../src/utilities/isCachedResultValid.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,UAAU,0BAA0B;IAClC,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CA8BhF"}
@@ -11,10 +11,14 @@ export function isCachedResultValid(options) {
11
11
  // The result is undefined, so the result is invalid
12
12
  return false;
13
13
  }
14
- if (result?.errors?.length) {
14
+ if (result.errors?.length) {
15
15
  // There are errors, so the result is invalid
16
16
  return false;
17
17
  }
18
+ if (!result.outputPath) {
19
+ // outputPath used to be an optional field, however, we do not want it to be undefined anymore.
20
+ return false;
21
+ }
18
22
  if (enableCacheInternalPackages && !isExternal && result.hash !== hash) {
19
23
  // The package is internal, enableCacheInternalPackages is enabled but hashes do not match, this is an invalid result.
20
24
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"isCachedResultValid.js","sourceRoot":"","sources":["../../src/utilities/isCachedResultValid.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmC;IACrE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;IAE1E,IAAI,CAAC,MAAM,EAAE;QACX,oDAAoD;QACpD,OAAO,KAAK,CAAC;KACd;IAED,IAAI,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;QAC1B,6CAA6C;QAC7C,OAAO,KAAK,CAAC;KACd;IAED,IAAI,2BAA2B,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;QACtE,sHAAsH;QACtH,OAAO,KAAK,CAAC;KACd;IAED,gCAAgC;IAChC,IAAI,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE;QAC7E,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import path from 'path';\nimport type { BundleRequest } from '../types/BundleRequest.js';\n\ninterface IsCachedResultValidOptions {\n bundleRequest: BundleRequest;\n hash?: string;\n}\n\n/**\n * Validates the result of a bundle request.\n * @param options - The options to use when validating the result.\n * @returns True if the result is valid, false otherwise.\n */\nexport function isCachedResultValid(options: IsCachedResultValidOptions): boolean {\n const { bundleRequest, hash } = options;\n const { enableCacheInternalPackages, isExternal, result } = bundleRequest;\n\n if (!result) {\n // The result is undefined, so the result is invalid\n return false;\n }\n\n if (result?.errors?.length) {\n // There are errors, so the result is invalid\n return false;\n }\n\n if (enableCacheInternalPackages && !isExternal && result.hash !== hash) {\n // The package is internal, enableCacheInternalPackages is enabled but hashes do not match, this is an invalid result.\n return false;\n }\n\n // Output files must be relative\n if (result.outputFiles?.find(({ outputPath }) => path.isAbsolute(outputPath))) {\n return false;\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"isCachedResultValid.js","sourceRoot":"","sources":["../../src/utilities/isCachedResultValid.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmC;IACrE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;IAE1E,IAAI,CAAC,MAAM,EAAE;QACX,oDAAoD;QACpD,OAAO,KAAK,CAAC;KACd;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE;QACzB,6CAA6C;QAC7C,OAAO,KAAK,CAAC;KACd;IAED,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;QACtB,+FAA+F;QAC/F,OAAO,KAAK,CAAC;KACd;IAED,IAAI,2BAA2B,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE;QACtE,sHAAsH;QACtH,OAAO,KAAK,CAAC;KACd;IAED,gCAAgC;IAChC,IAAI,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE;QAC7E,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import path from 'path';\nimport type { BundleRequest } from '../types/BundleRequest.js';\n\ninterface IsCachedResultValidOptions {\n bundleRequest: BundleRequest;\n hash?: string;\n}\n\n/**\n * Validates the result of a bundle request.\n * @param options - The options to use when validating the result.\n * @returns True if the result is valid, false otherwise.\n */\nexport function isCachedResultValid(options: IsCachedResultValidOptions): boolean {\n const { bundleRequest, hash } = options;\n const { enableCacheInternalPackages, isExternal, result } = bundleRequest;\n\n if (!result) {\n // The result is undefined, so the result is invalid\n return false;\n }\n\n if (result.errors?.length) {\n // There are errors, so the result is invalid\n return false;\n }\n\n if (!result.outputPath) {\n // outputPath used to be an optional field, however, we do not want it to be undefined anymore.\n return false;\n }\n\n if (enableCacheInternalPackages && !isExternal && result.hash !== hash) {\n // The package is internal, enableCacheInternalPackages is enabled but hashes do not match, this is an invalid result.\n return false;\n }\n\n // Output files must be relative\n if (result.outputFiles?.find(({ outputPath }) => path.isAbsolute(outputPath))) {\n return false;\n }\n\n return true;\n}\n"]}
@@ -17,6 +17,8 @@ export declare function parseRequestInfo(requestPath: string): {
17
17
  packageName: string;
18
18
  /** Optional package version (default: empty string) */
19
19
  version: string;
20
+ /** Optional hash (default: empty string) */
21
+ hash: string;
20
22
  /** Whether the bundled version is requested (default: false) */
21
23
  bundled: boolean;
22
24
  /** Optional file path (default: empty string) */
@@ -1 +1 @@
1
- {"version":3,"file":"parseRequestInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG;IACrD,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;CAClB,CAkBA"}
1
+ {"version":3,"file":"parseRequestInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG;IACrD,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;CAClB,CAmBA"}
@@ -19,13 +19,14 @@ export function parseRequestInfo(requestPath) {
19
19
  // - For character classes containing - , putting the - at the beginning
20
20
  // - Anchoring to the beginning of the string with ^
21
21
  const matches = requestPath.match(
22
- // 1 package name 2 version refresh 3 bundled 4 file path end or query
23
- /^\/?((?:@[-\w.]+\/)?[-\w.]+)(?:@([-\w.]+))?(?:\/v[\d.]+)?(?:\/(bundled|unbundled))?(\/[-@\w.+/]+)?(?:\?|$)/) || [];
22
+ // 1 package name 2 hash 3 version refresh 4 bundled 4 file path end or query
23
+ /^\/?((?:@[-\w.]+\/)?[-\w.]+)(?:@([-\w.]+))?(?:\/h-([0-9a-z.]+))?(?:\/v[\d.]+)?(?:\/(bundled|unbundled))?(\/[-@\w.+/]+)?(?:\?|$)/) || [];
24
24
  return {
25
25
  packageName: matches[1] || '',
26
26
  version: matches[2] || '',
27
- bundled: matches[3] === 'bundled',
28
- filePath: matches[4] || '',
27
+ hash: matches[3] || '',
28
+ bundled: matches[4] === 'bundled',
29
+ filePath: matches[5] || '',
29
30
  };
30
31
  }
31
32
  //# sourceMappingURL=parseRequestInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseRequestInfo.js","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAUlD,gFAAgF;IAChF,4DAA4D;IAC5D,kEAAkE;IAClE,wEAAwE;IACxE,oDAAoD;IACpD,MAAM,OAAO,GACX,WAAW,CAAC,KAAK;IACf,8GAA8G;IAC9G,4GAA4G,CAC7G,IAAI,EAAE,CAAC;IAEV,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QAC7B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS;QACjC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Parse a request for package file from the bundle server, such as\n * `/@scope/package@version/v3.2/bundled/path/to/file.js`\n *\n * Segments:\n * - Package name (and optionally `@version`)\n * - Optional refresh version `v#.#`\n * - Optional type `bundled` or `unbundled` (defaults to unbundled)\n * - Optional file path with leading slash (empty if no path)\n *\n * @param requestPath Pathname (server-relative URL) of the requested file.\n * @returns Info about the requested file. If `requestPath` doesn't follow the expected format,\n * the object will contain empty strings.\n */\nexport function parseRequestInfo(requestPath: string): {\n /** Package name (empty string if invalid request) */\n packageName: string;\n /** Optional package version (default: empty string) */\n version: string;\n /** Whether the bundled version is requested (default: false) */\n bundled: boolean;\n /** Optional file path (default: empty string) */\n filePath: string;\n} {\n // This is a hot path, and the following things appear to make the regex faster:\n // - /(?:Non-capturing groups)/ where capturing isn't needed\n // - /(Indexed capturing groups)/ instead of /(?<namedGroups>...)/\n // - For character classes containing - , putting the - at the beginning\n // - Anchoring to the beginning of the string with ^\n const matches =\n requestPath.match(\n // 1 package name 2 version refresh 3 bundled 4 file path end or query\n /^\\/?((?:@[-\\w.]+\\/)?[-\\w.]+)(?:@([-\\w.]+))?(?:\\/v[\\d.]+)?(?:\\/(bundled|unbundled))?(\\/[-@\\w.+/]+)?(?:\\?|$)/,\n ) || [];\n\n return {\n packageName: matches[1] || '',\n version: matches[2] || '',\n bundled: matches[3] === 'bundled',\n filePath: matches[4] || '',\n };\n}\n"]}
1
+ {"version":3,"file":"parseRequestInfo.js","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAYlD,gFAAgF;IAChF,4DAA4D;IAC5D,kEAAkE;IAClE,wEAAwE;IACxE,oDAAoD;IACpD,MAAM,OAAO,GACX,WAAW,CAAC,KAAK;IACf,+HAA+H;IAC/H,iIAAiI,CAClI,IAAI,EAAE,CAAC;IAEV,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QAC7B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QACzB,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QACtB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS;QACjC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Parse a request for package file from the bundle server, such as\n * `/@scope/package@version/v3.2/bundled/path/to/file.js`\n *\n * Segments:\n * - Package name (and optionally `@version`)\n * - Optional refresh version `v#.#`\n * - Optional type `bundled` or `unbundled` (defaults to unbundled)\n * - Optional file path with leading slash (empty if no path)\n *\n * @param requestPath Pathname (server-relative URL) of the requested file.\n * @returns Info about the requested file. If `requestPath` doesn't follow the expected format,\n * the object will contain empty strings.\n */\nexport function parseRequestInfo(requestPath: string): {\n /** Package name (empty string if invalid request) */\n packageName: string;\n /** Optional package version (default: empty string) */\n version: string;\n /** Optional hash (default: empty string) */\n hash: string;\n /** Whether the bundled version is requested (default: false) */\n bundled: boolean;\n /** Optional file path (default: empty string) */\n filePath: string;\n} {\n // This is a hot path, and the following things appear to make the regex faster:\n // - /(?:Non-capturing groups)/ where capturing isn't needed\n // - /(Indexed capturing groups)/ instead of /(?<namedGroups>...)/\n // - For character classes containing - , putting the - at the beginning\n // - Anchoring to the beginning of the string with ^\n const matches =\n requestPath.match(\n // 1 package name 2 hash 3 version refresh 4 bundled 4 file path end or query\n /^\\/?((?:@[-\\w.]+\\/)?[-\\w.]+)(?:@([-\\w.]+))?(?:\\/h-([0-9a-z.]+))?(?:\\/v[\\d.]+)?(?:\\/(bundled|unbundled))?(\\/[-@\\w.+/]+)?(?:\\?|$)/,\n ) || [];\n\n return {\n packageName: matches[1] || '',\n version: matches[2] || '',\n hash: matches[3] || '',\n bundled: matches[4] === 'bundled',\n filePath: matches[5] || '',\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/api-server",
3
- "version": "0.21.9",
3
+ "version": "0.22.0",
4
4
  "description": "An implementation of the API server that does interacts with a task scheduler.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -28,22 +28,21 @@
28
28
  "@lage-run/scheduler": "^1.1.9",
29
29
  "@lage-run/target-graph": "^0.8.7",
30
30
  "@lage-run/hasher": "^1.0.5",
31
- "@ms-cloudpack/bundler": "^0.15.0",
32
- "@ms-cloudpack/bundler-types": "^0.19.3",
33
- "@ms-cloudpack/config": "^0.14.2",
31
+ "@ms-cloudpack/bundler": "^0.15.2",
32
+ "@ms-cloudpack/bundler-types": "^0.19.4",
33
+ "@ms-cloudpack/config": "^0.14.4",
34
34
  "@ms-cloudpack/create-express-app": "^1.3.12",
35
35
  "@ms-cloudpack/data-bus": "^0.4.1",
36
36
  "@ms-cloudpack/file-watcher": "^0.1.1",
37
37
  "@ms-cloudpack/json-utilities": "^0.0.8",
38
- "@ms-cloudpack/package-utilities": "^5.1.12",
38
+ "@ms-cloudpack/package-utilities": "^5.1.14",
39
39
  "@ms-cloudpack/path-string-parsing": "^1.1.1",
40
40
  "@ms-cloudpack/path-utilities": "^2.3.5",
41
41
  "@ms-cloudpack/task-reporter": "^0.10.0",
42
42
  "@ms-cloudpack/telemetry": "^0.4.2",
43
- "@ms-cloudpack/remote-cache": "^0.1.13",
43
+ "@ms-cloudpack/remote-cache": "^0.1.14",
44
44
  "@trpc/client": "^10.40.0",
45
45
  "@trpc/server": "^10.40.0",
46
- "chokidar": "^3.5.3",
47
46
  "cors": "^2.8.5",
48
47
  "es-module-lexer": "^1.0.3",
49
48
  "fast-glob": "^3.2.12",
@@ -1,14 +0,0 @@
1
- import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
- export declare function getBundleDetails(options: {
3
- packagePath: string;
4
- }, context: {
5
- packages: PackageDefinitionsCache;
6
- }): Promise<{
7
- bundleId: string;
8
- isExternal: boolean;
9
- outputLocation: {
10
- path: string;
11
- folderName: string;
12
- };
13
- }>;
14
- //# sourceMappingURL=getBundleDetails.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBundleDetails.d.ts","sourceRoot":"","sources":["../../src/utilities/getBundleDetails.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAA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,QAAQ,EAAE,CAAC;IACvE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,UAAU,CAAC,CAAC;IAEzD,OAAO;QACL,QAAQ;QACR,UAAU;QACV,cAAc,EAAE;YACd,IAAI,EAAE,UAAU;YAChB,UAAU;SACX;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport hash from 'object-hash';\nimport filenamify from 'filenamify';\nimport path from 'path';\nimport { getCachePath } from './getCachePath.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport async function getBundleDetails(\n options: { packagePath: string },\n context: { packages: PackageDefinitionsCache },\n) {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath);\n\n if (!definition) {\n throw new Error(`Package definition (package.json) missing or invalid at \"${packagePath}\"`);\n }\n\n const { name: packageName, version } = definition;\n\n if (!packageName) {\n throw new Error(`Package definition (package.json) missing name at \"${packagePath}\"`);\n }\n\n const isExternal = isExternalPackage(packagePath);\n const bundleId = hash({\n name: packageName,\n ...definition,\n version: (isExternal ? version : packagePath) || packagePath,\n });\n\n // Derive where the output should be.\n const folderName = `${filenamify(packageName)}-${version}-${bundleId}`;\n const outputPath = path.join(getCachePath(), folderName);\n\n return {\n bundleId,\n isExternal,\n outputLocation: {\n path: outputPath,\n folderName,\n },\n };\n}\n"]}
@@ -1,9 +0,0 @@
1
- import type { Task } from '../types/Task.js';
2
- import type { ApiServer } from '../types/ApiServer.js';
3
- export declare function startWatcher(addTask: ApiServer['addTask']): {
4
- watch: <TReturn>(task: Task<TReturn>, options?: {
5
- onSuccess?: () => void;
6
- onDispose?: () => void;
7
- }) => void;
8
- };
9
- //# sourceMappingURL=startWatcher.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"startWatcher.d.ts","sourceRoot":"","sources":["../../src/utilities/startWatcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC;oDAIN;QAAE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE;EAiDrG"}
@@ -1,51 +0,0 @@
1
- import chokidar from 'chokidar';
2
- export function startWatcher(addTask) {
3
- const watched = new Set();
4
- return {
5
- watch: (task, options) => {
6
- const { id, name, dir } = task;
7
- // Have a single watcher per bundle request.
8
- if (watched.has(id) || !dir) {
9
- return;
10
- }
11
- watched.add(id);
12
- console.debug(`Initializing file watcher for ${name}`);
13
- // TODO: This is a bit of a hack. We should be able to use the watch API, but it doesn't seem to work.
14
- const watcher = chokidar.watch(dir).on('change', (event) => {
15
- console.debug(`Detected change "${event}", rebuilding "${name}"`);
16
- (async () => {
17
- // Start tracking work.
18
- let rebuilt = false;
19
- try {
20
- await addTask(task, { rerun: true });
21
- rebuilt = true;
22
- }
23
- catch (err) {
24
- console.error(`Error rebuilding "${name}":`, err?.stack || err);
25
- }
26
- const errors = task.getErrors?.();
27
- if (rebuilt && !errors?.length) {
28
- console.debug(`Notifying rebuild: ${name}`);
29
- options?.onSuccess?.();
30
- }
31
- else if (errors) {
32
- console.debug(`${name} ${errors.length} errors`);
33
- }
34
- })().catch(() => {
35
- // no-op
36
- });
37
- });
38
- task.dispose = async () => {
39
- try {
40
- await watcher.close();
41
- }
42
- catch {
43
- // ignore
44
- }
45
- task.onDispose?.();
46
- watched.delete(id);
47
- };
48
- },
49
- };
50
- }
51
- //# sourceMappingURL=startWatcher.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"startWatcher.js","sourceRoot":"","sources":["../../src/utilities/startWatcher.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC,MAAM,UAAU,YAAY,C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;wBACjB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,SAAS,CAAC,CAAC;qBAClD;gBACH,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;oBACd,QAAQ;gBACV,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;gBACxB,IAAI;oBACF,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;iBACvB;gBAAC,MAAM;oBACN,SAAS;iBACV;gBAED,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;gBAEnB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACrB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import chokidar from 'chokidar';\nimport type { Task } from '../types/Task.js';\nimport type { ApiServer } from '../types/ApiServer.js';\n\nexport function startWatcher(addTask: ApiServer['addTask']) {\n const watched = new Set<string>();\n\n return {\n watch: <TReturn>(task: Task<TReturn>, options?: { onSuccess?: () => void; onDispose?: () => void }) => {\n const { id, name, dir } = task;\n // Have a single watcher per bundle request.\n if (watched.has(id) || !dir) {\n return;\n }\n\n watched.add(id);\n\n console.debug(`Initializing file watcher for ${name}`);\n\n // TODO: This is a bit of a hack. We should be able to use the watch API, but it doesn't seem to work.\n const watcher = chokidar.watch(dir).on('change', (event: string) => {\n console.debug(`Detected change \"${event}\", rebuilding \"${name}\"`);\n\n (async () => {\n // Start tracking work.\n let rebuilt = false;\n try {\n await addTask(task, { rerun: true });\n rebuilt = true;\n } catch (err) {\n console.error(`Error rebuilding \"${name}\":`, (err as Error)?.stack || err);\n }\n const errors = task.getErrors?.();\n if (rebuilt && !errors?.length) {\n console.debug(`Notifying rebuild: ${name}`);\n options?.onSuccess?.();\n } else if (errors) {\n console.debug(`${name} ${errors.length} errors`);\n }\n })().catch(() => {\n // no-op\n });\n });\n\n task.dispose = async () => {\n try {\n await watcher.close();\n } catch {\n // ignore\n }\n\n task.onDispose?.();\n\n watched.delete(id);\n };\n },\n };\n}\n"]}