From b7719bd486de71ceccdc57c5703de49cdb3f9f77 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Thu, 6 May 2021 13:54:36 +1000 Subject: [PATCH] fix: handle empty deps when cloud run target (#41) * fix: handle empty deps when cloud run target * chore: cleanup comments --- src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index f370bc5..a948a0a 100644 --- a/src/index.js +++ b/src/index.js @@ -110,9 +110,13 @@ async function adaptToCloudRun({utils, serviceId, region, cloudRunBuildDir}) { utils.log.info(`Writing Cloud Run service to ./${serverOutputDir}`); // Prepare Cloud Run package.json - read SvelteKit App 'package.json', modify the JSON, write to serverOutputDir - const pkgjson = JSON.parse(readFileSync('package.json', 'utf-8')); + const pkgjson = JSON.parse(readFileSync(fileURLToPath(new URL('package.json', import.meta.url)), 'utf-8')); pkgjson.scripts.start = 'functions-framework --target=default'; - pkgjson.dependencies['@google-cloud/functions-framework'] = '^1.7.1'; // Peer-dep of this adapter instead? + if (pkgjson.dependencies === undefined) { + pkgjson.dependencies = {}; + } + + pkgjson.dependencies['@google-cloud/functions-framework'] = '^1.7.1'; pkgjson.engines = {node: '14'}; delete pkgjson.type; const data = JSON.stringify(pkgjson, null, 2);