Fix CLI module discovery and create-app test mock

Resolve CLI module entry points relative to the target project root
rather than relying on bare module name resolution. This ensures modules
are found even when the CLI package is symlinked from a separate location,
such as in the E2E test workspace setup.

Also add the missing cli-module-* entries to the create-app tasks test
mock that were omitted in a previous commit.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-15 01:12:43 +01:00
parent f100c26c92
commit 935c646e89
3 changed files with 19 additions and 5 deletions
+2 -2
View File
@@ -24,8 +24,8 @@ import { discoverCliModules } from './wiring/discoverCliModules';
const discoveredModules = discoverCliModules();
if (discoveredModules.length > 0) {
for (const moduleName of discoveredModules) {
initializer.add(import(moduleName));
for (const resolvedPath of discoveredModules) {
initializer.add(import(resolvedPath));
}
} else {
// No CLI modules found in the project root; fall back to the built-in
@@ -23,8 +23,10 @@ import { resolve as resolvePath } from 'node:path';
* Scans the target project root's package.json for dependencies that are CLI
* modules (packages with `backstage.role === 'cli-module'`).
*
* Returns the names of discovered CLI module packages, or an empty array if
* none are found or the project root cannot be read.
* Returns the resolved entry point paths of discovered CLI module packages,
* or an empty array if none are found or the project root cannot be read.
* The paths are resolved relative to the project root to ensure they can be
* imported regardless of where the CLI code itself is located.
*/
export function discoverCliModules(): string[] {
const rootDir = targetPaths.rootDir;
@@ -54,7 +56,8 @@ export function discoverCliModules(): string[] {
});
const depPkg = JSON.parse(fs.readFileSync(depPkgPath, 'utf8'));
if (PackageRoles.getRoleFromPackage(depPkg) === 'cli-module') {
modules.push(depName);
const resolvedPath = require.resolve(depName, { paths: [rootDir] });
modules.push(resolvedPath);
}
} catch {
// Skip packages that can't be resolved or read