Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeScript error while using SvelteKit. #517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 17 additions & 5 deletions src/lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import customNuxtIndex from '../lib/ui/nuxt/customNuxtIndex.js';
import nuxtGradientBackground from '../lib/ui/nuxt/nuxtGradientBackground.js';
import customLayoutSvelte from '../lib/ui/svelte/customLayoutSvelte.js';
import customPageSvelte from '../lib/ui/svelte/customPageSvelte.js';
import {
serverHooksSvelteJavaScript,
serverHooksSvelteTypeScript,
} from '../lib/ui/svelte/serverHooksSvelte.js';
import Constants from './constants.js';
import gradientBackground from './ui/svelte/gradientBackground.js';

Expand Down Expand Up @@ -263,11 +267,6 @@ function scaffoldSvelte() {
shell: true,
});

shell.cp(
path.join(__dirname, 'ui', 'svelte', 'hooks.server.js'),
path.join('ui', 'src')
);

const customTsConfig = ` {
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
Expand Down Expand Up @@ -328,6 +327,19 @@ function scaffoldSvelte() {

fs.writeFileSync(path.join('ui', viteConfigFileName), customViteConfig);

const serverHooksSvelteFileName = useTypescript
? 'hooks.server.ts'
: 'hooks.server.js';

const serverHooksSvelte = useTypescript
? serverHooksSvelteTypeScript
: serverHooksSvelteJavaScript;

fs.writeFileSync(
path.join('ui', 'src', serverHooksSvelteFileName),
serverHooksSvelte
);

// Remove Sveltekit demo pages and components if found
fs.emptyDirSync(path.join('ui', 'src', 'routes'));

Expand Down
9 changes: 0 additions & 9 deletions src/lib/ui/svelte/hooks.server.js

This file was deleted.

24 changes: 24 additions & 0 deletions src/lib/ui/svelte/serverHooksSvelte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const serverHooksSvelteJavaScript = `
// To enable o1js for the web, we must set the COOP and COEP headers.
// See here for more information: https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp-ui#enabling-coop-and-coep-headers
/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) {
const response = await resolve(event);
response.headers.set('Cross-Origin-Opener-Policy', 'same-origin');
response.headers.set('Cross-Origin-Embedder-Policy', 'require-corp');
return response;
}
`;

export const serverHooksSvelteTypeScript = `
import type { Handle } from "@sveltejs/kit";

// To enable o1js for the web, we must set the COOP and COEP headers.
// See here for more information: https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp-ui#enabling-coop-and-coep-headers
export const handle: Handle = async ({ event, resolve }) => {
const response = await resolve(event);
response.headers.set('Cross-Origin-Opener-Policy', 'same-origin');
response.headers.set('Cross-Origin-Embedder-Policy', 'require-corp');
return response;
}
`;