@vibe-agent-toolkit/utils 0.1.36 → 0.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"asset-reference.d.ts","sourceRoot":"","sources":["../src/asset-reference.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAuBhF"}
1
+ {"version":3,"file":"asset-reference.d.ts","sourceRoot":"","sources":["../src/asset-reference.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAmBhF"}
@@ -1,6 +1,7 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { createRequire } from 'node:module';
2
3
  import { pathToFileURL } from 'node:url';
3
- import { safePath } from './path-utils.js';
4
+ import { isAbsolutePath, safePath } from './path-utils.js';
4
5
  // First segment must be a valid npm package name (scoped or unscoped),
5
6
  // followed by `/` and at least one subpath segment. Paths starting with
6
7
  // `.`, `/`, or a Windows drive letter are filesystem paths, never bare
@@ -55,8 +56,65 @@ export function resolveAssetReference(specifier, baseDir) {
55
56
  if (!specifier.startsWith('@') && isModuleNotFound(cause)) {
56
57
  return safePath.resolve(baseDir, specifier);
57
58
  }
58
- throw new Error(`Failed to resolve asset reference '${specifier}': ${formatResolutionError(cause)}\n` +
59
- `Check the package's "exports" field, or run install in ${baseDir}.`, { cause: cause });
59
+ throw new Error(formatActionableError(specifier, baseDir, cause), { cause: cause });
60
+ }
61
+ }
62
+ /**
63
+ * Build a message that distinguishes the three common failure modes so callers
64
+ * know where to look. Node's raw error often points at the resolved on-disk
65
+ * path, which adopters easily misread as a VAT path-handling bug.
66
+ */
67
+ function formatActionableError(specifier, baseDir, cause) {
68
+ const headline = formatResolutionError(cause);
69
+ const code = cause?.code;
70
+ const missingPath = extractMissingModulePath(cause);
71
+ // Mode 1: Node walked the package's `exports` map, computed an absolute
72
+ // target path, and that file is not on disk. This is the most confusing
73
+ // case for adopters: the package IS installed, the exports map IS correct,
74
+ // but a build step in the target package didn't run (or produced different
75
+ // output). Name the missing file explicitly and point at the publisher.
76
+ if (code === 'MODULE_NOT_FOUND' && missingPath && missingPath !== specifier && isAbsolutePath(missingPath)) {
77
+ const fileExists = safeExistsSync(missingPath);
78
+ if (!fileExists) {
79
+ return (`Failed to resolve asset reference '${specifier}': ` +
80
+ `the package's "exports" map points to '${missingPath}', but that file does not exist on disk.\n` +
81
+ `Hint: the target package was found, but a build step did not produce this file. ` +
82
+ `Rebuild the publishing package (e.g., \`pnpm --filter <package> build\`) to generate the missing artifact, ` +
83
+ `or verify the package's "exports" subpath pattern matches what its build emits.\n` +
84
+ `Node error: ${headline}`);
85
+ }
86
+ }
87
+ // Mode 2: Exports map didn't expose the requested subpath at all.
88
+ if (code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
89
+ return (`Failed to resolve asset reference '${specifier}': ` +
90
+ `the target package does not expose this subpath in its "exports" map.\n` +
91
+ `Hint: check the package's package.json "exports" field — only paths declared there are reachable via bare specifier.\n` +
92
+ `Node error: ${headline}`);
93
+ }
94
+ // Mode 3: Package itself not installed / not reachable from baseDir.
95
+ return (`Failed to resolve asset reference '${specifier}': ${headline}\n` +
96
+ `Check the package's "exports" field, or run install in ${baseDir}.`);
97
+ }
98
+ /**
99
+ * Node's MODULE_NOT_FOUND message has the form: `Cannot find module 'X'`.
100
+ * Pull `X` out so we can decide whether the error refers to the original
101
+ * specifier (package not installed) or to a resolved on-disk path (file
102
+ * missing at exports target).
103
+ */
104
+ const CANNOT_FIND_MODULE_RE = /Cannot find module '([^']+)'/;
105
+ function extractMissingModulePath(cause) {
106
+ if (!(cause instanceof Error))
107
+ return undefined;
108
+ const match = CANNOT_FIND_MODULE_RE.exec(cause.message);
109
+ return match?.[1];
110
+ }
111
+ function safeExistsSync(filePath) {
112
+ try {
113
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- filePath is a Node-resolved exports target, used only to refine the error message
114
+ return existsSync(filePath);
115
+ }
116
+ catch {
117
+ return false;
60
118
  }
61
119
  }
62
120
  function isBareSpecifier(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"asset-reference.js","sourceRoot":"","sources":["../src/asset-reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,uEAAuE;AACvE,wEAAwE;AACxE,uEAAuE;AACvE,cAAc;AACd,MAAM,iBAAiB,GAAG,8CAA8C,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAiB,EAAE,OAAe;IACtE,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;QAChC,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,SAAS,GAAG,aAAa,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE5F,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,qEAAqE;QACrE,qEAAqE;QACrE,oEAAoE;QACpE,qBAAqB;QACrB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1D,OAAO,QAAQ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pC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,KAAK,IAAI;QACZ,MAAM,IAAI,GAAG;QACZ,GAAwB,CAAC,IAAI,KAAK,kBAAkB,CACtD,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,GAAY;IACzC,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,uEAAuE;QACvE,wDAAwD;QACxD,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAChD,OAAO,SAAS,IAAI,GAAG,CAAC,OAAO,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-agent-toolkit/utils",
3
- "version": "0.1.36",
3
+ "version": "0.1.37",
4
4
  "type": "module",
5
5
  "description": "Core utility functions with no external dependencies",
6
6
  "keywords": [