@visulima/task-runner 1.0.0-alpha.8 → 1.0.0-alpha.9

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 (40) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +3 -1
  3. package/dist/index.d.ts +791 -205
  4. package/dist/index.js +28 -20
  5. package/dist/packem_chunks/index.js +5593 -0
  6. package/dist/packem_shared/{Cache-CWaX_c8U.js → Cache-CbhoA268.js} +151 -10
  7. package/dist/packem_shared/{FileAccessTracker-CQ5Ot7Hd.js → FileAccessTracker-D8zIURPU.js} +1 -1
  8. package/dist/packem_shared/{FingerprintManager-CV7U4f4f.js → FingerprintManager-78DjwWQ4.js} +1 -1
  9. package/dist/packem_shared/HttpRemoteCache-BTXUBH7t.js +290 -0
  10. package/dist/packem_shared/INPUT_URI_SCHEMES-DRm76YI5.js +69 -0
  11. package/dist/packem_shared/{IncrementalFileHasher-BRS76-mb.js → IncrementalFileHasher-BBhVK491.js} +1 -1
  12. package/dist/packem_shared/ReapiRemoteCache-vgRxDMmu.js +1012 -0
  13. package/dist/packem_shared/{TaskOrchestrator-UCMHCx8c.js → TaskOrchestrator-CdRaQhTO.js} +34 -11
  14. package/dist/packem_shared/{TrackedTaskExecutor-CFPpQfXF.js → TrackedTaskExecutor-CWSMfHAW.js} +2 -2
  15. package/dist/packem_shared/V2_ROOT-DKBLxKo4.js +14 -0
  16. package/dist/packem_shared/actionDigestForTaskHash-BRE-9MT6.js +121 -0
  17. package/dist/packem_shared/archive-CnggHWb-.js +152 -0
  18. package/dist/packem_shared/{collectFiles-ClXHnHhg.js → collectFiles-cc1gokGU.js} +2 -1
  19. package/dist/packem_shared/{computeTaskHash-B5APHW7e.js → computeTaskHash-DHoBJ_-V.js} +10 -4
  20. package/dist/packem_shared/containsBlob-CwGB0a_q.js +125 -0
  21. package/dist/packem_shared/{createTaskGraph-B5YrfAMx.js → createTaskGraph-Bwl4hwAf.js} +17 -0
  22. package/dist/packem_shared/{defaultTaskRunner-DzR0ld8F.js → defaultTaskRunner-BaX4ZbFv.js} +24 -13
  23. package/dist/packem_shared/{detectFrameworks-CeFzKE6J.js → detectFrameworks-D7nyTc-o.js} +1 -1
  24. package/dist/packem_shared/{detectScriptShell-CR-xXKA4.js → detectScriptShell-CzxCM9-t.js} +1 -1
  25. package/dist/packem_shared/digestBuffer-CPdI2E1d.js +48 -0
  26. package/dist/packem_shared/{expandArguments-0AwD2BIA.js → expandArguments-Ba-hHYff.js} +2 -1
  27. package/dist/packem_shared/{expandTokensInString-C03AGAjh.js → expandTokensInString-Bb7nYehP.js} +2 -1
  28. package/dist/packem_shared/{extractPackageName-CbVNW-dr.js → extractPackageName-CMHjqGj_.js} +1 -1
  29. package/dist/packem_shared/{generateRunSummary-BE1jnQ3H.js → generateRunSummary-Bah7CFay.js} +1 -1
  30. package/dist/packem_shared/{getCurrentBranch-DsKPDoVj.js → getCurrentBranch-DVNikt0P.js} +11 -8
  31. package/dist/packem_shared/getMainWorktreeRoot-iBqToQJ4.js +114 -0
  32. package/dist/packem_shared/{parseCommands-CJ16ohOB.js → parseCommands-DDdIxaH5.js} +3 -3
  33. package/dist/packem_shared/resolveCacheMode-CsmHT_0o.js +21 -0
  34. package/dist/packem_shared/{runConcurrently-CmfC4r-f.js → runConcurrently-BCGQ9fJl.js} +1 -1
  35. package/dist/packem_shared/shell-quote-DWJJbt21.js +3 -0
  36. package/dist/packem_shared/{utils-zO0ZRgtf.js → utils-Bmnj-H2J.js} +4 -1
  37. package/index.js +52 -52
  38. package/package.json +23 -10
  39. package/dist/packem_shared/RemoteCache-DSU3lc87.js +0 -219
  40. package/dist/packem_shared/archive-UQHAnZUa.js +0 -102
@@ -1,10 +1,10 @@
1
- import { x as xxh3Hash } from './utils-zO0ZRgtf.js';
2
- import { Cache } from './Cache-CWaX_c8U.js';
3
- import { inferFrameworkEnvPatterns } from './detectFrameworks-CeFzKE6J.js';
4
- import { IncrementalFileHasher } from './IncrementalFileHasher-BRS76-mb.js';
5
- import { RemoteCache } from './RemoteCache-DSU3lc87.js';
6
- import { InProcessTaskHasher } from './computeTaskHash-B5APHW7e.js';
7
- import { TaskOrchestrator } from './TaskOrchestrator-UCMHCx8c.js';
1
+ import { x as xxh3Hash } from './utils-Bmnj-H2J.js';
2
+ import { createRemoteCacheBackend } from './resolveCacheMode-CsmHT_0o.js';
3
+ import { Cache } from './Cache-CbhoA268.js';
4
+ import { inferFrameworkEnvPatterns } from './detectFrameworks-D7nyTc-o.js';
5
+ import { IncrementalFileHasher } from './IncrementalFileHasher-BBhVK491.js';
6
+ import { InProcessTaskHasher } from './computeTaskHash-DHoBJ_-V.js';
7
+ import { TaskOrchestrator } from './TaskOrchestrator-CdRaQhTO.js';
8
8
  import { TaskScheduler } from './parsePartition-BfLbHGAx.js';
9
9
 
10
10
  const partitionAlwaysTasks = (taskGraph) => {
@@ -95,7 +95,7 @@ const defaultTaskRunner = async (_tasks, options, context) => {
95
95
  const defaultConfig = options.targetDefaults?.[task.target.target];
96
96
  return targetConfig?.command ?? defaultConfig?.command;
97
97
  };
98
- const remoteCache = options.remoteCache ? new RemoteCache(options.remoteCache) : void 0;
98
+ const remoteCache = options.remoteCache ? createRemoteCacheBackend(options.remoteCache) : void 0;
99
99
  let fingerprintEnvPatterns = options.fingerprintEnvPatterns ?? [];
100
100
  if (options.frameworkInference && options.autoFingerprint) {
101
101
  const inferredPatterns = await inferFrameworkEnvPatterns(workspaceRoot, projects);
@@ -110,6 +110,10 @@ const defaultTaskRunner = async (_tasks, options, context) => {
110
110
  dryRun: options.dryRun,
111
111
  fingerprintEnvPatterns,
112
112
  lifeCycle,
113
+ // Bridge-local upload errors (tar/digest in hash-bridge) flow back
114
+ // through the same callback the wire-level backend uses, so a user
115
+ // observes upload failures regardless of where they originate.
116
+ onRemoteUploadError: options.remoteCache?.onUploadError,
113
117
  remoteCache,
114
118
  resolveCommand: options.autoFingerprint ? resolveCommand : void 0,
115
119
  scheduler,
@@ -121,12 +125,19 @@ const defaultTaskRunner = async (_tasks, options, context) => {
121
125
  untrackedEnvVars: options.untrackedEnvVars,
122
126
  workspaceRoot
123
127
  });
124
- const results = await orchestrator.run();
125
- if (incrementalHasher) {
126
- await incrementalHasher.save().catch(() => {
127
- });
128
+ try {
129
+ const results = await orchestrator.run();
130
+ if (incrementalHasher) {
131
+ await incrementalHasher.save().catch(() => {
132
+ });
133
+ }
134
+ return results;
135
+ } finally {
136
+ if (remoteCache) {
137
+ await remoteCache.close().catch(() => {
138
+ });
139
+ }
128
140
  }
129
- return results;
130
141
  };
131
142
 
132
143
  export { defaultTaskRunner };
@@ -1,5 +1,5 @@
1
1
  import { join } from '@visulima/path';
2
- import { r as readPackageDeps } from './utils-zO0ZRgtf.js';
2
+ import { r as readPackageDeps } from './utils-Bmnj-H2J.js';
3
3
 
4
4
  const FRAMEWORK_DEFINITIONS = [
5
5
  {
@@ -37,7 +37,7 @@ const detectScriptShell = () => {
37
37
  stdio: ["ignore", "pipe", "ignore"],
38
38
  timeout: 5e3
39
39
  }).trim();
40
- if (result && result !== "undefined" && result !== "") {
40
+ if (result && result !== "undefined" && result !== "null" && result !== "") {
41
41
  cachedShellPath = result;
42
42
  return result;
43
43
  }
@@ -0,0 +1,48 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ createHash
22
+ } = __cjs_getBuiltinModule("node:crypto");
23
+ const {
24
+ createReadStream
25
+ } = __cjs_getBuiltinModule("node:fs");
26
+ const {
27
+ stat
28
+ } = __cjs_getBuiltinModule("node:fs/promises");
29
+
30
+ const digestBuffer = (bytes) => {
31
+ const hash = createHash("sha256").update(bytes).digest("hex");
32
+ return { hash, sizeBytes: bytes.byteLength };
33
+ };
34
+ const digestFile = async (filePath) => {
35
+ try {
36
+ const { size } = await stat(filePath);
37
+ const hasher = createHash("sha256");
38
+ const source = createReadStream(filePath);
39
+ for await (const chunk of source) {
40
+ hasher.update(chunk);
41
+ }
42
+ return { hash: hasher.digest("hex"), sizeBytes: size };
43
+ } catch {
44
+ return void 0;
45
+ }
46
+ };
47
+
48
+ export { digestBuffer, digestFile };
@@ -1,5 +1,6 @@
1
+ import { s as shellQuote } from './shell-quote-DWJJbt21.js';
2
+
1
3
  const PLACEHOLDER_REGEX = /\\?\{([@*]|[1-9]\d*)\}/g;
2
- const shellQuote = (s) => `'${s.replaceAll("'", String.raw`'\''`)}'`;
3
4
  const expandArguments = (config, additionalArguments) => {
4
5
  if (additionalArguments.length === 0) {
5
6
  return config;
@@ -1,9 +1,10 @@
1
+ import { s as shellQuote } from './shell-quote-DWJJbt21.js';
2
+
1
3
  const TOKEN_PATHS = {
2
4
  "affected.files": "affectedFiles",
3
5
  changed_files: "affectedFiles"
4
6
  };
5
7
  const TOKEN_REGEX = /\\?\$\{\s*([\w.]+)\s*(?:\|\s*flag\s+(["'])(.*?)\2\s*)?\}/g;
6
- const shellQuote = (value) => `'${value.replaceAll("'", String.raw`'\''`)}'`;
7
8
  const rewriteForProjectRoot = (filePath, projectRoot) => {
8
9
  if (filePath === projectRoot) {
9
10
  return ".";
@@ -20,7 +20,7 @@ const __cjs_getBuiltinModule = (module) => {
20
20
  const {
21
21
  readFile
22
22
  } = __cjs_getBuiltinModule("node:fs/promises");
23
- import { r as readPackageDeps, e as createXxh3Hasher } from './utils-zO0ZRgtf.js';
23
+ import { r as readPackageDeps, e as createXxh3Hasher } from './utils-Bmnj-H2J.js';
24
24
  import { join } from '@visulima/path';
25
25
 
26
26
  const extractPackageName = (path) => {
@@ -23,7 +23,7 @@ const {
23
23
  writeFile
24
24
  } = __cjs_getBuiltinModule("node:fs/promises");
25
25
  import { join } from '@visulima/path';
26
- import { u as uniqueId } from './utils-zO0ZRgtf.js';
26
+ import { u as uniqueId } from './utils-Bmnj-H2J.js';
27
27
 
28
28
  const getCacheStatus = (result) => {
29
29
  switch (result.status) {
@@ -78,14 +78,20 @@ const getCurrentBranch = (cwd) => {
78
78
  const resetBranchCache = () => {
79
79
  branchCache.clear();
80
80
  };
81
+ const resolveWhenContext = (context) => {
82
+ const env = context.env ?? process.env;
83
+ return {
84
+ branch: context.branch ?? "",
85
+ ci: context.ci ?? detectCi(env),
86
+ currentPlatform: context.platform ?? process.platform,
87
+ env
88
+ };
89
+ };
81
90
  const evaluateWhen = (when, context = {}) => {
82
91
  if (!when) {
83
92
  return true;
84
93
  }
85
- const env = context.env ?? process.env;
86
- const currentPlatform = context.platform ?? process.platform;
87
- const branch = context.branch ?? "";
88
- const ci = context.ci ?? detectCi(env);
94
+ const { branch, ci, currentPlatform, env } = resolveWhenContext(context);
89
95
  if (when.os !== void 0 && !matchPlatform(when.os, currentPlatform)) {
90
96
  return false;
91
97
  }
@@ -118,10 +124,7 @@ const explainWhen = (when, context = {}) => {
118
124
  if (!when || evaluateWhen(when, context)) {
119
125
  return "";
120
126
  }
121
- const env = context.env ?? process.env;
122
- const currentPlatform = context.platform ?? process.platform;
123
- const branch = context.branch ?? "";
124
- const ci = context.ci ?? detectCi(env);
127
+ const { branch, ci, currentPlatform, env } = resolveWhenContext(context);
125
128
  const reasons = [];
126
129
  if (when.os !== void 0 && !matchPlatform(when.os, currentPlatform)) {
127
130
  reasons.push(`os=${currentPlatform} does not match ${JSON.stringify(when.os)}`);
@@ -0,0 +1,114 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ execFileSync
22
+ } = __cjs_getBuiltinModule("node:child_process");
23
+ const {
24
+ statSync,
25
+ realpathSync
26
+ } = __cjs_getBuiltinModule("node:fs");
27
+ import { isAbsolute, resolve, dirname } from '@visulima/path';
28
+ import { loadNativeBindings } from './isNativeAvailable-BpD28A6Z.js';
29
+
30
+ let nativeWorktreeBindings;
31
+ let nativeProbed = false;
32
+ const getNativeBindings = () => {
33
+ if (nativeProbed) {
34
+ return nativeWorktreeBindings;
35
+ }
36
+ nativeProbed = true;
37
+ const bindings = loadNativeBindings();
38
+ if (bindings && typeof bindings.getMainWorktreeRoot === "function" && typeof bindings.isLinkedWorktree === "function") {
39
+ nativeWorktreeBindings = {
40
+ getMainWorktreeRoot: bindings.getMainWorktreeRoot,
41
+ isLinkedWorktree: bindings.isLinkedWorktree,
42
+ resetWorktreeCache: typeof bindings.resetWorktreeCache === "function" ? bindings.resetWorktreeCache : () => {
43
+ }
44
+ };
45
+ }
46
+ return nativeWorktreeBindings;
47
+ };
48
+ const fallbackCache = /* @__PURE__ */ new Map();
49
+ const canonicalize = (path) => {
50
+ try {
51
+ return realpathSync(path);
52
+ } catch {
53
+ return path;
54
+ }
55
+ };
56
+ const fallbackIsLinkedWorktree = (workspaceRoot) => {
57
+ try {
58
+ const stat = statSync(resolve(workspaceRoot, ".git"));
59
+ return stat.isFile();
60
+ } catch {
61
+ return false;
62
+ }
63
+ };
64
+ const fallbackGetMainWorktreeRoot = (workspaceRoot) => {
65
+ const canonicalRoot = canonicalize(workspaceRoot);
66
+ if (fallbackCache.has(canonicalRoot)) {
67
+ return fallbackCache.get(canonicalRoot);
68
+ }
69
+ let result;
70
+ try {
71
+ if (fallbackIsLinkedWorktree(canonicalRoot)) {
72
+ const stdout = execFileSync("git", ["rev-parse", "--git-common-dir"], {
73
+ cwd: canonicalRoot,
74
+ encoding: "utf8",
75
+ stdio: ["ignore", "pipe", "ignore"]
76
+ }).trim();
77
+ if (stdout.length > 0) {
78
+ const commonDir = isAbsolute(stdout) ? stdout : resolve(canonicalRoot, stdout);
79
+ const mainRoot = canonicalize(dirname(commonDir));
80
+ result = mainRoot === canonicalRoot ? void 0 : mainRoot;
81
+ }
82
+ } else {
83
+ result = void 0;
84
+ }
85
+ } catch {
86
+ result = void 0;
87
+ }
88
+ fallbackCache.set(canonicalRoot, result);
89
+ return result;
90
+ };
91
+ const getMainWorktreeRoot = (workspaceRoot) => {
92
+ const native = getNativeBindings();
93
+ if (native) {
94
+ const result = native.getMainWorktreeRoot(workspaceRoot);
95
+ return typeof result === "string" && result.length > 0 ? result : void 0;
96
+ }
97
+ return fallbackGetMainWorktreeRoot(workspaceRoot);
98
+ };
99
+ const isLinkedWorktree = (workspaceRoot) => {
100
+ const native = getNativeBindings();
101
+ if (native) {
102
+ return native.isLinkedWorktree(workspaceRoot);
103
+ }
104
+ return fallbackIsLinkedWorktree(workspaceRoot);
105
+ };
106
+ const resetWorktreeCache = () => {
107
+ fallbackCache.clear();
108
+ const native = getNativeBindings();
109
+ if (native) {
110
+ native.resetWorktreeCache();
111
+ }
112
+ };
113
+
114
+ export { getMainWorktreeRoot, isLinkedWorktree, resetWorktreeCache };
@@ -1,7 +1,7 @@
1
- import { expandArguments } from './expandArguments-0AwD2BIA.js';
1
+ import { expandArguments } from './expandArguments-Ba-hHYff.js';
2
2
  import { expandShortcut } from './expandShortcut-BVG05ee4.js';
3
- import { expandTokens } from './expandTokensInString-C03AGAjh.js';
4
- export { expandTokensInString } from './expandTokensInString-C03AGAjh.js';
3
+ import { expandTokens } from './expandTokensInString-Bb7nYehP.js';
4
+ export { expandTokensInString } from './expandTokensInString-Bb7nYehP.js';
5
5
  import { expandWildcard } from './expandWildcard-B0xN_knq.js';
6
6
  import { stripQuotes } from './stripQuotes-Cey-zwFf.js';
7
7
 
@@ -0,0 +1,21 @@
1
+ import { HttpRemoteCache } from './HttpRemoteCache-BTXUBH7t.js';
2
+ import { ReapiRemoteCache } from './ReapiRemoteCache-vgRxDMmu.js';
3
+
4
+ const resolveCacheMode = (options) => options.mode ?? "readwrite";
5
+ const createRemoteCacheBackend = (options) => {
6
+ const mode = resolveCacheMode(options);
7
+ const resolved = { ...options, mode };
8
+ switch (options.backend ?? "http") {
9
+ case "http": {
10
+ return new HttpRemoteCache(resolved);
11
+ }
12
+ case "reapi": {
13
+ return new ReapiRemoteCache(resolved);
14
+ }
15
+ default: {
16
+ return new HttpRemoteCache(resolved);
17
+ }
18
+ }
19
+ };
20
+
21
+ export { createRemoteCacheBackend, resolveCacheMode };
@@ -1,5 +1,5 @@
1
1
  import { runConcurrentFallback } from './runConcurrentFallback-BTmgGV1H.js';
2
- import { detectScriptShell } from './detectScriptShell-CR-xXKA4.js';
2
+ import { detectScriptShell } from './detectScriptShell-CzxCM9-t.js';
3
3
  import { logTimings } from './formatTimingTable-3qtCM552.js';
4
4
  import { withRestart } from './withRestart-BREjRJa4.js';
5
5
  import { runTeardown } from './runTeardown-BAezH79J.js';
@@ -0,0 +1,3 @@
1
+ const shellQuote = (value) => `'${value.replaceAll("'", String.raw`'\''`)}'`;
2
+
3
+ export { shellQuote as s };
@@ -17,6 +17,9 @@ const __cjs_getBuiltinModule = (module) => {
17
17
  return __cjs_require(module);
18
18
  };
19
19
 
20
+ const {
21
+ randomUUID
22
+ } = __cjs_getBuiltinModule("node:crypto");
20
23
  const {
21
24
  stat,
22
25
  realpath,
@@ -385,6 +388,6 @@ const readPackageDeps = async (packageJsonPath, options = READ_PACKAGE_DEPS_DEFA
385
388
  return void 0;
386
389
  }
387
390
  };
388
- const uniqueId = () => `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
391
+ const uniqueId = () => randomUUID();
389
392
 
390
393
  export { createFailureResult as a, hashStrings as b, collectFiles as c, resolveTaskCwd as d, createXxh3Hasher as e, hashFile as h, readPackageDeps as r, sortObjectKeys as s, uniqueId as u, xxh3Hash as x };