@pipelab/cli 2.0.0-beta.35 → 2.0.0-beta.37

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 (2) hide show
  1. package/index.mjs +169 -32
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -38,7 +38,8 @@ const SandboxFolder = {
38
38
  Config: "config",
39
39
  Temp: "temp",
40
40
  Cache: "cache",
41
- Pnpm: "pnpm"
41
+ Pnpm: "pnpm",
42
+ Artifacts: "artifacts"
42
43
  };
43
44
  const DEFAULT_NODE_VERSION = "24.14.1";
44
45
  const DEFAULT_PNPM_VERSION = "10.12.0";
@@ -134,6 +135,9 @@ var PipelabContext = class {
134
135
  getBuildHistoryPath(...subpaths) {
135
136
  return join(this.userDataPath, "build-history", ...subpaths);
136
137
  }
138
+ getArtifactsPath(...subpaths) {
139
+ return join(this.userDataPath, "artifacts", ...subpaths);
140
+ }
137
141
  getNodePath(version = DEFAULT_NODE_VERSION) {
138
142
  const isWindows = process.platform === "win32";
139
143
  return this.getThirdPartyPath("node", version, isWindows ? "node.exe" : "bin/node");
@@ -166,6 +170,10 @@ var PipelabContext = class {
166
170
  [SandboxFolder.Pnpm]: {
167
171
  label: "PNPM Home",
168
172
  path: this.getPnpmPath()
173
+ },
174
+ [SandboxFolder.Artifacts]: {
175
+ label: "Artifacts",
176
+ path: this.getArtifactsPath()
169
177
  }
170
178
  };
171
179
  return Object.keys(foldersRecord).map((key) => ({
@@ -4863,6 +4871,10 @@ var BuildHistoryStorage = class {
4863
4871
  if (pipelineId) {
4864
4872
  const entries = await this.loadPipelineHistory(pipelineId);
4865
4873
  for (const entry of entries) if (entry.cachePath) cachePathsToDelete.add(entry.cachePath);
4874
+ await rm(this.context.getArtifactsPath(pipelineId), {
4875
+ recursive: true,
4876
+ force: true
4877
+ }).catch(() => {});
4866
4878
  }
4867
4879
  await unlink(join(this.getStoragePath(), file));
4868
4880
  }
@@ -4888,6 +4900,10 @@ var BuildHistoryStorage = class {
4888
4900
  recursive: true,
4889
4901
  force: true
4890
4902
  }).catch(() => {});
4903
+ await rm(this.context.getArtifactsPath(pipelineId), {
4904
+ recursive: true,
4905
+ force: true
4906
+ }).catch(() => {});
4891
4907
  } catch (error) {
4892
4908
  if (error.code === "ENOENT") {
4893
4909
  this.logger.logger().warn(`No history file found for pipeline "${pipelineId}". Nothing to clear.`);
@@ -67357,7 +67373,7 @@ const checkParams = (definitionParams, elementParams) => {
67357
67373
  } else console.warn("Unexpected param \"" + param + "\"");
67358
67374
  for (const param of expected) if (isRequired(definitionParams[param])) throw new Error("Missing param \"" + param + "\"");
67359
67375
  };
67360
- const handleActionExecute = async (nodeId, pluginId, params, mainWindow, send, abortSignal, cwd, cachePath, context) => {
67376
+ const handleActionExecute = async (nodeId, pluginId, params, mainWindow, send, abortSignal, cwd, cachePath, context, onArtifact) => {
67361
67377
  const ctx = context;
67362
67378
  const { plugins } = usePlugins();
67363
67379
  const { logger } = useLogger();
@@ -67425,7 +67441,10 @@ const handleActionExecute = async (nodeId, pluginId, params, mainWindow, send, a
67425
67441
  },
67426
67442
  browserWindow: mainWindow,
67427
67443
  abortSignal,
67428
- context: ctx
67444
+ context: ctx,
67445
+ setArtifact: (name, path) => {
67446
+ onArtifact?.(name, path);
67447
+ }
67429
67448
  });
67430
67449
  mainWindow?.setProgressBar(1, { mode: "normal" });
67431
67450
  return {
@@ -67478,7 +67497,7 @@ const getFinalPlugins = () => {
67478
67497
  }
67479
67498
  return finalPlugins;
67480
67499
  };
67481
- const executeGraphWithHistory = async ({ graph, variables, projectName, projectPath, pipelineId, onNodeEnter, onNodeExit, onLog, abortSignal, mainWindow, cachePath, context }) => {
67500
+ const executeGraphWithHistory = async ({ graph, variables, projectName, projectPath, pipelineId, onNodeEnter, onNodeExit, onLog, onArtifact, onArtifactsFinalized, abortSignal, mainWindow, cachePath, context }) => {
67482
67501
  const ctx = context;
67483
67502
  const buildHistoryStorage = new BuildHistoryStorage(ctx);
67484
67503
  const buildId = nanoid();
@@ -67494,6 +67513,11 @@ const executeGraphWithHistory = async ({ graph, variables, projectName, projectP
67494
67513
  status: "running",
67495
67514
  logs: [],
67496
67515
  steps: [],
67516
+ metadata: {
67517
+ os: process.platform,
67518
+ arch: process.arch,
67519
+ nodeVersion: process.version
67520
+ },
67497
67521
  totalSteps: graph.length,
67498
67522
  completedSteps: 0,
67499
67523
  failedSteps: 0,
@@ -67501,12 +67525,14 @@ const executeGraphWithHistory = async ({ graph, variables, projectName, projectP
67501
67525
  createdAt: now,
67502
67526
  updatedAt: now
67503
67527
  };
67528
+ const executionSteps = initialEntry.steps;
67504
67529
  const shouldDisableHistory = process.env.PIPELAB_DISABLE_HISTORY === "true";
67505
67530
  if (!shouldDisableHistory) await buildHistoryStorage.save(initialEntry);
67506
67531
  const logs = [];
67507
67532
  const sandboxPath = await ctx.createTempFolder("pipeline-sandbox-");
67508
67533
  const { logger } = useLogger();
67509
67534
  let completedSteps = 0;
67535
+ const collectedArtifacts = [];
67510
67536
  const { registerPlugins, plugins: registeredPlugins } = usePlugins();
67511
67537
  const pluginIds = new Set(graph.map((node) => node.origin?.pluginId).filter(Boolean));
67512
67538
  const missingPlugins = [];
@@ -67532,21 +67558,47 @@ const executeGraphWithHistory = async ({ graph, variables, projectName, projectP
67532
67558
  id: nanoid(),
67533
67559
  level: "info",
67534
67560
  message: data.data.message,
67535
- timestamp: data.data.time,
67536
- nodeUid: node?.uid
67561
+ timestamp: data.data.time
67537
67562
  };
67538
67563
  logs.push(logEntry);
67564
+ const step = executionSteps.find((s) => s.id === node.uid);
67565
+ if (step) step.logs.push(logEntry);
67539
67566
  onLog?.(data, node);
67540
67567
  }
67541
- }, abortSignal, sandboxPath, cachePath, ctx);
67568
+ }, abortSignal, sandboxPath, cachePath, ctx, (name, path) => {
67569
+ collectedArtifacts.push({
67570
+ id: nanoid(),
67571
+ name,
67572
+ path,
67573
+ size: 0,
67574
+ type: "folder"
67575
+ });
67576
+ onArtifact?.(name, path, node);
67577
+ });
67542
67578
  throw new Error(`Execution of node type ${node.type} not implemented in utils.ts`);
67543
67579
  },
67544
67580
  onNodeEnter: (node) => {
67581
+ executionSteps.push({
67582
+ id: node.uid,
67583
+ name: node.origin?.nodeId || node.uid,
67584
+ status: "running",
67585
+ startTime: Date.now(),
67586
+ logs: []
67587
+ });
67545
67588
  onNodeEnter?.(node);
67546
67589
  },
67547
67590
  onNodeExit: async (node) => {
67548
67591
  completedSteps++;
67549
- if (!shouldDisableHistory) buildHistoryStorage.update(buildId, { completedSteps }, pipelineId).catch((err) => {
67592
+ const step = executionSteps.find((s) => s.id === node.uid);
67593
+ if (step) {
67594
+ step.status = "completed";
67595
+ step.endTime = Date.now();
67596
+ step.duration = step.endTime - step.startTime;
67597
+ }
67598
+ if (!shouldDisableHistory) buildHistoryStorage.update(buildId, {
67599
+ completedSteps,
67600
+ steps: executionSteps
67601
+ }, pipelineId).catch((err) => {
67550
67602
  logger().error(`Failed to update progress for build ${buildId}:`, err);
67551
67603
  });
67552
67604
  onNodeExit?.(node);
@@ -67554,14 +67606,43 @@ const executeGraphWithHistory = async ({ graph, variables, projectName, projectP
67554
67606
  abortSignal
67555
67607
  });
67556
67608
  const endTime = Date.now();
67557
- if (!shouldDisableHistory) await buildHistoryStorage.update(buildId, {
67558
- status: "completed",
67559
- endTime,
67560
- duration: endTime - startTime,
67561
- output: result.steps,
67562
- logs,
67563
- completedSteps
67564
- }, pipelineId);
67609
+ if (!shouldDisableHistory) {
67610
+ if (collectedArtifacts.length > 0) {
67611
+ const artifactsDir = ctx.getArtifactsPath(pipelineId, buildId);
67612
+ await mkdir(artifactsDir, { recursive: true });
67613
+ for (const artifact of collectedArtifacts) try {
67614
+ const destPath = join(artifactsDir, artifact.name);
67615
+ const originalNoAsar = process.noAsar;
67616
+ process.noAsar = true;
67617
+ try {
67618
+ await cp(artifact.path, destPath, { recursive: true });
67619
+ } finally {
67620
+ process.noAsar = originalNoAsar;
67621
+ }
67622
+ try {
67623
+ const s = await stat(destPath);
67624
+ artifact.type = s.isDirectory() ? "folder" : "file";
67625
+ artifact.size = s.isDirectory() ? await getFolderSize(destPath) : s.size;
67626
+ artifact.path = destPath;
67627
+ } catch (e) {
67628
+ logger().warn(`Failed to get size for artifact ${artifact.name}:`, e);
67629
+ }
67630
+ } catch (e) {
67631
+ logger().error(`Failed to copy artifact ${artifact.name}:`, e);
67632
+ }
67633
+ }
67634
+ onArtifactsFinalized?.(collectedArtifacts);
67635
+ await buildHistoryStorage.update(buildId, {
67636
+ status: "completed",
67637
+ endTime,
67638
+ duration: endTime - startTime,
67639
+ output: result.steps,
67640
+ logs,
67641
+ steps: executionSteps,
67642
+ completedSteps,
67643
+ artifacts: collectedArtifacts
67644
+ }, pipelineId);
67645
+ }
67565
67646
  return {
67566
67647
  result,
67567
67648
  buildId
@@ -67569,20 +67650,58 @@ const executeGraphWithHistory = async ({ graph, variables, projectName, projectP
67569
67650
  } catch (error) {
67570
67651
  const endTime = Date.now();
67571
67652
  const isCanceled = error instanceof Error && error.name === "AbortError";
67572
- if (!shouldDisableHistory) await buildHistoryStorage.update(buildId, {
67573
- status: isCanceled ? "cancelled" : "failed",
67574
- endTime,
67575
- duration: endTime - startTime,
67576
- error: {
67577
- message: error instanceof Error ? error.message : String(error),
67578
- stack: error instanceof Error ? error.stack : void 0,
67579
- timestamp: endTime
67580
- },
67581
- logs,
67582
- completedSteps,
67583
- failedSteps: isCanceled ? 0 : 1,
67584
- cancelledSteps: isCanceled ? 1 : 0
67585
- }, pipelineId);
67653
+ if (!shouldDisableHistory) {
67654
+ if (collectedArtifacts.length > 0) {
67655
+ const artifactsDir = ctx.getArtifactsPath(pipelineId, buildId);
67656
+ await mkdir(artifactsDir, { recursive: true });
67657
+ for (const artifact of collectedArtifacts) try {
67658
+ const destPath = join(artifactsDir, artifact.name);
67659
+ const originalNoAsar = process.noAsar;
67660
+ process.noAsar = true;
67661
+ try {
67662
+ await cp(artifact.path, destPath, { recursive: true });
67663
+ } finally {
67664
+ process.noAsar = originalNoAsar;
67665
+ }
67666
+ try {
67667
+ const s = await stat(destPath);
67668
+ artifact.type = s.isDirectory() ? "folder" : "file";
67669
+ artifact.size = s.isDirectory() ? await getFolderSize(destPath) : s.size;
67670
+ artifact.path = destPath;
67671
+ } catch (e) {
67672
+ logger().warn(`Failed to get size for artifact ${artifact.name}:`, e);
67673
+ }
67674
+ } catch (e) {
67675
+ logger().error(`Failed to copy artifact ${artifact.name}:`, e);
67676
+ }
67677
+ }
67678
+ onArtifactsFinalized?.(collectedArtifacts);
67679
+ for (const step of executionSteps) if (step.status === "running") {
67680
+ step.status = isCanceled ? "cancelled" : "failed";
67681
+ step.endTime = endTime;
67682
+ step.duration = endTime - step.startTime;
67683
+ step.error = {
67684
+ message: error instanceof Error ? error.message : String(error),
67685
+ timestamp: endTime
67686
+ };
67687
+ }
67688
+ await buildHistoryStorage.update(buildId, {
67689
+ status: isCanceled ? "cancelled" : "failed",
67690
+ endTime,
67691
+ duration: endTime - startTime,
67692
+ error: {
67693
+ message: error instanceof Error ? error.message : String(error),
67694
+ stack: error instanceof Error ? error.stack : void 0,
67695
+ timestamp: endTime
67696
+ },
67697
+ logs,
67698
+ steps: executionSteps,
67699
+ completedSteps,
67700
+ failedSteps: isCanceled ? 0 : 1,
67701
+ cancelledSteps: isCanceled ? 1 : 0,
67702
+ artifacts: collectedArtifacts
67703
+ }, pipelineId);
67704
+ }
67586
67705
  throw error;
67587
67706
  } finally {
67588
67707
  try {
@@ -68073,6 +68192,24 @@ const registerEngineHandlers = (context) => {
68073
68192
  });
68074
68193
  }
68075
68194
  },
68195
+ onArtifact: (name, path, node) => {
68196
+ send({
68197
+ type: "node-artifact",
68198
+ data: {
68199
+ nodeUid: node?.uid || "unknown",
68200
+ artifact: {
68201
+ name,
68202
+ path
68203
+ }
68204
+ }
68205
+ });
68206
+ },
68207
+ onArtifactsFinalized: (artifacts) => {
68208
+ send({
68209
+ type: "node-artifacts-finalized",
68210
+ data: { artifacts }
68211
+ });
68212
+ },
68076
68213
  abortSignal: abortControllerGraph.signal,
68077
68214
  cachePath: effectiveCachePath,
68078
68215
  context
@@ -69302,7 +69439,7 @@ async function runPipelineCommand(file, options, version) {
69302
69439
  }
69303
69440
  //#endregion
69304
69441
  //#region package.json
69305
- var version$2 = "2.0.0-beta.35";
69442
+ var version$2 = "2.0.0-beta.37";
69306
69443
  //#endregion
69307
69444
  //#region src/paths.ts
69308
69445
  const getDefaultUserDataPath = () => {
@@ -77254,7 +77391,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
77254
77391
  const isProduction = process.env.TEST !== "true";
77255
77392
  let posthog;
77256
77393
  if (isProduction && "phc_oXBjgJkl3ORfM2b6FZlbwaWHkGxJp9jFrj0l5aLjJql") posthog = new PostHog("phc_oXBjgJkl3ORfM2b6FZlbwaWHkGxJp9jFrj0l5aLjJql", { host: "https://eu.i.posthog.com" });
77257
- let version = "2.0.0-beta.35";
77394
+ let version = "2.0.0-beta.37";
77258
77395
  if (version === "0.0.0") try {
77259
77396
  const packageJsonPath = existsSync(join(__dirname, "package.json")) ? join(__dirname, "package.json") : join(__dirname, "..", "package.json");
77260
77397
  if (existsSync(packageJsonPath)) version = JSON.parse(readFileSync(packageJsonPath, "utf-8")).version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipelab/cli",
3
- "version": "2.0.0-beta.35",
3
+ "version": "2.0.0-beta.37",
4
4
  "description": "The command line interface for Pipelab",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "CynToolkit",