@fastly/compute-js-static-publish 8.1.0-beta.3 → 8.1.0-beta.5
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.
- package/CHANGELOG.md +602 -0
- package/DOCUMENTATION.md +53 -14
- package/MIGRATING.md +289 -0
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/deploy.js +27 -7
- package/build/cli/cli/commands/manage/index.d.ts +1 -0
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +13 -11
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +5 -3
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/status.js +7 -5
- package/build/cli/cli/commands/manage/template/init.js +6 -6
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +2 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/generate-app.js +6 -0
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +12 -6
- package/build/cli/cli/index.js +15 -1
- package/build/cli/cli/managed/fastly-service.d.ts +7 -0
- package/build/cli/cli/managed/fastly-service.d.ts.map +1 -1
- package/build/cli/cli/managed/fastly-service.js +31 -1
- package/build/cli/cli/managed/fingerprint.d.ts +12 -0
- package/build/cli/cli/managed/fingerprint.d.ts.map +1 -1
- package/build/cli/cli/managed/fingerprint.js +25 -0
- package/build/cli/cli/managed/project-file.d.ts.map +1 -1
- package/build/cli/cli/managed/project-file.js +9 -1
- package/build/cli/cli/managed/template-init.d.ts.map +1 -1
- package/build/cli/cli/managed/template-init.js +3 -1
- package/build/cli/cli/util/collection-selection-flags.d.ts +1 -1
- package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -1
- package/build/cli/cli/util/collection-selection-flags.js +31 -5
- package/build/cli/cli/util/config.d.ts +4 -0
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +33 -0
- package/build/cli/cli/util/fastly-options.d.ts +2 -0
- package/build/cli/cli/util/fastly-options.d.ts.map +1 -0
- package/build/cli/cli/util/fastly-options.js +52 -0
- package/build/cli/cli/util/output.js +1 -1
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +10 -4
- package/build/cli/models/config/collection-selection.d.ts +2 -0
- package/build/cli/models/config/collection-selection.d.ts.map +1 -1
- package/build/cli/models/config/collection-selection.js +48 -8
- package/build/cli/models/config/s3-storage-config.d.ts +1 -0
- package/build/cli/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/cli/models/config/s3-storage-config.js +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +3 -1
- package/build/server/hono/extensions.d.ts +3 -1
- package/build/server/hono/extensions.d.ts.map +1 -1
- package/build/server/hono/extensions.js +12 -7
- package/build/server/hono/index.d.ts +6 -1
- package/build/server/hono/index.d.ts.map +1 -1
- package/build/server/hono/index.js +21 -13
- package/build/server/models/config/collection-selection.d.ts +2 -0
- package/build/server/models/config/collection-selection.d.ts.map +1 -1
- package/build/server/models/config/collection-selection.js +48 -8
- package/build/server/models/config/s3-storage-config.d.ts +1 -0
- package/build/server/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/server/models/config/s3-storage-config.js +1 -0
- package/build/server/models/config/static-publish-rc.d.ts +1 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +3 -1
- package/build/server/server/collection-selection/index.d.ts.map +1 -1
- package/build/server/server/collection-selection/index.js +16 -6
- package/build/server/server/publisher-server/index.d.ts +2 -0
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +4 -4
- package/build/server/server/storage/s3-storage-provider.d.ts +2 -1
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +15 -7
- package/package.json +4 -2
- package/resources/app/fastly.toml.njk +8 -8
- package/resources/app/static-publish.project.js.njk +6 -0
- package/resources/app/static-publish.rc.js.njk +6 -0
- package/resources/template-init/hono/gitignore +1 -0
- package/resources/templates/hono/src/index.ts +6 -4
package/DOCUMENTATION.md
CHANGED
|
@@ -184,7 +184,7 @@ Ready to go live? All you need is a [free Fastly account](https://www.fastly.com
|
|
|
184
184
|
npm run fastly:deploy
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
The app reads the S3 credentials from the Secret Store that has the resource link name `S3_CREDENTIALS` on your service.
|
|
187
|
+
The app reads the S3 credentials from the Secret Store that has the resource link name `S3_CREDENTIALS` on your service. To use another resource link name, for example a link that your service already has, set `s3.secretStoreLinkName` in `static-publish.rc.js` (in a managed project, in `static-publish.project.js`), and build the app again. `setSecretStoreForS3Credentials()` in the code of the app also sets the name, and is used in place of `s3.secretStoreLinkName`. In the same way, `s3.fastlyBackendName` sets the name of the backend of the S3 endpoint (default `s3_storage`).
|
|
188
188
|
|
|
189
189
|
When the Fastly CLI creates a new service, it creates a Secret Store named `S3_CREDENTIALS`, links it to the service with the same name, and prompts you for the values `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY`.
|
|
190
190
|
|
|
@@ -234,13 +234,13 @@ An **ejected app** is in the repo, and you own its code. Every app that `scaffol
|
|
|
234
234
|
|
|
235
235
|
#### Managed projects
|
|
236
236
|
|
|
237
|
-
`scaffold --managed` writes only one file, `static-publish.project.js`, in the current directory (the project dir), and adds `.static-publish
|
|
237
|
+
`scaffold --managed` writes only one file, `static-publish.project.js`, in the current directory (the project dir), and adds `node_modules/`, `.static-publish/`, and the working directory to the `.gitignore` there, if they are not in it:
|
|
238
238
|
|
|
239
239
|
```
|
|
240
240
|
my-site/
|
|
241
241
|
├── static-publish.project.js # Commit this: the only config file
|
|
242
242
|
├── public/ # Your static site files
|
|
243
|
-
├── .gitignore # Ignores .static-publish
|
|
243
|
+
├── .gitignore # Ignores node_modules/, .static-publish/, and static-publisher/
|
|
244
244
|
└── static-publisher/ # ⚠️ Do not commit - the working directory
|
|
245
245
|
```
|
|
246
246
|
|
|
@@ -252,6 +252,8 @@ The project file has the settings that an ejected app has in its two files:
|
|
|
252
252
|
|
|
253
253
|
Paths in the project file are relative to it. The name of the file marks the mode: a directory with `static-publish.project.js` is a managed project, and a directory with `static-publish.rc.js` is an ejected app. A directory with both is an error.
|
|
254
254
|
|
|
255
|
+
The project file is a JavaScript module, and the CLI loads it with `import()`. Thus the `type` field of the nearest `package.json` decides its module format. The file that `scaffold --managed` writes uses `export default`, which needs an ES module. In a directory whose `package.json` has `"type": "commonjs"`, change `export default` to `module.exports =`. The other contents of the file stay the same.
|
|
256
|
+
|
|
255
257
|
`publish-content`, `collections`, and `clean` run in the project dir (or with `--project-dir`), and read the project file. `publish-content` purges the service of `managed.serviceId`, after `--fastly-service-id` and `FASTLY_SERVICE_ID`.
|
|
256
258
|
|
|
257
259
|
To run the app on your computer:
|
|
@@ -281,7 +283,7 @@ managed: {
|
|
|
281
283
|
```
|
|
282
284
|
|
|
283
285
|
- Only `local_server` and `setup` can be added. The CLI writes the other parts of `fastly.toml`.
|
|
284
|
-
- The CLI also writes some resources: the KV Store of the content, and in S3 mode, the `S3_CREDENTIALS` Secret Store and the `s3_storage` backend. A resource with one of these names is an error.
|
|
286
|
+
- The CLI also writes some resources: the KV Store of the content, and in S3 mode, the `S3_CREDENTIALS` Secret Store and the `s3_storage` backend (other names with `s3.secretStoreLinkName` and `s3.fastlyBackendName`). A resource with one of these names is an error.
|
|
285
287
|
- Do not put a secret in the project file: in `local_server`, read it from an environment variable (`env`) or a file (`file`) that is not committed.
|
|
286
288
|
- `local_server` does not change the fingerprint, because it is only for `fastly compute serve`. `setup` changes it.
|
|
287
289
|
- `eject` writes the sections into the `fastly.toml` of the ejected app.
|
|
@@ -300,9 +302,9 @@ To deploy the app:
|
|
|
300
302
|
npx @fastly/compute-js-static-publish@beta deploy
|
|
301
303
|
```
|
|
302
304
|
|
|
303
|
-
`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`).
|
|
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.
|
|
304
306
|
|
|
305
|
-
- **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.
|
|
306
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.
|
|
307
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.
|
|
308
310
|
|
|
@@ -620,6 +622,7 @@ const rc = {
|
|
|
620
622
|
// Tried in order. The first source that gives a collection wins.
|
|
621
623
|
// If no source gives a collection, the default collection is used.
|
|
622
624
|
sources: [
|
|
625
|
+
{ type: 'host', pattern: 'stag.example.com', value: 'staging' },
|
|
623
626
|
{ type: 'host', pattern: '{collection}.preview.example.com' },
|
|
624
627
|
{ type: 'path', prefix: '/_preview/{collection}', sticky: 'cookie' },
|
|
625
628
|
{ type: 'query', param: 'collection', sticky: 'cookie' },
|
|
@@ -640,14 +643,15 @@ const rc = {
|
|
|
640
643
|
|
|
641
644
|
| Source | Reads | Notes |
|
|
642
645
|
|--------|-------|-------|
|
|
643
|
-
| `host` | The hostname, matched against `pattern` | Needs a wildcard domain and TLS for it. The pattern has one `{collection}` in one label, with fixed text around it if you want (`branch-{collection}.preview.example.com`). A host label has at most 63 characters. Make sure that your production hostname does not match the pattern. |
|
|
644
|
-
| `path` | A path prefix, which is removed before the file lookup | Works on `*.edgecompute.app`. Links that start with `/` lose the prefix, so use it with `sticky: 'cookie'`, or for a site with relative links. The links in HTML do not change. |
|
|
646
|
+
| `host` | The hostname, matched against `pattern` | Needs a wildcard domain and TLS for it. The pattern has one `{collection}` in one label, with fixed text around it if you want (`branch-{collection}.preview.example.com`). A host label has at most 63 characters. Make sure that your production hostname does not match the pattern. With `value`, `pattern` is one hostname without `{collection}`, and selects the collection in `value` (`stag.example.com` → `staging`). |
|
|
647
|
+
| `path` | A path prefix, which is removed before the file lookup | Works on `*.edgecompute.app`. Links that start with `/` lose the prefix, so use it with `sticky: 'cookie'`, or for a site with relative links. The links in HTML do not change. With `value`, `prefix` has no `{collection}`, and selects the collection in `value` (`/_staging` → `staging`). |
|
|
645
648
|
| `query` | A query parameter | Only the request that has it. Usually used with `sticky: 'cookie'`. |
|
|
646
649
|
| `cookie` | A cookie | Also serves the activate path (`/activate?collection=<name>&redirectTo=<path>`) and the reset path. |
|
|
647
650
|
| `header` | A request header | For tests, CI checks, and API clients. |
|
|
648
651
|
|
|
649
652
|
- `sticky: 'cookie'` on a `path` or `query` source: when the source matches, set the cookie of the `cookie` source, and redirect (`308`) to the URL without the prefix or the parameter. It needs a `cookie` source.
|
|
650
653
|
- A name must follow the [collection name rule](#-collections-publish-preview-promote) and match `allow`. Otherwise the source is skipped.
|
|
654
|
+
- A `value` must also follow the collection name rule, and match `allow` if it is set. Otherwise the config is not valid, and the CLI and the app show an error.
|
|
651
655
|
- Redirects go only to a path on the same site. `redirectTo` with another site redirects to `/`.
|
|
652
656
|
- The responses of a selected collection (not the default collection) get `X-Robots-Tag: noindex` (unless `noindex` is `false`). They get `Cache-Control: private` if the URL does not name the collection. See [Shared caches](#shared-caches).
|
|
653
657
|
- To find out if a selected collection exists, `PublisherServer` reads its index, also when the [response cache](#️-caching-responses-with-the-core-cache) has the response.
|
|
@@ -1056,10 +1060,11 @@ async function handleRequest(request) {
|
|
|
1056
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 |
|
|
1057
1061
|
| `fallback` | `false`: if no file matches, do not serve the SPA file or the 404 page. Return `null`. | `true` |
|
|
1058
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` |
|
|
1059
1064
|
|
|
1060
1065
|
`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.
|
|
1061
1066
|
|
|
1062
|
-
`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:
|
|
1067
|
+
`serveFallback(request, { collectionName, onMissing })` 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:
|
|
1063
1068
|
|
|
1064
1069
|
```js
|
|
1065
1070
|
async function handleRequest(request) {
|
|
@@ -1189,6 +1194,7 @@ npx @fastly/compute-js-static-publish@beta template init
|
|
|
1189
1194
|
hono-extensions/
|
|
1190
1195
|
├── package.json # Your dependencies, and the peer dependencies on the packages that the app provides
|
|
1191
1196
|
├── tsconfig.json # For your editor
|
|
1197
|
+
├── .gitignore # Ignores node_modules/
|
|
1192
1198
|
├── 10-auth.ts # A module
|
|
1193
1199
|
├── api.ts # A module
|
|
1194
1200
|
├── _example.ts # An example, not a module (the name starts with _)
|
|
@@ -1207,7 +1213,7 @@ hono-extensions/
|
|
|
1207
1213
|
- `beforeFiles`: before the published files.
|
|
1208
1214
|
- `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.
|
|
1209
1215
|
|
|
1210
|
-
A module default-exports `defineExtension()`. Give it a function for each phase that the module uses. Each function gets the Hono app
|
|
1216
|
+
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:
|
|
1211
1217
|
|
|
1212
1218
|
```ts
|
|
1213
1219
|
// hono-extensions/10-header.ts
|
|
@@ -1252,18 +1258,36 @@ templateOptions: {
|
|
|
1252
1258
|
},
|
|
1253
1259
|
```
|
|
1254
1260
|
|
|
1261
|
+
**Helpers:** the third argument of each phase function has the `serveStatic()`, `staticResponse()`, `serveFallback()`, 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 order, with its own rules. For example, to serve `/theme/*` before a login check, on a preview, from the selected collection or from the default collection if the preview is missing, and with a plain `404` (never the 404 page of the collection):
|
|
1262
|
+
|
|
1263
|
+
```ts
|
|
1264
|
+
// hono-extensions/10-theme.ts
|
|
1265
|
+
import { defineExtension } from '@fastly/compute-js-static-publish/hono';
|
|
1266
|
+
|
|
1267
|
+
export default defineExtension((app, options, { staticResponse }) => {
|
|
1268
|
+
app.use('/theme/*', async (c, next) => {
|
|
1269
|
+
if (c.var.staticPublisher.collectionName == null) {
|
|
1270
|
+
return next(); // not a preview: the published files of the app serve it
|
|
1271
|
+
}
|
|
1272
|
+
return await staticResponse(c, { onMissing: 'default' }) ?? c.text('Not found', 404);
|
|
1273
|
+
});
|
|
1274
|
+
});
|
|
1275
|
+
```
|
|
1276
|
+
|
|
1277
|
+
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. This example is 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. `staticResponse()` looks up that path.
|
|
1278
|
+
|
|
1255
1279
|
**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.
|
|
1256
1280
|
|
|
1257
1281
|
**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.
|
|
1258
1282
|
|
|
1259
|
-
**The build** bundles the modules into `src/hono-extensions.generated.js` of the app (the `prebuild` [template hook](#-template-hooks)). The packages that the app provides stay imports, so that the app has one copy of each: the dependencies of the app (for example `hono` and `@fastly/hono-fastly-compute`), this package, and `fastly:*`. Thus, do not
|
|
1283
|
+
**The build** bundles the modules into `src/hono-extensions.generated.js` of the app (the `prebuild` [template hook](#-template-hooks)). The packages that the app provides stay imports, so that the app has one copy of each: the dependencies of the app (for example `hono` and `@fastly/hono-fastly-compute`), this package, and `fastly:*`. Thus, do not add them to the `dependencies` of the folder. `template init` writes them as peer dependencies in `hono-extensions/package.json`, with the versions that the app has. `npm install` in `hono-extensions/` installs them too, because npm 7 and later install peer dependencies. These copies are only for your editor and the type checker. The build always uses the copies of the app. Install other packages in the folder, and the build bundles them.
|
|
1260
1284
|
|
|
1261
1285
|
- `build.hono.extensionsDir` sets another folder, relative to the project file (or to `static-publish.rc.js`). The default is `./hono-extensions`.
|
|
1262
1286
|
- Without the folder, or without modules, the app has no extensions. `dev` and `deploy` of a managed project then show how to make the folder.
|
|
1263
1287
|
- In a managed project, the files of the folder (without `node_modules/`) are part of the fingerprint, so a change to a module makes `deploy` deploy again.
|
|
1264
1288
|
- Keep the code of the extensions in the folder. A module can import a file from outside the folder, and the build bundles it, but a change to that file does not change the fingerprint, and the watcher does not see it.
|
|
1265
1289
|
|
|
1266
|
-
**`template init`** makes the folder with `package.json`, `tsconfig.json`, and the example. In a folder that exists, it updates only the peer dependencies, and adds the starter files that are missing. It never changes your modules. `--reset` writes the starter files again (it asks first, or needs `--force` with `--non-interactive`). `--check` changes nothing, and fails with `template-init-needed` if the folder is out of date, for example after an upgrade of this package; use it in CI.
|
|
1290
|
+
**`template init`** makes the folder with `package.json`, `tsconfig.json`, `.gitignore` (for `node_modules/`), and the example. In a folder that exists, it updates only the peer dependencies, and adds the starter files that are missing. It never changes your modules. `--reset` writes the starter files again (it asks first, or needs `--force` with `--non-interactive`). `--check` changes nothing, and fails with `template-init-needed` if the folder is out of date, for example after an upgrade of this package; use it in CI.
|
|
1267
1291
|
|
|
1268
1292
|
**Watch:** `dev -- --watch` (managed) and `npm run dev:watch` (ejected) also watch the extensions folder, also if it does not exist yet. A change in the folder bundles the modules again, and then the Fastly CLI builds and restarts the app. If a module has an error, the watcher shows it and the app keeps the last modules that built.
|
|
1269
1293
|
|
|
@@ -1314,6 +1338,7 @@ fire(app);
|
|
|
1314
1338
|
`fromStaticPublishRc(rc)` returns:
|
|
1315
1339
|
|
|
1316
1340
|
- `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`.
|
|
1341
|
+
- `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.
|
|
1317
1342
|
- `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.
|
|
1318
1343
|
- `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.
|
|
1319
1344
|
- `publisherServer`: the `PublisherServer`, to configure it. For example, `publisherServer.setResponseCache({ maxAge: 3600 })`.
|
|
@@ -1328,6 +1353,7 @@ If you make the `PublisherServer` yourself, use `fromPublisherServer(publisherSe
|
|
|
1328
1353
|
| `path` | The path to serve, in place of the request path. For example, `./favicon.ico`. |
|
|
1329
1354
|
| `rewriteRequestPath` | `(path, c) => string`. Changes the request path before it is resolved against `root`. |
|
|
1330
1355
|
| `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. |
|
|
1356
|
+
| `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`). |
|
|
1331
1357
|
|
|
1332
1358
|
For example, to serve `/assets/*` from the `static` directory:
|
|
1333
1359
|
|
|
@@ -1335,7 +1361,18 @@ For example, to serve `/assets/*` from the `static` directory:
|
|
|
1335
1361
|
app.use('/assets/*', serveStatic({ root: './static', rewriteRequestPath: (path) => path.replace(/^\/assets/, '') }));
|
|
1336
1362
|
```
|
|
1337
1363
|
|
|
1338
|
-
`
|
|
1364
|
+
`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:
|
|
1365
|
+
|
|
1366
|
+
```ts
|
|
1367
|
+
app.use('/theme/*', async (c, next) => {
|
|
1368
|
+
if (c.var.staticPublisher.collectionName == null) {
|
|
1369
|
+
return next(); // not a preview
|
|
1370
|
+
}
|
|
1371
|
+
return await staticResponse(c, { onMissing: 'default' }) ?? c.text('Not found', 404);
|
|
1372
|
+
});
|
|
1373
|
+
```
|
|
1374
|
+
|
|
1375
|
+
`serveFallback()` takes the `collectionName` and `onMissing` 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.
|
|
1339
1376
|
|
|
1340
1377
|
In TypeScript, use `StaticPublisherVariables` for the variables of the app, so that `c.var.staticPublisher` has a type:
|
|
1341
1378
|
|
|
@@ -1536,7 +1573,7 @@ In an ejected app, `status --json` gives `{ "schemaVersion": 1, "mode": "ejected
|
|
|
1536
1573
|
| `config-invalid` | `2` | `static-publish.rc.js`, `static-publish.project.js`, or `publish-content.config.js` cannot be loaded, or is not valid |
|
|
1537
1574
|
| `collection-name-invalid` | `2` | A collection name breaks the [rule](#-collections-publish-preview-promote) |
|
|
1538
1575
|
| `collection-not-found` | `2` | The command needs a collection that does not exist |
|
|
1539
|
-
| `project-dir-not-found` | `2` | `--project-dir` is not a directory, or has no config file |
|
|
1576
|
+
| `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. |
|
|
1540
1577
|
| `json-not-supported` | `2` | `--json` with a command that does not support it |
|
|
1541
1578
|
| `credentials-missing` | `2` | An API token or S3 credentials are necessary, but not given |
|
|
1542
1579
|
| `version-mismatch` | `2` | `managed.staticPublishVersion` is not the version of the CLI that runs |
|
|
@@ -1630,7 +1667,9 @@ npx @fastly/compute-js-static-publish@beta \
|
|
|
1630
1667
|
**Collection selection** (written as `collectionSelection` in `static-publish.rc.js`; see [Previews: Collection Selection](#-previews-collection-selection)):
|
|
1631
1668
|
- `--collection-selection`: A source. Can be repeated; the sources are tried in the order of the flags.
|
|
1632
1669
|
- `host:<pattern>`, for example `host:{collection}.preview.example.com`
|
|
1670
|
+
- `host:<hostname>,value=<collection>`, for example `host:stag.example.com,value=staging`
|
|
1633
1671
|
- `path:<prefix>[,sticky]`, for example `path:/_preview/{collection},sticky`
|
|
1672
|
+
- `path:<prefix>,value=<collection>[,sticky]`, for example `path:/_staging,value=staging`
|
|
1634
1673
|
- `query:<param>[,sticky]`, for example `query:collection,sticky`
|
|
1635
1674
|
- `cookie[:<cookieName>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]`
|
|
1636
1675
|
- `header:<name>`, for example `header:x-publisher-collection`
|
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":"
|
|
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,12 +7,13 @@ 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
|
|
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';
|
|
15
15
|
import { detectProjectMode } from '../../util/config.js';
|
|
16
|
+
import { findRefusedFastlyOption } from '../../util/fastly-options.js';
|
|
16
17
|
import { readServiceId } from '../../util/fastly-toml.js';
|
|
17
18
|
import { cliCommand, getOwnPackageDir, getOwnVersion } from '../../util/package.js';
|
|
18
19
|
import { appFastlyCommand } from '../run-dev-watch.js';
|
|
@@ -24,7 +25,7 @@ function help() {
|
|
|
24
25
|
console.log(`\
|
|
25
26
|
|
|
26
27
|
Usage:
|
|
27
|
-
${cliCommand()} deploy [options]
|
|
28
|
+
${cliCommand()} deploy [options] [-- <options for the Fastly CLI>]
|
|
28
29
|
|
|
29
30
|
Description:
|
|
30
31
|
Deploys the app of a managed project, only if it changed: generates the app,
|
|
@@ -50,6 +51,12 @@ Options:
|
|
|
50
51
|
managed.serviceId. Without one, the Fastly CLI
|
|
51
52
|
makes a new service.
|
|
52
53
|
--fastly-api-token=<token> Default: FASTLY_API_TOKEN.
|
|
54
|
+
-- <options> Options for 'fastly compute deploy' (in an ejected app,
|
|
55
|
+
'fastly compute publish'), for example
|
|
56
|
+
-- --status-check-timeout=180. Not allowed: --comment,
|
|
57
|
+
--service-id (-s), --token (-t), --package (-p),
|
|
58
|
+
--dir (-C), and --env, because deploy sets them, or
|
|
59
|
+
they deploy something else.
|
|
53
60
|
|
|
54
61
|
Global Options:
|
|
55
62
|
-h, --help Show this help message and exit.
|
|
@@ -66,6 +73,10 @@ function runFastly(appDir, args, apiToken) {
|
|
|
66
73
|
});
|
|
67
74
|
}
|
|
68
75
|
export async function action(actionArgs) {
|
|
76
|
+
// Options after -- go to the Fastly CLI.
|
|
77
|
+
const separator = actionArgs.indexOf('--');
|
|
78
|
+
const fastlyArgs = separator === -1 ? [] : actionArgs.slice(separator + 1);
|
|
79
|
+
const ownArgs = separator === -1 ? actionArgs : actionArgs.slice(0, separator);
|
|
69
80
|
const optionDefinitions = [
|
|
70
81
|
{ name: 'force', type: Boolean },
|
|
71
82
|
{ name: 'auto-upgrade', type: Boolean },
|
|
@@ -73,7 +84,7 @@ export async function action(actionArgs) {
|
|
|
73
84
|
{ name: 'fastly-service-id', type: String },
|
|
74
85
|
{ name: 'fastly-api-token', type: String },
|
|
75
86
|
];
|
|
76
|
-
const parsed = parseCommandLine(
|
|
87
|
+
const parsed = parseCommandLine(ownArgs, optionDefinitions);
|
|
77
88
|
if (parsed.needHelp) {
|
|
78
89
|
if (parsed.error != null) {
|
|
79
90
|
console.error(String(parsed.error));
|
|
@@ -84,6 +95,11 @@ export async function action(actionArgs) {
|
|
|
84
95
|
return;
|
|
85
96
|
}
|
|
86
97
|
const { force, ['auto-upgrade']: autoUpgrade, comment, ['fastly-service-id']: fastlyServiceId, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
98
|
+
const refused = findRefusedFastlyOption(fastlyArgs);
|
|
99
|
+
if (refused != null) {
|
|
100
|
+
fail('usage', refused);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
87
103
|
if (detectProjectMode() === 'ejected') {
|
|
88
104
|
if (isJsonMode()) {
|
|
89
105
|
fail('json-not-supported', `--json is not supported for 'deploy' in an ejected app.`);
|
|
@@ -107,6 +123,7 @@ export async function action(actionArgs) {
|
|
|
107
123
|
if (isNonInteractive()) {
|
|
108
124
|
publishArgs.push('--non-interactive');
|
|
109
125
|
}
|
|
126
|
+
publishArgs.push(...fastlyArgs);
|
|
110
127
|
const env = typeof fastlyApiToken === 'string' && fastlyApiToken !== '' ?
|
|
111
128
|
{ ...process.env, FASTLY_API_TOKEN: fastlyApiToken } :
|
|
112
129
|
process.env;
|
|
@@ -159,15 +176,17 @@ export async function action(actionArgs) {
|
|
|
159
176
|
const staticPublishVersion = getOwnVersion();
|
|
160
177
|
if (serviceId != null && !force) {
|
|
161
178
|
const active = await getActiveVersion(context, serviceId);
|
|
162
|
-
const deployed =
|
|
179
|
+
const deployed = active != null ? await getDeployedApp(context, serviceId, active) : null;
|
|
163
180
|
if (active != null && deployed?.fingerprint === fingerprint) {
|
|
164
|
-
|
|
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.`);
|
|
165
183
|
setJsonResult({
|
|
166
184
|
deployed: false,
|
|
167
185
|
reason: 'up-to-date',
|
|
168
186
|
serviceId,
|
|
169
187
|
version: active.number,
|
|
170
|
-
|
|
188
|
+
// Only the JSON result has the domain, so get it only in JSON mode.
|
|
189
|
+
domain: isJsonMode() ? (await getVersionDomains(context, serviceId, active.number))[0] ?? null : null,
|
|
171
190
|
fingerprint,
|
|
172
191
|
staticPublishVersion,
|
|
173
192
|
});
|
|
@@ -187,6 +206,7 @@ export async function action(actionArgs) {
|
|
|
187
206
|
if (isNonInteractive()) {
|
|
188
207
|
deployArgs.push('--non-interactive');
|
|
189
208
|
}
|
|
209
|
+
deployArgs.push(...fastlyArgs);
|
|
190
210
|
const deploy = runFastly(appDir, deployArgs, apiToken.apiToken);
|
|
191
211
|
if (deploy.error != null || deploy.status !== 0) {
|
|
192
212
|
fail('deploy-failed', `'fastly compute deploy' failed.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"
|
|
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"}
|