@fastly/compute-js-static-publish 4.0.0-alpha.3 → 4.0.0

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
@@ -1,6 +1,3 @@
1
- PRO TIP - If you are viewing this README in GitHub, click the hamburger menu on the row right above this to see a Table
2
- of Contents!
3
-
4
1
  # Static Publisher for JavaScript on Compute@Edge
5
2
 
6
3
  Using a static site generator to build your website? Do you simply need to serve some static files? With `compute-js-static-publish`, now you can deploy and serve everything from Fastly's blazing-fast [Compute@Edge](https://developer.fastly.com/learning/compute/).
@@ -8,16 +5,17 @@ Using a static site generator to build your website? Do you simply need to serve
8
5
  ## New! Version 4
9
6
 
10
7
  Version 4 of this tool has some awesome new features:
11
- - Support for optionally serving files from Fastly's [Object Store](https://www.fastly.com/blog/introducing-the-compute-edge-object-store-global-persistent-storage-for-compute-functions) instead of bundling them into the Wasm module. See [Object Store](#object-store) below for more information.
12
- - Your scaffolded application no longer uses a bundler by default, making the use of Webpack optional
13
- - Brotli and Gzip compression
14
- - Support for returning `304 Not Modified` status based on `If-None-Match` and `If-Modified-Since` request headers
15
- - `PublisherServer` class to map incoming requests to asset paths
16
- - Ability to include files in the publishing that won't necessarily be served by `PublisherServer`. The content of these files are available to your application and may be useful for reading data written by third-party tools, etc.
17
- - Makes content and metadata available to your application, giving your applications access to their content by their pre-package path/file
18
- - Even load JavaScript files as code into your Compute@Edge JavaScript application
19
-
20
- If you wish to update to this version, you may need to re-scaffold your application, or follow the migrations steps outlined in [MIGRATING.md](./MIGRATING.md).
8
+ - Support for serving files from Fastly's [Object Store](#object-store) instead of bundling them into the Wasm module.
9
+ - Scaffolded applications no longer use a bundler by default (Webpack is optional).
10
+ - Brotli and Gzip compression.
11
+ - Support for returning `304 Not Modified` status based on `If-None-Match` and `If-Modified-Since` request headers.
12
+ - [`PublisherServer`](#publisherserver) class to map incoming requests to asset paths.
13
+ - Support for publishing files that won't necessarily be served by `PublisherServer`. File contents are made available to your application–useful, e.g., for reading data written by third-party tools, etc.
14
+ - Makes content and metadata available to your application, via pre-package path/file.
15
+ - Support for loading JavaScript files as code into your Compute@Edge application.
16
+ - Added presets for [Vue](https://vuejs.org/) and [Astro](https://astro.build/).
17
+
18
+ If you wish to update to this version, you may need to re-scaffold your application, or follow the steps outlined in [MIGRATING.md](./MIGRATING.md).
21
19
 
22
20
  ## Prerequisites
23
21
 
@@ -35,7 +33,7 @@ Assuming the root of your output directory is `./public`,
35
33
  npx @fastly/compute-js-static-publish@latest --root-dir=./public
36
34
  ```
37
35
 
38
- This will generate a Compute@Edge application at `./compute-js`. It will add a default `./src/index.js` file that instantiates the `PublisherServer` class and runs it to serve the static files from your project.
36
+ This will generate a Compute@Edge application at `./compute-js`. It will add a default `./src/index.js` file that instantiates the [`PublisherServer`](#publisherserver) class and runs it to serve the static files from your project.
39
37
 
40
38
  > This process creates a `./static-publish.rc.js` to hold your configuration. This, as well as the other files created in your new Compute@Edge program at `./compute-js`, can be committed to source control (except for the ones we specify in `.gitignore`!)
41
39
 
@@ -65,12 +63,12 @@ Once your application is scaffolded, `@fastly/compute-js-static-publish` integra
65
63
  running as part of your build process.
66
64
 
67
65
  The files you have configured to be included (`--root-dir`) are enumerated and prepared. Their contents are included into
68
- your Wasm binary (or made available via Object Store, if so configured). This process is called "publishing".
66
+ your Wasm binary (or made available via [Object Store](#object-store), if so configured). This process is called "publishing".
69
67
 
70
68
  Once the files are published, they are available to the other source files in the Compute@Edge application. For example,
71
- the stock application simply runs the [PublisherServer](#publisherserver) class to serve up these files.
69
+ the stock application runs the [PublisherServer](#publisherserver) class to serve these files.
72
70
 
73
- For more advanced uses, such as accessing the contents of these file in your own application, see the
71
+ For more advanced uses, such as accessing the contents of these file in your application, see the
74
72
  [Using the packaged objects in your own application](#using-published-assets-in-your-own-application) section below.
75
73
 
76
74
  Publishing is meant to run each time before building your Compute@Edge application into a Wasm file.
@@ -79,9 +77,9 @@ If the files in `--root-dir` have changed, then a new set of files will be publi
79
77
  ### Content Compression
80
78
 
81
79
  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).
80
+ and gzip algorithms, and then stored alongside the original files in your Wasm binary (or [Object Store](#object-store)).
83
81
 
84
- > Note: By default, pre-compressed content assets are not generated when the object store is not used.
82
+ > Note: By default, pre-compressed content assets are not generated when the Object Store is not used.
85
83
  This is done to prevent the inclusion multiple of copies of each asset from making the Wasm binary too large.
86
84
  If you want to pre-compress assets when not using Object Store, add a value for 'contentCompression' to your
87
85
  `static-publish.rc.js` file.
@@ -125,10 +123,10 @@ Used to populate the `server` key under `static-publish.rc.js`.
125
123
  |------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
126
124
  | `public-dir` | <root-dir> | The directory that contains your website's public files. |
127
125
  | `static-dir` | (None) | Any directories under `--public-dir` that contain the website's static assets that will be served with a very long TTL. You can specify as many such directories as you wish, by listing multiple items. |
128
- | `auto-ext` | `.html,.htm` | Configuration for automatic file extensions. |
129
- | `auto-index` | `index.html,index.htm` | Configuration for automatically serving an index file. |
130
- | `spa` | (None) | Configuration for serving a fallback file for SPA applications. |
131
- | `not-found-page` | `<public-dir>/404.html` | Configuration for serving a 404 not found file. |
126
+ | `auto-ext` | `.html,.htm` | Specify automatic file extensions. |
127
+ | `auto-index` | `index.html,index.htm` | Specify filenames for automatically serving an index file. |
128
+ | `spa` | (None) | Path to a fallback file for SPA applications. |
129
+ | `not-found-page` | `<public-dir>/404.html` | Path to a fallback file for 404 Not Found. |
132
130
 
133
131
  See [PublisherServer](#publisherserver) for more information about these features.
134
132
 
@@ -140,13 +138,13 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
140
138
 
141
139
  These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute@Edge application.
142
140
 
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`. |
141
+ | Option | Default | Description |
142
+ |---------------------|------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
143
+ | `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute@Edge application. |
144
+ | `description` | `description` from `package.json`, or `Compute@Edge static site` | The description of your Compute@Edge application. |
145
+ | `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute@Edge application. |
146
+ | `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute@Edge application. |
147
+ | `object-store-name` | (None) | The name of an existing [Fastly Object Store](https://developer.fastly.com/learning/concepts/data-stores/#object-stores) to hold the content assets. In addition to already existing, it must be linked to the service specified by `--service-id`. |
150
148
 
151
149
  ## Usage with frameworks and static site generators
152
150
 
@@ -158,7 +156,9 @@ These arguments are used to populate the `fastly.toml` and `package.json` files
158
156
  | `cra-eject` | `./build` | `./build/static` | For apps written using Create React App, but which have since been ejected via `npm run eject`. Does not check for `react-scripts`. |
159
157
  | `vite` | `./dist` | (None) | For apps written using [Vite](https://vitejs.dev). |
160
158
  | `sveltekit` | `./dist` | (None) | For apps written using [SvelteKit](https://kit.svelte.dev). |
159
+ | `vue` | `./dist` | (None) | For apps written using [Vue](https://vuejs.org), and that were created using [create-vue](https://github.com/vuejs/create-vue). |
161
160
  | `next` | `./out` | (None) | For apps written using [Next.js](https://nextjs.org), using `npm run export`. *1 |
161
+ | `astro` | `./dist` | (None) | For apps written using [Astro](https://astro.build) (static apps only). *2 |
162
162
  | `gatsby` | `./public` | (None) | For apps written using [Gatsby](https://www.gatsbyjs.com). |
163
163
  | `docusaurus` | `./build` | (None) | For apps written using [Docusaurus](https://docusaurus.io) |
164
164
 
@@ -167,14 +167,16 @@ You may still override any of these options individually.
167
167
  *1 - For Next.js, consider using `@fastly/next-compute-js`, a Next.js server implementation that allows you to run
168
168
  your Next.js application on Compute@Edge.
169
169
 
170
+ *2 - Astro support does not support SSR.
171
+
170
172
  ## PublisherServer
171
173
 
172
- Publisher Server is a simple yet powerful server that can be used out of the box to serve the files prepared by this tool.
174
+ `PublisherServer` is a simple yet powerful server that can be used out of the box to serve the files prepared by this tool.
173
175
 
174
176
  This server handles the following automatically:
175
177
 
176
178
  * Maps the path of your request to a path under `--public-dir` and serves the content of the asset
177
- * Sources the content from the content packaged in the Wasm, or from the Object Store if so configured (see [Object Store](#object-store), below.)
179
+ * Sources the content from the content packaged in the Wasm binary, or from the [Object Store](#object-store), if configured.
178
180
  * Applies long-lived cache headers to files served from `--static-dir` directories. Files under these directories will be cached by the browser for 1 year. (Use versioned or hashed filenames to avoid serving stale assets.)
179
181
  * Performs Brotli and gzip compression as requested by the `Accept-Encoding` headers.
180
182
  * Provides `Last-Modified` and `ETag` response headers, and uses them with `If-Modified-Since` and `If-None-Match` request headers to produce `304 Not Modified` responses.
@@ -208,20 +210,42 @@ For `compression`, the following values are allowed:
208
210
  * `'br'` - Brotli
209
211
  * `'gzip'` - Gzip
210
212
 
213
+ ## Associating your project with a Fastly Service
214
+
215
+ The project created by this tool is a Fastly Compute@Edge JavaScript application, complete with a `fastly.toml` file that
216
+ describes your project to the Fastly CLI.
217
+
218
+ To deploy your project to production, you deploy it to a [Fastly service](https://developer.fastly.com/reference/glossary#term-service)
219
+ in your account. Usually, you create your service automatically as part of your first deployment of the project.
220
+
221
+ In this case, `fastly.toml` has no value for `service_id` at the time you deploy, so `fastly compute publish` will prompt
222
+ you to create a Fastly service in your account for you (afterwards saving the new service's ID to your `fastly.toml` file).
223
+
224
+ Alternatively, you may deploy to a service that already exists. You can create this service using the
225
+ [Fastly CLI](https://developer.fastly.com/reference/cli/service/create/) or the [Fastly web app](https://manage.fastly.com/).
226
+ Note that since this is a Compute@Edge application, the service must be created as a Wasm service.
227
+
228
+ Before deploying your application, specify the service by setting the `service_id` value in the `fastly.toml` file to the
229
+ ID of the service. The `fastly compute publish` will deploy to the service identified by this value.
230
+
231
+ To specify the service at the time you are scaffolding the project (for example, if you are running this tool and deploying
232
+ as part of a CI process), specify the `--service-id` command line argument to populate `fastly.toml` with this value.
233
+
211
234
  ## Using the Object Store (BETA) <a name="object-store"></a>
212
235
 
213
- Starting v4, it's now possible to upload assets to and serve them from the Fastly Object Store.
236
+ Starting with v4, it's now possible to upload assets to and serve them from a [Fastly Object Store](https://developer.fastly.com/learning/concepts/data-stores/#object-stores).
214
237
 
215
- Fastly Object Store is currently part of a [beta release](https://docs.fastly.com/products/fastly-product-lifecycle#beta),
216
- and to use it you will need to have the feature enabled for your account.
238
+ You can enable the use of Object Store with `@fastly/compute-js-static-publish` as you scaffold your application, or
239
+ at any later time.
217
240
 
218
- To enable the use of Object Store with `@fastly/compute-js-static-publish`, you will need to perform the following steps:
241
+ At the time you enable the use of Object Store:
219
242
 
220
- * Create a service on Fastly to host your Compute@Edge application. One way to do this would be to simply run `fastly
221
- compute publish` your application.
243
+ * Your Fastly service must already exist. See [Associating your project with a Fastly Service](#associating-your-project-with-a-fastly-service) above.
222
244
 
223
- * Create an Object Store under your Fastly account. At the moment you need to use the Fastly CLI. Once the Object Store
224
- is created, it must be linked to your Fastly service using the Resources API.
245
+ * Your Object Store must already exist under the same Fastly account, and be linked to the service.
246
+ As of this writing, to create the Object Store you will need to use either the Fastly CLI [fastly object-store create](https://developer.fastly.com/reference/cli/object-store/create/)
247
+ or the Fastly [Object Store API](https://developer.fastly.com/reference/api/services/resources/object-store/#create-store).
248
+ Once the Object Store is created, you must be link it to your Fastly service using the [Resource API](https://developer.fastly.com/reference/api/services/resource/#create-resource).
225
249
 
226
250
  ```shell
227
251
  # Create an object store
@@ -231,13 +255,13 @@ $ curl -i -X POST "https://api.fastly.com/resources/stores/object" -H "Fastly-Ke
231
255
  $ curl -i -X POST "https://api.fastly.com/service/YOUR_FASTLY_SERVICE_ID/version/YOUR_FASTLY_SERVICE_VERSION/resource" -H "Fastly-Key: YOUR_FASTLY_TOKEN" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -d "name=example-store-service-a&resource_id=YOUR_OBJECT_STORE_ID"
232
256
  ```
233
257
 
234
- Object Store API: https://developer.fastly.com/reference/cli/object-store/create/
235
-
236
- Resources API: https://developer.fastly.com/reference/api/services/resource/
237
-
238
- * Once the object store is created and linked to your service, add the Object Store's name to your `static-publish.rc.js`
258
+ Once the Object Store is created and linked to your service, add its name to your `static-publish.rc.js`
239
259
  file under the `objectStore` key.
240
260
 
261
+ To specify the Object Store at the time you are scaffolding the project (for example, if you are running this tool and
262
+ deploying as part of a CI process), specify the `--service-id` and `--object-store-name` command line arguments to populate
263
+ the respective files with these values.
264
+
241
265
  After you have done the above steps, go ahead and build your application as normal. If you use `fastly compute build --verbose`
242
266
  (or run `npm run build` directly), you should see output in your logs saying that files are being sent to the Object Store.
243
267
 
@@ -349,7 +373,7 @@ And that's it! It should be possible to run this task to clean up once in a whil
349
373
 
350
374
  > Note that content types are tested at publishing time, not at runtime.
351
375
 
352
- * `server` - Configuration of `PublisherServer()`. See the [Configuring PublisherServer](#configuring-publisherserver) section
376
+ * `server` - [Configuration of `PublisherServer()`](#configuring-publisherserver).
353
377
  above.
354
378
 
355
379
  ### Running custom code alongside Publisher Server
@@ -358,22 +382,23 @@ The generated `./src/index.js` program instantiates the server and simply asks i
358
382
 
359
383
  You are free to add code to this file.
360
384
 
361
- For example, if the server is unable to formulate a response to the request, then it returns `null`. You may add your
362
- own code to handle these cases, such as to provide custom responses.
385
+ For example, if the `PublisherServer` is unable to formulate a response to the request, then it returns `null`. You may
386
+ add your own code to handle these cases, such as to provide custom responses.
363
387
 
364
388
  ```js
365
389
  import { getServer } from './statics.js';
366
- const server = getServer();
390
+ const staticContentServer = getServer();
367
391
 
368
392
  addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
369
393
  async function handleRequest(event) {
370
394
 
371
- const response = await server.serveRequest(event.request);
395
+ const response = await staticContentServer.serveRequest(event.request);
372
396
  if (response != null) {
373
397
  return response;
374
398
  }
375
399
 
376
400
  // Do custom things here!
401
+ // Handle API requests, serve non-static responses, etc.
377
402
 
378
403
  return new Response('Not found', { status: 404 });
379
404
  }
@@ -385,7 +410,7 @@ Publishing, as described earlier, is the process of preparing files for inclusio
385
410
  This process also makes metadata available about each of the files that are included, such as its content type, the last
386
411
  modified date, the file hash, and so on.
387
412
 
388
- The `PublisherServer` class that is used by the default scaffolded application is one simple application of this content
413
+ The [`PublisherServer` class](#publisherserver) used by the default scaffolded application is a simple application of this content
389
414
  and metadata. By importing `./statics.js` into your Compute@Edge application, you can just as easily access this
390
415
  information about the assets that were included during publishing.
391
416
 
@@ -516,8 +541,8 @@ See the definition of `ContentAssetMetadataMapEntry` in the [`types/content-asse
516
541
 
517
542
  ### Using Webpack
518
543
 
519
- As of v4, Webpack is no longer required, and by default is no longer part of the default scaffolded application.
520
- If you wish to use some features of Webpack, you can elect to include Webpack in your generated application by specifying
544
+ As of v4, Webpack is no longer required, and is no longer part of the default scaffolded application.
545
+ If you wish to use some features of Webpack, you may include Webpack in your generated application by specifying
521
546
  `--webpack` at the command line.
522
547
 
523
548
  ## Migrating
@@ -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,iBAoe5F"}
1
+ {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/build-static.ts"],"names":[],"mappings":"AA+DA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AA6IhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAoe5F"}
@@ -2,33 +2,60 @@
2
2
  // public folder to be served.
3
3
  // e.g., with create-react-app, this would be the ./build directory.
4
4
  // Outputs:
5
+ //
5
6
  // statics-metadata.js
6
- // deploymentId: string - deployment ID
7
- // contentAssetMetadataMap: Map<string, ContentAssetMetadata> - mapping of asset keys to their metadata
8
- // - key: filename relative to public dir (e.g., /foo/index.html)
9
- // - value:
10
- // - size (to be implemented soon): number - File size in bytes
11
- // - contentType: string - MIME type
12
- // - timestamp (to be implemented soon): last modified time as unix time
13
- // - etag (to be implemented soon): string - Etag
14
- // - text: boolean - whether this is a text file
7
+ //
8
+ // objectStoreName: string - Name of object store, or null if not used.
9
+ // contentAssetMetadataMap: Map<string, ContentAssetMetadataMapEntry> - mapping of asset keys to their metadata
10
+ // - key: string - assetKey, the filename relative to root dir (e.g., /public/foo/index.html)
11
+ // - value: ContentAssetMetadataMapEntry - metadata for asset
12
+ //
13
+ // ContentAssetMetadataMapEntry structure
14
+ // - assetKey: string - filename relative to root dir
15
+ // - contentType: string - MIME type
16
+ // - text: boolean - whether this is a text file
17
+ // - lastModifiedTime: number - last modified time as unix time (seconds)
18
+ // - fileInfo: FileInfo - information about the file
19
+ // - compressedFileInfos: Map<string, FileInfo> - information about any compressed versions
20
+ // - key: string - compression algorithm name (e.g., "gzip", "br", etc.)
21
+ // - value: FileInfo - information about the compressed version of the file
22
+ // - isInline: boolean - whether this file is "inline". If false, object is in the object store.
23
+ // FileInfo structure
24
+ // - hash: string - SHA-256 hash of file
25
+ // - size: number - file size in bytes
26
+ // - staticFilePath: string - path to file in local filesystem, relative to root dir
27
+ // - objectStoreKey: string - object store key, present only for items in object store
28
+ //
15
29
  // statics.js
16
- // imports statics-metadata.js and adds utilities to load the files
17
- // contentAssetMap: Map<string, ContentAsset>
18
- // - key: filename relative to public dir (e.g., /foo/index.html)
19
- // - value:
20
- // - getMetadata() - gets the metadata entry
21
- // - getBody() - gets a Body object that represents the asset
22
- // moduleAssetMap: Map<string, ModuleAsset>
23
- // - key: filename relative to public dir (e.g., /foo/index.html)
24
- // - value:
25
- // - getMetadata() - gets the metadata entry
26
- // - async getModule() - Returns a promise that imports the module and returns a reference.
27
- // This simply returns the statically imported module if it is statically imported.
28
- // - getStaticModule() - Advanced. Returns the statically imported module, or null.
29
- // This also reexports values like the "spa" value in the static-publish.rc.js
30
- // file so that the C@E handler knows what file to serve up if
31
- // the resource doesn't map to a file.
30
+ // imports statics-metadata.js and adds utilities for working with the content assets, as well as
31
+ // for loading module assets. Also gives access to StaticPublisher and its config.
32
+ // See README.md for details
33
+ //
34
+ // moduleAssetMap: Map<string, ModuleAssetMapEntry>
35
+ // - key: string - assetKey, the filename relative to root dir (e.g., /module/hello.js)
36
+ // - value: ModuleAssetMapEntry - information about the module
37
+ //
38
+ // ModuleAssetMapEntry structure
39
+ // - isStaticImport: boolean - if true, then uses a static import statement to load the module
40
+ // - if false, then module is loaded when getModule is called
41
+ // - module: any - the statically loaded module if isStaticImport is true, or null
42
+ // - loadModule: function - a function that dynamically loads the module and returns it, if isStaticImport is false, or null
43
+ //
44
+ // contentAssets: ContentAssets instance
45
+ // moduleAssets: ModuleAssets instance
46
+ //
47
+ // getServer(): function - instantiates PublisherServer singleton and returns it
48
+ // serverConfig: PublisherServerConfigNormalized - publisher server config settings
49
+ //
50
+ // PublisherServerConfigNormalized structure
51
+ // - publicDirPrefix: string
52
+ // - staticItems: string[]
53
+ // - compression: string[]
54
+ // - spaFile: string or null
55
+ // - notFoundPageFile: string or null
56
+ // - autoExt: string[]
57
+ // - autoIndex: string[]
58
+ //
32
59
  import * as fs from "fs";
33
60
  import * as path from "path";
34
61
  import * as url from "url";
@@ -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;AAoPvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAma5D"}
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,QAka5D"}
@@ -467,7 +467,6 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
467
467
  fs.writeFileSync(fastlyTomlPath, fastlyTomlContent, "utf-8");
468
468
  // static-publish.rc.js
469
469
  const rootDirRel = path.relative(computeJsDir, rootDir);
470
- const publicDirRel = path.relative(computeJsDir, publicDir);
471
470
  // publicDirPrefix -- if public dir is deeper than the root dir, then
472
471
  // public dir is used as a prefix to drill into asset names.
473
472
  // e.g.,
@@ -8,7 +8,9 @@ const optionDefinitions = [
8
8
  // - cra (or create-react-app)
9
9
  // - vite
10
10
  // - sveltekit
11
+ // - vue
11
12
  // - next
13
+ // - astro
12
14
  // - gatsby
13
15
  // - docusaurus
14
16
  { name: 'preset', type: String, },
@@ -0,0 +1,7 @@
1
+ import { AppOptions, IPresetBase } from '../preset-base.js';
2
+ export declare class AstroPreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: Partial<AppOptions>;
5
+ check(packageJson: any): boolean;
6
+ }
7
+ //# sourceMappingURL=astro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/astro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,WAAY,YAAW,WAAW;IAC7C,IAAI,SAAW;IACf,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK,CAAC,WAAW,EAAE,GAAG;CAavB"}
@@ -0,0 +1,23 @@
1
+ export class AstroPreset {
2
+ constructor() {
3
+ this.name = 'Astro';
4
+ this.defaultOptions = {
5
+ rootDir: './dist',
6
+ name: 'my-astro-app',
7
+ description: 'Compute@Edge static site from Astro',
8
+ };
9
+ }
10
+ check(packageJson) {
11
+ if (packageJson == null) {
12
+ console.error("❌ Can't read/parse package.json");
13
+ console.error("Run this from a Astro project directory.");
14
+ return false;
15
+ }
16
+ if (packageJson?.dependencies?.['astro'] == null) {
17
+ console.error("❌ Can't find astro in dependencies");
18
+ console.error("Run this from a Astro project directory.");
19
+ return false;
20
+ }
21
+ return true;
22
+ }
23
+ }
@@ -0,0 +1,7 @@
1
+ import { AppOptions, IPresetBase } from '../preset-base.js';
2
+ export declare class VuePreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: Partial<AppOptions>;
5
+ check(packageJson: any): boolean;
6
+ }
7
+ //# sourceMappingURL=vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../../../../src/cli/presets/implementations/vue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,SAAU,YAAW,WAAW;IAC3C,IAAI,SAAS;IACb,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAIjC;IACF,KAAK,CAAC,WAAW,EAAE,GAAG;CAcvB"}
@@ -0,0 +1,24 @@
1
+ export class VuePreset {
2
+ constructor() {
3
+ this.name = 'Vue';
4
+ this.defaultOptions = {
5
+ rootDir: './dist',
6
+ name: 'my-vue-app',
7
+ description: 'Compute@Edge static site from Vue (create-vue)',
8
+ };
9
+ }
10
+ check(packageJson) {
11
+ if (packageJson == null) {
12
+ console.error("❌ Can't read/parse package.json");
13
+ console.error("Run this from a Vue project directory created by create-vue.");
14
+ return false;
15
+ }
16
+ if (packageJson?.devDependencies?.['vite'] == null) {
17
+ console.error("❌ Can't find vite in dependencies");
18
+ console.error("Run this from a Vue project directory created by create-vue.");
19
+ console.log("If this is a project created with the Vue CLI, migrate it to use Vite first. Refer to the create-vue documentation at https://www.npmjs.com/package/create-vue (not authored or maintained by Fastly) for details on this process.");
20
+ return false;
21
+ }
22
+ return true;
23
+ }
24
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAS,WAAW,CASxD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAU/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAS,WAAW,CAWxD,CAAC"}
@@ -1,7 +1,9 @@
1
1
  import { CreateReactAppPreset, CreateReactAppEjectedPreset } from './implementations/create-react-app.js';
2
2
  import { VitePreset } from './implementations/vite.js';
3
3
  import { SvelteKitPreset } from './implementations/sveltekit.js';
4
+ import { VuePreset } from './implementations/vue.js';
4
5
  import { NextJsPreset } from './implementations/next.js';
6
+ import { AstroPreset } from "./implementations/astro.js";
5
7
  import { GatsbyPreset } from './implementations/gatsby.js';
6
8
  import { DocusaurusPreset } from './implementations/docusaurus.js';
7
9
  export const presets = {
@@ -10,7 +12,9 @@ export const presets = {
10
12
  'cra-eject': CreateReactAppEjectedPreset,
11
13
  'vite': VitePreset,
12
14
  'sveltekit': SvelteKitPreset,
15
+ 'vue': VuePreset,
13
16
  'next': NextJsPreset,
17
+ 'astro': AstroPreset,
14
18
  'gatsby': GatsbyPreset,
15
19
  'docusaurus': DocusaurusPreset,
16
20
  };
@@ -1,7 +1,7 @@
1
1
  export declare abstract class AssetManager<TAsset> {
2
2
  protected readonly assets: Record<string, TAsset>;
3
3
  protected constructor();
4
- setAsset(assetKey: string, asset: TAsset): void;
4
+ protected initAsset(assetKey: string, asset: TAsset): void;
5
5
  getAsset(assetKey: string): TAsset | null;
6
6
  }
7
7
  //# sourceMappingURL=asset-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.d.ts","sourceRoot":"","sources":["../../../src/server/assets/asset-manager.ts"],"names":[],"mappings":"AAAA,8BAAsB,YAAY,CAAC,MAAM;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElD,SAAS;IAIT,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAIxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAI1C"}
1
+ {"version":3,"file":"asset-manager.d.ts","sourceRoot":"","sources":["../../../src/server/assets/asset-manager.ts"],"names":[],"mappings":"AAAA,8BAAsB,YAAY,CAAC,MAAM;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElD,SAAS;IAIT,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAInD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAI1C"}
@@ -2,7 +2,7 @@ export class AssetManager {
2
2
  constructor() {
3
3
  this.assets = {};
4
4
  }
5
- setAsset(assetKey, asset) {
5
+ initAsset(assetKey, asset) {
6
6
  this.assets[assetKey] = asset;
7
7
  }
8
8
  getAsset(assetKey) {
@@ -136,7 +136,7 @@ export class ContentAssets extends AssetManager {
136
136
  }
137
137
  asset = new ContentObjectStoreAsset(metadata, objectStoreName);
138
138
  }
139
- this.setAsset(assetKey, asset);
139
+ this.initAsset(assetKey, asset);
140
140
  }
141
141
  }
142
142
  }
@@ -39,7 +39,7 @@ export class ModuleAssets extends AssetManager {
39
39
  else {
40
40
  asset = new ModuleAssetDynamic(assetKey, moduleEntry.loadModule);
41
41
  }
42
- this.setAsset(assetKey, asset);
42
+ this.initAsset(assetKey, asset);
43
43
  }
44
44
  }
45
45
  }
@@ -1,6 +1,6 @@
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
- export class InlineStoreEntry {
3
+ class InlineStoreEntry {
4
4
  constructor(array, contentEncoding, hash, size) {
5
5
  this._body = new ReadableStreamForBytes(array);
6
6
  this._consumed = false;
@@ -63,6 +63,7 @@ export class InlineStoreEntry {
63
63
  }
64
64
  }
65
65
  InlineStoreEntry.decoder = new TextDecoder();
66
+ export { InlineStoreEntry };
66
67
  class ReadableStreamForBytes extends ReadableStream {
67
68
  constructor(array) {
68
69
  super({
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.3",
4
+ "version": "4.0.0",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "@types/glob-to-regexp": "^0.4.1",
41
41
  "@types/node": "^18.0.0",
42
42
  "rimraf": "^4.3.0",
43
- "typescript": "^4.9.5"
43
+ "typescript": "^5.0.2"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18"
@@ -1,17 +1,18 @@
1
1
  /// <reference types="@fastly/js-compute" />
2
-
3
2
  import { getServer } from './statics.js';
4
- const server = getServer();
3
+ const staticContentServer = getServer();
5
4
 
6
5
  // eslint-disable-next-line no-restricted-globals
7
6
  addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
8
7
  async function handleRequest(event) {
9
8
 
10
- const response = await server.serveRequest(event.request);
11
-
9
+ const response = await staticContentServer.serveRequest(event.request);
12
10
  if (response != null) {
13
11
  return response;
14
12
  }
15
13
 
14
+ // Do custom things here!
15
+ // Handle API requests, serve non-static responses, etc.
16
+
16
17
  return new Response('Not found', { status: 404 });
17
18
  }