Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
|
||
| // Runs scripts/template_<name>.js of the app in the current directory, if it | ||
| // exists. The npm scripts prebuild, postbuild, and postinstall of every | ||
| // generated app call this, so a template (or the user, in an ejected app) can |
| /// <reference types="@fastly/js-compute" /> | ||
| import { env } from 'fastly:env'; | ||
| import { PublisherServer } from '@fastly/compute-js-static-publish'; | ||
| import rc from '../static-publish.rc.js'; | ||
| const publisherServer = PublisherServer.fromStaticPublishRc(rc); | ||
|
|
||
| // eslint-disable-next-line no-restricted-globals | ||
| addEventListener("fetch", (event) => event.respondWith(handleRequest(event))); | ||
| async function handleRequest(event) { | ||
|
|
||
| console.log('FASTLY_SERVICE_VERSION', env('FASTLY_SERVICE_VERSION')); | ||
|
|
||
| const request = event.request; | ||
|
|
||
| const response = await publisherServer.serveRequest(request); | ||
| if (response != null) { | ||
| return response; | ||
| } | ||
|
|
||
| // Do custom things here! | ||
| // Handle API requests, serve non-static responses, etc. | ||
|
|
||
| return new Response('Not found', { status: 404 }); | ||
| } | ||
| `, | ||
| }, |
There was a problem hiding this comment.
I'm not thrilled about this code being in a multiline string. Our tools won't be able to do type checking, linting, formatting, etc. If possible it would be much better for the files map to map target names to names of source files in the template's directory so they can be standalone files.
A similar concern exists for templates adding dependencies; if those aren't specified in a package.json then updating them will be a manual process.
|
We close this PR. We will split the 8.1 work again into fewer and larger PRs, to make the review easier. A new PR will replace this PR. The branch stays. Thank you for the review. The new plan includes your feedback: the template files will be real files, not strings in the code. |
Part 3 of 13 of the 8.1 stack (PR 3, item 3). Base: PR 2.
Changes
src/index.jsand its dependencies now come from a template (AppTemplate, inscaffold/templates/). The current app is theplaintemplate, the only one in 8.1. Users cannot select a template yet (that comes in 8.2). A template only adds files:generateApp()throws for a template file thatgenerateApp()writes itself.prebuild,postbuild, andpostinstall. Each one runscompute-js-static-publish run-template-hook <name>, which runsscripts/template_<name>.jsif it exists. The CLI handlesrun-template-hookbefore the banner, so it prints nothing extra.static-publish.rc.jsof a new app hasgeneratedFrom: the template, the version of this package, and the date.Review points
generatedFrom.src/index.jsis the same.Tests
npm teston this branch: 120 passed.Docs
CHANGELOG, README, and
src/cli/CLAUDE.md.🤖 Generated with Claude Code