-
-
Notifications
You must be signed in to change notification settings - Fork 940
fix: #526 CLI warn if using @trigger.dev/react package with Next.js pages directory #530
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -12,6 +12,9 @@ import { readPackageJson } from "../../utils/readPackageJson"; | |||
| import { standardWatchFilePaths } from "../watchConfig"; | ||||
| import { telemetryClient } from "../../telemetry/telemetry"; | ||||
| import { detectMiddlewareUsage } from "./middleware"; | ||||
| import semver from "semver"; | ||||
| import boxen from "boxen"; | ||||
| import { createRequire } from "node:module"; | ||||
|
|
||||
| export class NextJs implements Framework { | ||||
| id = "nextjs"; | ||||
|
|
@@ -89,6 +92,58 @@ export class NextJs implements Framework { | |||
| break; | ||||
| } | ||||
| } | ||||
|
|
||||
| const nextJsDir = await detectPagesOrAppDir(path); | ||||
| const nextConfigExists = await detectNextConfigFile(path); | ||||
|
|
||||
| const require = createRequire(import.meta.url); | ||||
| const nextPath = require.resolve("next"); | ||||
| const reactPath = require.resolve("@trigger.dev/react"); | ||||
|
|
||||
| if (nextConfigExists && nextJsDir === "pages" && typeof reactPath !== "undefined") { | ||||
| const nextPackageJsonPath = pathModule.join(nextPath, "../../../", "package.json"); | ||||
| const nextPackageJsonData = JSON.parse(await fs.readFile(nextPackageJsonPath, "utf8")); | ||||
|
Comment on lines
+96
to
+105
Member
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. It would be much better to use the current way we check for dependencies. This function gets the "next" dependency version, and then returns true if it exists. You could create a function that uses this same methodology where you can pass in a package name and it returns undefined or the version string.
|
||||
|
|
||||
| const nextVersion = nextPackageJsonData.version; | ||||
|
|
||||
| if (semver.gte(nextVersion, "13.1.0")) { | ||||
| logger.warn( | ||||
| `⚠️ We've detected you're using Next.js Pages, please add the following to your next.config` | ||||
| ); | ||||
| logger.info( | ||||
| boxen( | ||||
| ` | ||||
| const nextConfig = { | ||||
| // existing code | ||||
| transpilePackages: ["@trigger.dev/react"], | ||||
| }; | ||||
| module.exports = nextConfig; | ||||
| `, | ||||
| { padding: 1, borderStyle: "double", borderColor: "magenta" } | ||||
| ) | ||||
| ); | ||||
| } | ||||
|
|
||||
| if (semver.lt(nextVersion, "13.1.0")) { | ||||
| logger.warn( | ||||
| `⚠️ We've detected you're using Next.js Pages, please add the following to your next.config` | ||||
| ); | ||||
| logger.info( | ||||
| boxen( | ||||
| ` | ||||
| Add the following to your next.config file: | ||||
|
|
||||
| const withTM = require('next-transpile-modules')(['@trigger.dev/react']); | ||||
|
|
||||
| module.exports = withTM({ | ||||
| //...existing config object | ||||
| }); | ||||
| `, | ||||
| { margin: 1, borderStyle: "double", borderColor: "magenta" } | ||||
| ) | ||||
| ); | ||||
| } | ||||
| } | ||||
| } | ||||
|
|
||||
| defaultHostnames = ["localhost"]; | ||||
|
|
||||
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.
Let's create a separate function for all of this logic, and export it from this file so tests can be written.
Could you also wrap the function in a try catch block so if an error is thrown it doesn't break installs. It doesn't need to do anything in the catch.