@fastly/compute-js-static-publish 3.6.0 → 4.0.0-alpha.1

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 (197) hide show
  1. package/README.md +441 -103
  2. package/build/assets/asset-manager.d.ts +7 -0
  3. package/build/assets/asset-manager.d.ts.map +1 -0
  4. package/build/assets/asset-manager.js +11 -0
  5. package/build/assets/content-assets.d.ts +29 -0
  6. package/build/assets/content-assets.d.ts.map +1 -0
  7. package/build/assets/content-assets.js +88 -0
  8. package/build/assets/module-assets.d.ts +23 -0
  9. package/build/assets/module-assets.d.ts.map +1 -0
  10. package/build/assets/module-assets.js +45 -0
  11. package/build/cli/build-static.d.ts.map +1 -0
  12. package/build/cli/build-static.js +524 -0
  13. package/build/cli/clean-object-store.d.ts +2 -0
  14. package/build/cli/clean-object-store.d.ts.map +1 -0
  15. package/build/cli/cli.d.ts.map +1 -0
  16. package/build/{cli.js → cli/cli.js} +0 -0
  17. package/build/cli/commands/build-static.d.ts +3 -0
  18. package/build/cli/commands/build-static.d.ts.map +1 -0
  19. package/build/cli/commands/build-static.js +502 -0
  20. package/build/cli/commands/clean-object-store.d.ts +3 -0
  21. package/build/cli/commands/clean-object-store.d.ts.map +1 -0
  22. package/build/cli/commands/clean-object-store.js +54 -0
  23. package/build/cli/commands/init-app.d.ts.map +1 -0
  24. package/build/cli/commands/init-app.js +559 -0
  25. package/build/cli/compression/brotli.d.ts +3 -0
  26. package/build/cli/compression/brotli.d.ts.map +1 -0
  27. package/build/cli/compression/brotli.js +15 -0
  28. package/build/cli/compression/gzip.d.ts +3 -0
  29. package/build/cli/compression/gzip.d.ts.map +1 -0
  30. package/build/cli/compression/gzip.js +15 -0
  31. package/build/cli/compression/index.d.ts +8 -0
  32. package/build/cli/compression/index.d.ts.map +1 -0
  33. package/build/cli/compression/index.js +12 -0
  34. package/build/cli/index.d.ts +3 -0
  35. package/build/cli/index.d.ts.map +1 -0
  36. package/build/cli/index.js +86 -0
  37. package/build/cli/init-app.d.ts +3 -0
  38. package/build/cli/init-app.d.ts.map +1 -0
  39. package/build/{init-app.js → cli/init-app.js} +16 -16
  40. package/build/cli/load-config.d.ts +3 -0
  41. package/build/cli/load-config.d.ts.map +1 -0
  42. package/build/cli/load-config.js +357 -0
  43. package/build/cli/presets/implementations/create-react-app.d.ts +11 -0
  44. package/build/cli/presets/implementations/create-react-app.d.ts.map +1 -0
  45. package/build/cli/presets/implementations/create-react-app.js +34 -0
  46. package/build/cli/presets/implementations/docusaurus.d.ts +7 -0
  47. package/build/cli/presets/implementations/docusaurus.d.ts.map +1 -0
  48. package/build/cli/presets/implementations/docusaurus.js +13 -0
  49. package/build/cli/presets/implementations/gatsby.d.ts +7 -0
  50. package/build/cli/presets/implementations/gatsby.d.ts.map +1 -0
  51. package/build/cli/presets/implementations/gatsby.js +13 -0
  52. package/build/cli/presets/implementations/next.d.ts +7 -0
  53. package/build/cli/presets/implementations/next.d.ts.map +1 -0
  54. package/build/cli/presets/implementations/next.js +13 -0
  55. package/build/cli/presets/implementations/sveltekit.d.ts +7 -0
  56. package/build/cli/presets/implementations/sveltekit.d.ts.map +1 -0
  57. package/build/cli/presets/implementations/sveltekit.js +13 -0
  58. package/build/cli/presets/implementations/vite.d.ts +7 -0
  59. package/build/cli/presets/implementations/vite.d.ts.map +1 -0
  60. package/build/cli/presets/implementations/vite.js +13 -0
  61. package/build/cli/presets/index.d.ts +3 -0
  62. package/build/cli/presets/index.d.ts.map +1 -0
  63. package/build/cli/presets/index.js +16 -0
  64. package/build/cli/presets/preset-base.d.ts +19 -0
  65. package/build/cli/presets/preset-base.d.ts.map +1 -0
  66. package/build/cli/util/data.d.ts +7 -0
  67. package/build/cli/util/data.d.ts.map +1 -0
  68. package/build/cli/util/data.js +58 -0
  69. package/build/cli/util/fastly-api.d.ts +10 -0
  70. package/build/cli/util/fastly-api.d.ts.map +1 -0
  71. package/build/cli/util/fastly-api.js +47 -0
  72. package/build/cli/util/files.d.ts +11 -0
  73. package/build/cli/util/files.d.ts.map +1 -0
  74. package/build/cli/util/files.js +33 -0
  75. package/build/cli/util/hash.d.ts +5 -0
  76. package/build/cli/util/hash.d.ts.map +1 -0
  77. package/build/cli/util/hash.js +9 -0
  78. package/build/cli/util/id.d.ts +3 -0
  79. package/build/cli/util/id.d.ts.map +1 -0
  80. package/build/cli/util/id.js +17 -0
  81. package/build/cli/util/object-store.d.ts +16 -0
  82. package/build/cli/util/object-store.d.ts.map +1 -0
  83. package/build/cli/util/object-store.js +108 -0
  84. package/build/cli/util/publish-id.d.ts +5 -0
  85. package/build/cli/util/publish-id.d.ts.map +1 -0
  86. package/build/cli/util/publish-id.js +26 -0
  87. package/build/constants/compression.d.ts +3 -0
  88. package/build/constants/compression.d.ts.map +1 -0
  89. package/build/constants/compression.js +4 -0
  90. package/build/index.d.ts +5 -2
  91. package/build/index.d.ts.map +1 -1
  92. package/build/index.js +5 -1
  93. package/build/presets/implementations/create-react-app.js +1 -2
  94. package/build/presets/preset-base.d.ts +1 -1
  95. package/build/presets/preset-base.d.ts.map +1 -1
  96. package/build/server/assets/asset-manager.d.ts +7 -0
  97. package/build/server/assets/asset-manager.d.ts.map +1 -0
  98. package/build/server/assets/asset-manager.js +11 -0
  99. package/build/server/assets/content-assets.d.ts +33 -0
  100. package/build/server/assets/content-assets.d.ts.map +1 -0
  101. package/build/server/assets/content-assets.js +142 -0
  102. package/build/server/assets/module-assets.d.ts +23 -0
  103. package/build/server/assets/module-assets.d.ts.map +1 -0
  104. package/build/server/assets/module-assets.js +45 -0
  105. package/build/server/object-store/include-bytes-store-entry.d.ts +19 -0
  106. package/build/server/object-store/include-bytes-store-entry.d.ts.map +1 -0
  107. package/build/server/object-store/include-bytes-store-entry.js +87 -0
  108. package/build/server/object-store/inline-store-entry.d.ts +25 -0
  109. package/build/server/object-store/inline-store-entry.d.ts.map +1 -0
  110. package/build/server/object-store/inline-store-entry.js +99 -0
  111. package/build/server/publisher-server.d.ts +23 -0
  112. package/build/server/publisher-server.d.ts.map +1 -0
  113. package/build/server/publisher-server.js +257 -0
  114. package/build/server/serve-preconditions/if-modified-since.d.ts +4 -0
  115. package/build/server/serve-preconditions/if-modified-since.d.ts.map +1 -0
  116. package/build/server/serve-preconditions/if-modified-since.js +26 -0
  117. package/build/server/serve-preconditions/if-none-match.d.ts +3 -0
  118. package/build/server/serve-preconditions/if-none-match.d.ts.map +1 -0
  119. package/build/server/serve-preconditions/if-none-match.js +24 -0
  120. package/build/server/util/http.d.ts +2 -0
  121. package/build/server/util/http.d.ts.map +1 -0
  122. package/build/server/util/http.js +9 -0
  123. package/build/types/compute.d.ts +11 -0
  124. package/build/types/compute.d.ts.map +1 -0
  125. package/build/types/compute.js +1 -0
  126. package/build/types/config-normalized.d.ts +33 -0
  127. package/build/types/config-normalized.d.ts.map +1 -0
  128. package/build/types/config-normalized.js +1 -0
  129. package/build/types/config.d.ts +36 -0
  130. package/build/types/config.d.ts.map +1 -0
  131. package/build/types/config.js +1 -0
  132. package/build/types/content-assets.d.ts +38 -0
  133. package/build/types/content-assets.d.ts.map +1 -0
  134. package/build/types/content-assets.js +1 -0
  135. package/build/types/content-types.d.ts +11 -0
  136. package/build/types/content-types.d.ts.map +1 -0
  137. package/build/types/content-types.js +1 -0
  138. package/build/types/index.d.ts +7 -0
  139. package/build/types/index.d.ts.map +1 -0
  140. package/build/types/index.js +1 -0
  141. package/build/types/module-assets.d.ts +15 -0
  142. package/build/types/module-assets.d.ts.map +1 -0
  143. package/build/types/module-assets.js +1 -0
  144. package/build/types/util.d.ts +7 -0
  145. package/build/types/util.d.ts.map +1 -0
  146. package/build/types/util.js +1 -0
  147. package/build/util/content-types.d.ts +5 -0
  148. package/build/util/content-types.d.ts.map +1 -0
  149. package/build/util/content-types.js +92 -0
  150. package/build/util/data.d.ts +7 -0
  151. package/build/util/data.d.ts.map +1 -0
  152. package/build/util/data.js +58 -0
  153. package/build/util/fastly-api.d.ts +10 -0
  154. package/build/util/fastly-api.d.ts.map +1 -0
  155. package/build/util/fastly-api.js +47 -0
  156. package/build/util/files.d.ts +10 -0
  157. package/build/util/files.d.ts.map +1 -0
  158. package/build/util/files.js +32 -0
  159. package/build/util/hash.d.ts +2 -0
  160. package/build/util/hash.d.ts.map +1 -0
  161. package/build/util/hash.js +8 -0
  162. package/build/util/id.d.ts +3 -0
  163. package/build/util/id.d.ts.map +1 -0
  164. package/build/util/id.js +17 -0
  165. package/build/util/index.d.ts +3 -0
  166. package/build/util/index.d.ts.map +1 -0
  167. package/build/util/index.js +2 -0
  168. package/build/util/metadata.d.ts +3 -0
  169. package/build/util/metadata.d.ts.map +1 -0
  170. package/build/util/metadata.js +12 -0
  171. package/build/util/object-store.d.ts +12 -0
  172. package/build/util/object-store.d.ts.map +1 -0
  173. package/build/util/object-store.js +80 -0
  174. package/package.json +9 -5
  175. package/resources/index.js +9 -114
  176. package/resources/statics-metadata.d.ts +10 -0
  177. package/resources/statics.d.ts +15 -7
  178. package/resources/webpack.config.js +4 -10
  179. package/build/assets.d.ts +0 -8
  180. package/build/assets.d.ts.map +0 -1
  181. package/build/assets.js +0 -24
  182. package/build/build-static.d.ts.map +0 -1
  183. package/build/build-static.js +0 -249
  184. package/build/cli.d.ts.map +0 -1
  185. package/build/init-app.d.ts.map +0 -1
  186. package/build/static-assets.d.ts +0 -11
  187. package/build/static-assets.d.ts.map +0 -1
  188. package/build/static-assets.js +0 -33
  189. package/build/types.d.ts +0 -50
  190. package/build/types.d.ts.map +0 -1
  191. package/resources/default-content-types.cjs +0 -106
  192. package/resources/default-content-types.d.ts +0 -15
  193. /package/build/{build-static.d.ts → cli/build-static.d.ts} +0 -0
  194. /package/build/{content-types.js → cli/clean-object-store.js} +0 -0
  195. /package/build/{cli.d.ts → cli/cli.d.ts} +0 -0
  196. /package/build/{init-app.d.ts → cli/commands/init-app.d.ts} +0 -0
  197. /package/build/{types.js → cli/presets/preset-base.js} +0 -0
@@ -2,10 +2,18 @@
2
2
  * Generated by @fastly/compute-js-static-publish.
3
3
  */
4
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;
5
+ import type {
6
+ ModuleAssetMap,
7
+ PublisherServerConfigNormalized,
8
+ ContentAssets,
9
+ ModuleAssets,
10
+ PublisherServer,
11
+ } from '@fastly/compute-js-static-publish';
12
+
13
+ export declare const moduleAssetMap: ModuleAssetMap;
14
+
15
+ export declare const serverConfig: PublisherServerConfigNormalized;
16
+ export declare const contentAssets: ContentAssets;
17
+ export declare const moduleAssets: ModuleAssets;
18
+
19
+ export declare function getServer(): PublisherServer;
@@ -12,16 +12,10 @@ module.exports = {
12
12
  libraryTarget: "this",
13
13
  },
14
14
  module: {
15
- // Asset modules are modules that allow the use asset files (fonts, icons, etc)
16
- // without additional configuration or dependencies.
17
- rules: [
18
- // asset/source exports the source code of the asset.
19
- // Usage: e.g., import notFoundPage from "./page_404.html"
20
- {
21
- test: /\.(txt|html)/,
22
- type: "asset/source",
23
- },
24
- ],
15
+ // Loaders go here.
16
+ // e.g., ts-loader for TypeScript
17
+ // rules: [
18
+ // ],
25
19
  },
26
20
  plugins: [
27
21
  // Polyfills go here.
package/build/assets.d.ts DELETED
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
package/build/assets.js DELETED
@@ -1,24 +0,0 @@
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
- }
@@ -1 +0,0 @@
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,iBA8P5F"}
@@ -1,249 +0,0 @@
1
- // This program builds static resources out of the files in the
2
- // public folder to be served. It reads the name of the public
3
- // folder from the static-publish.rc.js file.
4
- // With create-react-app, this would be the ./build directory.
5
- // This also reexports the "spa" value in the static-publish.rc.js
6
- // file so that the C@E handler knows what file to serve up if
7
- // the resource doesn't map to a file.
8
- import * as fs from "fs";
9
- import * as path from "path";
10
- import * as url from "url";
11
- function getFiles(results, dir) {
12
- const entries = fs.readdirSync(dir, { withFileTypes: true });
13
- for (const entry of entries) {
14
- const name = path.resolve(dir, entry.name);
15
- if (entry.isDirectory()) {
16
- getFiles(results, name);
17
- }
18
- else {
19
- results.push(name);
20
- }
21
- }
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
- }
32
- export async function buildStaticLoader(commandLineValues) {
33
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
34
- const { 'suppress-framework-warnings': suppressFrameworkWarnings } = commandLineValues;
35
- const displayFrameworkWarnings = !suppressFrameworkWarnings;
36
- console.log("🚀 Building loader...");
37
- let config;
38
- try {
39
- const staticPublishRcPath = path.resolve('./static-publish.rc.js');
40
- config = (await import(staticPublishRcPath)).default;
41
- }
42
- catch (ex) {
43
- console.error("❌ Can't load static-publish.rc.js");
44
- console.error("Run this from a compute-js-static-publish compute-js directory.");
45
- console.error("Error: ", String(ex));
46
- process.exitCode = 1;
47
- return;
48
- }
49
- const outputDir = path.resolve();
50
- const publicDirRoot = path.resolve((_a = config.publicDir) !== null && _a !== void 0 ? _a : './');
51
- const results = [];
52
- getFiles(results, publicDirRoot);
53
- console.log(`✔️ Public directory '${publicDirRoot}'.`);
54
- const staticDirs = (_b = config.staticDirs) !== null && _b !== void 0 ? _b : [];
55
- if (staticDirs.length > 0) {
56
- console.log(`✔️ Using static directories: ${staticDirs.join(', ')}`);
57
- }
58
- else {
59
- if (displayFrameworkWarnings) {
60
- console.log(`✔️ No static directories defined.`);
61
- }
62
- }
63
- const staticRoots = staticDirs.map(dir => path.resolve(publicDirRoot, dir));
64
- const DEFAULT_EXCLUDE_DIRS = [
65
- './node_modules'
66
- ];
67
- const excludeDirs = (_c = config.excludeDirs) !== null && _c !== void 0 ? _c : DEFAULT_EXCLUDE_DIRS;
68
- if (excludeDirs.length > 0) {
69
- console.log(`✔️ Using exclude directories: ${excludeDirs.join(', ')}`);
70
- }
71
- else {
72
- if (displayFrameworkWarnings) {
73
- console.log(`✔️ No exclude directories defined.`);
74
- }
75
- }
76
- const excludeRoots = excludeDirs.map(dir => path.resolve(publicDirRoot, dir));
77
- const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
78
- // Load defaultContentTypes module
79
- const defaultContentTypesJsSrcPath = path.resolve(__dirname, '../resources/default-content-types.cjs');
80
- const defaultContentTypes = await import(defaultContentTypesJsSrcPath);
81
- // Load content types
82
- const finalContentTypes = defaultContentTypes.mergeContentTypes((_d = config.contentTypes) !== null && _d !== void 0 ? _d : []);
83
- const DEFAULT_INCLUDE_DIRS = [
84
- './.well-known'
85
- ];
86
- const includeDirs = (_e = config.includeDirs) !== null && _e !== void 0 ? _e : DEFAULT_INCLUDE_DIRS;
87
- if (includeDirs.length > 0) {
88
- console.log(`✔️ Using include directories: ${includeDirs.join(', ')}`);
89
- }
90
- else {
91
- if (displayFrameworkWarnings) {
92
- console.log(`✔️ No include directories defined.`);
93
- }
94
- }
95
- const includeRoots = includeDirs.map(dir => path.resolve(publicDirRoot, dir));
96
- const excludeTest = (_f = config.excludeTest) !== null && _f !== void 0 ? _f : null;
97
- const files = results
98
- .filter(file => {
99
- // Exclude files that come from C@E app dir
100
- if (outputDir != publicDirRoot && file.startsWith(outputDir)) {
101
- return false;
102
- }
103
- // Include files that come from "included roots" dir
104
- if (includeRoots.some(root => file.startsWith(root))) {
105
- return true;
106
- }
107
- // Exclude files that are in directories that start with "."
108
- if (file.indexOf('/.') !== -1) {
109
- return false;
110
- }
111
- // Exclude files that come from "excluded roots" dir
112
- if (excludeRoots.some(root => file.startsWith(root))) {
113
- return false;
114
- }
115
- return true;
116
- })
117
- .filter(file => {
118
- return excludeTest == null || !excludeTest(file);
119
- });
120
- const moduleTest = (_g = config.moduleTest) !== null && _g !== void 0 ? _g : null;
121
- const knownAssets = {};
122
- // Create "static content" dir that will be used to hold a copy of static files
123
- // NOTE: this is needed because includeBytes doesn't seem to be able to traverse
124
- // up to parent dir of Compute project.
125
- const staticContentDir = './src/static-content';
126
- fs.rmSync(staticContentDir, { recursive: true, force: true });
127
- fs.mkdirSync(staticContentDir, { recursive: true });
128
- let fileContents = `/*
129
- * Generated by @fastly/compute-js-static-publish.
130
- */
131
-
132
- `;
133
- fileContents += 'import { includeBytes } from "fastly:experimental";\n';
134
- fileContents += 'import { StaticAssets } from "@fastly/compute-js-static-publish";\n';
135
- // If any files need to be loaded as modules, import them now.
136
- const loadAsModule = [];
137
- if (moduleTest != null) {
138
- for (const [index, file] of files.entries()) {
139
- const filePath = file.slice(publicDirRoot.length);
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
- }
147
- }
148
- }
149
- }
150
- fileContents += 'const textDecoder = new TextDecoder();\n';
151
- fileContents += `\nexport const assets = {\n`;
152
- for (const [index, file] of files.entries()) {
153
- const contentDef = defaultContentTypes.testFileContentType(finalContentTypes, file);
154
- const filePath = file.slice(publicDirRoot.length);
155
- const type = contentDef === null || contentDef === void 0 ? void 0 : contentDef.type;
156
- const isStatic = staticRoots.some(root => file.startsWith(root));
157
- knownAssets[filePath] = { contentType: type, };
158
- if (contentDef != null) {
159
- console.log('✔️ ' + filePath + ': ' + JSON.stringify(type) + (isStatic ? ' [STATIC]' : ''));
160
- }
161
- else {
162
- if (displayFrameworkWarnings) {
163
- console.log('⚠️ Notice: Unknown file type ' + filePath + '. Treating as binary file.');
164
- }
165
- }
166
- // Serve static files by copying them into the static content dir and using includeBytes()
167
- let staticFileExt, staticFileType;
168
- if (contentDef == null || contentDef.binary) {
169
- staticFileExt = '.bin';
170
- staticFileType = 'binary';
171
- }
172
- else {
173
- staticFileExt = '.txt';
174
- staticFileType = 'string';
175
- }
176
- const staticFilePath = `${staticContentDir}/file${index}${staticFileExt}`;
177
- fs.cpSync(file, staticFilePath);
178
- console.log(`✔️ Copied static ${staticFileType} file "${file}" to "${staticFilePath}".`);
179
- let content = `includeBytes("${staticFilePath}")`;
180
- if (staticFileType === 'string') {
181
- content = `textDecoder.decode(${content})`;
182
- }
183
- let module;
184
- if (loadAsModule[index] === 'static') {
185
- module = 'fileModule' + index;
186
- }
187
- else {
188
- module = 'null';
189
- }
190
- let loadModuleFunction;
191
- if (loadAsModule[index] === 'dynamic') {
192
- const relativeFilePath = path.relative('./src', file);
193
- loadModuleFunction = `() => import("${relativeFilePath}")`;
194
- }
195
- else {
196
- loadModuleFunction = 'null';
197
- }
198
- fileContents += ` ${JSON.stringify(filePath)}: { type: ${JSON.stringify(staticFileType)}, contentType: ${JSON.stringify(type)}, content: ${content}, module: ${module}, loadModule: ${loadModuleFunction}, isStatic: ${JSON.stringify(isStatic)} },\n`;
199
- }
200
- fileContents += '};\n';
201
- let spaFile = (_h = config.spa) !== null && _h !== void 0 ? _h : false;
202
- if (spaFile) {
203
- console.log(`✔️ Application SPA file '${spaFile}'.`);
204
- if (!knownAssets[spaFile] || knownAssets[spaFile].contentType !== 'text/html') {
205
- if (displayFrameworkWarnings) {
206
- console.log(`⚠️ Notice: '${spaFile}' does not exist or is not of type 'text/html'. Ignoring.`);
207
- }
208
- spaFile = false;
209
- }
210
- }
211
- else {
212
- if (displayFrameworkWarnings) {
213
- console.log(`✔️ Application is not a SPA.`);
214
- }
215
- }
216
- fileContents += `\nexport const spaFile = ${JSON.stringify(spaFile)};\n`;
217
- let notFoundPageFile = (_j = config.notFoundPage) !== null && _j !== void 0 ? _j : false;
218
- if (notFoundPageFile) {
219
- console.log(`✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
220
- if (!knownAssets[notFoundPageFile] || knownAssets[notFoundPageFile].contentType !== 'text/html') {
221
- if (displayFrameworkWarnings) {
222
- console.log(`⚠️ Notice: '${notFoundPageFile}' does not exist or is not of type 'text/html'. Ignoring.`);
223
- }
224
- notFoundPageFile = false;
225
- }
226
- }
227
- else {
228
- if (displayFrameworkWarnings) {
229
- console.log(`✔️ Application specifies no 'not found (404)' page.`);
230
- }
231
- }
232
- fileContents += `\nexport const notFoundPageFile = ${JSON.stringify(notFoundPageFile)};\n`;
233
- let autoIndex = (_k = config.autoIndex) !== null && _k !== void 0 ? _k : false;
234
- fileContents += `\nexport const autoIndex = ${JSON.stringify(autoIndex)};\n`;
235
- let autoExt = (_l = config.autoExt) !== null && _l !== void 0 ? _l : false;
236
- fileContents += `\nexport const autoExt = ${JSON.stringify(autoExt)};\n`;
237
- fileContents += '\nexport const staticAssets = new StaticAssets(assets);\n';
238
- fs.writeFileSync('./src/statics.js', fileContents);
239
- console.log("✅ Wrote static file loader for " + files.length + " file(s).");
240
- // Copy Types file for static file loader
241
- try {
242
- const staticsTypeFile = path.resolve(__dirname, '../resources/statics.d.ts');
243
- fs.copyFileSync(staticsTypeFile, './src/statics.d.ts');
244
- console.log("✅ Wrote static file loader types file statics.d.ts.");
245
- }
246
- catch (_m) {
247
- console.log("⚠️ Notice: could not wrote static file loader types file statics.d.ts.");
248
- }
249
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
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,QA+R5D"}
@@ -1,11 +0,0 @@
1
- /// <reference types="@fastly/js-compute" />
2
- import { Asset, AssetsMap } from "./types.js";
3
- export declare class StaticAssets {
4
- readonly assetsMap: AssetsMap;
5
- constructor(assetsMap: AssetsMap);
6
- getAsset(key: string): Asset;
7
- get assets(): AssetsMap;
8
- serveAsset(asset: Asset): Response;
9
- serveAssetForEvent(event: FetchEvent, pathPrefix?: string): Response | null;
10
- }
11
- //# sourceMappingURL=static-assets.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,33 +0,0 @@
1
- export class StaticAssets {
2
- constructor(assetsMap) {
3
- this.assetsMap = assetsMap;
4
- }
5
- getAsset(key) {
6
- return this.assetsMap[key];
7
- }
8
- get assets() {
9
- return this.assetsMap;
10
- }
11
- serveAsset(asset) {
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
- serveAssetForEvent(event, pathPrefix = '') {
25
- const { request } = event;
26
- const { pathname } = new URL(request.url);
27
- const asset = this.getAsset(`${pathPrefix}${pathname}`);
28
- if (!asset) {
29
- return null;
30
- }
31
- return this.serveAsset(asset);
32
- }
33
- }
package/build/types.d.ts DELETED
@@ -1,50 +0,0 @@
1
- declare type TestFn = (name: string) => boolean;
2
- export declare type ContentTypeDef = {
3
- test: RegExp | TestFn;
4
- type: string;
5
- binary?: boolean;
6
- };
7
- export declare type ContentTypeMatch = {
8
- type: string;
9
- binary: boolean;
10
- };
11
- export declare type DefaultContentTypesModule = {
12
- mergeContentTypes: (contentTypes: ContentTypeDef[]) => ContentTypeDef[];
13
- testFileContentType: (contentTypes: ContentTypeDef[], file: string) => ContentTypeMatch;
14
- };
15
- export declare type AssetBase = {
16
- contentType: string;
17
- module: any | null;
18
- loadModule: (() => Promise<any>) | null;
19
- isStatic: boolean;
20
- };
21
- export declare type StringAsset = AssetBase & {
22
- type: 'string';
23
- content: string;
24
- };
25
- export declare type BinaryAsset = AssetBase & {
26
- type: 'binary';
27
- content: Uint8Array;
28
- };
29
- export declare type Asset = StringAsset | BinaryAsset;
30
- export declare type AssetsMap = {
31
- [filePath: string]: Asset;
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;
36
- export declare type Config = {
37
- publicDir: string;
38
- excludeDirs?: string[] | null;
39
- includeDirs?: string[] | null;
40
- staticDirs?: string[] | null;
41
- excludeTest?: ((path: string) => boolean) | null;
42
- moduleTest?: ModuleTestFunction;
43
- spa?: string | null;
44
- autoIndex?: string[] | false | null;
45
- autoExt?: string[] | false | null;
46
- notFoundPage?: string | false | null;
47
- contentTypes?: ContentTypeDef[] | null;
48
- };
49
- export {};
50
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
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,UAAU,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IACxC,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;IACpC,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AACF,oBAAY,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC;AAE9C,oBAAY,SAAS,GAAG;IACtB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;CAC3B,CAAC;AAEF,oBAAY,cAAc,GAAG,QAAQ,GAAG,SAAS,CAAC;AAClD,oBAAY,gBAAgB,GAAG,cAAc,GAAG,KAAK,CAAC;AACtD,oBAAY,kBAAkB,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,gBAAgB,CAAC,GAAG,IAAI,CAAC;AAEpF,oBAAY,MAAM,GAAG;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,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"}
@@ -1,106 +0,0 @@
1
- const defaultContentTypes = [
2
- // Text formats
3
- { test: /.txt$/, type: 'text/plain', binary: false },
4
- { test: /.htm(l)?$/, type: 'text/html', binary: false },
5
- { test: /.xml$/, type: 'application/xml', binary: false },
6
- { test: /.json$/, type: 'application/json', binary: false },
7
- { test: /.map$/, type: 'application/json', binary: false },
8
- { test: /.js$/, type: 'application/javascript', binary: false },
9
- { test: /.css$/, type: 'text/css', binary: false },
10
- { test: /.svg$/, type: 'image/svg+xml', binary: false },
11
-
12
- // Binary formats
13
- { test: /.bmp$/, type: 'image/bmp', binary: true },
14
- { test: /.png$/, type: 'image/png', binary: true },
15
- { test: /.gif$/, type: 'image/gif', binary: true },
16
- { test: /.jp(e)?g$/, type: 'image/jpeg', binary: true },
17
- { test: /.ico$/, type: 'image/vnd.microsoft.icon', binary: true },
18
- { test: /.tif(f)?$/, type: 'image/png', binary: true },
19
- { test: /.aac$/, type: 'audio/aac', binary: true },
20
- { test: /.mp3$/, type: 'audio/mpeg', binary: true },
21
- { test: /.avi$/, type: 'video/x-msvideo', binary: true },
22
- { test: /.mp4$/, type: 'video/mp4', binary: true },
23
- { test: /.mpeg$/, type: 'video/mpeg', binary: true },
24
- { test: /.webm$/, type: 'video/webm', binary: true },
25
- { test: /.pdf$/, type: 'application/pdf', binary: true },
26
- { test: /.tar$/, type: 'application/x-tar', binary: true },
27
- { test: /.zip$/, type: 'application/zip', binary: true },
28
- { test: /.eot$/, type: 'application/vnd.ms-fontobject', binary: true },
29
- { test: /.otf$/, type: 'font/otf', binary: true },
30
- { test: /.ttf$/, type: 'font/ttf', binary: true },
31
- { test: /.woff$/, type: 'font/woff', binary: true },
32
- { test: /.woff2$/, type: 'font/woff2', binary: true },
33
- ];
34
-
35
- function mergeContentTypes(contentTypes) {
36
-
37
- const finalContentTypes = [];
38
-
39
- if(!Array.isArray(contentTypes)) {
40
- console.warn('contentTypes not an array, ignoring.');
41
- } else {
42
-
43
- for (const [index, contentType] of contentTypes.entries()) {
44
- let invalid = false;
45
-
46
- if(
47
- typeof contentType.test !== 'function' &&
48
- !(contentType.test instanceof RegExp)
49
- ) {
50
- console.log(`⚠️ Ignoring contentTypes[${index}]: 'test' must be a function or regular expression.`);
51
- invalid = true;
52
- }
53
-
54
- if(typeof contentType.type !== 'string' || contentType.type.indexOf('/') === -1) {
55
- console.log(`⚠️ Ignoring contentTypes[${index}]: 'type' must be a string representing a MIME type.`);
56
- invalid = true;
57
- }
58
-
59
- if('binary' in contentType && typeof contentType.binary !== 'boolean') {
60
- console.log(`⚠️ Ignoring contentTypes[${index}]: optional 'binary' must be a boolean value.`);
61
- invalid = true;
62
- }
63
-
64
- if(!invalid) {
65
- const contentTypeDef = {
66
- test: contentType.test,
67
- type: contentType.type,
68
- };
69
- if(contentType.binary != null) {
70
- contentTypeDef.binary = contentType.binary;
71
- }
72
- finalContentTypes.push(contentTypeDef);
73
- }
74
- }
75
- }
76
-
77
- console.log('✔️ Applying ' + finalContentTypes.length + ' custom content type(s).');
78
-
79
- for (const contentType of defaultContentTypes) {
80
- finalContentTypes.push(contentType);
81
- }
82
-
83
- return finalContentTypes;
84
- }
85
-
86
- function testFileContentType(contentTypes, file) {
87
- for (const contentType of contentTypes ?? defaultContentTypes) {
88
- let matched = false;
89
- if(contentType.test instanceof RegExp) {
90
- matched = contentType.test.test(file);
91
- } else {
92
- // should be a function
93
- matched = contentType.test(file);
94
- }
95
- if(matched) {
96
- return { type: contentType.type, binary: Boolean(contentType.binary) };
97
- }
98
- }
99
- return null;
100
- }
101
-
102
- module.exports = {
103
- defaultContentTypes,
104
- mergeContentTypes,
105
- testFileContentType,
106
- };
@@ -1,15 +0,0 @@
1
- export type ContentTypeDef = {
2
- test: RegExp | ((path: string) => boolean),
3
- type: string,
4
- binary?: boolean,
5
- };
6
-
7
- export type ContentTypeTestResult = {
8
- type: string,
9
- binary: boolean,
10
- };
11
-
12
- declare const defaultContentTypes: ContentTypeDef[];
13
-
14
- declare function mergeContentTypes(entries?: ContentTypeDef[]): ContentTypeDef[];
15
- declare function testFileContentType(entries: ContentTypeDef[] | null | undefined, path: string): ContentTypeTestResult | null;
File without changes
File without changes