@fastly/compute-js-static-publish 8.0.1 → 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 (247) hide show
  1. package/DOCUMENTATION.md +779 -22
  2. package/README.md +2 -2
  3. package/README.short.md +2 -2
  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 +78 -33
  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 +208 -290
  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 +1 -0
  100. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  101. package/build/cli/cli/storage/kv-store-provider.js +9 -1
  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 +4 -0
  105. package/build/cli/cli/storage/storage-provider.d.ts +3 -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.map +1 -1
  109. package/build/cli/cli/util/collection-name.d.ts +3 -0
  110. package/build/cli/cli/util/collection-name.d.ts.map +1 -0
  111. package/build/cli/cli/util/collection-name.js +24 -0
  112. package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
  113. package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
  114. package/build/cli/cli/util/collection-selection-flags.js +131 -0
  115. package/build/cli/cli/util/config.d.ts +13 -0
  116. package/build/cli/cli/util/config.d.ts.map +1 -1
  117. package/build/cli/cli/util/config.js +172 -38
  118. package/build/cli/cli/util/data.d.ts.map +1 -1
  119. package/build/cli/cli/util/global-options.d.ts +13 -0
  120. package/build/cli/cli/util/global-options.d.ts.map +1 -0
  121. package/build/cli/cli/util/global-options.js +53 -0
  122. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  123. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  124. package/build/cli/cli/util/kv-store-items.js +16 -40
  125. package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
  126. package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
  127. package/build/cli/cli/util/kv-store-local-server.js +4 -2
  128. package/build/cli/cli/util/output.d.ts +31 -0
  129. package/build/cli/cli/util/output.d.ts.map +1 -0
  130. package/build/cli/cli/util/output.js +139 -0
  131. package/build/cli/cli/util/package.d.ts +3 -0
  132. package/build/cli/cli/util/package.d.ts.map +1 -1
  133. package/build/cli/cli/util/package.js +12 -0
  134. package/build/cli/cli/util/progress.d.ts.map +1 -1
  135. package/build/cli/cli/util/purge.d.ts +6 -2
  136. package/build/cli/cli/util/purge.d.ts.map +1 -1
  137. package/build/cli/cli/util/purge.js +7 -2
  138. package/build/cli/cli/util/resources.d.ts +2 -0
  139. package/build/cli/cli/util/resources.d.ts.map +1 -0
  140. package/build/cli/cli/util/resources.js +8 -0
  141. package/build/cli/cli/util/service-id.d.ts +1 -0
  142. package/build/cli/cli/util/service-id.d.ts.map +1 -1
  143. package/build/cli/cli/util/service-id.js +5 -1
  144. package/build/cli/cli/util/variants.d.ts.map +1 -1
  145. package/build/cli/models/assets/index.d.ts +6 -0
  146. package/build/cli/models/assets/index.d.ts.map +1 -1
  147. package/build/cli/models/assets/index.js +24 -0
  148. package/build/cli/models/collections/index.d.ts +3 -0
  149. package/build/cli/models/collections/index.d.ts.map +1 -0
  150. package/build/cli/models/collections/index.js +15 -0
  151. package/build/cli/models/compression/index.d.ts +1 -1
  152. package/build/cli/models/compression/index.d.ts.map +1 -1
  153. package/build/cli/models/config/collection-selection.d.ts +55 -0
  154. package/build/cli/models/config/collection-selection.d.ts.map +1 -0
  155. package/build/cli/models/config/collection-selection.js +238 -0
  156. package/build/cli/models/config/item-patterns.d.ts +4 -0
  157. package/build/cli/models/config/item-patterns.d.ts.map +1 -0
  158. package/build/cli/models/config/item-patterns.js +43 -0
  159. package/build/cli/models/config/publish-content-config.d.ts +6 -1
  160. package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
  161. package/build/cli/models/config/static-publish-project.d.ts +23 -0
  162. package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
  163. package/build/cli/models/config/static-publish-project.js +11 -0
  164. package/build/cli/models/config/static-publish-rc.d.ts +25 -0
  165. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
  166. package/build/cli/models/config/static-publish-rc.js +31 -0
  167. package/build/cli/models/config/template-settings.d.ts +10 -0
  168. package/build/cli/models/config/template-settings.d.ts.map +1 -0
  169. package/build/cli/models/config/template-settings.js +72 -0
  170. package/build/cli/models/server/index.d.ts.map +1 -1
  171. package/build/cli/models/server/index.js +6 -2
  172. package/build/server/hono/extensions.d.ts +48 -0
  173. package/build/server/hono/extensions.d.ts.map +1 -0
  174. package/build/server/hono/extensions.js +65 -0
  175. package/build/server/hono/index.d.ts +30 -0
  176. package/build/server/hono/index.d.ts.map +1 -0
  177. package/build/server/hono/index.js +72 -0
  178. package/build/server/hono/path.d.ts +7 -0
  179. package/build/server/hono/path.d.ts.map +1 -0
  180. package/build/server/hono/path.js +32 -0
  181. package/build/server/models/assets/index.d.ts +6 -0
  182. package/build/server/models/assets/index.d.ts.map +1 -1
  183. package/build/server/models/assets/index.js +24 -0
  184. package/build/server/models/collections/index.d.ts +3 -0
  185. package/build/server/models/collections/index.d.ts.map +1 -0
  186. package/build/server/models/collections/index.js +15 -0
  187. package/build/server/models/compression/index.d.ts +1 -1
  188. package/build/server/models/compression/index.d.ts.map +1 -1
  189. package/build/server/models/config/collection-selection.d.ts +55 -0
  190. package/build/server/models/config/collection-selection.d.ts.map +1 -0
  191. package/build/server/models/config/collection-selection.js +238 -0
  192. package/build/server/models/config/item-patterns.d.ts +4 -0
  193. package/build/server/models/config/item-patterns.d.ts.map +1 -0
  194. package/build/server/models/config/item-patterns.js +43 -0
  195. package/build/server/models/config/publish-content-config.d.ts +6 -1
  196. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  197. package/build/server/models/config/static-publish-project.d.ts +23 -0
  198. package/build/server/models/config/static-publish-project.d.ts.map +1 -0
  199. package/build/server/models/config/static-publish-project.js +11 -0
  200. package/build/server/models/config/static-publish-rc.d.ts +25 -0
  201. package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
  202. package/build/server/models/config/static-publish-rc.js +31 -0
  203. package/build/server/models/server/index.d.ts.map +1 -1
  204. package/build/server/models/server/index.js +6 -2
  205. package/build/server/server/collection-selection/index.d.ts +11 -0
  206. package/build/server/server/collection-selection/index.d.ts.map +1 -0
  207. package/build/server/server/collection-selection/index.js +192 -0
  208. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
  209. package/build/server/server/collection-selector/from-cookie.js +6 -8
  210. package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
  211. package/build/server/server/index.d.ts +4 -1
  212. package/build/server/server/index.d.ts.map +1 -1
  213. package/build/server/server/index.js +3 -1
  214. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  215. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  216. package/build/server/server/publisher-server/accept-html.js +50 -0
  217. package/build/server/server/publisher-server/index.d.ts +59 -7
  218. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  219. package/build/server/server/publisher-server/index.js +362 -145
  220. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  221. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  222. package/build/server/server/publisher-server/response-cache.js +24 -1
  223. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
  224. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  225. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  226. package/build/server/server/util/body-length.d.ts.map +1 -1
  227. package/build/server/server/util/server-timing.d.ts.map +1 -1
  228. package/package.json +21 -3
  229. package/resources/app/fastly.toml.njk +58 -0
  230. package/resources/app/gitignore.njk +9 -0
  231. package/resources/app/publish-content.config.from-project.js.njk +9 -0
  232. package/resources/app/publish-content.config.js.njk +35 -0
  233. package/resources/app/static-publish.project.js.njk +83 -0
  234. package/resources/app/static-publish.rc.js.njk +43 -0
  235. package/resources/template-init/hono/_example.ts +22 -0
  236. package/resources/template-init/hono/tsconfig.json +17 -0
  237. package/resources/templates/hono/package-lock.json +4123 -0
  238. package/resources/templates/hono/package.json +15 -0
  239. package/resources/templates/hono/scripts/template_postinstall.js +10 -0
  240. package/resources/templates/hono/scripts/template_prebuild.js +8 -0
  241. package/resources/templates/hono/scripts/template_watch.js +15 -0
  242. package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
  243. package/resources/templates/hono/src/index.ts +53 -0
  244. package/resources/templates/hono/tsconfig.json +17 -0
  245. package/resources/templates/plain/package-lock.json +4088 -0
  246. package/resources/templates/plain/package.json +10 -0
  247. package/resources/templates/plain/src/index.js +34 -0
@@ -4,18 +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';
16
21
  import { ProgressLog } from '../../util/progress.js';
17
22
  import { loadPurgeTarget, purgeCollection } from '../../util/purge.js';
18
- import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
23
+ import { getStorageKeysByHexPrefix, isVariantInStorage, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
19
24
  // Storage key format:
20
25
  // <publishId>_index_<preview_id>.json
21
26
  // <publishId>_settings_<preview_id>.json
@@ -132,7 +137,7 @@ export async function action(actionArgs) {
132
137
  if (parsed.error != null) {
133
138
  console.error(String(parsed.error));
134
139
  console.error();
135
- process.exitCode = 1;
140
+ recordFailure('usage', String(parsed.error));
136
141
  }
137
142
  help();
138
143
  return;
@@ -142,8 +147,7 @@ export async function action(actionArgs) {
142
147
  if (s3UploadConcurrencyValue !== undefined) {
143
148
  if (typeof s3UploadConcurrencyValue !== 'string' || !/^\d+$/.test(s3UploadConcurrencyValue) ||
144
149
  Number(s3UploadConcurrencyValue) < 1 || Number(s3UploadConcurrencyValue) > 256) {
145
- console.error(`❌ --s3-upload-concurrency must be an integer from 1 to 256.`);
146
- process.exitCode = 1;
150
+ fail('usage', `--s3-upload-concurrency must be an integer from 1 to 256.`);
147
151
  return;
148
152
  }
149
153
  s3UploadConcurrency = Number(s3UploadConcurrencyValue);
@@ -151,7 +155,7 @@ export async function action(actionArgs) {
151
155
  const overwriteExisting = _overwriteExisting ?? _kvOverwrite;
152
156
  // compute-js-static-publisher cli is always run from the Compute application directory
153
157
  // in other words, the directory that contains `fastly.toml`.
154
- const computeAppDir = path.resolve();
158
+ const computeAppDir = getComputeAppDir();
155
159
  console.log(`🚀 Publishing content...`);
156
160
  // #### load config
157
161
  let staticPublisherRc;
@@ -159,20 +163,22 @@ export async function action(actionArgs) {
159
163
  staticPublisherRc = await loadStaticPublisherRcFile();
160
164
  }
161
165
  catch (err) {
162
- console.error("❌ Can't load static-publish.rc.js");
166
+ console.error(`❌ Can't load ${configFileName()}`);
163
167
  console.error("Run this from a compute-js-static-publish compute-js directory.");
164
168
  if (err instanceof LoadConfigError) {
165
169
  for (const error of err.errors) {
166
170
  console.error(error);
167
171
  }
168
172
  }
169
- process.exitCode = 1;
173
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
170
174
  return;
171
175
  }
172
- 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');
173
179
  let publishContentConfig;
174
180
  try {
175
- publishContentConfig = await loadPublishContentConfigFile(configFilePath);
181
+ publishContentConfig = await loadPublishContentConfig(configFilePathValue);
176
182
  }
177
183
  catch (err) {
178
184
  console.error(`❌ Can't load ${configFilePath}`);
@@ -181,15 +187,14 @@ export async function action(actionArgs) {
181
187
  console.error(error);
182
188
  }
183
189
  }
184
- process.exitCode = 1;
190
+ recordFailure('config-invalid', `Can't load ${configFilePath}.`);
185
191
  return;
186
192
  }
187
193
  // --brotli-quality overrides brotliQuality in the config file.
188
194
  let brotliQualitySource = 'config';
189
195
  if (brotliQualityValue !== undefined) {
190
196
  if (typeof brotliQualityValue !== 'string' || !/^\d+$/.test(brotliQualityValue) || Number(brotliQualityValue) > 11) {
191
- console.error(`❌ --brotli-quality must be an integer from 0 to 11.`);
192
- process.exitCode = 1;
197
+ fail('usage', `--brotli-quality must be an integer from 0 to 11.`);
193
198
  return;
194
199
  }
195
200
  publishContentConfig.brotliQuality = Number(brotliQualityValue);
@@ -210,7 +215,7 @@ export async function action(actionArgs) {
210
215
  catch (err) {
211
216
  console.error(`❌ Cannot process expiration time`);
212
217
  console.error(String(err));
213
- process.exitCode = 1;
218
+ recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
214
219
  return;
215
220
  }
216
221
  console.log(`✔️ Public directory '${rootRelative(publicDirRoot)}'.`);
@@ -238,7 +243,7 @@ export async function action(actionArgs) {
238
243
  catch (err) {
239
244
  console.error(`❌ Could not instantiate store provider`);
240
245
  console.error(String(err));
241
- process.exitCode = 1;
246
+ recordFailure(errorCodeOf(err), String(err));
242
247
  return;
243
248
  }
244
249
  // Purge target: checked now, so that a missing API token fails before anything is uploaded.
@@ -248,13 +253,14 @@ export async function action(actionArgs) {
248
253
  localMode: localMode ?? false,
249
254
  computeAppDir,
250
255
  fastlyServiceId,
256
+ projectServiceId: managedProject?.managed.serviceId,
251
257
  fastlyApiToken,
252
258
  purgeEnvironments: purgeEnvironmentValues,
253
259
  });
254
260
  }
255
261
  catch (err) {
256
262
  console.error(String(err));
257
- process.exitCode = 1;
263
+ recordFailure(errorCodeOf(err), String(err));
258
264
  return;
259
265
  }
260
266
  // Load content types
@@ -278,10 +284,20 @@ export async function action(actionArgs) {
278
284
  if (includeWellKnown) {
279
285
  console.log(`✔️ (.well-known is exempt from exclusion.)`);
280
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
+ }
281
294
  // ### Collection name that we're currently publishing
282
295
  // for example, live, staging
283
296
  const collectionName = collectionNameValue ?? process.env.PUBLISHER_COLLECTION_NAME ?? defaultCollectionName;
284
297
  console.log(`✔️ Collection Name: ${collectionName}`);
298
+ if (!await checkCollectionNameForWrite(storageProvider, publishId, collectionName)) {
299
+ return;
300
+ }
285
301
  if (expirationTime == null) {
286
302
  // includes null and undefined
287
303
  console.log(`✔️ Publishing with no expiration timestamp.`);
@@ -319,6 +335,8 @@ export async function action(actionArgs) {
319
335
  // #### Keys that are already in storage
320
336
  // The key of a file is the hash of its content. If the key exists, storage
321
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.
322
340
  // In local mode, a key can refer to a working file that was deleted, so we do not list.
323
341
  // All the keys that the scan looks for start with `<publishId>_files_sha256_` and a hex
324
342
  // hash, so we list them in 16 parts at the same time.
@@ -330,17 +348,6 @@ export async function action(actionArgs) {
330
348
  console.log(`✅ Found ${existingKeys.size} key(s) in ${((Date.now() - listStart) / 1000).toFixed(1)} s.`);
331
349
  }
332
350
  let existingVariantCount = 0;
333
- function isVariantInStorage(variantKey, numChunks) {
334
- if (existingKeys == null || !existingKeys.has(variantKey)) {
335
- return false;
336
- }
337
- for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
338
- if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
339
- return false;
340
- }
341
- }
342
- return true;
343
- }
344
351
  // #### Iterate files
345
352
  const scanProgress = new ProgressLog('Files scanned', verbose);
346
353
  const fileResults = await concurrentMap(files, async (file) => {
@@ -374,9 +381,12 @@ export async function action(actionArgs) {
374
381
  if (!includeAsset) {
375
382
  return;
376
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);
377
387
  // #### Base file size, hash, last modified time
378
388
  const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
379
- scanProgress.add(1, () => `📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
389
+ scanProgress.add(1, () => `📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}${hidden ? ' (hidden)' : ''}`);
380
390
  const stats = fs.statSync(file);
381
391
  const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
382
392
  // We know the number of chunks of the original before we read it. For a
@@ -392,7 +402,8 @@ export async function action(actionArgs) {
392
402
  // Returns true if the index keeps the variant.
393
403
  async function prepareVariant(variant, variantKey, variantFilePath) {
394
404
  if ((variant === 'original' || baseNumChunks === 1) &&
395
- isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
405
+ existingKeys != null &&
406
+ await isVariantInStorage(storageProvider, existingKeys, variantKey, baseSize, variant === 'original' ? baseNumChunks : 1)) {
396
407
  if (verbose) {
397
408
  console.log(` ・ Asset found in storage with key "${variantKey}".`);
398
409
  }
@@ -458,6 +469,7 @@ export async function action(actionArgs) {
458
469
  }
459
470
  return {
460
471
  assetKey,
472
+ hidden,
461
473
  asset: {
462
474
  key: `sha256:${baseHash}`,
463
475
  size: baseSize,
@@ -468,16 +480,24 @@ export async function action(actionArgs) {
468
480
  batchItems,
469
481
  };
470
482
  });
483
+ let hiddenCount = 0;
471
484
  for (const result of fileResults) {
472
485
  if (result == null) {
473
486
  continue;
474
487
  }
475
- 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
+ }
476
495
  for (const batchItem of result.batchItems) {
477
496
  batch.add(batchItem);
478
497
  }
479
498
  }
480
499
  console.log(`✅ Scan complete.`);
500
+ console.log(` | ${Object.keys(assetsIndex).length} file(s) in the index, ${hiddenCount} of them hidden.`);
481
501
  if (existingKeys != null) {
482
502
  console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
483
503
  }
@@ -491,6 +511,8 @@ export async function action(actionArgs) {
491
511
  const indexMetadata = {
492
512
  publishedTime: Math.floor(Date.now() / 1000),
493
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,
494
516
  };
495
517
  const indexFileName = `index_${collectionName}.json`;
496
518
  const indexFilePath = path.resolve(storageContentDir, indexFileName);
@@ -519,7 +541,7 @@ export async function action(actionArgs) {
519
541
  let spaFile = server.spaFile;
520
542
  if (spaFile != null) {
521
543
  console.log(` ✔️ Application SPA file '${spaFile}'.`);
522
- const spaAsset = assetsIndex[spaFile];
544
+ const spaAsset = findAssetEntry(assetsIndex, spaFile, true);
523
545
  if (spaAsset == null || spaAsset.contentType !== 'text/html') {
524
546
  if (verbose) {
525
547
  console.log(` ⚠️ Notice: '${spaFile}' does not exist or is not of type 'text/html'. Ignoring.`);
@@ -535,7 +557,7 @@ export async function action(actionArgs) {
535
557
  let notFoundPageFile = server.notFoundPageFile;
536
558
  if (notFoundPageFile != null) {
537
559
  console.log(` ✔️ Application 'not found (404)' file '${notFoundPageFile}'.`);
538
- const notFoundPageAsset = assetsIndex[notFoundPageFile];
560
+ const notFoundPageAsset = findAssetEntry(assetsIndex, notFoundPageFile, true);
539
561
  if (notFoundPageAsset == null || notFoundPageAsset.contentType !== 'text/html') {
540
562
  if (verbose) {
541
563
  console.log(` ⚠️ Notice: '${notFoundPageFile}' does not exist or is not of type 'text/html'. Ignoring.`);
@@ -564,8 +586,31 @@ export async function action(actionArgs) {
564
586
  const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
565
587
  await storageProvider.submitStorageEntry(settingsFileKey, settingsFilePath, JSON.stringify(serverSettings));
566
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 = [];
567
591
  if (purgeTarget != null) {
568
- await purgeCollection(purgeTarget, publishId, collectionName);
592
+ purgeResults.push(...await purgeCollection(purgeTarget, publishId, collectionName));
569
593
  }
570
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
+ });
571
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"}