-
Notifications
You must be signed in to change notification settings - Fork 151
fix(middleware): Support wasm in bundled middleware #802
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@opennextjs/aws": patch | ||
--- | ||
|
||
fix(middleware): copy wasm files for bundled middleware |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ import path from "node:path"; | |||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
import type { FunctionOptions, SplittedFunctionOptions } from "types/open-next"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
import { loadMiddlewareManifest } from "config/util.js"; | ||||||||||||||||||||||||||||||||||||||||
import type { Plugin } from "esbuild"; | ||||||||||||||||||||||||||||||||||||||||
import logger from "../logger.js"; | ||||||||||||||||||||||||||||||||||||||||
import { minifyAll } from "../minimize-js.js"; | ||||||||||||||||||||||||||||||||||||||||
|
@@ -13,7 +14,10 @@ import { getCrossPlatformPathRegex } from "../utils/regex.js"; | |||||||||||||||||||||||||||||||||||||||
import { bundleNextServer } from "./bundleNextServer.js"; | ||||||||||||||||||||||||||||||||||||||||
import { compileCache } from "./compileCache.js"; | ||||||||||||||||||||||||||||||||||||||||
import { copyTracedFiles } from "./copyTracedFiles.js"; | ||||||||||||||||||||||||||||||||||||||||
import { generateEdgeBundle } from "./edge/createEdgeBundle.js"; | ||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||
copyMiddlewareResources, | ||||||||||||||||||||||||||||||||||||||||
generateEdgeBundle, | ||||||||||||||||||||||||||||||||||||||||
} from "./edge/createEdgeBundle.js"; | ||||||||||||||||||||||||||||||||||||||||
import * as buildHelper from "./helper.js"; | ||||||||||||||||||||||||||||||||||||||||
import { installDependencies } from "./installDeps.js"; | ||||||||||||||||||||||||||||||||||||||||
import { type CodePatcher, applyCodePatches } from "./patch/codePatcher.js"; | ||||||||||||||||||||||||||||||||||||||||
|
@@ -135,12 +139,14 @@ async function generateBundle( | |||||||||||||||||||||||||||||||||||||||
// `.next/standalone/package/path` (ie. `.next`, `server.js`). | ||||||||||||||||||||||||||||||||||||||||
// We need to output the handler file inside the package path. | ||||||||||||||||||||||||||||||||||||||||
const packagePath = buildHelper.getPackagePath(options); | ||||||||||||||||||||||||||||||||||||||||
fs.mkdirSync(path.join(outputPath, packagePath), { recursive: true }); | ||||||||||||||||||||||||||||||||||||||||
const outPackagePath = path.join(outputPath, packagePath); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
fs.mkdirSync(outPackagePath, { recursive: true }); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
const ext = fnOptions.runtime === "deno" ? "mjs" : "cjs"; | ||||||||||||||||||||||||||||||||||||||||
fs.copyFileSync( | ||||||||||||||||||||||||||||||||||||||||
path.join(options.buildDir, `cache.${ext}`), | ||||||||||||||||||||||||||||||||||||||||
path.join(outputPath, packagePath, "cache.cjs"), | ||||||||||||||||||||||||||||||||||||||||
path.join(outPackagePath, "cache.cjs"), | ||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if (fnOptions.runtime === "deno") { | ||||||||||||||||||||||||||||||||||||||||
|
@@ -150,7 +156,7 @@ async function generateBundle( | |||||||||||||||||||||||||||||||||||||||
// Bundle next server if necessary | ||||||||||||||||||||||||||||||||||||||||
const isBundled = fnOptions.experimentalBundledNextServer ?? false; | ||||||||||||||||||||||||||||||||||||||||
if (isBundled) { | ||||||||||||||||||||||||||||||||||||||||
await bundleNextServer(path.join(outputPath, packagePath), appPath, { | ||||||||||||||||||||||||||||||||||||||||
await bundleNextServer(outPackagePath, appPath, { | ||||||||||||||||||||||||||||||||||||||||
minify: options.minify, | ||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
@@ -159,15 +165,22 @@ async function generateBundle( | |||||||||||||||||||||||||||||||||||||||
if (!config.middleware?.external) { | ||||||||||||||||||||||||||||||||||||||||
fs.copyFileSync( | ||||||||||||||||||||||||||||||||||||||||
path.join(options.buildDir, "middleware.mjs"), | ||||||||||||||||||||||||||||||||||||||||
path.join(outputPath, packagePath, "middleware.mjs"), | ||||||||||||||||||||||||||||||||||||||||
path.join(outPackagePath, "middleware.mjs"), | ||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
const middlewareManifest = loadMiddlewareManifest( | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should create a generic function for this and use it both here and there opennextjs-aws/packages/open-next/src/build/edge/createEdgeBundle.ts Lines 212 to 230 in fbe09ae
We also need to copy the assets |
||||||||||||||||||||||||||||||||||||||||
path.join(options.appBuildOutputPath, ".next"), | ||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
copyMiddlewareResources( | ||||||||||||||||||||||||||||||||||||||||
options, | ||||||||||||||||||||||||||||||||||||||||
middlewareManifest.middleware["/"], | ||||||||||||||||||||||||||||||||||||||||
outPackagePath, | ||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// Copy open-next.config.mjs | ||||||||||||||||||||||||||||||||||||||||
buildHelper.copyOpenNextConfig( | ||||||||||||||||||||||||||||||||||||||||
options.buildDir, | ||||||||||||||||||||||||||||||||||||||||
path.join(outputPath, packagePath), | ||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||
buildHelper.copyOpenNextConfig(options.buildDir, outPackagePath); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
// Copy env files | ||||||||||||||||||||||||||||||||||||||||
buildHelper.copyEnvFile(appBuildOutputPath, packagePath, outputPath); | ||||||||||||||||||||||||||||||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this copy logic should also be in a function on this file so that everything middleware related is there https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/createMiddleware.ts.
Pretty sure we need to copy the wasm/asset files for the external middleware as well