@fastly/compute-js-static-publish 5.1.2 → 5.2.1
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 +31 -31
- package/build/cli/commands/init-app.js +9 -9
- package/build/cli/index.js +1 -1
- package/build/cli/presets/implementations/astro.js +1 -1
- package/build/cli/presets/implementations/create-react-app.js +1 -1
- package/build/cli/presets/implementations/docusaurus.js +1 -1
- package/build/cli/presets/implementations/gatsby.js +1 -1
- package/build/cli/presets/implementations/next.js +1 -1
- package/build/cli/presets/implementations/sveltekit.js +1 -1
- package/build/cli/presets/implementations/vite.js +1 -1
- package/build/cli/presets/implementations/vue.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Static Publisher for JavaScript on Compute
|
|
1
|
+
# Static Publisher for JavaScript on Fastly Compute
|
|
2
2
|
|
|
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
|
|
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](https://developer.fastly.com/learning/compute/).
|
|
4
4
|
|
|
5
5
|
## Prerequisites
|
|
6
6
|
|
|
@@ -18,11 +18,11 @@ Assuming the root of your output directory is `./public`,
|
|
|
18
18
|
npx @fastly/compute-js-static-publish@latest --root-dir=./public
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
This will generate a Compute
|
|
21
|
+
This will generate a Compute 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.
|
|
22
22
|
|
|
23
|
-
> This process creates a `./static-publish.rc.js` to hold your configuration. This, as well as the other files created in your new Compute
|
|
23
|
+
> This process creates a `./static-publish.rc.js` to hold your configuration. This, as well as the other files created in your new Compute program at `./compute-js`, can be committed to source control (except for the ones we specify in `.gitignore`!)
|
|
24
24
|
|
|
25
|
-
Now, each time you build this Compute
|
|
25
|
+
Now, each time you build this Compute project, `compute-js-static-publish` will re-scan your `./public` directory and regenerate `/src/statics-metadata.js` and `/src/statics.js`. These files hold references to your project's public files.
|
|
26
26
|
|
|
27
27
|
### 2. Test your application using [Fastly's local development server](https://developer.fastly.com/learning/compute/testing/#running-a-local-testing-server)
|
|
28
28
|
|
|
@@ -36,7 +36,7 @@ This will serve your application using the default `PublisherServer()`.
|
|
|
36
36
|
|
|
37
37
|
However, you can modify `/src/index.js` to add your own processing as you need. This file will not be overwritten after it is created.
|
|
38
38
|
|
|
39
|
-
### 3. When you're ready to go live, [deploy your Compute
|
|
39
|
+
### 3. When you're ready to go live, [deploy your Compute service](https://developer.fastly.com/reference/cli/compute/publish/)
|
|
40
40
|
|
|
41
41
|
```shell
|
|
42
42
|
fastly compute publish
|
|
@@ -51,7 +51,7 @@ fastly compute publish
|
|
|
51
51
|
- Support for `If-None-Match` and `If-Modified-Since` request headers.
|
|
52
52
|
- Optionally use Webpack as a module bundler.
|
|
53
53
|
- Selectively serve files from Fastly's [KV Store](#kv-store), or embedded into your Wasm module.
|
|
54
|
-
- Supports loading JavaScript files as code into your Compute
|
|
54
|
+
- Supports loading JavaScript files as code into your Compute application.
|
|
55
55
|
- Presets for several static site generators.
|
|
56
56
|
|
|
57
57
|
Some of these features are new! 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).
|
|
@@ -64,13 +64,13 @@ running as part of your build process.
|
|
|
64
64
|
The files you have configured to be included (`--root-dir`) are enumerated and prepared. Their contents are included into
|
|
65
65
|
your Wasm binary (or made available via [KV Store](#kv-store), if so configured). This process is called "publishing".
|
|
66
66
|
|
|
67
|
-
Once the files are published, they are available to the other source files in the Compute
|
|
67
|
+
Once the files are published, they are available to the other source files in the Compute application. For example,
|
|
68
68
|
the stock application runs the [PublisherServer](#publisherserver) class to serve these files.
|
|
69
69
|
|
|
70
70
|
For more advanced uses, such as accessing the contents of these file in your application, see the
|
|
71
71
|
[Using the packaged objects in your own application](#using-published-assets-in-your-own-application) section below.
|
|
72
72
|
|
|
73
|
-
Publishing is meant to run each time before building your Compute
|
|
73
|
+
Publishing is meant to run each time before building your Compute application into a Wasm file.
|
|
74
74
|
If the files in `--root-dir` have changed, then a new set of files will be published.
|
|
75
75
|
|
|
76
76
|
### Content Compression
|
|
@@ -98,21 +98,21 @@ npx @fastly/compute-js-static-publish \
|
|
|
98
98
|
|
|
99
99
|
If you provide options, they override the defaults described below.
|
|
100
100
|
|
|
101
|
-
Any configuration options will be written to a `static-publish.rc.js` file, and used each time you build your Compute
|
|
101
|
+
Any configuration options will be written to a `static-publish.rc.js` file, and used each time you build your Compute
|
|
102
102
|
application.
|
|
103
103
|
|
|
104
|
-
On subsequent builds of your Compute
|
|
104
|
+
On subsequent builds of your Compute application, `compute-js-static-publish` will run with a special flag, `build-static`,
|
|
105
105
|
reading from stored configuration, then scanning the `--public-dir` directory to recreate `./src/statics.js`.
|
|
106
106
|
|
|
107
107
|
Any relative file and directory paths passed at the command line are handled as relative to the current directory.
|
|
108
108
|
|
|
109
109
|
### Publishing options:
|
|
110
110
|
|
|
111
|
-
| Option | Default | Description
|
|
112
|
-
|
|
113
|
-
| `preset` | (None) | Apply default options from a specified preset. See ["Frameworks and Static Site Generators"](#usage-with-frameworks-and-static-site-generators).
|
|
114
|
-
| `output` | `./compute-js` | The directory in which to create the Compute
|
|
115
|
-
| `root-dir` | (None) | **Required**. The root of the directory that contains the files to include in the publishing. All files you wish to include must reside under this root.
|
|
111
|
+
| Option | Default | Description |
|
|
112
|
+
|------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
113
|
+
| `preset` | (None) | Apply default options from a specified preset. See ["Frameworks and Static Site Generators"](#usage-with-frameworks-and-static-site-generators). |
|
|
114
|
+
| `output` | `./compute-js` | The directory in which to create the Compute application. |
|
|
115
|
+
| `root-dir` | (None) | **Required**. The root of the directory that contains the files to include in the publishing. All files you wish to include must reside under this root. |
|
|
116
116
|
|
|
117
117
|
### Server options:
|
|
118
118
|
|
|
@@ -135,15 +135,15 @@ Note that the files referenced by `--spa` and `--not-found-page` do not necessar
|
|
|
135
135
|
|
|
136
136
|
### Fastly service options
|
|
137
137
|
|
|
138
|
-
These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute
|
|
138
|
+
These arguments are used to populate the `fastly.toml` and `package.json` files of your Compute application.
|
|
139
139
|
|
|
140
|
-
| Option | Default
|
|
141
|
-
|
|
142
|
-
| `name` | `name` from `package.json`, or `compute-js-static-site`
|
|
143
|
-
| `description` | `description` from `package.json`, or `Compute
|
|
144
|
-
| `author` | `author` from `package.json`, or `you@example.com`
|
|
145
|
-
| `service-id` | (None)
|
|
146
|
-
| `kv-store-name` | (None)
|
|
140
|
+
| Option | Default | Description |
|
|
141
|
+
|-----------------|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
142
|
+
| `name` | `name` from `package.json`, or `compute-js-static-site` | The name of your Compute application. |
|
|
143
|
+
| `description` | `description` from `package.json`, or `Compute static site` | The description of your Compute application. |
|
|
144
|
+
| `author` | `author` from `package.json`, or `you@example.com` | The author of your Compute application. |
|
|
145
|
+
| `service-id` | (None) | The ID of an existing Fastly WASM service for your Compute application. |
|
|
146
|
+
| `kv-store-name` | (None) | The name of an existing [Fastly KV Store](https://developer.fastly.com/learning/concepts/data-stores/#kv-stores) to hold the content assets. In addition to already existing, it must be linked to the service specified by `--service-id`. |
|
|
147
147
|
|
|
148
148
|
## Usage with frameworks and static site generators
|
|
149
149
|
|
|
@@ -164,7 +164,7 @@ These arguments are used to populate the `fastly.toml` and `package.json` files
|
|
|
164
164
|
You may still override any of these options individually.
|
|
165
165
|
|
|
166
166
|
*1 - For Next.js, consider using `@fastly/next-compute-js`, a Next.js server implementation that allows you to run
|
|
167
|
-
your Next.js application on Compute
|
|
167
|
+
your Next.js application on Compute.
|
|
168
168
|
|
|
169
169
|
*2 - Astro support does not support SSR.
|
|
170
170
|
|
|
@@ -211,7 +211,7 @@ For `compression`, the following values are allowed:
|
|
|
211
211
|
|
|
212
212
|
## Associating your project with a Fastly Service
|
|
213
213
|
|
|
214
|
-
The project created by this tool is a Fastly Compute
|
|
214
|
+
The project created by this tool is a Fastly Compute JavaScript application, complete with a `fastly.toml` file that
|
|
215
215
|
describes your project to the Fastly CLI.
|
|
216
216
|
|
|
217
217
|
To deploy your project to production, you deploy it to a [Fastly service](https://developer.fastly.com/reference/glossary#term-service)
|
|
@@ -222,7 +222,7 @@ you to create a Fastly service in your account for you (afterwards saving the ne
|
|
|
222
222
|
|
|
223
223
|
Alternatively, you may deploy to a service that already exists. You can create this service using the
|
|
224
224
|
[Fastly CLI](https://developer.fastly.com/reference/cli/service/create/) or the [Fastly web app](https://manage.fastly.com/).
|
|
225
|
-
Note that since this is a Compute
|
|
225
|
+
Note that since this is a Compute application, the service must be created as a Wasm service.
|
|
226
226
|
|
|
227
227
|
Before deploying your application, specify the service by setting the `service_id` value in the `fastly.toml` file to the
|
|
228
228
|
ID of the service. The `fastly compute publish` will deploy to the service identified by this value.
|
|
@@ -410,11 +410,11 @@ This process also makes metadata available about each of the files that are incl
|
|
|
410
410
|
modified date, the file hash, and so on.
|
|
411
411
|
|
|
412
412
|
The [`PublisherServer` class](#publisherserver) used by the default scaffolded application is a simple application of this content
|
|
413
|
-
and metadata. By importing `./statics.js` into your Compute
|
|
413
|
+
and metadata. By importing `./statics.js` into your Compute application, you can just as easily access this
|
|
414
414
|
information about the assets that were included during publishing.
|
|
415
415
|
|
|
416
416
|
> IMPORTANT: Use a static `import` statement, rather than using `await import()` to load `./statics.js`, in order to
|
|
417
|
-
ensure that its top-level code runs during the initialization phase of your Compute
|
|
417
|
+
ensure that its top-level code runs during the initialization phase of your Compute application.
|
|
418
418
|
|
|
419
419
|
#### Assets
|
|
420
420
|
|
|
@@ -528,9 +528,9 @@ helloModule.hello(); // Will print "Hello, World!"
|
|
|
528
528
|
#### Metadata
|
|
529
529
|
|
|
530
530
|
In some use cases, you may have a use case where you need to know about the files that were included during publishing,
|
|
531
|
-
but not in the context of Compute
|
|
531
|
+
but not in the context of Compute. (e.g., a tool that runs in Node.js that performs some maintenance task on assets).
|
|
532
532
|
|
|
533
|
-
You cannot import `./statics.js` from a Node.js application, as it holds dependencies on Compute
|
|
533
|
+
You cannot import `./statics.js` from a Node.js application, as it holds dependencies on Compute.
|
|
534
534
|
|
|
535
535
|
Instead, you can import `./statics-metadata.js`, a companion file that is generated in the same directory. This file
|
|
536
536
|
exposes plain JavaScript objects that contain the metadata about your content assets that were included in the final
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// This program creates a Compute
|
|
1
|
+
// This program creates a Fastly Compute JavaScript application
|
|
2
2
|
// in a subfolder named compute-js.
|
|
3
3
|
// This project can be served using fastly compute serve
|
|
4
|
-
// or deployed to a Compute
|
|
4
|
+
// or deployed to a Compute service using fastly compute publish.
|
|
5
5
|
import * as child_process from "child_process";
|
|
6
6
|
import * as path from "path";
|
|
7
7
|
import * as fs from "fs";
|
|
@@ -17,7 +17,7 @@ const defaultOptions = {
|
|
|
17
17
|
autoExt: ['.html', '.htm'],
|
|
18
18
|
author: 'you@example.com',
|
|
19
19
|
name: 'compute-js-static-site',
|
|
20
|
-
description: 'Compute
|
|
20
|
+
description: 'Fastly Compute static site',
|
|
21
21
|
serviceId: undefined,
|
|
22
22
|
kvStoreName: undefined,
|
|
23
23
|
};
|
|
@@ -391,7 +391,7 @@ export function initApp(commandLineValues) {
|
|
|
391
391
|
console.log('Creating project with Webpack.');
|
|
392
392
|
console.log('');
|
|
393
393
|
}
|
|
394
|
-
console.log("Initializing Compute
|
|
394
|
+
console.log("Initializing Compute Application in " + computeJsDir + "...");
|
|
395
395
|
fs.mkdirSync(computeJsDir);
|
|
396
396
|
fs.mkdirSync(path.resolve(computeJsDir, './src'));
|
|
397
397
|
// .gitignore
|
|
@@ -418,7 +418,7 @@ export function initApp(commandLineValues) {
|
|
|
418
418
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
419
419
|
},
|
|
420
420
|
dependencies: {
|
|
421
|
-
'@fastly/js-compute': '^
|
|
421
|
+
'@fastly/js-compute': '^3.0.0',
|
|
422
422
|
},
|
|
423
423
|
engines: {
|
|
424
424
|
node: '>=18.0.0',
|
|
@@ -450,7 +450,7 @@ export function initApp(commandLineValues) {
|
|
|
450
450
|
// fastly.toml
|
|
451
451
|
// language=toml
|
|
452
452
|
const fastlyTomlContent = `\
|
|
453
|
-
# This file describes a Fastly Compute
|
|
453
|
+
# This file describes a Fastly Compute package. To learn more visit:
|
|
454
454
|
# https://developer.fastly.com/reference/fastly-toml/
|
|
455
455
|
|
|
456
456
|
authors = [ "${author}" ]
|
|
@@ -550,18 +550,18 @@ ${useWebpack ? 'module.exports =' : 'export default'} config;
|
|
|
550
550
|
const indexJsSrcPath = path.resolve(__dirname, '../../../resources/index.js');
|
|
551
551
|
const indexJsPath = path.resolve(computeJsDir, './src/index.js');
|
|
552
552
|
fs.copyFileSync(indexJsSrcPath, indexJsPath);
|
|
553
|
-
console.log("🚀 Compute
|
|
553
|
+
console.log("🚀 Compute application created!");
|
|
554
554
|
console.log('Installing dependencies...');
|
|
555
555
|
console.log(`npm --prefix ${COMPUTE_JS_DIR} install`);
|
|
556
556
|
child_process.spawnSync('npm', ['--prefix', COMPUTE_JS_DIR, 'install'], { stdio: 'inherit' });
|
|
557
557
|
console.log('');
|
|
558
558
|
console.log('');
|
|
559
|
-
console.log('To run your Compute
|
|
559
|
+
console.log('To run your Compute application locally:');
|
|
560
560
|
console.log('');
|
|
561
561
|
console.log(' cd ' + COMPUTE_JS_DIR);
|
|
562
562
|
console.log(' fastly compute serve');
|
|
563
563
|
console.log('');
|
|
564
|
-
console.log('To build and deploy to your Compute
|
|
564
|
+
console.log('To build and deploy to your Compute service:');
|
|
565
565
|
console.log('');
|
|
566
566
|
console.log(' cd ' + COMPUTE_JS_DIR);
|
|
567
567
|
console.log(' fastly compute publish');
|
package/build/cli/index.js
CHANGED
|
@@ -70,7 +70,7 @@ const optionDefinitions = [
|
|
|
70
70
|
{ name: 'clean-kv-store', type: Boolean, },
|
|
71
71
|
];
|
|
72
72
|
const commandLineValues = commandLineArgs(optionDefinitions);
|
|
73
|
-
console.log("Fastly Compute
|
|
73
|
+
console.log("Fastly Compute JavaScript Static Publisher");
|
|
74
74
|
let mode = 'init-app';
|
|
75
75
|
if (commandLineValues['build-static']) {
|
|
76
76
|
mode = 'build-static';
|
|
@@ -5,7 +5,7 @@ export class CreateReactAppPreset {
|
|
|
5
5
|
rootDir: './build',
|
|
6
6
|
staticDirs: ['[public-dir]/static'],
|
|
7
7
|
name: 'my-create-react-app',
|
|
8
|
-
description: 'Compute
|
|
8
|
+
description: 'Fastly Compute static site from create-react-app',
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
check(packageJson) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.1
|
|
5
|
-
"description": "Static Publisher for Compute
|
|
4
|
+
"version": "5.2.1",
|
|
5
|
+
"description": "Static Publisher for Fastly Compute JavaScript",
|
|
6
6
|
"main": "./build/index.js",
|
|
7
7
|
"types": "./build/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/fastly/compute-js-static-publish#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@fastly/js-compute": "^2.0.0",
|
|
35
34
|
"command-line-args": "^5.2.1",
|
|
36
35
|
"glob-to-regexp": "^0.4.1"
|
|
37
36
|
},
|
|
@@ -39,6 +38,7 @@
|
|
|
39
38
|
"@fastly/js-compute": "^2.0.0 || ^3.0.0"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
41
|
+
"@fastly/js-compute": "^3.0.0",
|
|
42
42
|
"@types/command-line-args": "^5.2.0",
|
|
43
43
|
"@types/glob-to-regexp": "^0.4.1",
|
|
44
44
|
"@types/node": "^18.0.0",
|