@vibe-agent-toolkit/utils 0.1.34 → 0.1.36

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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Resolve a VAT "asset reference" to an absolute filesystem path.
3
+ *
4
+ * An asset reference is either:
5
+ * - A filesystem path (relative to baseDir, or absolute), OR
6
+ * - An npm bare specifier (`@scope/pkg/subpath` or `pkg/subpath`),
7
+ * resolved via Node module resolution from baseDir, honoring the
8
+ * target package's `exports` map.
9
+ *
10
+ * Bare specifiers let VAT consumers reference schemas (and future
11
+ * config-supplied files) published as npm packages without hardcoding
12
+ * the package's internal layout. The publisher's `exports` field owns
13
+ * the layout; consumers stay portable.
14
+ *
15
+ * NOTE: this is a VAT-internal abstraction for locating files. It is NOT
16
+ * an RFC 3986 URI reference and is intentionally NOT used by markdown link
17
+ * walkers (including the `format: "uri-reference"` frontmatter checker) —
18
+ * bare specifiers are not valid URIs and would not resolve in a renderer.
19
+ *
20
+ * @example
21
+ * resolveAssetReference('@scope/pkg/schemas/foo.json', '/proj')
22
+ * // -> '/proj/node_modules/@scope/pkg/dist/schemas/foo.json' (per the
23
+ * // package's exports map)
24
+ * resolveAssetReference('./schemas/foo.json', '/proj')
25
+ * // -> '/proj/schemas/foo.json'
26
+ * resolveAssetReference('/abs/foo.json', '/proj')
27
+ * // -> '/abs/foo.json'
28
+ *
29
+ * @param specifier - The asset reference (path or bare npm specifier)
30
+ * @param baseDir - Absolute directory used as the resolution anchor
31
+ * @returns Absolute filesystem path to the asset
32
+ * @throws Error with actionable message and `cause` on resolution failure
33
+ */
34
+ export declare function resolveAssetReference(specifier: string, baseDir: string): string;
35
+ //# sourceMappingURL=asset-reference.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,80 @@
1
+ import { createRequire } from 'node:module';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { safePath } from './path-utils.js';
4
+ // First segment must be a valid npm package name (scoped or unscoped),
5
+ // followed by `/` and at least one subpath segment. Paths starting with
6
+ // `.`, `/`, or a Windows drive letter are filesystem paths, never bare
7
+ // specifiers.
8
+ const BARE_SPECIFIER_RE = /^(?:@[^/]+\/[^/]+|[a-z0-9][a-z0-9._-]*)\/.+/i;
9
+ /**
10
+ * Resolve a VAT "asset reference" to an absolute filesystem path.
11
+ *
12
+ * An asset reference is either:
13
+ * - A filesystem path (relative to baseDir, or absolute), OR
14
+ * - An npm bare specifier (`@scope/pkg/subpath` or `pkg/subpath`),
15
+ * resolved via Node module resolution from baseDir, honoring the
16
+ * target package's `exports` map.
17
+ *
18
+ * Bare specifiers let VAT consumers reference schemas (and future
19
+ * config-supplied files) published as npm packages without hardcoding
20
+ * the package's internal layout. The publisher's `exports` field owns
21
+ * the layout; consumers stay portable.
22
+ *
23
+ * NOTE: this is a VAT-internal abstraction for locating files. It is NOT
24
+ * an RFC 3986 URI reference and is intentionally NOT used by markdown link
25
+ * walkers (including the `format: "uri-reference"` frontmatter checker) —
26
+ * bare specifiers are not valid URIs and would not resolve in a renderer.
27
+ *
28
+ * @example
29
+ * resolveAssetReference('@scope/pkg/schemas/foo.json', '/proj')
30
+ * // -> '/proj/node_modules/@scope/pkg/dist/schemas/foo.json' (per the
31
+ * // package's exports map)
32
+ * resolveAssetReference('./schemas/foo.json', '/proj')
33
+ * // -> '/proj/schemas/foo.json'
34
+ * resolveAssetReference('/abs/foo.json', '/proj')
35
+ * // -> '/abs/foo.json'
36
+ *
37
+ * @param specifier - The asset reference (path or bare npm specifier)
38
+ * @param baseDir - Absolute directory used as the resolution anchor
39
+ * @returns Absolute filesystem path to the asset
40
+ * @throws Error with actionable message and `cause` on resolution failure
41
+ */
42
+ export function resolveAssetReference(specifier, baseDir) {
43
+ if (!isBareSpecifier(specifier)) {
44
+ return safePath.resolve(baseDir, specifier);
45
+ }
46
+ const requireFn = createRequire(pathToFileURL(safePath.join(baseDir, 'package.json')).href);
47
+ try {
48
+ return requireFn.resolve(specifier);
49
+ }
50
+ catch (cause) {
51
+ // Unscoped bare specifiers can also be interpreted as relative paths
52
+ // (e.g., `dir/file.json` with no installed package "dir"). Fall back
53
+ // to path resolution. Scoped (`@scope/...`) has no such ambiguity —
54
+ // surface the error.
55
+ if (!specifier.startsWith('@') && isModuleNotFound(cause)) {
56
+ return safePath.resolve(baseDir, specifier);
57
+ }
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 });
60
+ }
61
+ }
62
+ function isBareSpecifier(value) {
63
+ return BARE_SPECIFIER_RE.test(value);
64
+ }
65
+ function isModuleNotFound(err) {
66
+ return (typeof err === 'object' &&
67
+ err !== null &&
68
+ 'code' in err &&
69
+ err.code === 'MODULE_NOT_FOUND');
70
+ }
71
+ function formatResolutionError(err) {
72
+ if (err instanceof Error) {
73
+ // Node's MODULE_NOT_FOUND / ERR_PACKAGE_PATH_NOT_EXPORTED messages are
74
+ // long and noisy; first line is the actionable summary.
75
+ const firstLine = err.message.split('\n', 1)[0];
76
+ return firstLine ?? err.message;
77
+ }
78
+ return String(err);
79
+ }
80
+ //# sourceMappingURL=asset-reference.js.map
@@ -0,0 +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;AAC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,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/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  export * from './safe-exec.js';
8
8
  export * from './path-utils.js';
9
+ export * from './asset-reference.js';
9
10
  export * from './fs-utils.js';
10
11
  export * from './file-crawler.js';
11
12
  export * from './gitignore-checker.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,eAAe,CAAC;AAG9B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,oBAAoB,CAAC;AAGnC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,eAAe,CAAC;AAG9B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,eAAe,CAAC;AAG9B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,oBAAoB,CAAC;AAGnC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,wBAAwB,CAAC;AAGvC,cAAc,eAAe,CAAC;AAG9B,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -8,6 +8,8 @@
8
8
  export * from './safe-exec.js';
9
9
  // Cross-platform path utilities
10
10
  export * from './path-utils.js';
11
+ // Asset reference resolution (paths + npm bare specifiers)
12
+ export * from './asset-reference.js';
11
13
  // Filesystem utilities
12
14
  export * from './fs-utils.js';
13
15
  // Directory crawling with glob patterns
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8DAA8D;AAC9D,cAAc,gBAAgB,CAAC;AAE/B,gCAAgC;AAChC,cAAc,iBAAiB,CAAC;AAEhC,uBAAuB;AACvB,cAAc,eAAe,CAAC;AAE9B,wCAAwC;AACxC,cAAc,mBAAmB,CAAC;AAElC,sBAAsB;AACtB,cAAc,wBAAwB,CAAC;AAEvC,8CAA8C;AAC9C,cAAc,gBAAgB,CAAC;AAE/B,kEAAkE;AAClE,cAAc,oBAAoB,CAAC;AAEnC,yDAAyD;AACzD,cAAc,kBAAkB,CAAC;AAEjC,oDAAoD;AACpD,cAAc,mBAAmB,CAAC;AAElC,4CAA4C;AAC5C,cAAc,wBAAwB,CAAC;AAEvC,2DAA2D;AAC3D,cAAc,eAAe,CAAC;AAE9B,oEAAoE;AACpE,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8DAA8D;AAC9D,cAAc,gBAAgB,CAAC;AAE/B,gCAAgC;AAChC,cAAc,iBAAiB,CAAC;AAEhC,2DAA2D;AAC3D,cAAc,sBAAsB,CAAC;AAErC,uBAAuB;AACvB,cAAc,eAAe,CAAC;AAE9B,wCAAwC;AACxC,cAAc,mBAAmB,CAAC;AAElC,sBAAsB;AACtB,cAAc,wBAAwB,CAAC;AAEvC,8CAA8C;AAC9C,cAAc,gBAAgB,CAAC;AAE/B,kEAAkE;AAClE,cAAc,oBAAoB,CAAC;AAEnC,yDAAyD;AACzD,cAAc,kBAAkB,CAAC;AAEjC,oDAAoD;AACpD,cAAc,mBAAmB,CAAC;AAElC,4CAA4C;AAC5C,cAAc,wBAAwB,CAAC;AAEvC,2DAA2D;AAC3D,cAAc,eAAe,CAAC;AAE9B,oEAAoE;AACpE,cAAc,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-agent-toolkit/utils",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "type": "module",
5
5
  "description": "Core utility functions with no external dependencies",
6
6
  "keywords": [