Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): Add support for remix config feature flags #4566

Merged
merged 10 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
features: {
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",
"features": 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 features = ${JSON.stringify(config.features)};
chaance marked this conversation as resolved.
Show resolved Hide resolved
export const publicPath = ${JSON.stringify(config.publicPath)};
export const entry = { module: entryServer };
export const routes = {
Expand Down
9 changes: 9 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export interface AppConfig {
| string
| string[]
| (() => Promise<string | string[]> | string | string[]);

features?: { [key: string]: unknown }; // TODO: This type will change when we start adding features
}

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

features: { [key: string]: unknown }; // TODO: This type will change when we start adding features
}

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

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

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

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";
chaance marked this conversation as resolved.
Show resolved Hide resolved
chaance marked this conversation as resolved.
Show resolved Hide resolved

export * as cli from "./cli/index";
export { createApp } from "./cli/create";
Expand Down
4 changes: 4 additions & 0 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ interface RemixEntryContextType {
serverHandoffString?: string;
clientRoutes: ClientRoute[];
transitionManager: ReturnType<typeof createTransitionManager>;
features: {
v2_meta: boolean;
};
}

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

export interface AssetsManifest {
Expand Down
3 changes: 3 additions & 0 deletions packages/remix-server-runtime/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export interface ServerBuild {
assets: AssetsManifest;
publicPath: string;
assetsBuildDirectory: string;
features: {
v2_meta: boolean;
};
}

export interface HandleDocumentRequestFunction {
Expand Down
3 changes: 3 additions & 0 deletions packages/remix-server-runtime/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export interface EntryContext {
actionData?: RouteData;
routeModules: RouteModules<EntryRouteModule>;
serverHandoffString?: string;
features: {
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,
features: build.features,
};

let entryContext: EntryContext = {
Expand Down