Skip to content

Commit

Permalink
refactor: introduce a getPackagePath helper (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored Jan 24, 2025
1 parent b4ad0f0 commit 621f414
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/open-next/src/build/createAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function createCacheAssets(options: buildHelper.BuildOptions) {
logger.info("Bundling cache assets...");

const { appBuildOutputPath, outputDir } = options;
const packagePath = path.relative(options.monorepoRoot, appBuildOutputPath);
const packagePath = buildHelper.getPackagePath(options);
const buildId = buildHelper.getBuildId(appBuildOutputPath);
let useTagCache = false;

Expand Down
14 changes: 5 additions & 9 deletions packages/open-next/src/build/createServerBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@ export async function createServerBundle(options: buildHelper.BuildOptions) {

const remainingRoutes = new Set<string>();

const { appBuildOutputPath, monorepoRoot } = options;

const packagePath = path.relative(monorepoRoot, appBuildOutputPath);
const { appBuildOutputPath } = options;

// Find remaining routes
const serverPath = path.join(
appBuildOutputPath,
".next",
"standalone",
packagePath,
".next",
"server",
".next/standalone",
buildHelper.getPackagePath(options),
".next/server",
);

// Find app dir routes
Expand Down Expand Up @@ -118,7 +114,7 @@ async function generateBundle(
// `node_modules` inside `.next/standalone`, and others inside
// `.next/standalone/package/path` (ie. `.next`, `server.js`).
// We need to output the handler file inside the package path.
const packagePath = path.relative(monorepoRoot, appBuildOutputPath);
const packagePath = buildHelper.getPackagePath(options);
fs.mkdirSync(path.join(outputPath, packagePath), { recursive: true });

const ext = fnOptions.runtime === "deno" ? "mjs" : "cjs";
Expand Down
4 changes: 4 additions & 0 deletions packages/open-next/src/build/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ export async function isEdgeRuntime(
}
return (await overrides?.wrapper?.())?.edgeRuntime;
}

export function getPackagePath(options: BuildOptions) {
return path.relative(options.monorepoRoot, options.appBuildOutputPath);
}

0 comments on commit 621f414

Please # to comment.