@fastly/compute-js-static-publish 8.1.0-beta.4 → 8.1.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +9 -6
  2. package/DOCUMENTATION.md +105 -5
  3. package/MIGRATING.md +289 -0
  4. package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/deploy.js +5 -4
  6. package/build/cli/cli/commands/manage/index.d.ts +1 -0
  7. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  8. package/build/cli/cli/commands/manage/index.js +13 -11
  9. package/build/cli/cli/commands/manage/status.d.ts.map +1 -1
  10. package/build/cli/cli/commands/manage/status.js +7 -5
  11. package/build/cli/cli/index.js +15 -1
  12. package/build/cli/cli/managed/fastly-service.d.ts +7 -0
  13. package/build/cli/cli/managed/fastly-service.d.ts.map +1 -1
  14. package/build/cli/cli/managed/fastly-service.js +31 -1
  15. package/build/cli/cli/managed/fingerprint.d.ts +12 -0
  16. package/build/cli/cli/managed/fingerprint.d.ts.map +1 -1
  17. package/build/cli/cli/managed/fingerprint.js +25 -0
  18. package/build/cli/cli/util/config.d.ts +4 -0
  19. package/build/cli/cli/util/config.d.ts.map +1 -1
  20. package/build/cli/cli/util/config.js +33 -0
  21. package/build/cli/cli/util/output.js +1 -1
  22. package/build/server/hono/extensions.d.ts +3 -1
  23. package/build/server/hono/extensions.d.ts.map +1 -1
  24. package/build/server/hono/index.d.ts +11 -4
  25. package/build/server/hono/index.d.ts.map +1 -1
  26. package/build/server/hono/index.js +45 -18
  27. package/build/server/server/index.d.ts +1 -1
  28. package/build/server/server/index.d.ts.map +1 -1
  29. package/build/server/server/publisher-server/index.d.ts +7 -1
  30. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  31. package/build/server/server/publisher-server/index.js +56 -14
  32. package/package.json +3 -2
  33. package/resources/templates/hono/src/index.ts +14 -3
package/CHANGELOG.md CHANGED
@@ -12,9 +12,9 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
12
12
  ### Added
13
13
 
14
14
  - `scaffold --template hono` (and `managed.template: 'hono'` in a managed project): a TypeScript Hono app. `src/index.ts` uses `selectCollection()`, `serveStatic()`, and `serveFallback()` of `@fastly/compute-js-static-publish/hono`, and `fire()` of `@fastly/hono-fastly-compute`. The app has `tsconfig.json`, and `typescript` as a dev dependency; the build does not check types (run `npx tsc`). In a managed project, a change of `managed.template` generates the app again with the new template, and changes the fingerprint.
15
- - Hono extensions for the `hono` template: modules in `hono-extensions/` default-export `defineExtension()` (from `@fastly/compute-js-static-publish/hono`), with a function for each phase that they use: `middleware`, `beforeFiles` (before the published files), and `afterFiles` (for the requests that no published file matches). `c.env` in a module has the types of its bindings. The build bundles them into the app; the packages that the app provides stay imports. Options come from `templateOptions.hono.extensions` and bindings from `templateOptions.hono.bindings`, and `build.hono.extensionsDir` sets another folder. `template init` makes or updates the folder (with a `.gitignore` for `node_modules/`), and `template init --check` fails with the new error code `template-init-needed` if it is out of date. `dev -- --watch` and `npm run dev:watch` also watch the folder. `status --json` has `template`, with the packages that the template provides.
15
+ - Hono extensions for the `hono` template: modules in `hono-extensions/` default-export `defineExtension()` (from `@fastly/compute-js-static-publish/hono`), with a function for each phase that they use: `middleware`, `beforeFiles` (before the published files), and `afterFiles` (for the requests that no published file matches). Each phase function gets the app, the options of the module, and the helpers of the app (`serveStatic()`, `staticResponse()`, `serveFallback()`, `fallbackResponse()`, `isCollectionAvailable()`, and `publisherServer`). `c.env` in a module has the types of its bindings. The build bundles them into the app; the packages that the app provides stay imports. Options come from `templateOptions.hono.extensions` and bindings from `templateOptions.hono.bindings`, and `build.hono.extensionsDir` sets another folder. `template init` makes or updates the folder (with a `.gitignore` for `node_modules/`), and `template init --check` fails with the new error code `template-init-needed` if it is out of date. `dev -- --watch` and `npm run dev:watch` also watch the folder. `status --json` has `template`, with the packages that the template provides.
16
16
  - Examples of Hono extensions in `examples/hono/` (in the repository, not in the npm package): `grip` (realtime streams and Server-Sent Events with Fastly Fanout) and `oauth` (a login with GitHub or Google).
17
- - Hono support: `@fastly/compute-js-static-publish/hono`. `fromStaticPublishRc(rc)` (or `fromPublisherServer(server)`) returns `serveStatic()` (middleware that serves the published files with `serveRequest()`, and calls the next handler if no file matches), `serveFallback()` (for `app.notFound()`: the SPA file or the 404 page), `selectCollection()` (collection selection for a Hono app; it sets `c.var.staticPublisher`, and `serveStatic()` and `serveFallback()` use the selected collection), and `publisherServer`. The type `StaticPublisherVariables` is for the variables of the app. `hono` v4 is an optional peer dependency. This replaces `@fastly/hono-compute-js-static-publish`, which supports only v6 and v7; `MIGRATING.md` has the steps.
17
+ - Hono support: `@fastly/compute-js-static-publish/hono`. `fromStaticPublishRc(rc)` (or `fromPublisherServer(server)`) returns `serveStatic()` (middleware that serves the published files with `serveRequest()`, and calls the next handler if no file matches; the option `onMissing` replaces `collectionSelection.onMissing` for one route), `staticResponse(c)` (the same response for use in a handler, or `null`; never the SPA file or the 404 page), `serveFallback()` (for `app.notFound()`: the SPA file or the 404 page), `fallbackResponse(c)` (the same response for use in a handler, or `null`), `isCollectionAvailable(c)` (whether the selected collection, or another one, is published and not expired), `selectCollection()` (collection selection for a Hono app; it sets `c.var.staticPublisher`, and `serveStatic()` and `serveFallback()` use the selected collection), and `publisherServer`. The type `StaticPublisherVariables` is for the variables of the app. The options `status` and `headers` change the response of a file. `hono` v4 is an optional peer dependency. This replaces `@fastly/hono-compute-js-static-publish`, which supports only v6 and v7; `MIGRATING.md` has the steps.
18
18
  - `--project-dir`: run a command for the app in another directory, for example from the root of the repo in CI. All relative paths are then relative to that directory.
19
19
  - `--version`: print the version of this package. It works in any directory.
20
20
  - `--non-interactive`: the CLI never asks a question, and missing input is an error. It is also on when the `CI` environment variable is set (to a value that is not empty, `false`, or `0`).
@@ -35,24 +35,26 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
35
35
  - In the index, the key of a hidden file is `hidden:` and then the asset key. A collection that has hidden files requires the `hidden` feature, so an app built with 8.0.0 or later (before 8.1) does not serve it. An app built with v7 or with an 8.0 beta does not check `requires`: it serves the collection, but not its hidden files, also when the SPA file or the 404 page is hidden. Build and deploy your app with this version before you publish hidden files.
36
36
  - `publish-content` shows the number of hidden files. `collections list` shows the number of files and of hidden files in each collection, from the index metadata (`fileCount`, `hiddenFileCount`, which `publish-content` writes). For a collection published by an older version, it shows "unknown".
37
37
  - `getMatchingAsset(key, options)`: the second argument can now be an object, `{ applyAuto, includeHidden }`. A boolean (the value of `applyAuto`) continues to work.
38
- - `PublisherServer.serveRequest(request, options)`: the options `collectionName` (the collection for this call only), `pathname` (the path to look up, in place of the URL path), `fallback` (`false`: do not serve the SPA file or the 404 page), and `healthCheck` (`false`: do not answer `/healthz`). Without options, the behavior does not change.
39
- - `PublisherServer.serveFallback(request, { collectionName })`: serves the SPA file or the 404 page, as `serveRequest()` does when no file matches. Use it after `serveRequest()` with `fallback: false`.
38
+ - `PublisherServer.serveRequest(request, options)`: the options `collectionName` (the collection for this call only), `pathname` (the path to look up, in place of the URL path), `fallback` (`false`: do not serve the SPA file or the 404 page), `healthCheck` (`false`: do not answer `/healthz`), and `onMissing` (with collection selection: `'not-found'` or `'default'` for this call, in place of `collectionSelection.onMissing`). Without options, the behavior does not change.
39
+ - `PublisherServer.serveFallback(request, { collectionName, onMissing })`: serves the SPA file or the 404 page, as `serveRequest()` does when no file matches. Use it after `serveRequest()` with `fallback: false`.
40
40
  - Export the types `ServeRequestOptions` and `ServeFallbackOptions`.
41
41
  - Managed projects: `scaffold --managed` writes only `static-publish.project.js` in the current directory, and adds `.static-publish/` and the working directory to `.gitignore`. The project file has the fields of `static-publish.rc.js` at the top level, the fields of `publish-content.config.js` in `publishContent`, and the settings of the generated app in `managed`. `publish-content`, `collections`, and `clean` read it. A directory with both `static-publish.project.js` and `static-publish.rc.js` is an error. The type is `StaticPublishProject`.
42
42
  - Managed projects: `managed.fastlyToml` adds `local_server` and `setup` sections to the generated `fastly.toml`, for example a local Secret Store for `dev`. A resource with the name of one that the CLI writes is an error. `local_server` does not change the fingerprint.
43
43
  - `publish-content` purges the service of `managed.serviceId` in a managed project (after `--fastly-service-id` and `FASTLY_SERVICE_ID`, before `fastly.toml`).
44
44
  - Managed projects: the `dev` command generates the app in `.static-publish/app/`, installs it with `npm ci` only when its `package.json` or lockfile changed, and runs `fastly compute serve`. The app uses the lockfile of its template (`resources/templates/<name>/package-lock.json`), and the copy of this package that runs the CLI through a `file:` link.
45
- - Managed projects: `deploy` deploys the generated app only if its fingerprint changed (`--force` deploys anyway), records the fingerprint in the comment of the service version, and writes the Service ID of the first deploy (a new service) into `managed.serviceId`. A Service ID from `--fastly-service-id` or `FASTLY_SERVICE_ID` does not change the project file. `status` shows if a deploy is necessary, and the preview URLs. `dev` and `deploy` stop if `managed.staticPublishVersion` is not the version that runs; `upgrade` (or `--auto-upgrade` with a newer CLI) moves the project to it. In an ejected app, `deploy` runs `fastly compute publish`, with `--comment`, `--fastly-service-id`, and `--fastly-api-token` (`--force` and `--auto-upgrade` are errors there), and `status` shows the Service ID. Options after `--` go to `fastly compute deploy` (or `fastly compute publish`), for example `-- --status-check-timeout=180`. `deploy` refuses `--comment`, `--service-id`, `--token`, `--package`, `--dir`, and `--env` there.
45
+ - Managed projects: `deploy` deploys the generated app only if its fingerprint changed (`--force` deploys anyway), records the fingerprint in the comment of the service version, and writes the Service ID of the first deploy (a new service) into `managed.serviceId`. A Service ID from `--fastly-service-id` or `FASTLY_SERVICE_ID` does not change the project file. A version cloned by hand (no comment, the same package as the newest earlier version with a fingerprint) counts as that fingerprint. `status` shows if a deploy is necessary, and the preview URLs. `dev` and `deploy` stop if `managed.staticPublishVersion` is not the version that runs; `upgrade` (or `--auto-upgrade` with a newer CLI) moves the project to it. In an ejected app, `deploy` runs `fastly compute publish`, with `--comment`, `--fastly-service-id`, and `--fastly-api-token` (`--force` and `--auto-upgrade` are errors there), and `status` shows the Service ID. Options after `--` go to `fastly compute deploy` (or `fastly compute publish`), for example `-- --status-check-timeout=180`. `deploy` refuses `--comment`, `--service-id`, `--token`, `--package`, `--dir`, and `--env` there.
46
46
  - S3 mode: `s3.secretStoreLinkName` in `static-publish.rc.js` (in a managed project, in `static-publish.project.js`) sets the resource link name of the Secret Store with the S3 credentials. The default is `S3_CREDENTIALS`. The generated `fastly.toml` uses it. A call to `setSecretStoreForS3Credentials()` in the code of the app is used in place of it. The generated `fastly.toml` also uses `s3.fastlyBackendName` (the name of the backend, default `s3_storage`), and managed mode keeps both fields in the app.
47
47
  - Managed projects: `eject` converts a managed project into an ejected app in `./compute-js` (or `--dir`): the app that `deploy` would deploy, `static-publish.rc.js` (with `generatedFrom`) and `publish-content.config.js` from the project file (the paths point at the same directories), and this package pinned to the version that runs. It needs a published version, and it stops for functions or regular expressions in `publishContent`.
48
48
  - Docs: README "Managed and ejected apps", with the API token scopes for CI. `MIGRATING.md`: move an existing app to managed mode.
49
49
  - `--json`: `publish-content`, `collections list`, `collections delete`, `collections promote`, `status`, `deploy` (in a managed project), and `--version` write their result as one JSON object to stdout, with `schemaVersion: 1`. The log lines then go to stderr. With another command, `--json` is an error. The `publish-content` result shows the purge result for each environment (`purge.ok` is `false` if a purge failed).
50
50
  - Error codes: with `--json`, an error gives `{ "schemaVersion": 1, "error": { "code", "message" } }`. The README lists the codes, for example `collection-name-invalid` and `credentials-missing`.
51
51
  - README: "Using the CLI in CI", with the exit codes, the JSON output, and the error codes.
52
+ - `PublisherServer`: the options `status` and `headers` of `serveRequest()` and `serveFallback()` change the status and the headers of the response of a file, for one call. For a status other than `2xx`, the server does not evaluate the preconditions of the request.
52
53
 
53
54
  ### Changed
54
55
 
55
- - The npm package includes `CHANGELOG.md`.
56
+ - The npm package includes `CHANGELOG.md` and `MIGRATING.md`.
57
+ - A command for a managed project or an app (for example `status` or `deploy`) in a directory that has no `static-publish.project.js` or `static-publish.rc.js` now stops with an error that names the directories nearby that have one. Before, the CLI started scaffolding, and showed an unclear error for the command.
56
58
  - Scaffolding: the `src/index.js` of the `plain` app calls `serveRequest()` with `fallback: false`, then has the place for your own code, and then calls `serveFallback()` for the SPA file or the 404 page. Thus your code runs for each request that no published file matches, also when the collection has a fallback page. Code that must run before the published files goes before `serveRequest()`.
57
59
  - Scaffolding: the app has `@fastly/compute-js-static-publish` in `dependencies`. It was in `devDependencies`. The code of the app imports it, and the `postinstall` script of the app runs it, so `npm ci --omit=dev` needs it.
58
60
  - `PublisherServer.setResponseCache()`: the default of `maxBodySize` is now 16 MiB. It was 8 MiB.
@@ -76,6 +78,7 @@ This file does not list v7 releases after 7.0.8, or v6 releases after 6.3.0. For
76
78
 
77
79
  ### Fixed
78
80
 
81
+ - `PublisherServer`: a request for the 404 page with an `If-None-Match` that matched its `ETag` (or an `If-Modified-Since` after its time) got a `304` with no body. Now the server evaluates the preconditions only for a `2xx` response, as RFC 9110 says, so the response is always the `404` with the page.
79
82
  - `collections promote` now purges the target collection, as `publish-content` and `collections delete` do. Before, after a promote (for example to `live`), the service could serve the old content of the target from the cache until it expired. The new options `--fastly-service-id` and `--purge-environment` work as in `publish-content`. If a Service ID is found, the command needs an API token, also in S3 mode, and stops before it writes anything if the token is missing.
80
83
  - `collections promote --local`: the target collection got the index and settings files of the source collection. Thus a later `publish-content --local` to the source also changed the target, for example `live` after a promote from `staging`. Now the target has its own files. The KV Store and S3 modes were not affected.
81
84
  - `scaffold --storage-mode s3` without `--s3-endpoint` (a bucket on AWS): the command stopped with an uncaught `CredentialsProviderError` when the computer had no usable AWS credentials. Now it computes the host name of the bucket (`<bucket>.s3.<region>.amazonaws.com`, the same host name that the server uses), with no credentials and no network. A bucket name with a dot needs `--s3-endpoint`, and the command says so.
package/DOCUMENTATION.md CHANGED
@@ -304,7 +304,7 @@ npx @fastly/compute-js-static-publish@beta deploy
304
304
 
305
305
  `deploy` generates the app, installs it if necessary, and runs `fastly compute build` and `fastly compute deploy`, only if the app changed. It needs a Fastly API token (`FASTLY_API_TOKEN` or `--fastly-api-token`). Options after `--` go to `fastly compute deploy`, for example `deploy -- --status-check-timeout=180`. `deploy` refuses `--comment`, `--service-id` (`-s`), `--token` (`-t`), `--package` (`-p`), `--dir` (`-C`), and `--env` there, because it sets them, or they deploy something else.
306
306
 
307
- - **The fingerprint** is a SHA-256 of the generated app and the version of this package. It does not depend on the content, on `publishContent`, on the Service ID, or on the path of this package on your computer. `deploy` writes it into the comment of the new service version (`static-publish <version> fp:<fingerprint>`, then ` | <text>` with `--comment <text>`, for example a commit SHA). The next `deploy` reads the comment of the active version, and does nothing if the fingerprint is the same. `--force` deploys anyway.
307
+ - **The fingerprint** is a SHA-256 of the generated app and the version of this package. It does not depend on the content, on `publishContent`, on the Service ID, or on the path of this package on your computer. `deploy` writes it into the comment of the new service version (`static-publish <version> fp:<fingerprint>`, then ` | <text>` with `--comment <text>`, for example a commit SHA). The next `deploy` reads the comment of the active version, and does nothing if the fingerprint is the same. A version that you clone by hand, for example to add a backend, has no comment, but it keeps the package of the version that it came from. Thus, if the active version has no fingerprint, `deploy` and `status` use the newest earlier version that has one, if the two versions have the same package. `--force` deploys anyway.
308
308
  - **The first deploy** makes a new service (the Fastly CLI asks for its name and domain, unless `--non-interactive`), and writes its ID into `managed.serviceId`. Commit the project file then. To deploy to a service that exists, use `--fastly-service-id` or `FASTLY_SERVICE_ID`. These do not change `managed.serviceId`: to make a service that exists the service of the project, set `managed.serviceId` in the project file. With S3 storage, the first deploy must be done on your computer, because the Fastly CLI asks for the S3 credentials of the Secret Store; with `--non-interactive`, it is an error.
309
309
  - `status` shows the fingerprint of the app, the fingerprint of the active version, and if a deploy is necessary, and the preview URLs of [collection selection](#-previews-collection-selection). Without an API token, the deployed fingerprint is unknown.
310
310
 
@@ -1060,10 +1060,13 @@ async function handleRequest(request) {
1060
1060
  | `pathname` | The path to look up, in place of the path of the request URL. It must be decoded, and it must start with `/`. | The decoded path of the request URL |
1061
1061
  | `fallback` | `false`: if no file matches, do not serve the SPA file or the 404 page. Return `null`. | `true` |
1062
1062
  | `healthCheck` | `false`: do not answer `/healthz`. | `true` |
1063
+ | `onMissing` | With [collection selection](#-previews-collection-selection): what to do for this call when the selected collection is not published or has expired. `'not-found'`: the `404` below. `'default'`: serve the default collection, as a normal response of the default collection (its headers, without `X-Robots-Tag: noindex`). Without collection selection, it does nothing. | `collectionSelection.onMissing` |
1064
+ | `status` | The status of the response of a file (also of the SPA file and the 404 page). For a status other than `2xx`, the server does not evaluate the preconditions of the request (`If-None-Match` and the others), so the response always has the body. It does not change other responses, such as the `404` of a collection that is not available. | The status of the file: `200`, or `404` for the 404 page |
1065
+ | `headers` | Headers to set on the response of a file. Each one replaces the header of the same name. | |
1063
1066
 
1064
1067
  `serveRequest()` returns `null` for a method other than `GET` and `HEAD`, and when there is no response (no file matches, and there is no fallback page or `fallback` is `false`). If the default collection has no settings in storage, the response is `500`. A collection other than the default collection that is not published, or that expired, gets a plain-text `404` that names it.
1065
1068
 
1066
- `serveFallback(request, { collectionName })` serves the SPA file (`200`) or the 404 page (`404`) of the collection, as `serveRequest()` does when no file matches. It returns `null` for a method other than `GET` and `HEAD`, for a client that does not accept HTML, or when the collection has no fallback page. Use it with `fallback: false`, to run your own logic between the files and the fallback page. The scaffolded app (`src/index.js`) uses this order:
1069
+ `serveFallback(request, { collectionName, onMissing, status, headers })` serves the SPA file (`200`) or the 404 page (`404`) of the collection, as `serveRequest()` does when no file matches. It returns `null` for a method other than `GET` and `HEAD`, for a client that does not accept HTML, or when the collection has no fallback page. Use it with `fallback: false`, to run your own logic between the files and the fallback page. The scaffolded app (`src/index.js`) uses this order:
1067
1070
 
1068
1071
  ```js
1069
1072
  async function handleRequest(request) {
@@ -1212,7 +1215,7 @@ hono-extensions/
1212
1215
  - `beforeFiles`: before the published files.
1213
1216
  - `afterFiles`: after the published files. These handlers get only the requests that no published file matches, for example to make a page for a path that has no file, before the 404 page. The published files are served only for `GET` and `HEAD`, so these handlers also get all other methods.
1214
1217
 
1215
- A module default-exports `defineExtension()`. Give it a function for each phase that the module uses. Each function gets the Hono app and the options of the module, and adds handlers with `app.use()`, `app.get()`, `app.post()`, and the other methods of Hono. With only a function in place of the object, the function is the `middleware` phase:
1218
+ A module default-exports `defineExtension()`. Give it a function for each phase that the module uses. Each function gets the Hono app, the options of the module, and the helpers of the app (see below), and adds handlers with `app.use()`, `app.get()`, `app.post()`, and the other methods of Hono. With only a function in place of the object, the function is the `middleware` phase:
1216
1219
 
1217
1220
  ```ts
1218
1221
  // hono-extensions/10-header.ts
@@ -1257,6 +1260,68 @@ templateOptions: {
1257
1260
  },
1258
1261
  ```
1259
1262
 
1263
+ **The files step:** between `beforeFiles` and `afterFiles`, the app has a fixed step that serves the published files with `serveStatic()`. It is not a phase, and a module cannot remove it. A module can serve files in another way before it: a request that the module answers does not get to this step, and a request that the module passes on with `next()` does.
1264
+
1265
+ **Helpers:** the third argument of each phase function has the `serveStatic()`, `staticResponse()`, `serveFallback()`, `fallbackResponse()`, `isCollectionAvailable()`, and `publisherServer` that the app uses (see [Using Hono](#-using-hono)). They are made once when the app starts, with the same `collectionSelection`, so a module can serve published files in its own place in the order, with its own rules.
1266
+
1267
+ For example, a module that runs before a login check, and serves `/theme/*` on a preview: from the selected collection, or from the default collection if the preview is missing, and with a plain `404` (not the 404 page of the collection, which would show the preview without a login). Without a preview, the module does nothing, and the app serves the request as usual. In Hono, a handler cannot skip the handlers that come after it in the same `app.use()`, so the module decides first whether it takes part. Two ways to write it, which do the same:
1268
+
1269
+ ```ts
1270
+ // hono-extensions/10-theme.ts: one handler with staticResponse()
1271
+ import { defineExtension } from '@fastly/compute-js-static-publish/hono';
1272
+
1273
+ export default defineExtension((app, options, { staticResponse }) => {
1274
+ app.use('/theme/*', async (c, next) => {
1275
+ if (c.var.staticPublisher.collectionName == null) {
1276
+ return next(); // not a preview: the app serves it as usual
1277
+ }
1278
+ return await staticResponse(c, { onMissing: 'default' }) ?? c.text('Not found', 404);
1279
+ });
1280
+ });
1281
+ ```
1282
+
1283
+ ```ts
1284
+ // hono-extensions/10-theme.ts: serveStatic() with except() of hono/combine
1285
+ import { defineExtension } from '@fastly/compute-js-static-publish/hono';
1286
+ import { except } from 'hono/combine';
1287
+
1288
+ export default defineExtension((app, options, { serveStatic }) => {
1289
+ const notPreview = (c) => c.var.staticPublisher.collectionName == null;
1290
+ app.use('/theme/*', except(notPreview,
1291
+ serveStatic({ onMissing: 'default' }),
1292
+ (c) => c.text('Not found', 404),
1293
+ ));
1294
+ });
1295
+ ```
1296
+
1297
+ `except(condition, ...middleware)` skips the middleware when the condition is true, and runs it in order otherwise. `serveStatic()` calls the next middleware when no file matches; `staticResponse()` returns `null`. To give the normal 404 page in place of the plain `404`, use `return c.notFound()`.
1298
+
1299
+ With `onMissing: 'default'`, a missing preview gets a normal response of the default collection, with its headers. When the preview is published, the next request gets the file of the preview: `PublisherServer` checks the selected collection before it reads the response cache. These examples are for a `host`, `query`, `cookie`, or `header` source. With a `path` source, the request path has the prefix (for example `/_preview/pr-1/theme/site.css`), so the route `/theme/*` does not match it: add the handler on `*`, and check `c.var.staticPublisher.pathname`, the path without the prefix. `serveStatic()` and `staticResponse()` look up that path.
1300
+
1301
+ For example, a module that runs after a login check, and shows the page `/preview-not-found/` of the default collection, with a `404`, when the selected preview is not available. Because it is a module, it can come after the login check, so that a visitor who is not logged in cannot learn which previews exist:
1302
+
1303
+ ```ts
1304
+ // hono-extensions/30-preview-not-found.ts
1305
+ import { defineExtension } from '@fastly/compute-js-static-publish/hono';
1306
+
1307
+ export default defineExtension((app, options, { isCollectionAvailable, staticResponse }) => {
1308
+ app.use('*', async (c, next) => {
1309
+ if (await isCollectionAvailable(c)) {
1310
+ return next();
1311
+ }
1312
+ return await staticResponse(c, { path: '/preview-not-found/', collectionName: null, status: 404 })
1313
+ ?? c.text('Preview not found', 404);
1314
+ });
1315
+ });
1316
+ ```
1317
+
1318
+ **`publisherServer` in a module:** the app has one `PublisherServer` for all requests. Use the other helpers where you can: they use the selected collection, and the path without the prefix of a `path` source. In a handler, a module can call these methods of `publisherServer`:
1319
+
1320
+ - `isCollectionAvailable()`, `serveRequest()`, `serveFallback()`, and `resolveCollection()`.
1321
+ - The methods that read the collection of the request: `getServerConfig()`, `getStaticItems()`, `getAssetEntryMap()`, `getMatchingAsset()`, and `testExtendedCache()`. They use the collection of the last `serveRequest()` or `serveFallback()` in the request (also through `serveStatic()` and the other helpers), or of `beginRequest()`, which uses the active collection, not the selected one. If neither ran in the request, call `publisherServer.beginRequest(c.req.raw)` first.
1322
+
1323
+ Do not call the `set…()` methods (`setActiveCollectionName()`, `setCollectionSelection()`, `setResponseCache()`, and the others) in a handler: they change the server for all requests. In the phase function, which runs one time when the app starts, they change the configuration of the whole app. Do not call the lower-level methods (`serveAsset()`, `serveCached()`, `loadAssetVariant()`, `handlePreconditions()`, and `findAcceptEncodingsGroups()`). Use `staticResponse()` and `fallbackResponse()` in their place.
1324
+
1260
1325
  **Bindings** put Fastly resources on `c.env`, as `buildFire()` of `@fastly/hono-fastly-compute` does. A module declares the bindings that it uses in the first argument of `defineExtension()`, and `c.env` in its handlers has their types, for example `ConfigStore | undefined` for `'ConfigStore:site_config'` (`undefined` if the resource does not exist or is not linked to the service). `templateOptions.hono.bindings` adds bindings for the app. The same name with the same resource in two places is allowed. The same name with two different resources stops the build, and the message names both places. `c.var` is not typed in a module, so that a module can set its own variables.
1261
1326
 
1262
1327
  **Errors** in a module stop the build, and the message names the file: a default export that is not `defineExtension()`, an object with no phase, a key that is not a phase, or a phase that is not a function.
@@ -1319,7 +1384,10 @@ fire(app);
1319
1384
  `fromStaticPublishRc(rc)` returns:
1320
1385
 
1321
1386
  - `serveStatic(options?)`: middleware that serves the file that matches the request. If no file matches, or the method is not `GET` or `HEAD`, it calls the next handler, so a route after it gets the request. It does not serve the SPA file or the 404 page, and it does not answer `/healthz`.
1387
+ - `staticResponse(c, options?)`: the same response as `serveStatic()`, for use inside a handler: the response of the file that matches the request, or `null` if no file matches or the method is not `GET` or `HEAD`. It takes the options of `serveStatic()`. Like `serveStatic()`, it never returns the SPA file or the 404 page.
1322
1388
  - `serveFallback(options?)`: for `app.notFound()`. It serves the SPA file or the 404 page. If there is neither, or the client does not accept HTML, it gives Hono's default 404 response.
1389
+ - `fallbackResponse(c, options?)`: the response of the SPA file or the 404 page, for use inside a handler, or `null` if there is neither, the client does not accept HTML, or the method is not `GET` or `HEAD`. It takes the options of `serveFallback()`.
1390
+ - `isCollectionAvailable(c, collectionName?)`: `true` if the collection is published, has not expired, and this version of the app can serve it. Without `collectionName`, it checks the collection that `selectCollection()` selected, or else the active collection. `collectionName` is as in the option of `serveStatic()`.
1323
1391
  - `selectCollection()`: middleware that selects the collection of each request with the [`collectionSelection`](#-previews-collection-selection) of `static-publish.rc.js`. It returns the redirects of the selection (a `sticky` source, and the activate and reset paths of the `cookie` source), and sets `c.var.staticPublisher`. Then `serveStatic()` and `serveFallback()` use the selected collection. For a `path` source, `serveStatic()` looks up the path without the prefix.
1324
1392
  - `publisherServer`: the `PublisherServer`, to configure it. For example, `publisherServer.setResponseCache({ maxAge: 3600 })`.
1325
1393
 
@@ -1333,6 +1401,9 @@ If you make the `PublisherServer` yourself, use `fromPublisherServer(publisherSe
1333
1401
  | `path` | The path to serve, in place of the request path. For example, `./favicon.ico`. |
1334
1402
  | `rewriteRequestPath` | `(path, c) => string`. Changes the request path before it is resolved against `root`. |
1335
1403
  | `collectionName` | The collection: a string, `null` for the default collection, or `(c) => string \| null \| undefined`. Without it, or if the function returns `undefined`, the collection is the one that `selectCollection()` selected, or else the active collection. |
1404
+ | `onMissing` | With collection selection: `'not-found'` or `'default'` when the selected collection is not published or has expired, for this route only. The default is `collectionSelection.onMissing`. With `'default'`, the response is a normal response of the default collection, with its headers (no `X-Robots-Tag: noindex`). |
1405
+ | `status` | The status of the response of a file. For a status other than `2xx`, the preconditions of the request are not evaluated, so the response always has the body. See the [options of `serveRequest()`](#options-of-serverequest). |
1406
+ | `headers` | Headers to set on the response of a file. Each one replaces the header of the same name. |
1336
1407
 
1337
1408
  For example, to serve `/assets/*` from the `static` directory:
1338
1409
 
@@ -1340,7 +1411,36 @@ For example, to serve `/assets/*` from the `static` directory:
1340
1411
  app.use('/assets/*', serveStatic({ root: './static', rewriteRequestPath: (path) => path.replace(/^\/assets/, '') }));
1341
1412
  ```
1342
1413
 
1343
- `serveFallback()` takes the `collectionName` option, too. To give a default to all the middleware, pass it to `fromStaticPublishRc(rc, { collectionName })`. An option in a call replaces the default.
1414
+ `staticResponse()` is for a handler that decides itself whether to serve a file. For example, to serve `/theme/*` for a preview from the selected collection, or from the default collection if the preview is missing, and with a plain `404` and never the 404 page of the collection:
1415
+
1416
+ ```ts
1417
+ app.use('/theme/*', async (c, next) => {
1418
+ if (c.var.staticPublisher.collectionName == null) {
1419
+ return next(); // not a preview
1420
+ }
1421
+ return await staticResponse(c, { onMissing: 'default' }) ?? c.text('Not found', 404);
1422
+ });
1423
+ ```
1424
+
1425
+ To serve a page with another status, use `status`. For example, a `404` with the page `/preview-not-found/` of the default collection, when the selected preview is not available:
1426
+
1427
+ ```ts
1428
+ app.use('*', async (c, next) => {
1429
+ if (await isCollectionAvailable(c)) {
1430
+ return next();
1431
+ }
1432
+ return await staticResponse(c, { path: '/preview-not-found/', collectionName: null, status: 404 })
1433
+ ?? c.text('Preview not found', 404);
1434
+ });
1435
+ ```
1436
+
1437
+ `fallbackResponse()` is the same for the SPA file or the 404 page. For example, a `410` with the 404 page of the site, for a removed page:
1438
+
1439
+ ```ts
1440
+ app.get('/blog/removed-post', async (c) => await fallbackResponse(c, { status: 410 }) ?? c.text('Gone', 410));
1441
+ ```
1442
+
1443
+ `serveFallback()` and `fallbackResponse()` take the `collectionName`, `onMissing`, `status`, and `headers` options, too. To give a default to all the middleware, pass it to `fromStaticPublishRc(rc, { collectionName, onMissing })`. An option in a call replaces the default.
1344
1444
 
1345
1445
  In TypeScript, use `StaticPublisherVariables` for the variables of the app, so that `c.var.staticPublisher` has a type:
1346
1446
 
@@ -1541,7 +1641,7 @@ In an ejected app, `status --json` gives `{ "schemaVersion": 1, "mode": "ejected
1541
1641
  | `config-invalid` | `2` | `static-publish.rc.js`, `static-publish.project.js`, or `publish-content.config.js` cannot be loaded, or is not valid |
1542
1642
  | `collection-name-invalid` | `2` | A collection name breaks the [rule](#-collections-publish-preview-promote) |
1543
1643
  | `collection-not-found` | `2` | The command needs a collection that does not exist |
1544
- | `project-dir-not-found` | `2` | `--project-dir` is not a directory, or has no config file |
1644
+ | `project-dir-not-found` | `2` | `--project-dir` is not a directory, or has no config file. Also a command for a project or an app (for example `status`) in a directory with no config file. |
1545
1645
  | `json-not-supported` | `2` | `--json` with a command that does not support it |
1546
1646
  | `credentials-missing` | `2` | An API token or S3 credentials are necessary, but not given |
1547
1647
  | `version-mismatch` | `2` | `managed.staticPublishVersion` is not the version of the CLI that runs |
package/MIGRATING.md ADDED
@@ -0,0 +1,289 @@
1
+ # Migration Guide
2
+
3
+ New major versions of `@fastly/compute-js-static-publish` can involve changes to the files that
4
+ are generated during scaffolding. For this reason, it is recommended that you re-scaffold your application.
5
+
6
+ This is straightforward if you're using `compute-js-static-publisher` out-of-the-box. Otherwise, read on.
7
+
8
+ > [!NOTE]
9
+ > This document is under construction.
10
+ >
11
+
12
+ ## Move an existing app to managed mode (8.1)
13
+
14
+ You do not have to do this. An ejected app (a `compute-js/` directory with `static-publish.rc.js`) continues to work.
15
+ In managed mode, this package generates the app from one file, `static-publish.project.js`, and you upgrade by
16
+ changing the version of this package. See "Managed and ejected apps" in `README.md`.
17
+
18
+ > [!IMPORTANT]
19
+ > Managed mode generates the app from a template: `plain` (the default) or `hono`. If you changed `src/index.js` (or
20
+ > other files of the app), move your changes into options of the project file, or into Hono extensions (see
21
+ > [An app with changes to `src/index.js`](#an-app-with-changes-to-srcindexjs)), or keep your app ejected.
22
+
23
+ These steps move a project with this layout. Change the paths to match your project:
24
+
25
+ ```
26
+ my-site/
27
+ ├── public/
28
+ └── compute-js/ ← static-publish.rc.js, publish-content.config.js, fastly.toml, ...
29
+ ```
30
+
31
+ 1. In `my-site/`, add this package as a dev dependency at 8.1.0 or later, so that the version is pinned:
32
+
33
+ ```sh
34
+ npm install --save-dev @fastly/compute-js-static-publish
35
+ ```
36
+
37
+ 2. Make `my-site/static-publish.project.js`. Paths in it are relative to `my-site/`:
38
+
39
+ ```js
40
+ /** @type {import('@fastly/compute-js-static-publish').StaticPublishProject} */
41
+ const project = {
42
+ // From compute-js/static-publish.rc.js: the storage fields (kvStore or s3), publishId,
43
+ // defaultCollectionName, and collectionSelection, if you have it. Do not copy generatedFrom.
44
+ storageMode: "kv-store",
45
+ kvStore: { kvStoreName: "site-content" },
46
+ publishId: "default",
47
+ defaultCollectionName: "live",
48
+ // A new working directory beside the project file.
49
+ staticPublisherWorkingDir: "./static-publisher",
50
+
51
+ // The contents of compute-js/publish-content.config.js, with rootDir relative to my-site/
52
+ // ('../public' becomes './public').
53
+ publishContent: {
54
+ rootDir: "./public",
55
+ server: { /* ... */ },
56
+ },
57
+
58
+ managed: {
59
+ // From compute-js/fastly.toml: name, description, authors, and service_id.
60
+ name: "my-site",
61
+ description: "My site",
62
+ authors: [ "me@example.com" ],
63
+ serviceId: "SERVICE_ID",
64
+ // The version of this package that you installed in step 1.
65
+ staticPublishVersion: "8.1.0",
66
+ },
67
+ };
68
+
69
+ export default project;
70
+ ```
71
+
72
+ If the app has no service yet, write the line ` serviceId: undefined,` (exactly), so that the first `deploy`
73
+ writes the Service ID into it.
74
+
75
+ 3. Add these lines to `my-site/.gitignore`:
76
+
77
+ ```
78
+ /.static-publish/
79
+ /static-publisher/
80
+ ```
81
+
82
+ 4. In `my-site/`, check the project, publish to the local KV Store, and run the app:
83
+
84
+ ```sh
85
+ npx compute-js-static-publish status
86
+ npx compute-js-static-publish publish-content --local
87
+ npx compute-js-static-publish dev
88
+ ```
89
+
90
+ The CLI uses only the files of the directory where it runs, so `compute-js/` has no effect here.
91
+
92
+ 5. Deploy. The first `deploy` deploys the generated app to the service of `managed.serviceId`, because the active
93
+ version has no fingerprint yet:
94
+
95
+ ```sh
96
+ FASTLY_API_TOKEN=... npx compute-js-static-publish deploy
97
+ ```
98
+
99
+ The collections in storage do not change. Publish again only to change the content.
100
+
101
+ 6. When the steps above work, take `compute-js/` out of the repo, and commit `static-publish.project.js`.
102
+
103
+ ### An app with changes to `src/index.js`
104
+
105
+ Managed mode generates `src/index.js` again for each build, so your changes to it would be lost. With the `hono`
106
+ template, you can keep your code in Hono extensions: modules in the folder `hono-extensions/`, beside the project file.
107
+ The build bundles them into the app. Code that ran before `serveRequest()`, for example a redirect of an old host name,
108
+ a login check, or a proxy to another service, goes into a `middleware` or `beforeFiles` phase. Code that ran when no
109
+ file matched, for example a special page for a path, goes into an `afterFiles` phase. Each module gets its own options,
110
+ and declares the Fastly resources that it uses (bindings).
111
+
112
+ 1. In step 2, add `template: "hono"` to `managed`.
113
+ 2. In `my-site/`, make the folder, and install its packages:
114
+
115
+ ```sh
116
+ npx compute-js-static-publish template init
117
+ cd hono-extensions
118
+ npm install
119
+ ```
120
+
121
+ 3. Move each part of your code into a module. See "Hono extensions" in `README.md` for the phases, the options, and
122
+ the bindings, and `examples/hono/` in the repository for two complete examples.
123
+ 4. Continue with step 3 above. `dev` and `deploy` build the app with your modules.
124
+
125
+ ## Move from `@fastly/hono-compute-js-static-publish` (8.1)
126
+
127
+ `@fastly/hono-compute-js-static-publish` supports v6 and v7 of this package. From 8.1, this package has Hono support itself, as `@fastly/compute-js-static-publish/hono`. First upgrade the app to v8 (see [Upgrade from v7 to v8](#upgrade-from-v7-to-v8)). Then:
128
+
129
+ 1. Remove the old package, and add the packages that a Hono app uses on Compute:
130
+
131
+ ```sh
132
+ npm uninstall @fastly/hono-compute-js-static-publish
133
+ npm install hono @fastly/hono-fastly-compute
134
+ ```
135
+
136
+ 2. Change the code. `fromStaticPublishRc()` now returns an object, not the `serveStatic` function:
137
+
138
+ ```js
139
+ // Before
140
+ import { fire } from 'hono/service-worker';
141
+ import { fromStaticPublishRc } from '@fastly/hono-compute-js-static-publish';
142
+ const serveStatic = fromStaticPublishRc(rc);
143
+
144
+ // After
145
+ import { fire } from '@fastly/hono-fastly-compute';
146
+ import { fromStaticPublishRc } from '@fastly/compute-js-static-publish/hono';
147
+ const { serveStatic, serveFallback } = fromStaticPublishRc(rc);
148
+ ```
149
+
150
+ Use `fire()` from `@fastly/hono-fastly-compute`, not from `hono/service-worker`. By default, the handler of `hono/service-worker` sends each 404 response to `fetch()`, and Compute has no default backend.
151
+
152
+ 3. Add `app.notFound(serveFallback())`. `serveStatic()` does not serve the SPA file or the 404 page.
153
+
154
+ 4. Change the types in the JSDoc of your config files to the main package, for example `import('@fastly/compute-js-static-publish').StaticPublishRc`. The `/hono` export does not have these types.
155
+
156
+ Differences of `serveStatic()`:
157
+
158
+ - It serves files with `PublisherServer.serveRequest()`. Thus it uses `autoIndex`, `autoExt`, the compressed variants, and the response cache. The old package looked up the request path in the index directly.
159
+ - It applies `publicDirPrefix` (deprecated). If it is set, `root` is relative to it.
160
+ - It serves only `GET` and `HEAD`. For other methods, it calls the next handler.
161
+ - For previews, use `selectCollection()` with `collectionSelection` in `static-publish.rc.js` (see [Using Hono](./README.md#-using-hono)).
162
+
163
+ ## Upgrade from v7 to v8
164
+
165
+ v8 can use the files that v7 published. The storage key layout did not change. v8 also accepts the v7 format of
166
+ `static-publish.rc.js` (`kvStoreName` at the top level). Thus, an app that uses the KV Store does not need a new
167
+ scaffold.
168
+
169
+ To upgrade an app that uses the KV Store:
170
+
171
+ 1. In the `compute-js/` directory of your app, install v8:
172
+
173
+ ```sh
174
+ npm install @fastly/compute-js-static-publish@beta
175
+ ```
176
+
177
+ 2. Make sure that the CLI can get a Fastly API token. Set the `FASTLY_API_TOKEN` environment variable, or use
178
+ `--fastly-api-token`. v8 no longer uses the token logged in by the Fastly CLI.
179
+
180
+ 3. Build and deploy your app again. The Wasm binary contains a copy of `static-publish.rc.js`, and the server code
181
+ changed.
182
+
183
+ 4. Publish your content again with `npm run publish-content`. This step is optional. v8 serves the content that v7
184
+ published.
185
+
186
+ ### Changes to examine
187
+
188
+ - **The CLI purges after it publishes.** In v8, `publish-content` purges the surrogate key `<publishId>-<collection>`
189
+ in KV Store mode too. It finds the Service ID from `--fastly-service-id`, then the `FASTLY_SERVICE_ID`
190
+ environment variable, then `service_id` in `fastly.toml`. If it finds a Service ID, the API token must have permission to purge
191
+ that service. If you do not want a purge, make sure that the CLI does not find a Service ID. If the purge fails,
192
+ the CLI shows a warning, and the publish is complete. `collections delete` purges the same way after it deletes a
193
+ collection.
194
+ - **`kvStoreAssetInclusionTest` has a new name.** In `publish-content.config.js`, use `assetInclusionTest`. The old
195
+ name continues to work, but it is deprecated.
196
+ - **Imports of files in `build/` are not supported.** Import the named exports of
197
+ `@fastly/compute-js-static-publish`.
198
+ - **`--public-dir` and `server.publicDirPrefix` are deprecated.** `publish-content` shows a warning if
199
+ `publicDirPrefix` is not empty. See [Stop using `publicDirPrefix`](#stop-using-publicdirprefix-deprecated).
200
+ - **The `@fastly/cli` dependency is removed** from this package. A scaffolded app continues to have `@fastly/cli` as
201
+ its own dependency.
202
+
203
+ ### Stop using `publicDirPrefix` (deprecated)
204
+
205
+ `--public-dir` and `server.publicDirPrefix` are deprecated. A future version will remove them. If `publish-content`
206
+ shows a warning about `server.publicDirPrefix`, do the steps in this section. If it does not show the warning, you do
207
+ not use this feature, and you do not have to do anything.
208
+
209
+ `publicDirPrefix` lets you publish files that requests cannot get. For example, with this layout, `rootDir` is
210
+ `'../site'` and `publicDirPrefix` is `'/public'`:
211
+
212
+ ```
213
+ site/
214
+ 404.html published as /404.html, but /404.html is not a URL
215
+ templates/
216
+ email.html published as /templates/email.html, but it is not a URL
217
+ public/
218
+ index.html published as /public/index.html, served at /index.html
219
+ ```
220
+
221
+ To stop using `publicDirPrefix`:
222
+
223
+ 1. Find the files that are under `rootDir` but not under the public directory (`site/public/` in the example). For
224
+ each file, do one of these steps:
225
+ - If your app does not use the file, do nothing. After step 2, the CLI does not publish it.
226
+ - If the file is your `spaFile` or your `notFoundPageFile`, or if your code reads the file with
227
+ `getMatchingAsset()`, move it into the public directory, and add it to `hiddenItems` in
228
+ `publish-content.config.js` (from 8.1.0). A hidden file is published, but requests cannot get it at its own URL,
229
+ for example `/404.html`. The server still serves a hidden `spaFile` or `notFoundPageFile` as the fallback page,
230
+ and your code gets a hidden file with `getMatchingAsset(key, { includeHidden: true })`. See "Hidden files" in
231
+ `README.md`. Your app must be built with 8.1.0 or later to serve a collection that has hidden files:
232
+
233
+ ```js
234
+ hiddenItems: [ '/404.html', '/templates/' ],
235
+ ```
236
+
237
+ Before 8.1.0, there are no hidden files. Move the file into the public directory. Then requests can also get it
238
+ at its own URL. To prevent this for a file that your code reads, return a response in `src/index.js` before you
239
+ call `serveRequest()`:
240
+
241
+ ```js
242
+ const url = new URL(request.url);
243
+ if (url.pathname.startsWith('/templates/')) {
244
+ return new Response('Not found', { status: 404 });
245
+ }
246
+ const response = await publisherServer.serveRequest(request);
247
+ ```
248
+
249
+ 2. In `publish-content.config.js`:
250
+ - Set `rootDir` to the public directory, for example `'../site/public'`.
251
+ - Remove `publicDirPrefix` from the `server` section.
252
+ - In `spaFile` and `notFoundPageFile`, remove the prefix, for example change `'/public/404.html'` to
253
+ `'/404.html'`. These values are asset keys, and asset keys are relative to `rootDir`.
254
+ - Do not change `staticItems`. These values are already relative to the public directory.
255
+
256
+ 3. If your code calls `getMatchingAsset()` with a key that starts with the prefix, remove the prefix from the key, for
257
+ example change `'/public/index.html'` to `'/index.html'`. Then build and deploy your app. Between the deploy and
258
+ step 4, your code does not find these files.
259
+
260
+ 4. Publish each collection that you serve again. Each collection keeps its old settings and its old index until you
261
+ publish it again. The keys of the files are the hashes of the content, so the CLI does not upload the same files
262
+ again.
263
+
264
+ ### Move from the KV Store to S3-compatible storage (BETA)
265
+
266
+ You do not have to move to S3-compatible storage. The KV Store continues to be the default storage mode.
267
+
268
+ There is no tool that moves your content from the KV Store to a bucket. The CLI publishes from your source files.
269
+ Thus, to move, you publish your content again into the bucket:
270
+
271
+ 1. Scaffold a new app with `--storage-mode=s3`, `--s3-region`, `--s3-bucket`, and, if necessary, `--s3-endpoint`.
272
+ Scaffold it into a different directory, so that you can compare the new files with your current app.
273
+
274
+ 2. Copy your changes from your current app into the new app, for example the changes to `src/index.js` and to
275
+ `publish-content.config.js`. Keep the same `publishId` and `defaultCollectionName`.
276
+
277
+ 3. Set up the S3 credentials for publishing and for the server. See "Using S3 Compatible Storage (Beta)" in
278
+ `README.md`.
279
+
280
+ 4. Publish each collection that you need again, from its source files. The collections that are in the KV Store
281
+ are not copied.
282
+
283
+ 5. Build and deploy the new app. Then examine your site.
284
+
285
+ 6. When you do not need the KV Store content, delete it. Before you do this, make sure that no service version
286
+ that is active or staged uses that KV Store.
287
+
288
+ > [!NOTE]
289
+ > S3-compatible storage is in beta. The configuration and these steps can change before this feature is stable.
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/deploy.ts"],"names":[],"mappings":"AAiFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqMhD"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/deploy.ts"],"names":[],"mappings":"AAiFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAsMhD"}
@@ -7,8 +7,8 @@ import fs from 'node:fs';
7
7
  import path from 'node:path';
8
8
  import { managedAppState, prepareManagedApp } from '../../managed/app.js';
9
9
  import { checkVersionForCommand, loadManagedProject, showTemplateFolderHint } from '../../managed/command-helpers.js';
10
- import { getActiveVersion, getVersionDomains } from '../../managed/fastly-service.js';
11
- import { formatVersionComment, parseVersionComment } from '../../managed/fingerprint.js';
10
+ import { getActiveVersion, getDeployedApp, getVersionDomains } from '../../managed/fastly-service.js';
11
+ import { formatVersionComment } from '../../managed/fingerprint.js';
12
12
  import { writeBackServiceId } from '../../managed/project-edit.js';
13
13
  import { loadApiToken } from '../../util/api-token.js';
14
14
  import { parseCommandLine } from '../../util/args.js';
@@ -176,9 +176,10 @@ export async function action(actionArgs) {
176
176
  const staticPublishVersion = getOwnVersion();
177
177
  if (serviceId != null && !force) {
178
178
  const active = await getActiveVersion(context, serviceId);
179
- const deployed = parseVersionComment(active?.comment);
179
+ const deployed = active != null ? await getDeployedApp(context, serviceId, active) : null;
180
180
  if (active != null && deployed?.fingerprint === fingerprint) {
181
- console.log(`✅ The active version ${active.number} already has this app (fingerprint ${fingerprint}). Nothing to deploy. Use --force to deploy anyway.`);
181
+ const from = deployed.fingerprintVersion != null ? `, the same package as version ${deployed.fingerprintVersion}` : '';
182
+ console.log(`✅ The active version ${active.number} already has this app (fingerprint ${fingerprint}${from}). Nothing to deploy. Use --force to deploy anyway.`);
182
183
  setJsonResult({
183
184
  deployed: false,
184
185
  reason: 'up-to-date',
@@ -1,2 +1,3 @@
1
+ export declare const MANAGEMENT_COMMANDS: readonly string[];
1
2
  export declare function action(actionArgs: string[]): Promise<void>;
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AAsFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmChD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AAmGA,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAAuB,CAAC;AAEzE,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuBhD"}
@@ -81,18 +81,20 @@ Examples:
81
81
  ${cliCommand()} publish-content --project-dir=./compute-js
82
82
  `);
83
83
  }
84
+ const modes = {
85
+ 'clean': cleanCommand,
86
+ 'deploy': deployCommand,
87
+ 'dev': devCommand,
88
+ 'eject': ejectCommand,
89
+ 'status': statusCommand,
90
+ 'upgrade': upgradeCommand,
91
+ 'publish-content': publishContentCommand,
92
+ 'collections': collectionsCommands,
93
+ 'template': templateCommands,
94
+ };
95
+ // The commands for a project or an app. Scaffolding mode does not have them.
96
+ export const MANAGEMENT_COMMANDS = Object.keys(modes);
84
97
  export async function action(actionArgs) {
85
- const modes = {
86
- 'clean': cleanCommand,
87
- 'deploy': deployCommand,
88
- 'dev': devCommand,
89
- 'eject': ejectCommand,
90
- 'status': statusCommand,
91
- 'upgrade': upgradeCommand,
92
- 'publish-content': publishContentCommand,
93
- 'collections': collectionsCommands,
94
- 'template': templateCommands,
95
- };
96
98
  const commandAndArgs = getCommandAndArgs(actionArgs, modes);
97
99
  if (commandAndArgs.needHelp) {
98
100
  if (commandAndArgs.error != null) {
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/status.ts"],"names":[],"mappings":"AAgDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAsIhD"}
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/status.ts"],"names":[],"mappings":"AA+CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyIhD"}