From 869238aa7b077d6baef2a93e5f924e58739b0eff Mon Sep 17 00:00:00 2001 From: Chance Strickland Date: Mon, 14 Nov 2022 11:33:48 -0800 Subject: [PATCH] feat(compiler): Add support for remix config future flags (#4566) * add support for remix config future flags * put `future` on entry context for runtime access --- .changeset/calm-eels-invite.md | 5 +++++ packages/remix-dev/__tests__/readConfig-test.ts | 6 ++++++ .../compiler/plugins/serverEntryModulePlugin.ts | 1 + packages/remix-dev/config.ts | 13 +++++++++++++ packages/remix-dev/index.ts | 2 +- packages/remix-react/components.tsx | 4 +++- packages/remix-react/entry.ts | 5 +++++ packages/remix-server-runtime/build.ts | 3 ++- packages/remix-server-runtime/entry.ts | 5 +++++ packages/remix-server-runtime/server.ts | 1 + 10 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .changeset/calm-eels-invite.md diff --git a/.changeset/calm-eels-invite.md b/.changeset/calm-eels-invite.md new file mode 100644 index 00000000000..8d1ea67cb2e --- /dev/null +++ b/.changeset/calm-eels-invite.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +Added support for feature flags in `remix.config.js` diff --git a/packages/remix-dev/__tests__/readConfig-test.ts b/packages/remix-dev/__tests__/readConfig-test.ts index 5f14c9f4f44..a6cdea1f44e 100644 --- a/packages/remix-dev/__tests__/readConfig-test.ts +++ b/packages/remix-dev/__tests__/readConfig-test.ts @@ -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 { @@ -32,6 +35,9 @@ describe("readConfig", () => { "devServerPort": Any, "entryClientFile": "entry.client.tsx", "entryServerFile": "entry.server.tsx", + "future": Object { + "v2_meta": Any, + }, "mdx": undefined, "publicPath": "/build/", "relativeAssetsBuildDirectory": Any, diff --git a/packages/remix-dev/compiler/plugins/serverEntryModulePlugin.ts b/packages/remix-dev/compiler/plugins/serverEntryModulePlugin.ts index 941c1a90b81..56955b4ce4f 100644 --- a/packages/remix-dev/compiler/plugins/serverEntryModulePlugin.ts +++ b/packages/remix-dev/compiler/plugins/serverEntryModulePlugin.ts @@ -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 = { diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts index 0a6d3943eb7..5c8a67ec29f 100644 --- a/packages/remix-dev/config.ts +++ b/packages/remix-dev/config.ts @@ -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`. */ @@ -157,6 +161,8 @@ export interface AppConfig { | string | string[] | (() => Promise | string | string[]); + + future?: Partial; } /** @@ -275,6 +281,8 @@ export interface RemixConfig { * The path for the tsconfig file, if present on the root directory. */ tsconfigPath: string | undefined; + + future: FutureConfig; } /** @@ -472,6 +480,10 @@ export async function readConfig( writeConfigDefaults(tsconfigPath); } + let future = { + v2_meta: appConfig.future?.v2_meta === true, + }; + return { appDirectory, cacheDirectory, @@ -495,6 +507,7 @@ export async function readConfig( mdx, watchPaths, tsconfigPath, + future, }; } diff --git a/packages/remix-dev/index.ts b/packages/remix-dev/index.ts index 7876a895d8b..ba236fd8bc6 100644 --- a/packages/remix-dev/index.ts +++ b/packages/remix-dev/index.ts @@ -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"; diff --git a/packages/remix-react/components.tsx b/packages/remix-react/components.tsx index 1c43538167c..ced5b54c778 100644 --- a/packages/remix-react/components.tsx +++ b/packages/remix-react/components.tsx @@ -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, @@ -71,6 +71,7 @@ interface RemixEntryContextType { serverHandoffString?: string; clientRoutes: ClientRoute[]; transitionManager: ReturnType; + future: FutureConfig; } export const RemixEntryContext = React.createContext< @@ -195,6 +196,7 @@ export function RemixEntry({ routeData: loaderData, actionData, transitionManager, + future: entryContext.future, }} > ; serverHandoffString?: string; + future: FutureConfig; +} + +export interface FutureConfig { + v2_meta: boolean; } export interface AssetsManifest { diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index edc3311f696..21eca52ad8a 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -577,6 +577,7 @@ async function handleDocumentRequest({ appState: appState, matches: entryMatches, routeData, + future: build.future, }; let entryContext: EntryContext = {