Skip to content

Commit

Permalink
feat(compiler): Add support for remix config future flags (#4566)
Browse files Browse the repository at this point in the history
* add support for remix config future flags
* put `future` on entry context for runtime access
  • Loading branch information
chaance authored and kentcdodds committed Dec 15, 2022
1 parent 48a3516 commit 869238a
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-eels-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Added support for feature flags in `remix.config.js`
6 changes: 6 additions & 0 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ describe("readConfig", () => {
assetsBuildDirectory: expect.any(String),
relativeAssetsBuildDirectory: expect.any(String),
tsconfigPath: expect.any(String),
future: {
v2_meta: expect.any(Boolean),
},
},
`
Object {
Expand All @@ -32,6 +35,9 @@ describe("readConfig", () => {
"devServerPort": Any<Number>,
"entryClientFile": "entry.client.tsx",
"entryServerFile": "entry.server.tsx",
"future": Object {
"v2_meta": Any<Boolean>,
},
"mdx": undefined,
"publicPath": "/build/",
"relativeAssetsBuildDirectory": Any<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ${Object.keys(config.routes)
export const assetsBuildDirectory = ${JSON.stringify(
config.relativeAssetsBuildDirectory
)};
export const future = ${JSON.stringify(config.future)};
export const publicPath = ${JSON.stringify(config.publicPath)};
export const entry = { module: entryServer };
export const routes = {
Expand Down
13 changes: 13 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export type ServerBuildTarget =
export type ServerModuleFormat = "esm" | "cjs";
export type ServerPlatform = "node" | "neutral";

interface FutureConfig {
v2_meta: boolean;
}

/**
* The user-provided config in `remix.config.js`.
*/
Expand Down Expand Up @@ -157,6 +161,8 @@ export interface AppConfig {
| string
| string[]
| (() => Promise<string | string[]> | string | string[]);

future?: Partial<FutureConfig>;
}

/**
Expand Down Expand Up @@ -275,6 +281,8 @@ export interface RemixConfig {
* The path for the tsconfig file, if present on the root directory.
*/
tsconfigPath: string | undefined;

future: FutureConfig;
}

/**
Expand Down Expand Up @@ -472,6 +480,10 @@ export async function readConfig(
writeConfigDefaults(tsconfigPath);
}

let future = {
v2_meta: appConfig.future?.v2_meta === true,
};

return {
appDirectory,
cacheDirectory,
Expand All @@ -495,6 +507,7 @@ export async function readConfig(
mdx,
watchPaths,
tsconfigPath,
future,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/remix-dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./modules";

export type { AppConfig } from "./config";
export type { AppConfig, RemixConfig as ResolvedRemixConfig } from "./config";

export * as cli from "./cli/index";
export { createApp } from "./cli/create";
Expand Down
4 changes: 3 additions & 1 deletion packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { createPath } from "history";
import type { SerializeFrom } from "@remix-run/server-runtime";

import type { AppData, FormEncType, FormMethod } from "./data";
import type { EntryContext, AssetsManifest } from "./entry";
import type { AssetsManifest, EntryContext, FutureConfig } from "./entry";
import type { AppState, SerializedError } from "./errors";
import {
RemixRootDefaultErrorBoundary,
Expand Down Expand Up @@ -71,6 +71,7 @@ interface RemixEntryContextType {
serverHandoffString?: string;
clientRoutes: ClientRoute[];
transitionManager: ReturnType<typeof createTransitionManager>;
future: FutureConfig;
}

export const RemixEntryContext = React.createContext<
Expand Down Expand Up @@ -195,6 +196,7 @@ export function RemixEntry({
routeData: loaderData,
actionData,
transitionManager,
future: entryContext.future,
}}
>
<RemixErrorBoundary
Expand Down
5 changes: 5 additions & 0 deletions packages/remix-react/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface EntryContext {
actionData?: RouteData;
routeModules: RouteModules;
serverHandoffString?: string;
future: FutureConfig;
}

export interface FutureConfig {
v2_meta: boolean;
}

export interface AssetsManifest {
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-server-runtime/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DataFunctionArgs } from "./routeModules";
import type { EntryContext, AssetsManifest } from "./entry";
import type { AssetsManifest, EntryContext, FutureConfig } from "./entry";
import type { ServerRouteManifest } from "./routes";

/**
Expand All @@ -13,6 +13,7 @@ export interface ServerBuild {
assets: AssetsManifest;
publicPath: string;
assetsBuildDirectory: string;
future: FutureConfig;
}

export interface HandleDocumentRequestFunction {
Expand Down
5 changes: 5 additions & 0 deletions packages/remix-server-runtime/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface EntryContext {
actionData?: RouteData;
routeModules: RouteModules<EntryRouteModule>;
serverHandoffString?: string;
future: FutureConfig;
}

export interface FutureConfig {
v2_meta: boolean;
}

export interface AssetsManifest {
Expand Down
1 change: 1 addition & 0 deletions packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ async function handleDocumentRequest({
appState: appState,
matches: entryMatches,
routeData,
future: build.future,
};

let entryContext: EntryContext = {
Expand Down

0 comments on commit 869238a

Please sign in to comment.