@ohos-ports/layer0-prefetch 4.20.0-beta.0 → 4.20.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 (281) hide show
  1. package/node_modules/@layer0/core/README.md +50 -0
  2. package/node_modules/@layer0/core/build.d.ts +5 -0
  3. package/node_modules/@layer0/core/build.js +17 -0
  4. package/node_modules/@layer0/core/cache/Cache.d.ts +56 -0
  5. package/node_modules/@layer0/core/cache/Cache.js +138 -0
  6. package/node_modules/@layer0/core/cache/CacheKey.d.ts +52 -0
  7. package/node_modules/@layer0/core/cache/CacheKey.js +95 -0
  8. package/node_modules/@layer0/core/config.d.ts +53 -0
  9. package/node_modules/@layer0/core/config.js +113 -0
  10. package/node_modules/@layer0/core/constants.d.ts +214 -0
  11. package/node_modules/@layer0/core/constants.js +216 -0
  12. package/node_modules/@layer0/core/context.d.ts +38 -0
  13. package/node_modules/@layer0/core/context.js +98 -0
  14. package/node_modules/@layer0/core/default-app/all/layer0.config.js +60 -0
  15. package/node_modules/@layer0/core/default-app/js/routes.js +27 -0
  16. package/node_modules/@layer0/core/default-app/ts/routes.ts +27 -0
  17. package/node_modules/@layer0/core/deploy/DeploymentBuilder.d.ts +177 -0
  18. package/node_modules/@layer0/core/deploy/DeploymentBuilder.js +543 -0
  19. package/node_modules/@layer0/core/deploy/bundle-esbuild.d.ts +11 -0
  20. package/node_modules/@layer0/core/deploy/bundle-esbuild.js +67 -0
  21. package/node_modules/@layer0/core/deploy/bundle-ncc.d.ts +8 -0
  22. package/node_modules/@layer0/core/deploy/bundle-ncc.js +30 -0
  23. package/node_modules/@layer0/core/deploy/bundle-nft.d.ts +7 -0
  24. package/node_modules/@layer0/core/deploy/bundle-nft.js +41 -0
  25. package/node_modules/@layer0/core/deploy/bundle-webpack.d.ts +11 -0
  26. package/node_modules/@layer0/core/deploy/bundle-webpack.js +127 -0
  27. package/node_modules/@layer0/core/deploy/index.d.ts +19 -0
  28. package/node_modules/@layer0/core/deploy/index.js +6 -0
  29. package/node_modules/@layer0/core/deploy/listSources.d.ts +11 -0
  30. package/node_modules/@layer0/core/deploy/listSources.js +18 -0
  31. package/node_modules/@layer0/core/deploy/paths.d.ts +27 -0
  32. package/node_modules/@layer0/core/deploy/paths.js +33 -0
  33. package/node_modules/@layer0/core/deploy/resolveInPackage.d.ts +7 -0
  34. package/node_modules/@layer0/core/deploy/resolveInPackage.js +21 -0
  35. package/node_modules/@layer0/core/deploy/routeToFiles.d.ts +14 -0
  36. package/node_modules/@layer0/core/deploy/routeToFiles.js +24 -0
  37. package/node_modules/@layer0/core/dev/DevServerOptions.d.ts +33 -0
  38. package/node_modules/@layer0/core/dev/DevServerOptions.js +2 -0
  39. package/node_modules/@layer0/core/dev/createDevServer.d.ts +8 -0
  40. package/node_modules/@layer0/core/dev/createDevServer.js +114 -0
  41. package/node_modules/@layer0/core/dev/index.d.ts +3 -0
  42. package/node_modules/@layer0/core/dev/index.js +6 -0
  43. package/node_modules/@layer0/core/dev/runLocalApp.d.ts +8 -0
  44. package/node_modules/@layer0/core/dev/runLocalApp.js +73 -0
  45. package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.d.ts +11 -0
  46. package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.js +30 -0
  47. package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.d.ts +12 -0
  48. package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.js +22 -0
  49. package/node_modules/@layer0/core/edge/EdgeResponseWriter.d.ts +122 -0
  50. package/node_modules/@layer0/core/edge/EdgeResponseWriter.js +451 -0
  51. package/node_modules/@layer0/core/edge/createEdgeConfig.d.ts +16 -0
  52. package/node_modules/@layer0/core/edge/createEdgeConfig.js +284 -0
  53. package/node_modules/@layer0/core/environment.d.ts +24 -0
  54. package/node_modules/@layer0/core/environment.js +42 -0
  55. package/node_modules/@layer0/core/errors/BackendFetchError.d.ts +11 -0
  56. package/node_modules/@layer0/core/errors/BackendFetchError.js +17 -0
  57. package/node_modules/@layer0/core/errors/FrameworkBuildError.d.ts +7 -0
  58. package/node_modules/@layer0/core/errors/FrameworkBuildError.js +26 -0
  59. package/node_modules/@layer0/core/index.d.ts +3 -0
  60. package/node_modules/@layer0/core/index.js +9 -0
  61. package/node_modules/@layer0/core/init/addToPackageJson.d.ts +7 -0
  62. package/node_modules/@layer0/core/init/addToPackageJson.js +22 -0
  63. package/node_modules/@layer0/core/init/index.d.ts +2 -0
  64. package/node_modules/@layer0/core/init/index.js +6 -0
  65. package/node_modules/@layer0/core/init/init.d.ts +5 -0
  66. package/node_modules/@layer0/core/init/init.js +17 -0
  67. package/node_modules/@layer0/core/lambda/JSBackend.d.ts +30 -0
  68. package/node_modules/@layer0/core/lambda/JSBackend.js +51 -0
  69. package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.d.ts +8 -0
  70. package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.js +19 -0
  71. package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.d.ts +17 -0
  72. package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.js +132 -0
  73. package/node_modules/@layer0/core/lambda/consoleWrapper.d.ts +16 -0
  74. package/node_modules/@layer0/core/lambda/consoleWrapper.js +127 -0
  75. package/node_modules/@layer0/core/lambda/getBodyLoggingData.d.ts +10 -0
  76. package/node_modules/@layer0/core/lambda/getBodyLoggingData.js +108 -0
  77. package/node_modules/@layer0/core/lambda/handler.d.ts +1 -0
  78. package/node_modules/@layer0/core/lambda/handler.js +91 -0
  79. package/node_modules/@layer0/core/lambda/handler.js.map +7 -0
  80. package/node_modules/@layer0/core/lambda/innerHandler.d.ts +7 -0
  81. package/node_modules/@layer0/core/lambda/innerHandler.js +181 -0
  82. package/node_modules/@layer0/core/lambda/lambdaInstance.d.ts +29 -0
  83. package/node_modules/@layer0/core/lambda/lambdaInstance.js +71 -0
  84. package/node_modules/@layer0/core/lambda/reqResMapper.d.ts +24 -0
  85. package/node_modules/@layer0/core/lambda/reqResMapper.js +286 -0
  86. package/node_modules/@layer0/core/lambda/stdStreamsWrapper.d.ts +31 -0
  87. package/node_modules/@layer0/core/lambda/stdStreamsWrapper.js +196 -0
  88. package/node_modules/@layer0/core/lambda/toJSBackend.d.ts +10 -0
  89. package/node_modules/@layer0/core/lambda/toJSBackend.js +23 -0
  90. package/node_modules/@layer0/core/node_modules/esbuild/LICENSE.md +21 -0
  91. package/node_modules/@layer0/core/node_modules/esbuild/README.md +3 -0
  92. package/node_modules/@layer0/core/node_modules/esbuild/bin/esbuild +223 -0
  93. package/node_modules/@layer0/core/node_modules/esbuild/install.js +301 -0
  94. package/node_modules/@layer0/core/node_modules/esbuild/lib/main.d.ts +716 -0
  95. package/node_modules/@layer0/core/node_modules/esbuild/lib/main.js +2532 -0
  96. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/README.md +3 -0
  97. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/bin/esbuild +0 -0
  98. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/esbuild.wasm +0 -0
  99. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/package.json +28 -0
  100. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec.js +575 -0
  101. package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec_node.js +40 -0
  102. package/node_modules/@layer0/core/node_modules/esbuild/package.json +78 -0
  103. package/node_modules/@layer0/core/package.json +132 -0
  104. package/node_modules/@layer0/core/parser/parseRouter.d.ts +13 -0
  105. package/node_modules/@layer0/core/parser/parseRouter.js +77 -0
  106. package/node_modules/@layer0/core/plugins/PluginBase.d.ts +18 -0
  107. package/node_modules/@layer0/core/plugins/PluginBase.js +19 -0
  108. package/node_modules/@layer0/core/router/Backend.d.ts +69 -0
  109. package/node_modules/@layer0/core/router/Backend.js +176 -0
  110. package/node_modules/@layer0/core/router/BackendOptions.d.ts +11 -0
  111. package/node_modules/@layer0/core/router/BackendOptions.js +2 -0
  112. package/node_modules/@layer0/core/router/BaseResponseWriter.d.ts +65 -0
  113. package/node_modules/@layer0/core/router/BaseResponseWriter.js +81 -0
  114. package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.d.ts +4 -0
  115. package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.js +89 -0
  116. package/node_modules/@layer0/core/router/CacheManifest.d.ts +80 -0
  117. package/node_modules/@layer0/core/router/CacheManifest.js +83 -0
  118. package/node_modules/@layer0/core/router/CacheOptions.d.ts +171 -0
  119. package/node_modules/@layer0/core/router/CacheOptions.js +2 -0
  120. package/node_modules/@layer0/core/router/CustomCacheKey.d.ts +140 -0
  121. package/node_modules/@layer0/core/router/CustomCacheKey.js +272 -0
  122. package/node_modules/@layer0/core/router/GroupConfig.d.ts +7 -0
  123. package/node_modules/@layer0/core/router/GroupConfig.js +20 -0
  124. package/node_modules/@layer0/core/router/Groups.d.ts +7 -0
  125. package/node_modules/@layer0/core/router/Groups.js +21 -0
  126. package/node_modules/@layer0/core/router/Headers.d.ts +3 -0
  127. package/node_modules/@layer0/core/router/Headers.js +2 -0
  128. package/node_modules/@layer0/core/router/PathMatcher.d.ts +51 -0
  129. package/node_modules/@layer0/core/router/PathMatcher.js +73 -0
  130. package/node_modules/@layer0/core/router/Preload.d.ts +16 -0
  131. package/node_modules/@layer0/core/router/Preload.js +2 -0
  132. package/node_modules/@layer0/core/router/PreloadRequests.d.ts +23 -0
  133. package/node_modules/@layer0/core/router/PreloadRequests.js +66 -0
  134. package/node_modules/@layer0/core/router/Request.d.ts +74 -0
  135. package/node_modules/@layer0/core/router/Request.js +2 -0
  136. package/node_modules/@layer0/core/router/RequestContext.d.ts +12 -0
  137. package/node_modules/@layer0/core/router/RequestContext.js +11 -0
  138. package/node_modules/@layer0/core/router/Response.d.ts +55 -0
  139. package/node_modules/@layer0/core/router/Response.js +2 -0
  140. package/node_modules/@layer0/core/router/ResponseWriter.d.ts +1011 -0
  141. package/node_modules/@layer0/core/router/ResponseWriter.js +1341 -0
  142. package/node_modules/@layer0/core/router/Route.d.ts +124 -0
  143. package/node_modules/@layer0/core/router/Route.js +280 -0
  144. package/node_modules/@layer0/core/router/RouteCriteria.d.ts +68 -0
  145. package/node_modules/@layer0/core/router/RouteCriteria.js +2 -0
  146. package/node_modules/@layer0/core/router/RouteGroup.d.ts +157 -0
  147. package/node_modules/@layer0/core/router/RouteGroup.js +223 -0
  148. package/node_modules/@layer0/core/router/RouteGroupList.d.ts +45 -0
  149. package/node_modules/@layer0/core/router/RouteGroupList.js +73 -0
  150. package/node_modules/@layer0/core/router/Router.d.ts +439 -0
  151. package/node_modules/@layer0/core/router/Router.js +907 -0
  152. package/node_modules/@layer0/core/router/addBuiltInRoutes.d.ts +2 -0
  153. package/node_modules/@layer0/core/router/addBuiltInRoutes.js +58 -0
  154. package/node_modules/@layer0/core/router/addPreloadHeaders.d.ts +7 -0
  155. package/node_modules/@layer0/core/router/addPreloadHeaders.js +57 -0
  156. package/node_modules/@layer0/core/router/cacheManifestFromRouter.d.ts +6 -0
  157. package/node_modules/@layer0/core/router/cacheManifestFromRouter.js +85 -0
  158. package/node_modules/@layer0/core/router/createCustomCacheKey.d.ts +27 -0
  159. package/node_modules/@layer0/core/router/createCustomCacheKey.js +35 -0
  160. package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.d.ts +36 -0
  161. package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.js +70 -0
  162. package/node_modules/@layer0/core/router/index.d.ts +11 -0
  163. package/node_modules/@layer0/core/router/index.js +17 -0
  164. package/node_modules/@layer0/core/router/interpolateParams.d.ts +21 -0
  165. package/node_modules/@layer0/core/router/interpolateParams.js +150 -0
  166. package/node_modules/@layer0/core/router/loadRouter.d.ts +13 -0
  167. package/node_modules/@layer0/core/router/loadRouter.js +29 -0
  168. package/node_modules/@layer0/core/router/mergeQueryString.d.ts +1 -0
  169. package/node_modules/@layer0/core/router/mergeQueryString.js +23 -0
  170. package/node_modules/@layer0/core/router/normalizeCriteria.d.ts +6 -0
  171. package/node_modules/@layer0/core/router/normalizeCriteria.js +20 -0
  172. package/node_modules/@layer0/core/router/stream.d.ts +12 -0
  173. package/node_modules/@layer0/core/router/stream.js +30 -0
  174. package/node_modules/@layer0/core/router/universalRouteUtils.d.ts +55 -0
  175. package/node_modules/@layer0/core/router/universalRouteUtils.js +114 -0
  176. package/node_modules/@layer0/core/router/validateWriter.d.ts +41 -0
  177. package/node_modules/@layer0/core/router/validateWriter.js +120 -0
  178. package/node_modules/@layer0/core/serverless.yml +30 -0
  179. package/node_modules/@layer0/core/source.d.ts +9 -0
  180. package/node_modules/@layer0/core/source.js +17 -0
  181. package/node_modules/@layer0/core/test-utils/MockRequest.d.ts +15 -0
  182. package/node_modules/@layer0/core/test-utils/MockRequest.js +36 -0
  183. package/node_modules/@layer0/core/test-utils/MockResponse.d.ts +7 -0
  184. package/node_modules/@layer0/core/test-utils/MockResponse.js +24 -0
  185. package/node_modules/@layer0/core/test-utils/expect-extend.d.ts +1 -0
  186. package/node_modules/@layer0/core/test-utils/expect-extend.js +11 -0
  187. package/node_modules/@layer0/core/test-utils/index.d.ts +4 -0
  188. package/node_modules/@layer0/core/test-utils/index.js +11 -0
  189. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.d.ts +19 -0
  190. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.js +45 -0
  191. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.d.ts +19 -0
  192. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.js +38 -0
  193. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.d.ts +19 -0
  194. package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.js +45 -0
  195. package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.d.ts +20 -0
  196. package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.js +50 -0
  197. package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.d.ts +18 -0
  198. package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.js +40 -0
  199. package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.d.ts +19 -0
  200. package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.js +43 -0
  201. package/node_modules/@layer0/core/test-utils/matchers.d.ts +6 -0
  202. package/node_modules/@layer0/core/test-utils/matchers.js +18 -0
  203. package/node_modules/@layer0/core/test-utils/utils/createRouteMock.d.ts +21 -0
  204. package/node_modules/@layer0/core/test-utils/utils/createRouteMock.js +27 -0
  205. package/node_modules/@layer0/core/test-utils/utils/getBackend.d.ts +13 -0
  206. package/node_modules/@layer0/core/test-utils/utils/getBackend.js +30 -0
  207. package/node_modules/@layer0/core/test-utils/utils/getMessage.d.ts +1 -0
  208. package/node_modules/@layer0/core/test-utils/utils/getMessage.js +16 -0
  209. package/node_modules/@layer0/core/test-utils/utils/runRoute.d.ts +10 -0
  210. package/node_modules/@layer0/core/test-utils/utils/runRoute.js +39 -0
  211. package/node_modules/@layer0/core/timing.d.ts +115 -0
  212. package/node_modules/@layer0/core/timing.js +200 -0
  213. package/node_modules/@layer0/core/transform/index.d.ts +1 -0
  214. package/node_modules/@layer0/core/transform/index.js +4 -0
  215. package/node_modules/@layer0/core/transform/transformMethod.d.ts +40 -0
  216. package/node_modules/@layer0/core/transform/transformMethod.js +58 -0
  217. package/node_modules/@layer0/core/types.d.ts +102 -0
  218. package/node_modules/@layer0/core/types.js +30 -0
  219. package/node_modules/@layer0/core/utils/Tasks.d.ts +32 -0
  220. package/node_modules/@layer0/core/utils/Tasks.js +80 -0
  221. package/node_modules/@layer0/core/utils/Validator.d.ts +18 -0
  222. package/node_modules/@layer0/core/utils/Validator.js +178 -0
  223. package/node_modules/@layer0/core/utils/bindParamsToPath.d.ts +15 -0
  224. package/node_modules/@layer0/core/utils/bindParamsToPath.js +49 -0
  225. package/node_modules/@layer0/core/utils/convertParamsToBackReferences.d.ts +16 -0
  226. package/node_modules/@layer0/core/utils/convertParamsToBackReferences.js +45 -0
  227. package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.d.ts +7 -0
  228. package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.js +26 -0
  229. package/node_modules/@layer0/core/utils/decode.d.ts +9 -0
  230. package/node_modules/@layer0/core/utils/decode.js +44 -0
  231. package/node_modules/@layer0/core/utils/esImport.d.ts +1 -0
  232. package/node_modules/@layer0/core/utils/esImport.js +9 -0
  233. package/node_modules/@layer0/core/utils/fs.d.ts +1 -0
  234. package/node_modules/@layer0/core/utils/fs.js +7 -0
  235. package/node_modules/@layer0/core/utils/get.d.ts +6 -0
  236. package/node_modules/@layer0/core/utils/get.js +19 -0
  237. package/node_modules/@layer0/core/utils/getPackageVersion.d.ts +7 -0
  238. package/node_modules/@layer0/core/utils/getPackageVersion.js +19 -0
  239. package/node_modules/@layer0/core/utils/has.d.ts +6 -0
  240. package/node_modules/@layer0/core/utils/has.js +15 -0
  241. package/node_modules/@layer0/core/utils/identity.d.ts +7 -0
  242. package/node_modules/@layer0/core/utils/identity.js +12 -0
  243. package/node_modules/@layer0/core/utils/index.d.ts +1 -0
  244. package/node_modules/@layer0/core/utils/index.js +4 -0
  245. package/node_modules/@layer0/core/utils/isEmpty.d.ts +6 -0
  246. package/node_modules/@layer0/core/utils/isEmpty.js +20 -0
  247. package/node_modules/@layer0/core/utils/isString.d.ts +1 -0
  248. package/node_modules/@layer0/core/utils/isString.js +6 -0
  249. package/node_modules/@layer0/core/utils/logo.d.ts +5 -0
  250. package/node_modules/@layer0/core/utils/logo.js +27 -0
  251. package/node_modules/@layer0/core/utils/mapValues.d.ts +7 -0
  252. package/node_modules/@layer0/core/utils/mapValues.js +16 -0
  253. package/node_modules/@layer0/core/utils/minBy.d.ts +8 -0
  254. package/node_modules/@layer0/core/utils/minBy.js +41 -0
  255. package/node_modules/@layer0/core/utils/nonWebpackRequire.d.ts +11 -0
  256. package/node_modules/@layer0/core/utils/nonWebpackRequire.js +28 -0
  257. package/node_modules/@layer0/core/utils/packageUtils.d.ts +12 -0
  258. package/node_modules/@layer0/core/utils/packageUtils.js +22 -0
  259. package/node_modules/@layer0/core/utils/ports.d.ts +5 -0
  260. package/node_modules/@layer0/core/utils/ports.js +7 -0
  261. package/node_modules/@layer0/core/utils/readBody.d.ts +7 -0
  262. package/node_modules/@layer0/core/utils/readBody.js +15 -0
  263. package/node_modules/@layer0/core/utils/readRawBody.d.ts +9 -0
  264. package/node_modules/@layer0/core/utils/readRawBody.js +21 -0
  265. package/node_modules/@layer0/core/utils/regExpEscape.d.ts +12 -0
  266. package/node_modules/@layer0/core/utils/regExpEscape.js +20 -0
  267. package/node_modules/@layer0/core/utils/requireInternal.d.ts +7 -0
  268. package/node_modules/@layer0/core/utils/requireInternal.js +24 -0
  269. package/node_modules/@layer0/core/utils/set.d.ts +10 -0
  270. package/node_modules/@layer0/core/utils/set.js +21 -0
  271. package/node_modules/@layer0/core/utils/toEdgeRegex.d.ts +11 -0
  272. package/node_modules/@layer0/core/utils/toEdgeRegex.js +23 -0
  273. package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.d.ts +12 -0
  274. package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.js +17 -0
  275. package/node_modules/@layer0/core/utils/toLower.d.ts +1 -0
  276. package/node_modules/@layer0/core/utils/toLower.js +9 -0
  277. package/node_modules/@layer0/core/utils/validateBackends.d.ts +5 -0
  278. package/node_modules/@layer0/core/utils/validateBackends.js +30 -0
  279. package/node_modules/@layer0/core/utils/watch.d.ts +10 -0
  280. package/node_modules/@layer0/core/utils/watch.js +17 -0
  281. package/package.json +47 -3
@@ -0,0 +1,543 @@
1
+ "use strict";
2
+ /* istanbul ignore file */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_extra_1 = require("fs-extra");
8
+ const shelljs_1 = __importDefault(require("shelljs"));
9
+ const path_1 = require("path");
10
+ const bundle_esbuild_1 = require("./bundle-esbuild");
11
+ const globby_1 = __importDefault(require("globby"));
12
+ // @ts-ignore
13
+ const unixify_1 = __importDefault(require("unixify"));
14
+ const chalk_1 = __importDefault(require("chalk"));
15
+ const config_1 = __importDefault(require("../config"));
16
+ const paths_1 = require("./paths");
17
+ const init_1 = require("../init");
18
+ const routeToFiles_1 = require("./routeToFiles");
19
+ const constants_1 = require("../constants");
20
+ const RouteGroup_1 = require("../router/RouteGroup");
21
+ const listSources_1 = __importDefault(require("./listSources"));
22
+ const resolveInPackage_1 = __importDefault(require("./resolveInPackage"));
23
+ const paths_2 = require("./paths");
24
+ const loadRouter_1 = __importDefault(require("../router/loadRouter"));
25
+ const source_1 = require("../source");
26
+ const parseRouter_1 = __importDefault(require("../parser/parseRouter"));
27
+ const Route_1 = __importDefault(require("../router/Route"));
28
+ const slash_1 = __importDefault(require("slash"));
29
+ /**
30
+ * The class helps you bundle apps for deployment on Layer0.
31
+ */
32
+ class DeploymentBuilder {
33
+ constructor(appDir = process.cwd()) {
34
+ // This structure has connasence of structure, names and types with Layer0 subaccount deployment lambda.
35
+ this.assetExpiration = {};
36
+ this.appDir = appDir;
37
+ this.layer0Dir = path_1.join(this.appDir, paths_1.LAYER0_DIR);
38
+ this.jsDir = path_1.join(this.appDir, paths_1.JS_DIR);
39
+ this.staticAssetsDir = path_1.join(this.appDir, paths_1.ASSETS_DIR);
40
+ this.permanentStaticAssetsDir = path_1.join(this.appDir, paths_1.PERMANENT_ASSETS_DIR);
41
+ this.sourcesDir = path_1.join(this.appDir, paths_1.SOURCES_DIR);
42
+ }
43
+ /**
44
+ * Logs a message to the console if process.env.debug is set to true
45
+ * @param msg The message to log
46
+ */
47
+ log(...msg) {
48
+ if (process.env.DEBUG === 'true') {
49
+ console.log('[Layer0 BUILD]:', ...msg);
50
+ }
51
+ }
52
+ /**
53
+ * Runs a command.
54
+ * @param path The command to run
55
+ * @param options Options for shelljs
56
+ * @return {Promise} A promise that resolves when the command is finished.
57
+ */
58
+ exec(command, options = {}) {
59
+ return new Promise((resolve, reject) => {
60
+ console.log(chalk_1.default.grey(`[Layer0] Running command: ${command}`));
61
+ shelljs_1.default.exec(command, options, (code, stdout, stderr) => {
62
+ if (code != 0)
63
+ return reject(new Error(stderr));
64
+ return resolve(stdout);
65
+ });
66
+ });
67
+ }
68
+ /**
69
+ * Adds an asset to the bundle for JavaScript workers
70
+ * @param src The source path
71
+ * @param dest An optional destination path within the lambda root directory.
72
+ * If not provided, the destination path will be the same as the source path.
73
+ * @param options Options for copySync
74
+ * @return a self reference, suitable for chaining
75
+ */
76
+ addJSAsset(src, dest, options) {
77
+ dest = dest || path_1.relative(process.cwd(), src);
78
+ this.copySync(src, path_1.join(this.jsDir, dest), options);
79
+ return this;
80
+ }
81
+ /**
82
+ * Copies a file or directory into .layer0/src
83
+ * @param src
84
+ */
85
+ addSource(src) {
86
+ const dest = path_1.relative(this.appDir, src);
87
+ this.copySync(src, path_1.join(this.sourcesDir, dest));
88
+ }
89
+ /**
90
+ * Adds source files to the bundle based on:
91
+ *
92
+ * - The `sources` property of layer0.config.js, or, if not present
93
+ * - All files committed to git.
94
+ *
95
+ * If sources is not present in layer0.config.js, and the project does not use git, an error will be thrown.
96
+ */
97
+ async addSources() {
98
+ process.stdout.write('> Copying sources into bundle... ');
99
+ for (let file of await listSources_1.default(this.appDir, config_1.default.get('sources', null))) {
100
+ this.addSource(file);
101
+ }
102
+ process.stdout.write('done.\n');
103
+ }
104
+ /**
105
+ * Adds the prod entry point from the connector attribute in layer0.config.js
106
+ * @return a self reference, suitable for chaining
107
+ */
108
+ async addProdEntrypoint() {
109
+ let connector = config_1.default.get('connector',
110
+ /* set by @layer0/cli/build when falling back to framework detection */
111
+ process.env.LAYER0_CONNECTOR || null);
112
+ if (connector) {
113
+ let name = 'prod';
114
+ let prod;
115
+ if (connector.startsWith('.')) {
116
+ // relative path
117
+ prod =
118
+ [
119
+ path_1.join(this.appDir, connector, `${name}.cjs`),
120
+ path_1.join(this.appDir, connector, `${name}.mjs`),
121
+ path_1.join(this.appDir, connector, `${name}.js`),
122
+ ].find(file => fs_extra_1.existsSync(file)) || '';
123
+ }
124
+ else {
125
+ // package name
126
+ prod = path_1.join(resolveInPackage_1.default(connector, `${name}.js`));
127
+ }
128
+ if (fs_extra_1.existsSync(prod)) {
129
+ this.addJSAsset(prod, paths_2.pathForBackend(constants_1.BACKENDS.js));
130
+ }
131
+ }
132
+ return this;
133
+ }
134
+ /**
135
+ * Adds a folder or file as static asset.
136
+ * Also register directories as asset aliases when they contains an index.html file
137
+ *
138
+ * @param src The source path
139
+ * @param dest An optional destination path in s3. If not provided, the destination path will be the same as the source path.
140
+ * @return a self reference, suitable for chaining
141
+ */
142
+ addStaticAsset(src, dest, { permanent = false, exclude = [] } = {}) {
143
+ dest = dest || path_1.relative(process.cwd(), src);
144
+ permanent = permanent && process.env.LAYER0_DISABLE_PERMANENT_ASSETS !== 'true';
145
+ const staticAssetDir = permanent ? this.permanentStaticAssetsDir : this.staticAssetsDir;
146
+ const absoluteDest = path_1.join(staticAssetDir, dest);
147
+ this.copySync(src, absoluteDest, {
148
+ filter: file => !exclude.some(excludedFile => file.indexOf(excludedFile) >= 0),
149
+ });
150
+ return this;
151
+ }
152
+ /**
153
+ * Ensures that all path/to/dir/index.html files in S3 have an alias for /path/to/dir. This
154
+ * allows the edge to simply forward URLs like /foo to S3 and have S3 respond with /foo/index.html.
155
+ * THis is critical to the functionality of Gatsby, Next.js, and other static site builders.
156
+ */
157
+ createStaticAssetAliases() {
158
+ process.stdout.write('> Writing static asset aliases... ');
159
+ const assetAliases = {};
160
+ const dirs = [this.staticAssetsDir, this.permanentStaticAssetsDir];
161
+ dirs.forEach(dir => {
162
+ const files = globby_1.default.sync('**/index.html', {
163
+ cwd: dir,
164
+ onlyFiles: true,
165
+ dot: true,
166
+ });
167
+ files.forEach(indexFile => {
168
+ assetAliases[path_1.dirname(indexFile)] = indexFile;
169
+ });
170
+ });
171
+ this.writeFileSync(path_1.join(this.layer0Dir, constants_1.LAYER0_ASSET_ALIASES_FILE), JSON.stringify(assetAliases, null, ' '));
172
+ process.stdout.write('done.\n');
173
+ }
174
+ /**
175
+ * Ensures all assets in the "all", "js", and "ts" subdirectories of `defaultAppPath` are either already
176
+ * present in the user's app or are copied over from `defaultAppPath`.
177
+ * @param defaultAppPath
178
+ * @return A self reference, suitable for chaining
179
+ */
180
+ addDefaultAppResources(defaultAppPath) {
181
+ const addResources = (fromPath) => {
182
+ for (let file of globby_1.default.sync('**/*', {
183
+ cwd: fromPath,
184
+ })) {
185
+ if (!fs_extra_1.existsSync(path_1.join(this.appDir, file))) {
186
+ console.log(`> ${chalk_1.default.green(file)} not found, creating...`);
187
+ this.copySync(path_1.join(fromPath, file), path_1.join(this.appDir, file));
188
+ }
189
+ }
190
+ };
191
+ addResources(path_1.join(defaultAppPath, 'all'));
192
+ if (fs_extra_1.existsSync(path_1.join(process.cwd(), 'tsconfig.json'))) {
193
+ addResources(path_1.join(defaultAppPath, 'ts'));
194
+ }
195
+ else {
196
+ addResources(path_1.join(defaultAppPath, 'js'));
197
+ }
198
+ return this;
199
+ }
200
+ /**
201
+ * Copies all the layer0 scripts into the package.json file, if they don't already exist.
202
+ * @param scriptsOverride Used to pass framework-specific script overrides
203
+ * @param overrideExisting Set to true to override existing layer0 script elements
204
+ * @return A self reference, suitable for chaining
205
+ */
206
+ addDefaultLayer0Scripts(scriptsOverride = {}, overrideExisting = false) {
207
+ init_1.addToPackageJson({
208
+ scripts: {
209
+ 'layer0:dev': 'layer0 dev',
210
+ 'layer0:build': 'layer0 build',
211
+ 'layer0:deploy': 'layer0 deploy',
212
+ ...scriptsOverride,
213
+ },
214
+ }, overrideExisting);
215
+ console.log(chalk_1.default.bold('\nAdded the following scripts to package.json:\n'));
216
+ console.log(` ${chalk_1.default.cyan('layer0:dev')} - Simulate your app on Layer0 locally.`);
217
+ console.log(` ${chalk_1.default.cyan('layer0:build')} - Build your app for deployment on Layer0.`);
218
+ console.log(` ${chalk_1.default.cyan('layer0:deploy')} - Build and deploy your app on Layer0.`);
219
+ return this;
220
+ }
221
+ /**
222
+ * Copies a file
223
+ * @param from the source path
224
+ * @param to the destination path
225
+ */
226
+ copySync(from, to, copySyncOptions = {}) {
227
+ if (fs_extra_1.existsSync(from)) {
228
+ this.log(`COPY: ${from.replace(this.appDir + '/', '')} -> ${to.replace(this.appDir + '/', '')}`);
229
+ return fs_extra_1.copySync(from, to, copySyncOptions);
230
+ }
231
+ else {
232
+ console.warn(`${chalk_1.default.yellow('Warning:')} The following file/directory path referenced in your Layer0 router configuration does not exist: ${path_1.relative(process.cwd(), from)}. Requests matching this route will return a 404 status.`);
233
+ }
234
+ }
235
+ /**
236
+ * Writes a file
237
+ * @param to the destination path
238
+ * @param content the contents of the file
239
+ * @param encoding the encoding
240
+ */
241
+ writeFileSync(to, content) {
242
+ this.log(`WRITE: ${to.replace(this.appDir + '/', '')}`);
243
+ fs_extra_1.mkdirpSync(path_1.dirname(to));
244
+ return fs_extra_1.writeFileSync(to, content, 'utf8');
245
+ }
246
+ /**
247
+ * Deletes all files in a directory
248
+ * @param dir The directory to empty
249
+ */
250
+ emptyDirSync(dir) {
251
+ this.log(`EMPTY: ${dir.replace(this.appDir + '/', '')}`);
252
+ return fs_extra_1.emptyDirSync(dir);
253
+ }
254
+ /**
255
+ * Reads a file
256
+ * @param path the file path
257
+ * @param options Options for `fs.readFileSync`
258
+ * @returns The file contents
259
+ */
260
+ readFileSync(path, { encoding = 'utf8' } = {}) {
261
+ this.log(`READ: ${path.replace(this.appDir + '/', '')}`);
262
+ return fs_extra_1.readFileSync(path, { encoding });
263
+ }
264
+ /**
265
+ * Deletes a file
266
+ * @param path The file to delete
267
+ */
268
+ removeSync(path) {
269
+ this.log(`DELETE: ${path.replace(this.appDir + '/', '')}`);
270
+ return fs_extra_1.removeSync(path);
271
+ }
272
+ /**
273
+ * Deletes the output of the previous build.
274
+ */
275
+ clearPreviousBuildOutput() {
276
+ // clear .layer0 directory
277
+ this.emptyDirSync(this.layer0Dir);
278
+ return this;
279
+ }
280
+ /**
281
+ * Returns the router instance.
282
+ * @return {Router}
283
+ */
284
+ async getRouter() {
285
+ // this is needed for RouteGroup#dir to find source files to add to the manifest
286
+ source_1.setSourceDir(process.cwd());
287
+ if (!this.router) {
288
+ if (process.env.WEBPACK === 'true') {
289
+ // There is no visualizer for ESBuild's bundle analysis meta file yet, so if the user wants to analyze their
290
+ // router bundle, we need to let them build with webpack
291
+ // To run a build with analysis, the user needs to run: ANALYZE=true WEBPACK=true layer0 build
292
+ // Also, we late-load webpack here since webpack and webpack-bundle-analyzer are peer dependencies that are not
293
+ // required if the user doesn't need to build with webpack.
294
+ await require('./bundle-webpack').default();
295
+ }
296
+ else {
297
+ await bundle_esbuild_1.bundleRouterAndConfig();
298
+ }
299
+ const cwd = process.cwd();
300
+ const routerFile = path_1.basename(config_1.default.get('routes'));
301
+ try {
302
+ process.chdir(this.jsDir);
303
+ this.router = loadRouter_1.default(path_1.join(this.jsDir, routerFile));
304
+ }
305
+ finally {
306
+ process.chdir(cwd);
307
+ }
308
+ }
309
+ return this.router;
310
+ }
311
+ /**
312
+ * Layer0 version of @layer0/core.
313
+ * @type {String}
314
+ */
315
+ static get layer0Version() {
316
+ return (process.env[constants_1.LAYER0_ENV_VARIABLES.versionOverride] ||
317
+ require('../package.json').version.replace(/\+.*/, '')); // remove the suffix added by yalc so that the last deployed lamba is used when testing an unreleased version of Layer0 core
318
+ }
319
+ /**
320
+ * Copies all of the standard assets into the JS and static asset bundles. These are the same for any framework.
321
+ */
322
+ async build(options) {
323
+ await this.includeFiles();
324
+ await this.includeNodeModules();
325
+ // store the router source so we can show it in console and download for debugging purposes
326
+ const routerPath = path_1.join(this.appDir, config_1.default.get('routes'));
327
+ this.addSource(routerPath);
328
+ // routes.js and layer0.config.js
329
+ const router = await this.getRouter();
330
+ // Add the prod entry point from the connector attribute in layer0.config.js
331
+ if (!(options === null || options === void 0 ? void 0 : options.excludeProdEntryPoint)) {
332
+ await this.addProdEntrypoint();
333
+ }
334
+ // lambda handler
335
+ this.addJSAsset(path_1.join(__dirname, '..', 'lambda', 'handler.js'), 'handler.js');
336
+ this.addJSAsset(path_1.join(__dirname, '..', 'lambda', 'handler.js.map'), 'handler.js.map');
337
+ const configPath = [
338
+ path_1.join(this.appDir, constants_1.LAYER0_CONFIG_FILE),
339
+ path_1.join(this.appDir, constants_1.LAYER0_CONFIG_FILE.replace('.js', '.cjs')),
340
+ ].find(fs_extra_1.existsSync);
341
+ // add layer0.config.js to src
342
+ if (configPath)
343
+ this.addSource(configPath);
344
+ // When run with --sources, add the source code to the build for debugging purposes based on the sources property of layer0.config.js
345
+ if (process.env.LAYER0_INCLUDE_SOURCES === 'true') {
346
+ await this.addSources();
347
+ }
348
+ // Parse router and store result
349
+ const routerInfo = parseRouter_1.default(routerPath);
350
+ this.writeFileSync(path_1.join(this.layer0Dir, 'routerInfo.json'), JSON.stringify({ location: config_1.default.get('routes'), info: routerInfo }, null, 3));
351
+ // s3
352
+ process.env.LAYER0_EDGE_BUILD = 'true';
353
+ const edgeConfig = await router.createEdgeConfig();
354
+ // Copy all serveStatic assets to S3
355
+ for (let destination in edgeConfig.destinations) {
356
+ const { routes, errorRoutes = [] } = edgeConfig.destinations[destination];
357
+ routes
358
+ .concat(errorRoutes)
359
+ .filter(r => r.route &&
360
+ r.route.action === constants_1.ACTIONS.proxy &&
361
+ // @ts-ignore - not happy with r.route potentially undefined here
362
+ [constants_1.BACKENDS.static, constants_1.BACKENDS.permanentStatic].includes(r.route.backend))
363
+ .forEach(r => {
364
+ var _a, _b;
365
+ (_b = (_a = r.route) === null || _a === void 0 ? void 0 : _a.fsPath) === null || _b === void 0 ? void 0 : _b.forEach(fsPath => {
366
+ // @ts-ignore - not happy with r.route potentially undefined here
367
+ const { fsExclude: exclude, backend, disableAutoPublish } = r.route;
368
+ if (!disableAutoPublish) {
369
+ const permanent = backend === constants_1.BACKENDS.permanentStatic;
370
+ // File or directory to serve as assets
371
+ const relativePath = routeToFiles_1.rootDirForPath(fsPath);
372
+ const absoluteDirPath = path_1.join(process.cwd(), relativePath);
373
+ const filesToAdd = [];
374
+ if (fs_extra_1.existsSync(absoluteDirPath) && fs_extra_1.lstatSync(absoluteDirPath).isDirectory()) {
375
+ // directories
376
+ const regex = Route_1.default.toRegexp(slash_1.default(fsPath));
377
+ const files = globby_1.default.sync('**/*', { cwd: path_1.join(process.cwd(), relativePath) });
378
+ for (let file of files) {
379
+ const filePath = path_1.join(relativePath, file);
380
+ if (regex.test(`/${slash_1.default(filePath)}`)) {
381
+ // only copy the file to s3 if it can match the route specified in the serveStatic target path (the first parameter)
382
+ filesToAdd.push(filePath);
383
+ }
384
+ }
385
+ }
386
+ else {
387
+ // individual files
388
+ filesToAdd.push(relativePath);
389
+ }
390
+ this.log(`Adding static assets for route ${r.path}`);
391
+ for (let file of filesToAdd) {
392
+ this.addStaticAsset(path_1.join(this.appDir, file), file, { permanent, exclude });
393
+ }
394
+ }
395
+ });
396
+ });
397
+ }
398
+ // .layer0/LAYER0_VERSION
399
+ this.writeFileSync(path_1.join(this.layer0Dir, 'LAYER0_VERSION'), DeploymentBuilder.layer0Version);
400
+ // layer0.json is not actually used by anything - we just include it here to make it easier to debug the edge logic so we have easy access to it during development.
401
+ this.writeFileSync(path_1.join(this.layer0Dir, 'layer0.json'), JSON.stringify(edgeConfig, null, ' '));
402
+ this.createStaticAssetAliases();
403
+ process.stdout.write('> Writing static asset manifest... ');
404
+ this.writeStaticAssetManifest(router);
405
+ this.writeStaticAssetExpiration();
406
+ // needed for static asset expiration
407
+ this.addJSAsset(path_1.join(this.layer0Dir, 'static-asset-expiration.json'));
408
+ process.stdout.write('done.\n');
409
+ }
410
+ /**
411
+ * Adds all configured extra files to the lamdba directory
412
+ */
413
+ async includeFiles() {
414
+ if (config_1.default.has('includeFiles')) {
415
+ process.stdout.write('> Copying includeFiles into the bundle... ');
416
+ const globs = config_1.default.get('includeFiles', {});
417
+ for (let key in globs) {
418
+ const relativeDest = globs[key];
419
+ if (relativeDest) {
420
+ // Per https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows,
421
+ // Windows paths need to be converted to forward-slashes.
422
+ const files = globby_1.default.sync(unixify_1.default(path_1.join(this.appDir, key)));
423
+ for (let src of files) {
424
+ // if the relativeDest is true, copy it to the same path within the lambda
425
+ const dest = relativeDest === true
426
+ ? path_1.relative(this.appDir, src)
427
+ : path_1.join(relativeDest, path_1.relative(path_1.join(this.appDir, key), src));
428
+ await this.copySync(src, path_1.join(this.jsDir, dest), { dereference: true });
429
+ }
430
+ }
431
+ }
432
+ process.stdout.write('done.\n');
433
+ }
434
+ }
435
+ isYarn() {
436
+ return fs_extra_1.existsSync(path_1.join(process.cwd(), 'yarn.lock'));
437
+ }
438
+ /**
439
+ * Adds all dependencies from package.json to the JS bundle (excluding devDependencies)
440
+ */
441
+ async includeNodeModules() {
442
+ if (config_1.default.get('includeNodeModules', false) === true) {
443
+ const args = [];
444
+ const envVars = { ...process.env };
445
+ const yalc = process.env.YALC === 'true';
446
+ let cmd = 'npm'; // default to npm
447
+ let lockFile;
448
+ // Set Env variables for the lambda functions
449
+ envVars['npm_config_target_arch'] = 'x64';
450
+ envVars['npm_config_target_platform'] = 'linux';
451
+ // yarn
452
+ if (this.isYarn()) {
453
+ lockFile = 'yarn.lock';
454
+ cmd = 'yarn';
455
+ if (!yalc) {
456
+ args.push('install', '--frozen-lockfile');
457
+ }
458
+ }
459
+ else {
460
+ args.push('--target_arch=x64');
461
+ args.push('--target_platform=linux');
462
+ if (fs_extra_1.existsSync(path_1.join(process.cwd(), 'package-lock.json'))) {
463
+ lockFile = 'package-lock.json';
464
+ args.push(yalc ? 'install' : 'ci');
465
+ }
466
+ else {
467
+ args.push('install');
468
+ }
469
+ }
470
+ args.push('--production');
471
+ process.stdout.write('> Adding production dependencies to the bundle... ');
472
+ this.preparePackageJson();
473
+ if (lockFile && !yalc) {
474
+ this.copySync(path_1.join(this.appDir, lockFile), path_1.join(this.jsDir, lockFile));
475
+ }
476
+ await this.exec(`${cmd} ${args.join(' ')}`, { cwd: this.jsDir, env: envVars });
477
+ process.stdout.write('done.\n');
478
+ }
479
+ }
480
+ /**
481
+ * Copies the package.json file into the lambda and adjust all dependencies that
482
+ * use file paths
483
+ */
484
+ preparePackageJson() {
485
+ const dest = path_1.join(this.jsDir, 'package.json');
486
+ this.copySync(path_1.join(this.appDir, 'package.json'), dest);
487
+ const contents = JSON.parse(fs_extra_1.readFileSync(dest, 'utf8'));
488
+ const { dependencies } = contents;
489
+ if (dependencies) {
490
+ for (let name in dependencies) {
491
+ const value = dependencies[name];
492
+ if (value.startsWith('file:')) {
493
+ // convert file:./path/to/module to file:../../path/to/module
494
+ const newValue = value.replace(/file:/, `file:..${path_1.sep}..${path_1.sep}`);
495
+ this.log(`Rewriting ${name}: ${value} => ${newValue}`);
496
+ dependencies[name] = newValue;
497
+ }
498
+ }
499
+ }
500
+ delete contents.devDependencies;
501
+ fs_extra_1.writeFileSync(dest, JSON.stringify(contents, null, ' '), 'utf8');
502
+ }
503
+ /**
504
+ * Configures the TTL for a static asset. Once the TTL has expired, it will be refreshed
505
+ * by forwarding requests for that asset to serverless.
506
+ * @param path The path to the asset within the app
507
+ * @param maxAgeSeconds The TTL in seconds
508
+ * @return A self-reference, suitable for chaining
509
+ */
510
+ setStaticAssetExpiration(path, maxAgeSeconds, staleWhileRevalidateSeconds) {
511
+ this.assetExpiration[path] = {
512
+ maxAgeSeconds,
513
+ staleWhileRevalidateSeconds,
514
+ };
515
+ return this;
516
+ }
517
+ /**
518
+ * Write the manifest for that tells us what static asset routes to configure in the cloud
519
+ * @param router
520
+ */
521
+ writeStaticAssetManifest(router) {
522
+ this.writeFileSync(path_1.join(this.jsDir, RouteGroup_1.STATIC_ASSET_MANIFEST_FILE), JSON.stringify(router.getStaticAssetManifest(), null, ' '));
523
+ }
524
+ /**
525
+ * Writes static asset expiration times so that we can configure them on S3
526
+ */
527
+ writeStaticAssetExpiration() {
528
+ this.writeFileSync(path_1.join(this.layer0Dir, 'static-asset-expiration.json'), JSON.stringify(this.assetExpiration, null, ' '));
529
+ }
530
+ /**
531
+ * Deletes all .map files from specified folder
532
+ */
533
+ deleteMapFiles(dir) {
534
+ const mapFiles = globby_1.default.sync('**/*.map', {
535
+ onlyFiles: true,
536
+ cwd: dir,
537
+ });
538
+ mapFiles.forEach(file => {
539
+ this.removeSync(path_1.join(dir, file));
540
+ });
541
+ }
542
+ }
543
+ exports.default = DeploymentBuilder;
@@ -0,0 +1,11 @@
1
+ import { BuildOptions } from 'esbuild';
2
+ /**
3
+ * Creates a serverless bundle using ESBuild
4
+ * @param options Options for ESBuild
5
+ */
6
+ export declare function bundle(options?: BuildOptions): Promise<void>;
7
+ /**
8
+ * Builds the user's routes and layer0.config files.
9
+ * @param options Options for ESBuild
10
+ */
11
+ export declare function bundleRouterAndConfig(options?: BuildOptions): Promise<void>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const esbuild_1 = require("esbuild");
7
+ const fs_1 = require("../utils/fs");
8
+ const path_1 = require("path");
9
+ const config_1 = __importDefault(require("../config"));
10
+ const logo_1 = __importDefault(require("../utils/logo"));
11
+ const paths_1 = require("./paths");
12
+ /**
13
+ * Creates a serverless bundle using ESBuild
14
+ * @param options Options for ESBuild
15
+ */
16
+ async function bundle(options) {
17
+ // Always exclude fsevents as it cannot be bundled - it's binary.
18
+ const external = ['fsevents'];
19
+ const esBuildDefaults = {
20
+ bundle: true,
21
+ minify: true,
22
+ platform: 'node',
23
+ target: 'node14.0',
24
+ sourcemap: true,
25
+ external,
26
+ };
27
+ await esbuild_1.build({
28
+ ...esBuildDefaults,
29
+ ...options,
30
+ });
31
+ }
32
+ exports.bundle = bundle;
33
+ /**
34
+ * Builds the user's routes and layer0.config files.
35
+ * @param options Options for ESBuild
36
+ */
37
+ async function bundleRouterAndConfig(options = {}) {
38
+ const cwd = process.cwd();
39
+ const destDir = path_1.join(process.cwd(), paths_1.JS_DIR);
40
+ const routerPath = path_1.join(process.cwd(), config_1.default.get('routes'));
41
+ const configPath = [path_1.join(cwd, 'layer0.config.js'), path_1.join(cwd, 'layer0.config.cjs')].find(fs_1.existsSync);
42
+ // Use process.stdout.write to be able to concatenate `done.` to the same output line.
43
+ process.stdout.write(`> Bundling ${logo_1.default} router... `);
44
+ if (!configPath) {
45
+ throw new Error('layer0.config.js not found. Run "layer0 init" to create this file.');
46
+ }
47
+ // We keep the original extension for the router since esm requires it when running
48
+ const destRouterName = path_1.basename(routerPath);
49
+ const destRouterPath = path_1.join(destDir, destRouterName);
50
+ // for config: bundle input may be .js|.ts|.cjs but we output to .js
51
+ const destConfigName = path_1.basename(configPath);
52
+ const destConfigPath = path_1.join(destDir, destConfigName.replace(path_1.extname(destConfigName), '.js'));
53
+ await Promise.all([
54
+ bundle({
55
+ ...options,
56
+ entryPoints: [routerPath],
57
+ outfile: destRouterPath,
58
+ }),
59
+ bundle({
60
+ ...options,
61
+ entryPoints: [configPath],
62
+ outfile: destConfigPath,
63
+ }),
64
+ ]);
65
+ process.stdout.write('done.\n');
66
+ }
67
+ exports.bundleRouterAndConfig = bundleRouterAndConfig;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Bundles an app info a single JS file with @vercel/ncc. This helps minimize the size of the lambda because of
3
+ * it's efficient tree shaking. This can be a solution when your app is too large to fit within
4
+ * the maximum size of a lambda.
5
+ * @param src The entry point source file
6
+ * @param destDir The output directory
7
+ */
8
+ export default function bundleWithNcc(src: string, destDir: string): Promise<void>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* istanbul ignore file */
7
+ const shelljs_1 = __importDefault(require("shelljs"));
8
+ /**
9
+ * Bundles an app info a single JS file with @vercel/ncc. This helps minimize the size of the lambda because of
10
+ * it's efficient tree shaking. This can be a solution when your app is too large to fit within
11
+ * the maximum size of a lambda.
12
+ * @param src The entry point source file
13
+ * @param destDir The output directory
14
+ */
15
+ async function bundleWithNcc(src, destDir) {
16
+ console.log('> Bundling your app with @vercel/ncc...');
17
+ loadNcc();
18
+ await shelljs_1.default.exec(`ncc build -m -o ${destDir} ${src}`);
19
+ console.log('> done.');
20
+ }
21
+ exports.default = bundleWithNcc;
22
+ function loadNcc() {
23
+ try {
24
+ require('@vercel/ncc');
25
+ }
26
+ catch (e) {
27
+ console.log('Required dependency @vercel/ncc not found. Install @vercel/ncc@^0.34.0 as a devDependency then retry this command.');
28
+ process.exit(1);
29
+ }
30
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates an exploded, tree shaken bundle that more easily fits within Lambda's size limits and
3
+ * reduces code start times.
4
+ * @param src The entry point source file
5
+ * @param destDir The output directory
6
+ */
7
+ export default function bundleWithNft(src: string, destDir: string): Promise<void>;