From 0591f54313362d239ad3e65fad6642a2cf3ce55c Mon Sep 17 00:00:00 2001 From: logonoff Date: Thu, 5 Dec 2024 15:32:27 -0500 Subject: [PATCH] Revert "CONSOLE-3905: Throw warnings when `guessModuleFilePath` is needed" This reverts commit b066e5a219168a76594000f000537651b75b8dc0. --- .../src/codegen/active-plugins.ts | 54 +++++++------------ 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/frontend/packages/console-plugin-sdk/src/codegen/active-plugins.ts b/frontend/packages/console-plugin-sdk/src/codegen/active-plugins.ts index ee6f84ca158..db13bba6071 100644 --- a/frontend/packages/console-plugin-sdk/src/codegen/active-plugins.ts +++ b/frontend/packages/console-plugin-sdk/src/codegen/active-plugins.ts @@ -17,47 +17,23 @@ import { consolePkgScope, PluginPackage } from './plugin-resolver'; const getExtensionsFilePath = (pkg: PluginPackage) => path.resolve(pkg._path, extensionsFile); -export type ActivePluginsModuleData = { - /** Generated module source code. */ - code: string; - /** Diagnostics collected while generating module source code. */ - diagnostics: { errors: string[]; warnings: string[] }; - /** Absolute file paths representing webpack file dependencies of the generated module. */ - fileDependencies: string[]; -}; - /** * Guess the file path of the module (e.g., the extension, * any barrel/index file) based on the given base path. * * Returns the base path if no file is found. */ -const guessModuleFilePath = ( - basePath: string, - diagnostics: ActivePluginsModuleData['diagnostics'], -) => { +const guessModuleFilePath = (basePath: string) => { const extensions = ['.tsx', '.ts', '.jsx', '.js']; // Sometimes the module is an index file, but the exposed module path only specifies the directory. // In that case, we need an explicit check for the index file. const indexModulePaths = ['index.ts', 'index.js'].map((i) => path.resolve(basePath, i)); - for (const p of indexModulePaths) { - if (fs.existsSync(p)) { - diagnostics.warnings.push( - `The module ${basePath} refers to an index file ${p}. Index/barrel files are not recommended as they may cause unnecessary code to be loaded. Consider specifying the module file directly.`, - ); - return p; - } - } - - const pathsToCheck = [...extensions.map((ext) => `${basePath}${ext}`)]; + const pathsToCheck = [...indexModulePaths, ...extensions.map((ext) => `${basePath}${ext}`)]; for (const p of pathsToCheck) { if (fs.existsSync(p)) { - diagnostics.warnings.push( - `The module ${basePath} refers to a file ${p}, but a file extension was not specified.`, - ); return p; } } @@ -67,16 +43,24 @@ const guessModuleFilePath = ( return basePath; }; -const getExposedModuleFilePath = ( - pkg: PluginPackage, - moduleName: string, - diagnostics: ActivePluginsModuleData['diagnostics'], -) => { +const getExposedModuleFilePath = (pkg: PluginPackage, moduleName: string) => { const modulePath = path.resolve(pkg._path, pkg.consolePlugin.exposedModules[moduleName]); - return path.extname(modulePath) - ? modulePath // Path already contains a file extension (no extra guessing needed) - : guessModuleFilePath(modulePath, diagnostics); + // Check if there is a file extension (no extra guessing needed) + if (!path.extname(modulePath)) { + return guessModuleFilePath(modulePath); + } + + return modulePath; +}; + +export type ActivePluginsModuleData = { + /** Generated module source code. */ + code: string; + /** Diagnostics collected while generating module source code. */ + diagnostics: { errors: string[]; warnings: string[] }; + /** Absolute file paths representing webpack file dependencies of the generated module. */ + fileDependencies: string[]; }; /** @@ -243,7 +227,7 @@ export const getActivePluginsModuleData = ( fileDependencies.push(getExtensionsFilePath(pkg)); Object.keys(pkg.consolePlugin.exposedModules || {}).forEach((moduleName) => { - const moduleFilePath = getExposedModuleFilePath(pkg, moduleName, { errors, warnings }); + const moduleFilePath = getExposedModuleFilePath(pkg, moduleName); if (fs.existsSync(moduleFilePath) && fs.statSync(moduleFilePath).isFile()) { fileDependencies.push(moduleFilePath);