-
Notifications
You must be signed in to change notification settings - Fork 176
Split build.ts #562
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
Split build.ts #562
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ebb0eb3
refactor: move window warning to the build helper
vicb 7c8868f
refactor: move all compile config to compileConfig
vicb 20344d7
refactor: move functions to the build helper
vicb f8a787b
refactor: create bulidNextApp
vicb ec61c59
refactor: extract compileCache
vicb 7da01ad
refactor: extract middleware
vicb d17a763
refactor: extract assets
vicb 3a9572d
refactor: extract revalidation and image
vicb 2830693
refactor: extract warmer bundle
vicb 79e24ba
refactor: fixes
vicb 6f28517
refactor: fixes
vicb 2da2d9c
fix: review feedback
vicb 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,24 @@ | ||
import cp from "node:child_process"; | ||
import path from "node:path"; | ||
|
||
import * as buildHelper from "./helper.js"; | ||
|
||
export function setStandaloneBuildMode(options: buildHelper.BuildOptions) { | ||
// Equivalent to setting `output: "standalone"` in next.config.js | ||
process.env.NEXT_PRIVATE_STANDALONE = "true"; | ||
// Equivalent to setting `experimental.outputFileTracingRoot` in next.config.js | ||
process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT = options.monorepoRoot; | ||
} | ||
|
||
export function buildNextjsApp(options: buildHelper.BuildOptions) { | ||
const { config, packager } = options; | ||
const command = | ||
config.buildCommand ?? | ||
(["bun", "npm"].includes(packager) | ||
? `${packager} run build` | ||
: `${packager} build`); | ||
cp.execSync(command, { | ||
stdio: "inherit", | ||
cwd: path.dirname(options.appPackageJsonPath), | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import path from "node:path"; | ||
|
||
import * as buildHelper from "./helper.js"; | ||
|
||
/** | ||
* Compiles the cache adapter. | ||
* | ||
* @param options Build options. | ||
* @param format Output format. | ||
* @returns The path to the compiled file. | ||
*/ | ||
export function compileCache( | ||
options: buildHelper.BuildOptions, | ||
format: "cjs" | "esm" = "cjs", | ||
) { | ||
const { config } = options; | ||
const ext = format === "cjs" ? "cjs" : "mjs"; | ||
const outFile = path.join(options.buildDir, `cache.${ext}`); | ||
|
||
const isAfter15 = | ||
buildHelper.compareSemver(options.nextVersion, "15.0.0") >= 0; | ||
|
||
buildHelper.esbuildSync( | ||
{ | ||
external: ["next", "styled-jsx", "react", "@aws-sdk/*"], | ||
entryPoints: [path.join(options.openNextDistDir, "adapters", "cache.js")], | ||
outfile: outFile, | ||
target: ["node18"], | ||
format, | ||
banner: { | ||
js: [ | ||
`globalThis.disableIncrementalCache = ${ | ||
config.dangerous?.disableIncrementalCache ?? false | ||
};`, | ||
`globalThis.disableDynamoDBCache = ${ | ||
config.dangerous?.disableTagCache ?? false | ||
};`, | ||
`globalThis.isNextAfter15 = ${isAfter15};`, | ||
].join(""), | ||
}, | ||
}, | ||
options, | ||
); | ||
return outFile; | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
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.
This is an added function.
It calls the two existing function for Node and edge if needed.
The edge test has been moved to this function.