peaks-loop-shared 0.0.101 → 0.0.103

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,29 @@
1
+ /**
2
+ * The canonical asset store — the legal home of the skills: `$PEAKS_HOME`,
3
+ * else `~/.peaks`. `null` when there is no home to speak of.
4
+ */
5
+ export declare function canonicalStoreRoot(env?: NodeJS.ProcessEnv): string | null;
6
+ /**
7
+ * The directory that holds the peaks assets — the root package's directory.
8
+ *
9
+ * The lookup must not depend on how npm laid the install out. The root
10
+ * package ships `skills/`; the shared package ships `dist/**` only, so the
11
+ * walk can never land on the shared package itself. npm NESTS the
12
+ * sub-packages under the root package in a global install and HOISTS them
13
+ * beside it in a local one, and a walk that only looks for "a directory with
14
+ * package.json AND skills/" finds the root in the nested layout and misses it
15
+ * in the hoisted one. That is why the published CLI died on its first import
16
+ * after a local install, while the global one worked.
17
+ *
18
+ * So every level of the walk asks one more question: is the root package
19
+ * BESIDE this directory? The answer no longer depends on npm's choice of
20
+ * layout — the root is found whether it is an ancestor (a checkout, a nested
21
+ * install) or a sibling in the same `node_modules` (a hoisted install, a pnpm
22
+ * store).
23
+ *
24
+ * The canonical store is the last resort — the skills' legal home, and the
25
+ * one place they are guaranteed to be when the root package is not on disk
26
+ * at all (this package installed on its own).
27
+ */
28
+ export declare function findRepoRoot(startPath: string): string;
29
+ //# sourceMappingURL=paths-resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths-resolve.d.ts","sourceRoot":"","sources":["../src/paths-resolve.ts"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,GAAG,IAAI,CAMtF;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAiBtD"}
@@ -0,0 +1,75 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, resolve } from 'node:path';
4
+ /**
5
+ * The package that owns the assets — `skills/`, `schemas/`, `contracts/`.
6
+ * The shared package ships `dist/**` only, so it can never be the answer.
7
+ */
8
+ const ROOT_PACKAGE_NAME = 'peaks-loop';
9
+ /**
10
+ * The env var that redirects the canonical asset store. The same name
11
+ * `scripts/canonical-store.mjs` uses (`CANONICAL_ROOT_ENV`).
12
+ *
13
+ * It is spelled out here rather than imported because that script lives in
14
+ * the ROOT package and this package publishes `dist/**` only — the two
15
+ * cannot import each other. One name, two readers, and the value is the
16
+ * store's LOCATION, not behaviour.
17
+ */
18
+ const CANONICAL_ROOT_ENV = 'PEAKS_HOME';
19
+ /** Does this directory look like the root package? `package.json` + `skills/`. */
20
+ function isRootPackageDir(dir) {
21
+ return existsSync(resolve(dir, 'package.json')) && existsSync(resolve(dir, 'skills'));
22
+ }
23
+ /**
24
+ * The canonical asset store — the legal home of the skills: `$PEAKS_HOME`,
25
+ * else `~/.peaks`. `null` when there is no home to speak of.
26
+ */
27
+ export function canonicalStoreRoot(env = process.env) {
28
+ const configured = env[CANONICAL_ROOT_ENV];
29
+ if (typeof configured === 'string' && configured.trim().length > 0)
30
+ return resolve(configured);
31
+ const home = homedir();
32
+ if (typeof home !== 'string' || home.length === 0)
33
+ return null;
34
+ return resolve(home, '.peaks');
35
+ }
36
+ /**
37
+ * The directory that holds the peaks assets — the root package's directory.
38
+ *
39
+ * The lookup must not depend on how npm laid the install out. The root
40
+ * package ships `skills/`; the shared package ships `dist/**` only, so the
41
+ * walk can never land on the shared package itself. npm NESTS the
42
+ * sub-packages under the root package in a global install and HOISTS them
43
+ * beside it in a local one, and a walk that only looks for "a directory with
44
+ * package.json AND skills/" finds the root in the nested layout and misses it
45
+ * in the hoisted one. That is why the published CLI died on its first import
46
+ * after a local install, while the global one worked.
47
+ *
48
+ * So every level of the walk asks one more question: is the root package
49
+ * BESIDE this directory? The answer no longer depends on npm's choice of
50
+ * layout — the root is found whether it is an ancestor (a checkout, a nested
51
+ * install) or a sibling in the same `node_modules` (a hoisted install, a pnpm
52
+ * store).
53
+ *
54
+ * The canonical store is the last resort — the skills' legal home, and the
55
+ * one place they are guaranteed to be when the root package is not on disk
56
+ * at all (this package installed on its own).
57
+ */
58
+ export function findRepoRoot(startPath) {
59
+ let current = resolve(startPath);
60
+ for (;;) {
61
+ if (isRootPackageDir(current))
62
+ return current;
63
+ const beside = resolve(current, ROOT_PACKAGE_NAME);
64
+ if (isRootPackageDir(beside))
65
+ return beside;
66
+ const parent = dirname(current);
67
+ if (parent === current)
68
+ break;
69
+ current = parent;
70
+ }
71
+ const canonical = canonicalStoreRoot();
72
+ if (canonical !== null && existsSync(resolve(canonical, 'skills')))
73
+ return canonical;
74
+ throw new Error(`Unable to locate Peaks repository root from ${startPath}`);
75
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,QAAQ,QAAqC,CAAC;AAC3D,eAAO,MAAM,SAAS,QAA8B,CAAC;AACrD,eAAO,MAAM,UAAU,QAA+B,CAAC;AACvD,eAAO,MAAM,YAAY,QAAiC,CAAC;AAE3D,eAAO,MAAM,kBAAkB,gHASrB,CAAC;AAEX,eAAO,MAAM,mBAAmB,srBAqBtB,CAAC"}
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,QAAqC,CAAC;AAC3D,eAAO,MAAM,SAAS,QAA8B,CAAC;AACrD,eAAO,MAAM,UAAU,QAA+B,CAAC;AACvD,eAAO,MAAM,YAAY,QAAiC,CAAC;AAE3D,eAAO,MAAM,kBAAkB,gHASrB,CAAC;AAEX,eAAO,MAAM,mBAAmB,srBAqBtB,CAAC"}
package/dist/paths.js CHANGED
@@ -1,17 +1,6 @@
1
- import { existsSync } from 'node:fs';
2
1
  import { dirname, resolve } from 'node:path';
3
2
  import { fileURLToPath } from 'node:url';
4
- function findRepoRoot(startPath) {
5
- let currentPath = startPath;
6
- while (currentPath !== dirname(currentPath)) {
7
- if (existsSync(resolve(currentPath, 'package.json')) &&
8
- existsSync(resolve(currentPath, 'skills'))) {
9
- return currentPath;
10
- }
11
- currentPath = dirname(currentPath);
12
- }
13
- throw new Error(`Unable to locate Peaks repository root from ${startPath}`);
14
- }
3
+ import { findRepoRoot } from './paths-resolve.js';
15
4
  const currentFile = fileURLToPath(import.meta.url);
16
5
  export const repoRoot = findRepoRoot(dirname(currentFile));
17
6
  export const skillsDir = resolve(repoRoot, 'skills');
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const CLI_VERSION = "4.1.12";
1
+ export declare const CLI_VERSION = "4.1.14";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = '4.1.12';
1
+ export const CLI_VERSION = '4.1.14';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peaks-loop-shared",
3
- "version": "0.0.101",
3
+ "version": "0.0.103",
4
4
  "description": "Shared pure-function utils for peaks-loop workspace packages (fs / paths / result / version). Slice 3a.",
5
5
  "keywords": [
6
6
  "peaks-loop",