Refactor resolveFramework to use declarative .some() and .every() - #8262
Refactor resolveFramework to use declarative .some() and .every()#8262gonzaloriestra wants to merge 1 commit into
Conversation
Replace complex and buggy `.reduce()` operations with standard `.some()` and `.every()` array helper methods in `packages/cli-kit/src/public/node/framework.ts`. This simplifies the control flow, improves readability, resolves a non-accumulating reduce bug on `.some` detectors, and enables early exit short-circuiting. Also added tests to cover `some` framework detectors in `framework.test.ts`.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/framework.d.ts@@ -1,3 +1,41 @@
+interface FrameworkDetectionPattern {
+ /**
+ * @example A file path
+ * ```
+ * "package.json"
+ * ```
+ */
+ path: string;
+ /**
+ * @example A matcher
+ * ```
+ * "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"next\":\\s*\".+?\"[^}]*}"
+ * ```
+ */
+ matchContent?: string;
+}
+interface Framework {
+ /**
+ * Name of the framework
+ * @example "nextjs"
+ */
+ name: string;
+ /**
+ * Detectors used to find out the framework
+ */
+ detectors: {
+ /**
+ * Collection of detectors that must be matched for the framework
+ * to be detected.
+ */
+ every?: FrameworkDetectionPattern[];
+ /**
+ * Collection of detectors where one match triggers the framework
+ * to be detected.
+ */
+ some?: FrameworkDetectionPattern[];
+ };
+}
/**
* Tries to identify the using of a framework analyzing the existence and/or content of different files inside a
* specific directory.
@@ -5,4 +43,6 @@
* @param rootDirectory - Directory from which the files required for each framework are searched
* @returns The name of the framework used or 'unknown' otherwise
*/
-export declare function resolveFramework(rootDirectory: string): Promise<string>;
\ No newline at end of file
+export declare function resolveFramework(rootDirectory: string): Promise<string>;
+export declare const _frameworks: Framework[];
+export {};
\ No newline at end of file
|
Refactored resolveFramework in packages/cli-kit/src/public/node/framework.ts to use standard .some() and .every() array helper methods instead of .reduce(). This fixes a bug in the old reduce implementation where the accumulator was not correctly passed on the
somedetectors and enables early exit short-circuiting. Added unit tests for these behaviors in framework.test.ts.PR created automatically by Jules for task 23259390411241093 started by @gonzaloriestra