-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add package-manager detector logic
- Loading branch information
Showing
18 changed files
with
378 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
import '../dist/main.mjs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Module } from '@nestjs/common' | ||
import { InitCommand } from '@/commands/init.command' | ||
import { PackageManagerModule } from '@/pkg-manager' | ||
|
||
@Module({ | ||
imports: [], | ||
imports: [PackageManagerModule], | ||
providers: [InitCommand] | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { AbstractPackageManager } from './managers/abstract.pkg-manager' | ||
export { PACKAGE_MANAGER } from './pkg-manager.consts' | ||
export { InjectPackageManager } from './pkg-manager.decorator' | ||
export { PackageManagerModule } from './pkg-manager.module' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { execa as $ } from 'execa' | ||
import type { WorkspaceProject } from '@/pkg-manager/pkg-manager.types' | ||
|
||
export abstract class AbstractPackageManager { | ||
constructor(private command: string) {} | ||
|
||
public abstract getWorkspaces(): Promise<WorkspaceProject[]> | ||
|
||
public async run(args: string[]) { | ||
const output = await $(this.command, args) | ||
|
||
return output.stdout | ||
} | ||
|
||
public get agent() { | ||
return this.command | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { scan } from '@neodx/fs' | ||
import { resolve } from 'node:path' | ||
import * as process from 'process' | ||
import { AbstractPackageManager } from '@/pkg-manager/managers/abstract.pkg-manager' | ||
import { PackageManager } from '@/pkg-manager/pkg-manager.consts' | ||
import type { WorkspaceProject } from '@/pkg-manager/pkg-manager.types' | ||
import type { PackageJson } from '@/shared/json' | ||
import { readJson } from '@/shared/json' | ||
|
||
// TODO: add yarn@berry support | ||
// TODO: split file structure to modules | ||
|
||
export class BunPackageManager extends AbstractPackageManager { | ||
constructor() { | ||
super(PackageManager.BUN) | ||
} | ||
|
||
public async getWorkspaces(): Promise<WorkspaceProject[]> { | ||
const packageJson = await readJson('package.json') | ||
|
||
if (!packageJson) return [] | ||
|
||
const rawWorkspaces = packageJson.workspaces | ||
|
||
const workspaces = Array.isArray(rawWorkspaces) | ||
? rawWorkspaces | ||
: rawWorkspaces!.packages | ||
|
||
const projectPatterns = await scan( | ||
process.cwd(), | ||
workspaces.map((match) => resolve(match, 'package.json')) | ||
) | ||
|
||
const bunWorkspaces = await Promise.all( | ||
projectPatterns.map(async (pattern) => { | ||
const scopedPkgJson = (await readJson(pattern)) as PackageJson | ||
|
||
const workspaceName = scopedPkgJson.name ?? null | ||
const workspaceDir = resolve(pattern, '..') | ||
|
||
return { | ||
name: workspaceName, | ||
location: workspaceDir | ||
} | ||
}) | ||
) | ||
|
||
return bunWorkspaces | ||
} | ||
} |
Oops, something went wrong.