diff --git a/integration/cf-compiler-test.ts b/integration/cf-compiler-test.ts index 13adcfc7148..2e0f61e3bed 100644 --- a/integration/cf-compiler-test.ts +++ b/integration/cf-compiler-test.ts @@ -6,7 +6,7 @@ import glob from "glob"; import { createFixtureProject, js, json } from "./helpers/create-fixture.js"; -const searchFiles = async (pattern: string | RegExp, files: string[]) => { +const searchFiles = (pattern: string | RegExp, files: string[]) => { let result = shell.grep("-l", pattern, files); return result.stdout .trim() @@ -14,7 +14,7 @@ const searchFiles = async (pattern: string | RegExp, files: string[]) => { .filter((line) => line.length > 0); }; -const findCodeFiles = async (directory: string) => +const findCodeFiles = (directory: string) => glob.sync("**/*.@(js|jsx|ts|tsx)", { cwd: directory, absolute: true, diff --git a/integration/defer-loader-test.ts b/integration/defer-loader-test.ts index 141c507eeb9..eae6950de76 100644 --- a/integration/defer-loader-test.ts +++ b/integration/defer-loader-test.ts @@ -72,7 +72,7 @@ test.beforeAll(async () => { appFixture = await createAppFixture(fixture); }); -test.afterAll(async () => appFixture.close()); +test.afterAll(() => appFixture.close()); test("deferred response can redirect on document request", async ({ page }) => { let app = new PlaywrightFixture(appFixture, page); diff --git a/integration/deno-compiler-test.ts b/integration/deno-compiler-test.ts index 506fabf6f62..d48d1d6856c 100644 --- a/integration/deno-compiler-test.ts +++ b/integration/deno-compiler-test.ts @@ -19,12 +19,12 @@ const importPattern = (importSpecifier: string) => String.raw`import\s*{.*}\s*from\s*"` + importSpecifier + String.raw`"` ); -const findCodeFiles = async (directory: string) => +const findCodeFiles = (directory: string) => glob.sync("**/*.@(js|jsx|ts|tsx)", { cwd: directory, absolute: true, }); -const searchFiles = async (pattern: string | RegExp, files: string[]) => { +const searchFiles = (pattern: string | RegExp, files: string[]) => { let result = shell.grep("-l", pattern, files); return result.stdout .trim() diff --git a/integration/fetch-globals-test.ts b/integration/fetch-globals-test.ts index 3592f230aea..12463b0f22b 100644 --- a/integration/fetch-globals-test.ts +++ b/integration/fetch-globals-test.ts @@ -35,7 +35,7 @@ test.beforeAll(async () => { appFixture = await createAppFixture(fixture); }); -test.afterAll(async () => appFixture.close()); +test.afterAll(() => appFixture.close()); test("returned variable from fetch() should be instance of global Response", async () => { let response = await fixture.requestDocument("/"); diff --git a/integration/flat-routes-test.ts b/integration/flat-routes-test.ts index 53eae110e1d..a45128260fc 100644 --- a/integration/flat-routes-test.ts +++ b/integration/flat-routes-test.ts @@ -159,14 +159,14 @@ test.describe("flat routes", () => { }); } - test("allows ignoredRouteFiles to be configured", async () => { + test("allows ignoredRouteFiles to be configured", () => { let routeIds = Object.keys(fixture.build.routes); expect(routeIds).not.toContain(IGNORED_ROUTE); }); }); -test.describe("emits warnings for route conflicts", async () => { +test.describe("emits warnings for route conflicts", () => { let buildStdio = new PassThrough(); let buildOutput: string; diff --git a/integration/route-collisions-test.ts b/integration/route-collisions-test.ts index 52bc3c445da..df881b36538 100644 --- a/integration/route-collisions-test.ts +++ b/integration/route-collisions-test.ts @@ -37,7 +37,7 @@ test.describe("build failures", () => { let originalConsoleWarn = console.warn; let originalConsoleError = console.error; - test.beforeAll(async () => { + test.beforeAll(() => { console.log = () => {}; console.warn = () => {}; console.error = () => {}; diff --git a/packages/remix-dev/compiler/css/plugins/bundleEntry.ts b/packages/remix-dev/compiler/css/plugins/bundleEntry.ts index 4eaa3f4cb0b..7e0de4acf17 100644 --- a/packages/remix-dev/compiler/css/plugins/bundleEntry.ts +++ b/packages/remix-dev/compiler/css/plugins/bundleEntry.ts @@ -21,7 +21,7 @@ export function cssBundleEntryModulePlugin({ config }: Context): Plugin { }; }); - build.onLoad({ filter }, async () => { + build.onLoad({ filter }, () => { return { resolveDir: config.appDirectory, loader: "js", diff --git a/packages/remix-dev/compiler/js/plugins/hmr.ts b/packages/remix-dev/compiler/js/plugins/hmr.ts index e0eded4f5d2..2c70ab01494 100644 --- a/packages/remix-dev/compiler/js/plugins/hmr.ts +++ b/packages/remix-dev/compiler/js/plugins/hmr.ts @@ -8,7 +8,7 @@ import type { Context } from "../../context"; export let hmrPlugin = ({ config }: Context): esbuild.Plugin => { return { name: "remix-hmr", - setup: async (build) => { + setup: (build) => { let cache = new Map(); build.onResolve({ filter: /^remix:hmr$/ }, (args) => { diff --git a/packages/remix-dev/compiler/js/plugins/routes.ts b/packages/remix-dev/compiler/js/plugins/routes.ts index c9891585a0d..9c54cbd27cb 100644 --- a/packages/remix-dev/compiler/js/plugins/routes.ts +++ b/packages/remix-dev/compiler/js/plugins/routes.ts @@ -27,7 +27,7 @@ export function browserRouteModulesPlugin( ): esbuild.Plugin { return { name: "browser-route-modules", - async setup(build) { + setup(build) { let routesByFile: Map = Object.keys(config.routes).reduce( (map, key) => { let route = config.routes[key]; diff --git a/packages/remix-dev/compiler/plugins/absoluteCssUrlsPlugin.ts b/packages/remix-dev/compiler/plugins/absoluteCssUrlsPlugin.ts index 21df14e5a45..81e0d983130 100644 --- a/packages/remix-dev/compiler/plugins/absoluteCssUrlsPlugin.ts +++ b/packages/remix-dev/compiler/plugins/absoluteCssUrlsPlugin.ts @@ -8,7 +8,7 @@ import type { Plugin, PluginBuild } from "esbuild"; export const absoluteCssUrlsPlugin = (): Plugin => { return { name: "absolute-css-urls-plugin", - setup: async (build: PluginBuild) => { + setup: (build: PluginBuild) => { build.onResolve({ filter: /.*/ }, async (args) => { let { kind, path: resolvePath } = args; if (kind === "url-token" && path.isAbsolute(resolvePath)) { diff --git a/packages/remix-dev/compiler/plugins/cssBundlePlugin.ts b/packages/remix-dev/compiler/plugins/cssBundlePlugin.ts index 98f43110520..a68a4d1d43f 100644 --- a/packages/remix-dev/compiler/plugins/cssBundlePlugin.ts +++ b/packages/remix-dev/compiler/plugins/cssBundlePlugin.ts @@ -15,7 +15,7 @@ export function cssBundlePlugin(refs: { }): Plugin { return { name: pluginName, - async setup(build) { + setup(build) { let preventInfiniteLoop = {}; build.onResolve({ filter: /^@remix-run\/css-bundle$/ }, async (args) => { // Prevent plugin from infinitely trying to resolve itself diff --git a/packages/remix-dev/compiler/plugins/cssImports.ts b/packages/remix-dev/compiler/plugins/cssImports.ts index e2a04a556a7..3ac56e072f7 100644 --- a/packages/remix-dev/compiler/plugins/cssImports.ts +++ b/packages/remix-dev/compiler/plugins/cssImports.ts @@ -97,7 +97,7 @@ export function cssFilePlugin(ctx: Context): esbuild.Plugin { ? [ { name: "postcss-plugin", - async setup(build) { + setup(build) { build.onLoad( { filter: /\.css$/, namespace: "file" }, async (args) => { diff --git a/packages/remix-dev/compiler/server/plugins/entry.ts b/packages/remix-dev/compiler/server/plugins/entry.ts index a7c9634b94b..c98f92e971d 100644 --- a/packages/remix-dev/compiler/server/plugins/entry.ts +++ b/packages/remix-dev/compiler/server/plugins/entry.ts @@ -25,7 +25,7 @@ export function serverEntryModulePlugin({ config, options }: Context): Plugin { }; }); - build.onLoad({ filter }, async () => { + build.onLoad({ filter }, () => { return { resolveDir: config.appDirectory, loader: "js", diff --git a/packages/remix-dev/devServer_unstable/env.ts b/packages/remix-dev/devServer_unstable/env.ts index d41c6449897..de810f6c6b4 100644 --- a/packages/remix-dev/devServer_unstable/env.ts +++ b/packages/remix-dev/devServer_unstable/env.ts @@ -2,7 +2,7 @@ import fse from "fs-extra"; import * as path from "node:path"; // Import environment variables from: .env, failing gracefully if it doesn't exist -export async function loadEnv(rootDirectory: string): Promise { +export function loadEnv(rootDirectory: string) { let envPath = path.join(rootDirectory, ".env"); if (!fse.existsSync(envPath)) return; diff --git a/packages/remix-node/crypto.ts b/packages/remix-node/crypto.ts index cf85ef6547d..9f32b06bdd2 100644 --- a/packages/remix-node/crypto.ts +++ b/packages/remix-node/crypto.ts @@ -1,13 +1,10 @@ import cookieSignature from "cookie-signature"; import type { SignFunction, UnsignFunction } from "@remix-run/server-runtime"; -export const sign: SignFunction = async (value, secret) => { +export const sign: SignFunction = (value, secret) => { return cookieSignature.sign(value, secret); }; -export const unsign: UnsignFunction = async ( - signed: string, - secret: string -) => { +export const unsign: UnsignFunction = (signed: string, secret: string) => { return cookieSignature.unsign(signed, secret); }; diff --git a/packages/remix-server-runtime/crypto.ts b/packages/remix-server-runtime/crypto.ts index 6f839a7117f..58d333033dd 100644 --- a/packages/remix-server-runtime/crypto.ts +++ b/packages/remix-server-runtime/crypto.ts @@ -1,9 +1,14 @@ -export type SignFunction = (value: string, secret: string) => Promise; +import type { PromiseOrSync } from "./utils"; + +export type SignFunction = ( + value: string, + secret: string +) => PromiseOrSync; export type UnsignFunction = ( cookie: string, secret: string -) => Promise; +) => PromiseOrSync; // TODO: Once node v16 is available on AWS we should use the globally provided // webcrypto "crypto" variable and re-enable this code-path in "./cookies.ts" diff --git a/packages/remix-server-runtime/index.ts b/packages/remix-server-runtime/index.ts index 038b6518e94..2fed70cceaa 100644 --- a/packages/remix-server-runtime/index.ts +++ b/packages/remix-server-runtime/index.ts @@ -77,3 +77,5 @@ export type { UploadHandler, UploadHandlerPart, } from "./reexport"; + +export type { PromiseOrSync } from "./utils"; diff --git a/packages/remix-server-runtime/sessions.ts b/packages/remix-server-runtime/sessions.ts index bf809b65414..a56372197d4 100644 --- a/packages/remix-server-runtime/sessions.ts +++ b/packages/remix-server-runtime/sessions.ts @@ -3,6 +3,7 @@ import type { CookieParseOptions, CookieSerializeOptions } from "cookie"; import type { Cookie, CookieOptions, CreateCookieFunction } from "./cookies"; import { isCookie } from "./cookies"; import { warnOnce } from "./warnings"; +import type { PromiseOrSync } from "./utils"; /** * An object of name/value pairs to be used in the session. @@ -223,12 +224,14 @@ export interface SessionIdStorageStrategy< createData: ( data: FlashSessionData, expires?: Date - ) => Promise; + ) => PromiseOrSync; /** * Returns data for a given session id, or `null` if there isn't any. */ - readData: (id: string) => Promise | null>; + readData: ( + id: string + ) => PromiseOrSync | null>; /** * Updates data for the given session id. @@ -237,12 +240,12 @@ export interface SessionIdStorageStrategy< id: string, data: FlashSessionData, expires?: Date - ) => Promise; + ) => PromiseOrSync; /** * Deletes data for a given session id from the data store. */ - deleteData: (id: string) => Promise; + deleteData: (id: string) => PromiseOrSync; } export type CreateSessionStorageFunction = < diff --git a/packages/remix-server-runtime/sessions/memoryStorage.ts b/packages/remix-server-runtime/sessions/memoryStorage.ts index d8072528fd9..94ce088146b 100644 --- a/packages/remix-server-runtime/sessions/memoryStorage.ts +++ b/packages/remix-server-runtime/sessions/memoryStorage.ts @@ -45,12 +45,12 @@ export const createMemorySessionStorageFactory = return createSessionStorage({ cookie, - async createData(data, expires) { + createData(data, expires) { let id = (++uniqueId).toString(); map.set(id, { data, expires }); return id; }, - async readData(id) { + readData(id) { if (map.has(id)) { let { data, expires } = map.get(id)!; @@ -64,10 +64,10 @@ export const createMemorySessionStorageFactory = return null; }, - async updateData(id, data, expires) { + updateData(id, data, expires) { map.set(id, { data, expires }); }, - async deleteData(id) { + deleteData(id) { map.delete(id); }, }); diff --git a/packages/remix-server-runtime/utils.ts b/packages/remix-server-runtime/utils.ts new file mode 100644 index 00000000000..ad9891bd8eb --- /dev/null +++ b/packages/remix-server-runtime/utils.ts @@ -0,0 +1 @@ +export type PromiseOrSync = Promise | T; diff --git a/scripts/playground/template/app/models/user.server.ts b/scripts/playground/template/app/models/user.server.ts index 32e030b4be5..62388ada2a8 100644 --- a/scripts/playground/template/app/models/user.server.ts +++ b/scripts/playground/template/app/models/user.server.ts @@ -5,11 +5,11 @@ import { prisma } from "~/db.server"; export type { User } from "@prisma/client"; -export async function getUserById(id: User["id"]) { +export function getUserById(id: User["id"]) { return prisma.user.findUnique({ where: { id } }); } -export async function getUserByEmail(email: User["email"]) { +export function getUserByEmail(email: User["email"]) { return prisma.user.findUnique({ where: { email } }); } @@ -28,7 +28,7 @@ export async function createUser(email: User["email"], password: string) { }); } -export async function deleteUserByEmail(email: User["email"]) { +export function deleteUserByEmail(email: User["email"]) { return prisma.user.delete({ where: { email } }); } diff --git a/scripts/playground/template/app/routes/logout.tsx b/scripts/playground/template/app/routes/logout.tsx index 5def3ddfda0..93a98af0aa9 100644 --- a/scripts/playground/template/app/routes/logout.tsx +++ b/scripts/playground/template/app/routes/logout.tsx @@ -7,6 +7,6 @@ export async function action({ request }: ActionArgs) { return logout(request); } -export async function loader() { +export function loader() { return redirect("/"); }