@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.
- package/node_modules/@layer0/core/README.md +50 -0
- package/node_modules/@layer0/core/build.d.ts +5 -0
- package/node_modules/@layer0/core/build.js +17 -0
- package/node_modules/@layer0/core/cache/Cache.d.ts +56 -0
- package/node_modules/@layer0/core/cache/Cache.js +138 -0
- package/node_modules/@layer0/core/cache/CacheKey.d.ts +52 -0
- package/node_modules/@layer0/core/cache/CacheKey.js +95 -0
- package/node_modules/@layer0/core/config.d.ts +53 -0
- package/node_modules/@layer0/core/config.js +113 -0
- package/node_modules/@layer0/core/constants.d.ts +214 -0
- package/node_modules/@layer0/core/constants.js +216 -0
- package/node_modules/@layer0/core/context.d.ts +38 -0
- package/node_modules/@layer0/core/context.js +98 -0
- package/node_modules/@layer0/core/default-app/all/layer0.config.js +60 -0
- package/node_modules/@layer0/core/default-app/js/routes.js +27 -0
- package/node_modules/@layer0/core/default-app/ts/routes.ts +27 -0
- package/node_modules/@layer0/core/deploy/DeploymentBuilder.d.ts +177 -0
- package/node_modules/@layer0/core/deploy/DeploymentBuilder.js +543 -0
- package/node_modules/@layer0/core/deploy/bundle-esbuild.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/bundle-esbuild.js +67 -0
- package/node_modules/@layer0/core/deploy/bundle-ncc.d.ts +8 -0
- package/node_modules/@layer0/core/deploy/bundle-ncc.js +30 -0
- package/node_modules/@layer0/core/deploy/bundle-nft.d.ts +7 -0
- package/node_modules/@layer0/core/deploy/bundle-nft.js +41 -0
- package/node_modules/@layer0/core/deploy/bundle-webpack.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/bundle-webpack.js +127 -0
- package/node_modules/@layer0/core/deploy/index.d.ts +19 -0
- package/node_modules/@layer0/core/deploy/index.js +6 -0
- package/node_modules/@layer0/core/deploy/listSources.d.ts +11 -0
- package/node_modules/@layer0/core/deploy/listSources.js +18 -0
- package/node_modules/@layer0/core/deploy/paths.d.ts +27 -0
- package/node_modules/@layer0/core/deploy/paths.js +33 -0
- package/node_modules/@layer0/core/deploy/resolveInPackage.d.ts +7 -0
- package/node_modules/@layer0/core/deploy/resolveInPackage.js +21 -0
- package/node_modules/@layer0/core/deploy/routeToFiles.d.ts +14 -0
- package/node_modules/@layer0/core/deploy/routeToFiles.js +24 -0
- package/node_modules/@layer0/core/dev/DevServerOptions.d.ts +33 -0
- package/node_modules/@layer0/core/dev/DevServerOptions.js +2 -0
- package/node_modules/@layer0/core/dev/createDevServer.d.ts +8 -0
- package/node_modules/@layer0/core/dev/createDevServer.js +114 -0
- package/node_modules/@layer0/core/dev/index.d.ts +3 -0
- package/node_modules/@layer0/core/dev/index.js +6 -0
- package/node_modules/@layer0/core/dev/runLocalApp.d.ts +8 -0
- package/node_modules/@layer0/core/dev/runLocalApp.js +73 -0
- package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.d.ts +11 -0
- package/node_modules/@layer0/core/dev/serverlessCompatibilityMiddleware.js +30 -0
- package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.d.ts +12 -0
- package/node_modules/@layer0/core/edge/EdgeErrorPageResponseWriter.js +22 -0
- package/node_modules/@layer0/core/edge/EdgeResponseWriter.d.ts +122 -0
- package/node_modules/@layer0/core/edge/EdgeResponseWriter.js +451 -0
- package/node_modules/@layer0/core/edge/createEdgeConfig.d.ts +16 -0
- package/node_modules/@layer0/core/edge/createEdgeConfig.js +284 -0
- package/node_modules/@layer0/core/environment.d.ts +24 -0
- package/node_modules/@layer0/core/environment.js +42 -0
- package/node_modules/@layer0/core/errors/BackendFetchError.d.ts +11 -0
- package/node_modules/@layer0/core/errors/BackendFetchError.js +17 -0
- package/node_modules/@layer0/core/errors/FrameworkBuildError.d.ts +7 -0
- package/node_modules/@layer0/core/errors/FrameworkBuildError.js +26 -0
- package/node_modules/@layer0/core/index.d.ts +3 -0
- package/node_modules/@layer0/core/index.js +9 -0
- package/node_modules/@layer0/core/init/addToPackageJson.d.ts +7 -0
- package/node_modules/@layer0/core/init/addToPackageJson.js +22 -0
- package/node_modules/@layer0/core/init/index.d.ts +2 -0
- package/node_modules/@layer0/core/init/index.js +6 -0
- package/node_modules/@layer0/core/init/init.d.ts +5 -0
- package/node_modules/@layer0/core/init/init.js +17 -0
- package/node_modules/@layer0/core/lambda/JSBackend.d.ts +30 -0
- package/node_modules/@layer0/core/lambda/JSBackend.js +51 -0
- package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.d.ts +8 -0
- package/node_modules/@layer0/core/lambda/RequestListenerJSBackend.js +19 -0
- package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.d.ts +17 -0
- package/node_modules/@layer0/core/lambda/adaptResponseEncodingToDownstream.js +132 -0
- package/node_modules/@layer0/core/lambda/consoleWrapper.d.ts +16 -0
- package/node_modules/@layer0/core/lambda/consoleWrapper.js +127 -0
- package/node_modules/@layer0/core/lambda/getBodyLoggingData.d.ts +10 -0
- package/node_modules/@layer0/core/lambda/getBodyLoggingData.js +108 -0
- package/node_modules/@layer0/core/lambda/handler.d.ts +1 -0
- package/node_modules/@layer0/core/lambda/handler.js +91 -0
- package/node_modules/@layer0/core/lambda/handler.js.map +7 -0
- package/node_modules/@layer0/core/lambda/innerHandler.d.ts +7 -0
- package/node_modules/@layer0/core/lambda/innerHandler.js +181 -0
- package/node_modules/@layer0/core/lambda/lambdaInstance.d.ts +29 -0
- package/node_modules/@layer0/core/lambda/lambdaInstance.js +71 -0
- package/node_modules/@layer0/core/lambda/reqResMapper.d.ts +24 -0
- package/node_modules/@layer0/core/lambda/reqResMapper.js +286 -0
- package/node_modules/@layer0/core/lambda/stdStreamsWrapper.d.ts +31 -0
- package/node_modules/@layer0/core/lambda/stdStreamsWrapper.js +196 -0
- package/node_modules/@layer0/core/lambda/toJSBackend.d.ts +10 -0
- package/node_modules/@layer0/core/lambda/toJSBackend.js +23 -0
- package/node_modules/@layer0/core/node_modules/esbuild/LICENSE.md +21 -0
- package/node_modules/@layer0/core/node_modules/esbuild/README.md +3 -0
- package/node_modules/@layer0/core/node_modules/esbuild/bin/esbuild +223 -0
- package/node_modules/@layer0/core/node_modules/esbuild/install.js +301 -0
- package/node_modules/@layer0/core/node_modules/esbuild/lib/main.d.ts +716 -0
- package/node_modules/@layer0/core/node_modules/esbuild/lib/main.js +2532 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/README.md +3 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/bin/esbuild +0 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/esbuild.wasm +0 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/package.json +28 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec.js +575 -0
- package/node_modules/@layer0/core/node_modules/esbuild/node_modules/@ohos-ports/esbuild-openharmony-arm64/wasm_exec_node.js +40 -0
- package/node_modules/@layer0/core/node_modules/esbuild/package.json +78 -0
- package/node_modules/@layer0/core/package.json +132 -0
- package/node_modules/@layer0/core/parser/parseRouter.d.ts +13 -0
- package/node_modules/@layer0/core/parser/parseRouter.js +77 -0
- package/node_modules/@layer0/core/plugins/PluginBase.d.ts +18 -0
- package/node_modules/@layer0/core/plugins/PluginBase.js +19 -0
- package/node_modules/@layer0/core/router/Backend.d.ts +69 -0
- package/node_modules/@layer0/core/router/Backend.js +176 -0
- package/node_modules/@layer0/core/router/BackendOptions.d.ts +11 -0
- package/node_modules/@layer0/core/router/BackendOptions.js +2 -0
- package/node_modules/@layer0/core/router/BaseResponseWriter.d.ts +65 -0
- package/node_modules/@layer0/core/router/BaseResponseWriter.js +81 -0
- package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.d.ts +4 -0
- package/node_modules/@layer0/core/router/BehindEdgeResponseWriterProxy.js +89 -0
- package/node_modules/@layer0/core/router/CacheManifest.d.ts +80 -0
- package/node_modules/@layer0/core/router/CacheManifest.js +83 -0
- package/node_modules/@layer0/core/router/CacheOptions.d.ts +171 -0
- package/node_modules/@layer0/core/router/CacheOptions.js +2 -0
- package/node_modules/@layer0/core/router/CustomCacheKey.d.ts +140 -0
- package/node_modules/@layer0/core/router/CustomCacheKey.js +272 -0
- package/node_modules/@layer0/core/router/GroupConfig.d.ts +7 -0
- package/node_modules/@layer0/core/router/GroupConfig.js +20 -0
- package/node_modules/@layer0/core/router/Groups.d.ts +7 -0
- package/node_modules/@layer0/core/router/Groups.js +21 -0
- package/node_modules/@layer0/core/router/Headers.d.ts +3 -0
- package/node_modules/@layer0/core/router/Headers.js +2 -0
- package/node_modules/@layer0/core/router/PathMatcher.d.ts +51 -0
- package/node_modules/@layer0/core/router/PathMatcher.js +73 -0
- package/node_modules/@layer0/core/router/Preload.d.ts +16 -0
- package/node_modules/@layer0/core/router/Preload.js +2 -0
- package/node_modules/@layer0/core/router/PreloadRequests.d.ts +23 -0
- package/node_modules/@layer0/core/router/PreloadRequests.js +66 -0
- package/node_modules/@layer0/core/router/Request.d.ts +74 -0
- package/node_modules/@layer0/core/router/Request.js +2 -0
- package/node_modules/@layer0/core/router/RequestContext.d.ts +12 -0
- package/node_modules/@layer0/core/router/RequestContext.js +11 -0
- package/node_modules/@layer0/core/router/Response.d.ts +55 -0
- package/node_modules/@layer0/core/router/Response.js +2 -0
- package/node_modules/@layer0/core/router/ResponseWriter.d.ts +1011 -0
- package/node_modules/@layer0/core/router/ResponseWriter.js +1341 -0
- package/node_modules/@layer0/core/router/Route.d.ts +124 -0
- package/node_modules/@layer0/core/router/Route.js +280 -0
- package/node_modules/@layer0/core/router/RouteCriteria.d.ts +68 -0
- package/node_modules/@layer0/core/router/RouteCriteria.js +2 -0
- package/node_modules/@layer0/core/router/RouteGroup.d.ts +157 -0
- package/node_modules/@layer0/core/router/RouteGroup.js +223 -0
- package/node_modules/@layer0/core/router/RouteGroupList.d.ts +45 -0
- package/node_modules/@layer0/core/router/RouteGroupList.js +73 -0
- package/node_modules/@layer0/core/router/Router.d.ts +439 -0
- package/node_modules/@layer0/core/router/Router.js +907 -0
- package/node_modules/@layer0/core/router/addBuiltInRoutes.d.ts +2 -0
- package/node_modules/@layer0/core/router/addBuiltInRoutes.js +58 -0
- package/node_modules/@layer0/core/router/addPreloadHeaders.d.ts +7 -0
- package/node_modules/@layer0/core/router/addPreloadHeaders.js +57 -0
- package/node_modules/@layer0/core/router/cacheManifestFromRouter.d.ts +6 -0
- package/node_modules/@layer0/core/router/cacheManifestFromRouter.js +85 -0
- package/node_modules/@layer0/core/router/createCustomCacheKey.d.ts +27 -0
- package/node_modules/@layer0/core/router/createCustomCacheKey.js +35 -0
- package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.d.ts +36 -0
- package/node_modules/@layer0/core/router/deriveSurrogateKeysFromJson.js +70 -0
- package/node_modules/@layer0/core/router/index.d.ts +11 -0
- package/node_modules/@layer0/core/router/index.js +17 -0
- package/node_modules/@layer0/core/router/interpolateParams.d.ts +21 -0
- package/node_modules/@layer0/core/router/interpolateParams.js +150 -0
- package/node_modules/@layer0/core/router/loadRouter.d.ts +13 -0
- package/node_modules/@layer0/core/router/loadRouter.js +29 -0
- package/node_modules/@layer0/core/router/mergeQueryString.d.ts +1 -0
- package/node_modules/@layer0/core/router/mergeQueryString.js +23 -0
- package/node_modules/@layer0/core/router/normalizeCriteria.d.ts +6 -0
- package/node_modules/@layer0/core/router/normalizeCriteria.js +20 -0
- package/node_modules/@layer0/core/router/stream.d.ts +12 -0
- package/node_modules/@layer0/core/router/stream.js +30 -0
- package/node_modules/@layer0/core/router/universalRouteUtils.d.ts +55 -0
- package/node_modules/@layer0/core/router/universalRouteUtils.js +114 -0
- package/node_modules/@layer0/core/router/validateWriter.d.ts +41 -0
- package/node_modules/@layer0/core/router/validateWriter.js +120 -0
- package/node_modules/@layer0/core/serverless.yml +30 -0
- package/node_modules/@layer0/core/source.d.ts +9 -0
- package/node_modules/@layer0/core/source.js +17 -0
- package/node_modules/@layer0/core/test-utils/MockRequest.d.ts +15 -0
- package/node_modules/@layer0/core/test-utils/MockRequest.js +36 -0
- package/node_modules/@layer0/core/test-utils/MockResponse.d.ts +7 -0
- package/node_modules/@layer0/core/test-utils/MockResponse.js +24 -0
- package/node_modules/@layer0/core/test-utils/expect-extend.d.ts +1 -0
- package/node_modules/@layer0/core/test-utils/expect-extend.js +11 -0
- package/node_modules/@layer0/core/test-utils/index.d.ts +4 -0
- package/node_modules/@layer0/core/test-utils/index.js +11 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheBrowser.js +45 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheEdge.js +38 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeCachedByTheServiceWorker.js +45 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.d.ts +20 -0
- package/node_modules/@layer0/core/test-utils/matchers/toBeServedStale.js +50 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.d.ts +18 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveBody.js +40 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.d.ts +19 -0
- package/node_modules/@layer0/core/test-utils/matchers/toHaveHeader.js +43 -0
- package/node_modules/@layer0/core/test-utils/matchers.d.ts +6 -0
- package/node_modules/@layer0/core/test-utils/matchers.js +18 -0
- package/node_modules/@layer0/core/test-utils/utils/createRouteMock.d.ts +21 -0
- package/node_modules/@layer0/core/test-utils/utils/createRouteMock.js +27 -0
- package/node_modules/@layer0/core/test-utils/utils/getBackend.d.ts +13 -0
- package/node_modules/@layer0/core/test-utils/utils/getBackend.js +30 -0
- package/node_modules/@layer0/core/test-utils/utils/getMessage.d.ts +1 -0
- package/node_modules/@layer0/core/test-utils/utils/getMessage.js +16 -0
- package/node_modules/@layer0/core/test-utils/utils/runRoute.d.ts +10 -0
- package/node_modules/@layer0/core/test-utils/utils/runRoute.js +39 -0
- package/node_modules/@layer0/core/timing.d.ts +115 -0
- package/node_modules/@layer0/core/timing.js +200 -0
- package/node_modules/@layer0/core/transform/index.d.ts +1 -0
- package/node_modules/@layer0/core/transform/index.js +4 -0
- package/node_modules/@layer0/core/transform/transformMethod.d.ts +40 -0
- package/node_modules/@layer0/core/transform/transformMethod.js +58 -0
- package/node_modules/@layer0/core/types.d.ts +102 -0
- package/node_modules/@layer0/core/types.js +30 -0
- package/node_modules/@layer0/core/utils/Tasks.d.ts +32 -0
- package/node_modules/@layer0/core/utils/Tasks.js +80 -0
- package/node_modules/@layer0/core/utils/Validator.d.ts +18 -0
- package/node_modules/@layer0/core/utils/Validator.js +178 -0
- package/node_modules/@layer0/core/utils/bindParamsToPath.d.ts +15 -0
- package/node_modules/@layer0/core/utils/bindParamsToPath.js +49 -0
- package/node_modules/@layer0/core/utils/convertParamsToBackReferences.d.ts +16 -0
- package/node_modules/@layer0/core/utils/convertParamsToBackReferences.js +45 -0
- package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.d.ts +7 -0
- package/node_modules/@layer0/core/utils/convertStringMatcherToRegex.js +26 -0
- package/node_modules/@layer0/core/utils/decode.d.ts +9 -0
- package/node_modules/@layer0/core/utils/decode.js +44 -0
- package/node_modules/@layer0/core/utils/esImport.d.ts +1 -0
- package/node_modules/@layer0/core/utils/esImport.js +9 -0
- package/node_modules/@layer0/core/utils/fs.d.ts +1 -0
- package/node_modules/@layer0/core/utils/fs.js +7 -0
- package/node_modules/@layer0/core/utils/get.d.ts +6 -0
- package/node_modules/@layer0/core/utils/get.js +19 -0
- package/node_modules/@layer0/core/utils/getPackageVersion.d.ts +7 -0
- package/node_modules/@layer0/core/utils/getPackageVersion.js +19 -0
- package/node_modules/@layer0/core/utils/has.d.ts +6 -0
- package/node_modules/@layer0/core/utils/has.js +15 -0
- package/node_modules/@layer0/core/utils/identity.d.ts +7 -0
- package/node_modules/@layer0/core/utils/identity.js +12 -0
- package/node_modules/@layer0/core/utils/index.d.ts +1 -0
- package/node_modules/@layer0/core/utils/index.js +4 -0
- package/node_modules/@layer0/core/utils/isEmpty.d.ts +6 -0
- package/node_modules/@layer0/core/utils/isEmpty.js +20 -0
- package/node_modules/@layer0/core/utils/isString.d.ts +1 -0
- package/node_modules/@layer0/core/utils/isString.js +6 -0
- package/node_modules/@layer0/core/utils/logo.d.ts +5 -0
- package/node_modules/@layer0/core/utils/logo.js +27 -0
- package/node_modules/@layer0/core/utils/mapValues.d.ts +7 -0
- package/node_modules/@layer0/core/utils/mapValues.js +16 -0
- package/node_modules/@layer0/core/utils/minBy.d.ts +8 -0
- package/node_modules/@layer0/core/utils/minBy.js +41 -0
- package/node_modules/@layer0/core/utils/nonWebpackRequire.d.ts +11 -0
- package/node_modules/@layer0/core/utils/nonWebpackRequire.js +28 -0
- package/node_modules/@layer0/core/utils/packageUtils.d.ts +12 -0
- package/node_modules/@layer0/core/utils/packageUtils.js +22 -0
- package/node_modules/@layer0/core/utils/ports.d.ts +5 -0
- package/node_modules/@layer0/core/utils/ports.js +7 -0
- package/node_modules/@layer0/core/utils/readBody.d.ts +7 -0
- package/node_modules/@layer0/core/utils/readBody.js +15 -0
- package/node_modules/@layer0/core/utils/readRawBody.d.ts +9 -0
- package/node_modules/@layer0/core/utils/readRawBody.js +21 -0
- package/node_modules/@layer0/core/utils/regExpEscape.d.ts +12 -0
- package/node_modules/@layer0/core/utils/regExpEscape.js +20 -0
- package/node_modules/@layer0/core/utils/requireInternal.d.ts +7 -0
- package/node_modules/@layer0/core/utils/requireInternal.js +24 -0
- package/node_modules/@layer0/core/utils/set.d.ts +10 -0
- package/node_modules/@layer0/core/utils/set.js +21 -0
- package/node_modules/@layer0/core/utils/toEdgeRegex.d.ts +11 -0
- package/node_modules/@layer0/core/utils/toEdgeRegex.js +23 -0
- package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.d.ts +12 -0
- package/node_modules/@layer0/core/utils/toHttpMethodMatchRegex.js +17 -0
- package/node_modules/@layer0/core/utils/toLower.d.ts +1 -0
- package/node_modules/@layer0/core/utils/toLower.js +9 -0
- package/node_modules/@layer0/core/utils/validateBackends.d.ts +5 -0
- package/node_modules/@layer0/core/utils/validateBackends.js +30 -0
- package/node_modules/@layer0/core/utils/watch.d.ts +10 -0
- package/node_modules/@layer0/core/utils/watch.js +17 -0
- package/package.json +47 -3
|
@@ -0,0 +1,41 @@
|
|
|
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 fs_extra_1 = require("fs-extra");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const slash_1 = __importDefault(require("slash"));
|
|
10
|
+
/**
|
|
11
|
+
* Creates an exploded, tree shaken bundle that more easily fits within Lambda's size limits and
|
|
12
|
+
* reduces code start times.
|
|
13
|
+
* @param src The entry point source file
|
|
14
|
+
* @param destDir The output directory
|
|
15
|
+
*/
|
|
16
|
+
async function bundleWithNft(src, destDir) {
|
|
17
|
+
const nodeFileTrace = loadNFT();
|
|
18
|
+
process.stdout.write('> Bundling your app with @vercel/nft...');
|
|
19
|
+
const { fileList } = await nodeFileTrace([src]);
|
|
20
|
+
for (let file of fileList) {
|
|
21
|
+
const dest = path_1.join(destDir, file);
|
|
22
|
+
fs_extra_1.mkdirpSync(path_1.dirname(dest));
|
|
23
|
+
fs_extra_1.copyFileSync(file, dest);
|
|
24
|
+
}
|
|
25
|
+
const entryPoint = path_1.join(destDir, 'index.js');
|
|
26
|
+
if (!fs_extra_1.existsSync(entryPoint)) {
|
|
27
|
+
fs_extra_1.writeFileSync(entryPoint, `require('./${slash_1.default(path_1.relative(process.cwd(), src))}')`, 'utf8');
|
|
28
|
+
}
|
|
29
|
+
process.stdout.write(' done.\n');
|
|
30
|
+
}
|
|
31
|
+
exports.default = bundleWithNft;
|
|
32
|
+
function loadNFT() {
|
|
33
|
+
try {
|
|
34
|
+
const { nodeFileTrace } = require('@vercel/nft');
|
|
35
|
+
return nodeFileTrace;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.log('Required dependency @vercel/nft not found. Install @vercel/nft@^0.21.0 as a devDependency then retry this command.');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import webpack from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Compiles the router and layer0.config.js in production mode.
|
|
4
|
+
* Returns a promise that resolves to the router.
|
|
5
|
+
*/
|
|
6
|
+
export default function bundle(): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a webpack compiler for bundling the router in development.
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export declare function createCompiler(): webpack.Compiler;
|
|
@@ -0,0 +1,127 @@
|
|
|
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 config_1 = __importDefault(require("../config"));
|
|
7
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const paths_1 = require("./paths");
|
|
10
|
+
const resolveInPackage_1 = __importDefault(require("./resolveInPackage"));
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const logo_1 = __importDefault(require("../utils/logo"));
|
|
13
|
+
// compatible type definitions are not yet available for this after updating to webpack 5
|
|
14
|
+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
15
|
+
const destDir = path_1.join(process.cwd(), paths_1.JS_DIR);
|
|
16
|
+
/**
|
|
17
|
+
* Compiles the router and layer0.config.js in production mode.
|
|
18
|
+
* Returns a promise that resolves to the router.
|
|
19
|
+
*/
|
|
20
|
+
async function bundle() {
|
|
21
|
+
var _a;
|
|
22
|
+
// Use process.stdout.write to be able to concatenate `done.` to the same output line.
|
|
23
|
+
process.stdout.write(`> Bundling ${logo_1.default} router... `);
|
|
24
|
+
const webpackConfig = createConfig({ mode: 'production' });
|
|
25
|
+
const webpackStats = await new Promise((resolve, reject) => {
|
|
26
|
+
webpack_1.default(webpackConfig, (err, stats) => (err ? reject(err) : resolve(stats)));
|
|
27
|
+
});
|
|
28
|
+
const compilationErrors = (_a = webpackStats === null || webpackStats === void 0 ? void 0 : webpackStats.compilation) === null || _a === void 0 ? void 0 : _a.errors;
|
|
29
|
+
if (compilationErrors === null || compilationErrors === void 0 ? void 0 : compilationErrors.length) {
|
|
30
|
+
console.error('Errors occurred while bundling your router:', compilationErrors);
|
|
31
|
+
throw new Error('Bundling router failed.');
|
|
32
|
+
}
|
|
33
|
+
process.stdout.write('done.\n');
|
|
34
|
+
}
|
|
35
|
+
exports.default = bundle;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a webpack compiler for bundling the router in development.
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
function createCompiler() {
|
|
41
|
+
return webpack_1.default(createConfig());
|
|
42
|
+
}
|
|
43
|
+
exports.createCompiler = createCompiler;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a webpack config for bundling the router
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
function createConfig(webpackConfig) {
|
|
49
|
+
const routesPath = path_1.join(process.cwd(), config_1.default.get('routes'));
|
|
50
|
+
const configPath = [
|
|
51
|
+
path_1.join(process.cwd(), 'layer0.config.js'),
|
|
52
|
+
path_1.join(process.cwd(), 'layer0.config.cjs'),
|
|
53
|
+
].find(fs_1.existsSync);
|
|
54
|
+
if (!configPath) {
|
|
55
|
+
throw new Error('layer0.config.js not found. Run "layer0 init" to create this file.');
|
|
56
|
+
}
|
|
57
|
+
const rules = [];
|
|
58
|
+
try {
|
|
59
|
+
// skip ts-loader if typescript is not installed in the project
|
|
60
|
+
require.resolve('typescript');
|
|
61
|
+
rules.push({
|
|
62
|
+
test: /\.ts$/,
|
|
63
|
+
use: [
|
|
64
|
+
{
|
|
65
|
+
loader: resolveInPackage_1.default('ts-loader'),
|
|
66
|
+
options: {
|
|
67
|
+
onlyCompileBundledFiles: true,
|
|
68
|
+
compilerOptions: {
|
|
69
|
+
noEmit: false,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
exclude: /node_modules/,
|
|
75
|
+
});
|
|
76
|
+
// eslint-disable-next-line no-empty
|
|
77
|
+
}
|
|
78
|
+
catch (e) { }
|
|
79
|
+
try {
|
|
80
|
+
// skip babel-loader if babel is not installed in the project
|
|
81
|
+
require.resolve('@babel/core');
|
|
82
|
+
rules.push({
|
|
83
|
+
test: /\.js$/,
|
|
84
|
+
use: resolveInPackage_1.default('babel-loader'),
|
|
85
|
+
exclude: /node_modules/,
|
|
86
|
+
});
|
|
87
|
+
// eslint-disable-next-line no-empty
|
|
88
|
+
}
|
|
89
|
+
catch (e) { }
|
|
90
|
+
const plugins = [];
|
|
91
|
+
if (process.env.ANALYZE === 'true') {
|
|
92
|
+
plugins.push(new BundleAnalyzerPlugin({
|
|
93
|
+
analyzerMode: 'static',
|
|
94
|
+
reportFilename: '../bundle-analysis.html',
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
stats: 'errors-warnings',
|
|
99
|
+
devtool: process.env.NODE_ENV === 'production' ? false : 'cheap-module-source-map',
|
|
100
|
+
entry: {
|
|
101
|
+
routes: routesPath,
|
|
102
|
+
'layer0.config': configPath,
|
|
103
|
+
},
|
|
104
|
+
optimization: {
|
|
105
|
+
// This prevents webpack from string replacing process.env.NODE_ENV, which has been found to cause trouble on the server
|
|
106
|
+
// For example, without this, process.env.NODE_ENV doesn't have the correct value in the user's routes file.
|
|
107
|
+
nodeEnv: false,
|
|
108
|
+
},
|
|
109
|
+
output: {
|
|
110
|
+
path: destDir,
|
|
111
|
+
libraryTarget: 'umd',
|
|
112
|
+
},
|
|
113
|
+
module: {
|
|
114
|
+
rules,
|
|
115
|
+
},
|
|
116
|
+
resolve: {
|
|
117
|
+
extensions: ['.ts', '.js'],
|
|
118
|
+
},
|
|
119
|
+
externals: {
|
|
120
|
+
chalk: 'chalk',
|
|
121
|
+
},
|
|
122
|
+
target: 'node',
|
|
123
|
+
mode: 'development',
|
|
124
|
+
...webpackConfig,
|
|
125
|
+
plugins: [...plugins, ...((webpackConfig === null || webpackConfig === void 0 ? void 0 : webpackConfig.plugins) || [])],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { default as DeploymentBuilder } from './DeploymentBuilder';
|
|
2
|
+
export { ExecOptions } from './DeploymentBuilder';
|
|
3
|
+
export { default as resolveInPackage } from './resolveInPackage';
|
|
4
|
+
/**
|
|
5
|
+
* Options for build entry points
|
|
6
|
+
*/
|
|
7
|
+
export interface BuildOptions {
|
|
8
|
+
/**
|
|
9
|
+
* When set to true, the framework build entry point should skip the framework
|
|
10
|
+
* build (e.g. next build, sapper build, nuxt build, etc...)
|
|
11
|
+
*/
|
|
12
|
+
skipFramework: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Excludes the prod entry point from being bundled
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
excludeProdEntryPoint?: boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var DeploymentBuilder_1 = require("./DeploymentBuilder");
|
|
4
|
+
exports.DeploymentBuilder = DeploymentBuilder_1.default;
|
|
5
|
+
var resolveInPackage_1 = require("./resolveInPackage");
|
|
6
|
+
exports.resolveInPackage = resolveInPackage_1.default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns source files that should be added to the bundle based on:
|
|
3
|
+
*
|
|
4
|
+
* - The `sources` property of layer0.config.js, or, if not present
|
|
5
|
+
* - Excluding gitignored files
|
|
6
|
+
*
|
|
7
|
+
* @param appDir The application root directory
|
|
8
|
+
* @param sourcesConfig The value of the sources config in layer0.config.js
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export default function listSources(appDir: string, sourcesConfig: string[] | null): Promise<string[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const globby_1 = require("globby");
|
|
4
|
+
/**
|
|
5
|
+
* Returns source files that should be added to the bundle based on:
|
|
6
|
+
*
|
|
7
|
+
* - The `sources` property of layer0.config.js, or, if not present
|
|
8
|
+
* - Excluding gitignored files
|
|
9
|
+
*
|
|
10
|
+
* @param appDir The application root directory
|
|
11
|
+
* @param sourcesConfig The value of the sources config in layer0.config.js
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
async function listSources(appDir, sourcesConfig) {
|
|
15
|
+
const globs = (sourcesConfig || ['**/*']).concat('!node_modules', '!.env');
|
|
16
|
+
return globby_1.sync(globs, { gitignore: true, cwd: appDir });
|
|
17
|
+
}
|
|
18
|
+
exports.default = listSources;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The .layer0 build directory
|
|
3
|
+
*/
|
|
4
|
+
export declare const LAYER0_DIR = ".layer0";
|
|
5
|
+
/**
|
|
6
|
+
* The destination directory for JS server code
|
|
7
|
+
*/
|
|
8
|
+
export declare const JS_DIR: string;
|
|
9
|
+
/**
|
|
10
|
+
* The destination directory for static assets
|
|
11
|
+
*/
|
|
12
|
+
export declare const ASSETS_DIR: string;
|
|
13
|
+
export declare const PERMANENT_ASSETS_DIR: string;
|
|
14
|
+
/**
|
|
15
|
+
* The directory into which source code is copied for debugging purposes
|
|
16
|
+
*/
|
|
17
|
+
export declare const SOURCES_DIR: string;
|
|
18
|
+
/**
|
|
19
|
+
* The name of the compiled routes file
|
|
20
|
+
*/
|
|
21
|
+
export declare const ROUTES_FILE_NAME = "routes.js";
|
|
22
|
+
/**
|
|
23
|
+
* Returns the destination path within the lambda dir for the specified backend
|
|
24
|
+
* @param backend A backend name
|
|
25
|
+
* @return a file path
|
|
26
|
+
*/
|
|
27
|
+
export declare function pathForBackend(backend: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
/**
|
|
5
|
+
* The .layer0 build directory
|
|
6
|
+
*/
|
|
7
|
+
exports.LAYER0_DIR = '.layer0';
|
|
8
|
+
/**
|
|
9
|
+
* The destination directory for JS server code
|
|
10
|
+
*/
|
|
11
|
+
exports.JS_DIR = path_1.join(exports.LAYER0_DIR, 'lambda');
|
|
12
|
+
/**
|
|
13
|
+
* The destination directory for static assets
|
|
14
|
+
*/
|
|
15
|
+
exports.ASSETS_DIR = path_1.join(exports.LAYER0_DIR, 's3');
|
|
16
|
+
exports.PERMANENT_ASSETS_DIR = path_1.join(exports.LAYER0_DIR, 's3-permanent');
|
|
17
|
+
/**
|
|
18
|
+
* The directory into which source code is copied for debugging purposes
|
|
19
|
+
*/
|
|
20
|
+
exports.SOURCES_DIR = path_1.join(exports.LAYER0_DIR, 'src');
|
|
21
|
+
/**
|
|
22
|
+
* The name of the compiled routes file
|
|
23
|
+
*/
|
|
24
|
+
exports.ROUTES_FILE_NAME = 'routes.js';
|
|
25
|
+
/**
|
|
26
|
+
* Returns the destination path within the lambda dir for the specified backend
|
|
27
|
+
* @param backend A backend name
|
|
28
|
+
* @return a file path
|
|
29
|
+
*/
|
|
30
|
+
function pathForBackend(backend) {
|
|
31
|
+
return path_1.join('__backends__', `${backend}.js`);
|
|
32
|
+
}
|
|
33
|
+
exports.pathForBackend = pathForBackend;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 resolve_package_path_1 = __importDefault(require("resolve-package-path"));
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the path to a file within a node package
|
|
10
|
+
* @param pkg The name of a node package
|
|
11
|
+
* @param file The path to the file within the package
|
|
12
|
+
* @return A file path
|
|
13
|
+
*/
|
|
14
|
+
function resolveInPackage(pkg, ...file) {
|
|
15
|
+
let path = resolve_package_path_1.default(pkg, __dirname) || resolve_package_path_1.default(pkg, process.cwd());
|
|
16
|
+
if (!path)
|
|
17
|
+
throw new Error(`Package ${pkg} not found.`);
|
|
18
|
+
const packagePath = path_1.dirname(path);
|
|
19
|
+
return path_1.join(packagePath, ...file);
|
|
20
|
+
}
|
|
21
|
+
exports.default = resolveInPackage;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a route path pattern to a glob which captures all of the files
|
|
3
|
+
* which it could possibly match
|
|
4
|
+
* @param route The path pattern for a route
|
|
5
|
+
* @returns a glob pattern
|
|
6
|
+
*/
|
|
7
|
+
export declare function routeToGlob(route: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Converts a route path pattern to a relative directory name
|
|
10
|
+
* that would contain all potential matching files.
|
|
11
|
+
* @param pathPattern The path pattern passed as the first argument to serveStatic()
|
|
12
|
+
* @returns a relative directory path
|
|
13
|
+
*/
|
|
14
|
+
export declare function rootDirForPath(pathPattern: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Converts a route path pattern to a glob which captures all of the files
|
|
5
|
+
* which it could possibly match
|
|
6
|
+
* @param route The path pattern for a route
|
|
7
|
+
* @returns a glob pattern
|
|
8
|
+
*/
|
|
9
|
+
function routeToGlob(route) {
|
|
10
|
+
return `${rootDirForPath(route)}**/*`;
|
|
11
|
+
}
|
|
12
|
+
exports.routeToGlob = routeToGlob;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a route path pattern to a relative directory name
|
|
15
|
+
* that would contain all potential matching files.
|
|
16
|
+
* @param pathPattern The path pattern passed as the first argument to serveStatic()
|
|
17
|
+
* @returns a relative directory path
|
|
18
|
+
*/
|
|
19
|
+
function rootDirForPath(pathPattern) {
|
|
20
|
+
return pathPattern
|
|
21
|
+
.replace(/^\//, '') // remove leading slash - we are searching within the app dir, not the root
|
|
22
|
+
.replace(/:.*/i, ''); // remove everything after the first variable
|
|
23
|
+
}
|
|
24
|
+
exports.rootDirForPath = rootDirForPath;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Options for `createDevServer`
|
|
4
|
+
*/
|
|
5
|
+
export default interface DevServerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* A label to prepend to all output from the application server
|
|
8
|
+
*/
|
|
9
|
+
label?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A manual function to run to start the application server instead of using a command
|
|
12
|
+
*/
|
|
13
|
+
run?: (port: number) => void;
|
|
14
|
+
/**
|
|
15
|
+
* The command to start the application server in development mode
|
|
16
|
+
*/
|
|
17
|
+
command?: (port: number) => string;
|
|
18
|
+
/**
|
|
19
|
+
* An array of regular expressions to search for in application server output. Once all have been
|
|
20
|
+
* matched, The "Layer0 ready on http://127.0.0.1:3000" line will be displayed.
|
|
21
|
+
*/
|
|
22
|
+
ready?: RegExp[];
|
|
23
|
+
/**
|
|
24
|
+
* A function that is called every time the application server outputs a line to stdout. Return false
|
|
25
|
+
* to hide that line from the user. This can be useful in hiding lines like "Application ready on 127.0.0.1:3001"
|
|
26
|
+
* to keep the user from getting confused about which URL to use when testing the app.
|
|
27
|
+
*/
|
|
28
|
+
filterOutput?: (line: string) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Optional function that returns a webpack compiler that should halt requests during rebuilds
|
|
31
|
+
*/
|
|
32
|
+
webpackConfig?: Configuration;
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DevServerOptions from './DevServerOptions';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a development server to simulate Layer0 locally. Changes to your routes are automatically
|
|
4
|
+
* applied without restarting `layer0 run`.
|
|
5
|
+
* @param appReady An optional promise that resolves when your app is to receive requests
|
|
6
|
+
* @returns A promise that resolves when Layer0 is ready to receive requests
|
|
7
|
+
*/
|
|
8
|
+
export default function createDevServer(options?: DevServerOptions): Promise<any>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
6
|
+
if (mod && mod.__esModule) return mod;
|
|
7
|
+
var result = {};
|
|
8
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
9
|
+
result["default"] = mod;
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
/* istanbul ignore file */
|
|
14
|
+
const path_1 = require("path");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
const express_1 = __importDefault(require("express"));
|
|
17
|
+
const loadRouter_1 = __importDefault(require("../router/loadRouter"));
|
|
18
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
+
const Cache_1 = require("../cache/Cache");
|
|
20
|
+
const timing_1 = require("../timing");
|
|
21
|
+
const logo_1 = __importStar(require("../utils/logo"));
|
|
22
|
+
const http_proxy_1 = __importDefault(require("http-proxy"));
|
|
23
|
+
const runLocalApp_1 = __importDefault(require("./runLocalApp"));
|
|
24
|
+
const bundle_esbuild_1 = require("../deploy/bundle-esbuild");
|
|
25
|
+
const config_1 = __importDefault(require("../config"));
|
|
26
|
+
const paths_1 = require("../deploy/paths");
|
|
27
|
+
const serverlessCompatibilityMiddleware_1 = __importDefault(require("./serverlessCompatibilityMiddleware"));
|
|
28
|
+
const ports_1 = require("../utils/ports");
|
|
29
|
+
/**
|
|
30
|
+
* Creates a development server to simulate Layer0 locally. Changes to your routes are automatically
|
|
31
|
+
* applied without restarting `layer0 run`.
|
|
32
|
+
* @param appReady An optional promise that resolves when your app is to receive requests
|
|
33
|
+
* @returns A promise that resolves when Layer0 is ready to receive requests
|
|
34
|
+
*/
|
|
35
|
+
function createDevServer(options) {
|
|
36
|
+
process.env.LAYER0_LOCAL = 'true';
|
|
37
|
+
const layer0 = express_1.default().disable('x-powered-by');
|
|
38
|
+
const appReady = (options === null || options === void 0 ? void 0 : options.command) || (options === null || options === void 0 ? void 0 : options.run) ? runLocalApp_1.default(ports_1.jsPort, options) : Promise.resolve();
|
|
39
|
+
layer0.use(serverlessCompatibilityMiddleware_1.default);
|
|
40
|
+
// Optional webpack compiler provided by the user
|
|
41
|
+
if (options === null || options === void 0 ? void 0 : options.webpackConfig) {
|
|
42
|
+
// compatible type definitions are not yet available for this after updating to webpack 5
|
|
43
|
+
const middleware = require('webpack-dev-middleware');
|
|
44
|
+
const webpack = require('webpack');
|
|
45
|
+
layer0.use(middleware(webpack(options.webpackConfig), {
|
|
46
|
+
writeToDisk: true,
|
|
47
|
+
publicPath: path_1.join(process.cwd(), paths_1.ASSETS_DIR),
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
let router;
|
|
51
|
+
const reloadRouter = () => {
|
|
52
|
+
const routerPath = path_1.join(process.cwd(), paths_1.JS_DIR, path_1.basename(config_1.default.get('routes')));
|
|
53
|
+
// Ensure that the router is reloaded when a new version is compiled
|
|
54
|
+
// Note: there is a known memory leak here, but if we only reload the router when the user changes it,
|
|
55
|
+
// the memory growth will be slow enough to not be noticeable in most cases.
|
|
56
|
+
delete require.cache[routerPath];
|
|
57
|
+
router = loadRouter_1.default(routerPath)
|
|
58
|
+
.setBackend(constants_1.BACKENDS.permanentStatic, {
|
|
59
|
+
domainOrIp: ports_1.localhost,
|
|
60
|
+
port: ports_1.assetPort,
|
|
61
|
+
})
|
|
62
|
+
.setBackend(constants_1.BACKENDS.static, {
|
|
63
|
+
domainOrIp: ports_1.localhost,
|
|
64
|
+
port: ports_1.assetPort,
|
|
65
|
+
})
|
|
66
|
+
.setBackend(constants_1.BACKENDS.js, { domainOrIp: constants_1.JS_BACKEND_HOSTNAME, port: ports_1.jsPort });
|
|
67
|
+
};
|
|
68
|
+
const routerReady = bundle_esbuild_1.bundleRouterAndConfig({
|
|
69
|
+
watch: {
|
|
70
|
+
onRebuild(error, result) {
|
|
71
|
+
Cache_1.clearCache();
|
|
72
|
+
reloadRouter();
|
|
73
|
+
if (!error) {
|
|
74
|
+
console.log(`${logo_1.infoLogLabel} router compiled successfully.`);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
}).then(reloadRouter);
|
|
79
|
+
// `router` will always be initialized as the middleware will stop incoming requests until build is done.
|
|
80
|
+
layer0.use(timing_1.withTimings(async (req, res) => {
|
|
81
|
+
await routerReady;
|
|
82
|
+
return router.run(req, res); // @ts-ignore TypeScript complains here because our Request and Response objects don't exactly match express's
|
|
83
|
+
}));
|
|
84
|
+
const layer0Ready = new Promise((resolve, reject) => {
|
|
85
|
+
try {
|
|
86
|
+
const server = layer0.listen(ports_1.port, resolve);
|
|
87
|
+
// Proxy websocket requests to the JS backend. Gatsby needs this for example.
|
|
88
|
+
const proxy = http_proxy_1.default.createProxyServer({
|
|
89
|
+
target: {
|
|
90
|
+
host: constants_1.JS_BACKEND_HOSTNAME,
|
|
91
|
+
port: ports_1.jsPort,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
server.on('upgrade', function (req, socket, head) {
|
|
95
|
+
proxy.ws(req, socket, head);
|
|
96
|
+
});
|
|
97
|
+
server.on('error', function (error) {
|
|
98
|
+
console.log(error.message);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
reject(e);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return Promise.all([routerReady, appReady, layer0Ready])
|
|
106
|
+
.then(() => {
|
|
107
|
+
console.log('\n' +
|
|
108
|
+
logo_1.default +
|
|
109
|
+
' ' +
|
|
110
|
+
chalk_1.default.green(`ready on ${chalk_1.default.bold(chalk_1.default.underline(`http://${ports_1.localhost}:${ports_1.port}\n`))}`));
|
|
111
|
+
})
|
|
112
|
+
.catch(err => console.log('error', err));
|
|
113
|
+
}
|
|
114
|
+
exports.default = createDevServer;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var createDevServer_1 = require("./createDevServer");
|
|
4
|
+
exports.createDevServer = createDevServer_1.default;
|
|
5
|
+
var createDevServer_2 = require("./createDevServer");
|
|
6
|
+
exports.default = createDevServer_2.default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DevServerOptions from './DevServerOptions';
|
|
2
|
+
/**
|
|
3
|
+
* Runs the user's app in development mode
|
|
4
|
+
* @param port The port on which to listen
|
|
5
|
+
* @param local Describes how to construct the command that runs the app
|
|
6
|
+
* @returns A promise that resolves when the app is ready to receive requests.
|
|
7
|
+
*/
|
|
8
|
+
export default function runLocalApp(port: number, options: DevServerOptions): void | Promise<void>;
|
|
@@ -0,0 +1,73 @@
|
|
|
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 shelljs_1 = __importDefault(require("shelljs"));
|
|
7
|
+
const nonWebpackRequire_1 = __importDefault(require("../utils/nonWebpackRequire"));
|
|
8
|
+
// we don't bundle chalk because it's large and we only use it in development
|
|
9
|
+
const chalk = nonWebpackRequire_1.default('chalk');
|
|
10
|
+
/**
|
|
11
|
+
* Runs the user's app in development mode
|
|
12
|
+
* @param port The port on which to listen
|
|
13
|
+
* @param local Describes how to construct the command that runs the app
|
|
14
|
+
* @returns A promise that resolves when the app is ready to receive requests.
|
|
15
|
+
*/
|
|
16
|
+
function runLocalApp(port, options) {
|
|
17
|
+
const { run, command } = options;
|
|
18
|
+
// If dev server uses a manual run function, skip all command functionality
|
|
19
|
+
if (run) {
|
|
20
|
+
return run(port);
|
|
21
|
+
}
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
if (!command)
|
|
24
|
+
return;
|
|
25
|
+
const label = chalk.grey(options.label || 'app');
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
try {
|
|
29
|
+
const childProcess = shelljs_1.default.exec(command(port), {
|
|
30
|
+
async: true,
|
|
31
|
+
env: { ...process.env, PORT: port.toString(), FORCE_COLOR: 'true' },
|
|
32
|
+
silent: true,
|
|
33
|
+
}, code => {
|
|
34
|
+
if (code > 0) {
|
|
35
|
+
console.error(chalk.red('Layer0 encountered a fatal error while running your application. Exiting...'));
|
|
36
|
+
reject();
|
|
37
|
+
process.exit(code);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
resolve();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
/* istanbul ignore next */
|
|
44
|
+
(_a = childProcess.stderr) === null || _a === void 0 ? void 0 : _a.on('data', data => process.stderr.write(`${label} ${data}`));
|
|
45
|
+
const ready = options.ready || [];
|
|
46
|
+
const filterOutput = options.filterOutput || ((_line) => true);
|
|
47
|
+
/* istanbul ignore next */
|
|
48
|
+
(_b = childProcess.stdout) === null || _b === void 0 ? void 0 : _b.on('data', data => {
|
|
49
|
+
let matched = false;
|
|
50
|
+
ready.some((pattern, i) => {
|
|
51
|
+
if (pattern.test(data)) {
|
|
52
|
+
ready.splice(i, 1);
|
|
53
|
+
matched = true;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (ready.length === 0) {
|
|
57
|
+
resolve();
|
|
58
|
+
}
|
|
59
|
+
if (matched || !filterOutput(data)) {
|
|
60
|
+
return; // hide the ready line so that the user doesn't see two URLs and get confused.
|
|
61
|
+
}
|
|
62
|
+
process.stdout.write(`${label} ${data}`);
|
|
63
|
+
if (!data.endsWith('\n')) {
|
|
64
|
+
process.stdout.write('\n');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
reject(e);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.default = runLocalApp;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* This middleware adds getHeaders(), getHeader(name), setHeader(name, value), and removeHeader(name) to Express's
|
|
4
|
+
* request object, making it compatible with the request object we provide in serverless.
|
|
5
|
+
* See lambda/reqResMapper.ts
|
|
6
|
+
* @param request
|
|
7
|
+
* @param _response
|
|
8
|
+
* @param next
|
|
9
|
+
*/
|
|
10
|
+
declare const serverlessCompatibilityMiddleware: RequestHandler;
|
|
11
|
+
export default serverlessCompatibilityMiddleware;
|