@fastly/compute-js-static-publish 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/build/build-static.js +13 -13
- package/build/init-app.js +8 -8
- package/package.json +1 -1
- package/resources/default-content-types.cjs +4 -4
- package/src/build-static.ts +13 -13
- package/src/init-app.ts +8 -8
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Assuming the root of your output directory is `./public`,
|
|
|
11
11
|
### 1. Run `compute-js-static-publish`
|
|
12
12
|
|
|
13
13
|
```shell
|
|
14
|
-
npx @fastly/compute-js-static-publish --public-dir=./public
|
|
14
|
+
npx @fastly/compute-js-static-publish@latest --public-dir=./public
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
>This will generate a Compute@Edge application at `./compute-js`. It will add a default `./src/index.js` file that serves the static files from your project.
|
|
@@ -91,21 +91,21 @@ These arguments are used to populate the `fastly.toml` and `package.json` files
|
|
|
91
91
|
|
|
92
92
|
You may still override any of these options individually.
|
|
93
93
|
|
|
94
|
-
*1 - For Next.js, consider using `@fastly/next-compute-js`, a
|
|
94
|
+
*1 - For Next.js, consider using `@fastly/next-compute-js`, a Next.js server implementation that allows you to run
|
|
95
95
|
your Next.js application on Compute@Edge.
|
|
96
96
|
|
|
97
97
|
## Troubleshooting
|
|
98
98
|
|
|
99
99
|
If you're using Fastly CLI 4.0.0 or newer, and your project was scaffolded using a version
|
|
100
|
-
of this tool older than 2.1.0, then you'll need to add the following to the
|
|
100
|
+
of this tool older than 2.1.0, then you'll need to either re-scaffold your project, or add the following to the
|
|
101
101
|
`fastly.toml` file that is in your `compute-js` directory.
|
|
102
102
|
|
|
103
103
|
```toml
|
|
104
104
|
[scripts]
|
|
105
|
-
build = "npx @fastly/compute-js-static-publish --build-static &&
|
|
105
|
+
build = "npx @fastly/compute-js-static-publish --build-static && npx webpack && npx js-compute-runtime ./bin/index.js ./bin/main.wasm"
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
If Fastly CLI has already added `build = "
|
|
108
|
+
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.
|
|
109
109
|
|
|
110
110
|
## Issues
|
|
111
111
|
|
package/build/build-static.js
CHANGED
|
@@ -41,14 +41,14 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
41
41
|
getFiles(results, config.publicDir);
|
|
42
42
|
const outputDir = path.resolve();
|
|
43
43
|
const publicDirRoot = path.resolve(config.publicDir);
|
|
44
|
-
console.log(
|
|
44
|
+
console.log(`✔️ Public directory '${publicDirRoot}'.`);
|
|
45
45
|
const staticDirs = (_a = config.staticDirs) !== null && _a !== void 0 ? _a : [];
|
|
46
46
|
if (staticDirs.length > 0) {
|
|
47
|
-
console.log(
|
|
47
|
+
console.log(`✔️ Using static directories: ${staticDirs.join(', ')}`);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
if (displayFrameworkWarnings) {
|
|
51
|
-
console.log(
|
|
51
|
+
console.log(`✔️ No static directories defined.`);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
const staticRoots = staticDirs.map(dir => path.resolve(config.publicDir, dir));
|
|
@@ -57,11 +57,11 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
57
57
|
];
|
|
58
58
|
const excludeDirs = (_b = config.excludeDirs) !== null && _b !== void 0 ? _b : DEFAULT_EXCLUDE_DIRS;
|
|
59
59
|
if (excludeDirs.length > 0) {
|
|
60
|
-
console.log(
|
|
60
|
+
console.log(`✔️ Using exclude directories: ${excludeDirs.join(', ')}`);
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
63
|
if (displayFrameworkWarnings) {
|
|
64
|
-
console.log(
|
|
64
|
+
console.log(`✔️ No exclude directories defined.`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
const excludeRoots = excludeDirs.map(dir => path.resolve(config.publicDir, dir));
|
|
@@ -79,11 +79,11 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
79
79
|
];
|
|
80
80
|
const includeDirs = (_d = config.includeDirs) !== null && _d !== void 0 ? _d : DEFAULT_INCLUDE_DIRS;
|
|
81
81
|
if (includeDirs.length > 0) {
|
|
82
|
-
console.log(
|
|
82
|
+
console.log(`✔️ Using include directories: ${includeDirs.join(', ')}`);
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
85
85
|
if (displayFrameworkWarnings) {
|
|
86
|
-
console.log(
|
|
86
|
+
console.log(`✔️ No include directories defined.`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
const includeRoots = includeDirs.map(dir => path.resolve(config.publicDir, dir));
|
|
@@ -141,7 +141,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
141
141
|
const filePath = file.slice(publicDirRoot.length);
|
|
142
142
|
const { contentType: type, isStatic, loadModule } = knownAssets[filePath];
|
|
143
143
|
if (contentDef != null) {
|
|
144
|
-
console.log('
|
|
144
|
+
console.log('✔️ ' + filePath + ': ' + JSON.stringify(type) + (isStatic ? ' [STATIC]' : ''));
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
147
147
|
if (displayFrameworkWarnings) {
|
|
@@ -167,7 +167,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
167
167
|
fileContents += '};\n';
|
|
168
168
|
let spaFile = (_e = config.spa) !== null && _e !== void 0 ? _e : false;
|
|
169
169
|
if (spaFile) {
|
|
170
|
-
console.log(
|
|
170
|
+
console.log(`✔️ Application SPA file '${spaFile}'.`);
|
|
171
171
|
if (!knownAssets[spaFile] || knownAssets[spaFile].contentType !== 'text/html') {
|
|
172
172
|
if (displayFrameworkWarnings) {
|
|
173
173
|
console.log(`⚠️ Notice: '${spaFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
@@ -177,13 +177,13 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
177
177
|
}
|
|
178
178
|
else {
|
|
179
179
|
if (displayFrameworkWarnings) {
|
|
180
|
-
console.log(
|
|
180
|
+
console.log(`✔️ Application is not a SPA.`);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
fileContents += `\nexport const spaFile = ${JSON.stringify(spaFile)};\n`;
|
|
184
184
|
let notFoundPageFile = (_f = config.notFoundPage) !== null && _f !== void 0 ? _f : false;
|
|
185
185
|
if (notFoundPageFile) {
|
|
186
|
-
console.log(
|
|
186
|
+
console.log(`✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
|
|
187
187
|
if (!knownAssets[notFoundPageFile] || knownAssets[notFoundPageFile].contentType !== 'text/html') {
|
|
188
188
|
if (displayFrameworkWarnings) {
|
|
189
189
|
console.log(`⚠️ Notice: '${notFoundPageFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
@@ -193,7 +193,7 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
193
193
|
}
|
|
194
194
|
else {
|
|
195
195
|
if (displayFrameworkWarnings) {
|
|
196
|
-
console.log(
|
|
196
|
+
console.log(`✔️ Application specifies no 'not found (404)' page.`);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
fileContents += `\nexport const notFoundPageFile = ${JSON.stringify(notFoundPageFile)};\n`;
|
|
@@ -202,5 +202,5 @@ export async function buildStaticLoader(commandLineValues) {
|
|
|
202
202
|
let autoExt = (_h = config.autoExt) !== null && _h !== void 0 ? _h : null;
|
|
203
203
|
fileContents += `\nexport const autoExt = ${JSON.stringify(autoExt)};\n`;
|
|
204
204
|
fs.writeFileSync('./src/statics.js', fileContents);
|
|
205
|
-
console.log("✅
|
|
205
|
+
console.log("✅ Wrote static file loader for " + files.length + " file(s).");
|
|
206
206
|
}
|
package/build/init-app.js
CHANGED
|
@@ -143,14 +143,14 @@ export function initApp(commandLineValues) {
|
|
|
143
143
|
console.log('');
|
|
144
144
|
console.log('Public Dir :', PUBLIC_DIR);
|
|
145
145
|
console.log('Static Dir :', BUILD_STATIC_DIR !== null && BUILD_STATIC_DIR !== void 0 ? BUILD_STATIC_DIR : '(None)');
|
|
146
|
-
console.log('SPA :', spaRel
|
|
147
|
-
console.log('404 Page :', notFoundRel
|
|
148
|
-
console.log('Auto-Index :', autoIndex
|
|
149
|
-
console.log('Auto-Ext :', autoExt
|
|
146
|
+
console.log('SPA :', spaRel !== null && spaRel !== void 0 ? spaRel : '(None)');
|
|
147
|
+
console.log('404 Page :', notFoundRel !== null && notFoundRel !== void 0 ? notFoundRel : '(None)');
|
|
148
|
+
console.log('Auto-Index :', autoIndex !== null && autoIndex !== void 0 ? autoIndex : '(None)');
|
|
149
|
+
console.log('Auto-Ext :', autoExt !== null && autoExt !== void 0 ? autoExt : '(None)');
|
|
150
150
|
console.log('name :', name);
|
|
151
151
|
console.log('author :', author);
|
|
152
152
|
console.log('description :', description);
|
|
153
|
-
console.log('Service ID :', fastlyServiceId);
|
|
153
|
+
console.log('Service ID :', fastlyServiceId !== null && fastlyServiceId !== void 0 ? fastlyServiceId : '(None)');
|
|
154
154
|
console.log('');
|
|
155
155
|
console.log("Initializing Compute@Edge Application in " + computeJsDir + "...");
|
|
156
156
|
fs.mkdirSync(computeJsDir);
|
|
@@ -204,10 +204,10 @@ description = "${description}"
|
|
|
204
204
|
language = "javascript"
|
|
205
205
|
manifest_version = 2
|
|
206
206
|
name = "${name}"
|
|
207
|
-
service_id = "${fastlyServiceId}"
|
|
208
|
-
|
|
207
|
+
${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
208
|
+
` : ''}
|
|
209
209
|
[scripts]
|
|
210
|
-
build = "npx @fastly/compute-js-static-publish --build-static &&
|
|
210
|
+
build = "npx @fastly/compute-js-static-publish --build-static && npx webpack && npx js-compute-runtime ./bin/index.js ./bin/main.wasm"
|
|
211
211
|
`;
|
|
212
212
|
const fastlyTomlPath = path.resolve(computeJsDir, 'fastly.toml');
|
|
213
213
|
fs.writeFileSync(fastlyTomlPath, fastlyTomlContent, "utf-8");
|
package/package.json
CHANGED
|
@@ -47,17 +47,17 @@ function mergeContentTypes(contentTypes) {
|
|
|
47
47
|
typeof contentType.test !== 'function' &&
|
|
48
48
|
!(contentType.test instanceof RegExp)
|
|
49
49
|
) {
|
|
50
|
-
console.
|
|
50
|
+
console.log(`⚠️ Ignoring contentTypes[${index}]: 'test' must be a function or regular expression.`);
|
|
51
51
|
invalid = true;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if(typeof contentType.type !== 'string' || contentType.type.indexOf('/') === -1) {
|
|
55
|
-
console.
|
|
55
|
+
console.log(`⚠️ Ignoring contentTypes[${index}]: 'type' must be a string representing a MIME type.`);
|
|
56
56
|
invalid = true;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
if('binary' in contentType && typeof contentType.binary !== 'boolean') {
|
|
60
|
-
console.
|
|
60
|
+
console.log(`⚠️ Ignoring contentTypes[${index}]: optional 'binary' must be a boolean value.`);
|
|
61
61
|
invalid = true;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -74,7 +74,7 @@ function mergeContentTypes(contentTypes) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
console.log('Applying ' + finalContentTypes.length + ' custom content type(s).');
|
|
77
|
+
console.log('✔️ Applying ' + finalContentTypes.length + ' custom content type(s).');
|
|
78
78
|
|
|
79
79
|
for (const contentType of defaultContentTypes) {
|
|
80
80
|
finalContentTypes.push(contentType);
|
package/src/build-static.ts
CHANGED
|
@@ -52,14 +52,14 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
52
52
|
|
|
53
53
|
const publicDirRoot = path.resolve(config.publicDir);
|
|
54
54
|
|
|
55
|
-
console.log(
|
|
55
|
+
console.log(`✔️ Public directory '${publicDirRoot}'.`);
|
|
56
56
|
|
|
57
57
|
const staticDirs: string[] = config.staticDirs ?? [];
|
|
58
58
|
if (staticDirs.length > 0) {
|
|
59
|
-
console.log(
|
|
59
|
+
console.log(`✔️ Using static directories: ${staticDirs.join(', ')}`);
|
|
60
60
|
} else {
|
|
61
61
|
if (displayFrameworkWarnings) {
|
|
62
|
-
console.log(
|
|
62
|
+
console.log(`✔️ No static directories defined.`);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
const staticRoots = staticDirs.map(
|
|
@@ -72,10 +72,10 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
72
72
|
|
|
73
73
|
const excludeDirs: string[] = config.excludeDirs ?? DEFAULT_EXCLUDE_DIRS;
|
|
74
74
|
if (excludeDirs.length > 0) {
|
|
75
|
-
console.log(
|
|
75
|
+
console.log(`✔️ Using exclude directories: ${excludeDirs.join(', ')}`);
|
|
76
76
|
} else {
|
|
77
77
|
if (displayFrameworkWarnings) {
|
|
78
|
-
console.log(
|
|
78
|
+
console.log(`✔️ No exclude directories defined.`);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
const excludeRoots = excludeDirs.map(
|
|
@@ -100,10 +100,10 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
100
100
|
|
|
101
101
|
const includeDirs: string[] = config.includeDirs ?? DEFAULT_INCLUDE_DIRS;
|
|
102
102
|
if (includeDirs.length > 0) {
|
|
103
|
-
console.log(
|
|
103
|
+
console.log(`✔️ Using include directories: ${includeDirs.join(', ')}`);
|
|
104
104
|
} else {
|
|
105
105
|
if (displayFrameworkWarnings) {
|
|
106
|
-
console.log(
|
|
106
|
+
console.log(`✔️ No include directories defined.`);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
const includeRoots = includeDirs.map(
|
|
@@ -172,7 +172,7 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
172
172
|
const { contentType: type, isStatic, loadModule } = knownAssets[filePath];
|
|
173
173
|
|
|
174
174
|
if (contentDef != null) {
|
|
175
|
-
console.log('
|
|
175
|
+
console.log('✔️ ' + filePath + ': ' + JSON.stringify(type) + (isStatic ? ' [STATIC]' : ''));
|
|
176
176
|
} else {
|
|
177
177
|
if (displayFrameworkWarnings) {
|
|
178
178
|
console.log('⚠️ Notice: Unknown file type ' + filePath + '. Treating as binary file.');
|
|
@@ -200,7 +200,7 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
200
200
|
|
|
201
201
|
let spaFile: string | false = config.spa ?? false;
|
|
202
202
|
if(spaFile) {
|
|
203
|
-
console.log(
|
|
203
|
+
console.log(`✔️ Application SPA file '${spaFile}'.`);
|
|
204
204
|
if(!knownAssets[spaFile] || knownAssets[spaFile].contentType !== 'text/html') {
|
|
205
205
|
if (displayFrameworkWarnings) {
|
|
206
206
|
console.log(`⚠️ Notice: '${spaFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
@@ -209,7 +209,7 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
209
209
|
}
|
|
210
210
|
} else {
|
|
211
211
|
if (displayFrameworkWarnings) {
|
|
212
|
-
console.log(
|
|
212
|
+
console.log(`✔️ Application is not a SPA.`);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -217,7 +217,7 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
217
217
|
|
|
218
218
|
let notFoundPageFile: string | false = config.notFoundPage ?? false;
|
|
219
219
|
if(notFoundPageFile) {
|
|
220
|
-
console.log(
|
|
220
|
+
console.log(`✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
|
|
221
221
|
if(!knownAssets[notFoundPageFile] || knownAssets[notFoundPageFile].contentType !== 'text/html') {
|
|
222
222
|
if (displayFrameworkWarnings) {
|
|
223
223
|
console.log(`⚠️ Notice: '${notFoundPageFile}' does not exist or is not of type 'text/html'. Ignoring.`);
|
|
@@ -226,7 +226,7 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
226
226
|
}
|
|
227
227
|
} else {
|
|
228
228
|
if (displayFrameworkWarnings) {
|
|
229
|
-
console.log(
|
|
229
|
+
console.log(`✔️ Application specifies no 'not found (404)' page.`);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
@@ -240,6 +240,6 @@ export async function buildStaticLoader(commandLineValues: commandLineArgs.Comma
|
|
|
240
240
|
|
|
241
241
|
fs.writeFileSync('./src/statics.js', fileContents);
|
|
242
242
|
|
|
243
|
-
console.log("✅
|
|
243
|
+
console.log("✅ Wrote static file loader for " + files.length + " file(s).");
|
|
244
244
|
|
|
245
245
|
}
|
package/src/init-app.ts
CHANGED
|
@@ -175,14 +175,14 @@ export function initApp(commandLineValues: CommandLineOptions) {
|
|
|
175
175
|
console.log('');
|
|
176
176
|
console.log('Public Dir :', PUBLIC_DIR);
|
|
177
177
|
console.log('Static Dir :', BUILD_STATIC_DIR ?? '(None)');
|
|
178
|
-
console.log('SPA :', spaRel
|
|
179
|
-
console.log('404 Page :', notFoundRel
|
|
180
|
-
console.log('Auto-Index :', autoIndex
|
|
181
|
-
console.log('Auto-Ext :', autoExt
|
|
178
|
+
console.log('SPA :', spaRel ?? '(None)');
|
|
179
|
+
console.log('404 Page :', notFoundRel ?? '(None)');
|
|
180
|
+
console.log('Auto-Index :', autoIndex ?? '(None)')
|
|
181
|
+
console.log('Auto-Ext :', autoExt ?? '(None)')
|
|
182
182
|
console.log('name :', name);
|
|
183
183
|
console.log('author :', author);
|
|
184
184
|
console.log('description :', description);
|
|
185
|
-
console.log('Service ID :', fastlyServiceId);
|
|
185
|
+
console.log('Service ID :', fastlyServiceId ?? '(None)');
|
|
186
186
|
console.log('');
|
|
187
187
|
|
|
188
188
|
console.log("Initializing Compute@Edge Application in " + computeJsDir + "...");
|
|
@@ -243,10 +243,10 @@ description = "${description}"
|
|
|
243
243
|
language = "javascript"
|
|
244
244
|
manifest_version = 2
|
|
245
245
|
name = "${name}"
|
|
246
|
-
service_id = "${fastlyServiceId}"
|
|
247
|
-
|
|
246
|
+
${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
|
|
247
|
+
` : ''}
|
|
248
248
|
[scripts]
|
|
249
|
-
build = "npx @fastly/compute-js-static-publish --build-static &&
|
|
249
|
+
build = "npx @fastly/compute-js-static-publish --build-static && npx webpack && npx js-compute-runtime ./bin/index.js ./bin/main.wasm"
|
|
250
250
|
`;
|
|
251
251
|
|
|
252
252
|
const fastlyTomlPath = path.resolve(computeJsDir, 'fastly.toml');
|