Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/create-cli/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

/**
* This file serves as the CLI entry point.
*
* We use a separate bin file (instead of pointing directly to src/index.js)
* because TypeScript build processes don't preserve file permissions.
* By tracking this file in git with executable permissions (+x), we ensure
* the CLI remains executable after npm publish without needing post-install scripts.
*/
import '../src/index.js';
2 changes: 1 addition & 1 deletion packages/create-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@code-pushup/create-cli",
"version": "0.119.0",
"license": "MIT",
"bin": "index.js",
"bin": "./bin/index.js",
Comment thread
matejchalk marked this conversation as resolved.
Outdated
"homepage": "https://github.com/code-pushup/cli/tree/main/packages/create-cli#readme",
"bugs": {
"url": "https://github.com/code-pushup/cli/issues?q=is%3Aissue%20state%3Aopen%20type%3ABug%20label%3A\"🧩%20create-cli\""
Expand Down
6 changes: 5 additions & 1 deletion packages/create-cli/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"sourceRoot": "packages/create-cli/src",
"projectType": "library",
"targets": {
"build": {},
"build": {
"options": {
"assets": ["{projectRoot}/*.md", "{projectRoot}/bin/*"]
}
},
Comment thread
matejchalk marked this conversation as resolved.
Outdated
"lint": {},

"unit-test": {},
Expand Down
29 changes: 26 additions & 3 deletions packages/create-cli/src/lib/setup/monorepo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { select } from '@inquirer/prompts';
import { createRequire } from 'node:module';
import path from 'node:path';
import {
MONOREPO_TOOL_DETECTORS,
Expand All @@ -8,9 +9,9 @@ import {
hasScript,
listPackages,
listWorkspaces,
loadNxProjectGraph,
logger,
readPnpmWorkspacePatterns,
stringifyError,
toUnixPath,
} from '@code-pushup/utils';
import type {
Expand Down Expand Up @@ -83,7 +84,15 @@ export async function listProjects(
}

async function listNxProjects(cwd: string): Promise<WizardProject[]> {
const graph = await loadNxProjectGraph();
const require = createRequire(path.join(cwd, 'package.json'));
const { readCachedProjectGraph, createProjectGraphAsync } =
require('@nx/devkit') as typeof import('@nx/devkit');

const graph = await loadProjectGraph(
readCachedProjectGraph,
createProjectGraphAsync,
);

return Object.values(graph.nodes).map(({ name, data }) => ({
name,
directory: path.join(cwd, data.root),
Expand Down Expand Up @@ -133,7 +142,7 @@ async function addNxTarget(
return false;
}
const config = JSON.parse(raw);
if (config.targets[TASK_NAME] != null) {
if (config.targets?.[TASK_NAME] != null) {
return true;
}
const updated = {
Expand Down Expand Up @@ -180,3 +189,17 @@ function toProject(cwd: string, pkg: WorkspacePackage): WizardProject {
relativeDir: toUnixPath(path.relative(cwd, pkg.directory)),
};
}

async function loadProjectGraph(
readCached: typeof import('@nx/devkit').readCachedProjectGraph,
createAsync: typeof import('@nx/devkit').createProjectGraphAsync,
) {
try {
return readCached();
} catch (error) {
logger.warn(
`Could not read cached project graph, falling back to async creation.\n${stringifyError(error)}`,
);
return createAsync({ exitOnError: false });
}
}
Loading