From 2a59c124c199eac6e7515a526248e4ddd8512ddb Mon Sep 17 00:00:00 2001 From: pieh Date: Thu, 19 Sep 2024 12:12:56 +0200 Subject: [PATCH] fix: honor forced remix and hydrogen framework and allow detecting when config file is missing --- .../build-info/src/frameworks/hydrogen.ts | 6 +-- .../build-info/src/frameworks/remix.test.ts | 54 ++++++++----------- packages/build-info/src/frameworks/remix.ts | 6 +-- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/packages/build-info/src/frameworks/hydrogen.ts b/packages/build-info/src/frameworks/hydrogen.ts index bb6b0996e9..96bcf377d9 100644 --- a/packages/build-info/src/frameworks/hydrogen.ts +++ b/packages/build-info/src/frameworks/hydrogen.ts @@ -44,12 +44,12 @@ export class Hydrogen extends BaseFramework implements Framework { async detect(): Promise { await super.detect() - if (this.detected?.configName) { - if (VITE_CONFIG_FILES.includes(this.detected.configName)) { + if (this.detected) { + if (this.detected.configName && VITE_CONFIG_FILES.includes(this.detected.configName)) { this.dev = VITE_DEV this.build = VITE_BUILD return this as DetectedFramework - } else if (CLASSIC_COMPILER_CONFIG_FILES.includes(this.detected.configName)) { + } else { this.dev = CLASSIC_COMPILER_DEV this.build = CLASSIC_COMPILER_BUILD return this as DetectedFramework diff --git a/packages/build-info/src/frameworks/remix.test.ts b/packages/build-info/src/frameworks/remix.test.ts index 4ee96c15bf..ef75d2d5af 100644 --- a/packages/build-info/src/frameworks/remix.test.ts +++ b/packages/build-info/src/frameworks/remix.test.ts @@ -234,6 +234,28 @@ beforeEach((ctx) => { }), }, ] as const, + [ + 'with no config file', + { + 'package.json': JSON.stringify({ + scripts: { + build: 'remix build', + dev: 'remix dev', + start: 'netlify serve', + typecheck: 'tsc', + }, + dependencies: { + '@remix-run/netlify-edge': '1.7.4', + remix: '1.7.4', + react: '18.2.0', + 'react-dom': '18.2.0', + }, + devDependencies: { + '@netlify/functions': '^1.0.0', + }, + }), + }, + ] as const, ].forEach(([description, files]) => test(`detects a Remix Classic Compiler site ${description}`, async ({ fs }) => { const cwd = mockFileSystem(files) @@ -249,35 +271,3 @@ beforeEach((ctx) => { expect(detected?.[0]?.dev?.port).toBeUndefined() }), ) - -test('does not detect an invalid Remix site with no config file', async ({ fs }) => { - const cwd = mockFileSystem({ - 'package.json': JSON.stringify({ - scripts: { - build: 'remix vite:build', - dev: 'remix vite:dev', - start: 'remix-serve ./build/server/index.js', - }, - dependencies: { - '@netlify/remix-runtime': '^2.3.0', - '@remix-run/node': '^2.9.2', - '@remix-run/react': '^2.9.2', - '@remix-run/serve': '^2.9.2', - react: '^18.2.0', - 'react-dom': '^18.2.0', - }, - devDependencies: { - '@netlify/remix-edge-adapter': '^3.3.0', - '@remix-run/dev': '^2.9.2', - '@types/react': '^18.2.20', - '@types/react-dom': '^18.2.7', - vite: '^5.0.0', - 'vite-tsconfig-paths': '^4.2.1', - }, - }), - }) - const detected = await new Project(fs, cwd).detectFrameworks() - - const detectedFrameworks = (detected ?? []).map((framework) => framework.id) - expect(detectedFrameworks).not.toContain('remix') -}) diff --git a/packages/build-info/src/frameworks/remix.ts b/packages/build-info/src/frameworks/remix.ts index 5c14923a22..de4471c99d 100644 --- a/packages/build-info/src/frameworks/remix.ts +++ b/packages/build-info/src/frameworks/remix.ts @@ -55,12 +55,12 @@ export class Remix extends BaseFramework implements Framework { async detect(): Promise { await super.detect() - if (this.detected?.configName) { - if (VITE_CONFIG_FILES.includes(this.detected.configName)) { + if (this.detected) { + if (this.detected.configName && VITE_CONFIG_FILES.includes(this.detected.configName)) { this.dev = VITE_DEV this.build = VITE_BUILD return this as DetectedFramework - } else if (CLASSIC_COMPILER_CONFIG_FILES.includes(this.detected.configName)) { + } else { this.dev = CLASSIC_COMPILER_DEV this.build = CLASSIC_COMPILER_BUILD return this as DetectedFramework