1- import type { Operation } from "effection" ;
2- import { until } from "effection" ;
1+ import { existsSync } from "node:fs" ;
32import { resolve } from "@std/path" ;
43import { parse as parseYaml } from "@std/yaml" ;
4+ import type { Operation } from "effection" ;
5+ import { until } from "effection" ;
56import z from "zod" ;
6- import { existsSync } from "node:fs" ;
77
8- import type { Workspaces } from "./types.ts" ;
9- import type { Package , Ref } from "../package/types.ts" ;
10- import { createDenoPackage , DenoJsonSchema } from "../package/deno.ts" ;
11- import { createNodePackage } from "../package/node.ts" ;
128import { useClone } from "../clones.ts" ;
9+ import { createNodePackage } from "../package/node.ts" ;
10+ import type { Package , Ref } from "../package/types.ts" ;
11+ import type { Workspaces } from "./types.ts" ;
1312
1413export type { Workspaces } from "./types.ts" ;
1514
@@ -20,21 +19,6 @@ const PnpmWorkspaceSchema = z.object({
2019 packages : z . array ( z . string ( ) ) ,
2120} ) ;
2221
23- /**
24- * Detect workspace type by checking for deno.json or pnpm-workspace.yaml.
25- */
26- function detectWorkspaceType (
27- rootPath : string ,
28- ) : "deno" | "node" | null {
29- if ( existsSync ( `${ rootPath } /deno.json` ) ) {
30- return "deno" ;
31- }
32- if ( existsSync ( `${ rootPath } /pnpm-workspace.yaml` ) ) {
33- return "node" ;
34- }
35- return null ;
36- }
37-
3822/**
3923 * Check if a path represents a hidden/internal package that should be excluded.
4024 * Hidden packages start with "." (e.g., ".internal")
@@ -88,19 +72,10 @@ function* expandPatterns(
8872 return dirs ;
8973}
9074
91- /**
92- * Get workspace patterns from a Deno monorepo (from deno.json workspace field).
93- */
94- function * getDenoPatterns ( rootPath : string ) : Operation < string [ ] > {
95- let content = yield * until ( Deno . readTextFile ( `${ rootPath } /deno.json` ) ) ;
96- let denoJson = DenoJsonSchema . parse ( JSON . parse ( content ) ) ;
97- return denoJson . workspace ?? [ ] ;
98- }
99-
10075/**
10176 * Get workspace patterns from a Node/PNPM monorepo.
10277 */
103- function * getNodePatterns ( rootPath : string ) : Operation < string [ ] > {
78+ function * getWorkspacePatterns ( rootPath : string ) : Operation < string [ ] > {
10479 let content = yield * until (
10580 Deno . readTextFile ( `${ rootPath } /pnpm-workspace.yaml` ) ,
10681 ) ;
@@ -111,27 +86,25 @@ function* getNodePatterns(rootPath: string): Operation<string[]> {
11186
11287/**
11388 * Create a Workspaces instance for a given repository.
89+ * Currently only supports PNPM monorepos.
11490 *
11591 * @param nameWithOwner - GitHub repo in "owner/repo" format
11692 */
11793export function * useWorkspaces ( nameWithOwner : string ) : Operation < Workspaces > {
11894 let rootPath = yield * useClone ( nameWithOwner ) ;
119- let type = detectWorkspaceType ( rootPath ) ;
12095
121- if ( ! type ) {
96+ if ( ! existsSync ( ` ${ rootPath } /pnpm-workspace.yaml` ) ) {
12297 throw new Error (
123- `Could not detect workspace type for ${ nameWithOwner } . ` +
124- `Expected deno.json or pnpm-workspace.yaml at root .` ,
98+ `Could not find pnpm- workspace.yaml for ${ nameWithOwner } . ` +
99+ `Only PNPM monorepos are currently supported .` ,
125100 ) ;
126101 }
127102
128103 let url = `https://github.com/${ nameWithOwner } ` ;
129104 let refName = "main" ;
130105
131- // Get workspace patterns based on type
132- let patterns = type === "deno"
133- ? yield * getDenoPatterns ( rootPath )
134- : yield * getNodePatterns ( rootPath ) ;
106+ // Get workspace patterns from pnpm-workspace.yaml
107+ let patterns = yield * getWorkspacePatterns ( rootPath ) ;
135108
136109 // Expand patterns to actual directories
137110 let workspaceDirs = yield * expandPatterns ( rootPath , patterns ) ;
@@ -143,13 +116,6 @@ export function* useWorkspaces(nameWithOwner: string): Operation<Workspaces> {
143116 url : `${ url } /tree/${ refName } /${ workspacePath } ` ,
144117 } ) ;
145118
146- // Create package factory based on type
147- let createPackage = type === "deno"
148- ? ( path : string , name : string , workspacePath : string , ref : Ref ) =>
149- createDenoPackage ( path , name , workspacePath , ref )
150- : ( path : string , name : string , workspacePath : string , ref : Ref ) =>
151- createNodePackage ( path , name , workspacePath , ref ) ;
152-
153119 // Build lookup caches lazily
154120 let packagesByWorkspace : Map < string , Package > | undefined ;
155121 let packagesByName : Map < string , Package > | undefined ;
@@ -165,7 +131,7 @@ export function* useWorkspaces(nameWithOwner: string): Operation<Workspaces> {
165131 let workspaceName = workspacePath . split ( "/" ) . pop ( ) ! ;
166132 let ref = createRef ( workspacePath ) ;
167133
168- let pkg = createPackage ( fullPath , workspaceName , workspacePath , ref ) ;
134+ let pkg = createNodePackage ( fullPath , workspaceName , workspacePath , ref ) ;
169135 packagesByWorkspace . set ( workspaceName , pkg ) ;
170136
171137 // Get package name for the name lookup
0 commit comments