@fastly/compute-js-static-publish 8.0.0-rc.2 → 8.0.1
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/DOCUMENTATION.md +1227 -0
- package/README.md +9 -2
- package/README.short.md +9 -2
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +1 -0
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +39 -2
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +1 -0
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +10 -1
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +1 -0
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +1 -0
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +1 -0
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +72 -76
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +39 -18
- package/build/cli/cli/storage/kv-store-provider.d.ts +1 -1
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +8 -5
- package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +12 -6
- package/build/cli/cli/storage/storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.d.ts +2 -1
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.js +38 -3
- package/build/cli/cli/util/progress.d.ts +11 -0
- package/build/cli/cli/util/progress.d.ts.map +1 -0
- package/build/cli/cli/util/progress.js +32 -0
- package/build/cli/cli/util/purge.d.ts +10 -1
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +31 -8
- package/build/cli/cli/util/service-id.js +1 -1
- package/build/cli/cli/util/variants.d.ts +7 -0
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/cli/util/variants.js +17 -0
- package/build/cli/models/server/index.d.ts +4 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +34 -1
- package/build/server/models/server/index.d.ts +4 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +34 -1
- package/build/server/server/publisher-server/index.d.ts +1 -1
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +85 -53
- package/build/server/server/publisher-server/response-cache.d.ts +13 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
- package/build/server/server/publisher-server/response-cache.js +54 -0
- package/build/server/server/util/body-length.d.ts +5 -0
- package/build/server/server/util/body-length.d.ts.map +1 -0
- package/build/server/server/util/body-length.js +63 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -54,6 +54,12 @@ npm run fastly:deploy # deploy the app
|
|
|
54
54
|
npm run fastly:publish # upload your static files
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
`fastly:publish` needs a Fastly API token that can write to the KV Store. Set the `FASTLY_API_TOKEN` environment variable, or add `-- --fastly-api-token=<token>`. The command does not read the token of your Fastly CLI profile. If you are logged in with the Fastly CLI, you can give it that token:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
|
|
61
|
+
```
|
|
62
|
+
|
|
57
63
|
In the future, unless you have further changes to make to your app itself, you can
|
|
58
64
|
upload further updates to your static files:
|
|
59
65
|
```sh
|
|
@@ -61,7 +67,7 @@ cd compute-js
|
|
|
61
67
|
npm run fastly:publish # upload your static files
|
|
62
68
|
```
|
|
63
69
|
|
|
64
|
-
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
|
|
70
|
+
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates. After the deploy, `fastly.toml` has the service ID, so `s3:publish` also purges the service's cache. For this purge, set `FASTLY_API_TOKEN` too. Without it, `s3:publish` stops with an error before it uploads files.
|
|
65
71
|
|
|
66
72
|
## Features
|
|
67
73
|
|
|
@@ -72,7 +78,8 @@ If the app uses S3-compatible storage, your files are already in the bucket afte
|
|
|
72
78
|
|
|
73
79
|
## Documentation
|
|
74
80
|
|
|
75
|
-
📘
|
|
81
|
+
📘 This package includes the full documentation in [DOCUMENTATION.md](DOCUMENTATION.md), with the CLI reference for this version.
|
|
82
|
+
It is also available on GitHub:
|
|
76
83
|
[https://github.com/fastly/compute-js-static-publish/tree/main](https://github.com/fastly/compute-js-static-publish/tree/main)
|
|
77
84
|
|
|
78
85
|
### Security issues
|
package/README.short.md
CHANGED
|
@@ -54,6 +54,12 @@ npm run fastly:deploy # deploy the app
|
|
|
54
54
|
npm run fastly:publish # upload your static files
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
`fastly:publish` needs a Fastly API token that can write to the KV Store. Set the `FASTLY_API_TOKEN` environment variable, or add `-- --fastly-api-token=<token>`. The command does not read the token of your Fastly CLI profile. If you are logged in with the Fastly CLI, you can give it that token:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
|
|
61
|
+
```
|
|
62
|
+
|
|
57
63
|
In the future, unless you have further changes to make to your app itself, you can
|
|
58
64
|
upload further updates to your static files:
|
|
59
65
|
```sh
|
|
@@ -61,7 +67,7 @@ cd compute-js
|
|
|
61
67
|
npm run fastly:publish # upload your static files
|
|
62
68
|
```
|
|
63
69
|
|
|
64
|
-
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
|
|
70
|
+
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates. After the deploy, `fastly.toml` has the service ID, so `s3:publish` also purges the service's cache. For this purge, set `FASTLY_API_TOKEN` too. Without it, `s3:publish` stops with an error before it uploads files.
|
|
65
71
|
|
|
66
72
|
## Features
|
|
67
73
|
|
|
@@ -72,7 +78,8 @@ If the app uses S3-compatible storage, your files are already in the bucket afte
|
|
|
72
78
|
|
|
73
79
|
## Documentation
|
|
74
80
|
|
|
75
|
-
📘
|
|
81
|
+
📘 This package includes the full documentation in [DOCUMENTATION.md](DOCUMENTATION.md), with the CLI reference for this version.
|
|
82
|
+
It is also available on GitHub:
|
|
76
83
|
[https://github.com/fastly/compute-js-static-publish/tree/main](https://github.com/fastly/compute-js-static-publish/tree/main)
|
|
77
84
|
|
|
78
85
|
### Security issues
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
|
|
@@ -27,6 +27,7 @@ KV Store Options:
|
|
|
27
27
|
--local Instead of working with the Fastly KV Store, operate on
|
|
28
28
|
local files that will be used to simulate the KV Store
|
|
29
29
|
with the local development environment.
|
|
30
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
30
31
|
|
|
31
32
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
32
33
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAiEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA+JhD"}
|
|
@@ -6,6 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import { parseCommandLine } from '../../../util/args.js';
|
|
7
7
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
8
8
|
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
9
|
+
import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
|
|
9
10
|
function help() {
|
|
10
11
|
console.log(`\
|
|
11
12
|
|
|
@@ -19,6 +20,9 @@ Description:
|
|
|
19
20
|
Use the 'npx @fastly/compute-js-static-publish clean' command afterward to remove content
|
|
20
21
|
files that are no longer referenced by any collection.
|
|
21
22
|
|
|
23
|
+
If a Service ID is found, the tool then purges the cached responses of the collection
|
|
24
|
+
from that service.
|
|
25
|
+
|
|
22
26
|
Required:
|
|
23
27
|
--collection-name=<name> The name of the collection to delete
|
|
24
28
|
|
|
@@ -26,11 +30,23 @@ KV Store Options:
|
|
|
26
30
|
--local Instead of working with the Fastly KV Store, operate on
|
|
27
31
|
local files that will be used to simulate the KV Store
|
|
28
32
|
with the local development environment.
|
|
33
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
29
34
|
|
|
30
|
-
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
35
|
+
--fastly-api-token=<token> Fastly API token for KV Store or cache access.
|
|
31
36
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
32
37
|
environment variable.
|
|
33
38
|
|
|
39
|
+
Purge Options:
|
|
40
|
+
--fastly-service-id=<id> Fastly Service ID to purge after deleting (not with --local).
|
|
41
|
+
If not set, the tool will check:
|
|
42
|
+
1. FASTLY_SERVICE_ID environment variable
|
|
43
|
+
2. service_id in fastly.toml
|
|
44
|
+
If none is found, the purge is skipped.
|
|
45
|
+
|
|
46
|
+
--purge-environment=<env> Environment to purge: production, staging, or a
|
|
47
|
+
comma-separated list of both. Can be repeated.
|
|
48
|
+
Default: production
|
|
49
|
+
|
|
34
50
|
S3 Storage Options (BETA):
|
|
35
51
|
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
36
52
|
--s3-secret-access-key=<key> interface with S3 or compatible storage.
|
|
@@ -47,6 +63,8 @@ export async function action(actionArgs) {
|
|
|
47
63
|
{ name: 'collection-name', type: String },
|
|
48
64
|
{ name: 'local', type: Boolean },
|
|
49
65
|
{ name: 'fastly-api-token', type: String, },
|
|
66
|
+
{ name: 'fastly-service-id', type: String, },
|
|
67
|
+
{ name: 'purge-environment', type: String, multiple: true, },
|
|
50
68
|
{ name: 's3-access-key-id', type: String, },
|
|
51
69
|
{ name: 's3-secret-access-key', type: String, },
|
|
52
70
|
];
|
|
@@ -60,7 +78,7 @@ export async function action(actionArgs) {
|
|
|
60
78
|
help();
|
|
61
79
|
return;
|
|
62
80
|
}
|
|
63
|
-
const { verbose, ['collection-name']: collectionNameValue, ['fastly-api-token']: fastlyApiToken, local: localMode, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
81
|
+
const { verbose, ['collection-name']: collectionNameValue, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, local: localMode, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
64
82
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
65
83
|
// in other words, the directory that contains `fastly.toml`.
|
|
66
84
|
const computeAppDir = path.resolve();
|
|
@@ -116,6 +134,22 @@ export async function action(actionArgs) {
|
|
|
116
134
|
return;
|
|
117
135
|
}
|
|
118
136
|
console.log(`✔️ Collection to delete: ${collectionName}`);
|
|
137
|
+
// Purge target: checked now, so that a missing API token fails before anything is deleted.
|
|
138
|
+
let purgeTarget;
|
|
139
|
+
try {
|
|
140
|
+
purgeTarget = loadPurgeTarget({
|
|
141
|
+
localMode: localMode ?? false,
|
|
142
|
+
computeAppDir,
|
|
143
|
+
fastlyServiceId,
|
|
144
|
+
fastlyApiToken,
|
|
145
|
+
purgeEnvironments: purgeEnvironmentValues,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.error(String(err));
|
|
150
|
+
process.exitCode = 1;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
119
153
|
// ### Asset Keys to delete
|
|
120
154
|
const assetKeysToDelete = new Set();
|
|
121
155
|
// ### List all indexes ###
|
|
@@ -144,5 +178,8 @@ export async function action(actionArgs) {
|
|
|
144
178
|
console.log(`Deleting key from storage: ${key}`);
|
|
145
179
|
await storageProvider.deleteStorageEntry(key);
|
|
146
180
|
}, undefined, true);
|
|
181
|
+
if (purgeTarget != null) {
|
|
182
|
+
await purgeCollection(purgeTarget, publishId, collectionName);
|
|
183
|
+
}
|
|
147
184
|
console.log("✅ Completed.");
|
|
148
185
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0BhD"}
|
|
@@ -27,6 +27,7 @@ KV Store Options:
|
|
|
27
27
|
--local Instead of working with the Fastly KV Store, operate on
|
|
28
28
|
local files that will be used to simulate the KV Store
|
|
29
29
|
with the local development environment.
|
|
30
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
30
31
|
|
|
31
32
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
32
33
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
@@ -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":"AA6CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4IhD"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import { decodeIndexMetadata } from '../../../../models/server/index.js';
|
|
6
|
+
import { decodeIndexMetadata, getUnsupportedIndexFeatures } from '../../../../models/server/index.js';
|
|
7
7
|
import { isExpired } from '../../../../models/time/index.js';
|
|
8
8
|
import { parseCommandLine } from '../../../util/args.js';
|
|
9
9
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
@@ -21,6 +21,7 @@ KV Store Options:
|
|
|
21
21
|
--local Instead of working with the Fastly KV Store, operate on
|
|
22
22
|
local files that will be used to simulate the KV Store
|
|
23
23
|
with the local development environment.
|
|
24
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
24
25
|
|
|
25
26
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
26
27
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
@@ -134,6 +135,14 @@ export async function action(actionArgs) {
|
|
|
134
135
|
else {
|
|
135
136
|
console.log(` Published : ${new Date(indexMetadata.publishedTime * 1000)}`);
|
|
136
137
|
}
|
|
138
|
+
if (indexMetadata.requires != null) {
|
|
139
|
+
console.log(` Requires : ${indexMetadata.requires.join(', ')}`);
|
|
140
|
+
const unsupportedFeatures = getUnsupportedIndexFeatures(indexMetadata);
|
|
141
|
+
if (unsupportedFeatures.length > 0) {
|
|
142
|
+
console.log(` ⚠️ This version does not support ${unsupportedFeatures.join(', ')}. An application`);
|
|
143
|
+
console.log(` that is built with this version will not serve this collection.`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
137
146
|
if (indexMetadata.expirationTime == null) {
|
|
138
147
|
console.log(' Expiration : not set');
|
|
139
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAmEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuLhD"}
|
|
@@ -43,6 +43,7 @@ KV Store Options:
|
|
|
43
43
|
--local Instead of working with the Fastly KV Store, operate on
|
|
44
44
|
local files that will be used to simulate the KV Store
|
|
45
45
|
with the local development environment.
|
|
46
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
46
47
|
|
|
47
48
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
48
49
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AA+DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0JhD"}
|
|
@@ -39,6 +39,7 @@ KV Store Options:
|
|
|
39
39
|
--local Instead of working with the Fastly KV Store, operate on
|
|
40
40
|
local files that will be used to simulate the KV Store
|
|
41
41
|
with the local development environment.
|
|
42
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
42
43
|
|
|
43
44
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
44
45
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
@@ -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":"AA2DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
|
|
@@ -29,6 +29,7 @@ KV Store Options:
|
|
|
29
29
|
--local Instead of working with the Fastly KV Store, operate on
|
|
30
30
|
local files that will be used to simulate the KV Store
|
|
31
31
|
with the local development environment.
|
|
32
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
32
33
|
|
|
33
34
|
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
34
35
|
If not set, the tool uses the FASTLY_API_TOKEN
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA8HA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4jBhD"}
|
|
@@ -11,9 +11,10 @@ import { mergeContentTypes, testFileContentType } from '../../util/content-types
|
|
|
11
11
|
import { LoadConfigError, loadPublishContentConfigFile, loadStaticPublisherRcFile } from '../../util/config.js';
|
|
12
12
|
import { applyDefaults } from '../../util/data.js';
|
|
13
13
|
import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
|
|
14
|
-
import { ensureVariantFileExists } from '../../util/variants.js';
|
|
14
|
+
import { ensureVariantFileExists, OncePerKey } from '../../util/variants.js';
|
|
15
15
|
import { concurrentMap } from '../../util/retryable.js';
|
|
16
|
-
import {
|
|
16
|
+
import { ProgressLog } from '../../util/progress.js';
|
|
17
|
+
import { loadPurgeTarget, purgeCollection } from '../../util/purge.js';
|
|
17
18
|
import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
18
19
|
// Storage key format:
|
|
19
20
|
// <publishId>_index_<preview_id>.json
|
|
@@ -80,6 +81,7 @@ KV Store Options:
|
|
|
80
81
|
--local Instead of working with the Fastly KV Store, operate on
|
|
81
82
|
local files that will be used to simulate the KV Store
|
|
82
83
|
with the local development environment.
|
|
84
|
+
KV Store mode only. In S3 mode, --local is an error.
|
|
83
85
|
|
|
84
86
|
--kv-overwrite Alias for --overwrite-existing.
|
|
85
87
|
|
|
@@ -93,6 +95,9 @@ S3 Storage Options (BETA):
|
|
|
93
95
|
Default: 64
|
|
94
96
|
|
|
95
97
|
Global Options:
|
|
98
|
+
--verbose Verbose mode. Logs each file and each upload.
|
|
99
|
+
Without this, the log shows the progress after
|
|
100
|
+
each 1000 files or uploads.
|
|
96
101
|
-h, --help Show this help message and exit.
|
|
97
102
|
|
|
98
103
|
Examples:
|
|
@@ -104,7 +109,7 @@ Examples:
|
|
|
104
109
|
}
|
|
105
110
|
export async function action(actionArgs) {
|
|
106
111
|
const optionDefinitions = [
|
|
107
|
-
{ name: 'verbose', type: Boolean },
|
|
112
|
+
{ name: 'verbose', type: Boolean, defaultValue: false },
|
|
108
113
|
{ name: 'config', type: String },
|
|
109
114
|
{ name: 'collection-name', type: String, },
|
|
110
115
|
{ name: 'root-dir', type: String, },
|
|
@@ -306,7 +311,11 @@ export async function action(actionArgs) {
|
|
|
306
311
|
const batch = new StorageProviderBatch();
|
|
307
312
|
// Assets included in the publishing, keyed by asset key
|
|
308
313
|
const assetsIndex = {};
|
|
309
|
-
|
|
314
|
+
// For each variant that we know about during this publishing, true if the
|
|
315
|
+
// index keeps the variant. Keyed on the variant's storage key. Files with the
|
|
316
|
+
// same content have the same keys, so the first of them prepares each variant
|
|
317
|
+
// one time, and the other files await its result.
|
|
318
|
+
const variantKeeps = new OncePerKey();
|
|
310
319
|
// #### Keys that are already in storage
|
|
311
320
|
// The key of a file is the hash of its content. If the key exists, storage
|
|
312
321
|
// already has the same content. Thus we do not compress, hash, or upload it again.
|
|
@@ -333,6 +342,7 @@ export async function action(actionArgs) {
|
|
|
333
342
|
return true;
|
|
334
343
|
}
|
|
335
344
|
// #### Iterate files
|
|
345
|
+
const scanProgress = new ProgressLog('Files scanned', verbose);
|
|
336
346
|
const fileResults = await concurrentMap(files, async (file) => {
|
|
337
347
|
// #### asset key
|
|
338
348
|
const assetKey = file.slice(publicDirRoot.length)
|
|
@@ -366,15 +376,9 @@ export async function action(actionArgs) {
|
|
|
366
376
|
}
|
|
367
377
|
// #### Base file size, hash, last modified time
|
|
368
378
|
const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
|
|
369
|
-
|
|
379
|
+
scanProgress.add(1, () => `📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
|
|
370
380
|
const stats = fs.statSync(file);
|
|
371
381
|
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
372
|
-
// #### Keep flag per variant
|
|
373
|
-
let variantKeeps = baseHashToVariantKeepMap.get(baseHash);
|
|
374
|
-
if (variantKeeps == null) {
|
|
375
|
-
variantKeeps = new Map();
|
|
376
|
-
baseHashToVariantKeepMap.set(baseHash, variantKeeps);
|
|
377
|
-
}
|
|
378
382
|
// We know the number of chunks of the original before we read it. For a
|
|
379
383
|
// compressed variant, we know it only if the original fits in one chunk.
|
|
380
384
|
const baseNumChunks = storageProvider.calculateNumChunks(baseSize);
|
|
@@ -384,21 +388,10 @@ export async function action(actionArgs) {
|
|
|
384
388
|
...contentCompression,
|
|
385
389
|
];
|
|
386
390
|
const batchItems = [];
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (variant
|
|
391
|
-
variantKey = `${variantKey}_${variant}`;
|
|
392
|
-
variantFilename = `${variantFilename}_${variant}`;
|
|
393
|
-
}
|
|
394
|
-
const variantFilePath = path.resolve(storageContentDir, variantFilename);
|
|
395
|
-
let keep = variantKeeps.get(variant);
|
|
396
|
-
if (keep != null) {
|
|
397
|
-
if (verbose) {
|
|
398
|
-
console.log(` 🏃♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
else if ((variant === 'original' || baseNumChunks === 1) &&
|
|
391
|
+
// Finds the variant in storage, or prepares it and adds it to batchItems.
|
|
392
|
+
// Returns true if the index keeps the variant.
|
|
393
|
+
async function prepareVariant(variant, variantKey, variantFilePath) {
|
|
394
|
+
if ((variant === 'original' || baseNumChunks === 1) &&
|
|
402
395
|
isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
|
|
403
396
|
if (verbose) {
|
|
404
397
|
console.log(` ・ Asset found in storage with key "${variantKey}".`);
|
|
@@ -406,48 +399,59 @@ export async function action(actionArgs) {
|
|
|
406
399
|
existingVariantCount++;
|
|
407
400
|
// We upload a compressed variant only if it is smaller than the
|
|
408
401
|
// original. Thus if it is in storage, the index keeps it.
|
|
409
|
-
|
|
410
|
-
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
await ensureVariantFileExists(variantFilePath, variant, file, verbose, { brotliQuality: publishContentConfig.brotliQuality });
|
|
405
|
+
let contentEncoding, hash, size;
|
|
406
|
+
if (variant === 'original') {
|
|
407
|
+
contentEncoding = undefined;
|
|
408
|
+
hash = baseHash;
|
|
409
|
+
size = baseSize;
|
|
411
410
|
}
|
|
412
411
|
else {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
variantKeeps.set(variant, keep);
|
|
428
|
-
if (keep) {
|
|
429
|
-
const numChunks = storageProvider.calculateNumChunks(size);
|
|
430
|
-
const metadataJson = {
|
|
431
|
-
size: String(size),
|
|
432
|
-
hash,
|
|
433
|
-
};
|
|
434
|
-
if (contentEncoding != null) {
|
|
435
|
-
metadataJson.contentEncoding = contentEncoding;
|
|
436
|
-
}
|
|
437
|
-
if (numChunks > 1) {
|
|
438
|
-
metadataJson.numChunks = String(numChunks);
|
|
439
|
-
}
|
|
440
|
-
batchItems.push({
|
|
441
|
-
size,
|
|
442
|
-
key: variantKey,
|
|
443
|
-
filePath: variantFilePath,
|
|
444
|
-
metadataJson,
|
|
445
|
-
});
|
|
412
|
+
contentEncoding = variant;
|
|
413
|
+
({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
|
|
414
|
+
}
|
|
415
|
+
// Only keep variants whose file size actually ends up smaller than
|
|
416
|
+
// what we started with. Do not upload the other variants.
|
|
417
|
+
const keep = variant === 'original' || size < baseSize;
|
|
418
|
+
if (keep) {
|
|
419
|
+
const numChunks = storageProvider.calculateNumChunks(size);
|
|
420
|
+
const metadataJson = {
|
|
421
|
+
size: String(size),
|
|
422
|
+
hash,
|
|
423
|
+
};
|
|
424
|
+
if (contentEncoding != null) {
|
|
425
|
+
metadataJson.contentEncoding = contentEncoding;
|
|
446
426
|
}
|
|
447
|
-
|
|
448
|
-
|
|
427
|
+
if (numChunks > 1) {
|
|
428
|
+
metadataJson.numChunks = String(numChunks);
|
|
449
429
|
}
|
|
430
|
+
batchItems.push({
|
|
431
|
+
size,
|
|
432
|
+
key: variantKey,
|
|
433
|
+
filePath: variantFilePath,
|
|
434
|
+
metadataJson,
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
else if (verbose) {
|
|
438
|
+
console.log(` ・ Variant "${variantKey}" is not smaller than the original, not uploading.`);
|
|
450
439
|
}
|
|
440
|
+
return keep;
|
|
441
|
+
}
|
|
442
|
+
for (const variant of variants) {
|
|
443
|
+
let variantKey = `${publishId}_files_sha256_${baseHash}`;
|
|
444
|
+
let variantFilename = `${baseHash}`;
|
|
445
|
+
if (variant !== 'original') {
|
|
446
|
+
variantKey = `${variantKey}_${variant}`;
|
|
447
|
+
variantFilename = `${variantFilename}_${variant}`;
|
|
448
|
+
}
|
|
449
|
+
const variantFilePath = path.resolve(storageContentDir, variantFilename);
|
|
450
|
+
const { promise, first } = variantKeeps.run(variantKey, () => prepareVariant(variant, variantKey, variantFilePath));
|
|
451
|
+
if (!first && verbose) {
|
|
452
|
+
console.log(` 🏃♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
|
|
453
|
+
}
|
|
454
|
+
const keep = await promise;
|
|
451
455
|
if (variant !== 'original' && keep) {
|
|
452
456
|
variantsToKeep.push(variant);
|
|
453
457
|
}
|
|
@@ -477,7 +481,10 @@ export async function action(actionArgs) {
|
|
|
477
481
|
if (existingKeys != null) {
|
|
478
482
|
console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
|
|
479
483
|
}
|
|
480
|
-
|
|
484
|
+
else {
|
|
485
|
+
console.log(` | ${batch.storageProviderBatchEntries.length} variant(s) to upload.`);
|
|
486
|
+
}
|
|
487
|
+
await storageProvider.applyBatch(batch, { existingKeys, verbose });
|
|
481
488
|
// #### INDEX FILE
|
|
482
489
|
console.log(`🗂️ Saving Index...`);
|
|
483
490
|
const indexFileKey = `${publishId}_index_${collectionName}`;
|
|
@@ -558,18 +565,7 @@ export async function action(actionArgs) {
|
|
|
558
565
|
await storageProvider.submitStorageEntry(settingsFileKey, settingsFilePath, JSON.stringify(serverSettings));
|
|
559
566
|
console.log(`✅ Settings have been saved.`);
|
|
560
567
|
if (purgeTarget != null) {
|
|
561
|
-
|
|
562
|
-
for (const environment of purgeTarget.environments) {
|
|
563
|
-
console.log(`Purging surrogate key [${surrogateKey}] on service [${purgeTarget.serviceId}] (${environment})...`);
|
|
564
|
-
const purged = await purgeSurrogateKey(purgeTarget.fastlyApiContext, purgeTarget.serviceId, surrogateKey, true, environment);
|
|
565
|
-
if (purged) {
|
|
566
|
-
console.log('Purged');
|
|
567
|
-
}
|
|
568
|
-
else {
|
|
569
|
-
// The content is published. Only the cached copies may be stale until they expire.
|
|
570
|
-
console.warn(`⚠️ Warning: Failed purging (${environment}). Cached copies may be served until they expire.`);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
568
|
+
await purgeCollection(purgeTarget, publishId, collectionName);
|
|
573
569
|
}
|
|
574
570
|
console.log(`🎉 Completed.`);
|
|
575
571
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAwEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAktBhD"}
|
|
@@ -52,8 +52,9 @@ Compute Service Metadata:
|
|
|
52
52
|
Server Config:
|
|
53
53
|
--public-dir <path> Deprecated. Base dir for content (default: root-dir)
|
|
54
54
|
--static-dir <path>,<path...> Directory served with long TTL (can repeat)
|
|
55
|
-
--spa <file> SPA fallback file (e.g., /index.html)
|
|
56
|
-
--not-found-page <file> 404 fallback file (e.g., /404.html)
|
|
55
|
+
--spa <file> SPA fallback file, under --root-dir (e.g., ./public/index.html)
|
|
56
|
+
--not-found-page <file> 404 fallback file, under --root-dir (e.g., ./public/404.html)
|
|
57
|
+
(default: 404.html in --root-dir, if the file exists)
|
|
57
58
|
--auto-index <name>,<name...> Index filename (e.g., index.html,index.htm)
|
|
58
59
|
--auto-ext <ext>,<ext...> Automatic extensions (e.g., .html,.htm)
|
|
59
60
|
|
|
@@ -69,7 +70,7 @@ const defaultOptions = {
|
|
|
69
70
|
staticDirs: [],
|
|
70
71
|
staticPublisherWorkingDir: undefined,
|
|
71
72
|
spa: undefined,
|
|
72
|
-
notFoundPage:
|
|
73
|
+
notFoundPage: undefined,
|
|
73
74
|
autoIndex: ['index.html', 'index.htm'],
|
|
74
75
|
autoExt: ['.html', '.htm'],
|
|
75
76
|
author: 'you@example.com',
|
|
@@ -502,14 +503,17 @@ export async function action(actionArgs) {
|
|
|
502
503
|
spaFilename = processPublicDirToken(SPA, publicDir);
|
|
503
504
|
// At any rate it must exist under the root directory
|
|
504
505
|
if (!spaFilename.startsWith(rootDir)) {
|
|
505
|
-
console.
|
|
506
|
-
console.
|
|
507
|
-
|
|
506
|
+
console.error(`❌ Specified SPA file '${SPA}' is not under the asset root directory.`);
|
|
507
|
+
console.error(` * ${rootRelative(spaFilename)} must be under ${rootRelative(rootDir)}`);
|
|
508
|
+
console.error(` Give the path from the current directory, for example ${rootRelative(rootDir)}/index.html.`);
|
|
509
|
+
process.exitCode = 1;
|
|
510
|
+
return;
|
|
508
511
|
}
|
|
509
|
-
|
|
510
|
-
console.
|
|
511
|
-
console.
|
|
512
|
-
|
|
512
|
+
if (!fs.existsSync(spaFilename)) {
|
|
513
|
+
console.error(`❌ Specified SPA file '${SPA}' does not exist.`);
|
|
514
|
+
console.error(` * ${rootRelative(spaFilename)} does not exist.`);
|
|
515
|
+
process.exitCode = 1;
|
|
516
|
+
return;
|
|
513
517
|
}
|
|
514
518
|
}
|
|
515
519
|
const NOT_FOUND_PAGE = options.notFoundPage;
|
|
@@ -519,14 +523,24 @@ export async function action(actionArgs) {
|
|
|
519
523
|
notFoundPageFilename = processPublicDirToken(NOT_FOUND_PAGE, publicDir);
|
|
520
524
|
// At any rate it must exist under the root directory
|
|
521
525
|
if (!notFoundPageFilename.startsWith(rootDir)) {
|
|
522
|
-
console.
|
|
523
|
-
console.
|
|
524
|
-
|
|
526
|
+
console.error(`❌ Specified Not Found file '${NOT_FOUND_PAGE}' is not under the asset root directory.`);
|
|
527
|
+
console.error(` * ${rootRelative(notFoundPageFilename)} must be under ${rootRelative(rootDir)}`);
|
|
528
|
+
console.error(` Give the path from the current directory, for example ${rootRelative(rootDir)}/404.html.`);
|
|
529
|
+
process.exitCode = 1;
|
|
530
|
+
return;
|
|
525
531
|
}
|
|
526
|
-
|
|
527
|
-
console.
|
|
528
|
-
console.
|
|
529
|
-
|
|
532
|
+
if (!fs.existsSync(notFoundPageFilename)) {
|
|
533
|
+
console.error(`❌ Specified Not Found file '${NOT_FOUND_PAGE}' does not exist.`);
|
|
534
|
+
console.error(` * ${rootRelative(notFoundPageFilename)} does not exist.`);
|
|
535
|
+
process.exitCode = 1;
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
// Without --not-found-page, use 404.html in the public directory if it exists.
|
|
541
|
+
const defaultNotFoundPageFilename = processPublicDirToken('[public-dir]/404.html', publicDir);
|
|
542
|
+
if (fs.existsSync(defaultNotFoundPageFilename)) {
|
|
543
|
+
notFoundPageFilename = defaultNotFoundPageFilename;
|
|
530
544
|
}
|
|
531
545
|
}
|
|
532
546
|
const autoIndex = options.autoIndex;
|
|
@@ -923,7 +937,11 @@ To build and deploy to your Compute service:
|
|
|
923
937
|
|
|
924
938
|
cd ${COMPUTE_JS_DIR}
|
|
925
939
|
npm run fastly:deploy
|
|
926
|
-
npm run fastly:publish
|
|
940
|
+
FASTLY_API_TOKEN=xxxx npm run fastly:publish
|
|
941
|
+
|
|
942
|
+
fastly:publish reads the API token only from FASTLY_API_TOKEN or --fastly-api-token,
|
|
943
|
+
not from your Fastly CLI profile. To use the token of the Fastly CLI, type:
|
|
944
|
+
FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
|
|
927
945
|
|
|
928
946
|
`);
|
|
929
947
|
}
|
|
@@ -971,6 +989,9 @@ To build and deploy to your Compute service:
|
|
|
971
989
|
a different name, the Fastly CLI uses it for the resource link too. Then call
|
|
972
990
|
setSecretStoreForS3Credentials() with that name in src/index.js, and deploy again.
|
|
973
991
|
|
|
992
|
+
After the deploy, fastly.toml has the service ID, so s3:publish also purges the
|
|
993
|
+
service's cache. For this purge, s3:publish needs FASTLY_API_TOKEN too.
|
|
994
|
+
|
|
974
995
|
`);
|
|
975
996
|
}
|
|
976
997
|
}
|
|
@@ -12,7 +12,7 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
12
12
|
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
13
13
|
deleteStorageEntry(key: string): Promise<void>;
|
|
14
14
|
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
|
-
uploadEntries(entries: StorageProviderBatchEntry[]): Promise<void>;
|
|
15
|
+
uploadEntries(entries: StorageProviderBatchEntry[], verbose?: boolean): Promise<void>;
|
|
16
16
|
doConcurrentParallel<TObject extends {
|
|
17
17
|
key: string;
|
|
18
18
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|