Skip to content

Commit

Permalink
feat!: remove serverBuildTarget codepaths
Browse files Browse the repository at this point in the history
docs: update docs to reference removal of serverBuildTarget
  • Loading branch information
jacob-ebey committed Mar 2, 2023
1 parent 342dc60 commit fe5c936
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 94 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-wombats-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": major
---

Remove serverBuildTarget remix.config option.
14 changes: 1 addition & 13 deletions docs/file-conventions/remix-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,13 @@ to `"build/index.js"`.

## serverBuildTarget

<docs-warning>This option is deprecated and will be removed in the next major version release. Use a combination of [`publicPath`][public-path],
<docs-warning>This option has been removed in v2. Use a combination of [`publicPath`][public-path],
[`serverBuildPath`][server-build-path], [`serverConditions`][server-conditions],
[`serverDependenciesToBundle`][server-dependencies-to-bundle]
[`serverMainFields`][server-main-fields], [`serverMinify`][server-minify],
[`serverModuleFormat`][server-module-format] and/or
[`serverPlatform`][server-platform] instead.</docs-warning>

The target of the server build. Defaults to `"node-cjs"`.

The `serverBuildTarget` can be one of the following:

- [`"arc"`][arc]
- [`"cloudflare-pages"`][cloudflare-pages]
- [`"cloudflare-workers"`][cloudflare-workers]
- [`"deno"`][deno]
- [`"netlify"`][netlify]
- [`"node-cjs"`][node-cjs]
- [`"vercel"`][vercel]

**Migration Table:**

| serverBuildTarget | publicPath | serverBuildPath | serverConditions | serverMainFields | serverModuleFormat | serverPlatform | serverDependenciesToBundle | serverMinify |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverBuildTarget: "cloudflare-pages",
serverBuildPath: "functions/[[path]].js",
serverConditions: ["worker"],
serverMainFields: ["browser", "module", "main"],
serverModuleFormat: "esm",
serverPlatform: "neutral",
server: "./server.js",
devServerBroadcastDelay: 1000,
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// serverBuildPath: "functions/[[path]].js",
// publicPath: "/build/",
};
5 changes: 4 additions & 1 deletion packages/remix-dev/__tests__/fixtures/deno/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverBuildTarget: "deno",
serverConditions: ["deno", "worker"],
serverMainFields: ["browser", "module", "main"],
serverModuleFormat: "esm",
serverPlatform: "neutral",
server: "./server.ts",
/*
If live reload causes page to re-render without changes (live reload is too fast),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
serverBuildTarget: "node-cjs",
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
Expand Down
9 changes: 1 addition & 8 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import path from "path";

import type { RemixConfig } from "../config";
import { serverBuildTargetWarning, readConfig } from "../config";
import { 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 @@ -75,7 +69,6 @@ describe("readConfig", () => {
},
},
"serverBuildPath": Any<String>,
"serverBuildTarget": "node-cjs",
"serverBuildTargetEntryModule": "export * from \\"@remix-run/dev/server-build\\";",
"serverConditions": undefined,
"serverDependenciesToBundle": Array [],
Expand Down
70 changes: 1 addition & 69 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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 All @@ -24,15 +23,6 @@ export type RemixMdxConfigFunction = (
filename: string
) => Promise<RemixMdxConfig | undefined> | RemixMdxConfig | undefined;

export type ServerBuildTarget =
| "node-cjs"
| "arc"
| "netlify"
| "vercel"
| "cloudflare-pages"
| "cloudflare-workers"
| "deno";

export type ServerModuleFormat = "esm" | "cjs";
export type ServerPlatform = "node" | "neutral";

Expand Down Expand Up @@ -138,13 +128,6 @@ export interface AppConfig {
*/
serverBuildPath?: string;

/**
* The target of the server build. Defaults to "node-cjs".
*
* @deprecated Use a combination of `{@link AppConfig.publicPath}`, `{@link AppConfig.serverBuildPath}`, `{@link AppConfig.serverConditions}`, `{@link AppConfig.serverDependenciesToBundle}`, `{@link AppConfig.serverMainFields}`, `{@link AppConfig.serverMinify}`, `{@link AppConfig.serverModuleFormat}` and/or `{@link AppConfig.serverPlatform}` instead.
*/
serverBuildTarget?: ServerBuildTarget;

/**
* The order of conditions to use when resolving server dependencies'
* `exports` field in `package.json`.
Expand Down Expand Up @@ -281,12 +264,6 @@ export interface RemixConfig {
*/
serverBuildPath: string;

/**
* The target of the server build. Defaults to "node-cjs".
*
* @deprecated Use a combination of `{@link AppConfig.publicPath}`, `{@link AppConfig.serverBuildPath}`, `{@link AppConfig.serverConditions}`, `{@link AppConfig.serverDependenciesToBundle}`, `{@link AppConfig.serverMainFields}`, `{@link AppConfig.serverMinify}`, `{@link AppConfig.serverModuleFormat}` and/or `{@link AppConfig.serverPlatform}` instead. */
serverBuildTarget?: ServerBuildTarget;

/**
* The default entry module for the server build if a {@see AppConfig.server}
* is not provided.
Expand Down Expand Up @@ -397,17 +374,7 @@ export async function readConfig(
}
}

if (appConfig.serverBuildTarget) {
warnOnce(serverBuildTargetWarning, "v2_serverBuildTarget");
}

let isCloudflareRuntime = ["cloudflare-pages", "cloudflare-workers"].includes(
appConfig.serverBuildTarget ?? ""
);
let isDenoRuntime = appConfig.serverBuildTarget === "deno";

let serverBuildPath = resolveServerBuildPath(rootDirectory, appConfig);
let serverBuildTarget = appConfig.serverBuildTarget;
let serverBuildTargetEntryModule = `export * from ${JSON.stringify(
serverBuildVirtualModule.id
)};`;
Expand All @@ -418,21 +385,6 @@ export async function readConfig(
let serverMinify = appConfig.serverMinify;
let serverModuleFormat = appConfig.serverModuleFormat || "cjs";
let serverPlatform = appConfig.serverPlatform || "node";
if (isCloudflareRuntime) {
serverConditions ??= ["worker"];
serverDependenciesToBundle = "all";
serverMainFields ??= ["browser", "module", "main"];
serverMinify ??= true;
serverModuleFormat = "esm";
serverPlatform = "neutral";
}
if (isDenoRuntime) {
serverConditions ??= ["deno", "worker"];
serverDependenciesToBundle = "all";
serverMainFields ??= ["module", "main"];
serverModuleFormat = "esm";
serverPlatform = "neutral";
}
serverMainFields ??=
serverModuleFormat === "esm" ? ["module", "main"] : ["main", "module"];
serverMinify ??= false;
Expand Down Expand Up @@ -547,9 +499,7 @@ export async function readConfig(
process.env.REMIX_DEV_SERVER_WS_PORT = String(devServerPort);
let devServerBroadcastDelay = appConfig.devServerBroadcastDelay || 0;

let defaultPublicPath =
appConfig.serverBuildTarget === "arc" ? "/_static/build/" : "/build/";
let publicPath = addTrailingSlash(appConfig.publicPath || defaultPublicPath);
let publicPath = addTrailingSlash(appConfig.publicPath || "/build/");

let rootRouteFile = findEntry(appDirectory, "root");
if (!rootRouteFile) {
Expand Down Expand Up @@ -638,7 +588,6 @@ export async function readConfig(
rootDirectory,
routes,
serverBuildPath,
serverBuildTarget,
serverBuildTargetEntryModule,
serverConditions,
serverDependenciesToBundle,
Expand Down Expand Up @@ -692,21 +641,6 @@ const resolveServerBuildPath = (
) => {
let serverBuildPath = "build/index.js";

switch (appConfig.serverBuildTarget) {
case "arc":
serverBuildPath = "server/index.js";
break;
case "cloudflare-pages":
serverBuildPath = "functions/[[path]].js";
break;
case "netlify":
serverBuildPath = ".netlify/functions-internal/server.js";
break;
case "vercel":
serverBuildPath = "api/index.js";
break;
}

// retain deprecated behavior for now
if (appConfig.serverBuildDirectory) {
serverBuildPath = path.join(appConfig.serverBuildDirectory, "index.js");
Expand All @@ -725,5 +659,3 @@ 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 fe5c936

Please sign in to comment.