@fastly/compute-js-static-publish 3.2.1 → 3.3.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":"AAkBA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAchD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBAmP5F"}
1
+ {"version":3,"file":"build-static.d.ts","sourceRoot":"","sources":["../src/build-static.ts"],"names":[],"mappings":"AAoBA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAwBhD,wBAAsB,iBAAiB,CAAC,iBAAiB,EAAE,eAAe,CAAC,kBAAkB,iBA6P5F"}
@@ -20,6 +20,15 @@ function getFiles(results, dir) {
20
20
  }
21
21
  }
22
22
  }
23
+ function processModuleTestResult(value) {
24
+ if (value === true) {
25
+ return 'static';
26
+ }
27
+ if (value === false) {
28
+ return false;
29
+ }
30
+ return value;
31
+ }
23
32
  export async function buildStaticLoader(commandLineValues) {
24
33
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
25
34
  const { 'suppress-framework-warnings': suppressFrameworkWarnings } = commandLineValues;
@@ -121,17 +130,20 @@ export async function buildStaticLoader(commandLineValues) {
121
130
  */
122
131
 
123
132
  `;
124
- fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n';
125
133
  fileContents += 'import { includeBytes } from "fastly:experimental";\n';
134
+ fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n';
126
135
  // If any files need to be loaded as modules, import them now.
127
136
  const loadAsModule = [];
128
137
  if (moduleTest != null) {
129
138
  for (const [index, file] of files.entries()) {
130
- const relativeFilePath = path.relative('./src', file);
131
139
  const filePath = file.slice(publicDirRoot.length);
132
- if (moduleTest(filePath)) {
133
- loadAsModule[index] = true;
134
- fileContents += `import * as fileModule${index} from "${relativeFilePath}";\n`;
140
+ const moduleTestValue = processModuleTestResult(moduleTest(filePath));
141
+ if (moduleTestValue) {
142
+ loadAsModule[index] = moduleTestValue;
143
+ if (moduleTestValue === 'static') {
144
+ const relativeFilePath = path.relative('./src', file);
145
+ fileContents += `import * as fileModule${index} from "${relativeFilePath}";\n`;
146
+ }
135
147
  }
136
148
  }
137
149
  }
@@ -168,13 +180,21 @@ export async function buildStaticLoader(commandLineValues) {
168
180
  content = `textDecoder.decode(${content})`;
169
181
  }
170
182
  let module;
171
- if (loadAsModule[index]) {
183
+ if (loadAsModule[index] === 'static') {
172
184
  module = 'fileModule' + index;
173
185
  }
174
186
  else {
175
187
  module = 'null';
176
188
  }
177
- fileContents += ` ${JSON.stringify(filePath)}: { type: ${JSON.stringify(staticFileType)}, contentType: ${JSON.stringify(type)}, content: ${content}, module: ${module}, isStatic: ${JSON.stringify(isStatic)} },\n`;
189
+ let loadModuleFunction;
190
+ if (loadAsModule[index] === 'dynamic') {
191
+ const relativeFilePath = path.relative('./src', file);
192
+ loadModuleFunction = `() => import("${relativeFilePath}")`;
193
+ }
194
+ else {
195
+ loadModuleFunction = 'null';
196
+ }
197
+ fileContents += ` ${JSON.stringify(filePath)}: { type: ${JSON.stringify(staticFileType)}, contentType: ${JSON.stringify(type)}, content: ${content}, module: ${module}, loadModule: ${loadModuleFunction}, isStatic: ${JSON.stringify(isStatic)} },\n`;
178
198
  }
179
199
  fileContents += '};\n';
180
200
  let spaFile = (_h = config.spa) !== null && _h !== void 0 ? _h : false;
@@ -4,6 +4,7 @@ export declare class StaticAssets {
4
4
  readonly assetsMap: AssetsMap;
5
5
  constructor(assetsMap: AssetsMap);
6
6
  getAsset(key: string): Asset;
7
+ get assets(): AssetsMap;
7
8
  serveAsset(asset: Asset): Response;
8
9
  serveAssetForEvent(event: FetchEvent, pathPrefix?: string): Response | null;
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"static-assets.d.ts","sourceRoot":"","sources":["../src/static-assets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,qBAAa,YAAY;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAIzB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAI5B,UAAU,CAAC,KAAK,EAAE,KAAK;IAcvB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,GAAE,MAAW;CAWrE"}
1
+ {"version":3,"file":"static-assets.d.ts","sourceRoot":"","sources":["../src/static-assets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,qBAAa,YAAY;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAIzB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAInC,IAAW,MAAM,IAAI,SAAS,CAE7B;IAEM,UAAU,CAAC,KAAK,EAAE,KAAK;IAcvB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,GAAE,MAAW;CAWrE"}
@@ -5,6 +5,9 @@ export class StaticAssets {
5
5
  getAsset(key) {
6
6
  return this.assetsMap[key];
7
7
  }
8
+ get assets() {
9
+ return this.assetsMap;
10
+ }
8
11
  serveAsset(asset) {
9
12
  // Aggressive caching for static files, and no caching for everything else.
10
13
  const headers = {
package/build/types.d.ts CHANGED
@@ -15,6 +15,7 @@ export declare type DefaultContentTypesModule = {
15
15
  export declare type AssetBase = {
16
16
  contentType: string;
17
17
  module: any | null;
18
+ loadModule: () => Promise<any> | null;
18
19
  isStatic: boolean;
19
20
  };
20
21
  export declare type StringAsset = AssetBase & {
@@ -29,13 +30,16 @@ export declare type Asset = StringAsset | BinaryAsset;
29
30
  export declare type AssetsMap = {
30
31
  [filePath: string]: Asset;
31
32
  };
33
+ export declare type ModuleLoadType = 'static' | 'dynamic';
34
+ export declare type ModuleTestResult = ModuleLoadType | false;
35
+ export declare type ModuleTestFunction = ((path: string) => true | ModuleTestResult) | null;
32
36
  export declare type Config = {
33
37
  publicDir: string;
34
38
  excludeDirs?: string[] | null;
35
39
  includeDirs?: string[] | null;
36
40
  staticDirs?: string[] | null;
37
41
  excludeTest?: ((path: string) => boolean) | null;
38
- moduleTest?: ((path: string) => boolean) | null;
42
+ moduleTest?: ModuleTestFunction;
39
43
  spa?: string | null;
40
44
  autoIndex?: string[] | false | null;
41
45
  autoExt?: string[] | false | null;
@@ -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,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AACF,oBAAY,WAAW,GAAG,SAAS,GAAG;IACpC,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AACF,oBAAY,WAAW,GAAG,SAAS,GAAG;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AAE,MAAM,EAAG,GAAG,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,IAAI,CAAC;IACjD,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,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.2.1",
4
+ "version": "3.3.0",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",