@fastly/compute-js-static-publish 3.0.1 → 3.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../src/build-static.ts"],"names":[],"mappings":"AAcA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAchD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAsO5F"}
1
+ {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../src/build-static.ts"],"names":[],"mappings":"AAkBA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAchD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAmP5F"}
@@ -21,7 +21,7 @@ function getFiles(results, dir) {
21
21
  }
22
22
  }
23
23
  export async function buildStaticLoader(commandLineValues) {
24
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
24
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
25
25
  const { 'suppress-framework-warnings': suppressFrameworkWarnings } = commandLineValues;
26
26
  const displayFrameworkWarnings = !suppressFrameworkWarnings;
27
27
  console.log("🚀 Building loader...");
@@ -65,8 +65,8 @@ export async function buildStaticLoader(commandLineValues) {
65
65
  }
66
66
  }
67
67
  const excludeRoots = excludeDirs.map(dir => path.resolve(publicDirRoot, dir));
68
- // Load defaultContentTypes module
69
68
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
69
+ // Load defaultContentTypes module
70
70
  const defaultContentTypesJsSrcPath = path.resolve(__dirname, '../resources/default-content-types.cjs');
71
71
  const defaultContentTypes = await import(defaultContentTypesJsSrcPath);
72
72
  // Load content types
@@ -84,7 +84,7 @@ export async function buildStaticLoader(commandLineValues) {
84
84
  }
85
85
  }
86
86
  const includeRoots = includeDirs.map(dir => path.resolve(publicDirRoot, dir));
87
- const excludeTest = config.excludeTest;
87
+ const excludeTest = (_f = config.excludeTest) !== null && _f !== void 0 ? _f : null;
88
88
  const files = results
89
89
  .filter(file => {
90
90
  // Exclude files that come from C@E app dir
@@ -108,7 +108,7 @@ export async function buildStaticLoader(commandLineValues) {
108
108
  .filter(file => {
109
109
  return excludeTest == null || !excludeTest(file);
110
110
  });
111
- const moduleTest = config.moduleTest;
111
+ const moduleTest = (_g = config.moduleTest) !== null && _g !== void 0 ? _g : null;
112
112
  const knownAssets = {};
113
113
  // Create "static content" dir that will be used to hold a copy of static files
114
114
  // NOTE: this is needed because includeBytes doesn't seem to be able to traverse
@@ -116,7 +116,11 @@ export async function buildStaticLoader(commandLineValues) {
116
116
  const staticContentDir = './src/static-content';
117
117
  fs.rmSync(staticContentDir, { recursive: true, force: true });
118
118
  fs.mkdirSync(staticContentDir, { recursive: true });
119
- let fileContents = '';
119
+ let fileContents = `/*
120
+ * Generated by @fastly/compute-js-static-publish.
121
+ */
122
+
123
+ `;
120
124
  fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n';
121
125
  fileContents += 'import { includeBytes } from "fastly:experimental";\n';
122
126
  // If any files need to be loaded as modules, import them now.
@@ -147,22 +151,20 @@ export async function buildStaticLoader(commandLineValues) {
147
151
  }
148
152
  }
149
153
  // Serve static files by copying them into the static content dir and using includeBytes()
150
- let staticFileExt, staticFileTypeDesc, isBinary;
154
+ let staticFileExt, staticFileType;
151
155
  if (contentDef == null || contentDef.binary) {
152
156
  staticFileExt = '.bin';
153
- staticFileTypeDesc = 'binary';
154
- isBinary = true;
157
+ staticFileType = 'binary';
155
158
  }
156
159
  else {
157
160
  staticFileExt = '.txt';
158
- staticFileTypeDesc = 'text';
159
- isBinary = false;
161
+ staticFileType = 'string';
160
162
  }
161
163
  const staticFilePath = `${staticContentDir}/file${index}${staticFileExt}`;
162
164
  fs.cpSync(file, staticFilePath);
163
- console.log(`✔️ Copied static ${staticFileTypeDesc} file "${file}" to "${staticFilePath}".`);
165
+ console.log(`✔️ Copied static ${staticFileType} file "${file}" to "${staticFilePath}".`);
164
166
  let content = `includeBytes("${staticFilePath}")`;
165
- if (!isBinary) {
167
+ if (staticFileType === 'string') {
166
168
  content = `textDecoder.decode(${content})`;
167
169
  }
168
170
  let module;
@@ -172,10 +174,10 @@ export async function buildStaticLoader(commandLineValues) {
172
174
  else {
173
175
  module = 'null';
174
176
  }
175
- fileContents += ` ${JSON.stringify(filePath)}: { contentType: ${JSON.stringify(type)}, content: ${content}, module: ${module}, isStatic: ${JSON.stringify(isStatic)} },\n`;
177
+ fileContents += ` ${JSON.stringify(filePath)}: { type: ${JSON.stringify(staticFileType)}, contentType: ${JSON.stringify(type)}, content: ${content}, module: ${module}, isStatic: ${JSON.stringify(isStatic)} },\n`;
176
178
  }
177
179
  fileContents += '};\n';
178
- let spaFile = (_f = config.spa) !== null && _f !== void 0 ? _f : false;
180
+ let spaFile = (_h = config.spa) !== null && _h !== void 0 ? _h : false;
179
181
  if (spaFile) {
180
182
  console.log(`✔️ Application SPA file '${spaFile}'.`);
181
183
  if (!knownAssets[spaFile] || knownAssets[spaFile].contentType !== 'text/html') {
@@ -191,7 +193,7 @@ export async function buildStaticLoader(commandLineValues) {
191
193
  }
192
194
  }
193
195
  fileContents += `\nexport const spaFile = ${JSON.stringify(spaFile)};\n`;
194
- let notFoundPageFile = (_g = config.notFoundPage) !== null && _g !== void 0 ? _g : false;
196
+ let notFoundPageFile = (_j = config.notFoundPage) !== null && _j !== void 0 ? _j : false;
195
197
  if (notFoundPageFile) {
196
198
  console.log(`✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
197
199
  if (!knownAssets[notFoundPageFile] || knownAssets[notFoundPageFile].contentType !== 'text/html') {
@@ -207,11 +209,20 @@ export async function buildStaticLoader(commandLineValues) {
207
209
  }
208
210
  }
209
211
  fileContents += `\nexport const notFoundPageFile = ${JSON.stringify(notFoundPageFile)};\n`;
210
- let autoIndex = (_h = config.autoIndex) !== null && _h !== void 0 ? _h : null;
212
+ let autoIndex = (_k = config.autoIndex) !== null && _k !== void 0 ? _k : false;
211
213
  fileContents += `\nexport const autoIndex = ${JSON.stringify(autoIndex)};\n`;
212
- let autoExt = (_j = config.autoExt) !== null && _j !== void 0 ? _j : null;
214
+ let autoExt = (_l = config.autoExt) !== null && _l !== void 0 ? _l : false;
213
215
  fileContents += `\nexport const autoExt = ${JSON.stringify(autoExt)};\n`;
214
216
  fileContents += '\nexport const staticAssets = new StaticAssets(assets);\n';
215
217
  fs.writeFileSync('./src/statics.js', fileContents);
216
218
  console.log("✅ Wrote static file loader for " + files.length + " file(s).");
219
+ // Copy Types file for static file loader
220
+ try {
221
+ const staticsTypeFile = path.resolve(__dirname, '../resources/statics.d.ts');
222
+ fs.copyFileSync(staticsTypeFile, './src/statics.d.ts');
223
+ console.log("✅ Wrote static file loader types file statics.d.ts.");
224
+ }
225
+ catch (_m) {
226
+ console.log("⚠️ Notice: could not wrote static file loader types file statics.d.ts.");
227
+ }
217
228
  }
package/build/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export type { Asset, AssetsMap } from './types.js';
1
+ export type { Asset, AssetsMap, Config } from './types.js';
2
2
  export { StaticAssets } from './static-assets.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -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,QA2R5D"}
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"}
package/build/init-app.js CHANGED
@@ -161,6 +161,7 @@ export function initApp(commandLineValues) {
161
161
  /bin
162
162
  /pkg
163
163
  /src/statics.js
164
+ /src/statics.d.ts
164
165
  /src/static-content
165
166
  `;
166
167
  const gitIgnorePath = path.resolve(computeJsDir, '.gitignore');
@@ -238,6 +239,7 @@ ${fastlyServiceId != null ? `service_id = "${fastlyServiceId}"
238
239
  notFoundFileRel = '/' + path.relative(publicDir, notFoundPageFilename);
239
240
  }
240
241
  const staticPublishJsContent = `\
242
+ /** @type {import('@fastly/compute-js-static-publish').Config} */
241
243
  module.exports = {
242
244
  publicDir: ${JSON.stringify(publicDirRel)},
243
245
  excludeDirs: [ './node_modules' ],
package/build/types.d.ts CHANGED
@@ -12,14 +12,35 @@ export declare type DefaultContentTypesModule = {
12
12
  mergeContentTypes: (contentTypes: ContentTypeDef[]) => ContentTypeDef[];
13
13
  testFileContentType: (contentTypes: ContentTypeDef[], file: string) => ContentTypeMatch;
14
14
  };
15
- export declare type Asset = {
15
+ export declare type AssetBase = {
16
16
  contentType: string;
17
- content: ArrayBuffer | string;
18
- module: unknown | null;
17
+ module: any | null;
19
18
  isStatic: boolean;
20
19
  };
20
+ export declare type StringAsset = AssetBase & {
21
+ type: 'string';
22
+ content: string;
23
+ };
24
+ export declare type BinaryAsset = AssetBase & {
25
+ type: 'binary';
26
+ content: Uint8Array;
27
+ };
28
+ export declare type Asset = StringAsset | BinaryAsset;
21
29
  export declare type AssetsMap = {
22
30
  [filePath: string]: Asset;
23
31
  };
32
+ export declare type Config = {
33
+ publicDir: string;
34
+ excludeDirs?: string[] | null;
35
+ includeDirs?: string[] | null;
36
+ staticDirs?: string[] | null;
37
+ excludeTest?: ((path: string) => boolean) | null;
38
+ moduleTest?: ((path: string) => boolean) | null;
39
+ spa?: string | null;
40
+ autoIndex?: string[] | false | null;
41
+ autoExt?: string[] | false | null;
42
+ notFoundPage?: string | false | null;
43
+ contentTypes?: ContentTypeDef[] | null;
44
+ };
24
45
  export {};
25
46
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,aAAK,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAExC,oBAAY,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IACtC,iBAAiB,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,CAAC;IACxE,mBAAmB,EAAE,CAAC,YAAY,EAAE,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,KAAK,gBAAgB,CAAC;CACzF,CAAC;AAEF,oBAAY,KAAK,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,WAAW,GAAG,MAAM,CAAC;IAC9B,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;CAC3B,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src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,EAAG,GAAG,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,IAAI,CAAC;IACjD,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,IAAI,CAAC;IAChD,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;IACrC,YAAY,CAAC,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;CACxC,CAAC"}
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.0.1",
4
+ "version": "3.2.0",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",
@@ -15,7 +15,7 @@ function getMatchingRequestPath(path) {
15
15
 
16
16
  // ... or, we can try auto-ext:
17
17
  // looks for an asset that has the specified suffix (usually extension, such as .html)
18
- if(autoExt != null) {
18
+ if(Array.isArray(autoExt)) {
19
19
  for (const extEntry of autoExt) {
20
20
  let pathWithExt = path + extEntry;
21
21
  if (staticAssets.getAsset(pathWithExt) != null) {
@@ -34,7 +34,7 @@ function getMatchingRequestPath(path) {
34
34
  dir = dir.slice(0, -1);
35
35
  }
36
36
  dir = dir + '/';
37
- if(autoIndex != null) {
37
+ if(Array.isArray(autoIndex)) {
38
38
  for (const indexEntry of autoIndex) {
39
39
  let indexPath = dir + indexEntry;
40
40
  if (staticAssets.getAsset(indexPath) != null) {
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Generated by @fastly/compute-js-static-publish.
3
+ */
4
+
5
+ import type { AssetsMap, StaticAssets } from "@fastly/compute-js-static-publish";
6
+ export declare const assets: AssetsMap;
7
+ export declare const spaFile: string | false;
8
+ export declare const notFoundPageFile: string | false;
9
+ export declare const autoIndex: string[] | false;
10
+ export declare const autoExt: string[] | false;
11
+ export declare const staticAssets: StaticAssets;