Skip to content

Commit

Permalink
chore: use warnOnce method
Browse files Browse the repository at this point in the history
test: add unit test
  • Loading branch information
jacob-ebey committed Mar 1, 2023
1 parent f778550 commit 867c272
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverBuildTarget: "node-cjs",
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
Expand Down
10 changes: 8 additions & 2 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -69,7 +75,7 @@ describe("readConfig", () => {
},
},
"serverBuildPath": Any<String>,
"serverBuildTarget": undefined,
"serverBuildTarget": "node-cjs",
"serverBuildTargetEntryModule": "export * from \\"@remix-run/dev/server-build\\";",
"serverConditions": undefined,
"serverDependenciesToBundle": Array [],
Expand Down
7 changes: 4 additions & 3 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.`;

0 comments on commit 867c272

Please sign in to comment.