From 359a1abbe7cce78d52758803e70417399c0d0f97 Mon Sep 17 00:00:00 2001 From: Khue Nguyen Date: Tue, 13 Dec 2022 17:35:12 -0800 Subject: [PATCH 1/2] chore: simplify required server files --- src/ImageOptimizationLambda.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/ImageOptimizationLambda.ts b/src/ImageOptimizationLambda.ts index 5b6af274..96fbd4ed 100644 --- a/src/ImageOptimizationLambda.ts +++ b/src/ImageOptimizationLambda.ts @@ -67,23 +67,15 @@ export class ImageOptimizationLambda extends NodejsFunction { if (!fs.existsSync(modulesPath)) fs.mkdirSync(modulesPath); if (!fs.existsSync(target)) fs.symlinkSync(source, target, 'dir'); - // Read the nextjs server config and write contents to bundle output via hooks - const configFile = 'required-server-files.json'; - const requiredServerFilesPath = path.join(props.nextBuild.nextStandaloneBuildDir, configFile); - const data = fs.readFileSync(requiredServerFilesPath, 'utf-8'); - super(scope, id, { entry: imageOptHandlerPath, runtime: RUNTIME, bundling: { commandHooks: { - beforeBundling(inputDir: string, outputDir: string): string[] { + beforeBundling(_: string, outputDir: string): string[] { // Saves the required-server-files.json to the .next folder - return [ - `echo '${data}' > ${inputDir}/${configFile}`, - `mkdir ${outputDir}/.next`, - `cp ${inputDir}/${configFile} ${outputDir}/.next`, - ]; + const filePath = path.join(props.nextBuild.nextStandaloneBuildDir, 'required-server-files.json'); + return [`mkdir ${outputDir}/.next`, `cp ${filePath} ${outputDir}/.next`]; }, afterBundling() { return []; From ead4f7a258e0dd28853b5439b39ec7ed113f699e Mon Sep 17 00:00:00 2001 From: khuezy Date: Tue, 13 Dec 2022 17:52:10 -0800 Subject: [PATCH 2/2] Update src/ImageOptimizationLambda.ts Co-authored-by: Mischa Spiegelmock --- src/ImageOptimizationLambda.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ImageOptimizationLambda.ts b/src/ImageOptimizationLambda.ts index 96fbd4ed..6a28b1ac 100644 --- a/src/ImageOptimizationLambda.ts +++ b/src/ImageOptimizationLambda.ts @@ -75,7 +75,7 @@ export class ImageOptimizationLambda extends NodejsFunction { beforeBundling(_: string, outputDir: string): string[] { // Saves the required-server-files.json to the .next folder const filePath = path.join(props.nextBuild.nextStandaloneBuildDir, 'required-server-files.json'); - return [`mkdir ${outputDir}/.next`, `cp ${filePath} ${outputDir}/.next`]; + return [`mkdir -p "${outputDir}/.next"`, `cp "${filePath}" "${outputDir}/.next"`]; }, afterBundling() { return [];