mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 21:07:46 +00:00
[remix] Improve hueristics for detecting Remix + Vite (#11256)
In particular, when both `remix.config` and `vite.config` files exist, run some additional checks to try to detect if the project is using the Vite plugin or not.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { build as buildVite } from './build-vite';
|
||||
import { build as buildLegacy } from './build-legacy';
|
||||
import { findConfig } from './utils';
|
||||
import { isVite } from './utils';
|
||||
import type { BuildV2 } from '@vercel/build-utils';
|
||||
|
||||
export const build: BuildV2 = opts => {
|
||||
const isLegacy = findConfig(opts.workPath, 'remix.config');
|
||||
return isLegacy ? buildLegacy(opts) : buildVite(opts);
|
||||
return isVite(opts.workPath) ? buildVite(opts) : buildLegacy(opts);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import semver from 'semver';
|
||||
import { existsSync, promises as fs } from 'fs';
|
||||
import { existsSync, readFileSync, promises as fs } from 'fs';
|
||||
import { basename, dirname, join, relative, resolve, sep } from 'path';
|
||||
import { pathToRegexp, Key } from 'path-to-regexp';
|
||||
import { debug, type PackageJson } from '@vercel/build-utils';
|
||||
@@ -420,3 +420,30 @@ export function logNftWarnings(warnings: Set<Error>, required?: string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isVite(dir: string): boolean {
|
||||
const viteConfig = findConfig(dir, 'vite.config', ['.js', '.ts']);
|
||||
if (!viteConfig) return false;
|
||||
|
||||
const remixConfig = findConfig(dir, 'remix.config');
|
||||
if (!remixConfig) return true;
|
||||
|
||||
// `remix.config` and `vite.config` exist, so check a couple other ways
|
||||
|
||||
// Is `vite:build` found in the `package.json` "build" script?
|
||||
const pkg: PackageJson = JSON.parse(
|
||||
readFileSync(join(dir, 'package.json'), 'utf8')
|
||||
);
|
||||
if (pkg.scripts?.build && /\bvite:build\b/.test(pkg.scripts.build)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Is `@remix-run/dev` package found in `vite.config`?
|
||||
const viteConfigContents = readFileSync(viteConfig, 'utf8');
|
||||
if (/['"]@remix-run\/dev['"]/.test(viteConfigContents)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If none of those conditions matched, then treat it as a legacy project and print a warning
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user