Skip to content

Commit

Permalink
Fix next version check (#409)
Browse files Browse the repository at this point in the history
* fix package version

* change variable name

* Create giant-pianos-float.md
  • Loading branch information
conico974 committed May 12, 2024
1 parent c2817fe commit d5efc43
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-pianos-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"open-next": patch
---

Fix next version check
19 changes: 4 additions & 15 deletions packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ function setStandaloneBuildMode(monorepoRoot: string) {
}

function buildNextjsApp(packager: "npm" | "yarn" | "pnpm" | "bun") {
const { nextPackageJsonPath } = options;
const { appPackageJsonPath } = options;
const command =
config.buildCommand ??
(["bun", "npm"].includes(packager)
? `${packager} run build`
: `${packager} build`);
cp.execSync(command, {
stdio: "inherit",
cwd: path.dirname(nextPackageJsonPath),
cwd: path.dirname(appPackageJsonPath),
});
}

Expand All @@ -213,19 +213,8 @@ function printHeader(header: string) {
}

function printNextjsVersion() {
const { appPath } = options;
cp.spawnSync(
"node",
[
"-e",
`"console.info('Next.js v' + require('next/package.json').version)"`,
],
{
stdio: "inherit",
cwd: appPath,
shell: true,
},
);
const { nextVersion } = options;
logger.info(`Next.js version : ${nextVersion}`);
}

function printOpenNextVersion() {
Expand Down
19 changes: 11 additions & 8 deletions packages/open-next/src/build/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ export function normalizeOptions(config: OpenNextConfig, root: string) {
);
const outputDir = path.join(buildOutputPath, ".open-next");

let nextPackageJsonPath: string;
let appPackageJsonPath: string;
if (config.packageJsonPath) {
const _pkgPath = path.join(process.cwd(), config.packageJsonPath);
nextPackageJsonPath = _pkgPath.endsWith("package.json")
appPackageJsonPath = _pkgPath.endsWith("package.json")
? _pkgPath
: path.join(_pkgPath, "./package.json");
} else {
nextPackageJsonPath = findNextPackageJsonPath(appPath, root);
appPackageJsonPath = findNextPackageJsonPath(appPath, root);
}
return {
openNextVersion: getOpenNextVersion(),
nextVersion: getNextVersion(nextPackageJsonPath),
nextPackageJsonPath,
nextVersion: getNextVersion(appPath),
appPackageJsonPath,
appPath,
appBuildOutputPath: buildOutputPath,
appPublicPath: path.join(appPath, "public"),
Expand Down Expand Up @@ -209,9 +209,12 @@ export function getOpenNextVersion(): string {
return require(path.join(__dirname, "../../package.json")).version;
}

export function getNextVersion(nextPackageJsonPath: string): string {
const version = require(nextPackageJsonPath)?.dependencies?.next;
// require('next/package.json').version
export function getNextVersion(appPath: string): string {
// We cannot just require("next/package.json") because it could be executed in a different directory
const nextPackageJsonPath = require.resolve("next/package.json", {
paths: [appPath],
});
const version = require(nextPackageJsonPath)?.version;

if (!version) {
throw new Error("Failed to find Next version");
Expand Down

0 comments on commit d5efc43

Please sign in to comment.