Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default tseslint.config(
},
{
// in bin files, imports with side effects are allowed
files: ['**/bin/**/*.ts', '**/bin/**/*.js'],
files: ['**/bin/**/*.ts', '**/bin/**/*.js', '**/bin.js'],
rules: {
'import/no-unassigned-import': 'off',
},
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"outputPath": "{projectRoot}/dist",
"main": "{projectRoot}/src/index.ts",
"tsConfig": "{projectRoot}/tsconfig.lib.json",
"assets": ["{projectRoot}/*.md"]
"assets": ["{projectRoot}/*.md", "{projectRoot}/bin.js"]
}
},
"unit-test": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/index.js → packages/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
* 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';
import './src/index.js';
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"type": "module",
"bin": {
"code-pushup": "./bin/index.js"
"code-pushup": "./bin.js"
},
"engines": {
"node": ">=20"
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"sourceRoot": "packages/cli/src",
"projectType": "library",
"targets": {
"build": {
"options": {
"assets": ["{projectRoot}/*.md", "{projectRoot}/bin/*"]
}
},
"build": {},
"lint": {},
"unit-test": {},
"int-test": {},
Expand Down
11 changes: 11 additions & 0 deletions packages/create-cli/bin.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.js",
"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
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