@fastly/compute-js-static-publish 2.2.1 → 2.3.0-alpha.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.
Files changed (58) hide show
  1. package/README.md +5 -5
  2. package/build/assets.d.ts +8 -0
  3. package/build/assets.d.ts.map +1 -0
  4. package/build/assets.js +24 -0
  5. package/build/build-static.d.ts +3 -0
  6. package/build/build-static.d.ts.map +1 -0
  7. package/build/build-static.js +0 -3
  8. package/build/cli.d.ts +3 -0
  9. package/build/cli.d.ts.map +1 -0
  10. package/build/cli.js +77 -0
  11. package/build/index.d.ts +3 -0
  12. package/build/index.d.ts.map +1 -0
  13. package/build/index.js +2 -77
  14. package/build/init-app.d.ts +3 -0
  15. package/build/init-app.d.ts.map +1 -0
  16. package/build/init-app.js +8 -8
  17. package/build/presets/implementations/create-react-app.d.ts +16 -0
  18. package/build/presets/implementations/create-react-app.d.ts.map +1 -0
  19. package/build/presets/implementations/docusaurus.d.ts +11 -0
  20. package/build/presets/implementations/docusaurus.d.ts.map +1 -0
  21. package/build/presets/implementations/gatsby.d.ts +11 -0
  22. package/build/presets/implementations/gatsby.d.ts.map +1 -0
  23. package/build/presets/implementations/next.d.ts +11 -0
  24. package/build/presets/implementations/next.d.ts.map +1 -0
  25. package/build/presets/implementations/sveltekit.d.ts +11 -0
  26. package/build/presets/implementations/sveltekit.d.ts.map +1 -0
  27. package/build/presets/implementations/vite.d.ts +11 -0
  28. package/build/presets/implementations/vite.d.ts.map +1 -0
  29. package/build/presets/index.d.ts +3 -0
  30. package/build/presets/index.d.ts.map +1 -0
  31. package/build/presets/preset-base.d.ts +18 -0
  32. package/build/presets/preset-base.d.ts.map +1 -0
  33. package/build/static-assets.d.ts +8 -0
  34. package/build/static-assets.d.ts.map +1 -0
  35. package/build/static-assets.js +24 -0
  36. package/build/types.d.ts +26 -0
  37. package/build/types.d.ts.map +1 -0
  38. package/build/types.js +1 -0
  39. package/package.json +13 -4
  40. package/.idea/compute-js-static-publish.iml +0 -12
  41. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  42. package/.idea/jsLibraryMappings.xml +0 -6
  43. package/.idea/misc.xml +0 -6
  44. package/.idea/modules.xml +0 -8
  45. package/.idea/vcs.xml +0 -6
  46. package/src/build-static.ts +0 -245
  47. package/src/content-types.ts +0 -7
  48. package/src/index.ts +0 -89
  49. package/src/init-app.ts +0 -331
  50. package/src/presets/implementations/create-react-app.ts +0 -34
  51. package/src/presets/implementations/docusaurus.ts +0 -13
  52. package/src/presets/implementations/gatsby.ts +0 -13
  53. package/src/presets/implementations/next.ts +0 -13
  54. package/src/presets/implementations/sveltekit.ts +0 -13
  55. package/src/presets/implementations/vite.ts +0 -13
  56. package/src/presets/index.ts +0 -18
  57. package/src/presets/preset-base.ts +0 -18
  58. package/tsconfig.json +0 -19
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 Node.js server implementation that allows you to run
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 && $(npm bin)/webpack && $(npm bin)/js-compute-runtime ./bin/index.js ./bin/main.wasm"
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 = "$(npm bin)/webpack && $(npm bin)/js-compute-runtime ./bin/index.js ./bin/main.wasm"`, then replace it with the above.
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
 
@@ -0,0 +1,8 @@
1
+ /// <reference types="@fastly/js-compute" />
2
+ import { AssetsMap } from "./types.js";
3
+ export declare class Assets {
4
+ readonly assetsMap: AssetsMap;
5
+ constructor(assetsMap: AssetsMap);
6
+ serveAsset(event: FetchEvent, pathPrefix?: string): Response | null;
7
+ }
8
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,qBAAa,MAAM;IACjB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAIzB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,GAAE,MAAW;CAqB7D"}
@@ -0,0 +1,24 @@
1
+ export class Assets {
2
+ constructor(assetsMap) {
3
+ this.assetsMap = assetsMap;
4
+ }
5
+ serveAsset(event, pathPrefix = '') {
6
+ const { request } = event;
7
+ const { pathname } = new URL(request.url);
8
+ const asset = this.assetsMap[`${pathPrefix}${pathname}`];
9
+ if (!asset) {
10
+ return null;
11
+ }
12
+ // Aggressive caching for static files, and no caching for everything else.
13
+ const headers = {
14
+ 'Cache-Control': asset.isStatic ? 'max-age=31536000' : 'no-cache',
15
+ };
16
+ if (asset.contentType != null) {
17
+ headers['Content-Type'] = asset.contentType;
18
+ }
19
+ return new Response(asset.content, {
20
+ status: 200,
21
+ headers,
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,3 @@
1
+ import commandLineArgs from "command-line-args";
2
+ export declare function buildStaticLoader(commandLineValues: commandLineArgs.CommandLineOptions): Promise<void>;
3
+ //# sourceMappingURL=build-static.d.ts.map
@@ -0,0 +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"}
@@ -71,9 +71,6 @@ export async function buildStaticLoader(commandLineValues) {
71
71
  const defaultContentTypes = await import(defaultContentTypesJsSrcPath);
72
72
  // Load content types
73
73
  const finalContentTypes = defaultContentTypes.mergeContentTypes((_c = config.contentTypes) !== null && _c !== void 0 ? _c : []);
74
- // Update the target file too, so webpack can see it.
75
- const defaultContentTypesJsPath = path.resolve('./default-content-types.cjs');
76
- fs.copyFileSync(defaultContentTypesJsSrcPath, defaultContentTypesJsPath);
77
74
  const DEFAULT_INCLUDE_DIRS = [
78
75
  './.well-known'
79
76
  ];
package/build/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/build/cli.js ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ import commandLineArgs from "command-line-args";
3
+ import { initApp } from "./init-app.js";
4
+ import { buildStaticLoader } from "./build-static.js";
5
+ const optionDefinitions = [
6
+ // (optional) Should be one of:
7
+ // - cra (or create-react-app)
8
+ // - vite
9
+ // - sveltekit
10
+ // - next
11
+ // - gatsby
12
+ // - docusaurus
13
+ { name: 'preset', type: String, },
14
+ { name: 'build-static', type: Boolean },
15
+ { name: 'suppress-framework-warnings', type: Boolean },
16
+ { name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
17
+ { name: 'public-dir', type: String, },
18
+ { name: 'static-dir', type: String, },
19
+ // List of files to automatically use as index, for example, index.html,index.htm
20
+ // If a request comes in but the route does not exist, we check the route
21
+ // plus a slash plus the items in this array.
22
+ {
23
+ name: 'auto-index',
24
+ type: (val) => {
25
+ if (val == null) {
26
+ return null;
27
+ }
28
+ const values = val
29
+ .split(',')
30
+ .map(x => x.trim())
31
+ .filter(x => x !== '');
32
+ return values.length > 0 ? values : null;
33
+ },
34
+ },
35
+ // List of extensions to apply to a path name, for example, if
36
+ // http://example.com/about is requested, we can respond with http://example.com/about.html
37
+ {
38
+ name: 'auto-ext',
39
+ type: (val) => {
40
+ if (val == null) {
41
+ return null;
42
+ }
43
+ const values = val
44
+ .split(',')
45
+ .map(x => x.trim())
46
+ .map(x => {
47
+ while (x.startsWith('.')) {
48
+ x = x.slice(1);
49
+ }
50
+ return '.' + x;
51
+ })
52
+ .filter(x => x !== '');
53
+ return values.length > 0 ? values : null;
54
+ },
55
+ },
56
+ { name: 'spa', type: String, },
57
+ { name: 'not-found-page', type: String, },
58
+ { name: 'name', type: String, },
59
+ { name: 'author', type: String, },
60
+ { name: 'description', type: String, },
61
+ // Fastly Service ID to be added to the fastly.toml that is generated.
62
+ { name: 'service-id', type: String },
63
+ ];
64
+ const commandLineValues = commandLineArgs(optionDefinitions);
65
+ console.log("Fastly Compute@Edge JavaScript Static Publisher");
66
+ let mode = 'init-app';
67
+ if (commandLineValues['build-static']) {
68
+ mode = 'build-static';
69
+ }
70
+ switch (mode) {
71
+ case 'build-static':
72
+ await buildStaticLoader(commandLineValues);
73
+ break;
74
+ case 'init-app':
75
+ initApp(commandLineValues);
76
+ break;
77
+ }
@@ -0,0 +1,3 @@
1
+ export { Asset, AssetsMap } from './types.js';
2
+ export { StaticAssets } from './static-assets.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
package/build/index.js CHANGED
@@ -1,77 +1,2 @@
1
- #!/usr/bin/env node
2
- import commandLineArgs from "command-line-args";
3
- import { initApp } from "./init-app.js";
4
- import { buildStaticLoader } from "./build-static.js";
5
- const optionDefinitions = [
6
- // (optional) Should be one of:
7
- // - cra (or create-react-app)
8
- // - vite
9
- // - sveltekit
10
- // - next
11
- // - gatsby
12
- // - docusaurus
13
- { name: 'preset', type: String, },
14
- { name: 'build-static', type: Boolean },
15
- { name: 'suppress-framework-warnings', type: Boolean },
16
- { name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
17
- { name: 'public-dir', type: String, },
18
- { name: 'static-dir', type: String, },
19
- // List of files to automatically use as index, for example, index.html,index.htm
20
- // If a request comes in but the route does not exist, we check the route
21
- // plus a slash plus the items in this array.
22
- {
23
- name: 'auto-index',
24
- type: (val) => {
25
- if (val == null) {
26
- return null;
27
- }
28
- const values = val
29
- .split(',')
30
- .map(x => x.trim())
31
- .filter(x => x !== '');
32
- return values.length > 0 ? values : null;
33
- },
34
- },
35
- // List of extensions to apply to a path name, for example, if
36
- // http://example.com/about is requested, we can respond with http://example.com/about.html
37
- {
38
- name: 'auto-ext',
39
- type: (val) => {
40
- if (val == null) {
41
- return null;
42
- }
43
- const values = val
44
- .split(',')
45
- .map(x => x.trim())
46
- .map(x => {
47
- while (x.startsWith('.')) {
48
- x = x.slice(1);
49
- }
50
- return '.' + x;
51
- })
52
- .filter(x => x !== '');
53
- return values.length > 0 ? values : null;
54
- },
55
- },
56
- { name: 'spa', type: String, },
57
- { name: 'not-found-page', type: String, },
58
- { name: 'name', type: String, },
59
- { name: 'author', type: String, },
60
- { name: 'description', type: String, },
61
- // Fastly Service ID to be added to the fastly.toml that is generated.
62
- { name: 'service-id', type: String },
63
- ];
64
- const commandLineValues = commandLineArgs(optionDefinitions);
65
- console.log("Fastly Compute@Edge JavaScript Static Publisher");
66
- let mode = 'init-app';
67
- if (commandLineValues['build-static']) {
68
- mode = 'build-static';
69
- }
70
- switch (mode) {
71
- case 'build-static':
72
- await buildStaticLoader(commandLineValues);
73
- break;
74
- case 'init-app':
75
- initApp(commandLineValues);
76
- break;
77
- }
1
+ /// <reference types="@fastly/js-compute" />
2
+ export { StaticAssets } from './static-assets.js';
@@ -0,0 +1,3 @@
1
+ import { CommandLineOptions } from "command-line-args";
2
+ export declare function initApp(commandLineValues: CommandLineOptions): void;
3
+ //# sourceMappingURL=init-app.d.ts.map
@@ -0,0 +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,QAyR5D"}
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 != null ? spaRel : '(None)');
147
- console.log('404 Page :', notFoundRel != null ? notFoundRel : '(None)');
148
- console.log('Auto-Index :', autoIndex != null ? autoIndex : '(None)');
149
- console.log('Auto-Ext :', autoExt != null ? autoExt : '(None)');
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 && $(npm bin)/webpack && $(npm bin)/js-compute-runtime ./bin/index.js ./bin/main.wasm"
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");
@@ -0,0 +1,16 @@
1
+ import { IPresetBase } from '../preset-base.js';
2
+ export declare class CreateReactAppPreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: {
5
+ 'public-dir': string;
6
+ 'static-dir': string;
7
+ name: string;
8
+ description: string;
9
+ };
10
+ check(packageJson: any): boolean;
11
+ }
12
+ export declare class CreateReactAppEjectedPreset extends CreateReactAppPreset {
13
+ name: string;
14
+ check(): boolean;
15
+ }
16
+ //# sourceMappingURL=create-react-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-react-app.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/create-react-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,oBAAqB,YAAW,WAAW;IACtD,IAAI,SAAsB;IAC1B,cAAc;;;;;MAKZ;IAEF,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO;CAejC;AAED,qBAAa,2BAA4B,SAAQ,oBAAoB;IACnE,IAAI,SAAgC;IACpC,KAAK;CAGN"}
@@ -0,0 +1,11 @@
1
+ import { IPresetBase } from '../preset-base.js';
2
+ export declare class DocusaurusPreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: {
5
+ 'public-dir': string;
6
+ name: string;
7
+ description: string;
8
+ };
9
+ check(): boolean;
10
+ }
11
+ //# sourceMappingURL=docusaurus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docusaurus.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/docusaurus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,gBAAiB,YAAW,WAAW;IAClD,IAAI,SAAgB;IACpB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
@@ -0,0 +1,11 @@
1
+ import { IPresetBase } from '../preset-base.js';
2
+ export declare class GatsbyPreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: {
5
+ 'public-dir': string;
6
+ name: string;
7
+ description: string;
8
+ };
9
+ check(): boolean;
10
+ }
11
+ //# sourceMappingURL=gatsby.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gatsby.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/gatsby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,YAAa,YAAW,WAAW;IAC9C,IAAI,SAAY;IAChB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
@@ -0,0 +1,11 @@
1
+ import { IPresetBase } from '../preset-base.js';
2
+ export declare class NextJsPreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: {
5
+ 'public-dir': string;
6
+ name: string;
7
+ description: string;
8
+ };
9
+ check(): boolean;
10
+ }
11
+ //# sourceMappingURL=next.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,YAAa,YAAW,WAAW;IAC9C,IAAI,SAAa;IACjB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
@@ -0,0 +1,11 @@
1
+ import { IPresetBase } from '../preset-base.js';
2
+ export declare class SvelteKitPreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: {
5
+ 'public-dir': string;
6
+ name: string;
7
+ description: string;
8
+ };
9
+ check(): boolean;
10
+ }
11
+ //# sourceMappingURL=sveltekit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sveltekit.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/sveltekit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,eAAgB,YAAW,WAAW;IACjD,IAAI,SAAe;IACnB,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
@@ -0,0 +1,11 @@
1
+ import { IPresetBase } from '../preset-base.js';
2
+ export declare class VitePreset implements IPresetBase {
3
+ name: string;
4
+ defaultOptions: {
5
+ 'public-dir': string;
6
+ name: string;
7
+ description: string;
8
+ };
9
+ check(): boolean;
10
+ }
11
+ //# sourceMappingURL=vite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../src/presets/implementations/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBAAa,UAAW,YAAW,WAAW;IAC5C,IAAI,SAAU;IACd,cAAc;;;;MAIZ;IACF,KAAK;CAGN"}
@@ -0,0 +1,3 @@
1
+ import { IPresetBase } from './preset-base.js';
2
+ export declare const presets: Record<string, new () => IPresetBase>;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/presets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAQ/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAS,WAAW,CASxD,CAAC"}
@@ -0,0 +1,18 @@
1
+ export declare type AppOptions = {
2
+ 'public-dir': string | undefined;
3
+ 'static-dir': string | undefined;
4
+ spa: string | null | undefined;
5
+ 'not-found-page': string | null | undefined;
6
+ 'auto-index': string[] | null | undefined;
7
+ 'auto-ext': string[] | null | undefined;
8
+ name: string;
9
+ author: string;
10
+ description: string;
11
+ 'service-id': string | undefined;
12
+ };
13
+ export interface IPresetBase {
14
+ name: string;
15
+ defaultOptions: Partial<AppOptions>;
16
+ check(packageJson: any | null, options: AppOptions): boolean;
17
+ }
18
+ //# sourceMappingURL=preset-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-base.d.ts","sourceRoot":"","sources":["../../src/presets/preset-base.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG;IACvB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACpC,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC;CAC9D"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="@fastly/js-compute" />
2
+ import { AssetsMap } from "./types.js";
3
+ export declare class StaticAssets {
4
+ readonly assetsMap: AssetsMap;
5
+ constructor(assetsMap: AssetsMap);
6
+ serveAsset(event: FetchEvent, pathPrefix?: string): Response | null;
7
+ }
8
+ //# sourceMappingURL=static-assets.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,24 @@
1
+ export class StaticAssets {
2
+ constructor(assetsMap) {
3
+ this.assetsMap = assetsMap;
4
+ }
5
+ serveAsset(event, pathPrefix = '') {
6
+ const { request } = event;
7
+ const { pathname } = new URL(request.url);
8
+ const asset = this.assetsMap[`${pathPrefix}${pathname}`];
9
+ if (!asset) {
10
+ return null;
11
+ }
12
+ // Aggressive caching for static files, and no caching for everything else.
13
+ const headers = {
14
+ 'Cache-Control': asset.isStatic ? 'max-age=31536000' : 'no-cache',
15
+ };
16
+ if (asset.contentType != null) {
17
+ headers['Content-Type'] = asset.contentType;
18
+ }
19
+ return new Response(asset.content, {
20
+ status: 200,
21
+ headers,
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ declare type TestFn = (name: string) => boolean;
3
+ export declare type ContentTypeDef = {
4
+ test: RegExp | TestFn;
5
+ type: string;
6
+ binary?: boolean;
7
+ };
8
+ export declare type ContentTypeMatch = {
9
+ type: string;
10
+ binary: boolean;
11
+ };
12
+ export declare type DefaultContentTypesModule = {
13
+ mergeContentTypes: (contentTypes: ContentTypeDef[]) => ContentTypeDef[];
14
+ testFileContentType: (contentTypes: ContentTypeDef[], file: string) => ContentTypeMatch;
15
+ };
16
+ export declare type Asset = {
17
+ contentType: string;
18
+ content: Buffer | string;
19
+ module: unknown | null;
20
+ isStatic: boolean;
21
+ };
22
+ export declare type AssetsMap = {
23
+ [filePath: string]: Asset;
24
+ };
25
+ export {};
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,MAAM,GAAG,MAAM,CAAC;IACzB,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"}
package/build/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "2.2.1",
4
+ "version": "2.3.0-alpha.0",
5
5
  "description": "Static Publisher for Compute@Edge JavaScript",
6
6
  "main": "./build/index.js",
7
+ "types": "./build/index.d.ts",
7
8
  "scripts": {
8
9
  "prepack": "npm run build",
9
10
  "build": "tsc",
10
11
  "test": "echo \"Error: no test specified\" && exit 1"
11
12
  },
12
13
  "bin": {
13
- "compute-js-static-publish": "./build/index.js",
14
- "compute-js-build-static-loader": "./build/build-static.js"
14
+ "compute-js-static-publish": "./build/cli.js"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -30,6 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/fastly/compute-js-static-publish#readme",
32
32
  "dependencies": {
33
+ "@fastly/js-compute": "^0.5.4",
33
34
  "command-line-args": "^5.2.1"
34
35
  },
35
36
  "devDependencies": {
@@ -39,5 +40,13 @@
39
40
  },
40
41
  "engines": {
41
42
  "node": ">=14.8"
42
- }
43
+ },
44
+ "files": [
45
+ "build",
46
+ "resources",
47
+ "LICENSE",
48
+ "package.json",
49
+ "README.md",
50
+ "SECURITY.md"
51
+ ]
43
52
  }
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="JAVA_MODULE" version="4">
3
- <component name="Go" enabled="true" />
4
- <component name="NewModuleRootManager" inherit-compiler-output="true">
5
- <exclude-output />
6
- <content url="file://$MODULE_DIR$">
7
- <excludeFolder url="file://$MODULE_DIR$/build" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
@@ -1,6 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="ES6PreferShortImport" enabled="false" level="WARNING" enabled_by_default="false" />
5
- </profile>
6
- </component>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptLibraryMappings">
4
- <file url="file://$PROJECT_DIR$" libraries="{Node.js Core}" />
5
- </component>
6
- </project>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager">
4
- <output url="file://$PROJECT_DIR$/out" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/compute-js-static-publish.iml" filepath="$PROJECT_DIR$/.idea/compute-js-static-publish.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>