@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 +78 -53
- package/build/cli/commands/build-static.d.ts.map +1 -1
- package/build/cli/commands/build-static.js +52 -25
- package/build/cli/commands/init-app.d.ts.map +1 -1
- package/build/cli/commands/init-app.js +0 -1
- package/build/cli/index.js +2 -0
- package/build/cli/presets/implementations/astro.d.ts +7 -0
- package/build/cli/presets/implementations/astro.d.ts.map +1 -0
- package/build/cli/presets/implementations/astro.js +23 -0
- package/build/cli/presets/implementations/vue.d.ts +7 -0
- package/build/cli/presets/implementations/vue.d.ts.map +1 -0
- package/build/cli/presets/implementations/vue.js +24 -0
- package/build/cli/presets/index.d.ts.map +1 -1
- package/build/cli/presets/index.js +4 -0
- package/build/server/assets/asset-manager.d.ts +1 -1
- package/build/server/assets/asset-manager.d.ts.map +1 -1
- package/build/server/assets/asset-manager.js +1 -1
- package/build/server/assets/content-assets.js +1 -1
- package/build/server/assets/module-assets.js +1 -1
- package/build/server/object-store/inline-store-entry.js +2 -1
- package/package.json +2 -2
- package/resources/index.js +5 -4
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
|
|
12
|
-
-
|
|
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
|
-
-
|
|
17
|
-
- Makes content and metadata available to your application,
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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` |
|
|
129
|
-
| `auto-index` | `index.html,index.htm` |
|
|
130
|
-
| `spa` | (None) |
|
|
131
|
-
| `not-found-page` | `<public-dir>/404.html` |
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
216
|
-
|
|
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
|
-
|
|
241
|
+
At the time you enable the use of Object Store:
|
|
219
242
|
|
|
220
|
-
*
|
|
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
|
-
*
|
|
224
|
-
|
|
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
|
|
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()
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
520
|
-
If you wish to use some features of Webpack, you
|
|
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":"
|
|
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
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// -
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
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
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
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,
|
|
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.,
|
package/build/cli/index.js
CHANGED
|
@@ -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 @@
|
|
|
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;
|
|
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
|
-
|
|
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,
|
|
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"}
|
|
@@ -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
|
-
|
|
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
|
|
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": "^
|
|
43
|
+
"typescript": "^5.0.2"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18"
|
package/resources/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
/// <reference types="@fastly/js-compute" />
|
|
2
|
-
|
|
3
2
|
import { getServer } from './statics.js';
|
|
4
|
-
const
|
|
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
|
|
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
|
}
|