@fastly/compute-js-static-publish 8.0.0-beta.3 → 8.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +32 -15
- package/build/cli/cli/commands/scaffold/index.js +3 -3
- package/build/cli/cli/util/variants.d.ts +1 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/cli/util/variants.js +7 -3
- package/package.json +1 -1
|
@@ -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":"AA4GA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0ehD"}
|
|
@@ -256,7 +256,7 @@ export async function action(actionArgs) {
|
|
|
256
256
|
const assetsIndex = {};
|
|
257
257
|
const baseHashToVariantMetadatasMap = new Map();
|
|
258
258
|
// #### Iterate files
|
|
259
|
-
|
|
259
|
+
const filePromises = files.map(async (file) => {
|
|
260
260
|
// #### asset key
|
|
261
261
|
const assetKey = file.slice(publicDirRoot.length)
|
|
262
262
|
// in Windows, assetKey will otherwise end up as \path\file.html
|
|
@@ -285,7 +285,7 @@ export async function action(actionArgs) {
|
|
|
285
285
|
includeAsset = true;
|
|
286
286
|
}
|
|
287
287
|
if (!includeAsset) {
|
|
288
|
-
|
|
288
|
+
return;
|
|
289
289
|
}
|
|
290
290
|
// #### Base file size, hash, last modified time
|
|
291
291
|
const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
|
|
@@ -303,6 +303,7 @@ export async function action(actionArgs) {
|
|
|
303
303
|
'original',
|
|
304
304
|
...contentCompression,
|
|
305
305
|
];
|
|
306
|
+
const batchItems = [];
|
|
306
307
|
for (const variant of variants) {
|
|
307
308
|
let variantKey = `${publishId}_files_sha256_${baseHash}`;
|
|
308
309
|
let variantFilename = `${baseHash}`;
|
|
@@ -313,22 +314,24 @@ export async function action(actionArgs) {
|
|
|
313
314
|
const variantFilePath = path.resolve(storageContentDir, variantFilename);
|
|
314
315
|
let variantMetadata = variantMetadatas.get(variant);
|
|
315
316
|
if (variantMetadata != null) {
|
|
316
|
-
|
|
317
|
+
if (verbose) {
|
|
318
|
+
console.log(` 🏃♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
|
|
319
|
+
}
|
|
317
320
|
}
|
|
318
321
|
else {
|
|
319
322
|
if (!overwriteExisting) {
|
|
320
323
|
const assetVariantMetadata = await storageProvider.getExistingAssetVariant(variantKey);
|
|
321
324
|
if (assetVariantMetadata != null) {
|
|
322
|
-
|
|
325
|
+
if (verbose) {
|
|
326
|
+
console.log(` ・ Asset found in storage with key "${variantKey}".`);
|
|
327
|
+
}
|
|
323
328
|
// And we already know its hash and size.
|
|
324
329
|
variantMetadata = Object.assign(assetVariantMetadata, { existsInKvStore: true });
|
|
325
330
|
}
|
|
326
331
|
}
|
|
327
332
|
if (variantMetadata == null) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
console.log(` ・ Prepping asset for storage with key "${variantKey}".`);
|
|
331
|
-
}
|
|
333
|
+
console.log(` ↦ Prepping new asset for storage: "${variantKey}"`);
|
|
334
|
+
await ensureVariantFileExists(variantFilePath, variant, file, verbose);
|
|
332
335
|
let contentEncoding, hash, size;
|
|
333
336
|
if (variant === 'original') {
|
|
334
337
|
contentEncoding = undefined;
|
|
@@ -359,7 +362,7 @@ export async function action(actionArgs) {
|
|
|
359
362
|
if (variantMetadata.numChunks != null) {
|
|
360
363
|
metadataJson.numChunks = String(variantMetadata.numChunks);
|
|
361
364
|
}
|
|
362
|
-
|
|
365
|
+
batchItems.push({
|
|
363
366
|
write: !variantMetadata.existsInKvStore,
|
|
364
367
|
size: variantMetadata.size,
|
|
365
368
|
key: variantKey,
|
|
@@ -373,13 +376,27 @@ export async function action(actionArgs) {
|
|
|
373
376
|
variantsToKeep.push(variant);
|
|
374
377
|
}
|
|
375
378
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
379
|
+
return {
|
|
380
|
+
assetKey,
|
|
381
|
+
asset: {
|
|
382
|
+
key: `sha256:${baseHash}`,
|
|
383
|
+
size: baseSize,
|
|
384
|
+
contentType: contentTypeTestResult.contentType,
|
|
385
|
+
lastModifiedTime,
|
|
386
|
+
variants: variantsToKeep,
|
|
387
|
+
},
|
|
388
|
+
batchItems,
|
|
382
389
|
};
|
|
390
|
+
});
|
|
391
|
+
const fileResults = await Promise.all(filePromises);
|
|
392
|
+
for (const result of fileResults) {
|
|
393
|
+
if (result == null) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
assetsIndex[result.assetKey] = result.asset;
|
|
397
|
+
for (const batchItem of result.batchItems) {
|
|
398
|
+
batch.add(batchItem);
|
|
399
|
+
}
|
|
383
400
|
}
|
|
384
401
|
console.log(`✅ Scan complete.`);
|
|
385
402
|
await storageProvider.applyBatch(batch);
|
|
@@ -662,7 +662,7 @@ export async function action(actionArgs) {
|
|
|
662
662
|
packageJsonScripts['fastly:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
|
|
663
663
|
}
|
|
664
664
|
else if (storageMode === 's3') {
|
|
665
|
-
packageJsonScripts['publish'] = 'npx @fastly/compute-js-static-publish publish-content
|
|
665
|
+
packageJsonScripts['s3:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
|
|
666
666
|
}
|
|
667
667
|
resourceFiles['package.json'] = JSON.stringify({
|
|
668
668
|
name,
|
|
@@ -908,11 +908,11 @@ To publish your content to your S3-compatible bucket
|
|
|
908
908
|
|
|
909
909
|
Using an AWS profile set with "aws configure", type:
|
|
910
910
|
cd ${COMPUTE_JS_DIR}
|
|
911
|
-
AWS_PROFILE=xxxx npm run publish
|
|
911
|
+
AWS_PROFILE=xxxx npm run s3:publish
|
|
912
912
|
|
|
913
913
|
Using AWS IAM credentials, type:
|
|
914
914
|
cd ${COMPUTE_JS_DIR}
|
|
915
|
-
AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npm run publish
|
|
915
|
+
AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npm run s3:publish
|
|
916
916
|
|
|
917
917
|
To run your Compute application locally
|
|
918
918
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type ContentCompressionTypes } from '../../models/compression/index.js';
|
|
2
2
|
export type Variants = 'original' | ContentCompressionTypes;
|
|
3
|
-
export declare function ensureVariantFileExists(variantFilePath: string, variant: Variants, file: string): Promise<void>;
|
|
3
|
+
export declare function ensureVariantFileExists(variantFilePath: string, variant: Variants, file: string, verbose: boolean): Promise<void>;
|
|
4
4
|
//# sourceMappingURL=variants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/variants.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAIjF,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,uBAAuB,CAAC;AAE5D,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/variants.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAIjF,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,uBAAuB,CAAC;AAE5D,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,iBA6BjB"}
|
|
@@ -5,19 +5,23 @@
|
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import { algs } from '../compression/index.js';
|
|
7
7
|
import { rootRelative } from './files.js';
|
|
8
|
-
export async function ensureVariantFileExists(variantFilePath, variant, file) {
|
|
8
|
+
export async function ensureVariantFileExists(variantFilePath, variant, file, verbose) {
|
|
9
9
|
// Compress/prepare the asset if it doesn't already exist
|
|
10
10
|
// We disregard chunked copies of the file and only check for the existence
|
|
11
11
|
// of the main copy of the file at this point.
|
|
12
12
|
if (!fs.existsSync(variantFilePath)) {
|
|
13
13
|
if (variant === 'original') {
|
|
14
14
|
fs.cpSync(file, variantFilePath);
|
|
15
|
-
|
|
15
|
+
if (verbose) {
|
|
16
|
+
console.log(` 📄→📄 Copied file '${rootRelative(file)}' to '${rootRelative(variantFilePath)}'.`);
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
20
|
const compressTo = algs[variant];
|
|
19
21
|
await compressTo(file, variantFilePath);
|
|
20
|
-
|
|
22
|
+
if (verbose) {
|
|
23
|
+
console.log(` 📄→🗄️ Compressed file '${rootRelative(file)}' to '${rootRelative(variantFilePath)}' [${variant}].`);
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
// However, if we did just create the file,
|
|
23
27
|
// we delete any chunked copies that may exist as they can be out of date.
|