@fastly/compute-js-static-publish 8.1.0-beta.2 → 8.1.0-beta.4
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 +601 -0
- package/DOCUMENTATION.md +28 -19
- package/README.md +18 -5
- package/README.short.md +18 -5
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +8 -10
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/deploy.js +68 -12
- package/build/cli/cli/commands/manage/eject.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/eject.js +22 -5
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +9 -4
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/status.js +6 -0
- package/build/cli/cli/commands/manage/template/init.js +6 -6
- package/build/cli/cli/commands/run-dev-watch.d.ts +1 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -1
- package/build/cli/cli/commands/run-dev-watch.js +45 -9
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +10 -3
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/generate-app.js +17 -1
- package/build/cli/cli/commands/scaffold/index.d.ts +3 -3
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +27 -24
- package/build/cli/cli/managed/app.d.ts +1 -1
- package/build/cli/cli/managed/app.d.ts.map +1 -1
- package/build/cli/cli/managed/app.js +5 -3
- package/build/cli/cli/managed/lockfile.js +1 -1
- package/build/cli/cli/managed/project-file.d.ts.map +1 -1
- package/build/cli/cli/managed/project-file.js +13 -4
- 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.map +1 -1
- package/build/cli/cli/util/config.js +9 -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/global-options.js +1 -1
- package/build/cli/cli/util/package.d.ts +2 -1
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +47 -9
- package/build/cli/cli/util/s3.d.ts +10 -4
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +13 -35
- 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/publish-content-config.d.ts +1 -0
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- 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/cli/models/server/index.d.ts +2 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +13 -1
- package/build/server/hono/extensions.d.ts.map +1 -1
- package/build/server/hono/extensions.js +12 -7
- 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/publish-content-config.d.ts +1 -0
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- 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/models/server/index.d.ts +2 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +13 -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/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 +2 -1
- package/resources/app/fastly.toml.njk +8 -8
- package/resources/app/publish-content.config.js.njk +1 -0
- 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 +0 -1
- package/resources/templates/plain/src/index.js +12 -2
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,10 +302,10 @@ 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
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.
|
|
306
|
-
- **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`. 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.
|
|
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
|
|
|
309
311
|
**The version of this package.** `managed.staticPublishVersion` records the version of this package that the project uses. `dev` and `deploy` compare it with the version that runs:
|
|
@@ -361,7 +363,7 @@ The app also has a `dev:watch` script:
|
|
|
361
363
|
"dev:watch": "compute-js-static-publish run-dev-watch"
|
|
362
364
|
```
|
|
363
365
|
|
|
364
|
-
`npm run dev:watch` runs `fastly compute serve --watch`, which builds and restarts the app when a file in the app directory changes. Options after `--` go to `fastly compute serve`, for example `npm run dev:watch -- --addr=127.0.0.1:8080`. If the app has `scripts/template_watch.js`, that file runs with Node.js next to the Fastly CLI, until the Fastly CLI stops. Use it to watch files outside the app directory: when they change, write a file in the app directory, and the Fastly CLI builds the app again.
|
|
366
|
+
`npm run dev:watch` runs `fastly compute serve --watch`, which builds and restarts the app when a file in the app directory changes. Options after `--` go to `fastly compute serve`, for example `npm run dev:watch -- --addr=127.0.0.1:8080`. If the app has `scripts/template_watch.js`, that file runs with Node.js next to the Fastly CLI, until the Fastly CLI stops. Use it to watch files outside the app directory: when they change, write a file in the app directory, and the Fastly CLI builds the app again. `dev:watch` does not work on Windows.
|
|
365
367
|
|
|
366
368
|
## ⚙️ Configuring `static-publish.rc.js`
|
|
367
369
|
|
|
@@ -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.
|
|
@@ -1014,7 +1018,9 @@ Assets are stored in multiple formats (uncompressed + compressed) if configured.
|
|
|
1014
1018
|
|
|
1015
1019
|
## 🧩 Using PublisherServer in Custom Apps
|
|
1016
1020
|
|
|
1017
|
-
You can combine PublisherServer with custom logic to support APIs, authentication, redirects, or A/B testing.
|
|
1021
|
+
You can combine PublisherServer with custom logic to support APIs, authentication, redirects, or A/B testing. Handle your own routes before you call `serveRequest()`.
|
|
1022
|
+
|
|
1023
|
+
`serveRequest()` returns `null` for a method other than `GET` or `HEAD`, and when no file matches and no SPA file or 404 page applies. If `publish-content.config.js` sets a 404 page or an SPA file, `serveRequest()` serves that page for each path that has no file. Thus, code after `serveRequest()` does not run for those requests.
|
|
1018
1024
|
|
|
1019
1025
|
```js
|
|
1020
1026
|
import { PublisherServer } from '@fastly/compute-js-static-publish';
|
|
@@ -1027,12 +1033,7 @@ addEventListener("fetch", event => {
|
|
|
1027
1033
|
});
|
|
1028
1034
|
|
|
1029
1035
|
async function handleRequest(request) {
|
|
1030
|
-
|
|
1031
|
-
if (response) {
|
|
1032
|
-
return response;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
// Add your custom logic here
|
|
1036
|
+
// Add your custom logic here, before serveRequest()
|
|
1036
1037
|
const url = new URL(request.url);
|
|
1037
1038
|
if (url.pathname === '/api/hello') {
|
|
1038
1039
|
return new Response(JSON.stringify({ greeting: "hi" }), {
|
|
@@ -1040,6 +1041,11 @@ async function handleRequest(request) {
|
|
|
1040
1041
|
});
|
|
1041
1042
|
}
|
|
1042
1043
|
|
|
1044
|
+
const response = await publisherServer.serveRequest(request);
|
|
1045
|
+
if (response != null) {
|
|
1046
|
+
return response;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1043
1049
|
return new Response("Not Found", { status: 404 });
|
|
1044
1050
|
}
|
|
1045
1051
|
```
|
|
@@ -1057,7 +1063,7 @@ async function handleRequest(request) {
|
|
|
1057
1063
|
|
|
1058
1064
|
`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.
|
|
1059
1065
|
|
|
1060
|
-
`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:
|
|
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:
|
|
1061
1067
|
|
|
1062
1068
|
```js
|
|
1063
1069
|
async function handleRequest(request) {
|
|
@@ -1187,6 +1193,7 @@ npx @fastly/compute-js-static-publish@beta template init
|
|
|
1187
1193
|
hono-extensions/
|
|
1188
1194
|
├── package.json # Your dependencies, and the peer dependencies on the packages that the app provides
|
|
1189
1195
|
├── tsconfig.json # For your editor
|
|
1196
|
+
├── .gitignore # Ignores node_modules/
|
|
1190
1197
|
├── 10-auth.ts # A module
|
|
1191
1198
|
├── api.ts # A module
|
|
1192
1199
|
├── _example.ts # An example, not a module (the name starts with _)
|
|
@@ -1254,14 +1261,14 @@ templateOptions: {
|
|
|
1254
1261
|
|
|
1255
1262
|
**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.
|
|
1256
1263
|
|
|
1257
|
-
**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
|
|
1264
|
+
**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.
|
|
1258
1265
|
|
|
1259
1266
|
- `build.hono.extensionsDir` sets another folder, relative to the project file (or to `static-publish.rc.js`). The default is `./hono-extensions`.
|
|
1260
1267
|
- 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.
|
|
1261
1268
|
- 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.
|
|
1262
1269
|
- 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.
|
|
1263
1270
|
|
|
1264
|
-
**`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.
|
|
1271
|
+
**`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.
|
|
1265
1272
|
|
|
1266
1273
|
**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.
|
|
1267
1274
|
|
|
@@ -1628,7 +1635,9 @@ npx @fastly/compute-js-static-publish@beta \
|
|
|
1628
1635
|
**Collection selection** (written as `collectionSelection` in `static-publish.rc.js`; see [Previews: Collection Selection](#-previews-collection-selection)):
|
|
1629
1636
|
- `--collection-selection`: A source. Can be repeated; the sources are tried in the order of the flags.
|
|
1630
1637
|
- `host:<pattern>`, for example `host:{collection}.preview.example.com`
|
|
1638
|
+
- `host:<hostname>,value=<collection>`, for example `host:stag.example.com,value=staging`
|
|
1631
1639
|
- `path:<prefix>[,sticky]`, for example `path:/_preview/{collection},sticky`
|
|
1640
|
+
- `path:<prefix>,value=<collection>[,sticky]`, for example `path:/_staging,value=staging`
|
|
1632
1641
|
- `query:<param>[,sticky]`, for example `query:collection,sticky`
|
|
1633
1642
|
- `cookie[:<cookieName>][,maxAge=<seconds>][,activatePath=<path>][,resetPath=<path>]`
|
|
1634
1643
|
- `header:<name>`, for example `header:x-publisher-collection`
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ This CLI tool helps you:
|
|
|
6
6
|
|
|
7
7
|
- ✅ Deploy static sites to Fastly Compute with zero backend
|
|
8
8
|
- 📦 Store files in Fastly KV Store efficiently
|
|
9
|
-
- 🎁
|
|
9
|
+
- 🎁 Since v8: Support for S3-compatible storage such as Fastly Object Storage (Beta)
|
|
10
10
|
- 🗂 Publish to named collections (`live`, `preview-42`, etc.)
|
|
11
11
|
- 🔄 Switch between collections at runtime
|
|
12
12
|
- 🧹 Clean up old or expired assets
|
|
@@ -21,7 +21,7 @@ Create a directory for your project, place your static files in `./public`, then
|
|
|
21
21
|
npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
**
|
|
24
|
+
**Since v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
27
|
npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
|
|
@@ -31,6 +31,14 @@ If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3
|
|
|
31
31
|
|
|
32
32
|
For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
|
|
33
33
|
|
|
34
|
+
**New in 8.1:** a managed project has only one file in your repo, `static-publish.project.js`, and the CLI generates the app. Add `--template=hono` for a Hono app:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npx @fastly/compute-js-static-publish@beta --managed --root-dir=./public --kv-store-name=site-content
|
|
38
|
+
npx @fastly/compute-js-static-publish@beta publish-content --local
|
|
39
|
+
npx @fastly/compute-js-static-publish@beta dev
|
|
40
|
+
```
|
|
41
|
+
|
|
34
42
|
### 🔧 Local Preview
|
|
35
43
|
|
|
36
44
|
```sh
|
|
@@ -73,11 +81,16 @@ If the app uses S3-compatible storage, your files are already in the bucket afte
|
|
|
73
81
|
|
|
74
82
|
- **Managed projects:** keep only `static-publish.project.js` in your repo. The CLI generates the app, and `dev`, `deploy`, `status`, `upgrade`, and `eject` work with it. ([Managed and ejected apps](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#managed-and-ejected-apps))
|
|
75
83
|
- **Previews:** serve another collection for a request, selected by host, path, query, cookie, or header. ([Previews](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-previews-collection-selection))
|
|
76
|
-
- **Hidden files:** publish files that the server does not serve for a request, for your own code to read. ([Hidden files](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#hidden-files))
|
|
77
|
-
- **Hono:** the `hono` template, with your own middleware and routes in `hono-extensions/`, and examples for GRIP streaming and OAuth login. For your own Hono app, `@fastly/compute-js-static-publish/hono` replaces `@fastly/hono-compute-js-static-publish`. ([Using Hono](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-hono))
|
|
84
|
+
- **Hidden files:** publish files that the server does not serve for a request, for your own code to read. Deploy your app with 8.1 before you publish hidden files: an app built with 8.0 does not serve a collection that has hidden files. ([Hidden files](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#hidden-files))
|
|
85
|
+
- **Hono:** the `hono` template (`--template=hono`), with your own middleware and routes in `hono-extensions/`, and examples for GRIP streaming and OAuth login. For your own Hono app, `@fastly/compute-js-static-publish/hono` replaces `@fastly/hono-compute-js-static-publish`. ([Using Hono](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-hono))
|
|
78
86
|
- **CI:** `--json` output, exit codes, error codes, `--project-dir`, and `--non-interactive`. ([Using the CLI in CI](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-the-cli-in-ci))
|
|
79
87
|
|
|
80
|
-
Before you upgrade, read [CHANGELOG.md](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/CHANGELOG.md)
|
|
88
|
+
Before you upgrade, read [CHANGELOG.md](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/CHANGELOG.md). These changes can break something:
|
|
89
|
+
|
|
90
|
+
- The name of a new collection must be a DNS label: lowercase `a-z`, `0-9`, and `-`, from 1 to 63 characters, with no `-` at the start or the end. A collection that exists continues to work with another name, with a warning.
|
|
91
|
+
- A usage or config error exits with `2`. Before, every error exited with `1`.
|
|
92
|
+
- `collectionSelector.fromCookie()`: the activate and reset paths redirect with `308`. Before, they used `302`.
|
|
93
|
+
- `PublisherServer`: the fields `serverTiming`, `settingsCached`, and `assetEntryMapCache` are read-only (deprecated). Code that assigns to them gets a TypeScript error.
|
|
81
94
|
|
|
82
95
|
## Features
|
|
83
96
|
|
package/README.short.md
CHANGED
|
@@ -6,7 +6,7 @@ This CLI tool helps you:
|
|
|
6
6
|
|
|
7
7
|
- ✅ Deploy static sites to Fastly Compute with zero backend
|
|
8
8
|
- 📦 Store files in Fastly KV Store efficiently
|
|
9
|
-
- 🎁
|
|
9
|
+
- 🎁 Since v8: Support for S3-compatible storage such as Fastly Object Storage (Beta)
|
|
10
10
|
- 🗂 Publish to named collections (`live`, `preview-42`, etc.)
|
|
11
11
|
- 🔄 Switch between collections at runtime
|
|
12
12
|
- 🧹 Clean up old or expired assets
|
|
@@ -21,7 +21,7 @@ Create a directory for your project, place your static files in `./public`, then
|
|
|
21
21
|
npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
**
|
|
24
|
+
**Since v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
|
|
25
25
|
|
|
26
26
|
```sh
|
|
27
27
|
npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
|
|
@@ -31,6 +31,14 @@ If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3
|
|
|
31
31
|
|
|
32
32
|
For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
|
|
33
33
|
|
|
34
|
+
**New in 8.1:** a managed project has only one file in your repo, `static-publish.project.js`, and the CLI generates the app. Add `--template=hono` for a Hono app:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npx @fastly/compute-js-static-publish@beta --managed --root-dir=./public --kv-store-name=site-content
|
|
38
|
+
npx @fastly/compute-js-static-publish@beta publish-content --local
|
|
39
|
+
npx @fastly/compute-js-static-publish@beta dev
|
|
40
|
+
```
|
|
41
|
+
|
|
34
42
|
### 🔧 Local Preview
|
|
35
43
|
|
|
36
44
|
```sh
|
|
@@ -73,11 +81,16 @@ If the app uses S3-compatible storage, your files are already in the bucket afte
|
|
|
73
81
|
|
|
74
82
|
- **Managed projects:** keep only `static-publish.project.js` in your repo. The CLI generates the app, and `dev`, `deploy`, `status`, `upgrade`, and `eject` work with it. ([Managed and ejected apps](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#managed-and-ejected-apps))
|
|
75
83
|
- **Previews:** serve another collection for a request, selected by host, path, query, cookie, or header. ([Previews](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-previews-collection-selection))
|
|
76
|
-
- **Hidden files:** publish files that the server does not serve for a request, for your own code to read. ([Hidden files](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#hidden-files))
|
|
77
|
-
- **Hono:** the `hono` template, with your own middleware and routes in `hono-extensions/`, and examples for GRIP streaming and OAuth login. For your own Hono app, `@fastly/compute-js-static-publish/hono` replaces `@fastly/hono-compute-js-static-publish`. ([Using Hono](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-hono))
|
|
84
|
+
- **Hidden files:** publish files that the server does not serve for a request, for your own code to read. Deploy your app with 8.1 before you publish hidden files: an app built with 8.0 does not serve a collection that has hidden files. ([Hidden files](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#hidden-files))
|
|
85
|
+
- **Hono:** the `hono` template (`--template=hono`), with your own middleware and routes in `hono-extensions/`, and examples for GRIP streaming and OAuth login. For your own Hono app, `@fastly/compute-js-static-publish/hono` replaces `@fastly/hono-compute-js-static-publish`. ([Using Hono](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-hono))
|
|
78
86
|
- **CI:** `--json` output, exit codes, error codes, `--project-dir`, and `--non-interactive`. ([Using the CLI in CI](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/README.md#-using-the-cli-in-ci))
|
|
79
87
|
|
|
80
|
-
Before you upgrade, read [CHANGELOG.md](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/CHANGELOG.md)
|
|
88
|
+
Before you upgrade, read [CHANGELOG.md](https://github.com/fastly/compute-js-static-publish/blob/beta/8.1/CHANGELOG.md). These changes can break something:
|
|
89
|
+
|
|
90
|
+
- The name of a new collection must be a DNS label: lowercase `a-z`, `0-9`, and `-`, from 1 to 63 characters, with no `-` at the start or the end. A collection that exists continues to work with another name, with a warning.
|
|
91
|
+
- A usage or config error exits with `2`. Before, every error exited with `1`.
|
|
92
|
+
- `collectionSelector.fromCookie()`: the activate and reset paths redirect with `308`. Before, they used `302`.
|
|
93
|
+
- `PublisherServer`: the fields `serverTiming`, `settingsCached`, and `assetEntryMapCache` are read-only (deprecated). Code that assigns to them gets a TypeScript error.
|
|
81
94
|
|
|
82
95
|
## Features
|
|
83
96
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmLhD"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import { countHiddenEntries } from '../../../../models/assets/index.js';
|
|
6
5
|
import { decodeIndexMetadata, getUnsupportedIndexFeatures } from '../../../../models/server/index.js';
|
|
7
6
|
import { isExpired } from '../../../../models/time/index.js';
|
|
8
7
|
import { parseCommandLine } from '../../../util/args.js';
|
|
@@ -124,7 +123,8 @@ export async function action(actionArgs) {
|
|
|
124
123
|
console.log(` ${collection}`);
|
|
125
124
|
}
|
|
126
125
|
const indexKey = indexesPrefix + collection;
|
|
127
|
-
|
|
126
|
+
// Only the metadata: the index itself can be large.
|
|
127
|
+
const indexEntryInfo = await storageProvider.getStorageEntryInfo(indexKey);
|
|
128
128
|
if (indexEntryInfo == null) {
|
|
129
129
|
throw new Error(`❌ Can't load storage entry ${indexesPrefix + collection}`);
|
|
130
130
|
}
|
|
@@ -161,15 +161,13 @@ export async function action(actionArgs) {
|
|
|
161
161
|
else {
|
|
162
162
|
console.log(` Published : ${new Date(indexMetadata.publishedTime * 1000)}`);
|
|
163
163
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
info.hidden = countHiddenEntries(assetEntryMap);
|
|
169
|
-
console.log(` Files : ${fileCount} (${countHiddenEntries(assetEntryMap)} hidden)`);
|
|
164
|
+
if (indexMetadata.fileCount != null) {
|
|
165
|
+
info.files = indexMetadata.fileCount;
|
|
166
|
+
info.hidden = indexMetadata.hiddenFileCount ?? 0;
|
|
167
|
+
console.log(` Files : ${indexMetadata.fileCount} (${indexMetadata.hiddenFileCount ?? 0} hidden)`);
|
|
170
168
|
}
|
|
171
|
-
|
|
172
|
-
console.log(' Files : unknown (
|
|
169
|
+
else {
|
|
170
|
+
console.log(' Files : unknown (published with an older version)');
|
|
173
171
|
}
|
|
174
172
|
if (indexMetadata.requires != null) {
|
|
175
173
|
console.log(` Requires : ${indexMetadata.requires.join(', ')}`);
|
|
@@ -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,iBAqMhD"}
|
|
@@ -13,8 +13,10 @@ 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';
|
|
19
|
+
import { appFastlyCommand } from '../run-dev-watch.js';
|
|
18
20
|
import { fail, isJsonMode, isNonInteractive, recordFailure, setJsonResult } from '../../util/output.js';
|
|
19
21
|
import { loadServiceId } from '../../util/service-id.js';
|
|
20
22
|
import { isS3StorageConfigRc } from '../../../models/config/static-publish-rc.js';
|
|
@@ -23,7 +25,7 @@ function help() {
|
|
|
23
25
|
console.log(`\
|
|
24
26
|
|
|
25
27
|
Usage:
|
|
26
|
-
${cliCommand()} deploy [options]
|
|
28
|
+
${cliCommand()} deploy [options] [-- <options for the Fastly CLI>]
|
|
27
29
|
|
|
28
30
|
Description:
|
|
29
31
|
Deploys the app of a managed project, only if it changed: generates the app,
|
|
@@ -31,10 +33,13 @@ Description:
|
|
|
31
33
|
'fastly compute deploy'. The comment of the new service version has the
|
|
32
34
|
fingerprint of the app, so that 'status' and the next deploy can compare it.
|
|
33
35
|
|
|
34
|
-
After the first deploy, the Service ID is written
|
|
35
|
-
${PROJECT_FILE_NAME}.
|
|
36
|
+
After the first deploy, which makes a new service, the Service ID is written
|
|
37
|
+
into managed.serviceId in ${PROJECT_FILE_NAME}. A Service ID from
|
|
38
|
+
--fastly-service-id or FASTLY_SERVICE_ID does not change the file.
|
|
36
39
|
|
|
37
|
-
In an ejected app, this runs 'fastly compute publish'
|
|
40
|
+
In an ejected app, this runs 'fastly compute publish', with --comment,
|
|
41
|
+
--fastly-service-id (as --service-id), and --fastly-api-token. --force and
|
|
42
|
+
--auto-upgrade are only for a managed project.
|
|
38
43
|
|
|
39
44
|
Options:
|
|
40
45
|
--force Deploy also when the fingerprint did not change.
|
|
@@ -46,14 +51,19 @@ Options:
|
|
|
46
51
|
managed.serviceId. Without one, the Fastly CLI
|
|
47
52
|
makes a new service.
|
|
48
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.
|
|
49
60
|
|
|
50
61
|
Global Options:
|
|
51
62
|
-h, --help Show this help message and exit.
|
|
52
63
|
`);
|
|
53
64
|
}
|
|
54
65
|
function runFastly(appDir, args, apiToken) {
|
|
55
|
-
const
|
|
56
|
-
const fastly = fs.existsSync(appFastly) ? appFastly : 'fastly';
|
|
66
|
+
const fastly = appFastlyCommand(appDir);
|
|
57
67
|
console.log(`▶️ fastly ${args.join(' ')}`);
|
|
58
68
|
return child_process.spawnSync(fastly, args, {
|
|
59
69
|
cwd: appDir,
|
|
@@ -63,6 +73,10 @@ function runFastly(appDir, args, apiToken) {
|
|
|
63
73
|
});
|
|
64
74
|
}
|
|
65
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);
|
|
66
80
|
const optionDefinitions = [
|
|
67
81
|
{ name: 'force', type: Boolean },
|
|
68
82
|
{ name: 'auto-upgrade', type: Boolean },
|
|
@@ -70,7 +84,7 @@ export async function action(actionArgs) {
|
|
|
70
84
|
{ name: 'fastly-service-id', type: String },
|
|
71
85
|
{ name: 'fastly-api-token', type: String },
|
|
72
86
|
];
|
|
73
|
-
const parsed = parseCommandLine(
|
|
87
|
+
const parsed = parseCommandLine(ownArgs, optionDefinitions);
|
|
74
88
|
if (parsed.needHelp) {
|
|
75
89
|
if (parsed.error != null) {
|
|
76
90
|
console.error(String(parsed.error));
|
|
@@ -81,12 +95,43 @@ export async function action(actionArgs) {
|
|
|
81
95
|
return;
|
|
82
96
|
}
|
|
83
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
|
+
}
|
|
84
103
|
if (detectProjectMode() === 'ejected') {
|
|
85
104
|
if (isJsonMode()) {
|
|
86
105
|
fail('json-not-supported', `--json is not supported for 'deploy' in an ejected app.`);
|
|
87
106
|
return;
|
|
88
107
|
}
|
|
89
|
-
|
|
108
|
+
// fastly compute publish always builds and deploys, and an ejected app has
|
|
109
|
+
// no managed.staticPublishVersion.
|
|
110
|
+
for (const [option, value] of [['--force', force], ['--auto-upgrade', autoUpgrade]]) {
|
|
111
|
+
if (value) {
|
|
112
|
+
fail('usage', `${option} is only for a managed project. In an ejected app, deploy runs 'fastly compute publish', which always deploys.`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const publishArgs = ['compute', 'publish'];
|
|
117
|
+
if (typeof comment === 'string' && comment !== '') {
|
|
118
|
+
publishArgs.push('--comment', comment);
|
|
119
|
+
}
|
|
120
|
+
if (typeof fastlyServiceId === 'string' && fastlyServiceId !== '') {
|
|
121
|
+
publishArgs.push('--service-id', fastlyServiceId);
|
|
122
|
+
}
|
|
123
|
+
if (isNonInteractive()) {
|
|
124
|
+
publishArgs.push('--non-interactive');
|
|
125
|
+
}
|
|
126
|
+
publishArgs.push(...fastlyArgs);
|
|
127
|
+
const env = typeof fastlyApiToken === 'string' && fastlyApiToken !== '' ?
|
|
128
|
+
{ ...process.env, FASTLY_API_TOKEN: fastlyApiToken } :
|
|
129
|
+
process.env;
|
|
130
|
+
console.log(`▶️ fastly ${publishArgs.join(' ')}`);
|
|
131
|
+
const result = child_process.spawnSync(appFastlyCommand(path.resolve()), publishArgs, {
|
|
132
|
+
env,
|
|
133
|
+
stdio: [isNonInteractive() ? 'ignore' : 'inherit', 'inherit', 'inherit'],
|
|
134
|
+
});
|
|
90
135
|
if (result.error != null || result.status !== 0) {
|
|
91
136
|
fail('deploy-failed', `'fastly compute publish' failed.`);
|
|
92
137
|
}
|
|
@@ -126,7 +171,8 @@ export async function action(actionArgs) {
|
|
|
126
171
|
console.warn(`⚠️ This CLI runs from the npx cache. The paths of the cache (in your home directory) go into the deployed Wasm binary.`);
|
|
127
172
|
console.warn(` * Add @fastly/compute-js-static-publish as a dev dependency of the project, and run it from there.`);
|
|
128
173
|
}
|
|
129
|
-
const
|
|
174
|
+
const state = await managedAppState(path.resolve(), project);
|
|
175
|
+
const { fingerprint } = state;
|
|
130
176
|
const staticPublishVersion = getOwnVersion();
|
|
131
177
|
if (serviceId != null && !force) {
|
|
132
178
|
const active = await getActiveVersion(context, serviceId);
|
|
@@ -138,14 +184,15 @@ export async function action(actionArgs) {
|
|
|
138
184
|
reason: 'up-to-date',
|
|
139
185
|
serviceId,
|
|
140
186
|
version: active.number,
|
|
141
|
-
|
|
187
|
+
// Only the JSON result has the domain, so get it only in JSON mode.
|
|
188
|
+
domain: isJsonMode() ? (await getVersionDomains(context, serviceId, active.number))[0] ?? null : null,
|
|
142
189
|
fingerprint,
|
|
143
190
|
staticPublishVersion,
|
|
144
191
|
});
|
|
145
192
|
return;
|
|
146
193
|
}
|
|
147
194
|
}
|
|
148
|
-
const { appDir } = await prepareManagedApp(path.resolve(), project);
|
|
195
|
+
const { appDir } = await prepareManagedApp(path.resolve(), project, state);
|
|
149
196
|
const build = runFastly(appDir, ['compute', 'build'], apiToken.apiToken);
|
|
150
197
|
if (build.error != null || build.status !== 0) {
|
|
151
198
|
fail('deploy-failed', `'fastly compute build' failed.`);
|
|
@@ -158,6 +205,7 @@ export async function action(actionArgs) {
|
|
|
158
205
|
if (isNonInteractive()) {
|
|
159
206
|
deployArgs.push('--non-interactive');
|
|
160
207
|
}
|
|
208
|
+
deployArgs.push(...fastlyArgs);
|
|
161
209
|
const deploy = runFastly(appDir, deployArgs, apiToken.apiToken);
|
|
162
210
|
if (deploy.error != null || deploy.status !== 0) {
|
|
163
211
|
fail('deploy-failed', `'fastly compute deploy' failed.`);
|
|
@@ -169,7 +217,15 @@ export async function action(actionArgs) {
|
|
|
169
217
|
fail('deploy-failed', 'The deploy finished, but the Service ID is not known.');
|
|
170
218
|
return;
|
|
171
219
|
}
|
|
172
|
-
|
|
220
|
+
// Write the Service ID into the project file only when it is the service of
|
|
221
|
+
// the project: a new service, or the one in the fastly.toml of the generated
|
|
222
|
+
// app. A Service ID from --fastly-service-id or FASTLY_SERVICE_ID is for this
|
|
223
|
+
// deploy only, so it does not change the committed file.
|
|
224
|
+
const oneOff = serviceIdResult?.source === 'commandline' || serviceIdResult?.source === 'env';
|
|
225
|
+
if (project.managed.serviceId == null && oneOff) {
|
|
226
|
+
console.log(` * managed.serviceId is not set. The Service ID ${serviceId} came from ${serviceIdResult.source === 'env' ? 'FASTLY_SERVICE_ID' : '--fastly-service-id'}, so ${PROJECT_FILE_NAME} was not changed.`);
|
|
227
|
+
}
|
|
228
|
+
if (project.managed.serviceId == null && !oneOff) {
|
|
173
229
|
const projectFilePath = path.resolve(PROJECT_FILE_NAME);
|
|
174
230
|
const updated = writeBackServiceId(fs.readFileSync(projectFilePath, 'utf-8'), serviceId);
|
|
175
231
|
if (updated != null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eject.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/eject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eject.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/eject.ts"],"names":[],"mappings":"AAyEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA6HhD"}
|
|
@@ -18,8 +18,8 @@ import { cliCommand, getOwnVersion } from '../../util/package.js';
|
|
|
18
18
|
import { MANAGED_APP_DIR, PROJECT_FILE_NAME, RC_FILE_NAME } from '../../../models/config/static-publish-project.js';
|
|
19
19
|
// An environment variable for the tests of this package only. The tests run a
|
|
20
20
|
// version that is not on npm, so they give here the spec of this package for
|
|
21
|
-
// the ejected app.
|
|
22
|
-
const PACKAGE_SPEC_ENV = '
|
|
21
|
+
// the ejected app. eject shows a warning when it is set.
|
|
22
|
+
const PACKAGE_SPEC_ENV = 'CJSP_TEST_ONLY_EJECT_PACKAGE_SPEC';
|
|
23
23
|
function help() {
|
|
24
24
|
console.log(`\
|
|
25
25
|
|
|
@@ -49,6 +49,14 @@ Global Options:
|
|
|
49
49
|
-h, --help Show this help message and exit.
|
|
50
50
|
`);
|
|
51
51
|
}
|
|
52
|
+
// True if dir is a directory in parent (not parent itself).
|
|
53
|
+
function isInside(dir, parent) {
|
|
54
|
+
const relative = path.relative(parent, dir);
|
|
55
|
+
return relative !== '' && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
56
|
+
}
|
|
57
|
+
function isSameOrInside(dir, parent) {
|
|
58
|
+
return dir === parent || isInside(dir, parent);
|
|
59
|
+
}
|
|
52
60
|
function isPublished(version) {
|
|
53
61
|
const result = child_process.spawnSync('npm', ['view', `${THIS_PACKAGE}@${version}`, 'version'], { encoding: 'utf-8' });
|
|
54
62
|
return result.status === 0 && result.stdout.trim() === version;
|
|
@@ -80,10 +88,15 @@ export async function action(actionArgs) {
|
|
|
80
88
|
}
|
|
81
89
|
const projectDir = path.resolve();
|
|
82
90
|
const appDir = path.resolve(dirValue ?? './compute-js');
|
|
83
|
-
|
|
91
|
+
const workingDir = path.resolve(project.rc.staticPublisherWorkingDir);
|
|
92
|
+
if (!isInside(appDir, projectDir) || isSameOrInside(appDir, path.resolve(MANAGED_APP_DIR))) {
|
|
84
93
|
fail('usage', `--dir must be a directory in the project dir, and not in ${MANAGED_APP_DIR}.`);
|
|
85
94
|
return;
|
|
86
95
|
}
|
|
96
|
+
if (isSameOrInside(appDir, workingDir)) {
|
|
97
|
+
fail('usage', `--dir must not be the working directory (${rootRelative(workingDir)}) or a directory in it. Use another --dir, or change staticPublisherWorkingDir.`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
87
100
|
if (fs.existsSync(appDir) && !force) {
|
|
88
101
|
fail('usage', `${rootRelative(appDir)} exists. Use --force to write into it.`);
|
|
89
102
|
return;
|
|
@@ -100,6 +113,9 @@ export async function action(actionArgs) {
|
|
|
100
113
|
fail('version-not-published', `Eject needs a version of ${THIS_PACKAGE} that is published on npm. ${version} is not.`);
|
|
101
114
|
return;
|
|
102
115
|
}
|
|
116
|
+
if (testSpec != null) {
|
|
117
|
+
console.warn(`⚠️ ${PACKAGE_SPEC_ENV} is set (for the tests of this package only): the ejected app gets ${THIS_PACKAGE} ${testSpec}, and the check that ${version} is on npm is skipped.`);
|
|
118
|
+
}
|
|
103
119
|
const packageSpec = testSpec ?? `^${version}`;
|
|
104
120
|
const serviceId = (typeof fastlyServiceId === 'string' && fastlyServiceId !== '' ? fastlyServiceId : undefined) ??
|
|
105
121
|
(process.env.FASTLY_SERVICE_ID || undefined) ??
|
|
@@ -131,10 +147,11 @@ export async function action(actionArgs) {
|
|
|
131
147
|
files['package-lock.json'] = JSON.stringify(lock, undefined, 2) + '\n';
|
|
132
148
|
console.log(`📦 Writing the app into ${rootRelative(appDir)}...`);
|
|
133
149
|
writeManagedAppFiles(appDir, files);
|
|
134
|
-
// Pin this package: "^<version>" stays in package.json,
|
|
150
|
+
// Pin this package: "^<version>" stays in the dependencies of package.json,
|
|
151
|
+
// and the lockfile gets exactly <version>.
|
|
135
152
|
const installArgs = testSpec != null ?
|
|
136
153
|
['install', '--no-audit', '--no-fund'] :
|
|
137
|
-
['install', '--save-
|
|
154
|
+
['install', '--save-prod', `${THIS_PACKAGE}@${version}`, '--no-audit', '--no-fund'];
|
|
138
155
|
console.log(`npm ${installArgs.join(' ')}`);
|
|
139
156
|
const install = child_process.spawnSync('npm', installArgs, { cwd: appDir, stdio: ['ignore', process.stderr, 'inherit'] });
|
|
140
157
|
if (install.error != null || install.status !== 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAiJA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAiJA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0mBhD"}
|