Skip to content

Commit a04d8fa

Browse files
committed
refactor: extract monorepo utils to shared pkg
1 parent bbf49e8 commit a04d8fa

21 files changed

+177
-82
lines changed

packages/ci/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"ansis": "^3.3.2",
3333
"glob": "^11.0.1",
3434
"simple-git": "^3.20.0",
35-
"yaml": "^2.5.1",
3635
"zod": "^4.2.1"
3736
},
3837
"files": [

packages/ci/src/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
export type { SourceFileIssue } from './lib/issues.js';
22
export type * from './lib/models.js';
3-
export {
4-
isMonorepoTool,
5-
MONOREPO_TOOLS,
6-
type MonorepoTool,
7-
} from './lib/monorepo/index.js';
83
export { runInCI } from './lib/run.js';
94
export { configPatternsSchema } from './lib/schemas.js';
105
export {

packages/ci/src/lib/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Format, PersistConfig, UploadConfig } from '@code-pushup/models';
2+
import type { MonorepoTool } from '@code-pushup/utils';
23
import type { SourceFileIssue } from './issues.js';
3-
import type { MonorepoTool } from './monorepo/index.js';
44

55
/**
66
* Customization options for {@link runInCI}

packages/ci/src/lib/monorepo/detect-tool.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/ci/src/lib/monorepo/handlers/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { MonorepoTool, MonorepoToolHandler } from '../tools.js';
1+
import type { MonorepoTool } from '@code-pushup/utils';
2+
import type { MonorepoToolHandler } from '../tools.js';
23
import { npmHandler } from './npm.js';
34
import { nxHandler } from './nx.js';
45
import { pnpmHandler } from './pnpm.js';

packages/ci/src/lib/monorepo/handlers/npm.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
import path from 'node:path';
2-
import { fileExists } from '@code-pushup/utils';
31
import {
2+
MONOREPO_TOOL_DETECTORS,
43
hasCodePushUpDependency,
54
hasScript,
6-
hasWorkspacesEnabled,
75
listWorkspaces,
8-
} from '../packages.js';
6+
} from '@code-pushup/utils';
97
import type { MonorepoToolHandler } from '../tools.js';
108

119
export const npmHandler: MonorepoToolHandler = {
1210
tool: 'npm',
1311

1412
async isConfigured(options) {
15-
return (
16-
(await fileExists(path.join(options.cwd, 'package-lock.json'))) &&
17-
(await hasWorkspacesEnabled(options.cwd))
18-
);
13+
return MONOREPO_TOOL_DETECTORS.npm(options.cwd);
1914
},
2015

2116
async listProjects(options) {

packages/ci/src/lib/monorepo/handlers/nx.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import path from 'node:path';
21
import {
2+
MONOREPO_TOOL_DETECTORS,
33
executeProcess,
4-
fileExists,
54
interpolate,
65
stringifyError,
76
toArray,
@@ -13,7 +12,7 @@ export const nxHandler: MonorepoToolHandler = {
1312

1413
async isConfigured(options) {
1514
return (
16-
(await fileExists(path.join(options.cwd, 'nx.json'))) &&
15+
(await MONOREPO_TOOL_DETECTORS.nx(options.cwd)) &&
1716
(
1817
await executeProcess({
1918
command: 'npx',

packages/ci/src/lib/monorepo/handlers/pnpm.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
import path from 'node:path';
2-
import * as YAML from 'yaml';
3-
import { fileExists, readTextFile } from '@code-pushup/utils';
41
import {
2+
MONOREPO_TOOL_DETECTORS,
53
hasCodePushUpDependency,
64
hasScript,
75
listPackages,
6+
readPnpmWorkspacePatterns,
87
readRootPackageJson,
9-
} from '../packages.js';
8+
} from '@code-pushup/utils';
109
import type { MonorepoToolHandler } from '../tools.js';
1110

12-
const WORKSPACE_FILE = 'pnpm-workspace.yaml';
13-
1411
export const pnpmHandler: MonorepoToolHandler = {
1512
tool: 'pnpm',
1613

1714
async isConfigured(options) {
18-
return (
19-
(await fileExists(path.join(options.cwd, WORKSPACE_FILE))) &&
20-
(await fileExists(path.join(options.cwd, 'package.json')))
21-
);
15+
return MONOREPO_TOOL_DETECTORS.pnpm(options.cwd);
2216
},
2317

2418
async listProjects(options) {
25-
const yaml = await readTextFile(path.join(options.cwd, WORKSPACE_FILE));
26-
const workspace = YAML.parse(yaml) as { packages?: string[] };
27-
const packages = await listPackages(options.cwd, workspace.packages);
19+
const patterns = await readPnpmWorkspacePatterns(options.cwd);
20+
const packages = await listPackages(options.cwd, patterns);
2821
const rootPackageJson = await readRootPackageJson(options.cwd);
2922
return packages
3023
.filter(

packages/ci/src/lib/monorepo/handlers/turbo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import path from 'node:path';
2-
import { fileExists, readJsonFile } from '@code-pushup/utils';
2+
import { MONOREPO_TOOL_DETECTORS, readJsonFile } from '@code-pushup/utils';
33
import type { MonorepoToolHandler } from '../tools.js';
44
import { npmHandler } from './npm.js';
55
import { pnpmHandler } from './pnpm.js';
@@ -17,7 +17,7 @@ export const turboHandler: MonorepoToolHandler = {
1717
async isConfigured(options) {
1818
const configPath = path.join(options.cwd, 'turbo.json');
1919
return (
20-
(await fileExists(configPath)) &&
20+
(await MONOREPO_TOOL_DETECTORS.turbo(options.cwd)) &&
2121
options.task in (await readJsonFile<TurboConfig>(configPath)).tasks
2222
);
2323
},

packages/ci/src/lib/monorepo/handlers/yarn.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
import path from 'node:path';
2-
import { executeProcess, fileExists } from '@code-pushup/utils';
31
import {
2+
MONOREPO_TOOL_DETECTORS,
3+
executeProcess,
44
hasCodePushUpDependency,
55
hasScript,
6-
hasWorkspacesEnabled,
76
listWorkspaces,
8-
} from '../packages.js';
7+
} from '@code-pushup/utils';
98
import type { MonorepoToolHandler } from '../tools.js';
109

1110
export const yarnHandler: MonorepoToolHandler = {
1211
tool: 'yarn',
1312

1413
async isConfigured(options) {
15-
return (
16-
(await fileExists(path.join(options.cwd, 'yarn.lock'))) &&
17-
(await hasWorkspacesEnabled(options.cwd))
18-
);
14+
return MONOREPO_TOOL_DETECTORS.yarn(options.cwd);
1915
},
2016

2117
async listProjects(options) {

0 commit comments

Comments
 (0)