Repository: remix-run/remix
Pull request #1084 (2021-12-16 19:18:10)

feat: added server platform config


Patch:
diff --git a/fixtures/gists-app/app/routes/gists.jsx b/fixtures/gists-app/app/routes/gists.jsx
index e473da158..d41e53091 100644
--- a/fixtures/gists-app/app/routes/gists.jsx
+++ b/fixtures/gists-app/app/routes/gists.jsx
@@ -44,7 +44,7 @@ export default function Gists() {
           {users.map(user => (
             <li key={user.id}>
               <Link
-                prefetch="intent"
+                // prefetch="intent"
                 to={user.id}
                 className="text-blue-700 underline"
               >
diff --git a/fixtures/gists-app/server.js b/fixtures/gists-app/server.js
index 68c2aac25..38dfdf84d 100644
--- a/fixtures/gists-app/server.js
+++ b/fixtures/gists-app/server.js
@@ -5,6 +5,32 @@ const { createRequestHandler } = require("@remix-run/express");
 
 const port = process.env.PORT || 3000;
 
+if (process.env.NODE_ENV === "test") {
+  class MockConsole {
+    assert() {}
+    clear() {}
+    count() {}
+    countReset() {}
+    debug() {}
+    dir() {}
+    dirxml() {}
+    error() {}
+    group() {}
+    groupCollapsed() {}
+    groupEnd() {}
+    info() {}
+    log() {}
+    table() {}
+    time() {}
+    timeEnd() {}
+    timeLog() {}
+    timeStamp() {}
+    trace() {}
+    warn() {}
+  }
+  global.console = new MockConsole();
+}
+
 let app = express();
 
 app.use(compression());
diff --git a/packages/remix-dev/compiler.ts b/packages/remix-dev/compiler.ts
index 113d3adaf..197d112b8 100644
--- a/packages/remix-dev/compiler.ts
+++ b/packages/remix-dev/compiler.ts
@@ -344,7 +344,7 @@ async function createServerBuild(
       resolveDir: config.serverBuildDirectory
     },
     outfile: path.resolve(config.serverBuildDirectory, "index.js"),
-    platform: "node",
+    platform: config.serverPlatform,
     format: config.serverModuleFormat,
     target: options.target,
     inject: [reactShim],
diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts
index 7fde8053b..733430371 100644
--- a/packages/remix-dev/config.ts
+++ b/packages/remix-dev/config.ts
@@ -82,7 +82,12 @@ export interface AppConfig {
   /**
    * The output format of the server build. Defaults to "cjs".
    */
-  serverModuleFormat: "esm" | "cjs";
+  serverModuleFormat?: "esm" | "cjs";
+
+  /**
+   * The platform the server build is targeting. Defaults to "node".
+   */
+  serverPlatform?: "node" | "neutral";
 
   /**
    * A list of filenames or a glob patterns to match files in the `app/routes`
@@ -165,6 +170,11 @@ export interface RemixConfig {
    * The output format of the server build. Defaults to "cjs".
    */
   serverModuleFormat: "esm" | "cjs";
+
+  /**
+   * The platform the server build is targeting. Defaults to "node".
+   */
+   serverPlatform: "node" | "neutral";
 }
 
 /**
@@ -194,6 +204,7 @@ export async function readConfig(
   }
 
   let serverModuleFormat = appConfig.serverModuleFormat || "cjs";
+  let serverPlatform = appConfig.serverPlatform || "node";
   let mdx = appConfig.mdx;
 
   let appDirectory = path.resolve(
@@ -273,6 +284,7 @@ export async function readConfig(
     serverBuildDirectory,
     serverMode,
     serverModuleFormat,
+    serverPlatform,
     mdx
   };
 }
diff --git a/packages/remix-node/parseMultipartFormData.ts b/packages/remix-node/parseMultipartFormData.ts
index 889e91538..c73968688 100644
--- a/packages/remix-node/parseMultipartFormData.ts
+++ b/packages/remix-node/parseMultipartFormData.ts
@@ -1,4 +1,4 @@
-import type { Readable } from "stream";
+import { Readable } from "stream";
 import Busboy from "busboy";
 
 import type { Request as NodeRequest } from "./fetch";
@@ -14,13 +14,20 @@ export function parseMultipartFormData(
 
 export async function internalParseFormData(
   contentType: string,
-  stream: Readable,
+  body: string | Buffer | Readable,
   abortController?: AbortController,
   uploadHandler?: UploadHandler
 ) {
   let formData = new NodeFormData();
   let fileWorkQueue: Promise<void>[] = [];
 
+  let stream: Readable;
+  if (typeof body === "string" || Buffer.isBuffer(body)) {
+    stream = Readable.from(body.toString());
+  } else {
+    stream = body;
+  }
+
   await new Promise<void>(async (resolve, reject) => {
     let busboy = new Busboy({
       highWaterMark: 2 * 1024 * 1024,


Test patch:
diff --git a/packages/remix-dev/__tests__/readConfig-test.ts b/packages/remix-dev/__tests__/readConfig-test.ts
index 36173e6d2..dad28fe42 100644
--- a/packages/remix-dev/__tests__/readConfig-test.ts
+++ b/packages/remix-dev/__tests__/readConfig-test.ts
@@ -434,6 +434,7 @@ describe("readConfig", () => {
         "serverBuildDirectory": Any<String>,
         "serverMode": "production",
         "serverModuleFormat": "cjs",
+        "serverPlatform": "node",
       }
     `
     );