@fastly/compute-js-static-publish 8.0.0 → 8.1.0-beta.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 (251) hide show
  1. package/DOCUMENTATION.md +1984 -0
  2. package/README.md +11 -4
  3. package/README.short.md +11 -4
  4. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/clean.js +12 -7
  6. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/collections/delete.js +29 -13
  8. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/index.js +6 -1
  10. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/collections/list.js +47 -7
  12. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  13. package/build/cli/cli/commands/manage/collections/promote.js +67 -20
  14. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  15. package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -11
  16. package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
  17. package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
  18. package/build/cli/cli/commands/manage/deploy.js +194 -0
  19. package/build/cli/cli/commands/manage/dev.d.ts +2 -0
  20. package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
  21. package/build/cli/cli/commands/manage/dev.js +77 -0
  22. package/build/cli/cli/commands/manage/eject.d.ts +2 -0
  23. package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
  24. package/build/cli/cli/commands/manage/eject.js +155 -0
  25. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  26. package/build/cli/cli/commands/manage/index.js +37 -1
  27. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  28. package/build/cli/cli/commands/manage/publish-content.js +85 -35
  29. package/build/cli/cli/commands/manage/status.d.ts +2 -0
  30. package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
  31. package/build/cli/cli/commands/manage/status.js +162 -0
  32. package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
  33. package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
  34. package/build/cli/cli/commands/manage/template/index.js +42 -0
  35. package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
  36. package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
  37. package/build/cli/cli/commands/manage/template/init.js +172 -0
  38. package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
  39. package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
  40. package/build/cli/cli/commands/manage/upgrade.js +59 -0
  41. package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
  42. package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
  43. package/build/cli/cli/commands/run-dev-watch.js +41 -0
  44. package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
  45. package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
  46. package/build/cli/cli/commands/run-template-hook.js +28 -0
  47. package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
  48. package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
  49. package/build/cli/cli/commands/scaffold/app-template.js +54 -0
  50. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
  51. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
  52. package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
  53. package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
  54. package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
  55. package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
  56. package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
  57. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  58. package/build/cli/cli/commands/scaffold/index.js +239 -300
  59. package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
  60. package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
  61. package/build/cli/cli/commands/scaffold/render.js +72 -0
  62. package/build/cli/cli/hono/build.d.ts +43 -0
  63. package/build/cli/cli/hono/build.d.ts.map +1 -0
  64. package/build/cli/cli/hono/build.js +297 -0
  65. package/build/cli/cli/index.js +98 -5
  66. package/build/cli/cli/managed/app.d.ts +21 -0
  67. package/build/cli/cli/managed/app.d.ts.map +1 -0
  68. package/build/cli/cli/managed/app.js +162 -0
  69. package/build/cli/cli/managed/command-helpers.d.ts +6 -0
  70. package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
  71. package/build/cli/cli/managed/command-helpers.js +81 -0
  72. package/build/cli/cli/managed/eject.d.ts +6 -0
  73. package/build/cli/cli/managed/eject.d.ts.map +1 -0
  74. package/build/cli/cli/managed/eject.js +68 -0
  75. package/build/cli/cli/managed/fastly-service.d.ts +8 -0
  76. package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
  77. package/build/cli/cli/managed/fastly-service.js +21 -0
  78. package/build/cli/cli/managed/fingerprint.d.ts +13 -0
  79. package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
  80. package/build/cli/cli/managed/fingerprint.js +60 -0
  81. package/build/cli/cli/managed/lockfile.d.ts +31 -0
  82. package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
  83. package/build/cli/cli/managed/lockfile.js +62 -0
  84. package/build/cli/cli/managed/project-edit.d.ts +3 -0
  85. package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
  86. package/build/cli/cli/managed/project-edit.js +35 -0
  87. package/build/cli/cli/managed/project-file.d.ts +16 -0
  88. package/build/cli/cli/managed/project-file.d.ts.map +1 -0
  89. package/build/cli/cli/managed/project-file.js +119 -0
  90. package/build/cli/cli/managed/template-init.d.ts +12 -0
  91. package/build/cli/cli/managed/template-init.d.ts.map +1 -0
  92. package/build/cli/cli/managed/template-init.js +120 -0
  93. package/build/cli/cli/managed/version-check.d.ts +25 -0
  94. package/build/cli/cli/managed/version-check.d.ts.map +1 -0
  95. package/build/cli/cli/managed/version-check.js +84 -0
  96. package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
  97. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  98. package/build/cli/cli/storage/kv-store-local-provider.js +6 -3
  99. package/build/cli/cli/storage/kv-store-provider.d.ts +2 -1
  100. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  101. package/build/cli/cli/storage/kv-store-provider.js +17 -6
  102. package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
  103. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  104. package/build/cli/cli/storage/s3-storage-provider.js +8 -2
  105. package/build/cli/cli/storage/storage-provider.d.ts +4 -0
  106. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  107. package/build/cli/cli/storage/storage-provider.js +32 -0
  108. package/build/cli/cli/util/api-token.d.ts +2 -1
  109. package/build/cli/cli/util/api-token.d.ts.map +1 -1
  110. package/build/cli/cli/util/api-token.js +38 -3
  111. package/build/cli/cli/util/collection-name.d.ts +3 -0
  112. package/build/cli/cli/util/collection-name.d.ts.map +1 -0
  113. package/build/cli/cli/util/collection-name.js +24 -0
  114. package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
  115. package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
  116. package/build/cli/cli/util/collection-selection-flags.js +131 -0
  117. package/build/cli/cli/util/config.d.ts +13 -0
  118. package/build/cli/cli/util/config.d.ts.map +1 -1
  119. package/build/cli/cli/util/config.js +172 -38
  120. package/build/cli/cli/util/data.d.ts.map +1 -1
  121. package/build/cli/cli/util/global-options.d.ts +13 -0
  122. package/build/cli/cli/util/global-options.d.ts.map +1 -0
  123. package/build/cli/cli/util/global-options.js +53 -0
  124. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  125. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  126. package/build/cli/cli/util/kv-store-items.js +16 -40
  127. package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
  128. package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
  129. package/build/cli/cli/util/kv-store-local-server.js +4 -2
  130. package/build/cli/cli/util/output.d.ts +31 -0
  131. package/build/cli/cli/util/output.d.ts.map +1 -0
  132. package/build/cli/cli/util/output.js +139 -0
  133. package/build/cli/cli/util/package.d.ts +3 -0
  134. package/build/cli/cli/util/package.d.ts.map +1 -1
  135. package/build/cli/cli/util/package.js +12 -0
  136. package/build/cli/cli/util/progress.d.ts +11 -0
  137. package/build/cli/cli/util/progress.d.ts.map +1 -0
  138. package/build/cli/cli/util/progress.js +32 -0
  139. package/build/cli/cli/util/purge.d.ts +15 -3
  140. package/build/cli/cli/util/purge.d.ts.map +1 -1
  141. package/build/cli/cli/util/purge.js +23 -10
  142. package/build/cli/cli/util/resources.d.ts +2 -0
  143. package/build/cli/cli/util/resources.d.ts.map +1 -0
  144. package/build/cli/cli/util/resources.js +8 -0
  145. package/build/cli/cli/util/service-id.d.ts +1 -0
  146. package/build/cli/cli/util/service-id.d.ts.map +1 -1
  147. package/build/cli/cli/util/service-id.js +5 -1
  148. package/build/cli/cli/util/variants.d.ts.map +1 -1
  149. package/build/cli/models/assets/index.d.ts +6 -0
  150. package/build/cli/models/assets/index.d.ts.map +1 -1
  151. package/build/cli/models/assets/index.js +24 -0
  152. package/build/cli/models/collections/index.d.ts +3 -0
  153. package/build/cli/models/collections/index.d.ts.map +1 -0
  154. package/build/cli/models/collections/index.js +15 -0
  155. package/build/cli/models/compression/index.d.ts +1 -1
  156. package/build/cli/models/compression/index.d.ts.map +1 -1
  157. package/build/cli/models/config/collection-selection.d.ts +55 -0
  158. package/build/cli/models/config/collection-selection.d.ts.map +1 -0
  159. package/build/cli/models/config/collection-selection.js +238 -0
  160. package/build/cli/models/config/item-patterns.d.ts +4 -0
  161. package/build/cli/models/config/item-patterns.d.ts.map +1 -0
  162. package/build/cli/models/config/item-patterns.js +43 -0
  163. package/build/cli/models/config/publish-content-config.d.ts +6 -1
  164. package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
  165. package/build/cli/models/config/static-publish-project.d.ts +23 -0
  166. package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
  167. package/build/cli/models/config/static-publish-project.js +11 -0
  168. package/build/cli/models/config/static-publish-rc.d.ts +25 -0
  169. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
  170. package/build/cli/models/config/static-publish-rc.js +31 -0
  171. package/build/cli/models/config/template-settings.d.ts +10 -0
  172. package/build/cli/models/config/template-settings.d.ts.map +1 -0
  173. package/build/cli/models/config/template-settings.js +72 -0
  174. package/build/cli/models/server/index.d.ts.map +1 -1
  175. package/build/cli/models/server/index.js +6 -2
  176. package/build/server/hono/extensions.d.ts +48 -0
  177. package/build/server/hono/extensions.d.ts.map +1 -0
  178. package/build/server/hono/extensions.js +65 -0
  179. package/build/server/hono/index.d.ts +30 -0
  180. package/build/server/hono/index.d.ts.map +1 -0
  181. package/build/server/hono/index.js +72 -0
  182. package/build/server/hono/path.d.ts +7 -0
  183. package/build/server/hono/path.d.ts.map +1 -0
  184. package/build/server/hono/path.js +32 -0
  185. package/build/server/models/assets/index.d.ts +6 -0
  186. package/build/server/models/assets/index.d.ts.map +1 -1
  187. package/build/server/models/assets/index.js +24 -0
  188. package/build/server/models/collections/index.d.ts +3 -0
  189. package/build/server/models/collections/index.d.ts.map +1 -0
  190. package/build/server/models/collections/index.js +15 -0
  191. package/build/server/models/compression/index.d.ts +1 -1
  192. package/build/server/models/compression/index.d.ts.map +1 -1
  193. package/build/server/models/config/collection-selection.d.ts +55 -0
  194. package/build/server/models/config/collection-selection.d.ts.map +1 -0
  195. package/build/server/models/config/collection-selection.js +238 -0
  196. package/build/server/models/config/item-patterns.d.ts +4 -0
  197. package/build/server/models/config/item-patterns.d.ts.map +1 -0
  198. package/build/server/models/config/item-patterns.js +43 -0
  199. package/build/server/models/config/publish-content-config.d.ts +6 -1
  200. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  201. package/build/server/models/config/static-publish-project.d.ts +23 -0
  202. package/build/server/models/config/static-publish-project.d.ts.map +1 -0
  203. package/build/server/models/config/static-publish-project.js +11 -0
  204. package/build/server/models/config/static-publish-rc.d.ts +25 -0
  205. package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
  206. package/build/server/models/config/static-publish-rc.js +31 -0
  207. package/build/server/models/server/index.d.ts.map +1 -1
  208. package/build/server/models/server/index.js +6 -2
  209. package/build/server/server/collection-selection/index.d.ts +11 -0
  210. package/build/server/server/collection-selection/index.d.ts.map +1 -0
  211. package/build/server/server/collection-selection/index.js +192 -0
  212. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
  213. package/build/server/server/collection-selector/from-cookie.js +6 -8
  214. package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
  215. package/build/server/server/index.d.ts +4 -1
  216. package/build/server/server/index.d.ts.map +1 -1
  217. package/build/server/server/index.js +3 -1
  218. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  219. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  220. package/build/server/server/publisher-server/accept-html.js +50 -0
  221. package/build/server/server/publisher-server/index.d.ts +59 -6
  222. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  223. package/build/server/server/publisher-server/index.js +370 -131
  224. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  225. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  226. package/build/server/server/publisher-server/response-cache.js +24 -1
  227. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
  228. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  229. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  230. package/build/server/server/util/body-length.d.ts.map +1 -1
  231. package/build/server/server/util/server-timing.d.ts.map +1 -1
  232. package/package.json +23 -4
  233. package/resources/app/fastly.toml.njk +58 -0
  234. package/resources/app/gitignore.njk +9 -0
  235. package/resources/app/publish-content.config.from-project.js.njk +9 -0
  236. package/resources/app/publish-content.config.js.njk +35 -0
  237. package/resources/app/static-publish.project.js.njk +83 -0
  238. package/resources/app/static-publish.rc.js.njk +43 -0
  239. package/resources/template-init/hono/_example.ts +22 -0
  240. package/resources/template-init/hono/tsconfig.json +17 -0
  241. package/resources/templates/hono/package-lock.json +4123 -0
  242. package/resources/templates/hono/package.json +15 -0
  243. package/resources/templates/hono/scripts/template_postinstall.js +10 -0
  244. package/resources/templates/hono/scripts/template_prebuild.js +8 -0
  245. package/resources/templates/hono/scripts/template_watch.js +15 -0
  246. package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
  247. package/resources/templates/hono/src/index.ts +53 -0
  248. package/resources/templates/hono/tsconfig.json +17 -0
  249. package/resources/templates/plain/package-lock.json +4088 -0
  250. package/resources/templates/plain/package.json +10 -0
  251. package/resources/templates/plain/src/index.js +34 -0
@@ -4,17 +4,23 @@
4
4
  */
5
5
  import * as fs from 'node:fs';
6
6
  import * as path from 'node:path';
7
+ import { HIDDEN_INDEX_FEATURE, findAssetEntry, hiddenIndexKey, } from '../../../models/assets/index.js';
8
+ import { parseItemPatterns, testItemPatterns } from '../../../models/config/item-patterns.js';
7
9
  import { encodeIndexMetadata } from '../../../models/server/index.js';
8
10
  import { calcExpirationTime } from '../../../models/time/index.js';
9
11
  import { parseCommandLine } from '../../util/args.js';
12
+ import { errorCodeOf, fail, recordFailure, setJsonResult } from '../../util/output.js';
13
+ import { checkCollectionNameForWrite } from '../../util/collection-name.js';
10
14
  import { mergeContentTypes, testFileContentType } from '../../util/content-types.js';
11
- import { LoadConfigError, loadPublishContentConfigFile, loadStaticPublisherRcFile } from '../../util/config.js';
15
+ import { LoadConfigError, configFileName, detectProjectMode, getComputeAppDir, loadProjectFile, loadPublishContentConfig, loadStaticPublisherRcFile, } from '../../util/config.js';
16
+ import { PROJECT_FILE_NAME } from '../../../models/config/static-publish-project.js';
12
17
  import { applyDefaults } from '../../util/data.js';
13
18
  import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
14
19
  import { ensureVariantFileExists, OncePerKey } from '../../util/variants.js';
15
20
  import { concurrentMap } from '../../util/retryable.js';
21
+ import { ProgressLog } from '../../util/progress.js';
16
22
  import { loadPurgeTarget, purgeCollection } from '../../util/purge.js';
17
- import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
23
+ import { getStorageKeysByHexPrefix, isVariantInStorage, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
18
24
  // Storage key format:
19
25
  // <publishId>_index_<preview_id>.json
20
26
  // <publishId>_settings_<preview_id>.json
@@ -94,6 +100,9 @@ S3 Storage Options (BETA):
94
100
  Default: 64
95
101
 
96
102
  Global Options:
103
+ --verbose Verbose mode. Logs each file and each upload.
104
+ Without this, the log shows the progress after
105
+ each 1000 files or uploads.
97
106
  -h, --help Show this help message and exit.
98
107
 
99
108
  Examples:
@@ -105,7 +114,7 @@ Examples:
105
114
  }
106
115
  export async function action(actionArgs) {
107
116
  const optionDefinitions = [
108
- { name: 'verbose', type: Boolean },
117
+ { name: 'verbose', type: Boolean, defaultValue: false },
109
118
  { name: 'config', type: String },
110
119
  { name: 'collection-name', type: String, },
111
120
  { name: 'root-dir', type: String, },
@@ -128,7 +137,7 @@ export async function action(actionArgs) {
128
137
  if (parsed.error != null) {
129
138
  console.error(String(parsed.error));
130
139
  console.error();
131
- process.exitCode = 1;
140
+ recordFailure('usage', String(parsed.error));
132
141
  }
133
142
  help();
134
143
  return;
@@ -138,8 +147,7 @@ export async function action(actionArgs) {
138
147
  if (s3UploadConcurrencyValue !== undefined) {
139
148
  if (typeof s3UploadConcurrencyValue !== 'string' || !/^\d+$/.test(s3UploadConcurrencyValue) ||
140
149
  Number(s3UploadConcurrencyValue) < 1 || Number(s3UploadConcurrencyValue) > 256) {
141
- console.error(`❌ --s3-upload-concurrency must be an integer from 1 to 256.`);
142
- process.exitCode = 1;
150
+ fail('usage', `--s3-upload-concurrency must be an integer from 1 to 256.`);
143
151
  return;
144
152
  }
145
153
  s3UploadConcurrency = Number(s3UploadConcurrencyValue);
@@ -147,7 +155,7 @@ export async function action(actionArgs) {
147
155
  const overwriteExisting = _overwriteExisting ?? _kvOverwrite;
148
156
  // compute-js-static-publisher cli is always run from the Compute application directory
149
157
  // in other words, the directory that contains `fastly.toml`.
150
- const computeAppDir = path.resolve();
158
+ const computeAppDir = getComputeAppDir();
151
159
  console.log(`🚀 Publishing content...`);
152
160
  // #### load config
153
161
  let staticPublisherRc;
@@ -155,20 +163,22 @@ export async function action(actionArgs) {
155
163
  staticPublisherRc = await loadStaticPublisherRcFile();
156
164
  }
157
165
  catch (err) {
158
- console.error("❌ Can't load static-publish.rc.js");
166
+ console.error(`❌ Can't load ${configFileName()}`);
159
167
  console.error("Run this from a compute-js-static-publish compute-js directory.");
160
168
  if (err instanceof LoadConfigError) {
161
169
  for (const error of err.errors) {
162
170
  console.error(error);
163
171
  }
164
172
  }
165
- process.exitCode = 1;
173
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
166
174
  return;
167
175
  }
168
- const configFilePath = configFilePathValue ?? './publish-content.config.js';
176
+ // In a managed project, the default is the publishContent section of the project file.
177
+ const managedProject = detectProjectMode() === 'managed' ? await loadProjectFile() : null;
178
+ const configFilePath = configFilePathValue ?? (managedProject != null ? `${PROJECT_FILE_NAME} (publishContent)` : './publish-content.config.js');
169
179
  let publishContentConfig;
170
180
  try {
171
- publishContentConfig = await loadPublishContentConfigFile(configFilePath);
181
+ publishContentConfig = await loadPublishContentConfig(configFilePathValue);
172
182
  }
173
183
  catch (err) {
174
184
  console.error(`❌ Can't load ${configFilePath}`);
@@ -177,15 +187,14 @@ export async function action(actionArgs) {
177
187
  console.error(error);
178
188
  }
179
189
  }
180
- process.exitCode = 1;
190
+ recordFailure('config-invalid', `Can't load ${configFilePath}.`);
181
191
  return;
182
192
  }
183
193
  // --brotli-quality overrides brotliQuality in the config file.
184
194
  let brotliQualitySource = 'config';
185
195
  if (brotliQualityValue !== undefined) {
186
196
  if (typeof brotliQualityValue !== 'string' || !/^\d+$/.test(brotliQualityValue) || Number(brotliQualityValue) > 11) {
187
- console.error(`❌ --brotli-quality must be an integer from 0 to 11.`);
188
- process.exitCode = 1;
197
+ fail('usage', `--brotli-quality must be an integer from 0 to 11.`);
189
198
  return;
190
199
  }
191
200
  publishContentConfig.brotliQuality = Number(brotliQualityValue);
@@ -206,7 +215,7 @@ export async function action(actionArgs) {
206
215
  catch (err) {
207
216
  console.error(`❌ Cannot process expiration time`);
208
217
  console.error(String(err));
209
- process.exitCode = 1;
218
+ recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
210
219
  return;
211
220
  }
212
221
  console.log(`✔️ Public directory '${rootRelative(publicDirRoot)}'.`);
@@ -234,7 +243,7 @@ export async function action(actionArgs) {
234
243
  catch (err) {
235
244
  console.error(`❌ Could not instantiate store provider`);
236
245
  console.error(String(err));
237
- process.exitCode = 1;
246
+ recordFailure(errorCodeOf(err), String(err));
238
247
  return;
239
248
  }
240
249
  // Purge target: checked now, so that a missing API token fails before anything is uploaded.
@@ -244,13 +253,14 @@ export async function action(actionArgs) {
244
253
  localMode: localMode ?? false,
245
254
  computeAppDir,
246
255
  fastlyServiceId,
256
+ projectServiceId: managedProject?.managed.serviceId,
247
257
  fastlyApiToken,
248
258
  purgeEnvironments: purgeEnvironmentValues,
249
259
  });
250
260
  }
251
261
  catch (err) {
252
262
  console.error(String(err));
253
- process.exitCode = 1;
263
+ recordFailure(errorCodeOf(err), String(err));
254
264
  return;
255
265
  }
256
266
  // Load content types
@@ -274,10 +284,20 @@ export async function action(actionArgs) {
274
284
  if (includeWellKnown) {
275
285
  console.log(`✔️ (.well-known is exempt from exclusion.)`);
276
286
  }
287
+ // The files to publish as hidden files (see also assetInclusionTest).
288
+ const hiddenItems = parseItemPatterns(publishContentConfig.hiddenItems, (i, x) => {
289
+ console.warn(`⚠️ Cannot parse hiddenItems item index ${i}: '${x}', skipping...`);
290
+ });
291
+ if (hiddenItems.length > 0) {
292
+ console.log(`✔️ Hidden items: ${publishContentConfig.hiddenItems.join(', ')}`);
293
+ }
277
294
  // ### Collection name that we're currently publishing
278
295
  // for example, live, staging
279
296
  const collectionName = collectionNameValue ?? process.env.PUBLISHER_COLLECTION_NAME ?? defaultCollectionName;
280
297
  console.log(`✔️ Collection Name: ${collectionName}`);
298
+ if (!await checkCollectionNameForWrite(storageProvider, publishId, collectionName)) {
299
+ return;
300
+ }
281
301
  if (expirationTime == null) {
282
302
  // includes null and undefined
283
303
  console.log(`✔️ Publishing with no expiration timestamp.`);
@@ -315,6 +335,8 @@ export async function action(actionArgs) {
315
335
  // #### Keys that are already in storage
316
336
  // The key of a file is the hash of its content. If the key exists, storage
317
337
  // already has the same content. Thus we do not compress, hash, or upload it again.
338
+ // For a file in more than one chunk, isVariantInStorage() also compares the
339
+ // stored size of each chunk.
318
340
  // In local mode, a key can refer to a working file that was deleted, so we do not list.
319
341
  // All the keys that the scan looks for start with `<publishId>_files_sha256_` and a hex
320
342
  // hash, so we list them in 16 parts at the same time.
@@ -326,18 +348,8 @@ export async function action(actionArgs) {
326
348
  console.log(`✅ Found ${existingKeys.size} key(s) in ${((Date.now() - listStart) / 1000).toFixed(1)} s.`);
327
349
  }
328
350
  let existingVariantCount = 0;
329
- function isVariantInStorage(variantKey, numChunks) {
330
- if (existingKeys == null || !existingKeys.has(variantKey)) {
331
- return false;
332
- }
333
- for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
334
- if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
335
- return false;
336
- }
337
- }
338
- return true;
339
- }
340
351
  // #### Iterate files
352
+ const scanProgress = new ProgressLog('Files scanned', verbose);
341
353
  const fileResults = await concurrentMap(files, async (file) => {
342
354
  // #### asset key
343
355
  const assetKey = file.slice(publicDirRoot.length)
@@ -369,9 +381,12 @@ export async function action(actionArgs) {
369
381
  if (!includeAsset) {
370
382
  return;
371
383
  }
384
+ // A hidden file is published, but PublisherServer does not serve it for a request.
385
+ const hidden = (typeof includeAsset === 'object' && includeAsset.hidden === true) ||
386
+ testItemPatterns(hiddenItems, assetKey);
372
387
  // #### Base file size, hash, last modified time
373
388
  const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
374
- console.log(`📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
389
+ scanProgress.add(1, () => `📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}${hidden ? ' (hidden)' : ''}`);
375
390
  const stats = fs.statSync(file);
376
391
  const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
377
392
  // We know the number of chunks of the original before we read it. For a
@@ -387,7 +402,8 @@ export async function action(actionArgs) {
387
402
  // Returns true if the index keeps the variant.
388
403
  async function prepareVariant(variant, variantKey, variantFilePath) {
389
404
  if ((variant === 'original' || baseNumChunks === 1) &&
390
- isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
405
+ existingKeys != null &&
406
+ await isVariantInStorage(storageProvider, existingKeys, variantKey, baseSize, variant === 'original' ? baseNumChunks : 1)) {
391
407
  if (verbose) {
392
408
  console.log(` ・ Asset found in storage with key "${variantKey}".`);
393
409
  }
@@ -453,6 +469,7 @@ export async function action(actionArgs) {
453
469
  }
454
470
  return {
455
471
  assetKey,
472
+ hidden,
456
473
  asset: {
457
474
  key: `sha256:${baseHash}`,
458
475
  size: baseSize,
@@ -463,29 +480,39 @@ export async function action(actionArgs) {
463
480
  batchItems,
464
481
  };
465
482
  });
483
+ let hiddenCount = 0;
466
484
  for (const result of fileResults) {
467
485
  if (result == null) {
468
486
  continue;
469
487
  }
470
- assetsIndex[result.assetKey] = result.asset;
488
+ if (result.hidden) {
489
+ assetsIndex[hiddenIndexKey(result.assetKey)] = result.asset;
490
+ hiddenCount++;
491
+ }
492
+ else {
493
+ assetsIndex[result.assetKey] = result.asset;
494
+ }
471
495
  for (const batchItem of result.batchItems) {
472
496
  batch.add(batchItem);
473
497
  }
474
498
  }
475
499
  console.log(`✅ Scan complete.`);
500
+ console.log(` | ${Object.keys(assetsIndex).length} file(s) in the index, ${hiddenCount} of them hidden.`);
476
501
  if (existingKeys != null) {
477
502
  console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
478
503
  }
479
504
  else {
480
505
  console.log(` | ${batch.storageProviderBatchEntries.length} variant(s) to upload.`);
481
506
  }
482
- await storageProvider.applyBatch(batch, { existingKeys });
507
+ await storageProvider.applyBatch(batch, { existingKeys, verbose });
483
508
  // #### INDEX FILE
484
509
  console.log(`🗂️ Saving Index...`);
485
510
  const indexFileKey = `${publishId}_index_${collectionName}`;
486
511
  const indexMetadata = {
487
512
  publishedTime: Math.floor(Date.now() / 1000),
488
513
  expirationTime: expirationTime ?? undefined,
514
+ // A server that does not support hidden files must not serve this collection.
515
+ requires: hiddenCount > 0 ? [HIDDEN_INDEX_FEATURE] : undefined,
489
516
  };
490
517
  const indexFileName = `index_${collectionName}.json`;
491
518
  const indexFilePath = path.resolve(storageContentDir, indexFileName);
@@ -514,7 +541,7 @@ export async function action(actionArgs) {
514
541
  let spaFile = server.spaFile;
515
542
  if (spaFile != null) {
516
543
  console.log(` ✔️ Application SPA file '${spaFile}'.`);
517
- const spaAsset = assetsIndex[spaFile];
544
+ const spaAsset = findAssetEntry(assetsIndex, spaFile, true);
518
545
  if (spaAsset == null || spaAsset.contentType !== 'text/html') {
519
546
  if (verbose) {
520
547
  console.log(` ⚠️ Notice: '${spaFile}' does not exist or is not of type 'text/html'. Ignoring.`);
@@ -530,7 +557,7 @@ export async function action(actionArgs) {
530
557
  let notFoundPageFile = server.notFoundPageFile;
531
558
  if (notFoundPageFile != null) {
532
559
  console.log(` ✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
533
- const notFoundPageAsset = assetsIndex[notFoundPageFile];
560
+ const notFoundPageAsset = findAssetEntry(assetsIndex, notFoundPageFile, true);
534
561
  if (notFoundPageAsset == null || notFoundPageAsset.contentType !== 'text/html') {
535
562
  if (verbose) {
536
563
  console.log(` ⚠️ Notice: '${notFoundPageFile}' does not exist or is not of type 'text/html'. Ignoring.`);
@@ -559,8 +586,31 @@ export async function action(actionArgs) {
559
586
  const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
560
587
  await storageProvider.submitStorageEntry(settingsFileKey, settingsFilePath, JSON.stringify(serverSettings));
561
588
  console.log(`✅ Settings have been saved.`);
589
+ // A failed purge is only a warning (exit 0), because the content is published.
590
+ const purgeResults = [];
562
591
  if (purgeTarget != null) {
563
- await purgeCollection(purgeTarget, publishId, collectionName);
592
+ purgeResults.push(...await purgeCollection(purgeTarget, publishId, collectionName));
564
593
  }
565
594
  console.log(`🎉 Completed.`);
595
+ setJsonResult({
596
+ collection: collectionName,
597
+ publishId,
598
+ // The files in the index.
599
+ files: {
600
+ total: Object.keys(assetsIndex).length,
601
+ hidden: hiddenCount,
602
+ },
603
+ // Each file, and each compressed variant that is kept.
604
+ storageItems: {
605
+ uploaded: batch.storageProviderBatchEntries.length,
606
+ reused: existingVariantCount,
607
+ },
608
+ expiresAt: expirationTime != null ? new Date(expirationTime * 1000).toISOString() : null,
609
+ // null: no purge (--local, or no Service ID).
610
+ purge: purgeTarget != null ? {
611
+ ok: purgeResults.every(x => x.result !== 'failed'),
612
+ serviceId: purgeTarget.serviceId,
613
+ environments: purgeResults,
614
+ } : null,
615
+ });
566
616
  }
@@ -0,0 +1,2 @@
1
+ export declare function action(actionArgs: string[]): Promise<void>;
2
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/status.ts"],"names":[],"mappings":"AAgDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiIhD"}
@@ -0,0 +1,162 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import path from 'node:path';
6
+ import { managedAppState } from '../../managed/app.js';
7
+ import { loadManagedProject } from '../../managed/command-helpers.js';
8
+ import { getActiveVersion, getVersionDomains } from '../../managed/fastly-service.js';
9
+ import { parseVersionComment } from '../../managed/fingerprint.js';
10
+ import { checkProjectVersion } from '../../managed/version-check.js';
11
+ import { loadApiToken } from '../../util/api-token.js';
12
+ import { parseCommandLine } from '../../util/args.js';
13
+ import { recordFailure, setJsonResult } from '../../util/output.js';
14
+ import { detectProjectMode } from '../../util/config.js';
15
+ import { getOwnVersion } from '../../util/package.js';
16
+ import { loadServiceId } from '../../util/service-id.js';
17
+ import { previewUrlTemplates } from '../../../models/config/collection-selection.js';
18
+ import { MANAGED_APP_DIR } from '../../../models/config/static-publish-project.js';
19
+ import { DEFAULT_APP_TEMPLATE_NAME } from '../scaffold/app-template.js';
20
+ import { providedVersions } from '../../managed/template-init.js';
21
+ function help() {
22
+ console.log(`\
23
+
24
+ Usage:
25
+ npx @fastly/compute-js-static-publish status [options]
26
+
27
+ Description:
28
+ Shows the state of the app. In a managed project: the fingerprint of the app
29
+ that the project generates, the fingerprint of the active version of the
30
+ service, and if a deploy is necessary. In an ejected app: the Service ID.
31
+
32
+ Options:
33
+ --fastly-service-id=<id> The service. Default: FASTLY_SERVICE_ID, then
34
+ managed.serviceId (or service_id in fastly.toml).
35
+ --fastly-api-token=<token> Reads the active version of the service. Default:
36
+ FASTLY_API_TOKEN. Without a token, the deployed
37
+ fingerprint is unknown.
38
+
39
+ Global Options:
40
+ -h, --help Show this help message and exit.
41
+ `);
42
+ }
43
+ export async function action(actionArgs) {
44
+ const optionDefinitions = [
45
+ { name: 'fastly-service-id', type: String },
46
+ { name: 'fastly-api-token', type: String },
47
+ ];
48
+ const parsed = parseCommandLine(actionArgs, optionDefinitions);
49
+ if (parsed.needHelp) {
50
+ if (parsed.error != null) {
51
+ console.error(String(parsed.error));
52
+ console.error();
53
+ recordFailure('usage', String(parsed.error));
54
+ }
55
+ help();
56
+ return;
57
+ }
58
+ const { ['fastly-service-id']: fastlyServiceId, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
59
+ if (detectProjectMode() === 'ejected') {
60
+ const serviceIdResult = loadServiceId({ commandLine: fastlyServiceId, fastlyTomlPath: path.resolve('fastly.toml') });
61
+ console.log(`Mode : ejected`);
62
+ console.log(`Service ID : ${serviceIdResult?.serviceId ?? '(none)'}`);
63
+ setJsonResult({ mode: 'ejected', serviceId: serviceIdResult?.serviceId ?? null });
64
+ return;
65
+ }
66
+ const project = await loadManagedProject('status', '');
67
+ if (project == null) {
68
+ return;
69
+ }
70
+ const running = getOwnVersion();
71
+ const versionCheck = checkProjectVersion(project.managed.staticPublishVersion, running);
72
+ const { fingerprint } = await managedAppState(path.resolve(), project);
73
+ const serviceIdResult = loadServiceId({
74
+ commandLine: fastlyServiceId,
75
+ // After the first deploy, the Fastly CLI writes service_id here.
76
+ fastlyTomlPath: path.resolve(MANAGED_APP_DIR, 'fastly.toml'),
77
+ projectServiceId: project.managed.serviceId,
78
+ });
79
+ const serviceId = serviceIdResult?.serviceId ?? null;
80
+ const apiToken = loadApiToken({ commandLine: fastlyApiToken });
81
+ let deployedFingerprint = null;
82
+ let deployedStaticPublishVersion = null;
83
+ let activeVersion = null;
84
+ let domain = null;
85
+ let needsDeploy;
86
+ const reasons = [];
87
+ if (serviceId == null) {
88
+ needsDeploy = true;
89
+ reasons.push('The project has no service yet (no Service ID).');
90
+ }
91
+ else if (apiToken == null) {
92
+ needsDeploy = null;
93
+ reasons.push('Unknown: no API token, so the active version of the service cannot be read.');
94
+ }
95
+ else {
96
+ const context = { apiToken: apiToken.apiToken };
97
+ const active = await getActiveVersion(context, serviceId);
98
+ if (active == null) {
99
+ needsDeploy = true;
100
+ reasons.push('The service has no active version.');
101
+ }
102
+ else {
103
+ activeVersion = active.number;
104
+ domain = (await getVersionDomains(context, serviceId, active.number))[0] ?? null;
105
+ const deployed = parseVersionComment(active.comment);
106
+ if (deployed == null) {
107
+ needsDeploy = true;
108
+ reasons.push(`The active version (${active.number}) was not deployed by 'deploy' (its comment has no fingerprint).`);
109
+ }
110
+ else {
111
+ deployedFingerprint = deployed.fingerprint;
112
+ deployedStaticPublishVersion = deployed.staticPublishVersion;
113
+ needsDeploy = deployed.fingerprint !== fingerprint;
114
+ if (needsDeploy) {
115
+ reasons.push(deployed.staticPublishVersion !== running ?
116
+ `The version of this package changed: ${deployed.staticPublishVersion} → ${running}.` :
117
+ 'The generated app changed.');
118
+ }
119
+ }
120
+ }
121
+ }
122
+ const baseUrl = domain != null ? `https://${domain}` : 'https://<service domain>';
123
+ const previewUrls = project.rc.collectionSelection != null ? previewUrlTemplates(baseUrl, project.rc.collectionSelection) : [];
124
+ // The packages that the template provides to its folder (for example to the
125
+ // Hono extensions), with the versions of the generated app.
126
+ const templateName = project.managed.template ?? DEFAULT_APP_TEMPLATE_NAME;
127
+ const providedPackages = providedVersions(templateName, path.resolve(MANAGED_APP_DIR, 'node_modules'), running);
128
+ console.log(`Mode : managed`);
129
+ console.log(`Template : ${templateName}`);
130
+ console.log(`Service ID : ${serviceId ?? '(none)'}${serviceIdResult != null ? ` (from ${serviceIdResult.source})` : ''}`);
131
+ console.log(`Version of the project : ${versionCheck.recorded ?? '(missing)'}`);
132
+ console.log(`Version that runs : ${running}${versionCheck.result !== 'same' ? ` ⚠️ ${versionCheck.result}` : ''}`);
133
+ console.log(`Fingerprint : ${fingerprint}`);
134
+ console.log(`Deployed fingerprint : ${deployedFingerprint ?? '(unknown)'}${activeVersion != null ? ` (version ${activeVersion})` : ''}`);
135
+ console.log(`Deploy necessary : ${needsDeploy == null ? 'unknown' : needsDeploy ? 'yes' : 'no'}`);
136
+ for (const reason of reasons) {
137
+ console.log(` * ${reason}`);
138
+ }
139
+ for (const { type, url } of previewUrls) {
140
+ console.log(`Preview URL (${type})${' '.repeat(Math.max(0, 9 - type.length))}: ${url}`);
141
+ }
142
+ setJsonResult({
143
+ mode: 'managed',
144
+ template: { name: templateName, provides: providedPackages },
145
+ serviceId,
146
+ staticPublishVersion: {
147
+ recorded: versionCheck.recorded ?? null,
148
+ running,
149
+ check: versionCheck.result,
150
+ },
151
+ fingerprint: {
152
+ current: fingerprint,
153
+ deployed: deployedFingerprint,
154
+ deployedStaticPublishVersion,
155
+ },
156
+ activeVersion,
157
+ domain,
158
+ needsDeploy,
159
+ reasons,
160
+ previewUrls,
161
+ });
162
+ }
@@ -0,0 +1,2 @@
1
+ export declare function action(actionArgs: string[]): Promise<void>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/template/index.ts"],"names":[],"mappings":"AA2BA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuBhD"}
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { getCommandAndArgs } from '../../../util/args.js';
6
+ import { recordFailure } from '../../../util/output.js';
7
+ import * as initCommand from './init.js';
8
+ function help() {
9
+ console.log(`\
10
+
11
+ Usage:
12
+ npx @fastly/compute-js-static-publish template <sub-command> [options]
13
+
14
+ Description:
15
+ Commands for the template of the app.
16
+
17
+ Available Subcommands:
18
+ init Make or update the folder of the template
19
+ (for the hono template: hono-extensions/)
20
+
21
+ Global Options:
22
+ -h, --help Show this help message and exit.
23
+ `);
24
+ }
25
+ export async function action(actionArgs) {
26
+ const modes = {
27
+ 'init': initCommand,
28
+ };
29
+ const commandAndArgs = getCommandAndArgs(actionArgs, modes);
30
+ if (commandAndArgs.needHelp) {
31
+ if (commandAndArgs.error != null) {
32
+ console.error(commandAndArgs.error);
33
+ console.error(`Specify one of the following sub-commands: ${Object.keys(modes).join(', ')}`);
34
+ console.error();
35
+ recordFailure('usage', commandAndArgs.error);
36
+ }
37
+ help();
38
+ return;
39
+ }
40
+ const { command, argv, } = commandAndArgs;
41
+ await modes[command].action(argv);
42
+ }
@@ -0,0 +1,13 @@
1
+ import { type StaticPublishRc } from '../../../../models/config/static-publish-rc.js';
2
+ export type RunTemplateInitParams = {
3
+ templateName: string;
4
+ rc: Pick<StaticPublishRc, 'build'>;
5
+ baseDir: string;
6
+ appNodeModulesDir: string | undefined;
7
+ reset?: boolean;
8
+ force?: boolean;
9
+ check?: boolean;
10
+ };
11
+ export declare function runTemplateInit(params: RunTemplateInitParams): Promise<void>;
12
+ export declare function action(actionArgs: string[]): Promise<void>;
13
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/template/init.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAyCtF,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAGnC,OAAO,EAAE,MAAM,CAAC;IAEhB,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AASF,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,iBAqDlE;AAED,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAsEhD"}