@vercel/static-build 0.18.1-canary.1 → 0.22.2-canary.2

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/dist/launcher.js DELETED
@@ -1,130 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAwsLauncher = exports.makeAwsLauncher = exports.getNowLauncher = exports.makeNowLauncher = void 0;
4
- const url_1 = require("url");
5
- const http_1 = require("http");
6
- const bridge_1 = require("./bridge");
7
- function makeNowLauncher(config) {
8
- const { entrypointPath, bridgePath, helpersPath, sourcemapSupportPath, shouldAddHelpers = false, shouldAddSourcemapSupport = false, } = config;
9
- return `const bridge_1 = require(${JSON.stringify(bridgePath)});
10
- const http_1 = require("http");
11
- ${shouldAddSourcemapSupport
12
- ? `require(${JSON.stringify(sourcemapSupportPath)});`
13
- : ''}
14
- const entrypointPath = ${JSON.stringify(entrypointPath)};
15
- const shouldAddHelpers = ${JSON.stringify(shouldAddHelpers)};
16
- const helpersPath = ${JSON.stringify(helpersPath)};
17
-
18
- const bridge = (${getNowLauncher(config)})();
19
- exports.launcher = bridge.launcher;`;
20
- }
21
- exports.makeNowLauncher = makeNowLauncher;
22
- function getNowLauncher({ entrypointPath, helpersPath, shouldAddHelpers = false, }) {
23
- return function () {
24
- let bridge = new bridge_1.Bridge();
25
- let isServerListening = false;
26
- const originalListen = http_1.Server.prototype.listen;
27
- http_1.Server.prototype.listen = function listen() {
28
- isServerListening = true;
29
- console.log('Legacy server listening...');
30
- bridge.setServer(this);
31
- http_1.Server.prototype.listen = originalListen;
32
- bridge.listen();
33
- return this;
34
- };
35
- if (!process.env.NODE_ENV) {
36
- const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
37
- process.env.NODE_ENV = region === 'dev1' ? 'development' : 'production';
38
- }
39
- try {
40
- // eslint-disable-next-line @typescript-eslint/no-var-requires
41
- let listener = require(entrypointPath);
42
- if (listener.default)
43
- listener = listener.default;
44
- if (typeof listener.listen === 'function') {
45
- http_1.Server.prototype.listen = originalListen;
46
- const server = listener;
47
- bridge.setServer(server);
48
- bridge.listen();
49
- }
50
- else if (typeof listener === 'function') {
51
- http_1.Server.prototype.listen = originalListen;
52
- let server;
53
- if (shouldAddHelpers) {
54
- bridge = new bridge_1.Bridge(undefined, true);
55
- server = require(helpersPath).createServerWithHelpers(listener, bridge);
56
- }
57
- else {
58
- server = http_1.createServer(listener);
59
- }
60
- bridge.setServer(server);
61
- bridge.listen();
62
- }
63
- else if (typeof listener === 'object' &&
64
- Object.keys(listener).length === 0) {
65
- setTimeout(() => {
66
- if (!isServerListening) {
67
- console.error('No exports found in module %j.', entrypointPath);
68
- console.error('Did you forget to export a function or a server?');
69
- process.exit(1);
70
- }
71
- }, 5000);
72
- }
73
- else {
74
- console.error('Invalid export found in module %j.', entrypointPath);
75
- console.error('The default export must be a function or server.');
76
- }
77
- }
78
- catch (err) {
79
- if (err.code === 'MODULE_NOT_FOUND') {
80
- console.error(err.message);
81
- console.error('Did you forget to add it to "dependencies" in `package.json`?');
82
- }
83
- else {
84
- console.error(err);
85
- }
86
- process.exit(1);
87
- }
88
- return bridge;
89
- };
90
- }
91
- exports.getNowLauncher = getNowLauncher;
92
- function makeAwsLauncher(config) {
93
- const { entrypointPath, awsLambdaHandler = '' } = config;
94
- return `const url_1 = require("url");
95
- const funcName = ${JSON.stringify(awsLambdaHandler.split('.').pop())};
96
- const entrypointPath = ${JSON.stringify(entrypointPath)};
97
- exports.launcher = ${getAwsLauncher(config)}`;
98
- }
99
- exports.makeAwsLauncher = makeAwsLauncher;
100
- function getAwsLauncher({ entrypointPath, awsLambdaHandler = '', }) {
101
- const funcName = awsLambdaHandler.split('.').pop();
102
- if (typeof funcName !== 'string') {
103
- throw new TypeError('Expected "string"');
104
- }
105
- // @ts-ignore
106
- return function (e, context, callback) {
107
- const { path, method: httpMethod, body, headers } = JSON.parse(e.body);
108
- const { query } = url_1.parse(path, true);
109
- const queryStringParameters = {};
110
- for (const [key, value] of Object.entries(query)) {
111
- if (typeof value === 'string') {
112
- queryStringParameters[key] = value;
113
- }
114
- }
115
- const awsGatewayEvent = {
116
- resource: '/{proxy+}',
117
- path: path,
118
- httpMethod: httpMethod,
119
- body: body,
120
- isBase64Encoded: true,
121
- queryStringParameters: queryStringParameters,
122
- multiValueQueryStringParameters: query,
123
- headers: headers,
124
- };
125
- // eslint-disable-next-line @typescript-eslint/no-var-requires
126
- const mod = require(entrypointPath);
127
- return mod[funcName](awsGatewayEvent, context, callback);
128
- };
129
- }
130
- exports.getAwsLauncher = getAwsLauncher;