@fastly/compute-js-static-publish 2.3.0-alpha.0 → 2.3.0-alpha.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.
@@ -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,iBAoN5F"}
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,iBAwN5F"}
@@ -132,6 +132,7 @@ export async function buildStaticLoader(commandLineValues) {
132
132
  }
133
133
  knownAssets[filePath] = { contentType: type, isStatic, loadModule, };
134
134
  }
135
+ fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n';
135
136
  fileContents += `\nexport const assets = {\n`;
136
137
  for (const [index, file] of files.entries()) {
137
138
  const contentDef = defaultContentTypes.testFileContentType(finalContentTypes, file);
@@ -150,7 +151,7 @@ export async function buildStaticLoader(commandLineValues) {
150
151
  content = 'Buffer.from(file' + index + ', "base64")';
151
152
  }
152
153
  else {
153
- content = 'file' + index;
154
+ content = 'String(file' + index + ')';
154
155
  }
155
156
  let module;
156
157
  if (loadModule) {
@@ -198,6 +199,7 @@ export async function buildStaticLoader(commandLineValues) {
198
199
  fileContents += `\nexport const autoIndex = ${JSON.stringify(autoIndex)};\n`;
199
200
  let autoExt = (_h = config.autoExt) !== null && _h !== void 0 ? _h : null;
200
201
  fileContents += `\nexport const autoExt = ${JSON.stringify(autoExt)};\n`;
202
+ fileContents += '\nexport const staticAssets = new StaticAssets(assets);\n';
201
203
  fs.writeFileSync('./src/statics.js', fileContents);
202
204
  console.log("✅ Wrote static file loader for " + files.length + " file(s).");
203
205
  }
@@ -3,6 +3,7 @@ import { AssetsMap } from "./types.js";
3
3
  export declare class StaticAssets {
4
4
  readonly assetsMap: AssetsMap;
5
5
  constructor(assetsMap: AssetsMap);
6
+ getAsset(key: string): import("./types.js").Asset;
6
7
  serveAsset(event: FetchEvent, pathPrefix?: string): Response | null;
7
8
  }
8
9
  //# sourceMappingURL=static-assets.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"static-assets.d.ts","sourceRoot":"","sources":["../src/static-assets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,qBAAa,YAAY;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAIzB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,GAAE,MAAW;CAqB7D"}
1
+ {"version":3,"file":"static-assets.d.ts","sourceRoot":"","sources":["../src/static-assets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,qBAAa,YAAY;IACvB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAIzB,QAAQ,CAAC,GAAG,EAAE,MAAM;IAIpB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,GAAE,MAAW;CAqB7D"}
@@ -2,10 +2,13 @@ export class StaticAssets {
2
2
  constructor(assetsMap) {
3
3
  this.assetsMap = assetsMap;
4
4
  }
5
+ getAsset(key) {
6
+ return this.assetsMap[key];
7
+ }
5
8
  serveAsset(event, pathPrefix = '') {
6
9
  const { request } = event;
7
10
  const { pathname } = new URL(request.url);
8
- const asset = this.assetsMap[`${pathPrefix}${pathname}`];
11
+ const asset = this.getAsset(`${pathPrefix}${pathname}`);
9
12
  if (!asset) {
10
13
  return null;
11
14
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "2.3.0-alpha.0",
4
+ "version": "2.3.0-alpha.2",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
7
  "types": "./build/index.d.ts",