@fastly/compute-js-static-publish 8.0.0-beta.0 → 8.0.0-beta.10
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/README.md +19 -5
- package/README.short.md +19 -5
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +16 -22
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +12 -21
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +6 -13
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +11 -20
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +11 -20
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +11 -20
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +6 -13
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +126 -92
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +53 -31
- package/build/cli/cli/compression/brotli.d.ts +2 -1
- package/build/cli/cli/compression/brotli.d.ts.map +1 -1
- package/build/cli/cli/compression/brotli.js +15 -4
- package/build/cli/cli/compression/gzip.d.ts +2 -1
- package/build/cli/cli/compression/gzip.d.ts.map +1 -1
- package/build/cli/cli/compression/gzip.js +8 -4
- package/build/cli/cli/compression/index.d.ts +4 -1
- package/build/cli/cli/compression/index.d.ts.map +1 -1
- package/build/cli/cli/index.js +8 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +4 -5
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +4 -7
- package/build/cli/cli/storage/kv-store-provider.d.ts +5 -5
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +39 -65
- package/build/cli/cli/storage/s3-storage-provider.d.ts +7 -6
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +76 -48
- package/build/cli/cli/storage/storage-provider.d.ts +8 -8
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +27 -11
- package/build/cli/cli/util/content-types.d.ts.map +1 -1
- package/build/cli/cli/util/content-types.js +4 -1
- package/build/cli/cli/util/kv-store-items.d.ts +12 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +49 -0
- package/build/cli/cli/util/kv-store.d.ts +6 -0
- package/build/cli/cli/util/kv-store.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store.js +39 -2
- package/build/cli/cli/util/purge.d.ts +3 -0
- package/build/cli/cli/util/purge.d.ts.map +1 -0
- package/build/cli/cli/util/purge.js +23 -0
- package/build/cli/cli/util/retryable.d.ts +2 -1
- package/build/cli/cli/util/retryable.d.ts.map +1 -1
- package/build/cli/cli/util/retryable.js +34 -1
- package/build/cli/cli/util/s3-credentials.d.ts +11 -0
- package/build/cli/cli/util/s3-credentials.d.ts.map +1 -0
- package/build/cli/cli/util/s3-credentials.js +38 -0
- package/build/cli/cli/util/s3.d.ts +1 -1
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +1 -1
- package/build/cli/cli/util/variants.d.ts +2 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/cli/util/variants.js +8 -4
- package/build/cli/models/assets/index.js +1 -1
- package/build/cli/models/config/publish-content-config.d.ts +2 -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/metadata/index.js +1 -1
- package/build/server/models/assets/index.js +1 -1
- package/build/server/models/config/publish-content-config.d.ts +2 -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/metadata/index.js +1 -1
- package/build/server/server/index.d.ts +1 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +1 -1
- package/build/server/server/publisher-server/index.js +2 -2
- package/build/server/server/storage/s3-storage-provider.d.ts +19 -15
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +52 -38
- package/build/server/server/storage/storage-provider.d.ts +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/package.json +3 -4
- package/build/cli/cli/util/aws-credentials.d.ts +0 -12
- package/build/cli/cli/util/aws-credentials.d.ts.map +0 -1
- package/build/cli/cli/util/aws-credentials.js +0 -67
|
@@ -12,6 +12,7 @@ import { LoadConfigError, loadPublishContentConfigFile, loadStaticPublisherRcFil
|
|
|
12
12
|
import { applyDefaults } from '../../util/data.js';
|
|
13
13
|
import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
|
|
14
14
|
import { ensureVariantFileExists } from '../../util/variants.js';
|
|
15
|
+
import { concurrentMap } from '../../util/retryable.js';
|
|
15
16
|
import { loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
16
17
|
// Storage key format:
|
|
17
18
|
// <publishId>_index_<preview_id>.json
|
|
@@ -42,6 +43,11 @@ Optional:
|
|
|
42
43
|
--root-dir=<dir> Directory to publish from. Overrides the config file setting.
|
|
43
44
|
Default: rootDir from publish-content.config.js
|
|
44
45
|
|
|
46
|
+
--fastly-api-token=<token> Fastly API token for KV Store or cache access.
|
|
47
|
+
If not set, the tool will check:
|
|
48
|
+
1. FASTLY_API_TOKEN environment variable
|
|
49
|
+
2. The default profile in the Fastly CLI
|
|
50
|
+
|
|
45
51
|
--overwrite-existing Always overwrite existing entries in storage, even if unchanged.
|
|
46
52
|
|
|
47
53
|
Expiration:
|
|
@@ -61,25 +67,13 @@ KV Store Options:
|
|
|
61
67
|
local files that will be used to simulate the KV Store
|
|
62
68
|
with the local development environment.
|
|
63
69
|
|
|
64
|
-
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
65
|
-
If not set, the tool will check:
|
|
66
|
-
1. FASTLY_API_TOKEN environment variable
|
|
67
|
-
2. Logged-in Fastly CLI profile
|
|
68
|
-
|
|
69
70
|
--kv-overwrite Alias for --overwrite-existing.
|
|
70
71
|
|
|
71
|
-
S3 Storage Options:
|
|
72
|
-
--
|
|
73
|
-
--
|
|
74
|
-
If not set, the tool will check
|
|
75
|
-
|
|
76
|
-
environment variables
|
|
77
|
-
2. The aws credentials file, see below
|
|
78
|
-
|
|
79
|
-
--aws-profile=<profile> Profile within the aws credentials file.
|
|
80
|
-
If not set, the tool will check:
|
|
81
|
-
1. AWS_PROFILE environment variable
|
|
82
|
-
2. The default profile, if set
|
|
72
|
+
S3 Storage Options (BETA):
|
|
73
|
+
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
74
|
+
--s3-secret-access-key=<key> interface with S3 or compatible storage.
|
|
75
|
+
If not set, the tool will check the S3_ACCESS_KEY_ID
|
|
76
|
+
and S3_SECRET_ACCESS_KEY environment variables.
|
|
83
77
|
|
|
84
78
|
Global Options:
|
|
85
79
|
-h, --help Show this help message and exit.
|
|
@@ -104,9 +98,8 @@ export async function action(actionArgs) {
|
|
|
104
98
|
{ name: 'local', type: Boolean },
|
|
105
99
|
{ name: 'fastly-api-token', type: String, },
|
|
106
100
|
{ name: 'kv-overwrite', type: Boolean },
|
|
107
|
-
{ name: '
|
|
108
|
-
{ name: '
|
|
109
|
-
{ name: 'aws-secret-access-key', type: String, },
|
|
101
|
+
{ name: 's3-access-key-id', type: String, },
|
|
102
|
+
{ name: 's3-secret-access-key', type: String, },
|
|
110
103
|
];
|
|
111
104
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
112
105
|
if (parsed.needHelp) {
|
|
@@ -118,7 +111,7 @@ export async function action(actionArgs) {
|
|
|
118
111
|
help();
|
|
119
112
|
return;
|
|
120
113
|
}
|
|
121
|
-
const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['kv-overwrite']: _kvOverwrite, ['
|
|
114
|
+
const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
122
115
|
const overwriteExisting = _overwriteExisting ?? _kvOverwrite;
|
|
123
116
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
124
117
|
// in other words, the directory that contains `fastly.toml`.
|
|
@@ -174,6 +167,9 @@ export async function action(actionArgs) {
|
|
|
174
167
|
return;
|
|
175
168
|
}
|
|
176
169
|
console.log(`✔️ Public directory '${rootRelative(publicDirRoot)}'.`);
|
|
170
|
+
if (publishContentConfig.brotliQuality != null) {
|
|
171
|
+
console.log(`✔️ Brotli quality: ${publishContentConfig.brotliQuality}`);
|
|
172
|
+
}
|
|
177
173
|
const publishId = staticPublisherRc.publishId;
|
|
178
174
|
console.log(` | Publish ID: ${publishId}`);
|
|
179
175
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
@@ -187,9 +183,8 @@ export async function action(actionArgs) {
|
|
|
187
183
|
computeAppDir,
|
|
188
184
|
localMode,
|
|
189
185
|
fastlyApiToken,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
awsSecretAccessKey,
|
|
186
|
+
s3AccessKeyId,
|
|
187
|
+
s3SecretAccessKey,
|
|
193
188
|
});
|
|
194
189
|
}
|
|
195
190
|
catch (err) {
|
|
@@ -248,15 +243,35 @@ export async function action(actionArgs) {
|
|
|
248
243
|
// and for serving using the local development server.
|
|
249
244
|
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
250
245
|
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
251
|
-
//
|
|
252
|
-
// Includes items that already exist as well. 'write' signifies
|
|
253
|
-
// that the item is to be written
|
|
246
|
+
// The items to write to storage.
|
|
254
247
|
const batch = new StorageProviderBatch();
|
|
255
248
|
// Assets included in the publishing, keyed by asset key
|
|
256
249
|
const assetsIndex = {};
|
|
257
|
-
const
|
|
250
|
+
const baseHashToVariantKeepMap = new Map();
|
|
251
|
+
// #### Keys that are already in storage
|
|
252
|
+
// The key of a file is the hash of its content. If the key exists, storage
|
|
253
|
+
// already has the same content. Thus we do not compress, hash, or upload it again.
|
|
254
|
+
// In local mode, a key can refer to a working file that was deleted, so we do not list.
|
|
255
|
+
let existingKeys;
|
|
256
|
+
if (!overwriteExisting && !localMode) {
|
|
257
|
+
console.log(`🔎 Listing files that are already in storage...`);
|
|
258
|
+
existingKeys = new Set(await storageProvider.getStorageKeys(`${publishId}_files_`) ?? []);
|
|
259
|
+
console.log(`✅ Found ${existingKeys.size} key(s).`);
|
|
260
|
+
}
|
|
261
|
+
let existingVariantCount = 0;
|
|
262
|
+
function isVariantInStorage(variantKey, numChunks) {
|
|
263
|
+
if (existingKeys == null || !existingKeys.has(variantKey)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
|
|
267
|
+
if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
258
273
|
// #### Iterate files
|
|
259
|
-
|
|
274
|
+
const fileResults = await concurrentMap(files, async (file) => {
|
|
260
275
|
// #### asset key
|
|
261
276
|
const assetKey = file.slice(publicDirRoot.length)
|
|
262
277
|
// in Windows, assetKey will otherwise end up as \path\file.html
|
|
@@ -285,24 +300,28 @@ export async function action(actionArgs) {
|
|
|
285
300
|
includeAsset = true;
|
|
286
301
|
}
|
|
287
302
|
if (!includeAsset) {
|
|
288
|
-
|
|
303
|
+
return;
|
|
289
304
|
}
|
|
290
305
|
// #### Base file size, hash, last modified time
|
|
291
306
|
const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
|
|
292
307
|
console.log(`📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
|
|
293
308
|
const stats = fs.statSync(file);
|
|
294
309
|
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
295
|
-
// ####
|
|
296
|
-
let
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
310
|
+
// #### Keep flag per variant
|
|
311
|
+
let variantKeeps = baseHashToVariantKeepMap.get(baseHash);
|
|
312
|
+
if (variantKeeps == null) {
|
|
313
|
+
variantKeeps = new Map();
|
|
314
|
+
baseHashToVariantKeepMap.set(baseHash, variantKeeps);
|
|
300
315
|
}
|
|
316
|
+
// We know the number of chunks of the original before we read it. For a
|
|
317
|
+
// compressed variant, we know it only if the original fits in one chunk.
|
|
318
|
+
const baseNumChunks = storageProvider.calculateNumChunks(baseSize);
|
|
301
319
|
const variantsToKeep = [];
|
|
302
320
|
const variants = [
|
|
303
321
|
'original',
|
|
304
322
|
...contentCompression,
|
|
305
323
|
];
|
|
324
|
+
const batchItems = [];
|
|
306
325
|
for (const variant of variants) {
|
|
307
326
|
let variantKey = `${publishId}_files_sha256_${baseHash}`;
|
|
308
327
|
let variantFilename = `${baseHash}`;
|
|
@@ -311,78 +330,92 @@ export async function action(actionArgs) {
|
|
|
311
330
|
variantFilename = `${variantFilename}_${variant}`;
|
|
312
331
|
}
|
|
313
332
|
const variantFilePath = path.resolve(storageContentDir, variantFilename);
|
|
314
|
-
let
|
|
315
|
-
if (
|
|
316
|
-
|
|
333
|
+
let keep = variantKeeps.get(variant);
|
|
334
|
+
if (keep != null) {
|
|
335
|
+
if (verbose) {
|
|
336
|
+
console.log(` 🏃♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else if ((variant === 'original' || baseNumChunks === 1) &&
|
|
340
|
+
isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
|
|
341
|
+
if (verbose) {
|
|
342
|
+
console.log(` ・ Asset found in storage with key "${variantKey}".`);
|
|
343
|
+
}
|
|
344
|
+
existingVariantCount++;
|
|
345
|
+
// We upload a compressed variant only if it is smaller than the
|
|
346
|
+
// original. Thus if it is in storage, the index keeps it.
|
|
347
|
+
keep = true;
|
|
348
|
+
variantKeeps.set(variant, keep);
|
|
317
349
|
}
|
|
318
350
|
else {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
351
|
+
await ensureVariantFileExists(variantFilePath, variant, file, verbose, { brotliQuality: publishContentConfig.brotliQuality });
|
|
352
|
+
let contentEncoding, hash, size;
|
|
353
|
+
if (variant === 'original') {
|
|
354
|
+
contentEncoding = undefined;
|
|
355
|
+
hash = baseHash;
|
|
356
|
+
size = baseSize;
|
|
326
357
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
size = baseSize;
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
contentEncoding = variant;
|
|
340
|
-
({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
|
|
341
|
-
}
|
|
358
|
+
else {
|
|
359
|
+
contentEncoding = variant;
|
|
360
|
+
({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
|
|
361
|
+
}
|
|
362
|
+
// Only keep variants whose file size actually ends up smaller than
|
|
363
|
+
// what we started with. Do not upload the other variants.
|
|
364
|
+
keep = variant === 'original' || size < baseSize;
|
|
365
|
+
variantKeeps.set(variant, keep);
|
|
366
|
+
if (keep) {
|
|
342
367
|
const numChunks = storageProvider.calculateNumChunks(size);
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
size,
|
|
368
|
+
const metadataJson = {
|
|
369
|
+
size: String(size),
|
|
346
370
|
hash,
|
|
347
|
-
numChunks: numChunks > 1 ? numChunks : undefined,
|
|
348
|
-
existsInKvStore: false,
|
|
349
371
|
};
|
|
372
|
+
if (contentEncoding != null) {
|
|
373
|
+
metadataJson.contentEncoding = contentEncoding;
|
|
374
|
+
}
|
|
375
|
+
if (numChunks > 1) {
|
|
376
|
+
metadataJson.numChunks = String(numChunks);
|
|
377
|
+
}
|
|
378
|
+
batchItems.push({
|
|
379
|
+
size,
|
|
380
|
+
key: variantKey,
|
|
381
|
+
filePath: variantFilePath,
|
|
382
|
+
metadataJson,
|
|
383
|
+
});
|
|
350
384
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
size: String(variantMetadata.size),
|
|
354
|
-
hash: variantMetadata.hash,
|
|
355
|
-
};
|
|
356
|
-
if (variantMetadata.contentEncoding != null) {
|
|
357
|
-
metadataJson.contentEncoding = variantMetadata.contentEncoding;
|
|
358
|
-
}
|
|
359
|
-
if (variantMetadata.numChunks != null) {
|
|
360
|
-
metadataJson.numChunks = String(variantMetadata.numChunks);
|
|
385
|
+
else if (verbose) {
|
|
386
|
+
console.log(` ・ Variant "${variantKey}" is not smaller than the original, not uploading.`);
|
|
361
387
|
}
|
|
362
|
-
batch.add({
|
|
363
|
-
write: !variantMetadata.existsInKvStore,
|
|
364
|
-
size: variantMetadata.size,
|
|
365
|
-
key: variantKey,
|
|
366
|
-
filePath: variantFilePath,
|
|
367
|
-
metadataJson,
|
|
368
|
-
});
|
|
369
388
|
}
|
|
370
|
-
|
|
371
|
-
// what we started with.
|
|
372
|
-
if (variant !== 'original' && variantMetadata.size < baseSize) {
|
|
389
|
+
if (variant !== 'original' && keep) {
|
|
373
390
|
variantsToKeep.push(variant);
|
|
374
391
|
}
|
|
375
392
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
393
|
+
return {
|
|
394
|
+
assetKey,
|
|
395
|
+
asset: {
|
|
396
|
+
key: `sha256:${baseHash}`,
|
|
397
|
+
size: baseSize,
|
|
398
|
+
contentType: contentTypeTestResult.contentType,
|
|
399
|
+
lastModifiedTime,
|
|
400
|
+
variants: variantsToKeep,
|
|
401
|
+
},
|
|
402
|
+
batchItems,
|
|
382
403
|
};
|
|
404
|
+
});
|
|
405
|
+
for (const result of fileResults) {
|
|
406
|
+
if (result == null) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
assetsIndex[result.assetKey] = result.asset;
|
|
410
|
+
for (const batchItem of result.batchItems) {
|
|
411
|
+
batch.add(batchItem);
|
|
412
|
+
}
|
|
383
413
|
}
|
|
384
414
|
console.log(`✅ Scan complete.`);
|
|
385
|
-
|
|
415
|
+
if (existingKeys != null) {
|
|
416
|
+
console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
|
|
417
|
+
}
|
|
418
|
+
await storageProvider.applyBatch(batch, { existingKeys });
|
|
386
419
|
// #### INDEX FILE
|
|
387
420
|
console.log(`🗂️ Saving Index...`);
|
|
388
421
|
const indexFileKey = `${publishId}_index_${collectionName}`;
|
|
@@ -458,5 +491,6 @@ export async function action(actionArgs) {
|
|
|
458
491
|
const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
|
|
459
492
|
await storageProvider.submitStorageEntry(settingsFileKey, settingsFilePath, JSON.stringify(serverSettings));
|
|
460
493
|
console.log(`✅ Settings have been saved.`);
|
|
494
|
+
await storageProvider.purgeSurrogateKey(`${publishId}-${collectionName}`);
|
|
461
495
|
console.log(`🎉 Completed.`);
|
|
462
496
|
}
|
|
@@ -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":"AAuEA,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,iBAyqBhD"}
|
|
@@ -12,7 +12,7 @@ import * as fs from 'node:fs';
|
|
|
12
12
|
import { parseCommandLine } from '../../util/args.js';
|
|
13
13
|
import { dotRelative, rootRelative } from '../../util/files.js';
|
|
14
14
|
import { findComputeJsStaticPublisherVersion } from '../../util/package.js';
|
|
15
|
-
import {
|
|
15
|
+
import { findHostnameForAwsS3RegionAndBucket } from '../../util/s3.js';
|
|
16
16
|
function help() {
|
|
17
17
|
console.log(`\
|
|
18
18
|
|
|
@@ -26,8 +26,9 @@ Description:
|
|
|
26
26
|
management mode.
|
|
27
27
|
|
|
28
28
|
Options:
|
|
29
|
-
--storage-mode <mode>
|
|
30
|
-
Can be "kv-store" or "s3".
|
|
29
|
+
--storage-mode <mode> Storage mode for content storage.
|
|
30
|
+
Can be "kv-store" or "s3" (BETA).
|
|
31
|
+
(default: kv-store)
|
|
31
32
|
If --storage-mode=kv-store, then:
|
|
32
33
|
--kv-store-name <name> (required) Name of the KV Store.
|
|
33
34
|
|
|
@@ -39,8 +40,8 @@ Options:
|
|
|
39
40
|
--root-dir <path> (required) Path to static content (e.g., ./public)
|
|
40
41
|
-o, --output <dir> Output directory for Compute app (default: ./compute-js)
|
|
41
42
|
--static-publisher-working-dir <dir> Working directory for build artifacts (default: <output>/static-publisher)
|
|
42
|
-
--publish-id <id> Advanced. Prefix for KV keys (default: "default")
|
|
43
43
|
(default: ./compute-js/static-publisher)
|
|
44
|
+
--publish-id <id> Advanced. Prefix for KV keys (default: "default")
|
|
44
45
|
|
|
45
46
|
Compute Service Metadata:
|
|
46
47
|
--name <name> App name (for fastly.toml)
|
|
@@ -201,7 +202,7 @@ function buildOptions(packageJson, commandLineOptions) {
|
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
{
|
|
204
|
-
let autoExt
|
|
205
|
+
let autoExt;
|
|
205
206
|
const autoExtValue = commandLineOptions['auto-ext'];
|
|
206
207
|
const asArray = Array.isArray(autoExtValue) ? autoExtValue : [autoExtValue];
|
|
207
208
|
if (asArray.every((x) => typeof x === 'string')) {
|
|
@@ -334,8 +335,8 @@ function processPublicDirToken(filepath, publicDir) {
|
|
|
334
335
|
export async function action(actionArgs) {
|
|
335
336
|
const optionDefinitions = [
|
|
336
337
|
{ name: 'verbose', type: Boolean },
|
|
337
|
-
//
|
|
338
|
-
{ name: 'storage-mode', type: String, },
|
|
338
|
+
// Storage mode for content storage. Can be "kv-store" or "s3".
|
|
339
|
+
{ name: 'storage-mode', type: String, defaultValue: 'kv-store', },
|
|
339
340
|
// If storage-mode=kv-store, then:
|
|
340
341
|
// Required. The name of a Fastly KV Store to hold the content assets.
|
|
341
342
|
// It is also added to the fastly.toml that is generated.
|
|
@@ -504,6 +505,7 @@ export async function action(actionArgs) {
|
|
|
504
505
|
else if (!fs.existsSync(spaFilename)) {
|
|
505
506
|
console.log(`⚠️ Warning: Ignoring specified SPA file '${SPA}' does not exist.`);
|
|
506
507
|
console.log(` * ${rootRelative(spaFilename)} does not exist.`);
|
|
508
|
+
spaFilename = undefined;
|
|
507
509
|
}
|
|
508
510
|
}
|
|
509
511
|
const NOT_FOUND_PAGE = options.notFoundPage;
|
|
@@ -520,6 +522,7 @@ export async function action(actionArgs) {
|
|
|
520
522
|
else if (!fs.existsSync(notFoundPageFilename)) {
|
|
521
523
|
console.log(`⚠️ Warning: Ignoring specified Not Found file '${NOT_FOUND_PAGE}' as it does not exist.`);
|
|
522
524
|
console.log(` * ${rootRelative(notFoundPageFilename)} does not exist.`);
|
|
525
|
+
notFoundPageFilename = undefined;
|
|
523
526
|
}
|
|
524
527
|
}
|
|
525
528
|
const autoIndex = options.autoIndex;
|
|
@@ -540,7 +543,7 @@ export async function action(actionArgs) {
|
|
|
540
543
|
const fastlyServiceId = options.serviceId;
|
|
541
544
|
const storageMode = options.storageMode;
|
|
542
545
|
if (!(storageMode === 'kv-store' || storageMode === 's3')) {
|
|
543
|
-
console.error(`❌
|
|
546
|
+
console.error(`❌ parameter --storage-mode must be set to 'kv-store' or 's3'.`);
|
|
544
547
|
process.exitCode = 1;
|
|
545
548
|
return;
|
|
546
549
|
}
|
|
@@ -569,7 +572,11 @@ export async function action(actionArgs) {
|
|
|
569
572
|
}
|
|
570
573
|
let s3Endpoint = options.s3Endpoint;
|
|
571
574
|
if (s3Endpoint == null || s3Endpoint === '') {
|
|
572
|
-
|
|
575
|
+
// If endpoint is not presented, we assume it's from AWS,
|
|
576
|
+
// and ask the SDK what the hostname would be.
|
|
577
|
+
// This is required because we need to add the hostname as a
|
|
578
|
+
// backend in the Compute service.
|
|
579
|
+
s3Endpoint = await findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
|
|
573
580
|
if (s3Endpoint) {
|
|
574
581
|
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
575
582
|
}
|
|
@@ -614,7 +621,7 @@ export async function action(actionArgs) {
|
|
|
614
621
|
console.log('KV Store Name :', kvStoreName);
|
|
615
622
|
}
|
|
616
623
|
else if (storageMode === 's3') {
|
|
617
|
-
console.log('Storage Name : S3
|
|
624
|
+
console.log('Storage Name : S3 (or compatible) storage (BETA)');
|
|
618
625
|
console.log('S3 Region :', s3Region);
|
|
619
626
|
console.log('S3 Bucket :', s3Bucket);
|
|
620
627
|
console.log('S3 Endpoint :', String(s3EndpointUrl));
|
|
@@ -662,7 +669,7 @@ export async function action(actionArgs) {
|
|
|
662
669
|
packageJsonScripts['fastly:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
|
|
663
670
|
}
|
|
664
671
|
else if (storageMode === 's3') {
|
|
665
|
-
packageJsonScripts['publish'] = 'npx @fastly/compute-js-static-publish publish-content
|
|
672
|
+
packageJsonScripts['s3:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
|
|
666
673
|
}
|
|
667
674
|
resourceFiles['package.json'] = JSON.stringify({
|
|
668
675
|
name,
|
|
@@ -671,7 +678,7 @@ export async function action(actionArgs) {
|
|
|
671
678
|
author,
|
|
672
679
|
type: 'module',
|
|
673
680
|
devDependencies: {
|
|
674
|
-
"@fastly/cli": "^
|
|
681
|
+
"@fastly/cli": "^16.0.0",
|
|
675
682
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
676
683
|
},
|
|
677
684
|
dependencies: {
|
|
@@ -689,10 +696,15 @@ export async function action(actionArgs) {
|
|
|
689
696
|
if (storageMode === 'kv-store') {
|
|
690
697
|
const localServerKvStorePath = dotRelative(computeJsDir, path.resolve(staticPublisherWorkingDir, 'kvstore.json'));
|
|
691
698
|
fastlyTomlLocalServer = /* language=text */ `\
|
|
699
|
+
[local_server]
|
|
700
|
+
|
|
692
701
|
[local_server.kv_stores]
|
|
693
702
|
${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
694
703
|
`;
|
|
695
704
|
fastlyTomlSetup = /* language=text */ `\
|
|
705
|
+
[setup]
|
|
706
|
+
|
|
707
|
+
[setup.kv_stores]
|
|
696
708
|
[setup.kv_stores.${kvStoreName}]
|
|
697
709
|
`;
|
|
698
710
|
// kvstore.json
|
|
@@ -700,24 +712,37 @@ ${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
|
700
712
|
}
|
|
701
713
|
else if (storageMode === 's3') {
|
|
702
714
|
fastlyTomlLocalServer = /* language=text */ `\
|
|
715
|
+
[local_server]
|
|
716
|
+
|
|
703
717
|
[local_server.secret_stores]
|
|
704
|
-
[[local_server.secret_stores.
|
|
705
|
-
key = "
|
|
706
|
-
env = "
|
|
707
|
-
[[local_server.secret_stores.
|
|
708
|
-
key = "
|
|
709
|
-
env = "
|
|
718
|
+
[[local_server.secret_stores.S3_CREDENTIALS]]
|
|
719
|
+
key = "S3_ACCESS_KEY_ID"
|
|
720
|
+
env = "S3_ACCESS_KEY_ID"
|
|
721
|
+
[[local_server.secret_stores.S3_CREDENTIALS]]
|
|
722
|
+
key = "S3_SECRET_ACCESS_KEY"
|
|
723
|
+
env = "S3_SECRET_ACCESS_KEY"
|
|
710
724
|
|
|
711
725
|
[local_server.backends]
|
|
712
|
-
[local_server.backends.
|
|
726
|
+
[local_server.backends.s3_storage]
|
|
713
727
|
url = "${String(s3EndpointUrl)}"
|
|
714
728
|
override_host = "${s3EndpointUrl.hostname}"
|
|
715
729
|
`;
|
|
716
730
|
fastlyTomlSetup = /* language=text */ `\
|
|
717
|
-
[setup
|
|
731
|
+
[setup]
|
|
732
|
+
|
|
733
|
+
[setup.backends]
|
|
734
|
+
[setup.backends.s3_storage]
|
|
718
735
|
address = "${s3EndpointUrl.hostname}"
|
|
719
736
|
description = "S3 API endpoint"
|
|
720
737
|
port = 443
|
|
738
|
+
[setup.secret_stores]
|
|
739
|
+
[setup.secret_stores.S3_CREDENTIALS]
|
|
740
|
+
description = "Credentials for S3 storage"
|
|
741
|
+
[setup.secret_stores.S3_CREDENTIALS.items]
|
|
742
|
+
[setup.secret_stores.S3_CREDENTIALS.items.S3_ACCESS_KEY_ID]
|
|
743
|
+
description = "Access Key ID"
|
|
744
|
+
[setup.secret_stores.S3_CREDENTIALS.items.S3_SECRET_ACCESS_KEY]
|
|
745
|
+
description = "Secret Access Key"
|
|
721
746
|
`;
|
|
722
747
|
}
|
|
723
748
|
resourceFiles['fastly.toml'] = /* language=text */ `\
|
|
@@ -824,7 +849,8 @@ const config = {
|
|
|
824
849
|
// excludeDotFiles: true,
|
|
825
850
|
// includeWellKnown: true,
|
|
826
851
|
// assetInclusionTest: (assetKey) => true,
|
|
827
|
-
// contentCompression: [ 'br', 'gzip' ],
|
|
852
|
+
// contentCompression: [ 'br', 'gzip' ],
|
|
853
|
+
// brotliQuality: 11,
|
|
828
854
|
// contentTypes: [
|
|
829
855
|
// { test: /.custom$/, contentType: 'application/x-custom', text: false },
|
|
830
856
|
// ],
|
|
@@ -906,25 +932,21 @@ To publish your content to your S3-compatible bucket
|
|
|
906
932
|
Bucket: ${s3Bucket}
|
|
907
933
|
Endpoint: ${String(s3EndpointUrl)}
|
|
908
934
|
|
|
909
|
-
Using an
|
|
910
|
-
cd ${COMPUTE_JS_DIR}
|
|
911
|
-
AWS_PROFILE=xxxx npm run publish
|
|
912
|
-
|
|
913
|
-
Using AWS IAM credentials, type:
|
|
935
|
+
Using an access key ID and secret access key for S3, type:
|
|
914
936
|
cd ${COMPUTE_JS_DIR}
|
|
915
|
-
|
|
937
|
+
S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run s3:publish
|
|
916
938
|
|
|
917
939
|
To run your Compute application locally
|
|
918
940
|
|
|
919
941
|
Run the following commands:
|
|
920
942
|
cd ${COMPUTE_JS_DIR}
|
|
921
|
-
|
|
943
|
+
S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run dev:start
|
|
922
944
|
|
|
923
945
|
To build and deploy to your Compute service:
|
|
924
946
|
|
|
925
|
-
Create a Secret Store in your account named
|
|
926
|
-
|
|
927
|
-
|
|
947
|
+
Create a Secret Store in your account named S3_CREDENTIALS, and set the following values:
|
|
948
|
+
S3_ACCESS_KEY_ID: xxxx
|
|
949
|
+
S3_SECRET_ACCESS_KEY: xxxx
|
|
928
950
|
|
|
929
951
|
Run the following commands:
|
|
930
952
|
cd ${COMPUTE_JS_DIR}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CompressOptions } from './index.js';
|
|
1
2
|
export declare const key = "br";
|
|
2
|
-
export declare function compressTo(src: string, dest: string): Promise<void>;
|
|
3
|
+
export declare function compressTo(src: string, dest: string, options?: CompressOptions): Promise<void>;
|
|
3
4
|
//# sourceMappingURL=brotli.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/brotli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/brotli.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,GAAG,OAAO,CAAC;AAMxB,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAexG"}
|
|
@@ -4,9 +4,20 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import zlib from 'node:zlib';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
7
8
|
export const key = 'br';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
// The async version runs on the libuv thread pool, so that more than one
|
|
10
|
+
// file can be compressed at the same time.
|
|
11
|
+
const brotliCompress = promisify(zlib.brotliCompress);
|
|
12
|
+
export async function compressTo(src, dest, options = {}) {
|
|
13
|
+
const buffer = await fs.promises.readFile(src);
|
|
14
|
+
// If no quality is specified, use the zlib default (11, the maximum).
|
|
15
|
+
const zlibOptions = {};
|
|
16
|
+
if (options.brotliQuality != null) {
|
|
17
|
+
zlibOptions.params = {
|
|
18
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: options.brotliQuality,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const resultBuffer = await brotliCompress(buffer, zlibOptions);
|
|
22
|
+
await fs.promises.writeFile(dest, resultBuffer);
|
|
12
23
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CompressOptions } from './index.js';
|
|
1
2
|
export declare const key = "gzip";
|
|
2
|
-
export declare function compressTo(src: string, dest: string): Promise<void>;
|
|
3
|
+
export declare function compressTo(src: string, dest: string, _options?: CompressOptions): Promise<void>;
|
|
3
4
|
//# sourceMappingURL=gzip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/gzip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/gzip.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,GAAG,SAAS,CAAC;AAM1B,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzG"}
|
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import zlib from 'node:zlib';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
7
8
|
export const key = 'gzip';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
// The async version runs on the libuv thread pool, so that more than one
|
|
10
|
+
// file can be compressed at the same time.
|
|
11
|
+
const gzip = promisify(zlib.gzip);
|
|
12
|
+
export async function compressTo(src, dest, _options = {}) {
|
|
13
|
+
const buffer = await fs.promises.readFile(src);
|
|
14
|
+
const resultBuffer = await gzip(buffer);
|
|
15
|
+
await fs.promises.writeFile(dest, resultBuffer);
|
|
12
16
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type ContentCompressionTypes } from '../../models/compression/index.js';
|
|
2
|
-
export type
|
|
2
|
+
export type CompressOptions = {
|
|
3
|
+
brotliQuality?: number;
|
|
4
|
+
};
|
|
5
|
+
export type CompressAlg = (src: string, dest: string, options?: CompressOptions) => Promise<void>;
|
|
3
6
|
declare const algs: Record<ContentCompressionTypes, CompressAlg>;
|
|
4
7
|
export { algs };
|
|
5
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,MAAM,eAAe,GAAG;IAE5B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAElG,QAAA,MAAM,IAAI,EAAE,MAAM,CAAC,uBAAuB,EAAE,WAAW,CAGtD,CAAC;AAEF,OAAO,EAAE,IAAI,EAAE,CAAC"}
|