@fastly/compute-js-static-publish 4.0.0-alpha.1 → 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 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
- Most arguments are optional, and if provided, override the defaults described below.
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
- --root-dir=./build/public \
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 | Default | Description |
132
- |---------------|------------------------------------------------------------------|------------------------------------------------------------------------------|
133
- | `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
134
- | `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
135
- | `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
136
- | `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
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 in the order listed in the header for the values listed here. The compression algorithm represented by the first match is applied. |
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
@@ -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;AA6IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBA+d5F"}
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"}
@@ -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.");
@@ -233,6 +233,10 @@ export async function buildStaticLoader(commandLineValues) {
233
233
  };
234
234
  });
235
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
+ }
236
240
  // Create "static content" dir that will be used to hold a copy of static files.
237
241
  // NOTE: this is needed because includeBytes doesn't seem to be able to traverse up to parent dir of the Compute project.
238
242
  const staticContentDir = './src/static-content';
@@ -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;AA0OvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAia5D"}
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 :', rootRelative(rootDir));
368
- console.log('Public Dir :', rootRelative(publicDir));
369
- console.log('Static Dir :', staticDirs.length > 0 ? staticDirs.map(rootRelative) : '(None)');
370
- console.log('SPA :', rootRelative(spaFilename) ?? '(None)');
371
- console.log('404 Page :', rootRelative(notFoundPageFilename) ?? '(None)');
372
- console.log('Auto-Index :', autoIndex.length > 0 ? autoIndex.map(rootRelative) : '(None)');
373
- console.log('Auto-Ext :', autoExt.length > 0 ? autoExt.map(rootRelative) : '(None)');
374
- console.log('name :', name);
375
- console.log('author :', author);
376
- console.log('description :', description);
377
- console.log('Service ID :', fastlyServiceId ?? '(None)');
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,
@@ -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<StaticPublisherConfigNormalized | null>;
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;AAqVvC,wBAAsB,cAAc,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,+BAA+B,GAAG,IAAI,CAAC,CAgB3G"}
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"}
@@ -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
- contentCompression = ['br', 'gzip'];
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 config = undefined;
350
+ let raw = undefined;
346
351
  const staticPublishRcPath = path.resolve('./static-publish.rc.js');
347
352
  try {
348
- config = (await import(staticPublishRcPath)).default;
353
+ raw = (await import(staticPublishRcPath)).default;
349
354
  }
350
355
  catch {
351
356
  errors.push('Unable to load ' + staticPublishRcPath);
352
357
  }
353
- if (config != null) {
354
- config = normalizeConfig(config, errors);
358
+ let normalized = undefined;
359
+ if (raw != null) {
360
+ normalized = normalizeConfig(raw, errors);
355
361
  }
356
- return config ?? null;
362
+ return { normalized: normalized ?? null, raw };
357
363
  }
@@ -10,6 +10,7 @@ export type AppOptions = {
10
10
  author: string | undefined;
11
11
  description: string | undefined;
12
12
  serviceId: string | undefined;
13
+ objectStoreName: string | undefined;
13
14
  };
14
15
  export interface IPresetBase {
15
16
  name: string;
@@ -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;CAC/B,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"}
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/package.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.1",
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",