Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"src/shared/utils/nodeRuntimeSupport.ts",
".env.example",
"scripts/postinstall.mjs",
"scripts/postinstallSupport.mjs",
"scripts/check-supported-node-runtime.ts",
"scripts/sync-env.mjs",
"scripts/native-binary-compat.mjs",
Expand Down
2 changes: 2 additions & 0 deletions scripts/pack-artifact-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const PACK_ARTIFACT_ROOT_ALLOWED_EXACT_PATHS: string[] = [
"scripts/check-supported-node-runtime.ts",
"scripts/native-binary-compat.mjs",
"scripts/postinstall.mjs",
"scripts/postinstallSupport.mjs",
"scripts/sync-env.mjs",
"src/shared/utils/nodeRuntimeSupport.ts",
];
Expand All @@ -89,6 +90,7 @@ export const PACK_ARTIFACT_REQUIRED_PATHS: string[] = [
"package.json",
"scripts/native-binary-compat.mjs",
"scripts/postinstall.mjs",
"scripts/postinstallSupport.mjs",
"src/shared/utils/nodeRuntimeSupport.ts",
];

Expand Down
5 changes: 5 additions & 0 deletions scripts/postinstall.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

import { PUBLISHED_BUILD_ARCH, PUBLISHED_BUILD_PLATFORM } from "./native-binary-compat.mjs";
import { hasStandaloneAppBundle } from "./postinstallSupport.mjs";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -174,6 +175,10 @@ async function fixBetterSqliteBinary() {
}

async function ensureSwcHelpers() {
if (!hasStandaloneAppBundle(ROOT)) {
return;
}

const swcHelpersApp = join(ROOT, "app", "node_modules", "@swc", "helpers");
const swcHelpersRoot = join(ROOT, "node_modules", "@swc", "helpers");

Expand Down
16 changes: 16 additions & 0 deletions scripts/postinstallSupport.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

import { existsSync } from "node:fs";
import { join } from "node:path";

/**
* Detect whether the current install tree contains the published standalone app bundle.
* Source checkouts should not create `app/` during postinstall because Next.js would
* mis-detect it as a competing App Router root and serve 404s for the real `src/app` routes.
*
* @param {string} rootDir
* @returns {boolean}
*/
export function hasStandaloneAppBundle(rootDir) {
return existsSync(join(rootDir, "app", "server.js"));
}
8 changes: 7 additions & 1 deletion tests/unit/pack-artifact-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ test("findUnexpectedArtifactPaths flags app pack files outside the allowlist", (

test("findMissingArtifactPaths flags missing root runtime files in the tarball", () => {
const missingPaths = findMissingArtifactPaths(
["app/server.js", "bin/omniroute.ts", "package.json", "scripts/postinstall.mjs"],
[
"app/server.js",
"bin/omniroute.ts",
"package.json",
"scripts/postinstall.mjs",
"scripts/postinstallSupport.mjs",
],
PACK_ARTIFACT_REQUIRED_PATHS
);

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/postinstall-support.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import test from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";

import { hasStandaloneAppBundle } from "../../scripts/postinstallSupport.mjs";

test("hasStandaloneAppBundle returns false for source checkout without standalone app", () => {
const root = mkdtempSync(join(tmpdir(), "omniroute-postinstall-src-"));

try {
mkdirSync(join(root, "src", "app"), { recursive: true });
assert.equal(hasStandaloneAppBundle(root), false);
} finally {
rmSync(root, { recursive: true, force: true });
}
});

test("hasStandaloneAppBundle returns true for published standalone app bundle", () => {
const root = mkdtempSync(join(tmpdir(), "omniroute-postinstall-standalone-"));

try {
mkdirSync(join(root, "app"), { recursive: true });
writeFileSync(join(root, "app", "server.js"), "export {};\n");
assert.equal(hasStandaloneAppBundle(root), true);
} finally {
rmSync(root, { recursive: true, force: true });
}
});