@fastly/compute-js-static-publish 4.0.0-alpha.0 → 4.0.0-alpha.2
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 +25 -10
- package/build/cli/commands/build-static.d.ts.map +1 -1
- package/build/cli/commands/build-static.js +16 -11
- package/build/cli/commands/clean-object-store.js +1 -1
- package/build/cli/commands/init-app.d.ts.map +1 -1
- package/build/cli/commands/init-app.js +24 -13
- package/build/cli/compression/brotli.js +2 -2
- package/build/cli/index.js +3 -0
- package/build/cli/load-config.d.ts +4 -1
- package/build/cli/load-config.d.ts.map +1 -1
- package/build/cli/load-config.js +12 -6
- package/build/cli/presets/preset-base.d.ts +1 -0
- package/build/cli/presets/preset-base.d.ts.map +1 -1
- package/build/cli/util/hash.d.ts +4 -1
- package/build/cli/util/hash.d.ts.map +1 -1
- package/build/cli/util/hash.js +3 -2
- package/build/server/assets/content-assets.d.ts +6 -6
- package/build/server/assets/content-assets.d.ts.map +1 -1
- package/build/server/assets/content-assets.js +43 -36
- package/build/server/object-store/inline-store-entry.d.ts +3 -1
- package/build/server/object-store/inline-store-entry.d.ts.map +1 -1
- package/build/server/object-store/inline-store-entry.js +5 -1
- package/build/server/publisher-server.d.ts +1 -1
- package/build/server/publisher-server.d.ts.map +1 -1
- package/build/server/publisher-server.js +36 -3
- package/build/types/compute.d.ts +1 -0
- package/build/types/compute.d.ts.map +1 -1
- package/build/types/content-assets.d.ts +2 -1
- package/build/types/content-assets.d.ts.map +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -76,19 +76,31 @@ For more advanced uses, such as accessing the contents of these file in your own
|
|
|
76
76
|
Publishing is meant to run each time before building your Compute@Edge application into a Wasm file.
|
|
77
77
|
If the files in `--root-dir` have changed, then a new set of files will be published.
|
|
78
78
|
|
|
79
|
+
### Content Compression
|
|
80
|
+
|
|
81
|
+
During publishing, this tool supports pre-compression of content. By default, your assets are compressed using the Brotli
|
|
82
|
+
and gzip algorithms, and then stored alongside the original files in your Wasm artifact (or Object Store).
|
|
83
|
+
|
|
84
|
+
> Note: By default, pre-compressed content assets are not generated when the object store is not used.
|
|
85
|
+
This is done to prevent the inclusion multiple of copies of each asset from making the Wasm binary too large.
|
|
86
|
+
If you want to pre-compress assets when not using Object Store, add a value for 'contentCompression' to your
|
|
87
|
+
`static-publish.rc.js` file.
|
|
88
|
+
|
|
79
89
|
## CLI options
|
|
80
90
|
|
|
81
|
-
|
|
91
|
+
Except for `--root-dir`, most arguments are optional.
|
|
82
92
|
|
|
83
93
|
```shell
|
|
84
94
|
npx @fastly/compute-js-static-publish \
|
|
85
95
|
--root-dir=./build \
|
|
86
|
-
--
|
|
96
|
+
--public-dir=./build/public \
|
|
87
97
|
--static-dir=./build/public/static \
|
|
88
98
|
--output=./compute-js \
|
|
89
99
|
--spa=./build/spa.html
|
|
90
100
|
```
|
|
91
101
|
|
|
102
|
+
If you provide options, they override the defaults described below.
|
|
103
|
+
|
|
92
104
|
Any configuration options will be written to a `static-publish.rc.js` file, and used each time you build your Compute@Edge
|
|
93
105
|
application.
|
|
94
106
|
|
|
@@ -128,12 +140,13 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
|
|
|
128
140
|
|
|
129
141
|
These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute@Edge application.
|
|
130
142
|
|
|
131
|
-
| Option
|
|
132
|
-
|
|
133
|
-
| `name`
|
|
134
|
-
| `description`
|
|
135
|
-
| `author`
|
|
136
|
-
| `service-id`
|
|
143
|
+
| Option | Default | Description |
|
|
144
|
+
|---------------------|------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
|
|
145
|
+
| `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
|
|
146
|
+
| `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
|
|
147
|
+
| `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
|
|
148
|
+
| `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
|
|
149
|
+
| `object-store-name` | (None) | The name of a Fastly Object Store to hold the content assets. It must be linked to the service specified by `--service-id`. |
|
|
137
150
|
|
|
138
151
|
## Usage with frameworks and static site generators
|
|
139
152
|
|
|
@@ -180,7 +193,7 @@ You can further configure the server by making modifications to the `server` key
|
|
|
180
193
|
|--------------------|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
181
194
|
| `publicDirPrefix` | `''` | Prefix to apply to web requests. Effectively, a directory within `rootDir` that is used by the web server to determine the asset to respond with. |
|
|
182
195
|
| `staticItems` | `[]` | A test to apply to item names to decide whether to serve them as "static" files, in other words, with a long TTL. These are used for files that are not expected to change. They can be provided as a string or array of strings. |
|
|
183
|
-
| `compression` | `[ 'br', 'gzip' ]` | If the request contains an `Accept-Encoding` header, they are checked
|
|
196
|
+
| `compression` | `[ 'br', 'gzip' ]` | If the request contains an `Accept-Encoding` header, they are checked for the values listed here. The compression algorithm that produces the smallest transfer size is applied. |
|
|
184
197
|
| `autoExt` | `[]` | When a file is not found, and it doesn't end in a slash, then try auto-ext: we try to serve a file with the same name post-fixed with the specified strings, tested in the order listed. These are tested before auto-index, if any. |
|
|
185
198
|
| `autoIndex` | `[]` | When a file is not found, then try auto-index: we treat it as a directory, then try to serve a file that has the specified strings, tested in the order listed. |
|
|
186
199
|
| `spaFile` | `null` | Asset key of a content item to serve with a status code of `200` when a GET request comes arrives for an unknown asset, and the Accept header includes text/html. |
|
|
@@ -306,7 +319,8 @@ And that's it! It should be possible to run this task to clean up once in a whil
|
|
|
306
319
|
binary if Object Store mode is not enabled.
|
|
307
320
|
|
|
308
321
|
* `contentCompression` - During the publishing, the tool will pre-generate compressed versions of content assets in these
|
|
309
|
-
formats and make them available to the Publisher Server or your application. Default value is [ 'br' | 'gzip' ]
|
|
322
|
+
formats and make them available to the Publisher Server or your application. Default value is [ 'br' | 'gzip' ] if
|
|
323
|
+
Object Store is enabled, or [] if Object Store is not enabled.
|
|
310
324
|
|
|
311
325
|
* `moduleAssetInclusionTest` - Optionally specify a test function that can be run against each enumerated asset during
|
|
312
326
|
the publishing, to determine whether to include the asset as a module asset. For every file, this function is passed
|
|
@@ -422,6 +436,7 @@ const storeEntry = await asset.getStoreEntry();
|
|
|
422
436
|
|
|
423
437
|
storeEntry.contentEncoding; // null, 'br', 'gzip'
|
|
424
438
|
storeEntry.hash; // SHA256 of the contents of the file
|
|
439
|
+
storeEntry.size; // Size of file in bytes
|
|
425
440
|
```
|
|
426
441
|
|
|
427
442
|
Regardless of which store these objects come from, they implement the `Body` interface as defined by `@fastly/js-compute`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AAuCA,OAAO,eAAe,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AAuCA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AA6IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAoe5F"}
|
|
@@ -34,7 +34,7 @@ import * as path from "path";
|
|
|
34
34
|
import * as url from "url";
|
|
35
35
|
import { loadConfigFile } from "../load-config.js";
|
|
36
36
|
import { applyDefaults } from "../util/data.js";
|
|
37
|
-
import {
|
|
37
|
+
import { calculateFileSizeAndHash } from "../util/hash.js";
|
|
38
38
|
import { getFiles } from "../util/files.js";
|
|
39
39
|
import { generateOrLoadPublishId } from "../util/publish-id.js";
|
|
40
40
|
import { loadApiKey } from "../util/fastly-api.js";
|
|
@@ -113,7 +113,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
113
113
|
console.log(`Publish ID: ${publishId}`);
|
|
114
114
|
console.log("🚀 Building loader...");
|
|
115
115
|
const errors = [];
|
|
116
|
-
const config = await loadConfigFile(errors);
|
|
116
|
+
const { normalized: config, raw: configRaw } = await loadConfigFile(errors);
|
|
117
117
|
if (config == null) {
|
|
118
118
|
console.error("❌ Can't load static-publish.rc.js");
|
|
119
119
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
@@ -220,18 +220,23 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
220
220
|
});
|
|
221
221
|
const stats = fs.statSync(file);
|
|
222
222
|
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
223
|
-
const hash =
|
|
223
|
+
const { size, hash } = calculateFileSizeAndHash(file);
|
|
224
224
|
return {
|
|
225
225
|
file,
|
|
226
226
|
assetKey,
|
|
227
227
|
lastModifiedTime,
|
|
228
228
|
hash,
|
|
229
|
+
size,
|
|
229
230
|
...contentAssetInclusionResult,
|
|
230
231
|
...moduleAssetInclusionResult,
|
|
231
232
|
...contentTypeTestResult,
|
|
232
233
|
};
|
|
233
234
|
});
|
|
234
235
|
console.log("🚀 Preparing content assets ...");
|
|
236
|
+
if (objectStoreName == null && configRaw != null && !("contentCompression" in configRaw)) {
|
|
237
|
+
console.log(`⚠️ Notice: By default, pre-compressed content assets are not generated when object store is not used.`);
|
|
238
|
+
console.log(" If you want to pre-compress assets, add a value for 'contentCompression' to your static-publish.rc.js.");
|
|
239
|
+
}
|
|
235
240
|
// Create "static content" dir that will be used to hold a copy of static files.
|
|
236
241
|
// NOTE: this is needed because includeBytes doesn't seem to be able to traverse up to parent dir of the Compute project.
|
|
237
242
|
const staticContentDir = './src/static-content';
|
|
@@ -255,15 +260,15 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
255
260
|
}
|
|
256
261
|
contentItems++;
|
|
257
262
|
console.log(`✔️ [${contentItems}] ${assetInfo.assetKey}: ${JSON.stringify(assetInfo.contentType)}`);
|
|
258
|
-
const { file, assetKey, contentType, text, hash, lastModifiedTime, } = assetInfo;
|
|
263
|
+
const { file, assetKey, contentType, text, hash, size, lastModifiedTime, } = assetInfo;
|
|
259
264
|
const entryBase = {
|
|
260
265
|
assetKey,
|
|
261
266
|
contentType,
|
|
262
267
|
lastModifiedTime,
|
|
263
|
-
hash,
|
|
264
268
|
text,
|
|
265
269
|
fileInfo: {
|
|
266
270
|
hash,
|
|
271
|
+
size,
|
|
267
272
|
},
|
|
268
273
|
};
|
|
269
274
|
let metadata;
|
|
@@ -278,8 +283,8 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
278
283
|
const staticFilePath = `${staticContentFilePath}_${alg}`;
|
|
279
284
|
if (await compressTo(file, staticFilePath, text)) {
|
|
280
285
|
console.log(`✔️ Compressed ${text ? 'text' : 'binary'} asset "${file}" to "${staticFilePath}" [${alg}].`);
|
|
281
|
-
const hash =
|
|
282
|
-
func(alg, staticFilePath, hash);
|
|
286
|
+
const { size, hash } = calculateFileSizeAndHash(staticFilePath);
|
|
287
|
+
func(alg, staticFilePath, hash, size);
|
|
283
288
|
}
|
|
284
289
|
}
|
|
285
290
|
}
|
|
@@ -292,8 +297,8 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
292
297
|
fs.cpSync(file, staticFilePath);
|
|
293
298
|
console.log(`✔️ Copied ${text ? 'text' : 'binary'} asset "${file}" to "${staticFilePath}".`);
|
|
294
299
|
const compressedFileInfos = {};
|
|
295
|
-
await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash) => {
|
|
296
|
-
compressedFileInfos[alg] = { staticFilePath, hash };
|
|
300
|
+
await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash, size) => {
|
|
301
|
+
compressedFileInfos[alg] = { staticFilePath, hash, size };
|
|
297
302
|
});
|
|
298
303
|
metadata = {
|
|
299
304
|
...entryBase,
|
|
@@ -318,9 +323,9 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
318
323
|
text,
|
|
319
324
|
});
|
|
320
325
|
const compressedFileInfos = {};
|
|
321
|
-
await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash) => {
|
|
326
|
+
await prepareCompressedVersions(contentCompression, (alg, staticFilePath, hash, size) => {
|
|
322
327
|
const objectStoreKey = `${publishId}:${assetKey}_${alg}_${hash}`;
|
|
323
|
-
compressedFileInfos[alg] = { staticFilePath, objectStoreKey, hash };
|
|
328
|
+
compressedFileInfos[alg] = { staticFilePath, objectStoreKey, hash, size };
|
|
324
329
|
objectStoreItems.push({
|
|
325
330
|
objectStoreKey,
|
|
326
331
|
staticFilePath,
|
|
@@ -7,7 +7,7 @@ import { getObjectStoreKeysFromMetadata } from "../../util/metadata.js";
|
|
|
7
7
|
export async function cleanObjectStore(commandLineValues) {
|
|
8
8
|
const { publishId } = generateOrLoadPublishId();
|
|
9
9
|
const errors = [];
|
|
10
|
-
const config = await loadConfigFile(errors);
|
|
10
|
+
const { normalized: config } = await loadConfigFile(errors);
|
|
11
11
|
if (config == null) {
|
|
12
12
|
console.error("❌ Can't load static-publish.rc.js");
|
|
13
13
|
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAoPvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAma5D"}
|
|
@@ -19,6 +19,7 @@ const defaultOptions = {
|
|
|
19
19
|
name: 'compute-js-static-site',
|
|
20
20
|
description: 'Compute@Edge static site',
|
|
21
21
|
serviceId: undefined,
|
|
22
|
+
objectStoreName: undefined,
|
|
22
23
|
};
|
|
23
24
|
// Current directory of this program that's running.
|
|
24
25
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
@@ -155,6 +156,13 @@ function processCommandLineArgs(commandLineValues) {
|
|
|
155
156
|
serviceId = serviceIdValue;
|
|
156
157
|
}
|
|
157
158
|
}
|
|
159
|
+
let objectStoreName;
|
|
160
|
+
{
|
|
161
|
+
const objectStoreNameValue = commandLineValues['object-store-name'];
|
|
162
|
+
if (objectStoreNameValue == null || typeof objectStoreNameValue === 'string') {
|
|
163
|
+
objectStoreName = objectStoreNameValue;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
158
166
|
return {
|
|
159
167
|
rootDir,
|
|
160
168
|
publicDir,
|
|
@@ -167,6 +175,7 @@ function processCommandLineArgs(commandLineValues) {
|
|
|
167
175
|
author,
|
|
168
176
|
description,
|
|
169
177
|
serviceId,
|
|
178
|
+
objectStoreName,
|
|
170
179
|
};
|
|
171
180
|
}
|
|
172
181
|
function pickKeys(keys, object) {
|
|
@@ -245,7 +254,7 @@ export function initApp(commandLineValues) {
|
|
|
245
254
|
...options,
|
|
246
255
|
...(preset != null ? preset.defaultOptions : {}),
|
|
247
256
|
...pickKeys(['author', 'name', 'description'], (packageJson ?? {})),
|
|
248
|
-
...pickKeys(['rootDir', 'publicDir', 'staticDirs', 'spa', 'notFoundPage', 'autoIndex', 'autoExt', 'author', 'name', 'description', 'serviceId'], commandLineAppOptions),
|
|
257
|
+
...pickKeys(['rootDir', 'publicDir', 'staticDirs', 'spa', 'notFoundPage', 'autoIndex', 'autoExt', 'author', 'name', 'description', 'serviceId', 'objectStoreName'], commandLineAppOptions),
|
|
249
258
|
};
|
|
250
259
|
if (preset != null) {
|
|
251
260
|
if (!preset.check(packageJson, options)) {
|
|
@@ -356,6 +365,7 @@ export function initApp(commandLineValues) {
|
|
|
356
365
|
const name = options.name;
|
|
357
366
|
const description = options.description;
|
|
358
367
|
const fastlyServiceId = options.serviceId;
|
|
368
|
+
const objectStoreName = options.objectStoreName;
|
|
359
369
|
function rootRelative(itemPath) {
|
|
360
370
|
if (itemPath == null) {
|
|
361
371
|
return null;
|
|
@@ -364,17 +374,18 @@ export function initApp(commandLineValues) {
|
|
|
364
374
|
return v.startsWith('..') ? v : './' + v;
|
|
365
375
|
}
|
|
366
376
|
console.log('');
|
|
367
|
-
console.log('Asset Root Dir
|
|
368
|
-
console.log('Public Dir
|
|
369
|
-
console.log('Static Dir
|
|
370
|
-
console.log('SPA
|
|
371
|
-
console.log('404 Page
|
|
372
|
-
console.log('Auto-Index
|
|
373
|
-
console.log('Auto-Ext
|
|
374
|
-
console.log('name
|
|
375
|
-
console.log('author
|
|
376
|
-
console.log('description
|
|
377
|
-
console.log('Service ID
|
|
377
|
+
console.log('Asset Root Dir :', rootRelative(rootDir));
|
|
378
|
+
console.log('Public Dir :', rootRelative(publicDir));
|
|
379
|
+
console.log('Static Dir :', staticDirs.length > 0 ? staticDirs.map(rootRelative) : '(None)');
|
|
380
|
+
console.log('SPA :', rootRelative(spaFilename) ?? '(None)');
|
|
381
|
+
console.log('404 Page :', rootRelative(notFoundPageFilename) ?? '(None)');
|
|
382
|
+
console.log('Auto-Index :', autoIndex.length > 0 ? autoIndex.map(rootRelative) : '(None)');
|
|
383
|
+
console.log('Auto-Ext :', autoExt.length > 0 ? autoExt.map(rootRelative) : '(None)');
|
|
384
|
+
console.log('name :', name);
|
|
385
|
+
console.log('author :', author);
|
|
386
|
+
console.log('description :', description);
|
|
387
|
+
console.log('Service ID :', fastlyServiceId ?? '(None)');
|
|
388
|
+
console.log('Object Store Name :', objectStoreName ?? '(None)');
|
|
378
389
|
console.log('');
|
|
379
390
|
if (useWebpack) {
|
|
380
391
|
console.log('Creating project with Webpack.');
|
|
@@ -504,7 +515,7 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
|
504
515
|
/** @type {import('@fastly/compute-js-static-publish').StaticPublisherConfig} */
|
|
505
516
|
const config = {
|
|
506
517
|
rootDir: ${JSON.stringify(rootDirRel)},
|
|
507
|
-
// objectStore: false,
|
|
518
|
+
${(objectStoreName != null ? 'objectStore: ' + JSON.stringify(objectStoreName) : '// objectStore: false')},
|
|
508
519
|
// excludeDirs: [ './node_modules' ],
|
|
509
520
|
// excludeDotFiles: true,
|
|
510
521
|
// includeWellKnown: true,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import
|
|
2
|
+
import zlib from 'zlib';
|
|
3
3
|
export const key = 'br';
|
|
4
4
|
export async function compressTo(src, dest, isText) {
|
|
5
5
|
const buffer = fs.readFileSync(src);
|
|
6
|
-
const resultBuffer =
|
|
6
|
+
const resultBuffer = zlib.brotliCompressSync(buffer);
|
|
7
7
|
// Don't actually create the file if it would be bigger
|
|
8
8
|
if (resultBuffer.length < buffer.length) {
|
|
9
9
|
fs.writeFileSync(dest, resultBuffer);
|
package/build/cli/index.js
CHANGED
|
@@ -61,6 +61,9 @@ const optionDefinitions = [
|
|
|
61
61
|
{ name: 'description', type: String, },
|
|
62
62
|
// Fastly Service ID to be added to the fastly.toml that is generated.
|
|
63
63
|
{ name: 'service-id', type: String },
|
|
64
|
+
// The name of a Fastly Object Store to hold the content assets.
|
|
65
|
+
// It must be linked to the service specified by `--service-id`.
|
|
66
|
+
{ name: 'object-store-name', type: String },
|
|
64
67
|
// Clean object store mode
|
|
65
68
|
{ name: 'clean-object-store', type: Boolean, },
|
|
66
69
|
];
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { StaticPublisherConfigNormalized } from "../types/config-normalized.js";
|
|
2
|
-
export declare function loadConfigFile(errors?: string[]): Promise<
|
|
2
|
+
export declare function loadConfigFile(errors?: string[]): Promise<{
|
|
3
|
+
normalized: StaticPublisherConfigNormalized | null;
|
|
4
|
+
raw: any;
|
|
5
|
+
}>;
|
|
3
6
|
//# sourceMappingURL=load-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/cli/load-config.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,+BAA+B,EAEhC,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/cli/load-config.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,+BAA+B,EAEhC,MAAM,+BAA+B,CAAC;AAyVvC,wBAAsB,cAAc,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC;IAAC,UAAU,EAAE,+BAA+B,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAC,CAAC,CAiBnI"}
|
package/build/cli/load-config.js
CHANGED
|
@@ -267,7 +267,12 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
|
|
|
267
267
|
errors.push('contentAssetInclusionTest, if specified, must be null or a function.');
|
|
268
268
|
}
|
|
269
269
|
if (!isSpecified(config, 'contentCompression')) {
|
|
270
|
-
|
|
270
|
+
if (objectStore != null) {
|
|
271
|
+
contentCompression = ['br', 'gzip'];
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
contentCompression = [];
|
|
275
|
+
}
|
|
271
276
|
}
|
|
272
277
|
else if (contentCompression === null) {
|
|
273
278
|
contentCompression = [];
|
|
@@ -342,16 +347,17 @@ const normalizeConfig = buildNormalizeFunctionForObject((config, errors) => {
|
|
|
342
347
|
};
|
|
343
348
|
});
|
|
344
349
|
export async function loadConfigFile(errors = []) {
|
|
345
|
-
let
|
|
350
|
+
let raw = undefined;
|
|
346
351
|
const staticPublishRcPath = path.resolve('./static-publish.rc.js');
|
|
347
352
|
try {
|
|
348
|
-
|
|
353
|
+
raw = (await import(staticPublishRcPath)).default;
|
|
349
354
|
}
|
|
350
355
|
catch {
|
|
351
356
|
errors.push('Unable to load ' + staticPublishRcPath);
|
|
352
357
|
}
|
|
353
|
-
|
|
354
|
-
|
|
358
|
+
let normalized = undefined;
|
|
359
|
+
if (raw != null) {
|
|
360
|
+
normalized = normalizeConfig(raw, errors);
|
|
355
361
|
}
|
|
356
|
-
return
|
|
362
|
+
return { normalized: normalized ?? null, raw };
|
|
357
363
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset-base.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/preset-base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,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;
|
|
1
|
+
{"version":3,"file":"preset-base.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/preset-base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,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,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACpC,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC;CAC9D"}
|
package/build/cli/util/hash.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/cli/util/hash.ts"],"names":[],"mappings":"AAGA,wBAAgB,
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/cli/util/hash.ts"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM;;;EAUxD"}
|
package/build/cli/util/hash.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
export function
|
|
3
|
+
export function calculateFileSizeAndHash(filename) {
|
|
4
4
|
const fileBuffer = fs.readFileSync(filename);
|
|
5
|
+
const size = fileBuffer.length;
|
|
5
6
|
const hash = crypto.createHash('sha256');
|
|
6
7
|
hash.update(fileBuffer);
|
|
7
|
-
return hash.digest('hex');
|
|
8
|
+
return { size, hash: hash.digest('hex') };
|
|
8
9
|
}
|
|
@@ -5,11 +5,11 @@ import type { ContentCompressionTypes } from "../../constants/compression.js";
|
|
|
5
5
|
export declare class ContentInlineAsset implements ContentAsset {
|
|
6
6
|
readonly isInline: boolean;
|
|
7
7
|
private readonly metadata;
|
|
8
|
-
private readonly
|
|
9
|
-
private readonly
|
|
8
|
+
private readonly sourceAndInfo;
|
|
9
|
+
private readonly compressedSourcesAndInfo;
|
|
10
10
|
constructor(metadata: ContentAssetMetadataMapEntryInline);
|
|
11
11
|
get assetKey(): string;
|
|
12
|
-
getStoreEntry(
|
|
12
|
+
getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
|
|
13
13
|
getBytes(): Uint8Array;
|
|
14
14
|
getText(): string;
|
|
15
15
|
getMetadata(): ContentAssetMetadataMapEntry;
|
|
@@ -18,11 +18,11 @@ export declare class ContentObjectStoreAsset implements ContentAsset {
|
|
|
18
18
|
readonly isInline: boolean;
|
|
19
19
|
private readonly metadata;
|
|
20
20
|
private readonly objectStoreName;
|
|
21
|
-
private readonly
|
|
22
|
-
private readonly
|
|
21
|
+
private readonly sourceAndInfo;
|
|
22
|
+
private readonly compressedSourcesAndInfo;
|
|
23
23
|
constructor(metadata: ContentAssetMetadataMapEntryObjectStore, objectStoreName: string);
|
|
24
24
|
get assetKey(): string;
|
|
25
|
-
getStoreEntry(
|
|
25
|
+
getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
|
|
26
26
|
getBytes(): Uint8Array;
|
|
27
27
|
getText(): string;
|
|
28
28
|
getMetadata(): ContentAssetMetadataMapEntry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-assets.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-assets.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,KAAK,EAEV,YAAY,EACZ,uBAAuB,EACvB,4BAA4B,EAC5B,kCAAkC,EAClC,uCAAuC,EACxC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"content-assets.d.ts","sourceRoot":"","sources":["../../../src/server/assets/content-assets.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,OAAO,KAAK,EAEV,YAAY,EACZ,uBAAuB,EACvB,4BAA4B,EAC5B,kCAAkC,EAClC,uCAAuC,EACxC,MAAM,+BAA+B,CAAC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ObjectStore } from "fastly:object-store";
|
|
|
3
3
|
import { AssetManager } from "./asset-manager.js";
|
|
4
4
|
import { InlineStoreEntry } from "../object-store/inline-store-entry.js";
|
|
5
5
|
const decoder = new TextDecoder();
|
|
6
|
+
function findMatchingSourceAndInfo(acceptEncodingsGroups, defaultSourceAndInfo, sourceAndInfoForEncodingFn) {
|
|
7
|
+
let sourceAndInfo;
|
|
8
|
+
let contentEncoding = null;
|
|
9
|
+
if (acceptEncodingsGroups != null) {
|
|
10
|
+
for (const encodingGroup of acceptEncodingsGroups) {
|
|
11
|
+
const sourceAndInfosForEncodingsGroup = encodingGroup
|
|
12
|
+
.map(encoding => ({ encoding, sourceAndInfo: sourceAndInfoForEncodingFn(encoding) }))
|
|
13
|
+
.filter(x => x.sourceAndInfo != null);
|
|
14
|
+
if (sourceAndInfosForEncodingsGroup.length === 0) {
|
|
15
|
+
// If no encoding in this group is available then move to next group
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
// Sort the items, putting the smallest size first
|
|
19
|
+
sourceAndInfosForEncodingsGroup
|
|
20
|
+
.sort((a, b) => a.sourceAndInfo.size - b.sourceAndInfo.size);
|
|
21
|
+
// The first item is the one we want.
|
|
22
|
+
sourceAndInfo = sourceAndInfosForEncodingsGroup[0].sourceAndInfo;
|
|
23
|
+
contentEncoding = sourceAndInfosForEncodingsGroup[0].encoding;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
sourceAndInfo ?? (sourceAndInfo = defaultSourceAndInfo);
|
|
28
|
+
return { sourceAndInfo, contentEncoding };
|
|
29
|
+
}
|
|
6
30
|
export class ContentInlineAsset {
|
|
7
31
|
constructor(metadata) {
|
|
8
32
|
this.isInline = true;
|
|
9
33
|
this.metadata = metadata;
|
|
10
|
-
this.
|
|
34
|
+
this.sourceAndInfo = {
|
|
11
35
|
source: includeBytes(metadata.fileInfo.staticFilePath),
|
|
12
36
|
hash: metadata.fileInfo.hash,
|
|
37
|
+
size: metadata.fileInfo.size,
|
|
13
38
|
};
|
|
14
|
-
this.
|
|
39
|
+
this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
|
|
15
40
|
.reduce((obj, [key, value]) => {
|
|
16
41
|
obj[key] = {
|
|
17
42
|
source: includeBytes(value.staticFilePath),
|
|
18
43
|
hash: value.hash,
|
|
44
|
+
size: value.size,
|
|
19
45
|
};
|
|
20
46
|
return obj;
|
|
21
47
|
}, {});
|
|
@@ -23,29 +49,19 @@ export class ContentInlineAsset {
|
|
|
23
49
|
get assetKey() {
|
|
24
50
|
return this.metadata.assetKey;
|
|
25
51
|
}
|
|
26
|
-
async getStoreEntry(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (const encoding of acceptEncodings) {
|
|
31
|
-
sourceAndHash = this.compressedSourcesAndHashes[encoding];
|
|
32
|
-
if (sourceAndHash != null) {
|
|
33
|
-
contentEncoding = encoding;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
sourceAndHash ?? (sourceAndHash = this.sourceAndHash);
|
|
39
|
-
return new InlineStoreEntry(sourceAndHash.source, contentEncoding, sourceAndHash.hash);
|
|
52
|
+
async getStoreEntry(acceptEncodingsGroups = []) {
|
|
53
|
+
const { sourceAndInfo, contentEncoding } = findMatchingSourceAndInfo(acceptEncodingsGroups, this.sourceAndInfo, encoding => this.compressedSourcesAndInfo[encoding]);
|
|
54
|
+
const { source, hash, size } = sourceAndInfo;
|
|
55
|
+
return new InlineStoreEntry(source, contentEncoding, hash, size);
|
|
40
56
|
}
|
|
41
57
|
getBytes() {
|
|
42
|
-
return this.
|
|
58
|
+
return this.sourceAndInfo.source;
|
|
43
59
|
}
|
|
44
60
|
getText() {
|
|
45
61
|
if (!this.metadata.text) {
|
|
46
62
|
throw new Error("Can't getText() for non-text content");
|
|
47
63
|
}
|
|
48
|
-
return decoder.decode(this.
|
|
64
|
+
return decoder.decode(this.sourceAndInfo.source);
|
|
49
65
|
}
|
|
50
66
|
getMetadata() {
|
|
51
67
|
return this.metadata;
|
|
@@ -56,15 +72,17 @@ export class ContentObjectStoreAsset {
|
|
|
56
72
|
this.isInline = false;
|
|
57
73
|
this.metadata = metadata;
|
|
58
74
|
this.objectStoreName = objectStoreName;
|
|
59
|
-
this.
|
|
75
|
+
this.sourceAndInfo = {
|
|
60
76
|
source: metadata.fileInfo.objectStoreKey,
|
|
61
77
|
hash: metadata.fileInfo.hash,
|
|
78
|
+
size: metadata.fileInfo.size,
|
|
62
79
|
};
|
|
63
|
-
this.
|
|
80
|
+
this.compressedSourcesAndInfo = Object.entries(metadata.compressedFileInfos)
|
|
64
81
|
.reduce((obj, [key, value]) => {
|
|
65
82
|
obj[key] = {
|
|
66
83
|
source: value.objectStoreKey,
|
|
67
84
|
hash: value.hash,
|
|
85
|
+
size: value.size,
|
|
68
86
|
};
|
|
69
87
|
return obj;
|
|
70
88
|
}, {});
|
|
@@ -72,26 +90,15 @@ export class ContentObjectStoreAsset {
|
|
|
72
90
|
get assetKey() {
|
|
73
91
|
return this.metadata.assetKey;
|
|
74
92
|
}
|
|
75
|
-
async getStoreEntry(
|
|
76
|
-
|
|
77
|
-
let contentEncoding = null;
|
|
78
|
-
if (acceptEncodings != null) {
|
|
79
|
-
for (const encoding of acceptEncodings) {
|
|
80
|
-
sourceAndHash = this.compressedSourcesAndHashes[encoding];
|
|
81
|
-
if (sourceAndHash != null) {
|
|
82
|
-
contentEncoding = encoding;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
sourceAndHash ?? (sourceAndHash = this.sourceAndHash);
|
|
88
|
-
const hash = sourceAndHash.hash;
|
|
93
|
+
async getStoreEntry(acceptEncodingsGroups = []) {
|
|
94
|
+
const { sourceAndInfo, contentEncoding } = findMatchingSourceAndInfo(acceptEncodingsGroups, this.sourceAndInfo, encoding => this.compressedSourcesAndInfo[encoding]);
|
|
89
95
|
const objectStore = new ObjectStore(this.objectStoreName);
|
|
90
96
|
let retries = 3;
|
|
91
97
|
while (retries > 0) {
|
|
92
|
-
const storeEntry = await objectStore.get(
|
|
98
|
+
const storeEntry = await objectStore.get(sourceAndInfo.source);
|
|
93
99
|
if (storeEntry != null) {
|
|
94
|
-
|
|
100
|
+
const { hash, size } = sourceAndInfo;
|
|
101
|
+
return Object.assign(storeEntry, { contentEncoding, hash, size });
|
|
95
102
|
}
|
|
96
103
|
// Note the null does NOT mean 404. The fact that we are here means
|
|
97
104
|
// metadata exists for this path, and we're just trying to get the data from
|
|
@@ -4,7 +4,8 @@ export declare class InlineStoreEntry implements StoreEntry {
|
|
|
4
4
|
_body: ReadableStreamForBytes;
|
|
5
5
|
_contentEncoding: string | null;
|
|
6
6
|
_hash: string;
|
|
7
|
-
|
|
7
|
+
_size: number;
|
|
8
|
+
constructor(array: Uint8Array, contentEncoding: string | null, hash: string, size: number);
|
|
8
9
|
get body(): ReadableStream<Uint8Array>;
|
|
9
10
|
get bodyUsed(): boolean;
|
|
10
11
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
@@ -13,6 +14,7 @@ export declare class InlineStoreEntry implements StoreEntry {
|
|
|
13
14
|
json(): Promise<any>;
|
|
14
15
|
get contentEncoding(): string | null;
|
|
15
16
|
get hash(): string;
|
|
17
|
+
get size(): number;
|
|
16
18
|
}
|
|
17
19
|
declare class ReadableStreamForBytes extends ReadableStream<Uint8Array> {
|
|
18
20
|
_disturbed: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-store-entry.d.ts","sourceRoot":"","sources":["../../../src/server/object-store/inline-store-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKpD,qBAAa,gBAAiB,YAAW,UAAU;IACjD,SAAS,EAAE,OAAO,CAAC;IAEnB,KAAK,EAAE,sBAAsB,CAAC;IAE9B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,KAAK,EAAE,MAAM,CAAC;gBAEF,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"inline-store-entry.d.ts","sourceRoot":"","sources":["../../../src/server/object-store/inline-store-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKpD,qBAAa,gBAAiB,YAAW,UAAU;IACjD,SAAS,EAAE,OAAO,CAAC;IAEnB,KAAK,EAAE,sBAAsB,CAAC;IAE9B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,KAAK,EAAE,MAAM,CAAC;IAEd,KAAK,EAAE,MAAM,CAAC;gBAEF,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAQzF,IAAI,IAAI,IAAI,cAAc,CAAC,UAAU,CAAC,CAErC;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAEK,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAiCzC,MAAM,CAAC,OAAO,cAAqB;IAC7B,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvB,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAK1B,IAAI,eAAe,kBAElB;IAED,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,WAEP;CACF;AAED,cAAM,sBAAuB,SAAQ,cAAc,CAAC,UAAU,CAAC;IAG7D,UAAU,UAAS;gBAEP,KAAK,EAAE,UAAU;IASpB,SAAS,IAAI,2BAA2B,CAAC,UAAU,CAAC;CA6B9D"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// A class designed to give a Body-style interface to Uint8Array.
|
|
2
2
|
// The intended use case is arrays brought in from includeBytes().
|
|
3
3
|
export class InlineStoreEntry {
|
|
4
|
-
constructor(array, contentEncoding, hash) {
|
|
4
|
+
constructor(array, contentEncoding, hash, size) {
|
|
5
5
|
this._body = new ReadableStreamForBytes(array);
|
|
6
6
|
this._consumed = false;
|
|
7
7
|
this._contentEncoding = contentEncoding;
|
|
8
8
|
this._hash = hash;
|
|
9
|
+
this._size = size;
|
|
9
10
|
}
|
|
10
11
|
get body() {
|
|
11
12
|
return this._body;
|
|
@@ -57,6 +58,9 @@ export class InlineStoreEntry {
|
|
|
57
58
|
get hash() {
|
|
58
59
|
return this._hash;
|
|
59
60
|
}
|
|
61
|
+
get size() {
|
|
62
|
+
return this._size;
|
|
63
|
+
}
|
|
60
64
|
}
|
|
61
65
|
InlineStoreEntry.decoder = new TextDecoder();
|
|
62
66
|
class ReadableStreamForBytes extends ReadableStream {
|
|
@@ -13,7 +13,7 @@ export declare class PublisherServer {
|
|
|
13
13
|
private readonly contentAssets;
|
|
14
14
|
constructor(serverConfig: PublisherServerConfigNormalized, contentAssets: ContentAssets);
|
|
15
15
|
getMatchingAsset(path: string): ContentAsset | null;
|
|
16
|
-
findAcceptEncodings(request: Request): ContentCompressionTypes[];
|
|
16
|
+
findAcceptEncodings(request: Request): ContentCompressionTypes[][];
|
|
17
17
|
testExtendedCache(pathname: string): boolean;
|
|
18
18
|
handlePreconditions(request: Request, asset: ContentAsset, responseHeaders: Record<string, string>): Response | null;
|
|
19
19
|
serveAsset(request: Request, asset: ContentAsset, init?: AssetInit): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publisher-server.d.ts","sourceRoot":"","sources":["../../src/server/publisher-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAK3D,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAmB3E,KAAK,SAAS,GA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Aa;IAoB9B,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IA2CnD,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,EAAE,EAAE;IAgDlE,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAalC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,QAAQ,GAAG,IAAI;IA6D9G,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IA0CtF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CA8C/D"}
|
|
@@ -78,9 +78,42 @@ export class PublisherServer {
|
|
|
78
78
|
}
|
|
79
79
|
const found = (request.headers.get('accept-encoding') ?? '')
|
|
80
80
|
.split(',')
|
|
81
|
-
.map(x =>
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
.map(x => {
|
|
82
|
+
let [encodingValue, qValueStr] = x.trim().split(';');
|
|
83
|
+
let qValue; // q value multiplied by 1000
|
|
84
|
+
if (qValueStr == null || !qValueStr.startsWith('q=')) {
|
|
85
|
+
// use default of 1.0
|
|
86
|
+
qValue = 1000;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
qValueStr = qValueStr.slice(2); // remove the q=
|
|
90
|
+
qValue = parseFloat(qValueStr);
|
|
91
|
+
if (Number.isNaN(qValue) || qValue > 1) {
|
|
92
|
+
qValue = 1;
|
|
93
|
+
}
|
|
94
|
+
if (qValue < 0) {
|
|
95
|
+
qValue = 0;
|
|
96
|
+
}
|
|
97
|
+
// q values can have up to 3 decimal digits
|
|
98
|
+
qValue = Math.floor(qValue * 1000);
|
|
99
|
+
}
|
|
100
|
+
return [encodingValue.trim(), qValue];
|
|
101
|
+
})
|
|
102
|
+
.filter(([encoding]) => this.serverConfig.compression.includes(encoding));
|
|
103
|
+
const priorityMap = new Map;
|
|
104
|
+
for (const [encoding, qValue] of found) {
|
|
105
|
+
let typesForQValue = priorityMap.get(qValue);
|
|
106
|
+
if (typesForQValue == null) {
|
|
107
|
+
typesForQValue = [];
|
|
108
|
+
priorityMap.set(qValue, typesForQValue);
|
|
109
|
+
}
|
|
110
|
+
typesForQValue.push(encoding);
|
|
111
|
+
}
|
|
112
|
+
// Sort keys, larger numbers to come first
|
|
113
|
+
const keysSorted = [...priorityMap.keys()]
|
|
114
|
+
.sort((qValueA, qValueB) => qValueB - qValueA);
|
|
115
|
+
return keysSorted
|
|
116
|
+
.map(qValue => priorityMap.get(qValue));
|
|
84
117
|
}
|
|
85
118
|
testExtendedCache(pathname) {
|
|
86
119
|
return this.staticItems
|
package/build/types/compute.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../src/types/compute.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAGpC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
1
|
+
{"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../src/types/compute.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAGpC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -3,6 +3,7 @@ import type { StoreEntry } from "../types/compute.js";
|
|
|
3
3
|
export type CompressedFileInfos<TData> = Partial<Record<ContentCompressionTypes, TData>>;
|
|
4
4
|
export type ContentFileInfo = {
|
|
5
5
|
hash: string;
|
|
6
|
+
size: number;
|
|
6
7
|
staticFilePath: string;
|
|
7
8
|
};
|
|
8
9
|
export type ContentFileInfoForObjectStore = ContentFileInfo & {
|
|
@@ -29,7 +30,7 @@ export type ContentAssetMetadataMap = {
|
|
|
29
30
|
export interface ContentAsset {
|
|
30
31
|
readonly assetKey: string;
|
|
31
32
|
getMetadata(): ContentAssetMetadataMapEntry;
|
|
32
|
-
getStoreEntry(
|
|
33
|
+
getStoreEntry(acceptEncodingsGroups?: ContentCompressionTypes[][]): Promise<StoreEntry>;
|
|
33
34
|
getBytes(): Uint8Array;
|
|
34
35
|
getText(): string;
|
|
35
36
|
readonly isInline: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-assets.d.ts","sourceRoot":"","sources":["../../src/types/content-assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,MAAM,mBAAmB,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,uBAAuB,EAAE,KAAK,CAAC,C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json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.2",
|
|
5
5
|
"description": "Static Publisher for Compute@Edge JavaScript",
|
|
6
6
|
"main": "./build/index.js",
|
|
7
7
|
"types": "./build/index.d.ts",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"homepage": "https://github.com/fastly/compute-js-static-publish#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fastly/js-compute": "^1.4.0",
|
|
35
|
-
"brotli-compress": "^1.3.3",
|
|
36
35
|
"command-line-args": "^5.2.1",
|
|
37
36
|
"glob-to-regexp": "^0.4.1"
|
|
38
37
|
},
|