@mono-labs/shared 0.1.267 → 0.1.270

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,20 @@
1
+ export interface WorkspaceRootResult {
2
+ root: string;
3
+ isWorkspace: boolean;
4
+ }
5
+ /**
6
+ * Walk up from startDir until we find a directory containing package.json.
7
+ * Returns the first match or falls back to startDir.
8
+ */
9
+ export declare function findProjectRoot(startDir?: string): string;
10
+ /**
11
+ * Walk up from startDir checking for monorepo/workspace markers:
12
+ * - package.json with "workspaces" field (yarn/npm workspaces)
13
+ * - pnpm-workspace.yaml
14
+ * - lerna.json, turbo.json, nx.json
15
+ * - .git directory (fallback)
16
+ *
17
+ * Returns { root, isWorkspace }.
18
+ */
19
+ export declare function findWorkspaceRoot(startDir?: string): WorkspaceRootResult;
20
+ //# sourceMappingURL=find-root.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-root.d.ts","sourceRoot":"","sources":["../src/find-root.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,OAAO,CAAA;CACpB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,GAAE,MAAsB,GAAG,MAAM,CAcxE;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,GAAE,MAAsB,GAAG,mBAAmB,CAkCvF"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findProjectRoot = findProjectRoot;
7
+ exports.findWorkspaceRoot = findWorkspaceRoot;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ /**
11
+ * Walk up from startDir until we find a directory containing package.json.
12
+ * Returns the first match or falls back to startDir.
13
+ */
14
+ function findProjectRoot(startDir = process.cwd()) {
15
+ let current = path_1.default.resolve(startDir);
16
+ while (true) {
17
+ const pkg = path_1.default.join(current, 'package.json');
18
+ if (fs_1.default.existsSync(pkg))
19
+ return current;
20
+ const parent = path_1.default.dirname(current);
21
+ if (parent === current)
22
+ break;
23
+ current = parent;
24
+ }
25
+ return path_1.default.resolve(startDir);
26
+ }
27
+ /**
28
+ * Walk up from startDir checking for monorepo/workspace markers:
29
+ * - package.json with "workspaces" field (yarn/npm workspaces)
30
+ * - pnpm-workspace.yaml
31
+ * - lerna.json, turbo.json, nx.json
32
+ * - .git directory (fallback)
33
+ *
34
+ * Returns { root, isWorkspace }.
35
+ */
36
+ function findWorkspaceRoot(startDir = process.cwd()) {
37
+ let dir = path_1.default.resolve(startDir);
38
+ while (true) {
39
+ // Check for package.json with workspaces field
40
+ const pkgPath = path_1.default.join(dir, 'package.json');
41
+ if (fs_1.default.existsSync(pkgPath)) {
42
+ try {
43
+ const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf8'));
44
+ if (pkg?.workspaces) {
45
+ return { root: dir, isWorkspace: true };
46
+ }
47
+ }
48
+ catch {
49
+ // ignore malformed package.json
50
+ }
51
+ }
52
+ // Check for other monorepo markers
53
+ const markers = ['pnpm-workspace.yaml', 'lerna.json', 'turbo.json', 'nx.json'];
54
+ if (markers.some((m) => fs_1.default.existsSync(path_1.default.join(dir, m)))) {
55
+ return { root: dir, isWorkspace: true };
56
+ }
57
+ // .git as fallback boundary
58
+ if (fs_1.default.existsSync(path_1.default.join(dir, '.git'))) {
59
+ return { root: dir, isWorkspace: false };
60
+ }
61
+ const parent = path_1.default.dirname(dir);
62
+ if (parent === dir)
63
+ break;
64
+ dir = parent;
65
+ }
66
+ return { root: path_1.default.resolve(startDir), isWorkspace: false };
67
+ }
@@ -0,0 +1,4 @@
1
+ export { writeLog } from './writeLog';
2
+ export { findProjectRoot, findWorkspaceRoot } from './find-root';
3
+ export type { WorkspaceRootResult } from './find-root';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAChE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findWorkspaceRoot = exports.findProjectRoot = exports.writeLog = void 0;
4
+ var writeLog_1 = require("./writeLog");
5
+ Object.defineProperty(exports, "writeLog", { enumerable: true, get: function () { return writeLog_1.writeLog; } });
6
+ var find_root_1 = require("./find-root");
7
+ Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return find_root_1.findProjectRoot; } });
8
+ Object.defineProperty(exports, "findWorkspaceRoot", { enumerable: true, get: function () { return find_root_1.findWorkspaceRoot; } });
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@mono-labs/shared",
3
- "version": "0.1.267",
3
+ "version": "0.1.270",
4
4
  "type": "commonjs",
5
5
  "description": "Shared utilities for mono-labs",
6
- "main": "dist/writeLog.js",
7
- "types": "dist/writeLog.d.ts",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/writeLog.d.ts",
11
- "require": "./dist/writeLog.js",
12
- "default": "./dist/writeLog.js"
10
+ "types": "./dist/index.d.ts",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
13
  }
14
14
  },
15
15
  "files": [