@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
@@ -0,0 +1,162 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import child_process from 'node:child_process';
6
+ import crypto from 'node:crypto';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import { normalizePublishContentConfig } from '../util/config.js';
10
+ import { MANAGED_APP_DIR } from '../../models/config/static-publish-project.js';
11
+ import { isS3StorageConfigRc } from '../../models/config/static-publish-rc.js';
12
+ import { generateApp } from '../commands/scaffold/generate-app.js';
13
+ import { DEFAULT_APP_TEMPLATE_NAME, loadAppTemplate } from '../commands/scaffold/app-template.js';
14
+ import { ConfigError, isJsonMode } from '../util/output.js';
15
+ import { getOwnPackageDir, getOwnVersion, readOwnPackageJson } from '../util/package.js';
16
+ import { computeFingerprint, managedAppFiles } from './fingerprint.js';
17
+ import { findHostnameForAwsS3RegionAndBucket } from '../util/s3.js';
18
+ import { appConfigFromProject } from './project-file.js';
19
+ import { buildManagedLockfile, managedPackageSpec, readTemplateLockfile } from './lockfile.js';
20
+ // The app config of a managed project, with the lockfile and the `file:` link
21
+ // to the copy of this package that runs the CLI.
22
+ // appDir is .static-publish/app, unless eject gives another one.
23
+ export async function managedAppConfig(projectDir, project, appDirOverride) {
24
+ const errors = [];
25
+ const publishContent = normalizePublishContentConfig(project.publishContent, errors);
26
+ if (publishContent == null || errors.length > 0) {
27
+ throw new ConfigError(`publishContent is not valid:\n${errors.join('\n')}`);
28
+ }
29
+ let s3EndpointUrl;
30
+ if (isS3StorageConfigRc(project.rc) && project.rc.s3.endpoint == null) {
31
+ const hostname = await findHostnameForAwsS3RegionAndBucket(project.rc.s3.region, project.rc.s3.bucket);
32
+ s3EndpointUrl = String(new URL(`https://${hostname}/`));
33
+ }
34
+ const appDir = appDirOverride ?? path.resolve(projectDir, MANAGED_APP_DIR);
35
+ const cliPackageDir = getOwnPackageDir();
36
+ const templateName = project.managed.template ?? DEFAULT_APP_TEMPLATE_NAME;
37
+ const appConfig = appConfigFromProject(project.rc, publishContent, project.managed, {
38
+ projectDir,
39
+ appDir,
40
+ staticPublishVersionSpec: managedPackageSpec(cliPackageDir),
41
+ template: loadAppTemplate(templateName),
42
+ s3EndpointUrl,
43
+ });
44
+ const lock = buildManagedLockfile(readTemplateLockfile(templateName), {
45
+ appName: appConfig.name,
46
+ appVersion: JSON.parse(generateApp(appConfig)['package.json']).version,
47
+ appDir,
48
+ cliPackageDir,
49
+ cliPackageJson: readOwnPackageJson(),
50
+ });
51
+ return { ...appConfig, packageLock: JSON.stringify(lock, undefined, 2) + '\n' };
52
+ }
53
+ // Write the files of the app. A file in the app dir is written again if it
54
+ // changed. A file outside the app dir (the local KV Store file in the working
55
+ // dir) is written only if it does not exist, so that the local data stays.
56
+ export function writeManagedAppFiles(appDir, files) {
57
+ const written = [];
58
+ for (const [file, content] of Object.entries(files)) {
59
+ const filePath = path.resolve(appDir, file);
60
+ const inApp = !path.relative(appDir, filePath).startsWith('..');
61
+ if (fs.existsSync(filePath)) {
62
+ if (!inApp || fs.readFileSync(filePath, 'utf-8') === content) {
63
+ continue;
64
+ }
65
+ }
66
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
67
+ fs.writeFileSync(filePath, content, 'utf-8');
68
+ written.push(file);
69
+ }
70
+ return written;
71
+ }
72
+ // The install stamp is in node_modules, so that it goes away with it.
73
+ const INSTALL_STAMP = 'node_modules/.compute-js-static-publish-install';
74
+ function installHash(appDir) {
75
+ const hash = crypto.createHash('sha256');
76
+ for (const file of ['package.json', 'package-lock.json']) {
77
+ hash.update(fs.readFileSync(path.resolve(appDir, file)));
78
+ hash.update('\0');
79
+ }
80
+ return hash.digest('hex');
81
+ }
82
+ export function needsInstall(appDir) {
83
+ const stampPath = path.resolve(appDir, INSTALL_STAMP);
84
+ return !fs.existsSync(stampPath) || fs.readFileSync(stampPath, 'utf-8') !== installHash(appDir);
85
+ }
86
+ // Run `npm ci` in the app dir, only if package.json or package-lock.json
87
+ // changed since the last install. Returns true if it installed.
88
+ export function installManagedApp(appDir) {
89
+ if (!needsInstall(appDir)) {
90
+ return false;
91
+ }
92
+ console.log(`📦 Installing the dependencies of the app (npm ci)...`);
93
+ const result = child_process.spawnSync('npm', ['ci', '--no-audit', '--no-fund'], {
94
+ cwd: appDir,
95
+ // With --json, stdout is for the JSON object only.
96
+ stdio: ['ignore', isJsonMode() ? process.stderr : 'inherit', 'inherit'],
97
+ });
98
+ if (result.error != null || result.status !== 0) {
99
+ throw new Error(`npm ci failed in ${appDir}.`);
100
+ }
101
+ fs.writeFileSync(path.resolve(appDir, INSTALL_STAMP), installHash(appDir), 'utf-8');
102
+ return true;
103
+ }
104
+ // The files and the fingerprint of the app of a managed project, in memory.
105
+ // The files of a folder that the app's build reads, keyed by a path that starts
106
+ // with prefix, for the fingerprint: all files, also the lockfile, but not
107
+ // node_modules (the lockfile pins it). Binary files are read as base64.
108
+ export function folderFilesForFingerprint(dir, prefix) {
109
+ const result = {};
110
+ if (!fs.existsSync(dir)) {
111
+ return result;
112
+ }
113
+ const walk = (sub) => {
114
+ for (const entry of fs.readdirSync(path.resolve(dir, sub), { withFileTypes: true })) {
115
+ const rel = sub === '' ? entry.name : `${sub}/${entry.name}`;
116
+ if (entry.isDirectory()) {
117
+ if (entry.name !== 'node_modules' && entry.name !== '.git') {
118
+ walk(rel);
119
+ }
120
+ }
121
+ else if (entry.isFile()) {
122
+ result[`${prefix}/${rel}`] = fs.readFileSync(path.resolve(dir, rel)).toString('base64');
123
+ }
124
+ }
125
+ };
126
+ walk('');
127
+ return result;
128
+ }
129
+ export async function managedAppState(projectDir, project) {
130
+ const appConfig = await managedAppConfig(projectDir, project);
131
+ const files = managedAppFiles(generateApp(appConfig));
132
+ // managed.fastlyToml.local_server is only for fastly compute serve. It does
133
+ // not change what deploy deploys, so the fingerprint does not include it.
134
+ const deployedFiles = appConfig.fastlyToml?.local_server != null ?
135
+ managedAppFiles(generateApp({ ...appConfig, fastlyToml: { ...appConfig.fastlyToml, local_server: undefined } })) :
136
+ files;
137
+ const cliPackageDir = getOwnPackageDir();
138
+ // The extensions folder of the hono template is part of the app that deploy
139
+ // deploys, so a change to it changes the fingerprint.
140
+ const extensionsDir = appConfig.build?.hono?.extensionsDir;
141
+ const fingerprintFiles = extensionsDir != null ?
142
+ { ...deployedFiles, ...folderFilesForFingerprint(extensionsDir, '<hono-extensions>') } :
143
+ deployedFiles;
144
+ const fingerprint = computeFingerprint(fingerprintFiles, {
145
+ staticPublishVersion: getOwnVersion(),
146
+ template: appConfig.template.name,
147
+ machinePaths: [cliPackageDir, path.relative(appConfig.appDir, cliPackageDir).split(path.sep).join('/')],
148
+ });
149
+ return { appDir: appConfig.appDir, appConfig, files, fingerprint };
150
+ }
151
+ // Generate the app of a managed project in .static-publish/app, and install
152
+ // its dependencies if necessary.
153
+ export async function prepareManagedApp(projectDir, project) {
154
+ const { appConfig, files, fingerprint } = await managedAppState(projectDir, project);
155
+ console.log(`🛠️ Generating the app in ${MANAGED_APP_DIR}...`);
156
+ const written = writeManagedAppFiles(appConfig.appDir, files);
157
+ if (written.length > 0) {
158
+ console.log(` | Wrote ${written.join(', ')}`);
159
+ }
160
+ const installed = installManagedApp(appConfig.appDir);
161
+ return { appDir: appConfig.appDir, appConfig, files, fingerprint, installed };
162
+ }
@@ -0,0 +1,6 @@
1
+ import { type StaticPublishProjectNormalized } from '../util/config.js';
2
+ export declare function loadManagedProject(command: string, ejectedHint: string): Promise<StaticPublishProjectNormalized | null>;
3
+ export declare function showTemplateFolderHint(project: StaticPublishProjectNormalized): void;
4
+ export declare function checkVersionForCommand(project: StaticPublishProjectNormalized, autoUpgrade: boolean): boolean;
5
+ export declare function writeProjectVersion(version: string): boolean;
6
+ //# sourceMappingURL=command-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-helpers.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/command-helpers.ts"],"names":[],"mappings":"AASA,OAAO,EAAmB,KAAK,8BAA8B,EAAsC,MAAM,mBAAmB,CAAC;AAS7H,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,GAAG,IAAI,CAAC,CAmB7H;AAID,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,8BAA8B,QAQ7E;AAKD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,8BAA8B,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAe7G;AAGD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAY5D"}
@@ -0,0 +1,81 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { PROJECT_FILE_NAME } from '../../models/config/static-publish-project.js';
8
+ import { LoadConfigError, detectProjectMode, loadProjectFile } from '../util/config.js';
9
+ import { getOwnVersion } from '../util/package.js';
10
+ import { DEFAULT_APP_TEMPLATE_NAME } from '../commands/scaffold/app-template.js';
11
+ import { DEFAULT_HONO_EXTENSIONS_DIR } from '../hono/build.js';
12
+ import { writeBackStaticPublishVersion } from './project-edit.js';
13
+ import { checkProjectVersion, versionCheckError } from './version-check.js';
14
+ import { fail, recordFailure } from '../util/output.js';
15
+ // Load the project file of a managed project, or report why not.
16
+ export async function loadManagedProject(command, ejectedHint) {
17
+ if (detectProjectMode() !== 'managed') {
18
+ fail('usage', `'${command}' works only in a managed project (${PROJECT_FILE_NAME}). ${ejectedHint}`);
19
+ return null;
20
+ }
21
+ try {
22
+ return await loadProjectFile();
23
+ }
24
+ catch (err) {
25
+ console.error(`❌ Can't load ${PROJECT_FILE_NAME}`);
26
+ if (err instanceof LoadConfigError) {
27
+ for (const error of err.errors) {
28
+ console.error(error);
29
+ }
30
+ }
31
+ else {
32
+ console.error(String(err));
33
+ }
34
+ recordFailure('config-invalid', `Can't load ${PROJECT_FILE_NAME}.`);
35
+ return null;
36
+ }
37
+ }
38
+ // For the hono template: a hint when the extensions folder does not exist. The
39
+ // app works without it.
40
+ export function showTemplateFolderHint(project) {
41
+ if ((project.managed.template ?? DEFAULT_APP_TEMPLATE_NAME) !== 'hono') {
42
+ return;
43
+ }
44
+ const extensionsDir = project.rc.build?.hono?.extensionsDir ?? DEFAULT_HONO_EXTENSIONS_DIR;
45
+ if (!fs.existsSync(path.resolve(extensionsDir))) {
46
+ console.log(`💡 No ${extensionsDir} folder. To add your own Hono middleware and routes, run: npx @fastly/compute-js-static-publish template init`);
47
+ }
48
+ }
49
+ // Check managed.staticPublishVersion against the running CLI. With
50
+ // autoUpgrade, a newer CLI writes its version into the project file. Returns
51
+ // false (and reports the error) if the command must stop.
52
+ export function checkVersionForCommand(project, autoUpgrade) {
53
+ const check = checkProjectVersion(project.managed.staticPublishVersion, getOwnVersion());
54
+ const error = versionCheckError(check, autoUpgrade);
55
+ if (error != null) {
56
+ fail('version-mismatch', error);
57
+ return false;
58
+ }
59
+ if (check.result === 'newer-cli' && autoUpgrade) {
60
+ if (!writeProjectVersion(check.running)) {
61
+ return false;
62
+ }
63
+ console.log(`✔️ --auto-upgrade: the project now uses ${check.running} (was ${check.recorded}).`);
64
+ project.managed.staticPublishVersion = check.running;
65
+ }
66
+ return true;
67
+ }
68
+ // Write managed.staticPublishVersion into the project file.
69
+ export function writeProjectVersion(version) {
70
+ const filePath = path.resolve(PROJECT_FILE_NAME);
71
+ const text = fs.readFileSync(filePath, 'utf-8');
72
+ const updated = writeBackStaticPublishVersion(text, version);
73
+ if (updated == null) {
74
+ fail('config-invalid', `Can't find the line 'staticPublishVersion: "…",' in the managed section of ${PROJECT_FILE_NAME}. Set it by hand to "${version}".`);
75
+ return false;
76
+ }
77
+ if (updated !== text) {
78
+ fs.writeFileSync(filePath, updated, 'utf-8');
79
+ }
80
+ return true;
81
+ }
@@ -0,0 +1,6 @@
1
+ import { type AppConfig } from '../commands/scaffold/generate-app.js';
2
+ export declare function findNonDataPaths(value: unknown, at?: string): string[];
3
+ export declare function scaffoldedPublishContent(config: AppConfig, baseDir: string): Record<string, unknown>;
4
+ export declare function isScaffoldedPublishContent(raw: unknown, config: AppConfig, projectDir: string): boolean;
5
+ export declare function renderPublishContentConfig(raw: Record<string, unknown>, projectDir: string, appDir: string): string;
6
+ //# sourceMappingURL=eject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eject.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/eject.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAWtE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,GAAE,MAAW,GAAG,MAAM,EAAE,CAW1E;AAKD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkBpG;AAWD,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAEvG;AAKD,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMnH"}
@@ -0,0 +1,68 @@
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 { renderAppResource } from '../commands/scaffold/render.js';
7
+ import { dotRelative } from '../util/files.js';
8
+ // eject converts the publishContent section of the project file into
9
+ // compute-js/publish-content.config.js. A JavaScript file cannot be split
10
+ // without a parser, so eject works on the loaded value: it can write data
11
+ // (strings, numbers, booleans, null, arrays, and plain objects), but not
12
+ // functions or regular expressions.
13
+ // The paths in the value that are not data, for example 'assetInclusionTest'.
14
+ export function findNonDataPaths(value, at = '') {
15
+ if (value === null || value === undefined || ['string', 'number', 'boolean'].includes(typeof value)) {
16
+ return [];
17
+ }
18
+ if (Array.isArray(value)) {
19
+ return value.flatMap((x, i) => findNonDataPaths(x, `${at}[${i}]`));
20
+ }
21
+ if (typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
22
+ return Object.entries(value).flatMap(([k, v]) => findNonDataPaths(v, at === '' ? k : `${at}.${k}`));
23
+ }
24
+ return [at === '' ? '(publishContent)' : at];
25
+ }
26
+ // The publishContent that scaffold --managed writes for an app config, with
27
+ // paths relative to baseDir. If the section of a project is equal to it, eject
28
+ // writes the same publish-content.config.js as an ejected scaffold.
29
+ export function scaffoldedPublishContent(config, baseDir) {
30
+ const publicDirPrefix = config.publicDir !== config.rootDir ? config.publicDir.slice(config.rootDir.length).split(path.sep).join('/') : '';
31
+ const assetKey = (file) => file != null ? file.slice(config.rootDir.length).split(path.sep).join('/') : false;
32
+ return {
33
+ rootDir: dotRelative(baseDir, config.rootDir).split(path.sep).join('/'),
34
+ server: {
35
+ ...(publicDirPrefix !== '' ? { publicDirPrefix } : {}),
36
+ staticItems: config.staticDirs.map(dir => {
37
+ const item = dir.slice(config.publicDir.length).split(path.sep).join('/');
38
+ return item.endsWith('/') ? item : item + '/';
39
+ }),
40
+ allowedEncodings: ['br', 'gzip'],
41
+ spaFile: assetKey(config.spaFilename),
42
+ notFoundPageFile: assetKey(config.notFoundPageFilename),
43
+ autoExt: config.autoExt,
44
+ autoIndex: config.autoIndex,
45
+ },
46
+ };
47
+ }
48
+ function canonical(value) {
49
+ return JSON.stringify(value, (_key, v) => {
50
+ if (v != null && typeof v === 'object' && !Array.isArray(v)) {
51
+ return Object.fromEntries(Object.keys(v).sort().filter(k => v[k] !== undefined).map(k => [k, v[k]]));
52
+ }
53
+ return v;
54
+ });
55
+ }
56
+ export function isScaffoldedPublishContent(raw, config, projectDir) {
57
+ return canonical(raw) === canonical(scaffoldedPublishContent(config, projectDir));
58
+ }
59
+ // publish-content.config.js for a publishContent section that is data. Paths
60
+ // are written again relative to the new directory, so that they point at the
61
+ // same directories.
62
+ export function renderPublishContentConfig(raw, projectDir, appDir) {
63
+ const value = { ...raw };
64
+ if (typeof value.rootDir === 'string') {
65
+ value.rootDir = dotRelative(appDir, path.resolve(projectDir, value.rootDir)).split(path.sep).join('/');
66
+ }
67
+ return renderAppResource('publish-content.config.from-project.js', { config: value });
68
+ }
@@ -0,0 +1,8 @@
1
+ import { type FastlyApiContext } from '../util/api-token.js';
2
+ export type ActiveVersion = {
3
+ number: number;
4
+ comment: string | null;
5
+ };
6
+ export declare function getActiveVersion(context: FastlyApiContext, serviceId: string): Promise<ActiveVersion | null>;
7
+ export declare function getVersionDomains(context: FastlyApiContext, serviceId: string, version: number): Promise<string[]>;
8
+ //# sourceMappingURL=fastly-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fastly-service.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/fastly-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,gBAAgB,EAAiB,MAAM,sBAAsB,CAAC;AAE5E,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAGF,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAQlH;AAGD,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAIxH"}
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { callFastlyApi } from '../util/api-token.js';
6
+ // The active version of a service, or null if no version is active.
7
+ export async function getActiveVersion(context, serviceId) {
8
+ const response = await callFastlyApi(context, `/service/${encodeURIComponent(serviceId)}/details`, 'Get service details');
9
+ const details = await response.json();
10
+ const active = details.active_version;
11
+ if (active == null || typeof active.number !== 'number') {
12
+ return null;
13
+ }
14
+ return { number: active.number, comment: active.comment ?? null };
15
+ }
16
+ // The domains of a service version.
17
+ export async function getVersionDomains(context, serviceId, version) {
18
+ const response = await callFastlyApi(context, `/service/${encodeURIComponent(serviceId)}/version/${version}/domain`, 'List domains');
19
+ const domains = await response.json();
20
+ return domains.flatMap(x => typeof x.name === 'string' ? [x.name] : []);
21
+ }
@@ -0,0 +1,13 @@
1
+ export declare function managedAppFiles(files: Record<string, string>): Record<string, string>;
2
+ export type FingerprintOptions = {
3
+ staticPublishVersion: string;
4
+ template: string;
5
+ machinePaths: string[];
6
+ };
7
+ export declare function computeFingerprint(files: Record<string, string>, options: FingerprintOptions): string;
8
+ export declare function formatVersionComment(staticPublishVersion: string, fingerprint: string, userComment?: string): string;
9
+ export declare function parseVersionComment(comment: string | null | undefined): {
10
+ staticPublishVersion: string;
11
+ fingerprint: string;
12
+ } | null;
13
+ //# sourceMappingURL=fingerprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/fingerprint.ts"],"names":[],"mappings":"AAkBA,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIrF;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IAGjB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CA2BrG;AAGD,wBAAgB,oBAAoB,CAAC,oBAAoB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAGpH;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG;IAAE,oBAAoB,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAMpI"}
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import crypto from 'node:crypto';
6
+ // The fingerprint of a managed app: a SHA-256 over the generated files and the
7
+ // version of this package. If it is the same as the fingerprint of the active
8
+ // service version, a deploy is not necessary. It does not depend on:
9
+ // - the service ID (fastly.toml gets it after the first deploy),
10
+ // - generatedFrom (a date),
11
+ // - the path of this package on the machine (the `file:` link),
12
+ // - the publishContent section (the app does not have publish-content.config.js),
13
+ // - the content.
14
+ // The files of a managed app: generateApp() makes them, without
15
+ // publish-content.config.js. A managed app publishes from the project file.
16
+ export function managedAppFiles(files) {
17
+ const result = { ...files };
18
+ delete result['publish-content.config.js'];
19
+ return result;
20
+ }
21
+ export function computeFingerprint(files, options) {
22
+ // The longest first, so that a path that contains another path is replaced whole.
23
+ const machinePaths = [...options.machinePaths].filter(x => x !== '').sort((a, b) => b.length - a.length);
24
+ const normalized = Object.entries(files)
25
+ .map(([file, content]) => {
26
+ let text = content;
27
+ for (const machinePath of machinePaths) {
28
+ text = text.split(machinePath).join('<compute-js-static-publish>');
29
+ }
30
+ if (file === 'fastly.toml') {
31
+ text = text.replace(/^service_id = .*\n/m, '');
32
+ }
33
+ // A managed app has no generatedFrom. The date in it would change the
34
+ // fingerprint each day, so it is removed if it is there.
35
+ if (file === 'static-publish.rc.js') {
36
+ text = text.replace(/^ {2}generatedFrom: \{\n[\s\S]*?^ {2}\},\n/m, '');
37
+ }
38
+ return [file, text];
39
+ })
40
+ .sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
41
+ return crypto.createHash('sha256')
42
+ .update(JSON.stringify({
43
+ staticPublishVersion: options.staticPublishVersion,
44
+ template: options.template,
45
+ files: normalized,
46
+ }))
47
+ .digest('hex');
48
+ }
49
+ // The comment of the service version that deploy makes. status reads it back.
50
+ export function formatVersionComment(staticPublishVersion, fingerprint, userComment) {
51
+ const comment = `static-publish ${staticPublishVersion} fp:${fingerprint}`;
52
+ return userComment != null && userComment.trim() !== '' ? `${comment} | ${userComment.trim()}` : comment;
53
+ }
54
+ export function parseVersionComment(comment) {
55
+ const match = /(?:^|\s)static-publish (\S+) fp:([0-9a-f]{64})(?:\s|$)/.exec(comment ?? '');
56
+ if (match == null) {
57
+ return null;
58
+ }
59
+ return { staticPublishVersion: match[1], fingerprint: match[2] };
60
+ }
@@ -0,0 +1,31 @@
1
+ export declare const THIS_PACKAGE = "@fastly/compute-js-static-publish";
2
+ export type PackageLock = {
3
+ name?: string;
4
+ version?: string;
5
+ lockfileVersion: number;
6
+ requires?: boolean;
7
+ packages: Record<string, Record<string, unknown>>;
8
+ };
9
+ type PackageJsonFields = {
10
+ version?: string;
11
+ license?: string;
12
+ dependencies?: Record<string, string>;
13
+ devDependencies?: Record<string, string>;
14
+ peerDependencies?: Record<string, string>;
15
+ bin?: Record<string, string> | string;
16
+ engines?: Record<string, string>;
17
+ };
18
+ export declare function templateLockfilePath(templateName: string): string;
19
+ export declare function readTemplateLockfile(templateName: string): PackageLock;
20
+ export declare function pinnedVersion(templateName: string, packageName: string): string | undefined;
21
+ export type ManagedLockfileOptions = {
22
+ appName: string | undefined;
23
+ appVersion: string;
24
+ appDir: string;
25
+ cliPackageDir: string;
26
+ cliPackageJson: PackageJsonFields;
27
+ };
28
+ export declare function managedPackageSpec(cliPackageDir: string): string;
29
+ export declare function buildManagedLockfile(templateLock: PackageLock, options: ManagedLockfileOptions): PackageLock;
30
+ export {};
31
+ //# sourceMappingURL=lockfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lockfile.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/lockfile.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,YAAY,sCAAsC,CAAC;AAEhE,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,WAAW,CAEtE;AAKD,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG3F;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IAEf,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,iBAAiB,CAAC;CACnC,CAAC;AAGF,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEhE;AAID,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,sBAAsB,GAAG,WAAW,CAiC5G"}
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { getOwnPackageDir } from '../util/package.js';
8
+ // The lockfile of a template (resources/templates/<name>/package-lock.json)
9
+ // pins the dependencies of the generated app: the compiler toolchain and the
10
+ // packages below it. It does not list this package. The generated app gets this
11
+ // package as a `file:` link to the copy that runs the CLI, because it must be
12
+ // exactly that version, and a lockfile in this package cannot list it.
13
+ export const THIS_PACKAGE = '@fastly/compute-js-static-publish';
14
+ export function templateLockfilePath(templateName) {
15
+ return path.resolve(getOwnPackageDir(), 'resources/templates', templateName, 'package-lock.json');
16
+ }
17
+ export function readTemplateLockfile(templateName) {
18
+ return JSON.parse(fs.readFileSync(templateLockfilePath(templateName), 'utf-8'));
19
+ }
20
+ // The version that a template's lockfile pins for a package, for example
21
+ // '@fastly/js-compute'. Code that needs this version uses only this helper, so
22
+ // that the way that templates pin versions can change in one place.
23
+ export function pinnedVersion(templateName, packageName) {
24
+ const entry = readTemplateLockfile(templateName).packages[`node_modules/${packageName}`];
25
+ return typeof entry?.version === 'string' ? entry.version : undefined;
26
+ }
27
+ // The spec of this package in the package.json of a managed app.
28
+ export function managedPackageSpec(cliPackageDir) {
29
+ return `file:${cliPackageDir}`;
30
+ }
31
+ // The lockfile of a managed app: the template's lockfile, with the `file:` link
32
+ // to this package added. `npm ci` accepts it, and does not change it.
33
+ export function buildManagedLockfile(templateLock, options) {
34
+ const lock = JSON.parse(JSON.stringify(templateLock));
35
+ const linkPath = path.relative(options.appDir, options.cliPackageDir).split(path.sep).join('/');
36
+ const spec = managedPackageSpec(options.cliPackageDir);
37
+ if (options.appName != null) {
38
+ lock.name = options.appName;
39
+ }
40
+ lock.version = options.appVersion;
41
+ const root = lock.packages[''] ?? {};
42
+ if (options.appName != null) {
43
+ root.name = options.appName;
44
+ }
45
+ root.version = options.appVersion;
46
+ root.devDependencies = { ...root.devDependencies, [THIS_PACKAGE]: spec };
47
+ lock.packages[''] = root;
48
+ lock.packages[`node_modules/${THIS_PACKAGE}`] = {
49
+ resolved: linkPath,
50
+ link: true,
51
+ };
52
+ const pkg = options.cliPackageJson;
53
+ const target = {};
54
+ for (const field of ['version', 'license', 'dependencies', 'bin', 'devDependencies', 'engines', 'peerDependencies']) {
55
+ if (pkg[field] != null) {
56
+ target[field] = pkg[field];
57
+ }
58
+ }
59
+ target.dev = true;
60
+ lock.packages[linkPath] = target;
61
+ return lock;
62
+ }
@@ -0,0 +1,3 @@
1
+ export declare function writeBackServiceId(text: string, serviceId: string): string | null;
2
+ export declare function writeBackStaticPublishVersion(text: string, version: string): string | null;
3
+ //# sourceMappingURL=project-edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-edit.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/project-edit.ts"],"names":[],"mappings":"AAgBA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjF;AAQD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ1F"}
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { SERVICE_ID_PLACEHOLDER_LINE } from './project-file.js';
6
+ // The CLI writes values back into static-publish.project.js only by replacing
7
+ // one known line. It never changes other JavaScript. Each function returns the
8
+ // new text, or null if the line is not there (exactly one time).
9
+ function countMatches(text, re) {
10
+ return [...text.matchAll(new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g'))].length;
11
+ }
12
+ // Replace the marked line ` serviceId: undefined,` that scaffold --managed wrote.
13
+ export function writeBackServiceId(text, serviceId) {
14
+ const lines = text.split('\n');
15
+ const indexes = lines.flatMap((line, i) => line === SERVICE_ID_PLACEHOLDER_LINE ? [i] : []);
16
+ if (indexes.length !== 1) {
17
+ return null;
18
+ }
19
+ lines[indexes[0]] = ` serviceId: ${JSON.stringify(serviceId)},`;
20
+ return lines.join('\n');
21
+ }
22
+ const VERSION_LINE = /^([ \t]*)staticPublishVersion:[ \t]*(["'])[^"'\n]*\2,[ \t]*$/m;
23
+ const ANY_VERSION_LINE = /^[ \t]*staticPublishVersion[ \t]*:/m;
24
+ const MANAGED_LINE = /^([ \t]*)managed:[ \t]*\{[ \t]*$/m;
25
+ // Set managed.staticPublishVersion. If the line is missing, add it as the first
26
+ // line of the managed section.
27
+ export function writeBackStaticPublishVersion(text, version) {
28
+ if (countMatches(text, VERSION_LINE) === 1) {
29
+ return text.replace(VERSION_LINE, (_line, indent) => `${indent}staticPublishVersion: ${JSON.stringify(version)},`);
30
+ }
31
+ if (countMatches(text, ANY_VERSION_LINE) === 0 && countMatches(text, MANAGED_LINE) === 1) {
32
+ return text.replace(MANAGED_LINE, (line, indent) => `${line}\n${indent} staticPublishVersion: ${JSON.stringify(version)},`);
33
+ }
34
+ return null;
35
+ }
@@ -0,0 +1,16 @@
1
+ import { type PublishContentConfigNormalized } from '../../models/config/publish-content-config.js';
2
+ import { type StaticPublishProjectManaged } from '../../models/config/static-publish-project.js';
3
+ import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
4
+ import { type AppTemplate } from '../commands/scaffold/app-template.js';
5
+ import { type AppConfig } from '../commands/scaffold/generate-app.js';
6
+ export declare const SERVICE_ID_PLACEHOLDER_LINE = " serviceId: undefined,";
7
+ export declare function renderProjectFile(config: AppConfig, projectDir: string, staticPublishVersion: string): string;
8
+ export type AppConfigFromProjectOptions = {
9
+ projectDir: string;
10
+ appDir: string;
11
+ staticPublishVersionSpec: string;
12
+ template: AppTemplate;
13
+ s3EndpointUrl?: string;
14
+ };
15
+ export declare function appConfigFromProject(rc: StaticPublishRc, publishContent: PublishContentConfigNormalized, managed: StaticPublishProjectManaged, options: AppConfigFromProjectOptions): AppConfig;
16
+ //# sourceMappingURL=project-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-file.d.ts","sourceRoot":"","sources":["../../../../src/cli/managed/project-file.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,KAAK,eAAe,EAA0D,MAAM,0CAA0C,CAAC;AAGxI,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAMtE,eAAO,MAAM,2BAA2B,8BAA8B,CAAC;AAKvE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAyC7G;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB,EAAE,MAAM,CAAC;IACjC,QAAQ,EAAE,WAAW,CAAC;IAGtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,eAAe,EACnB,cAAc,EAAE,8BAA8B,EAC9C,OAAO,EAAE,2BAA2B,EACpC,OAAO,EAAE,2BAA2B,GACnC,SAAS,CA6DX"}