Skip to content

Commit ec7d3d2

Browse files
committed
chore: add todo
1 parent 25b00de commit ec7d3d2

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

packages/core/src/lib/plugin-loader.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PluginLoadError, PluginNotFoundError } from './errors';
33
import { GeneratorRegistry } from './registry';
44
import { isGeneratorPlugin } from './type-guards';
55
import { logger } from '@nx/devkit';
6-
import { installPackages, detectCi } from './auto-installer';
6+
import { detectCi, installPackages } from './auto-installer';
77

88
const BUILTIN_PLUGIN_MAP: Record<string, string> = {
99
'openapi-tools': '@nx-plugin-openapi/plugin-openapi',
@@ -18,7 +18,7 @@ const cache = new Map<string, GeneratorPlugin>();
1818
function shouldTryAutoInstall(error: unknown, packageName: string): boolean {
1919
const msg = String(error);
2020
const code = (error as Record<string, unknown>)?.['code'];
21-
21+
2222
return (
2323
// Only for module not found errors
2424
(code === 'ERR_MODULE_NOT_FOUND' || /Cannot find module/.test(msg)) &&
@@ -108,6 +108,8 @@ export async function loadPlugin(
108108
pkg === '@nx-plugin-openapi/plugin-hey-openapi'
109109
) {
110110
const pkgName = pkg.split('/').pop() ?? ''; // e.g., 'plugin-openapi' or 'plugin-hey-openapi'
111+
// TODO remove fallback paths as this is no scenario for published packages.
112+
// for local development we should use another strategy
111113
const fallbackPaths = [
112114
`${root}/dist/packages/${pkgName}/src/index.js`,
113115
`${root}/packages/${pkgName}/src/index.js`,
@@ -141,7 +143,7 @@ export async function loadPlugin(
141143
try {
142144
installPackages([pkg], { dev: true });
143145
logger.info(`Successfully installed ${pkg}, retrying import...`);
144-
146+
145147
// Retry the import after installation
146148
// The module should now be available after installation
147149
const retryMod = (await import(pkg)) as {
@@ -158,13 +160,19 @@ export async function loadPlugin(
158160
logger.debug(`Found plugin as default export after installation`);
159161
candidate = retryMod.default;
160162
} else if (typeof retryMod.createPlugin === 'function') {
161-
logger.debug(`Found createPlugin factory function after installation`);
163+
logger.debug(
164+
`Found createPlugin factory function after installation`
165+
);
162166
candidate = (retryMod.createPlugin as () => unknown)();
163167
} else if (isGeneratorPlugin(retryMod.plugin)) {
164-
logger.debug(`Found plugin as named export 'plugin' after installation`);
168+
logger.debug(
169+
`Found plugin as named export 'plugin' after installation`
170+
);
165171
candidate = retryMod.plugin;
166172
} else if (isGeneratorPlugin(retryMod.Plugin)) {
167-
logger.debug(`Found plugin as named export 'Plugin' after installation`);
173+
logger.debug(
174+
`Found plugin as named export 'Plugin' after installation`
175+
);
168176
candidate = retryMod.Plugin;
169177
}
170178

@@ -182,7 +190,9 @@ export async function loadPlugin(
182190
);
183191
}
184192

185-
logger.info(`Successfully loaded plugin after auto-installation: ${name}`);
193+
logger.info(
194+
`Successfully loaded plugin after auto-installation: ${name}`
195+
);
186196
cache.set(name, candidate);
187197
return candidate;
188198
} catch (installError) {

0 commit comments

Comments
 (0)