From a5402e10eec4ffc2b800d6452270c3733bf6f3d4 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Fri, 24 Oct 2025 23:49:13 -0500 Subject: [PATCH 1/2] fix(core): remove usage of node:path to join framework preset path --- code/core/src/common/utils/validate-config.test.ts | 6 ++++++ code/core/src/common/utils/validate-config.ts | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/code/core/src/common/utils/validate-config.test.ts b/code/core/src/common/utils/validate-config.test.ts index 891b5daa63fb..245bb1264055 100644 --- a/code/core/src/common/utils/validate-config.test.ts +++ b/code/core/src/common/utils/validate-config.test.ts @@ -25,6 +25,12 @@ describe('validateFrameworkName', () => { expect(() => validateFrameworkName('some-community-framework')).toThrow(); }); + it('should not throw if scoped framework is unknown (community) but can be resolved', () => { + // mock require.resolve to return a value + vi.spyOn(require, 'resolve').mockReturnValue('@some-community/framework'); + expect(() => validateFrameworkName('@some-community/framework')).not.toThrow(); + }); + it('should throw if framework is unknown and cannot be resolved', () => { // mock require.resolve to fail vi.spyOn(require, 'resolve').mockImplementation(() => { diff --git a/code/core/src/common/utils/validate-config.ts b/code/core/src/common/utils/validate-config.ts index cc47ca84dc2a..e8c3de208e73 100644 --- a/code/core/src/common/utils/validate-config.ts +++ b/code/core/src/common/utils/validate-config.ts @@ -1,5 +1,3 @@ -import { join } from 'node:path'; - import { CouldNotEvaluateFrameworkError, InvalidFrameworkNameError, @@ -35,7 +33,7 @@ export function validateFrameworkName( // If it's not a known framework, we need to validate that it's a valid package at least try { - resolveModulePath(join(frameworkName, 'preset'), { + resolveModulePath(`${frameworkName}/preset`, { extensions: ['.mjs', '.js', '.cjs'], conditions: ['node', 'import', 'require'], }); From c144ed055977f76d209d9d02c7a23ab353b9df14 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Mon, 27 Oct 2025 11:32:09 -0500 Subject: [PATCH 2/2] chore: fix unit tests --- .../src/common/utils/validate-config.test.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/code/core/src/common/utils/validate-config.test.ts b/code/core/src/common/utils/validate-config.test.ts index 245bb1264055..e478c2db0afc 100644 --- a/code/core/src/common/utils/validate-config.test.ts +++ b/code/core/src/common/utils/validate-config.test.ts @@ -1,7 +1,12 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; +import { resolveModulePath } from 'exsolve'; + import { validateFrameworkName } from './validate-config'; +// mock exsolve to spy +vi.mock('exsolve', { spy: true }); + describe('validateFrameworkName', () => { afterEach(() => { vi.resetAllMocks(); @@ -20,21 +25,20 @@ describe('validateFrameworkName', () => { }); it('should not throw if framework is unknown (community) but can be resolved', () => { - // mock require.resolve to return a value - vi.spyOn(require, 'resolve').mockReturnValue('some-community-framework'); - expect(() => validateFrameworkName('some-community-framework')).toThrow(); + vi.mocked(resolveModulePath).mockImplementation(() => {}); + + expect(() => validateFrameworkName('some-community-framework')).not.toThrow(); }); it('should not throw if scoped framework is unknown (community) but can be resolved', () => { - // mock require.resolve to return a value - vi.spyOn(require, 'resolve').mockReturnValue('@some-community/framework'); + vi.mocked(resolveModulePath).mockImplementation(() => {}); + expect(() => validateFrameworkName('@some-community/framework')).not.toThrow(); - }); + }); it('should throw if framework is unknown and cannot be resolved', () => { - // mock require.resolve to fail - vi.spyOn(require, 'resolve').mockImplementation(() => { - throw new Error('Cannot resolve'); + vi.mocked(resolveModulePath).mockImplementation(() => { + throw new Error('cannot resolve'); }); expect(() => validateFrameworkName('foo')).toThrow();