Skip to content

Commit 194b389

Browse files
committed
Print Next.js version in build log
1 parent 17acd37 commit 194b389

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

.changeset/pretty-lemons-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"open-next": patch
3+
---
4+
5+
Print Next.js version in build log

packages/open-next/src/build.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import path from "node:path";
44
import cp from "node:child_process";
55
import { minifyAll } from "./minimize-js.js";
66
import { buildSync, BuildOptions } from "esbuild";
7+
import { exit } from "node:process";
8+
import { createRequire as topLevelCreateRequire } from "node:module";
79

10+
const require = topLevelCreateRequire(import.meta.url);
811
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
912
const appPath = process.cwd();
1013
const appPublicPath = path.join(appPath, "public");
@@ -17,7 +20,8 @@ export type PublicFiles = {
1720

1821
export async function build() {
1922
// Pre-build validation
20-
printVersion();
23+
printNextjsVersion();
24+
printOpenNextVersion();
2125
checkRunningInsideNextjsApp();
2226
const { root: monorepoRoot, packager } = findMonorepoRoot();
2327

@@ -109,10 +113,24 @@ function printHeader(header: string) {
109113
);
110114
}
111115

112-
function printVersion() {
113-
const pathToPackageJson = path.join(__dirname, "../package.json");
114-
const pkg = JSON.parse(fs.readFileSync(pathToPackageJson, "utf-8"));
115-
console.info(`Using v${pkg.version}`);
116+
function printNextjsVersion() {
117+
cp.spawnSync(
118+
"node",
119+
[
120+
"-e",
121+
`"console.info('Next.js v' + require('next/package.json').version)"`,
122+
],
123+
{
124+
stdio: "inherit",
125+
cwd: appPath,
126+
shell: true,
127+
}
128+
);
129+
}
130+
131+
function printOpenNextVersion() {
132+
const onVersion = require(path.join(__dirname, "../package.json")).version;
133+
console.info(`OpenNext v${onVersion}`);
116134
}
117135

118136
function injectMiddlewareGeolocation(outputPath: string, packagePath: string) {

0 commit comments

Comments
 (0)