diff --git a/packages/remix-dev/__tests__/fixtures/stack/remix.config.js b/packages/remix-dev/__tests__/fixtures/stack/remix.config.js index adf2a0b5d3e..5bb0822e720 100644 --- a/packages/remix-dev/__tests__/fixtures/stack/remix.config.js +++ b/packages/remix-dev/__tests__/fixtures/stack/remix.config.js @@ -1,5 +1,6 @@ /** @type {import('@remix-run/dev').AppConfig} */ module.exports = { + serverBuildTarget: "node-cjs", ignoredRouteFiles: ["**/.*"], // appDirectory: "app", // assetsBuildDirectory: "public/build", diff --git a/packages/remix-dev/__tests__/readConfig-test.ts b/packages/remix-dev/__tests__/readConfig-test.ts index 1dced697bf7..b953178b363 100644 --- a/packages/remix-dev/__tests__/readConfig-test.ts +++ b/packages/remix-dev/__tests__/readConfig-test.ts @@ -1,17 +1,23 @@ import path from "path"; import type { RemixConfig } from "../config"; -import { readConfig } from "../config"; +import { serverBuildTargetWarning, readConfig } from "../config"; const remixRoot = path.resolve(__dirname, "./fixtures/stack"); describe("readConfig", () => { let config: RemixConfig; + let warnStub; beforeEach(async () => { + let consoleWarn = console.warn; + warnStub = jest.fn(); + console.warn = warnStub; config = await readConfig(remixRoot); + console.warn = consoleWarn; }); it("generates a config", async () => { + expect(warnStub).toHaveBeenCalledWith(serverBuildTargetWarning); expect(config).toMatchInlineSnapshot( { rootDirectory: expect.any(String), @@ -69,7 +75,7 @@ describe("readConfig", () => { }, }, "serverBuildPath": Any, - "serverBuildTarget": undefined, + "serverBuildTarget": "node-cjs", "serverBuildTargetEntryModule": "export * from \\"@remix-run/dev/server-build\\";", "serverConditions": undefined, "serverDependenciesToBundle": Array [], diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index b89239d1a12..4c6f161eb86 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -13,6 +13,7 @@ import { serverBuildVirtualModule } from "./compiler/virtualModules"; import { writeConfigDefaults } from "./compiler/utils/tsconfig/write-config-defaults"; import { flatRoutes } from "./config/flat-routes"; import { getPreferredPackageManager } from "./cli/getPreferredPackageManager"; +import { warnOnce } from "./compiler/warnings"; export interface RemixMdxConfig { rehypePlugins?: any[]; @@ -397,9 +398,7 @@ export async function readConfig( } if (appConfig.serverBuildTarget) { - console.warn( - `The "serverBuildTarget" config option is deprecated. Use a combination of "publicPath", "serverBuildPath", "serverConditions", "serverDependenciesToBundle", "serverMainFields", "serverMinify", "serverModuleFormat" and/or "serverPlatform" instead.` - ); + warnOnce(serverBuildTargetWarning, "v2_serverBuildTarget"); } let isCloudflareRuntime = ["cloudflare-pages", "cloudflare-workers"].includes( @@ -726,3 +725,5 @@ let listFormat = new Intl.ListFormat("en", { style: "long", type: "conjunction", }); + +export let serverBuildTargetWarning = `The "serverBuildTarget" config option is deprecated. Use a combination of "publicPath", "serverBuildPath", "serverConditions", "serverDependenciesToBundle", "serverMainFields", "serverMinify", "serverModuleFormat" and/or "serverPlatform" instead.`;