Skip to content

Commit

Permalink
refactor: generalize features fixture
Browse files Browse the repository at this point in the history
We have a fixture which is used for testing generated features.
Historically we use it as vercel template fixture.

Here migrated it to react-router and removed vercel stuff from it.
  • Loading branch information
TrySound committed Feb 2, 2025
1 parent b9f84e7 commit 66765aa
Show file tree
Hide file tree
Showing 68 changed files with 209 additions and 249 deletions.
6 changes: 6 additions & 0 deletions fixtures/webstudio-features/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/node_modules/

# React Router
/.react-router/
/build/
4 changes: 4 additions & 0 deletions fixtures/webstudio-features/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
force=true
loglevel=error
audit=false
fund=false
12 changes: 12 additions & 0 deletions fixtures/webstudio-features/.template/app/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* We use mjs extension as constants in this file is shared with the build script
* and we use `node --eval` to extract the constants.
*/
export const assetBaseUrl = "/assets/";

/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
export const imageLoader = ({ src }) => {
return src;
};
12 changes: 12 additions & 0 deletions fixtures/webstudio-features/.template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dependencies": {
"@webstudio-is/image": "workspace:*",
"@webstudio-is/react-sdk": "workspace:*",
"@webstudio-is/sdk": "workspace:*",
"@webstudio-is/sdk-components-animation": "workspace:*",
"@webstudio-is/sdk-components-react": "workspace:*",
"@webstudio-is/sdk-components-react-radix": "workspace:*",
"@webstudio-is/sdk-components-react-router": "workspace:*",
"webstudio": "workspace:*"
}
}
5 changes: 5 additions & 0 deletions fixtures/webstudio-features/.template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"customConditions": ["webstudio"]
}
}
9 changes: 9 additions & 0 deletions fixtures/webstudio-features/.template/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vite";
// @ts-ignore
import { reactRouter } from "@react-router/dev/vite";
// @ts-ignore
import { dedupeMeta } from "./proxy-emulator/dedupe-meta";

export default defineConfig({
plugins: [reactRouter(), dedupeMeta],
});
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions fixtures/webstudio-features/app/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* We use mjs extension as constants in this file is shared with the build script
* and we use `node --eval` to extract the constants.
*/
export const assetBaseUrl = "/assets/";

/**
* @type {import("@webstudio-is/image").ImageLoader}
*/
export const imageLoader = ({ src }) => {
return src;
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { AppLoadContext } from "@remix-run/server-runtime";
import { ResourceRequest } from "@webstudio-is/sdk";

declare module "@remix-run/server-runtime" {
declare module "react-router" {
interface AppLoadContext {
EXCLUDE_FROM_SEARCH: boolean;
getDefaultActionResource?: (options: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import { Links, Meta, Outlet, useMatches } from "@remix-run/react";
import { Links, Meta, Outlet, useMatches } from "react-router";
// @todo think about how to make __generated__ typeable
// @ts-ignore
import { CustomCode } from "./__generated__/_index";
Expand Down
4 changes: 4 additions & 0 deletions fixtures/webstudio-features/app/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { type RouteConfig } from "@react-router/dev/routes";
import { flatRoutes } from "@react-router/fs-routes";

export default flatRoutes() satisfies RouteConfig;
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
type ServerRuntimeMetaFunction as MetaFunction,
type MetaFunction,
type LinksFunction,
type LinkDescriptor,
type ActionFunctionArgs,
type LoaderFunctionArgs,
type HeadersFunction,
json,
data,
redirect,
} from "@remix-run/server-runtime";
import { useLoaderData } from "@remix-run/react";
useLoaderData,
} from "react-router";
import {
isLocalResource,
loadResource,
Expand All @@ -20,7 +20,6 @@ import {
ReactSdkContext,
PageSettingsMeta,
PageSettingsTitle,
PageSettingsCanonicalLink,
} from "@webstudio-is/react-sdk/runtime";
import {
Page,
Expand Down Expand Up @@ -82,7 +81,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.status === 301 || pageMeta.status === 302
? pageMeta.status
: 302;
return redirect(pageMeta.redirect, status);
throw redirect(pageMeta.redirect, status);
}

// typecheck
Expand All @@ -92,7 +91,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
}

return json(
return data(
{
host,
url: url.href,
Expand Down Expand Up @@ -289,7 +288,6 @@ const Outlet = () => {
imageLoader={imageLoader}
/>
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
<PageSettingsCanonicalLink href={url} />
</ReactSdkContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
type ServerRuntimeMetaFunction as MetaFunction,
type MetaFunction,
type LinksFunction,
type LinkDescriptor,
type ActionFunctionArgs,
type LoaderFunctionArgs,
type HeadersFunction,
json,
data,
redirect,
} from "@remix-run/server-runtime";
import { useLoaderData } from "@remix-run/react";
useLoaderData,
} from "react-router";
import {
isLocalResource,
loadResource,
Expand All @@ -20,7 +20,6 @@ import {
ReactSdkContext,
PageSettingsMeta,
PageSettingsTitle,
PageSettingsCanonicalLink,
} from "@webstudio-is/react-sdk/runtime";
import {
Page,
Expand Down Expand Up @@ -82,7 +81,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.status === 301 || pageMeta.status === 302
? pageMeta.status
: 302;
return redirect(pageMeta.redirect, status);
throw redirect(pageMeta.redirect, status);
}

// typecheck
Expand All @@ -92,7 +91,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
}

return json(
return data(
{
host,
url: url.href,
Expand Down Expand Up @@ -289,7 +288,6 @@ const Outlet = () => {
imageLoader={imageLoader}
/>
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
<PageSettingsCanonicalLink href={url} />
</ReactSdkContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
type ServerRuntimeMetaFunction as MetaFunction,
type MetaFunction,
type LinksFunction,
type LinkDescriptor,
type ActionFunctionArgs,
type LoaderFunctionArgs,
type HeadersFunction,
json,
data,
redirect,
} from "@remix-run/server-runtime";
import { useLoaderData } from "@remix-run/react";
useLoaderData,
} from "react-router";
import {
isLocalResource,
loadResource,
Expand All @@ -20,7 +20,6 @@ import {
ReactSdkContext,
PageSettingsMeta,
PageSettingsTitle,
PageSettingsCanonicalLink,
} from "@webstudio-is/react-sdk/runtime";
import {
Page,
Expand Down Expand Up @@ -82,7 +81,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.status === 301 || pageMeta.status === 302
? pageMeta.status
: 302;
return redirect(pageMeta.redirect, status);
throw redirect(pageMeta.redirect, status);
}

// typecheck
Expand All @@ -92,7 +91,7 @@ export const loader = async (arg: LoaderFunctionArgs) => {
pageMeta.excludePageFromSearch = arg.context.EXCLUDE_FROM_SEARCH;
}

return json(
return data(
{
host,
url: url.href,
Expand Down Expand Up @@ -289,7 +288,6 @@ const Outlet = () => {
imageLoader={imageLoader}
/>
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
<PageSettingsCanonicalLink href={url} />
</ReactSdkContext.Provider>
);
};
Expand Down
Loading

0 comments on commit 66765aa

Please sign in to comment.