Skip to content

Commit ff98c24

Browse files
committed
chore(plugin): add logging for package.json reading
1 parent 189f440 commit ff98c24

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

packages/nx/src/config/schema-utils.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function getImplementationFactory<T>(
2121
const [implementationModulePath, implementationExportName] =
2222
implementation.split('#');
2323
return () => {
24-
console.log(`Resolving implementation: ${implementation} from ${directory}`);
24+
console.log(
25+
`Resolving implementation: ${implementation} from ${directory}`
26+
);
2527
const modulePath = resolveImplementation(
2628
implementationModulePath,
2729
directory,
@@ -33,10 +35,10 @@ export function getImplementationFactory<T>(
3335
registerPluginTSTranspiler();
3436
}
3537
try {
36-
const module = require(modulePath);
37-
return implementationExportName
38-
? module[implementationExportName]
39-
: module.default ?? module;
38+
const module = require(modulePath);
39+
return implementationExportName
40+
? module[implementationExportName]
41+
: module.default ?? module;
4042
} catch (e) {
4143
console.error(`Failed to require implementation at ${modulePath}:`, e);
4244
throw new Error(
@@ -58,8 +60,9 @@ export function resolveImplementation(
5860
packageName: string,
5961
projects: Record<string, ProjectConfiguration>
6062
): string {
61-
62-
console.log(`Resolving implementation: ${implementationModulePath} from ${directory}`);
63+
console.log(
64+
`Resolving implementation: ${implementationModulePath} from ${directory}`
65+
);
6366

6467
const validImplementations = ['', '.js', '.ts'].map(
6568
(x) => implementationModulePath + x
@@ -96,16 +99,19 @@ export function resolveImplementation(
9699
});
97100
console.log(`Resolved via require.resolve: ${resolved}`);
98101
return resolved;
99-
} catch(e) {
100-
console.error(`Failed to resolve "${maybeImplementation}" from "${directory}":`, e);
102+
} catch (e) {
103+
console.error(
104+
`Failed to resolve "${maybeImplementation}" from "${directory}":`,
105+
e
106+
);
101107
// If it fails, we continue to the next valid implementation
102108
// This is useful for cases where the implementation might be in a different format
103109
// or if the file is not found in the expected location.
104110
continue;
105111
}
106112
}
107113

108-
throw new Error(
114+
throw new Error(
109115
`Could not resolve "${implementationModulePath}" from "${directory}".`
110116
);
111117
}
@@ -148,18 +154,22 @@ function tryResolveFromSource(
148154
packageName: string,
149155
projects: Record<string, ProjectConfiguration>
150156
): string | null {
151-
console.log(`Trying to resolve from source: ${path} in ${directory} for package: ${packageName}`);
157+
console.log(
158+
`Trying to resolve from source: ${path} in ${directory} for package: ${packageName}`
159+
);
152160

153161
packageToProjectMap ??=
154162
getWorkspacePackagesMetadata(projects).packageToProjectMap;
155163
const localProject = packageToProjectMap[packageName];
156164
if (!localProject) {
157165
console.log(`No local project found for package: ${packageName}`);
158-
// it doesn't match any of the package names from the local projects
166+
// it doesn't match any of the package names from the local projects
159167
return null;
160168
}
161169

162-
console.log(`Found local project for package: ${packageName} at ${localProject.root}`);
170+
console.log(
171+
`Found local project for package: ${packageName} at ${localProject.root}`
172+
);
163173

164174
try {
165175
const fromExports = resolveExports(

packages/nx/src/project-graph/plugins/in-process-loader.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
pluginTranspilerIsRegistered,
2020
registerPluginTSTranspiler,
2121
} from './transpiler';
22+
import { workspaceRoot } from '@nx/devkit';
2223

2324
export function readPluginPackageJson(
2425
pluginName: string,
@@ -28,20 +29,33 @@ export function readPluginPackageJson(
2829
path: string;
2930
json: PackageJson;
3031
} {
32+
console.log(
33+
`Reading plugin package.json for: ${pluginName} from paths: ${paths} at root: ${workspaceRoot}`
34+
);
3135
try {
3236
const result = readModulePackageJsonWithoutFallbacks(pluginName, paths);
37+
console.log(
38+
`Found package.json via readModulePackageJsonWithoutFallbacks at: ${result.path}`
39+
);
3340
return {
3441
json: result.packageJson,
3542
path: result.path,
3643
};
3744
} catch (e) {
45+
console.log(
46+
`readModulePackageJsonWithoutFallbacks failed for ${pluginName}:`,
47+
e.message
48+
);
3849
if (e.code === 'MODULE_NOT_FOUND') {
3950
const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
4051
if (localPluginPath) {
4152
const localPluginPackageJson = path.join(
4253
localPluginPath.path,
4354
'package.json'
4455
);
56+
console.log(
57+
`Falling back to local plugin at: ${localPluginPackageJson}`
58+
);
4559
if (!pluginTranspilerIsRegistered()) {
4660
registerPluginTSTranspiler();
4761
}

packages/workspace/src/generators/preset/preset.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Preset } from '../utils/presets';
44
import { join } from 'path';
55

66
export async function presetGenerator(tree: Tree, options: Schema) {
7-
8-
console.log(`Running preset generator with preset: ${options.preset} and workspaces: ${options.workspaces}`);
9-
7+
console.log(
8+
`Running preset generator with preset: ${options.preset} and workspaces: ${options.workspaces}`
9+
);
10+
1011
try {
1112
const presetTask = await createPreset(tree, options);
1213
return async () => {
@@ -23,7 +24,7 @@ export default presetGenerator;
2324

2425
async function createPreset(tree: Tree, options: Schema) {
2526
console.log(`Creating preset: ${options.preset}`);
26-
27+
2728
console.log('reading nx.json');
2829
const nxJson = readNxJson(tree);
2930
const addPlugin =

0 commit comments

Comments
 (0)