@ms-cloudpack/api-server 0.58.11 → 0.58.12

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.
package/lib/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export type { TaskEndDescription } from './types/TaskEndDescription.js';
8
8
  export type { TaskMessage } from './types/TaskMessage.js';
9
9
  export type { TaskOptions } from './types/TaskOptions.js';
10
10
  export type { TaskStartDescription } from './types/TaskStartDescription.js';
11
- export type { EnsurePackageBundledContext } from './apis/ensurePackageBundled.js';
11
+ export type { EnsurePackageBundledContext, EnsurePackageBundledResult } from './apis/ensurePackageBundled.js';
12
12
  export { TaskRunner } from './utilities/TaskRunner.js';
13
13
  export { errorEntrySource } from './data/busSources.js';
14
14
  export { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC9F,YAAY,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,YAAY,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EAAE,UA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AC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,YAAY;AACZ,OAAO,EAAE,uBAAuB,EAA8B,MAAM,qCAAqC,CAAC;AAE1G,iDAAiD;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export type { Context, PartialContext } from './types/Context.js';\nexport type { BundleInfo, BundleEntryInfo, BundleEntryConsumes } from './types/BundleInfo.js';\nexport type { Session } from '@ms-cloudpack/common-types';\nexport type { TaskStats } from './types/TaskStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskOptions } from './types/TaskOptions.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\nexport type { EnsurePackageBundledContext } from './apis/ensurePackageBundled.js';\n\nexport { TaskRunner } from './utilities/TaskRunner.js';\nexport { errorEntrySource } from './data/busSources.js';\nexport { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';\nexport { createCloudpackServer, type CloudpackServer } from './trpc/createCloudpackServer.js';\nexport { getActiveSessionsPath } from './utilities/getActiveSessionsPath.js';\nexport { getConsumedDependencies } from './utilities/getConsumedDependencies.js';\nexport { getConsumedPaths } from './utilities/getConsumedPaths.js';\n\n// Utilities\nexport { createPartialApiContext, type LazyApiContextOptions } from './common/createPartialApiContext.js';\n\n// API methods directly used outside this package\nexport { addPackageOverride } from './apis/addPackageOverride.js';\nexport { ensurePackageBundled } from './apis/ensurePackageBundled.js';\nexport { syncDownload } from './apis/syncDownload.js';\nexport { syncUpload } from './apis/syncUpload.js';\nexport type { SyncResult } from './types/SyncResult.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,YAAY;AACZ,OAAO,EAAE,uBAAuB,EAA8B,MAAM,qCAAqC,CAAC;AAE1G,iDAAiD;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export type { Context, PartialContext } from './types/Context.js';\nexport type { BundleInfo, BundleEntryInfo, BundleEntryConsumes } from './types/BundleInfo.js';\nexport type { Session } from '@ms-cloudpack/common-types';\nexport type { TaskStats } from './types/TaskStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskOptions } from './types/TaskOptions.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\nexport type { EnsurePackageBundledContext, EnsurePackageBundledResult } from './apis/ensurePackageBundled.js';\n\nexport { TaskRunner } from './utilities/TaskRunner.js';\nexport { errorEntrySource } from './data/busSources.js';\nexport { createCloudpackClient, type CloudpackClient } from './trpc/createCloudpackClient.js';\nexport { createCloudpackServer, type CloudpackServer } from './trpc/createCloudpackServer.js';\nexport { getActiveSessionsPath } from './utilities/getActiveSessionsPath.js';\nexport { getConsumedDependencies } from './utilities/getConsumedDependencies.js';\nexport { getConsumedPaths } from './utilities/getConsumedPaths.js';\n\n// Utilities\nexport { createPartialApiContext, type LazyApiContextOptions } from './common/createPartialApiContext.js';\n\n// API methods directly used outside this package\nexport { addPackageOverride } from './apis/addPackageOverride.js';\nexport { ensurePackageBundled } from './apis/ensurePackageBundled.js';\nexport { syncDownload } from './apis/syncDownload.js';\nexport { syncUpload } from './apis/syncUpload.js';\nexport type { SyncResult } from './types/SyncResult.js';\n"]}
@@ -14,7 +14,7 @@ export function createTaskSchedulerReporter(reporter) {
14
14
  const target = entry.data.target;
15
15
  const task = reporterTasks.get(target.id);
16
16
  if (task) {
17
- task.message += entry.msg;
17
+ task.addMessage(entry.msg);
18
18
  }
19
19
  return;
20
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createTaskSchedulerReporter.js","sourceRoot":"","sources":["../../src/task-scheduler/createTaskSchedulerReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAiB,MAAM,kBAAkB,CAAC;AAI3D,MAAM,sBAAsB,GAAG;IAC7B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK;IAC/B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI;IAC7B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI;IAC7B,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,KAAK;IACjC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK;CAChC,CAAC;AAEF,MAAM,UA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AAS;wBACZ,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;wBAClC,MAAM;oBAER,KAAK,QAAQ;wBACX,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;wBAClC,MAAM;oBAER,KAAK,SAAS;wBACZ,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;wBACnC,MAAM;gBACV,CAAC;gBACD,OAAO;YACT,CAAC;YAED,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;gBACd,sBAAsB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC/C,OAAO;YACT,CAAC;QACH,CAAC;QACD,SAAS;YACP,OAAO;QACT,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { LogLevel, type Reporter } from '@lage-run/logger';\nimport type { Target } from '@lage-run/target-graph';\nimport type { TaskReporter, TaskReporterTask } from '@ms-cloudpack/task-reporter';\n\nconst logLevelToConsoleFnMap = {\n [LogLevel.error]: console.error,\n [LogLevel.warn]: console.warn,\n [LogLevel.info]: console.info,\n [LogLevel.verbose]: console.debug,\n [LogLevel.silly]: console.debug,\n};\n\nexport function createTaskSchedulerReporter(reporter: TaskReporter): Reporter {\n const reporterTasks = new Map<string, TaskReporterTask>();\n\n return {\n log(entry): void {\n if (entry.msg && entry.level <= LogLevel.warn && entry.data?.target) {\n const target = entry.data.target as Target;\n const task = reporterTasks.get(target.id);\n if (task) {\n task.message += entry.msg;\n }\n return;\n }\n\n if (entry.data && entry.data.status) {\n const { status } = entry.data;\n const target = entry.data.target as Target;\n\n // Ensure task is in the reporterTasks map\n let task = reporterTasks.get(target.id);\n if (!task) {\n task = reporter.addTask(target.label, true);\n reporterTasks.set(target.id, task);\n }\n\n switch (status) {\n case 'running':\n task.start();\n break;\n\n case 'success':\n task.complete({ status: 'complete' });\n break;\n\n case 'skipped':\n task.complete({ status: 'skip' });\n break;\n\n case 'failed':\n task.complete({ status: 'fail' });\n break;\n\n case 'aborted':\n task.complete({ status: 'abort' });\n break;\n }\n return;\n }\n\n if (entry.msg) {\n logLevelToConsoleFnMap[entry.level](entry.msg);\n return;\n }\n },\n summarize(): void {\n // noop\n },\n };\n}\n"]}
1
+ {"version":3,"file":"createTaskSchedulerReporter.js","sourceRoot":"","sources":["../../src/task-scheduler/createTaskSchedulerReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAiB,MAAM,kBAAkB,CAAC;AAI3D,MAAM,sBAAsB,GAAG;IAC7B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK;IAC/B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI;IAC7B,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI;IAC7B,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,KAAK;IACjC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK;CAChC,CAAC;AAEF,MAAM,UAAU,2BAA2B,CAAC,QAAsB;IAChE,MAAM,aAAa,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE1D,OAAO;QACL,GAAG,CAAC,KAAK;YACP,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;gBACpE,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAgB,CAAC;gBAC3C,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC1C,IAAI,IAAI,EAAE,CAAC;oBACT,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC7B,CAAC;gBACD,OAAO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AAC;QACD,SAAS;YACP,OAAO;QACT,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { LogLevel, type Reporter } from '@lage-run/logger';\nimport type { Target } from '@lage-run/target-graph';\nimport type { TaskReporter, TaskReporterTask } from '@ms-cloudpack/task-reporter';\n\nconst logLevelToConsoleFnMap = {\n [LogLevel.error]: console.error,\n [LogLevel.warn]: console.warn,\n [LogLevel.info]: console.info,\n [LogLevel.verbose]: console.debug,\n [LogLevel.silly]: console.debug,\n};\n\nexport function createTaskSchedulerReporter(reporter: TaskReporter): Reporter {\n const reporterTasks = new Map<string, TaskReporterTask>();\n\n return {\n log(entry): void {\n if (entry.msg && entry.level <= LogLevel.warn && entry.data?.target) {\n const target = entry.data.target as Target;\n const task = reporterTasks.get(target.id);\n if (task) {\n task.addMessage(entry.msg);\n }\n return;\n }\n\n if (entry.data && entry.data.status) {\n const { status } = entry.data;\n const target = entry.data.target as Target;\n\n // Ensure task is in the reporterTasks map\n let task = reporterTasks.get(target.id);\n if (!task) {\n task = reporter.addTask(target.label, true);\n reporterTasks.set(target.id, task);\n }\n\n switch (status) {\n case 'running':\n task.start();\n break;\n\n case 'success':\n task.complete({ status: 'complete' });\n break;\n\n case 'skipped':\n task.complete({ status: 'skip' });\n break;\n\n case 'failed':\n task.complete({ status: 'fail' });\n break;\n\n case 'aborted':\n task.complete({ status: 'abort' });\n break;\n }\n return;\n }\n\n if (entry.msg) {\n logLevelToConsoleFnMap[entry.level](entry.msg);\n return;\n }\n },\n summarize(): void {\n // noop\n },\n };\n}\n"]}
@@ -26,6 +26,7 @@ export interface BundleRequest {
26
26
  inputPath?: string;
27
27
  hash?: string;
28
28
  info?: BundleInfo;
29
+ bundleSource?: 'remote-cache' | 'local-cache' | 'bundler';
29
30
  };
30
31
  /** Whether the result was retrieved from the cache (set while bundling) */
31
32
  resultFromCache?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0FAA0F;IAC1F,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,UAAU,EAAE,OAAO,CAAC;IACpB,oDAAoD;IACpD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB;IAClB,IAAI,EAAE,UAAU,CAAC;IACjB,yBAAyB;IACzB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;QACzC,4FAA4F;QAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB,CAAC;IACF,2EAA2E;IAE3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,+DAA+D;IAC/D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iCAAiC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
1
+ {"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0FAA0F;IAC1F,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,UAAU,EAAE,OAAO,CAAC;IACpB,oDAAoD;IACpD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB;IAClB,IAAI,EAAE,UAAU,CAAC;IACjB,yBAAyB;IACzB,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,GAAG;QACzC,4FAA4F;QAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,UAAU,CAAC;QAClB,YAAY,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,SAAS,CAAC;KAC3D,CAAC;IACF,2EAA2E;IAE3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,+DAA+D;IAC/D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iCAAiC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleMode, BundleResult } from '@ms-cloudpack/common-types';\nimport type { BundleInfo } from './BundleInfo.js';\n\n/**\n * Tracks a given bundle request and its result.\n */\nexport interface BundleRequest {\n /** ID for the bundle. This will usually be the package path, or occasionally the hash. */\n id: string;\n /** Package name being bundled */\n packageName: string;\n /** Package version being bundled */\n version: string;\n /** Absolute path to the package */\n packagePath: string;\n /** Absolute path for the bundle output */\n outputPath?: string;\n /** Whether this is an external package (in node_modules) */\n isExternal: boolean;\n /** Whether we should force the incremental flag. */\n isIncremental?: boolean;\n /** Bundle mode */\n mode: BundleMode;\n /** Result of bundling */\n result?: Omit<BundleResult, 'inputPath'> & {\n /** Input path. Will be unset if the package couldn't be found or had an unhandled error. */\n inputPath?: string;\n hash?: string;\n info?: BundleInfo;\n };\n /** Whether the result was retrieved from the cache (set while bundling) */\n // TODO: this seems like it should be a property of the result?\n resultFromCache?: boolean;\n /** Whether to disable source maps */\n disableSourceMaps?: boolean;\n /** Whether to scan the bundled code for imports and exports */\n shouldGetBundleInfo?: boolean;\n /** Whether to disable caching */\n disableCache?: boolean;\n}\n"]}
1
+ {"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleMode, BundleResult } from '@ms-cloudpack/common-types';\nimport type { BundleInfo } from './BundleInfo.js';\n\n/**\n * Tracks a given bundle request and its result.\n */\nexport interface BundleRequest {\n /** ID for the bundle. This will usually be the package path, or occasionally the hash. */\n id: string;\n /** Package name being bundled */\n packageName: string;\n /** Package version being bundled */\n version: string;\n /** Absolute path to the package */\n packagePath: string;\n /** Absolute path for the bundle output */\n outputPath?: string;\n /** Whether this is an external package (in node_modules) */\n isExternal: boolean;\n /** Whether we should force the incremental flag. */\n isIncremental?: boolean;\n /** Bundle mode */\n mode: BundleMode;\n /** Result of bundling */\n result?: Omit<BundleResult, 'inputPath'> & {\n /** Input path. Will be unset if the package couldn't be found or had an unhandled error. */\n inputPath?: string;\n hash?: string;\n info?: BundleInfo;\n bundleSource?: 'remote-cache' | 'local-cache' | 'bundler';\n };\n /** Whether the result was retrieved from the cache (set while bundling) */\n // TODO: this seems like it should be a property of the result?\n resultFromCache?: boolean;\n /** Whether to disable source maps */\n disableSourceMaps?: boolean;\n /** Whether to scan the bundled code for imports and exports */\n shouldGetBundleInfo?: boolean;\n /** Whether to disable caching */\n disableCache?: boolean;\n}\n"]}
@@ -2,5 +2,5 @@ import type { BundleRequest } from './BundleRequest.js';
2
2
  /**
3
3
  * The result object that is written to the cache. This is a subset of the BundleRequest.result object.
4
4
  */
5
- export type ResultJson = Pick<NonNullable<BundleRequest['result']>, 'bundler' | 'entries' | 'hash' | 'outputFiles' | 'warnings' | 'errors'>;
5
+ export type ResultJson = Pick<NonNullable<BundleRequest['result']>, 'bundler' | 'bundlerVersion' | 'entries' | 'hash' | 'outputFiles' | 'warnings' | 'errors'>;
6
6
  //# sourceMappingURL=ResultJson.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ResultJson.d.ts","sourceRoot":"","sources":["../../src/types/ResultJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,EACpC,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,UAAU,GAAG,QAAQ,CACvE,CAAC"}
1
+ {"version":3,"file":"ResultJson.d.ts","sourceRoot":"","sources":["../../src/types/ResultJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,EACpC,SAAS,GAAG,gBAAgB,GAAG,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,UAAU,GAAG,QAAQ,CAC1F,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ResultJson.js","sourceRoot":"","sources":["../../src/types/ResultJson.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleRequest } from './BundleRequest.js';\n\n/**\n * The result object that is written to the cache. This is a subset of the BundleRequest.result object.\n */\nexport type ResultJson = Pick<\n NonNullable<BundleRequest['result']>,\n 'bundler' | 'entries' | 'hash' | 'outputFiles' | 'warnings' | 'errors'\n>;\n"]}
1
+ {"version":3,"file":"ResultJson.js","sourceRoot":"","sources":["../../src/types/ResultJson.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleRequest } from './BundleRequest.js';\n\n/**\n * The result object that is written to the cache. This is a subset of the BundleRequest.result object.\n */\nexport type ResultJson = Pick<\n NonNullable<BundleRequest['result']>,\n 'bundler' | 'bundlerVersion' | 'entries' | 'hash' | 'outputFiles' | 'warnings' | 'errors'\n>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAI1D,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,CAAC;AAC7F,MAAM,MAAM,yBAAyB,GAAG,cAAc,CACpD,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,iBAAiB,GAAG,mBAAmB,EACnF,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CACnD,CAAC;AAEF;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CA+Kf"}
1
+ {"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,CAAC;AAC7F,MAAM,MAAM,yBAAyB,GAAG,cAAc,CACpD,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,iBAAiB,GAAG,mBAAmB,EACnF,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CACnD,CAAC;AAEF;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAsCf"}
@@ -11,154 +11,148 @@ import { readResultFromCache } from './readResultFromCache.js';
11
11
  import { saveResultToCache } from './saveResultToCache.js';
12
12
  import { formatBundleTaskResult } from './formatBundleTaskResult.js';
13
13
  import { writeStubForDensityEntries } from './writeStubForDensityEntries.js';
14
- import { getRemoteCachePackageId } from './getRemoteCachePackageId.js';
15
14
  /**
16
15
  * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.
17
16
  */
18
17
  export async function bundleTask(options, context) {
19
- const { bundleRequest, force, hash, sourceHash } = options;
18
+ const { bundleRequest } = options;
20
19
  const { packageName, version } = bundleRequest;
21
- const { reporter, telemetryClient, packageHashes, packages, session, remoteCacheClient } = context;
22
- const { config, sequence } = session;
23
- const { mode } = config;
20
+ const { reporter, telemetryClient, session } = context;
21
+ const { sequence } = session;
24
22
  const { retryCount } = options;
25
- const taskName = `Bundle ${formatPackageName({
26
- name: packageName,
27
- version,
28
- })}${retryCount ? ` (retry ${retryCount})` : ''}`;
29
- await reporter.runTask(taskName, async () => {
23
+ const task = reporter.addTask(`Bundle ${formatPackageName({ name: packageName, version })}${retryCount ? ` (retry ${retryCount})` : ''}`);
24
+ try {
30
25
  await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {
31
- // If force is set, dispose the existing result.
32
- if (force && bundleRequest?.result?.dispose) {
33
- bundleRequest.result.dispose();
34
- bundleRequest.result = undefined;
35
- }
36
- let bundleSource = 'local-cache';
37
- const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;
38
- const outputPath = bundleRequest.outputPath ??
39
- (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;
40
- // Rehydrate the result if not incremental.
41
- if (bundleRequest.result === undefined && !force) {
42
- bundleRequest.result = await readResultFromCache(outputPath, {
43
- inputPath: packagePath,
44
- });
45
- bundleSource = 'local-cache';
46
- if (!bundleRequest.result && remoteCacheClient) {
47
- const downloadResult = await remoteCacheClient.downloadFolder({
48
- id: await getRemoteCachePackageId({ packagePath }, context),
49
- path: outputPath,
50
- friendlyName: `${packageName}@${version}`,
51
- });
52
- if (downloadResult === 'success') {
53
- // If the download was successful, read the result from cache.
54
- bundleRequest.result = await readResultFromCache(outputPath, {
55
- inputPath: packagePath,
56
- });
57
- bundleSource = 'remote-cache';
58
- }
59
- else if (downloadResult === 'already-exist') {
60
- throw new Error('Remote cache already exist, but cloudpack result is not found in local cache. This must be a bug.');
61
- }
62
- }
63
- }
64
- const cacheValidationHash = !isExternal
65
- ? sourceHash ||
66
- (await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true }))
67
- : undefined;
68
- // if the cached result is valid, use it.
69
- if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {
70
- console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);
71
- bundleRequest.resultFromCache = true;
72
- }
73
- else {
74
- bundleRequest.resultFromCache = false;
75
- // Only use cached result if it's successful.
76
- await prepareOutputPath(outputPath);
77
- if (bundleRequest.result?.rebuild) {
78
- bundleRequest.result = {
79
- ...(await bundleRequest.result.rebuild()),
80
- outputPath: bundleRequest.result.outputPath,
81
- hash: cacheValidationHash,
82
- };
83
- }
84
- else {
85
- const { bundler, bundlerOptions, inlinedDependencies, dynamicImports, bundlerCapabilities, ignoredBundlerWarnings, unsafeCjsExportNames, } = (await packages.get(packagePath)).cloudpack || {};
86
- const bundleOptions = {
87
- bundler,
88
- minify: mode === 'production',
89
- bundlerOptions,
90
- inputPath: packagePath,
91
- outputPath,
92
- incremental: isIncremental !== undefined ? isIncremental : false,
93
- sourcemap: !disableSourceMaps,
94
- entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),
95
- inlined: inlinedDependencies,
96
- external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),
97
- dynamicImports,
98
- ignoredBundlerWarnings,
99
- bundlerCapabilities,
100
- unsafeCjsExportNames,
101
- };
102
- const bundleInternalResult = await bundle(bundleOptions, { config });
103
- if (bundleInternalResult.bundler) {
104
- span.setAttribute('bundler', bundleInternalResult.bundler);
105
- }
106
- bundleRequest.result = {
107
- ...bundleInternalResult,
108
- outputPath: bundleOptions.outputPath ?? outputPath,
109
- hash: cacheValidationHash,
110
- };
111
- if (bundlerCapabilities?.density) {
112
- // Get export maps that need to be written as stubs for density.
113
- // If there are density exports, write stubs for them.
114
- const densityErrors = await writeStubForDensityEntries({
115
- options: {
116
- packageName,
117
- packagePath,
118
- result: bundleInternalResult,
119
- },
120
- context: { packages, config },
121
- });
122
- // Add any errors to the result.
123
- if (densityErrors.length > 0) {
124
- bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityErrors];
125
- }
126
- }
127
- }
128
- // Write the result to disk.
129
- await saveResultToCache(bundleRequest.result);
130
- }
131
- // If we should find required imports and exports per bundle
132
- if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {
133
- const bundleInfoPath = path.join(outputPath, 'bundle-info.json');
134
- // Exports map is needed to find the bundle info per entry we intend to bundle.
135
- // Exports map is used instead of bundleRequest.entries since it is easier to use
136
- // because it contains the paths other packages use to import the entry and
137
- // the relative location of the bundled files.
138
- const exportsMap = await getExportsMap({ packagePath }, { packages, config });
139
- const bundleInfo = await getBundleInfo({
140
- outputPath,
141
- outputFiles: bundleRequest.result.outputFiles,
142
- exportsMap,
143
- isExternal,
144
- packagePath,
145
- });
146
- bundleRequest.result.info = bundleInfo;
147
- // Write to cache for future use. (Ignore the promise result.)
148
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
149
- writeJson(bundleInfoPath, bundleInfo);
150
- }
26
+ await bundleTaskInternal(options, context);
151
27
  span.setAttributes({
152
28
  sequence,
153
29
  isCacheHit: !!bundleRequest.resultFromCache,
154
30
  isExternal: bundleRequest.isExternal,
155
31
  packageName: bundleRequest.packageName,
156
32
  packageVersion: bundleRequest.version,
157
- bundleSource,
33
+ bundleSource: bundleRequest.result?.bundleSource,
34
+ bundler: bundleRequest.result?.bundler,
35
+ bundlerVersion: bundleRequest.result?.bundlerVersion,
158
36
  });
159
- const taskResult = formatBundleTaskResult(bundleRequest);
160
- return taskResult;
161
37
  });
162
- });
38
+ }
39
+ catch (err) {
40
+ // If an unexpected error is thrown, add it to the result.
41
+ // This ensures consistent handling of either actual bundler errors or exceptions.
42
+ bundleRequest.result ??= {};
43
+ bundleRequest.result.errors ??= [];
44
+ bundleRequest.result.errors.push({
45
+ text: `Unexpected exception while bundling: ${err.stack || String(err)}`,
46
+ source: 'bundleTask',
47
+ });
48
+ }
49
+ task.complete(formatBundleTaskResult(bundleRequest));
50
+ }
51
+ /**
52
+ * Actually read the result from the cache or call `bundle()`.
53
+ * NOTE: The result is returned by mutating `options.bundleRequest.result`.
54
+ */
55
+ async function bundleTaskInternal(options, context) {
56
+ const { bundleRequest, force, hash, sourceHash } = options;
57
+ const { packageName, version } = bundleRequest;
58
+ const { packageHashes, packages, session } = context;
59
+ const { config } = session;
60
+ const { mode } = config;
61
+ // If force is set, dispose the existing result.
62
+ if (force && bundleRequest?.result?.dispose) {
63
+ bundleRequest.result.dispose();
64
+ bundleRequest.result = undefined;
65
+ }
66
+ const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;
67
+ const outputPath = bundleRequest.outputPath ??
68
+ (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;
69
+ // Rehydrate the result if not incremental.
70
+ if (bundleRequest.result === undefined && !force) {
71
+ bundleRequest.result = await readResultFromCache({ packageName, version, inputPath: packagePath, outputPath }, context);
72
+ }
73
+ const cacheValidationHash = !isExternal
74
+ ? sourceHash || (await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true }))
75
+ : undefined;
76
+ // if the cached result is valid, use it.
77
+ if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {
78
+ console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);
79
+ bundleRequest.resultFromCache = true;
80
+ }
81
+ else {
82
+ bundleRequest.resultFromCache = false;
83
+ // Only use cached result if it's successful.
84
+ await prepareOutputPath(outputPath);
85
+ if (bundleRequest.result?.rebuild) {
86
+ bundleRequest.result = {
87
+ ...(await bundleRequest.result.rebuild()),
88
+ outputPath: bundleRequest.result.outputPath,
89
+ hash: cacheValidationHash,
90
+ };
91
+ }
92
+ else {
93
+ const { bundler, bundlerOptions, inlinedDependencies, dynamicImports, bundlerCapabilities, ignoredBundlerWarnings, unsafeCjsExportNames, } = (await packages.get(packagePath)).cloudpack || {};
94
+ const bundleOptions = {
95
+ bundler,
96
+ minify: mode === 'production',
97
+ bundlerOptions,
98
+ inputPath: packagePath,
99
+ outputPath,
100
+ incremental: isIncremental !== undefined ? isIncremental : false,
101
+ sourcemap: !disableSourceMaps,
102
+ entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),
103
+ inlined: inlinedDependencies,
104
+ external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),
105
+ dynamicImports,
106
+ ignoredBundlerWarnings,
107
+ bundlerCapabilities,
108
+ unsafeCjsExportNames,
109
+ };
110
+ const bundleInternalResult = await bundle(bundleOptions, { config });
111
+ bundleRequest.result = {
112
+ ...bundleInternalResult,
113
+ outputPath: bundleOptions.outputPath ?? outputPath,
114
+ hash: cacheValidationHash,
115
+ bundleSource: 'bundler',
116
+ };
117
+ if (bundlerCapabilities?.density) {
118
+ // Get export maps that need to be written as stubs for density.
119
+ // If there are density exports, write stubs for them.
120
+ const densityErrors = await writeStubForDensityEntries({
121
+ options: {
122
+ packageName,
123
+ packagePath,
124
+ result: bundleInternalResult,
125
+ },
126
+ context: { packages, config },
127
+ });
128
+ // Add any errors to the result.
129
+ if (densityErrors.length > 0) {
130
+ bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityErrors];
131
+ }
132
+ }
133
+ }
134
+ // Write the result to disk.
135
+ await saveResultToCache(bundleRequest.result);
136
+ }
137
+ // If we should find required imports and exports per bundle
138
+ if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {
139
+ const bundleInfoPath = path.join(outputPath, 'bundle-info.json');
140
+ // Exports map is needed to find the bundle info per entry we intend to bundle.
141
+ // Exports map is used instead of bundleRequest.entries since it is easier to use
142
+ // because it contains the paths other packages use to import the entry and
143
+ // the relative location of the bundled files.
144
+ const exportsMap = await getExportsMap({ packagePath }, { packages, config });
145
+ const bundleInfo = await getBundleInfo({
146
+ outputPath,
147
+ outputFiles: bundleRequest.result.outputFiles,
148
+ exportsMap,
149
+ isExternal,
150
+ packagePath,
151
+ });
152
+ bundleRequest.result.info = bundleInfo;
153
+ // Write to cache for future use. (Ignore the promise result.)
154
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
155
+ writeJson(bundleInfoPath, bundleInfo);
156
+ }
163
157
  }
164
158
  //# sourceMappingURL=bundleTask.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,iB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,EAAE,CAAC,CAAC,aAAa,CAAC,eAAe;gBAC3C,UAAU,EAAE,aAAa,CAAC,UAAU;gBACpC,WAAW,EAAE,aAAa,CAAC,WAAW;gBACtC,cAAc,EAAE,aAAa,CAAC,OAAO;gBACrC,YAAY;aACb,CAAC,CAAC;YAEH,MAAM,UAAU,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;YAEzD,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { bundle, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.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 { getRemoteCachePackageId } from './getRemoteCachePackageId.js';\n\nexport type BundleTaskInternalOptions = BundleTaskOptions & { bundleRequest: BundleRequest };\nexport type BundleTaskInternalContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient' | 'remoteCacheClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(\n options: BundleTaskInternalOptions,\n context: BundleTaskInternalContext,\n): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, packageHashes, packages, session, remoteCacheClient } = context;\n const { config, sequence } = session;\n const { mode } = config;\n const { retryCount } = options;\n\n const taskName = `Bundle ${formatPackageName({\n name: packageName,\n version,\n })}${retryCount ? ` (retry ${retryCount})` : ''}`;\n\n await reporter.runTask(taskName, async () => {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\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 let bundleSource: 'remote-cache' | 'local-cache' | 'bundler' = 'local-cache';\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n bundleSource = 'local-cache';\n\n if (!bundleRequest.result && remoteCacheClient) {\n const downloadResult = await remoteCacheClient.downloadFolder({\n id: await getRemoteCachePackageId({ packagePath }, context),\n path: outputPath,\n friendlyName: `${packageName}@${version}`,\n });\n\n if (downloadResult === 'success') {\n // If the download was successful, read the result from cache.\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n bundleSource = 'remote-cache';\n } else if (downloadResult === 'already-exist') {\n throw new Error(\n 'Remote cache already exist, but cloudpack result is not found in local cache. This must be a bug.',\n );\n }\n }\n }\n const cacheValidationHash = !isExternal\n ? sourceHash ||\n (await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true }))\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n unsafeCjsExportNames,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n bundler,\n minify: mode === 'production',\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n unsafeCjsExportNames,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n if (bundleInternalResult.bundler) {\n span.setAttribute('bundler', bundleInternalResult.bundler);\n }\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n };\n\n if (bundlerCapabilities?.density) {\n // Get export maps that need to be written as stubs for density.\n // If there are density exports, write stubs for them.\n const densityErrors = await writeStubForDensityEntries({\n options: {\n packageName,\n packagePath,\n result: bundleInternalResult,\n },\n context: { packages, config },\n });\n\n // Add any errors to the result.\n if (densityErrors.length > 0) {\n bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityErrors];\n }\n }\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const bundleInfoPath = path.join(outputPath, 'bundle-info.json');\n\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 // Write to cache for future use. (Ignore the promise result.)\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n writeJson(bundleInfoPath, bundleInfo);\n }\n\n span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n packageName: bundleRequest.packageName,\n packageVersion: bundleRequest.version,\n bundleSource,\n });\n\n const taskResult = formatBundleTaskResult(bundleRequest);\n\n return taskResult;\n });\n });\n}\n"]}
1
+ {"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,E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AI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC7B,aAAa,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC;gBAC3F,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,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QAEjE,+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,8DAA8D;QAC9D,mEAAmE;QACnE,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IACxC,CAAC;AACH,CAAC","sourcesContent":["import { bundle, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\nimport { formatBundleTaskResult } from './formatBundleTaskResult.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { writeStubForDensityEntries } from './writeStubForDensityEntries.js';\n\nexport type BundleTaskInternalOptions = BundleTaskOptions & { bundleRequest: BundleRequest };\nexport type BundleTaskInternalContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient' | 'remoteCacheClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(\n options: BundleTaskInternalOptions,\n context: BundleTaskInternalContext,\n): Promise<void> {\n const { bundleRequest } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, session } = context;\n const { sequence } = session;\n const { retryCount } = options;\n\n const task = reporter.addTask(\n `Bundle ${formatPackageName({ name: packageName, version })}${retryCount ? ` (retry ${retryCount})` : ''}`,\n );\n\n try {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\n await bundleTaskInternal(options, context);\n\n span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n packageName: bundleRequest.packageName,\n packageVersion: bundleRequest.version,\n bundleSource: bundleRequest.result?.bundleSource,\n bundler: bundleRequest.result?.bundler,\n bundlerVersion: bundleRequest.result?.bundlerVersion,\n });\n });\n } catch (err) {\n // If an unexpected error is thrown, add it to the result.\n // This ensures consistent handling of either actual bundler errors or exceptions.\n bundleRequest.result ??= {};\n bundleRequest.result.errors ??= [];\n bundleRequest.result.errors.push({\n text: `Unexpected exception while bundling: ${(err as Error).stack || String(err)}`,\n source: 'bundleTask',\n });\n }\n\n task.complete(formatBundleTaskResult(bundleRequest));\n}\n\n/**\n * Actually read the result from the cache or call `bundle()`.\n * NOTE: The result is returned by mutating `options.bundleRequest.result`.\n */\nasync function bundleTaskInternal(\n options: BundleTaskInternalOptions,\n context: BundleTaskInternalContext,\n): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version } = bundleRequest;\n const { packageHashes, packages, session } = context;\n const { config } = session;\n const { mode } = config;\n\n // If force is set, dispose the existing result.\n if (force && bundleRequest?.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(\n { packageName, version, inputPath: packagePath, outputPath },\n context,\n );\n }\n\n const cacheValidationHash = !isExternal\n ? sourceHash || (await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true }))\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash: cacheValidationHash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n unsafeCjsExportNames,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n bundler,\n minify: mode === 'production',\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n unsafeCjsExportNames,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n bundleSource: 'bundler',\n };\n\n if (bundlerCapabilities?.density) {\n // Get export maps that need to be written as stubs for density.\n // If there are density exports, write stubs for them.\n const densityErrors = await writeStubForDensityEntries({\n options: {\n packageName,\n packagePath,\n result: bundleInternalResult,\n },\n context: { packages, config },\n });\n\n // Add any errors to the result.\n if (densityErrors.length > 0) {\n bundleRequest.result.errors = [...(bundleRequest.result.errors ?? []), ...densityErrors];\n }\n }\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const bundleInfoPath = path.join(outputPath, 'bundle-info.json');\n\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 // Write to cache for future use. (Ignore the promise result.)\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n writeJson(bundleInfoPath, bundleInfo);\n }\n}\n"]}
@@ -1,4 +1,13 @@
1
1
  import { type TaskReporterTaskResult } from '@ms-cloudpack/task-reporter';
2
2
  import type { BundleRequest } from '../types/BundleRequest.js';
3
+ /**
4
+ * Format a bundle result into a TaskReporter task result.
5
+ *
6
+ * NOTE: The info as formatted here will only be shown when a task is completed, not in the summary.
7
+ * Reporter configuration may change over time, but as of writing:
8
+ * - Failed tasks (message and errors) will be shown unless `--quiet`.
9
+ * - Successful tasks will only be shown with `--verbose` or `--debug`, or if the command sets
10
+ * `showCompleted` (`cloudpack bundle` does as of writing).
11
+ */
3
12
  export declare function formatBundleTaskResult(bundleRequest: BundleRequest): TaskReporterTaskResult;
4
13
  //# sourceMappingURL=formatBundleTaskResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatBundleTaskResult.d.ts","sourceRoot":"","sources":["../../src/utilities/formatBundleTaskResult.ts"],"names":[],"mappings":"AACA,OAAO,EAAqC,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC7G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAK/D,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,aAAa,GAAG,sBAAsB,CAqD3F"}
1
+ {"version":3,"file":"formatBundleTaskResult.d.ts","sourceRoot":"","sources":["../../src/utilities/formatBundleTaskResult.ts"],"names":[],"mappings":"AACA,OAAO,EAAqC,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC7G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAK/D;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,aAAa,GAAG,sBAAsB,CAsD3F"}
@@ -3,6 +3,15 @@ import { red, bulletedList, plural, indent } from '@ms-cloudpack/task-reporter';
3
3
  import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
4
4
  import { getFileSizeSync } from './getFileSizeSync.js';
5
5
  import path from 'path';
6
+ /**
7
+ * Format a bundle result into a TaskReporter task result.
8
+ *
9
+ * NOTE: The info as formatted here will only be shown when a task is completed, not in the summary.
10
+ * Reporter configuration may change over time, but as of writing:
11
+ * - Failed tasks (message and errors) will be shown unless `--quiet`.
12
+ * - Successful tasks will only be shown with `--verbose` or `--debug`, or if the command sets
13
+ * `showCompleted` (`cloudpack bundle` does as of writing).
14
+ */
6
15
  export function formatBundleTaskResult(bundleRequest) {
7
16
  const { result, packageName, version, packagePath } = bundleRequest;
8
17
  if (!result) {
@@ -28,6 +37,7 @@ export function formatBundleTaskResult(bundleRequest) {
28
37
  const hasErrors = result.errors.length > 0;
29
38
  const status = hasErrors ? 'fail' : 'complete';
30
39
  const message = hasErrors ? plural(result.errors.length, 'error$s found') : undefined;
40
+ // Only shown with --verbose or --debug
31
41
  const details = bulletedList([
32
42
  `Package: ${bundleRequest.packageName}@${bundleRequest.version}`,
33
43
  `Bundler: ${result.bundler || 'unknown'}`,
@@ -1 +1 @@
1
- {"version":3,"file":"formatBundleTaskResult.js","sourceRoot":"","sources":["../../src/utilities/formatBundleTaskResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAA+B,MAAM,6BAA6B,CAAC;AAE7G,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,sBAAsB,CAAC,aAA4B;IACjE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,aAAa,CAAC;IAEpE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,yCAAyC,WAAW,IAAI,OAAO,GAAG;SAC5E,CAAC;IACJ,CAAC;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EAAE;QAChE,YAAY,MAAM,CAAC,OAAO,IAAI,SAAS,EAAE;QACzC,eAAe,aAAa,CAAC,eAAe,EAAE;QAC9C,eAAe,aAAa,CAAC,WAAW,EAAE;QAC1C,UAAU;QACV,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QACnC,gBAAgB,MAAM,CAAC,UAAU,EAAE;QACnC,eAAe;QACf,MAAM,CAAC,WAAW,CAAC,GAAG,CACpB,CAAC,IAAI,EAAE,EAAE,CACP,GAAG,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,eAAe;QAC3D,8GAA8G;QAC9G,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAClD,GAAG,CACP;KACF,CAAC,CAAC;IAEH,OAAO;QACL,MAAM;QACN,OAAO;QACP,MAAM;QACN,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { formatLocation } from '@ms-cloudpack/path-utilities';\nimport { red, bulletedList, plural, indent, type TaskReporterTaskResult } from '@ms-cloudpack/task-reporter';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { getFileSizeSync } from './getFileSizeSync.js';\nimport path from 'path';\n\nexport function formatBundleTaskResult(bundleRequest: BundleRequest): TaskReporterTaskResult {\n const { result, packageName, version, packagePath } = bundleRequest;\n\n if (!result) {\n return {\n status: 'fail',\n details: `[bundleTask] 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 source: 'bundleTask',\n });\n }\n\n const errors = result.errors?.map((error) => {\n const { text, source, location } = error;\n const filePath = location ? ' ' + formatLocation({ ...location, fromPath: packagePath }) : '';\n return `[${source}]${filePath}\\n${red(indent(text, 1))}`;\n });\n const hasErrors = result.errors.length > 0;\n const status = hasErrors ? 'fail' : 'complete';\n const message = hasErrors ? plural(result.errors.length, 'error$s found') : undefined;\n const details = bulletedList([\n `Package: ${bundleRequest.packageName}@${bundleRequest.version}`,\n `Bundler: ${result.bundler || 'unknown'}`,\n `From cache: ${bundleRequest.resultFromCache}`,\n `Input path: ${bundleRequest.packagePath}`,\n `Entries:`,\n Object.values(result.entries || {}),\n `Output path: ${result.outputPath}`,\n `Output files:`,\n result.outputFiles.map(\n (file) =>\n `${normalizeRelativePath(file.outputPath)} (${getFileSizeSync(\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- there are output files, so this is set\n path.resolve(result.outputPath!, file.outputPath),\n )})`,\n ),\n ]);\n\n return {\n status,\n message,\n errors,\n details,\n };\n}\n"]}
1
+ {"version":3,"file":"formatBundleTaskResult.js","sourceRoot":"","sources":["../../src/utilities/formatBundleTaskResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAA+B,MAAM,6BAA6B,CAAC;AAE7G,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAA4B;IACjE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,aAAa,CAAC;IAEpE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,yCAAyC,WAAW,IAAI,OAAO,GAAG;SAC5E,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;IAC1B,MAAM,CAAC,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S,EAAE;QACzC,eAAe,aAAa,CAAC,eAAe,EAAE;QAC9C,eAAe,aAAa,CAAC,WAAW,EAAE;QAC1C,UAAU;QACV,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QACnC,gBAAgB,MAAM,CAAC,UAAU,EAAE;QACnC,eAAe;QACf,MAAM,CAAC,WAAW,CAAC,GAAG,CACpB,CAAC,IAAI,EAAE,EAAE,CACP,GAAG,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,eAAe;QAC3D,8GAA8G;QAC9G,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAClD,GAAG,CACP;KACF,CAAC,CAAC;IAEH,OAAO;QACL,MAAM;QACN,OAAO;QACP,MAAM;QACN,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { formatLocation } from '@ms-cloudpack/path-utilities';\nimport { red, bulletedList, plural, indent, type TaskReporterTaskResult } from '@ms-cloudpack/task-reporter';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { getFileSizeSync } from './getFileSizeSync.js';\nimport path from 'path';\n\n/**\n * Format a bundle result into a TaskReporter task result.\n *\n * NOTE: The info as formatted here will only be shown when a task is completed, not in the summary.\n * Reporter configuration may change over time, but as of writing:\n * - Failed tasks (message and errors) will be shown unless `--quiet`.\n * - Successful tasks will only be shown with `--verbose` or `--debug`, or if the command sets\n * `showCompleted` (`cloudpack bundle` does as of writing).\n */\nexport function formatBundleTaskResult(bundleRequest: BundleRequest): TaskReporterTaskResult {\n const { result, packageName, version, packagePath } = bundleRequest;\n\n if (!result) {\n return {\n status: 'fail',\n details: `[bundleTask] 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 source: 'bundleTask',\n });\n }\n\n const errors = result.errors?.map((error) => {\n const { text, source, location } = error;\n const filePath = location ? ' ' + formatLocation({ ...location, fromPath: packagePath }) : '';\n return `[${source}]${filePath}\\n${red(indent(text, 1))}`;\n });\n const hasErrors = result.errors.length > 0;\n const status = hasErrors ? 'fail' : 'complete';\n const message = hasErrors ? plural(result.errors.length, 'error$s found') : undefined;\n // Only shown with --verbose or --debug\n const details = bulletedList([\n `Package: ${bundleRequest.packageName}@${bundleRequest.version}`,\n `Bundler: ${result.bundler || 'unknown'}`,\n `From cache: ${bundleRequest.resultFromCache}`,\n `Input path: ${bundleRequest.packagePath}`,\n `Entries:`,\n Object.values(result.entries || {}),\n `Output path: ${result.outputPath}`,\n `Output files:`,\n result.outputFiles.map(\n (file) =>\n `${normalizeRelativePath(file.outputPath)} (${getFileSizeSync(\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- there are output files, so this is set\n path.resolve(result.outputPath!, file.outputPath),\n )})`,\n ),\n ]);\n\n return {\n status,\n message,\n errors,\n details,\n };\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns the path to the result.json file (result object that is written to the cache)
3
+ * in the bundle output directory.
4
+ * @param outputPath Path to the bundle output directory.
5
+ */
6
+ export declare function getResultJsonPath(outputPath: string): string;
7
+ //# sourceMappingURL=getResultJsonPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getResultJsonPath.d.ts","sourceRoot":"","sources":["../../src/utilities/getResultJsonPath.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE5D"}
@@ -0,0 +1,10 @@
1
+ import path from 'path';
2
+ /**
3
+ * Returns the path to the result.json file (result object that is written to the cache)
4
+ * in the bundle output directory.
5
+ * @param outputPath Path to the bundle output directory.
6
+ */
7
+ export function getResultJsonPath(outputPath) {
8
+ return path.join(outputPath, 'result.json');
9
+ }
10
+ //# sourceMappingURL=getResultJsonPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getResultJsonPath.js","sourceRoot":"","sources":["../../src/utilities/getResultJsonPath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import path from 'path';\n\n/**\n * Returns the path to the result.json file (result object that is written to the cache)\n * in the bundle output directory.\n * @param outputPath Path to the bundle output directory.\n */\nexport function getResultJsonPath(outputPath: string): string {\n return path.join(outputPath, 'result.json');\n}\n"]}
@@ -1,10 +1,18 @@
1
1
  import type { BundleRequest } from '../types/BundleRequest.js';
2
+ import type { RemoteCacheClient } from '@ms-cloudpack/remote-cache';
3
+ import type { PartialContext } from '../types/Context.js';
2
4
  /**
3
- * Reads the 'results.json' file from the cache, and construct a BundleRequest.result object from it.
4
- * @param outputPath - The path to the cache directory.
5
- * @param additionalProperties - Additional properties to add to the result object.
5
+ * Reads the `result.json` file from the cache, and construct a BundleRequest.result object from it.
6
+ * If the package wasn't already cached and `context.remoteCacheClient` is set, attempts to download it.
6
7
  */
7
- export declare function readResultFromCache(outputPath: string, additionalProperties: {
8
+ export declare function readResultFromCache(params: {
9
+ packageName: string;
10
+ version: string;
11
+ /** Package path (will be added to the result). */
8
12
  inputPath: string;
9
- }): Promise<BundleRequest['result']>;
13
+ /** The path to the cache directory. */
14
+ outputPath: string;
15
+ /** If provided, and the package isn't found locally, attempt to download it. */
16
+ remoteCacheClient?: RemoteCacheClient;
17
+ }, context: PartialContext<'packageHashes' | 'packages', 'cachePath'>): Promise<BundleRequest['result']>;
10
18
  //# sourceMappingURL=readResultFromCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"readResultFromCache.d.ts","sourceRoot":"","sources":["../../src/utilities/readResultFromCache.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG/D;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,oBAAoB,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1C,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAsBlC"}
1
+ {"version":3,"file":"readResultFromCache.d.ts","sourceRoot":"","sources":["../../src/utilities/readResultFromCache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE;IACN,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC,EACD,OAAO,EAAE,cAAc,CAAC,eAAe,GAAG,UAAU,EAAE,WAAW,CAAC,GAEjE,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAoDlC"}
@@ -1,19 +1,43 @@
1
1
  import { readJson } from '@ms-cloudpack/json-utilities';
2
- import path from 'path';
2
+ import { getRemoteCachePackageId } from './getRemoteCachePackageId.js';
3
+ import { getResultJsonPath } from './getResultJsonPath.js';
3
4
  /**
4
- * Reads the 'results.json' file from the cache, and construct a BundleRequest.result object from it.
5
- * @param outputPath - The path to the cache directory.
6
- * @param additionalProperties - Additional properties to add to the result object.
5
+ * Reads the `result.json` file from the cache, and construct a BundleRequest.result object from it.
6
+ * If the package wasn't already cached and `context.remoteCacheClient` is set, attempts to download it.
7
7
  */
8
- export async function readResultFromCache(outputPath, additionalProperties) {
9
- const resultFromFile = await readJson(path.join(outputPath, 'result.json'));
8
+ export async function readResultFromCache(params, context) {
9
+ const { packageName, version, inputPath, outputPath, remoteCacheClient } = params;
10
+ let bundleSource;
11
+ const resultPath = getResultJsonPath(outputPath);
12
+ let resultFromFile = await readJson(resultPath);
13
+ if (resultFromFile) {
14
+ bundleSource = 'local-cache';
15
+ }
16
+ else if (remoteCacheClient) {
17
+ const downloadResult = await remoteCacheClient.downloadFolder({
18
+ id: await getRemoteCachePackageId({ packagePath: inputPath }, context),
19
+ path: outputPath,
20
+ friendlyName: `${packageName}@${version}`,
21
+ });
22
+ if (downloadResult === 'success') {
23
+ resultFromFile = await readJson(resultPath);
24
+ if (!resultFromFile) {
25
+ throw new Error(`Downloading from the remote cache succeeded, but ${resultPath} could not be read. This is a Cloudpack bug.`);
26
+ }
27
+ bundleSource = 'remote-cache';
28
+ }
29
+ else if (downloadResult === 'already-exist') {
30
+ throw new Error(`The cache folder ${outputPath} already exists, but result.json was not found. This is a Cloudpack bug.`);
31
+ }
32
+ }
10
33
  if (!resultFromFile) {
11
34
  return undefined;
12
35
  }
13
36
  const result = {
14
37
  ...resultFromFile,
15
- ...additionalProperties,
38
+ inputPath,
16
39
  outputPath,
40
+ bundleSource,
17
41
  };
18
42
  // Rename deprecated bundlerName to bundler to avoid bumping the hash version.
19
43
  /* eslint-disable etc/no-deprecated */
@@ -1 +1 @@
1
- {"version":3,"file":"readResultFromCache.js","sourceRoot":"","sources":["../../src/utilities/readResultFromCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,UAAkB,EAClB,oBAA2C;IAE3C,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAa,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;IAExF,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GAA4B;QACtC,GAAG,cAAc;QACjB,GAAG,oBAAoB;QACvB,UAAU;KACX,CAAC;IAEF,8EAA8E;IAC9E,sCAAsC;IACtC,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC;QACpC,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IACD,qCAAqC;IAErC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { readJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { ResultJson } from '../types/ResultJson.js';\n\n/**\n * Reads the 'results.json' file from the cache, and construct a BundleRequest.result object from it.\n * @param outputPath - The path to the cache directory.\n * @param additionalProperties - Additional properties to add to the result object.\n */\nexport async function readResultFromCache(\n outputPath: string,\n additionalProperties: { inputPath: string },\n): Promise<BundleRequest['result']> {\n const resultFromFile = await readJson<ResultJson>(path.join(outputPath, 'result.json'));\n\n if (!resultFromFile) {\n return undefined;\n }\n\n const result: BundleRequest['result'] = {\n ...resultFromFile,\n ...additionalProperties,\n outputPath,\n };\n\n // Rename deprecated bundlerName to bundler to avoid bumping the hash version.\n /* eslint-disable etc/no-deprecated */\n if (result.bundlerName) {\n result.bundler = result.bundlerName;\n delete result.bundlerName;\n }\n /* eslint-enable etc/no-deprecated */\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"readResultFromCache.js","sourceRoot":"","sources":["../../src/utilities/readResultFromCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAIxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE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QACV,YAAY;KACb,CAAC;IAEF,8EAA8E;IAC9E,sCAAsC;IACtC,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC;QACpC,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IACD,qCAAqC;IAErC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { readJson } from '@ms-cloudpack/json-utilities';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { ResultJson } from '../types/ResultJson.js';\nimport type { RemoteCacheClient } from '@ms-cloudpack/remote-cache';\nimport { getRemoteCachePackageId } from './getRemoteCachePackageId.js';\nimport type { PartialContext } from '../types/Context.js';\nimport { getResultJsonPath } from './getResultJsonPath.js';\n\n/**\n * Reads the `result.json` file from the cache, and construct a BundleRequest.result object from it.\n * If the package wasn't already cached and `context.remoteCacheClient` is set, attempts to download it.\n */\nexport async function readResultFromCache(\n params: {\n packageName: string;\n version: string;\n /** Package path (will be added to the result). */\n inputPath: string;\n /** The path to the cache directory. */\n outputPath: string;\n /** If provided, and the package isn't found locally, attempt to download it. */\n remoteCacheClient?: RemoteCacheClient;\n },\n context: PartialContext<'packageHashes' | 'packages', 'cachePath'>,\n // outputPath: string,\n): Promise<BundleRequest['result']> {\n const { packageName, version, inputPath, outputPath, remoteCacheClient } = params;\n let bundleSource: NonNullable<BundleRequest['result']>['bundleSource'];\n\n const resultPath = getResultJsonPath(outputPath);\n\n let resultFromFile = await readJson<ResultJson>(resultPath);\n\n if (resultFromFile) {\n bundleSource = 'local-cache';\n } else if (remoteCacheClient) {\n const downloadResult = await remoteCacheClient.downloadFolder({\n id: await getRemoteCachePackageId({ packagePath: inputPath }, context),\n path: outputPath,\n friendlyName: `${packageName}@${version}`,\n });\n\n if (downloadResult === 'success') {\n resultFromFile = await readJson<ResultJson>(resultPath);\n if (!resultFromFile) {\n throw new Error(\n `Downloading from the remote cache succeeded, but ${resultPath} could not be read. This is a Cloudpack bug.`,\n );\n }\n bundleSource = 'remote-cache';\n } else if (downloadResult === 'already-exist') {\n throw new Error(\n `The cache folder ${outputPath} already exists, but result.json was not found. This is a Cloudpack bug.`,\n );\n }\n }\n\n if (!resultFromFile) {\n return undefined;\n }\n\n const result: BundleRequest['result'] = {\n ...resultFromFile,\n inputPath,\n outputPath,\n bundleSource,\n };\n\n // Rename deprecated bundlerName to bundler to avoid bumping the hash version.\n /* eslint-disable etc/no-deprecated */\n if (result.bundlerName) {\n result.bundler = result.bundlerName;\n delete result.bundlerName;\n }\n /* eslint-enable etc/no-deprecated */\n\n return result;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"saveResultToCache.d.ts","sourceRoot":"","sources":["../../src/utilities/saveResultToCache.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG/D;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,mBAAmB,EAAE,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhH"}
1
+ {"version":3,"file":"saveResultToCache.d.ts","sourceRoot":"","sources":["../../src/utilities/saveResultToCache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI/D;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,mBAAmB,EAAE,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBhH"}
@@ -1,22 +1,23 @@
1
1
  import { writeJson } from '@ms-cloudpack/json-utilities';
2
- import path from 'path';
2
+ import { getResultJsonPath } from './getResultJsonPath.js';
3
3
  /**
4
4
  * Writes the bundleRequestResults to a 'results.json' file.
5
5
  * @param bundleRequestResult - The result object to write to the cache.
6
6
  */
7
7
  export async function saveResultToCache(bundleRequestResult) {
8
- const { outputPath, bundler, entries, hash, outputFiles, warnings, errors } = bundleRequestResult;
8
+ const { outputPath, bundler, bundlerVersion, entries, hash, outputFiles, warnings, errors } = bundleRequestResult;
9
9
  if (!outputPath) {
10
10
  return;
11
11
  }
12
12
  const result = {
13
13
  bundler,
14
+ bundlerVersion,
14
15
  entries,
15
16
  hash,
16
17
  outputFiles,
17
18
  warnings,
18
19
  errors,
19
20
  };
20
- await writeJson(path.join(outputPath, 'result.json'), result);
21
+ await writeJson(getResultJsonPath(outputPath), result);
21
22
  }
22
23
  //# sourceMappingURL=saveResultToCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"saveResultToCache.js","sourceRoot":"","sources":["../../src/utilities/saveResultToCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,mBAAyD;IAC/F,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,mBAAmB,CAAC;IAClG,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAe;QACzB,OAAO;QACP,OAAO;QACP,IAAI;QACJ,WAAW;QACX,QAAQ;QACR,MAAM;KACP,CAAC;IAEF,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { writeJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { ResultJson } from '../types/ResultJson.js';\n\n/**\n * Writes the bundleRequestResults to a 'results.json' file.\n * @param bundleRequestResult - The result object to write to the cache.\n */\nexport async function saveResultToCache(bundleRequestResult: NonNullable<BundleRequest['result']>): Promise<void> {\n const { outputPath, bundler, entries, hash, outputFiles, warnings, errors } = bundleRequestResult;\n if (!outputPath) {\n return;\n }\n\n const result: ResultJson = {\n bundler,\n entries,\n hash,\n outputFiles,\n warnings,\n errors,\n };\n\n await writeJson(path.join(outputPath, 'result.json'), result);\n}\n"]}
1
+ {"version":3,"file":"saveResultToCache.js","sourceRoot":"","sources":["../../src/utilities/saveResultToCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,mBAAyD;IAC/F,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,mBAAmB,CAAC;IAClH,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAe;QACzB,OAAO;QACP,cAAc;QACd,OAAO;QACP,IAAI;QACJ,WAAW;QACX,QAAQ;QACR,MAAM;KACP,CAAC;IAEF,MAAM,SAAS,CAAC,iBAAiB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import { writeJson } from '@ms-cloudpack/json-utilities';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { ResultJson } from '../types/ResultJson.js';\nimport { getResultJsonPath } from './getResultJsonPath.js';\n\n/**\n * Writes the bundleRequestResults to a 'results.json' file.\n * @param bundleRequestResult - The result object to write to the cache.\n */\nexport async function saveResultToCache(bundleRequestResult: NonNullable<BundleRequest['result']>): Promise<void> {\n const { outputPath, bundler, bundlerVersion, entries, hash, outputFiles, warnings, errors } = bundleRequestResult;\n if (!outputPath) {\n return;\n }\n\n const result: ResultJson = {\n bundler,\n bundlerVersion,\n entries,\n hash,\n outputFiles,\n warnings,\n errors,\n };\n\n await writeJson(getResultJsonPath(outputPath), result);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/api-server",
3
- "version": "0.58.11",
3
+ "version": "0.58.12",
4
4
  "description": "An implementation of the API server that does interacts with a task scheduler.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,22 +27,22 @@
27
27
  "@lage-run/logger": "^1.3.0",
28
28
  "@lage-run/scheduler": "^1.2.1",
29
29
  "@lage-run/target-graph": "^0.9.0",
30
- "@ms-cloudpack/bundler": "^0.23.34",
31
- "@ms-cloudpack/common-types": "^0.24.3",
32
- "@ms-cloudpack/config": "^0.33.10",
33
- "@ms-cloudpack/create-express-app": "^1.10.15",
30
+ "@ms-cloudpack/bundler": "^0.23.35",
31
+ "@ms-cloudpack/common-types": "^0.24.4",
32
+ "@ms-cloudpack/config": "^0.33.11",
33
+ "@ms-cloudpack/create-express-app": "^1.10.16",
34
34
  "@ms-cloudpack/data-bus": "^0.4.3",
35
- "@ms-cloudpack/esm-stub-utilities": "^0.14.4",
35
+ "@ms-cloudpack/esm-stub-utilities": "^0.14.5",
36
36
  "@ms-cloudpack/file-watcher": "^0.2.0",
37
- "@ms-cloudpack/import-map": "^0.8.25",
37
+ "@ms-cloudpack/import-map": "^0.8.26",
38
38
  "@ms-cloudpack/json-utilities": "^0.1.10",
39
- "@ms-cloudpack/package-hashes": "^0.7.22",
40
- "@ms-cloudpack/package-utilities": "^11.3.0",
39
+ "@ms-cloudpack/package-hashes": "^0.7.23",
40
+ "@ms-cloudpack/package-utilities": "^11.3.1",
41
41
  "@ms-cloudpack/path-string-parsing": "^1.2.6",
42
- "@ms-cloudpack/path-utilities": "^3.0.0",
43
- "@ms-cloudpack/remote-cache": "^0.10.6",
44
- "@ms-cloudpack/task-reporter": "^0.14.8",
45
- "@ms-cloudpack/telemetry": "^0.10.10",
42
+ "@ms-cloudpack/path-utilities": "^3.0.1",
43
+ "@ms-cloudpack/remote-cache": "^0.10.7",
44
+ "@ms-cloudpack/task-reporter": "^0.15.0",
45
+ "@ms-cloudpack/telemetry": "^0.10.11",
46
46
  "@trpc/client": "11.0.0-rc.682",
47
47
  "@trpc/server": "11.0.0-rc.682",
48
48
  "cors": "^2.8.5",