Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"globals": "^15.0.0",
"jest": "^29.6.2",
"mongodb": "^6.3.0",
"next": "^14.0.4",
"prettier": "^3.0.2",
"react": "^18",
"react-dom": "^18",
Expand Down
21 changes: 17 additions & 4 deletions src/hooks/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ import { resolve } from "node:path";
import { walkAncestor as walk } from "../util/walk";
import { ESTree } from "meriyah";

import type { NextConfig } from "next";
import type webpack from "webpack";
// Minimal local types replacing `next` and `webpack` dev dependencies (only needed for types).
interface WebpackConfiguration {
module?: {
rules?: unknown[];
};
}

interface WebpackContext {
isServer: boolean;
nextRuntime?: string;
}

interface NextConfig {
webpack?: (config: WebpackConfiguration, context: WebpackContext) => WebpackConfiguration;
}

import { call_, identifier, literal, member, ret } from "../generate";
import { warn } from "../message";
Expand Down Expand Up @@ -48,8 +61,8 @@ export async function injectConfig(loadConfig: () => Promise<NextConfig>): Promi

// Webpack loader injection (Next.js with --webpack or older Next.js)
const orig = result.webpack;
result.webpack = (config: webpack.Configuration, context) => {
if (orig) config = orig(config, context) as webpack.Configuration;
result.webpack = (config: WebpackConfiguration, context: WebpackContext) => {
if (orig) config = orig(config, context);
if (context.isServer && context.nextRuntime !== "edge") {
assert(config.module?.rules);
// Guard against the loader being added multiple times (e.g. when Next.js 16
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/next.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ exports[`mapping a Next.js appmap 1`] = `
"http_server_response": {
"headers": {
"Content-Type": "application/json",
"Vary": "RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url",
"Vary": "RSC, Next-Router-State-Tree, Next-Router-Prefetch",
},
"status_code": 200,
},
Expand Down Expand Up @@ -189,7 +189,7 @@ exports[`mapping a Next.js appmap 1`] = `
"http_server_response": {
"headers": {
"Cache-Control": "no-store, must-revalidate",
"Content-Length": "1333",
"Content-Length": "1197",
"Content-Type": "text/html; charset=utf-8",
"Vary": "Accept-Encoding",
"X-Powered-By": "Next.js",
Expand Down
2 changes: 1 addition & 1 deletion test/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "yarn@3.6.3",
"private": true,
"dependencies": {
"next": "^14.0.4",
"next": "^14.2.35",
"react": "^18",
"react-dom": "^18"
},
Expand Down
2 changes: 1 addition & 1 deletion test/next16/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "yarn@3.6.3",
"private": true,
"dependencies": {
"next": "^16.0.0",
"next": "^16.1.7",
"react": "^19",
"react-dom": "^19"
},
Expand Down
Loading
Loading