@fastly/compute-js-static-publish 3.4.0 → 3.6.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
@@ -29,7 +29,7 @@ npm install
29
29
  fastly compute serve
30
30
  ```
31
31
 
32
- The build process will generate a `/src/statics.js` file (in `./compute-js`) that holds references to your project's public files.
32
+ The build process will generate a `/src/statics.js` and accompanying `/src/statics.d.ts` file (in `./compute-js`) that holds references to your project's public files.
33
33
 
34
34
  ### 3. When you're ready to go live, [deploy your Compute@Edge service](https://developer.fastly.com/reference/cli/compute/publish/)
35
35
 
@@ -101,13 +101,11 @@ You may still override any of these options individually.
101
101
 
102
102
  ## Migrating
103
103
 
104
- If you've updated your project to 3.0.0 or newer of `@fastly/compute-js-static-publish`, and it was scaffolded a version of this tool older than 3.0.0, you'll need to either re-scaffold your project, or make some changes to your application.
105
-
106
- If you wish to modify your application, make the following changes:
104
+ To update `@fastly/compute-js-static-publish` to a new major version, we recommend that you re-scaffold your application. However, we know that's not always possible, so the following is provided to help you overcome any breaking changes.
107
105
 
108
106
  * `webpack.config.js`
109
107
 
110
- * Add a new `externals` array to the bottom if it doesn't exist already, and add the following entry:
108
+ * Starting `v3.0.0`, we depend on `v1.0.0` of the `js-compute` library. You'll need to add a new `externals` array to the bottom if it doesn't exist already, and add the following entry:
111
109
 
112
110
  ```javascript
113
111
  module.exports = {
@@ -123,7 +121,7 @@ If you wish to modify your application, make the following changes:
123
121
  }
124
122
  ```
125
123
 
126
- * Remove the following code from the `module.rules` array.
124
+ * Starting `v3.0.0`, we are able to produce more size-efficient Wasm files by using the [`includeBytes` function](https://js-compute-reference-docs.edgecompute.app/docs/fastly:experimental/includeBytes) to include the contents of static files instead of Webpack static assets. The following code can safely be removed from the `module.rules` array.
127
125
 
128
126
  ```javascript
129
127
  {
@@ -150,24 +148,29 @@ If you wish to modify your application, make the following changes:
150
148
 
151
149
  * `.gitignore`
152
150
 
153
- * Add the following entry:
151
+ * Add any of the following entries that may be missing from your `.gitignore` file:
154
152
 
155
153
  ```gitignore
154
+ /src/statics.js
155
+ /src/statics.d.ts
156
156
  /src/static-content
157
157
  ```
158
+
159
+ * Various versions of `@fastly/compute-js-static-publish` have specified different build scripts. At the current time, the following is the recommended setup, regardless of the version of `@fastly/compute-js-static-publish` or Fastly CLI.
158
160
 
159
- ## Troubleshooting
160
-
161
- If you're using Fastly CLI 4.0.0 or newer, and your project was scaffolded using a version
162
- of this tool older than 2.1.0, then you'll need to either re-scaffold your project, or add the following to the
163
- `fastly.toml` file that is in your `compute-js` directory.
164
-
165
- ```toml
166
- [scripts]
167
- build = "npx @fastly/compute-js-static-publish --build-static && npx webpack && npx js-compute-runtime ./bin/index.js ./bin/main.wasm"
168
- ```
161
+ * The build script listed in `compute-js/fastly.toml` should look like this:
162
+ ```toml
163
+ [scripts]
164
+ build = "npm run build"
165
+ ```
169
166
 
170
- If Fastly CLI has already added `build = "npx webpack && npx js-compute-runtime ./bin/index.js ./bin/main.wasm"`, then replace it with the above.
167
+ * The `scripts` section of `compute-js/package.json` should contain the following lines:
168
+ ```json
169
+ {
170
+ "prebuild": "npx @fastly/compute-js-static-publish --build-static && webpack",
171
+ "build": "js-compute-runtime ./bin/index.js ./bin/main.wasm"
172
+ }
173
+ ```
171
174
 
172
175
  ## Issues
173
176
 
@@ -1 +1 @@
1
- {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../src/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiDvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QA6R5D"}
1
+ {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../src/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiDvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QA+R5D"}
package/build/init-app.js CHANGED
@@ -174,13 +174,13 @@ export function initApp(commandLineValues) {
174
174
  "description": ${JSON.stringify(description)},
175
175
  "author": ${JSON.stringify(author)},
176
176
  "devDependencies": {
177
- "@fastly/compute-js-static-publish": "^3.0.1",
177
+ "@fastly/compute-js-static-publish": "^3.5.0",
178
178
  "@fastly/expressly": "^1.0.0-beta.2",
179
179
  "webpack": "^5.75.0",
180
180
  "webpack-cli": "^5.0.0"
181
181
  },
182
182
  "dependencies": {
183
- "@fastly/js-compute": "^1.0.1"
183
+ "@fastly/js-compute": "^1.3.4"
184
184
  },
185
185
  "engines": {
186
186
  "node": ">=16.0.0"
@@ -189,7 +189,9 @@ export function initApp(commandLineValues) {
189
189
  "private": true,
190
190
  "main": "src/index.js",
191
191
  "scripts": {
192
- "deploy": "fastly compute deploy"
192
+ "deploy": "fastly compute deploy",
193
+ "prebuild": "npx @fastly/compute-js-static-publish --build-static && webpack",
194
+ "build": "js-compute-runtime ./bin/index.js ./bin/main.wasm"
193
195
  },
194
196
  "version": "0.2.1"
195
197
  }
@@ -210,7 +212,7 @@ name = "${name}"
210
212
  ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
211
213
  ` : ''}
212
214
  [scripts]
213
- build = "npx @fastly/compute-js-static-publish --build-static && npx webpack && npx js-compute-runtime ./bin/index.js ./bin/main.wasm"
215
+ build = "npm run build"
214
216
  `;
215
217
  const fastlyTomlPath = path.resolve(computeJsDir, 'fastly.toml');
216
218
  fs.writeFileSync(fastlyTomlPath, fastlyTomlContent, "utf-8");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "3.4.0",
4
+ "version": "3.6.0",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/fastly/compute-js-static-publish#readme",
32
32
  "dependencies": {
33
- "@fastly/js-compute": "^1.0.1",
33
+ "@fastly/js-compute": "^1.4.0",
34
34
  "command-line-args": "^5.2.1"
35
35
  },
36
36
  "devDependencies": {
@@ -84,7 +84,7 @@ function mergeContentTypes(contentTypes) {
84
84
  }
85
85
 
86
86
  function testFileContentType(contentTypes, file) {
87
- for (const contentType of contentTypes) {
87
+ for (const contentType of contentTypes ?? defaultContentTypes) {
88
88
  let matched = false;
89
89
  if(contentType.test instanceof RegExp) {
90
90
  matched = contentType.test.test(file);
@@ -100,6 +100,7 @@ function testFileContentType(contentTypes, file) {
100
100
  }
101
101
 
102
102
  module.exports = {
103
+ defaultContentTypes,
103
104
  mergeContentTypes,
104
105
  testFileContentType,
105
106
  };
@@ -0,0 +1,15 @@
1
+ export type ContentTypeDef = {
2
+ test: RegExp | ((path: string) => boolean),
3
+ type: string,
4
+ binary?: boolean,
5
+ };
6
+
7
+ export type ContentTypeTestResult = {
8
+ type: string,
9
+ binary: boolean,
10
+ };
11
+
12
+ declare const defaultContentTypes: ContentTypeDef[];
13
+
14
+ declare function mergeContentTypes(entries?: ContentTypeDef[]): ContentTypeDef[];
15
+ declare function testFileContentType(entries: ContentTypeDef[] | null | undefined, path: string): ContentTypeTestResult | null;