turbometro 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +80 -0
- package/bin/turbometro.js +2 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +107 -0
- package/dist/find-root.d.ts +2 -0
- package/dist/find-root.js +14 -0
- package/dist/graph.d.ts +14 -0
- package/dist/graph.js +74 -0
- package/dist/layout.d.ts +19 -0
- package/dist/layout.js +15 -0
- package/dist/parse-turbo.d.ts +5 -0
- package/dist/parse-turbo.js +29 -0
- package/dist/parse-workspace.d.ts +4 -0
- package/dist/parse-workspace.js +100 -0
- package/dist/render-html.d.ts +8 -0
- package/dist/render-html.js +699 -0
- package/dist/render-map.d.ts +29 -0
- package/dist/render-map.js +287 -0
- package/dist/replay.d.ts +9 -0
- package/dist/replay.js +74 -0
- package/dist/scale.d.ts +7 -0
- package/dist/scale.js +19 -0
- package/dist/scene-data.d.ts +40 -0
- package/dist/scene-data.js +146 -0
- package/dist/theme.d.ts +15 -0
- package/dist/theme.js +15 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.js +1 -0
- package/fixtures/mini-mono/apps/web/package.json +11 -0
- package/fixtures/mini-mono/package.json +5 -0
- package/fixtures/mini-mono/packages/ui/package.json +11 -0
- package/fixtures/mini-mono/packages/utils/package.json +8 -0
- package/fixtures/mini-mono/pnpm-workspace.yaml +3 -0
- package/fixtures/mini-mono/turbo.json +10 -0
- package/package.json +44 -0
- package/vendor/dag-map/LICENSE +201 -0
- package/vendor/dag-map/NOTICE +6 -0
- package/vendor/dag-map/src/color-scales.js +61 -0
- package/vendor/dag-map/src/dag-map.css +63 -0
- package/vendor/dag-map/src/events.js +108 -0
- package/vendor/dag-map/src/graph-utils.js +185 -0
- package/vendor/dag-map/src/hasse.css +61 -0
- package/vendor/dag-map/src/index.js +55 -0
- package/vendor/dag-map/src/layout-flow.js +1066 -0
- package/vendor/dag-map/src/layout-hasse.js +485 -0
- package/vendor/dag-map/src/layout-metro.js +542 -0
- package/vendor/dag-map/src/occupancy.js +138 -0
- package/vendor/dag-map/src/render-flow-station.js +132 -0
- package/vendor/dag-map/src/render.js +360 -0
- package/vendor/dag-map/src/route-angular.js +137 -0
- package/vendor/dag-map/src/route-bezier.js +51 -0
- package/vendor/dag-map/src/route-metro.js +122 -0
- package/vendor/dag-map/src/themes.js +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 scs0209
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# turbometro
|
|
2
|
+
|
|
3
|
+
**Your monorepo as a subway — trains run when turbo does.**
|
|
4
|
+
|
|
5
|
+
`npx turbometro` turns a **pnpm + Turborepo** workspace into a self-contained **3D subway**: packages are stations, workspace deps are rails, and turbo tasks ride as trains.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
> **v0.1 honesty:** trains are **synthetic / replay** by default (not a live turbo attach). Live attach is on the roadmap.
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx turbometro
|
|
15
|
+
# writes ./metro.html — serve it over http (CDN Three.js)
|
|
16
|
+
npx --yes serve . -p 4173
|
|
17
|
+
# open http://localhost:4173/metro.html
|
|
18
|
+
# click a neon station → buildings assemble once → train rides
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Demo (this repo)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install
|
|
25
|
+
npm run build
|
|
26
|
+
node bin/turbometro.js --demo --out metro.html
|
|
27
|
+
npx --yes serve . -p 4173
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Against the fixture:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
node bin/turbometro.js --cwd fixtures/mini-mono --out metro.html
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## CLI
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
turbometro [--out metro.html] [--replay run.json] [--force] [--cwd dir]
|
|
40
|
+
turbometro --demo
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Flag | Meaning |
|
|
44
|
+
|------|---------|
|
|
45
|
+
| `--demo` | Built-in sample graph (no workspace required) |
|
|
46
|
+
| `--replay` | Use a timeline JSON instead of synthetic events |
|
|
47
|
+
| `--force` | Bypass the 150-package hard cap |
|
|
48
|
+
| `--out` | Output path (default `./metro.html`) |
|
|
49
|
+
|
|
50
|
+
## Interaction
|
|
51
|
+
|
|
52
|
+
- **First click** on a station: stop kit assembles piece-by-piece, then the train materializes and rides the dep path
|
|
53
|
+
- **Later clicks**: train keeps the mesh — only the path retargets (no flicker)
|
|
54
|
+
- Orbit: drag · zoom: scroll · **Clear train** removes the rider
|
|
55
|
+
|
|
56
|
+
## Requirements
|
|
57
|
+
|
|
58
|
+
- Node ≥ 20
|
|
59
|
+
- Target repo: `pnpm-workspace.yaml` + `turbo.json` or `turbo.jsonc`
|
|
60
|
+
- Dependency cycles: **warned** and cycle edges dropped (map still renders)
|
|
61
|
+
- Open the HTML via a local static server (`file://` can block ES modules / CDN)
|
|
62
|
+
|
|
63
|
+
## Replay JSON
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"events": [
|
|
68
|
+
{ "t": 0, "task": "build", "package": "@mini/web", "status": "running" },
|
|
69
|
+
{ "t": 800, "task": "build", "package": "@mini/web", "status": "pass" }
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Credits
|
|
75
|
+
|
|
76
|
+
Metro layout engine vendored from [23min/DAG-map](https://github.com/23min/DAG-map) (Apache-2.0). See `vendor/dag-map/NOTICE`.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
MIT — © scs0209
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { findWorkspaceRoot } from './find-root.js';
|
|
4
|
+
import { dropCycleEdges } from './graph.js';
|
|
5
|
+
import { parseWorkspace } from './parse-workspace.js';
|
|
6
|
+
import { parseTurbo } from './parse-turbo.js';
|
|
7
|
+
import { scaleGuard } from './scale.js';
|
|
8
|
+
import { buildSyntheticReplay, demoGraphAndTurbo, loadReplay, } from './replay.js';
|
|
9
|
+
import { renderMetroHtml } from './render-html.js';
|
|
10
|
+
function parseArgs(argv) {
|
|
11
|
+
const opts = {
|
|
12
|
+
cwd: process.cwd(),
|
|
13
|
+
out: path.join(process.cwd(), 'metro.html'),
|
|
14
|
+
demo: false,
|
|
15
|
+
replayPath: null,
|
|
16
|
+
force: false,
|
|
17
|
+
};
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const a = argv[i];
|
|
20
|
+
if (a === '--demo')
|
|
21
|
+
opts.demo = true;
|
|
22
|
+
else if (a === '--force')
|
|
23
|
+
opts.force = true;
|
|
24
|
+
else if (a === '--out')
|
|
25
|
+
opts.out = path.resolve(argv[++i] ?? 'metro.html');
|
|
26
|
+
else if (a === '--replay')
|
|
27
|
+
opts.replayPath = path.resolve(argv[++i] ?? '');
|
|
28
|
+
else if (a === '--cwd')
|
|
29
|
+
opts.cwd = path.resolve(argv[++i] ?? '.');
|
|
30
|
+
else if (a === '--help' || a === '-h') {
|
|
31
|
+
printHelp();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return opts;
|
|
36
|
+
}
|
|
37
|
+
function printHelp() {
|
|
38
|
+
console.log(`turbometro — monorepo subway map
|
|
39
|
+
|
|
40
|
+
Usage:
|
|
41
|
+
turbometro [--out metro.html] [--replay run.json] [--force]
|
|
42
|
+
turbometro --demo
|
|
43
|
+
|
|
44
|
+
Requires pnpm-workspace.yaml + turbo.json(c). Default trains are synthetic replay.
|
|
45
|
+
`);
|
|
46
|
+
}
|
|
47
|
+
async function main() {
|
|
48
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
49
|
+
let graph;
|
|
50
|
+
let turbo;
|
|
51
|
+
let title;
|
|
52
|
+
let disclaimer;
|
|
53
|
+
if (opts.demo) {
|
|
54
|
+
const demo = demoGraphAndTurbo();
|
|
55
|
+
graph = demo.graph;
|
|
56
|
+
turbo = demo.turbo;
|
|
57
|
+
title = 'turbometro demo';
|
|
58
|
+
disclaimer =
|
|
59
|
+
'Demo data. v0.1 trains are synthetic/replay — not a live turbo attach.';
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const root = findWorkspaceRoot(opts.cwd);
|
|
63
|
+
if (!root) {
|
|
64
|
+
console.error('turbometro: no pnpm-workspace.yaml found (searched upward from cwd).');
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
graph = parseWorkspace(root);
|
|
69
|
+
turbo = parseTurbo(root);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error(`turbometro: ${e.message}`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
title = path.basename(root);
|
|
76
|
+
disclaimer =
|
|
77
|
+
'v0.1 trains are synthetic/replay (default). Pass --replay run.json to override. Live turbo attach is roadmap.';
|
|
78
|
+
}
|
|
79
|
+
const scale = scaleGuard(graph.nodes.length, opts.force);
|
|
80
|
+
if (!scale.ok) {
|
|
81
|
+
console.error(`turbometro: ${scale.error}`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (scale.warn)
|
|
85
|
+
console.warn(`turbometro: ${scale.warn}`);
|
|
86
|
+
const { graph: acyclic, dropped } = dropCycleEdges(graph);
|
|
87
|
+
if (dropped.length) {
|
|
88
|
+
console.warn(`turbometro: dropped ${dropped.length} cycle edge(s): ${dropped.join(', ')}`);
|
|
89
|
+
}
|
|
90
|
+
graph = acyclic;
|
|
91
|
+
const replay = opts.replayPath
|
|
92
|
+
? loadReplay(opts.replayPath)
|
|
93
|
+
: buildSyntheticReplay(graph, turbo);
|
|
94
|
+
const html = await renderMetroHtml({
|
|
95
|
+
title,
|
|
96
|
+
graph,
|
|
97
|
+
turbo,
|
|
98
|
+
replay,
|
|
99
|
+
disclaimer,
|
|
100
|
+
});
|
|
101
|
+
fs.writeFileSync(opts.out, html, 'utf8');
|
|
102
|
+
console.log(`Wrote ${opts.out}`);
|
|
103
|
+
}
|
|
104
|
+
main().catch((err) => {
|
|
105
|
+
console.error(err);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Walk up from cwd until pnpm-workspace.yaml is found. */
|
|
4
|
+
export function findWorkspaceRoot(cwd) {
|
|
5
|
+
let dir = path.resolve(cwd);
|
|
6
|
+
for (;;) {
|
|
7
|
+
if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml')))
|
|
8
|
+
return dir;
|
|
9
|
+
const parent = path.dirname(dir);
|
|
10
|
+
if (parent === dir)
|
|
11
|
+
return null;
|
|
12
|
+
dir = parent;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Graph } from './types.js';
|
|
2
|
+
/** Find edges that participate in a cycle (DFS). */
|
|
3
|
+
export declare function findCycleEdgeKeys(graph: Graph): Set<string>;
|
|
4
|
+
/** Drop cycle edges; returns new graph + dropped keys. */
|
|
5
|
+
export declare function dropCycleEdges(graph: Graph): {
|
|
6
|
+
graph: Graph;
|
|
7
|
+
dropped: string[];
|
|
8
|
+
};
|
|
9
|
+
/** Pick a parent of `pkg` if any (for short train path). */
|
|
10
|
+
export declare function pickParent(graph: Graph, pkg: string): string | null;
|
|
11
|
+
export declare function shortestPathEndpoints(graph: Graph, pkg: string): {
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
} | null;
|
package/dist/graph.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Find edges that participate in a cycle (DFS). */
|
|
2
|
+
export function findCycleEdgeKeys(graph) {
|
|
3
|
+
const children = new Map();
|
|
4
|
+
for (const n of graph.nodes)
|
|
5
|
+
children.set(n.name, []);
|
|
6
|
+
for (const [from, to] of graph.edges) {
|
|
7
|
+
children.get(from)?.push(to);
|
|
8
|
+
}
|
|
9
|
+
const WHITE = 0, GRAY = 1, BLACK = 2;
|
|
10
|
+
const color = new Map();
|
|
11
|
+
for (const n of graph.nodes)
|
|
12
|
+
color.set(n.name, WHITE);
|
|
13
|
+
const cycleEdges = new Set();
|
|
14
|
+
function dfs(u, stack) {
|
|
15
|
+
color.set(u, GRAY);
|
|
16
|
+
stack.push(u);
|
|
17
|
+
for (const v of children.get(u) ?? []) {
|
|
18
|
+
const c = color.get(v) ?? WHITE;
|
|
19
|
+
if (c === GRAY) {
|
|
20
|
+
// edge u→v closes a cycle; mark all edges on the cycle path
|
|
21
|
+
const idx = stack.indexOf(v);
|
|
22
|
+
const cycle = stack.slice(idx);
|
|
23
|
+
for (let i = 0; i < cycle.length; i++) {
|
|
24
|
+
const a = cycle[i];
|
|
25
|
+
const b = cycle[(i + 1) % cycle.length];
|
|
26
|
+
cycleEdges.add(`${a}->${b}`);
|
|
27
|
+
}
|
|
28
|
+
cycleEdges.add(`${u}->${v}`);
|
|
29
|
+
}
|
|
30
|
+
else if (c === WHITE) {
|
|
31
|
+
dfs(v, stack);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
stack.pop();
|
|
35
|
+
color.set(u, BLACK);
|
|
36
|
+
}
|
|
37
|
+
for (const n of graph.nodes) {
|
|
38
|
+
if (color.get(n.name) === WHITE)
|
|
39
|
+
dfs(n.name, []);
|
|
40
|
+
}
|
|
41
|
+
return cycleEdges;
|
|
42
|
+
}
|
|
43
|
+
/** Drop cycle edges; returns new graph + dropped keys. */
|
|
44
|
+
export function dropCycleEdges(graph) {
|
|
45
|
+
const bad = findCycleEdgeKeys(graph);
|
|
46
|
+
if (bad.size === 0)
|
|
47
|
+
return { graph, dropped: [] };
|
|
48
|
+
const edges = graph.edges.filter(([a, b]) => !bad.has(`${a}->${b}`));
|
|
49
|
+
return {
|
|
50
|
+
graph: { nodes: graph.nodes, edges },
|
|
51
|
+
dropped: [...bad],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Pick a parent of `pkg` if any (for short train path). */
|
|
55
|
+
export function pickParent(graph, pkg) {
|
|
56
|
+
// edges are depender → dependency; train rides from dependency toward depender
|
|
57
|
+
// so "parent" along the ride is a dependency of pkg... wait:
|
|
58
|
+
// Design: short dep path ride into the package that has the task.
|
|
59
|
+
// Event is on package P. Ride along an edge into P.
|
|
60
|
+
// Incoming: someone depends on P? Or P depends on someone?
|
|
61
|
+
// D6: ride short dep path then stop at event package.
|
|
62
|
+
// Heuristic: from a workspace dependency of P (upstream) → P.
|
|
63
|
+
// Our edges are [depender, dependency] i.e. app → ui.
|
|
64
|
+
// So path app→ui means app depends on ui. Train for task on `app` should come from `ui` toward `app`.
|
|
65
|
+
// Edge direction in layout: we passed [app, ui]. For train on app, reverse: ui → app.
|
|
66
|
+
const deps = graph.edges.filter(([from]) => from === pkg).map(([, to]) => to);
|
|
67
|
+
return deps[0] ?? null;
|
|
68
|
+
}
|
|
69
|
+
export function shortestPathEndpoints(graph, pkg) {
|
|
70
|
+
const upstream = pickParent(graph, pkg);
|
|
71
|
+
if (!upstream)
|
|
72
|
+
return null;
|
|
73
|
+
return { from: upstream, to: pkg };
|
|
74
|
+
}
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace graph → dag-map input
|
|
3
|
+
*
|
|
4
|
+
* Mapping rules (v0.1):
|
|
5
|
+
* - package name → node.id / label
|
|
6
|
+
* - kind (apps|packages|other) → node.cls (theme class colors)
|
|
7
|
+
* - edge [depender, dependency] kept as dag-map edge [from, to]
|
|
8
|
+
* - routes: auto-discovered by layoutMetro (greedy longest-path)
|
|
9
|
+
*/
|
|
10
|
+
import type { Graph } from './types.js';
|
|
11
|
+
export type DagMapInput = {
|
|
12
|
+
nodes: Array<{
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
cls: string;
|
|
16
|
+
}>;
|
|
17
|
+
edges: Array<[string, string]>;
|
|
18
|
+
};
|
|
19
|
+
export declare function toDagMapInput(graph: Graph): DagMapInput;
|
package/dist/layout.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const CLS = {
|
|
2
|
+
apps: 'pure',
|
|
3
|
+
packages: 'recordable',
|
|
4
|
+
other: 'side_effecting',
|
|
5
|
+
};
|
|
6
|
+
export function toDagMapInput(graph) {
|
|
7
|
+
return {
|
|
8
|
+
nodes: graph.nodes.map((n) => ({
|
|
9
|
+
id: n.name,
|
|
10
|
+
label: n.name,
|
|
11
|
+
cls: CLS[n.kind] ?? 'pure',
|
|
12
|
+
})),
|
|
13
|
+
edges: graph.edges.map(([a, b]) => [a, b]),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TurboTasks } from './types.js';
|
|
2
|
+
/** Strip // and /* *\/ comments for turbo.jsonc. */
|
|
3
|
+
export declare function stripJsonc(text: string): string;
|
|
4
|
+
export declare function findTurboConfigPath(root: string): string | null;
|
|
5
|
+
export declare function parseTurbo(root: string): TurboTasks;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Strip // and /* *\/ comments for turbo.jsonc. */
|
|
4
|
+
export function stripJsonc(text) {
|
|
5
|
+
return text
|
|
6
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
7
|
+
.replace(/^\s*\/\/.*$/gm, '');
|
|
8
|
+
}
|
|
9
|
+
export function findTurboConfigPath(root) {
|
|
10
|
+
for (const name of ['turbo.json', 'turbo.jsonc']) {
|
|
11
|
+
const p = path.join(root, name);
|
|
12
|
+
if (fs.existsSync(p))
|
|
13
|
+
return p;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
export function parseTurbo(root) {
|
|
18
|
+
const cfgPath = findTurboConfigPath(root);
|
|
19
|
+
if (!cfgPath) {
|
|
20
|
+
throw new Error(`Missing turbo.json or turbo.jsonc in ${root}. turbometro v0.1 requires Turborepo.`);
|
|
21
|
+
}
|
|
22
|
+
const raw = stripJsonc(fs.readFileSync(cfgPath, 'utf8'));
|
|
23
|
+
const json = JSON.parse(raw);
|
|
24
|
+
const tasks = json.tasks ?? json.pipeline;
|
|
25
|
+
if (!tasks || Object.keys(tasks).length === 0) {
|
|
26
|
+
throw new Error(`No tasks/pipeline found in ${cfgPath}`);
|
|
27
|
+
}
|
|
28
|
+
return tasks;
|
|
29
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
function expandGlob(root, pattern) {
|
|
4
|
+
// Support "apps/*" and "packages/*" style only (v0.1).
|
|
5
|
+
if (!pattern.endsWith('/*')) {
|
|
6
|
+
const abs = path.join(root, pattern);
|
|
7
|
+
return fs.existsSync(abs) ? [abs] : [];
|
|
8
|
+
}
|
|
9
|
+
const base = pattern.slice(0, -2);
|
|
10
|
+
const absBase = path.join(root, base);
|
|
11
|
+
if (!fs.existsSync(absBase))
|
|
12
|
+
return [];
|
|
13
|
+
return fs
|
|
14
|
+
.readdirSync(absBase, { withFileTypes: true })
|
|
15
|
+
.filter((d) => d.isDirectory())
|
|
16
|
+
.map((d) => path.join(absBase, d.name));
|
|
17
|
+
}
|
|
18
|
+
/** Minimal pnpm-workspace.yaml packages: list parser (no full YAML dep). */
|
|
19
|
+
export function parseWorkspacePackagesList(yamlText) {
|
|
20
|
+
const lines = yamlText.split(/\r?\n/);
|
|
21
|
+
const pkgs = [];
|
|
22
|
+
let inPackages = false;
|
|
23
|
+
for (const raw of lines) {
|
|
24
|
+
const line = raw.replace(/#.*$/, '');
|
|
25
|
+
if (/^\s*packages\s*:/.test(line)) {
|
|
26
|
+
inPackages = true;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (inPackages) {
|
|
30
|
+
if (/^\S/.test(line) && !/^\s*-\s*/.test(line))
|
|
31
|
+
break;
|
|
32
|
+
const m = line.match(/^\s*-\s*['"]?([^'"]+?)['"]?\s*$/);
|
|
33
|
+
if (m)
|
|
34
|
+
pkgs.push(m[1]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return pkgs;
|
|
38
|
+
}
|
|
39
|
+
function kindFromDir(root, dir) {
|
|
40
|
+
const rel = path.relative(root, dir).split(path.sep)[0] || 'other';
|
|
41
|
+
if (rel === 'apps')
|
|
42
|
+
return 'apps';
|
|
43
|
+
if (rel === 'packages')
|
|
44
|
+
return 'packages';
|
|
45
|
+
return 'other';
|
|
46
|
+
}
|
|
47
|
+
function isWorkspaceDep(spec, workspaceNames) {
|
|
48
|
+
if (spec.startsWith('workspace:'))
|
|
49
|
+
return true;
|
|
50
|
+
return workspaceNames.has(spec);
|
|
51
|
+
}
|
|
52
|
+
export function parseWorkspace(root) {
|
|
53
|
+
const wsPath = path.join(root, 'pnpm-workspace.yaml');
|
|
54
|
+
if (!fs.existsSync(wsPath)) {
|
|
55
|
+
throw new Error(`Missing pnpm-workspace.yaml in ${root}`);
|
|
56
|
+
}
|
|
57
|
+
const patterns = parseWorkspacePackagesList(fs.readFileSync(wsPath, 'utf8'));
|
|
58
|
+
if (patterns.length === 0) {
|
|
59
|
+
throw new Error('pnpm-workspace.yaml has no packages entries');
|
|
60
|
+
}
|
|
61
|
+
const dirs = patterns.flatMap((p) => expandGlob(root, p));
|
|
62
|
+
const nodes = [];
|
|
63
|
+
for (const dir of dirs) {
|
|
64
|
+
const pkgPath = path.join(dir, 'package.json');
|
|
65
|
+
if (!fs.existsSync(pkgPath))
|
|
66
|
+
continue;
|
|
67
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
68
|
+
if (!pkg.name)
|
|
69
|
+
continue;
|
|
70
|
+
nodes.push({
|
|
71
|
+
name: pkg.name,
|
|
72
|
+
dir,
|
|
73
|
+
kind: kindFromDir(root, dir),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (nodes.length === 0) {
|
|
77
|
+
throw new Error('No workspace packages found');
|
|
78
|
+
}
|
|
79
|
+
const names = new Set(nodes.map((n) => n.name));
|
|
80
|
+
const edges = [];
|
|
81
|
+
const edgeSet = new Set();
|
|
82
|
+
for (const node of nodes) {
|
|
83
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(node.dir, 'package.json'), 'utf8'));
|
|
84
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
85
|
+
for (const [depName, spec] of Object.entries(deps)) {
|
|
86
|
+
if (!names.has(depName))
|
|
87
|
+
continue;
|
|
88
|
+
if (!isWorkspaceDep(spec, names))
|
|
89
|
+
continue;
|
|
90
|
+
// dag-map expects edges [from, to] as parent→child along flow;
|
|
91
|
+
// we use dependency direction: depender → dependency (train rides toward work).
|
|
92
|
+
const key = `${node.name}->${depName}`;
|
|
93
|
+
if (edgeSet.has(key))
|
|
94
|
+
continue;
|
|
95
|
+
edgeSet.add(key);
|
|
96
|
+
edges.push([node.name, depName]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return { nodes, edges };
|
|
100
|
+
}
|