From f855bfb7a18ed9186463e8a04af8e4ef886d3b6a Mon Sep 17 00:00:00 2001 From: Kousuke Ebihara Date: Sun, 15 May 2022 00:24:14 +0900 Subject: [PATCH] fix: reading 'log' error (#157) Co-authored-by: Juan Rodriguez --- src/files/entry.d.ts | 10 ++++++++++ src/files/entry.js | 1 + src/files/firebase-to-svelte-kit.js | 2 +- src/index.js | 5 ++++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/files/entry.d.ts diff --git a/src/files/entry.d.ts b/src/files/entry.d.ts new file mode 100644 index 0000000..aa89f10 --- /dev/null +++ b/src/files/entry.d.ts @@ -0,0 +1,10 @@ +declare module "APP" { + import { App } from "@sveltejs/kit"; + export { App }; +} + +declare module "MANIFEST" { + import { SSRManifest } from "@sveltejs/kit"; + + export const manifest: SSRManifest; +} diff --git a/src/files/entry.js b/src/files/entry.js index b592264..5cfccaa 100644 --- a/src/files/entry.js +++ b/src/files/entry.js @@ -1,3 +1,4 @@ + import { Server } from 'SERVER'; import { manifest } from 'MANIFEST'; import { toSvelteKitRequest } from './firebase-to-svelte-kit.js'; diff --git a/src/files/firebase-to-svelte-kit.js b/src/files/firebase-to-svelte-kit.js index a39cc21..e349c23 100644 --- a/src/files/firebase-to-svelte-kit.js +++ b/src/files/firebase-to-svelte-kit.js @@ -6,7 +6,7 @@ */ export function toSvelteKitRequest(request) { const host = `${request.headers['x-forwarded-proto']}://${request.headers.host}`; - const { href, pathname, searchParams: searchParameters } = new URL(request.url || '', host); + const {href, pathname, searchParams: searchParameters} = new URL(request.url || '', host); return new Request(href, { method: request.method, diff --git a/src/index.js b/src/index.js index 3e4076d..11fa81a 100644 --- a/src/index.js +++ b/src/index.js @@ -25,7 +25,6 @@ const entrypoint = function (options = {}) { builder.log.minor(`Adapter configuration:\n\t${JSON.stringify(options)}`); const { functions, publicDir } = parseFirebaseConfiguration({ firebaseJsonPath, target, sourceRewriteMatch }); ensureStaticResourceDirsDiffer({ source: path.join(process.cwd(), builder.getStaticDirectory()), dest: publicDir }); - const functionsPackageJson = JSON.parse(readFileSync(path.join(functions.source, 'package.json'), 'utf-8')); if (!functionsPackageJson?.main) { throw new Error(`Error reading ${functionsPackageJson}. Required field "main" missing.`); @@ -107,6 +106,10 @@ const entrypoint = function (options = {}) { builder.writeClient(publicDir); builder.log.minor(logRelativeDir('Prerendering static pages to', publicDir)); + const {paths} = await builder.prerender({dest: publicDir}); + writeFileSync(`${dirs.tmp}/manifest.js`, `export const manifest = ${builder.generateManifest({ + relativePath, + })};\n\nexport const prerendered = new Set(${JSON.stringify(paths)});\n`); }, }; };