Skip to content
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

Fix next version check #409

Merged
merged 3 commits into from
May 12, 2024
Merged
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
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", {
conico974 marked this conversation as resolved.
Show resolved Hide resolved
paths: [appPath],
});
const version = require(nextPackageJsonPath)?.version;

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