@aligent/cdk-prerender-proxy 0.2.4 → 0.2.5-beta
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/lib/handlers/cache-control.ts +7 -20
- package/lib/handlers/error-response.ts +8 -51
- package/lib/handlers/node_modules/.package-lock.json +32 -3
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/index.d.ts +6 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/index.js +14 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/cache-control.d.ts +3 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/cache-control.js +24 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/error-response.d.ts +3 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/error-response.js +50 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender-check.d.ts +3 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender-check.js +28 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender.d.ts +3 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/prerender.js +49 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/redirect.d.ts +3 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/lib/redirect.js +33 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/package.json +27 -0
- package/lib/handlers/node_modules/@aligent/cdk-lambda-at-edge-handlers/tsconfig.json +3 -0
- package/lib/handlers/node_modules/@middy/core/LICENSE +21 -0
- package/lib/handlers/node_modules/@middy/core/README.md +65 -0
- package/lib/handlers/node_modules/@middy/core/index.cjs +207 -0
- package/lib/handlers/node_modules/@middy/core/index.d.ts +91 -0
- package/lib/handlers/node_modules/@middy/core/index.js +199 -0
- package/lib/handlers/node_modules/@middy/core/package.json +65 -0
- package/lib/handlers/node_modules/@types/node/README.md +4 -4
- package/lib/handlers/node_modules/@types/node/assert/strict.d.ts +5 -1
- package/lib/handlers/node_modules/@types/node/assert.d.ts +904 -67
- package/lib/handlers/node_modules/@types/node/async_hooks.d.ts +371 -96
- package/lib/handlers/node_modules/@types/node/buffer.d.ts +2199 -25
- package/lib/handlers/node_modules/@types/node/child_process.d.ts +1151 -308
- package/lib/handlers/node_modules/@types/node/cluster.d.ts +356 -208
- package/lib/handlers/node_modules/@types/node/console.d.ts +324 -45
- package/lib/handlers/node_modules/@types/node/constants.d.ts +8 -3
- package/lib/handlers/node_modules/@types/node/crypto.d.ts +3230 -846
- package/lib/handlers/node_modules/@types/node/dgram.d.ts +478 -74
- package/lib/handlers/node_modules/@types/node/diagnostics_channel.d.ts +153 -0
- package/lib/handlers/node_modules/@types/node/dns/promises.d.ts +308 -35
- package/lib/handlers/node_modules/@types/node/dns.d.ts +444 -107
- package/lib/handlers/node_modules/@types/node/dom-events.d.ts +126 -0
- package/lib/handlers/node_modules/@types/node/domain.d.ts +162 -16
- package/lib/handlers/node_modules/@types/node/events.d.ts +624 -39
- package/lib/handlers/node_modules/@types/node/fs/promises.d.ts +911 -365
- package/lib/handlers/node_modules/@types/node/fs.d.ts +2611 -978
- package/lib/handlers/node_modules/@types/node/globals.d.ts +66 -421
- package/lib/handlers/node_modules/@types/node/globals.global.d.ts +1 -1
- package/lib/handlers/node_modules/@types/node/http.d.ts +1416 -199
- package/lib/handlers/node_modules/@types/node/http2.d.ts +1688 -530
- package/lib/handlers/node_modules/@types/node/https.d.ts +532 -26
- package/lib/handlers/node_modules/@types/node/index.d.ts +92 -16
- package/lib/handlers/node_modules/@types/node/inspector.d.ts +511 -811
- package/lib/handlers/node_modules/@types/node/module.d.ts +75 -13
- package/lib/handlers/node_modules/@types/node/net.d.ts +710 -167
- package/lib/handlers/node_modules/@types/node/os.d.ts +252 -25
- package/lib/handlers/node_modules/@types/node/package.json +30 -25
- package/lib/handlers/node_modules/@types/node/path.d.ts +59 -31
- package/lib/handlers/node_modules/@types/node/perf_hooks.d.ts +420 -105
- package/lib/handlers/node_modules/@types/node/process.d.ts +1249 -228
- package/lib/handlers/node_modules/@types/node/punycode.d.ts +67 -25
- package/lib/handlers/node_modules/@types/node/querystring.d.ts +113 -10
- package/lib/handlers/node_modules/@types/node/readline/promises.d.ts +143 -0
- package/lib/handlers/node_modules/@types/node/readline.d.ts +570 -109
- package/lib/handlers/node_modules/@types/node/repl.d.ts +154 -125
- package/lib/handlers/node_modules/@types/node/stream/consumers.d.ts +12 -0
- package/lib/handlers/node_modules/@types/node/stream/promises.d.ts +18 -43
- package/lib/handlers/node_modules/@types/node/stream/web.d.ts +330 -0
- package/lib/handlers/node_modules/@types/node/stream.d.ts +1117 -248
- package/lib/handlers/node_modules/@types/node/string_decoder.d.ts +60 -0
- package/lib/handlers/node_modules/@types/node/test.d.ts +446 -0
- package/lib/handlers/node_modules/@types/node/timers/promises.d.ts +81 -9
- package/lib/handlers/node_modules/@types/node/timers.d.ts +84 -17
- package/lib/handlers/node_modules/@types/node/tls.d.ts +510 -275
- package/lib/handlers/node_modules/@types/node/trace_events.d.ts +120 -10
- package/lib/handlers/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/assert.d.ts +961 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/async_hooks.d.ts +501 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/buffer.d.ts +2259 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/child_process.d.ts +1369 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/cluster.d.ts +410 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/console.d.ts +412 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/crypto.d.ts +3964 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +153 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/dns/promises.d.ts +370 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/dns.d.ts +659 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/events.d.ts +678 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/fs/promises.d.ts +1138 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/fs.d.ts +3872 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/globals.d.ts +294 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/http.d.ts +1651 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/http2.d.ts +2134 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/https.d.ts +542 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/index.d.ts +88 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/inspector.d.ts +2741 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/module.d.ts +114 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/net.d.ts +869 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/os.d.ts +466 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/path.d.ts +191 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/perf_hooks.d.ts +625 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/process.d.ts +1482 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/readline.d.ts +653 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/stream.d.ts +1340 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/test.d.ts +446 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/timers.d.ts +94 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/tls.d.ts +1028 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/url.d.ts +897 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/util.d.ts +1926 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/v8.d.ts +396 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/vm.d.ts +509 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/worker_threads.d.ts +689 -0
- package/lib/handlers/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
- package/lib/handlers/node_modules/@types/node/tty.d.ts +163 -23
- package/lib/handlers/node_modules/@types/node/url.d.ts +825 -44
- package/lib/handlers/node_modules/@types/node/util.d.ts +1842 -72
- package/lib/handlers/node_modules/@types/node/v8.d.ts +276 -78
- package/lib/handlers/node_modules/@types/node/vm.d.ts +410 -53
- package/lib/handlers/node_modules/@types/node/wasi.d.ts +102 -30
- package/lib/handlers/node_modules/@types/node/worker_threads.d.ts +559 -152
- package/lib/handlers/node_modules/@types/node/zlib.d.ts +234 -78
- package/lib/handlers/node_modules/esbuild/README.md +3 -0
- package/lib/handlers/node_modules/esbuild/bin/esbuild +0 -0
- package/lib/handlers/node_modules/esbuild/install.js +256 -0
- package/lib/handlers/node_modules/esbuild/lib/main.d.ts +397 -0
- package/lib/handlers/node_modules/esbuild/lib/main.js +1939 -0
- package/lib/handlers/node_modules/esbuild/package.json +15 -0
- package/lib/handlers/package-lock.json +62 -6
- package/lib/handlers/package.json +6 -1
- package/lib/handlers/prerender-check.ts +8 -27
- package/lib/handlers/prerender.ts +8 -43
- package/package.json +1 -1
- package/lib/handlers/node_modules/@types/node/base.d.ts +0 -19
- package/lib/handlers/node_modules/@types/node/diagnostic_channel.d.ts +0 -34
- package/lib/handlers/node_modules/@types/node/ts3.6/assert.d.ts +0 -98
- package/lib/handlers/node_modules/@types/node/ts3.6/base.d.ts +0 -68
- package/lib/handlers/node_modules/@types/node/ts3.6/index.d.ts +0 -7
- package/lib/handlers/node_modules/@types/node/util/types.d.ts +0 -53
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
const fs = require("fs");
|
|
21
|
+
const os = require("os");
|
|
22
|
+
const path = require("path");
|
|
23
|
+
const zlib = require("zlib");
|
|
24
|
+
const https = require("https");
|
|
25
|
+
const child_process = require("child_process");
|
|
26
|
+
const version = "0.12.15";
|
|
27
|
+
const binPath = path.join(__dirname, "bin", "esbuild");
|
|
28
|
+
async function installBinaryFromPackage(name, fromPath, toPath) {
|
|
29
|
+
const cachePath = getCachePath(name);
|
|
30
|
+
try {
|
|
31
|
+
fs.copyFileSync(cachePath, toPath);
|
|
32
|
+
fs.chmodSync(toPath, 493);
|
|
33
|
+
validateBinaryVersion(toPath);
|
|
34
|
+
const now = new Date();
|
|
35
|
+
fs.utimesSync(cachePath, now, now);
|
|
36
|
+
return;
|
|
37
|
+
} catch (e) {
|
|
38
|
+
}
|
|
39
|
+
let buffer;
|
|
40
|
+
let didFail = false;
|
|
41
|
+
try {
|
|
42
|
+
buffer = installUsingNPM(name, fromPath);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
didFail = true;
|
|
45
|
+
console.error(`Trying to install "${name}" using npm`);
|
|
46
|
+
console.error(`Failed to install "${name}" using npm: ${err && err.message || err}`);
|
|
47
|
+
}
|
|
48
|
+
if (!buffer) {
|
|
49
|
+
const url = `https://registry.npmjs.org/${name}/-/${name}-${version}.tgz`;
|
|
50
|
+
console.error(`Trying to download ${JSON.stringify(url)}`);
|
|
51
|
+
try {
|
|
52
|
+
buffer = extractFileFromTarGzip(await fetch(url), fromPath);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error(`Failed to download ${JSON.stringify(url)}: ${err && err.message || err}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!buffer) {
|
|
58
|
+
console.error(`Install unsuccessful`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
fs.writeFileSync(toPath, buffer, { mode: 493 });
|
|
62
|
+
try {
|
|
63
|
+
validateBinaryVersion(toPath);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error(`The version of the downloaded binary is incorrect: ${err && err.message || err}`);
|
|
66
|
+
console.error(`Install unsuccessful`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
fs.mkdirSync(path.dirname(cachePath), {
|
|
71
|
+
recursive: true,
|
|
72
|
+
mode: 448
|
|
73
|
+
});
|
|
74
|
+
fs.copyFileSync(toPath, cachePath);
|
|
75
|
+
cleanCacheLRU(cachePath);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
}
|
|
78
|
+
if (didFail)
|
|
79
|
+
console.error(`Install successful`);
|
|
80
|
+
}
|
|
81
|
+
function validateBinaryVersion(binaryPath) {
|
|
82
|
+
const stdout = child_process.execFileSync(binaryPath, ["--version"]).toString().trim();
|
|
83
|
+
if (stdout !== version) {
|
|
84
|
+
throw new Error(`Expected ${JSON.stringify(version)} but got ${JSON.stringify(stdout)}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function getCachePath(name) {
|
|
88
|
+
const home = os.homedir();
|
|
89
|
+
const common = ["esbuild", "bin", `${name}@${version}`];
|
|
90
|
+
if (process.platform === "darwin")
|
|
91
|
+
return path.join(home, "Library", "Caches", ...common);
|
|
92
|
+
if (process.platform === "win32")
|
|
93
|
+
return path.join(home, "AppData", "Local", "Cache", ...common);
|
|
94
|
+
const XDG_CACHE_HOME = process.env.XDG_CACHE_HOME;
|
|
95
|
+
if (process.platform === "linux" && XDG_CACHE_HOME && path.isAbsolute(XDG_CACHE_HOME))
|
|
96
|
+
return path.join(XDG_CACHE_HOME, ...common);
|
|
97
|
+
return path.join(home, ".cache", ...common);
|
|
98
|
+
}
|
|
99
|
+
function cleanCacheLRU(fileToKeep) {
|
|
100
|
+
const dir = path.dirname(fileToKeep);
|
|
101
|
+
const entries = [];
|
|
102
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
103
|
+
const entryPath = path.join(dir, entry);
|
|
104
|
+
try {
|
|
105
|
+
const stats = fs.statSync(entryPath);
|
|
106
|
+
entries.push({ path: entryPath, mtime: stats.mtime });
|
|
107
|
+
} catch (e) {
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
entries.sort((a, b) => +b.mtime - +a.mtime);
|
|
111
|
+
for (const entry of entries.slice(5)) {
|
|
112
|
+
try {
|
|
113
|
+
fs.unlinkSync(entry.path);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function fetch(url) {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
https.get(url, (res) => {
|
|
121
|
+
if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
|
|
122
|
+
return fetch(res.headers.location).then(resolve, reject);
|
|
123
|
+
if (res.statusCode !== 200)
|
|
124
|
+
return reject(new Error(`Server responded with ${res.statusCode}`));
|
|
125
|
+
let chunks = [];
|
|
126
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
127
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
128
|
+
}).on("error", reject);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function extractFileFromTarGzip(buffer, file) {
|
|
132
|
+
try {
|
|
133
|
+
buffer = zlib.unzipSync(buffer);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
|
|
136
|
+
}
|
|
137
|
+
let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
|
|
138
|
+
let offset = 0;
|
|
139
|
+
file = `package/${file}`;
|
|
140
|
+
while (offset < buffer.length) {
|
|
141
|
+
let name = str(offset, 100);
|
|
142
|
+
let size = parseInt(str(offset + 124, 12), 8);
|
|
143
|
+
offset += 512;
|
|
144
|
+
if (!isNaN(size)) {
|
|
145
|
+
if (name === file)
|
|
146
|
+
return buffer.subarray(offset, offset + size);
|
|
147
|
+
offset += size + 511 & ~511;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
throw new Error(`Could not find ${JSON.stringify(file)} in archive`);
|
|
151
|
+
}
|
|
152
|
+
function installUsingNPM(name, file) {
|
|
153
|
+
const installDir = path.join(os.tmpdir(), "esbuild-" + Math.random().toString(36).slice(2));
|
|
154
|
+
fs.mkdirSync(installDir, { recursive: true });
|
|
155
|
+
fs.writeFileSync(path.join(installDir, "package.json"), "{}");
|
|
156
|
+
const env = __spreadProps(__spreadValues({}, process.env), { npm_config_global: void 0 });
|
|
157
|
+
child_process.execSync(`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${name}@${version}`, { cwd: installDir, stdio: "pipe", env });
|
|
158
|
+
const buffer = fs.readFileSync(path.join(installDir, "node_modules", name, file));
|
|
159
|
+
try {
|
|
160
|
+
removeRecursive(installDir);
|
|
161
|
+
} catch (e) {
|
|
162
|
+
}
|
|
163
|
+
return buffer;
|
|
164
|
+
}
|
|
165
|
+
function removeRecursive(dir) {
|
|
166
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
167
|
+
const entryPath = path.join(dir, entry);
|
|
168
|
+
let stats;
|
|
169
|
+
try {
|
|
170
|
+
stats = fs.lstatSync(entryPath);
|
|
171
|
+
} catch (e) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (stats.isDirectory())
|
|
175
|
+
removeRecursive(entryPath);
|
|
176
|
+
else
|
|
177
|
+
fs.unlinkSync(entryPath);
|
|
178
|
+
}
|
|
179
|
+
fs.rmdirSync(dir);
|
|
180
|
+
}
|
|
181
|
+
function isYarnBerryOrNewer() {
|
|
182
|
+
const { npm_config_user_agent } = process.env;
|
|
183
|
+
if (npm_config_user_agent) {
|
|
184
|
+
const match = npm_config_user_agent.match(/yarn\/(\d+)/);
|
|
185
|
+
if (match && match[1]) {
|
|
186
|
+
return parseInt(match[1], 10) >= 2;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
function installDirectly(name) {
|
|
192
|
+
if (process.env.ESBUILD_BINARY_PATH) {
|
|
193
|
+
fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, binPath);
|
|
194
|
+
validateBinaryVersion(binPath);
|
|
195
|
+
} else {
|
|
196
|
+
const tempBinPath = binPath + "__";
|
|
197
|
+
installBinaryFromPackage(name, "bin/esbuild", tempBinPath).then(() => fs.renameSync(tempBinPath, binPath)).catch((e) => setImmediate(() => {
|
|
198
|
+
throw e;
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function installWithWrapper(name, fromPath, toPath) {
|
|
203
|
+
fs.writeFileSync(binPath, `#!/usr/bin/env node
|
|
204
|
+
const path = require('path');
|
|
205
|
+
const esbuild_exe = path.join(__dirname, '..', ${JSON.stringify(toPath)});
|
|
206
|
+
const child_process = require('child_process');
|
|
207
|
+
const { status } = child_process.spawnSync(esbuild_exe, process.argv.slice(2), { stdio: 'inherit' });
|
|
208
|
+
process.exitCode = status === null ? 1 : status;
|
|
209
|
+
`);
|
|
210
|
+
const absToPath = path.join(__dirname, toPath);
|
|
211
|
+
if (process.env.ESBUILD_BINARY_PATH) {
|
|
212
|
+
fs.copyFileSync(process.env.ESBUILD_BINARY_PATH, absToPath);
|
|
213
|
+
validateBinaryVersion(absToPath);
|
|
214
|
+
} else {
|
|
215
|
+
installBinaryFromPackage(name, fromPath, absToPath).catch((e) => setImmediate(() => {
|
|
216
|
+
throw e;
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function installOnUnix(name) {
|
|
221
|
+
if (isYarnBerryOrNewer()) {
|
|
222
|
+
installWithWrapper(name, "bin/esbuild", "esbuild");
|
|
223
|
+
} else {
|
|
224
|
+
installDirectly(name);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function installOnWindows(name) {
|
|
228
|
+
installWithWrapper(name, "esbuild.exe", "esbuild.exe");
|
|
229
|
+
}
|
|
230
|
+
const platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
231
|
+
const knownWindowsPackages = {
|
|
232
|
+
"win32 ia32 LE": "esbuild-windows-32",
|
|
233
|
+
"win32 x64 LE": "esbuild-windows-64"
|
|
234
|
+
};
|
|
235
|
+
const knownUnixlikePackages = {
|
|
236
|
+
"android arm64 LE": "esbuild-android-arm64",
|
|
237
|
+
"darwin arm64 LE": "esbuild-darwin-arm64",
|
|
238
|
+
"darwin x64 LE": "esbuild-darwin-64",
|
|
239
|
+
"freebsd arm64 LE": "esbuild-freebsd-arm64",
|
|
240
|
+
"freebsd x64 LE": "esbuild-freebsd-64",
|
|
241
|
+
"openbsd x64 LE": "esbuild-openbsd-64",
|
|
242
|
+
"linux arm LE": "esbuild-linux-arm",
|
|
243
|
+
"linux arm64 LE": "esbuild-linux-arm64",
|
|
244
|
+
"linux ia32 LE": "esbuild-linux-32",
|
|
245
|
+
"linux mips64el LE": "esbuild-linux-mips64le",
|
|
246
|
+
"linux ppc64 LE": "esbuild-linux-ppc64le",
|
|
247
|
+
"linux x64 LE": "esbuild-linux-64"
|
|
248
|
+
};
|
|
249
|
+
if (platformKey in knownWindowsPackages) {
|
|
250
|
+
installOnWindows(knownWindowsPackages[platformKey]);
|
|
251
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
252
|
+
installOnUnix(knownUnixlikePackages[platformKey]);
|
|
253
|
+
} else {
|
|
254
|
+
console.error(`Unsupported platform: ${platformKey}`);
|
|
255
|
+
process.exit(1);
|
|
256
|
+
}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
export type Platform = 'browser' | 'node' | 'neutral';
|
|
2
|
+
export type Format = 'iife' | 'cjs' | 'esm';
|
|
3
|
+
export type Loader = 'js' | 'jsx' | 'ts' | 'tsx' | 'css' | 'json' | 'text' | 'base64' | 'file' | 'dataurl' | 'binary' | 'default';
|
|
4
|
+
export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent';
|
|
5
|
+
export type Charset = 'ascii' | 'utf8';
|
|
6
|
+
export type TreeShaking = true | 'ignore-annotations';
|
|
7
|
+
|
|
8
|
+
interface CommonOptions {
|
|
9
|
+
sourcemap?: boolean | 'inline' | 'external' | 'both';
|
|
10
|
+
legalComments?: 'none' | 'inline' | 'eof' | 'linked' | 'external';
|
|
11
|
+
sourceRoot?: string;
|
|
12
|
+
sourcesContent?: boolean;
|
|
13
|
+
|
|
14
|
+
format?: Format;
|
|
15
|
+
globalName?: string;
|
|
16
|
+
target?: string | string[];
|
|
17
|
+
|
|
18
|
+
minify?: boolean;
|
|
19
|
+
minifyWhitespace?: boolean;
|
|
20
|
+
minifyIdentifiers?: boolean;
|
|
21
|
+
minifySyntax?: boolean;
|
|
22
|
+
charset?: Charset;
|
|
23
|
+
treeShaking?: TreeShaking;
|
|
24
|
+
|
|
25
|
+
jsx?: 'transform' | 'preserve';
|
|
26
|
+
jsxFactory?: string;
|
|
27
|
+
jsxFragment?: string;
|
|
28
|
+
|
|
29
|
+
define?: { [key: string]: string };
|
|
30
|
+
pure?: string[];
|
|
31
|
+
keepNames?: boolean;
|
|
32
|
+
|
|
33
|
+
color?: boolean;
|
|
34
|
+
logLevel?: LogLevel;
|
|
35
|
+
logLimit?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface BuildOptions extends CommonOptions {
|
|
39
|
+
bundle?: boolean;
|
|
40
|
+
splitting?: boolean;
|
|
41
|
+
preserveSymlinks?: boolean;
|
|
42
|
+
outfile?: string;
|
|
43
|
+
metafile?: boolean;
|
|
44
|
+
outdir?: string;
|
|
45
|
+
outbase?: string;
|
|
46
|
+
platform?: Platform;
|
|
47
|
+
external?: string[];
|
|
48
|
+
loader?: { [ext: string]: Loader };
|
|
49
|
+
resolveExtensions?: string[];
|
|
50
|
+
mainFields?: string[];
|
|
51
|
+
conditions?: string[];
|
|
52
|
+
write?: boolean;
|
|
53
|
+
allowOverwrite?: boolean;
|
|
54
|
+
tsconfig?: string;
|
|
55
|
+
outExtension?: { [ext: string]: string };
|
|
56
|
+
publicPath?: string;
|
|
57
|
+
entryNames?: string;
|
|
58
|
+
chunkNames?: string;
|
|
59
|
+
assetNames?: string;
|
|
60
|
+
inject?: string[];
|
|
61
|
+
banner?: { [type: string]: string };
|
|
62
|
+
footer?: { [type: string]: string };
|
|
63
|
+
incremental?: boolean;
|
|
64
|
+
entryPoints?: string[] | Record<string, string>;
|
|
65
|
+
stdin?: StdinOptions;
|
|
66
|
+
plugins?: Plugin[];
|
|
67
|
+
absWorkingDir?: string;
|
|
68
|
+
nodePaths?: string[]; // The "NODE_PATH" variable from Node.js
|
|
69
|
+
watch?: boolean | WatchMode;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface WatchMode {
|
|
73
|
+
onRebuild?: (error: BuildFailure | null, result: BuildResult | null) => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface StdinOptions {
|
|
77
|
+
contents: string;
|
|
78
|
+
resolveDir?: string;
|
|
79
|
+
sourcefile?: string;
|
|
80
|
+
loader?: Loader;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface Message {
|
|
84
|
+
pluginName: string;
|
|
85
|
+
text: string;
|
|
86
|
+
location: Location | null;
|
|
87
|
+
notes: Note[];
|
|
88
|
+
|
|
89
|
+
// Optional user-specified data that is passed through unmodified. You can
|
|
90
|
+
// use this to stash the original error, for example.
|
|
91
|
+
detail: any;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface Note {
|
|
95
|
+
text: string;
|
|
96
|
+
location: Location | null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface Location {
|
|
100
|
+
file: string;
|
|
101
|
+
namespace: string;
|
|
102
|
+
line: number; // 1-based
|
|
103
|
+
column: number; // 0-based, in bytes
|
|
104
|
+
length: number; // in bytes
|
|
105
|
+
lineText: string;
|
|
106
|
+
suggestion: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface OutputFile {
|
|
110
|
+
path: string;
|
|
111
|
+
contents: Uint8Array; // "text" as bytes
|
|
112
|
+
text: string; // "contents" as text
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface BuildInvalidate {
|
|
116
|
+
(): Promise<BuildIncremental>;
|
|
117
|
+
dispose(): void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface BuildIncremental extends BuildResult {
|
|
121
|
+
rebuild: BuildInvalidate;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface BuildResult {
|
|
125
|
+
errors: Message[];
|
|
126
|
+
warnings: Message[];
|
|
127
|
+
outputFiles?: OutputFile[]; // Only when "write: false"
|
|
128
|
+
rebuild?: BuildInvalidate; // Only when "incremental: true"
|
|
129
|
+
stop?: () => void; // Only when "watch: true"
|
|
130
|
+
metafile?: Metafile; // Only when "metafile: true"
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface BuildFailure extends Error {
|
|
134
|
+
errors: Message[];
|
|
135
|
+
warnings: Message[];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface ServeOptions {
|
|
139
|
+
port?: number;
|
|
140
|
+
host?: string;
|
|
141
|
+
servedir?: string;
|
|
142
|
+
onRequest?: (args: ServeOnRequestArgs) => void;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface ServeOnRequestArgs {
|
|
146
|
+
remoteAddress: string;
|
|
147
|
+
method: string;
|
|
148
|
+
path: string;
|
|
149
|
+
status: number;
|
|
150
|
+
timeInMS: number; // The time to generate the response, not to send it
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface ServeResult {
|
|
154
|
+
port: number;
|
|
155
|
+
host: string;
|
|
156
|
+
wait: Promise<void>;
|
|
157
|
+
stop: () => void;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface TransformOptions extends CommonOptions {
|
|
161
|
+
tsconfigRaw?: string | {
|
|
162
|
+
compilerOptions?: {
|
|
163
|
+
jsxFactory?: string,
|
|
164
|
+
jsxFragmentFactory?: string,
|
|
165
|
+
useDefineForClassFields?: boolean,
|
|
166
|
+
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error',
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
sourcefile?: string;
|
|
171
|
+
loader?: Loader;
|
|
172
|
+
banner?: string;
|
|
173
|
+
footer?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface TransformResult {
|
|
177
|
+
code: string;
|
|
178
|
+
map: string;
|
|
179
|
+
warnings: Message[];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface TransformFailure extends Error {
|
|
183
|
+
errors: Message[];
|
|
184
|
+
warnings: Message[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface Plugin {
|
|
188
|
+
name: string;
|
|
189
|
+
setup: (build: PluginBuild) => (void | Promise<void>);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface PluginBuild {
|
|
193
|
+
initialOptions: BuildOptions;
|
|
194
|
+
onStart(callback: () =>
|
|
195
|
+
(OnStartResult | null | void | Promise<OnStartResult | null | void>)): void;
|
|
196
|
+
onEnd(callback: (result: BuildResult) =>
|
|
197
|
+
(void | Promise<void>)): void;
|
|
198
|
+
onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) =>
|
|
199
|
+
(OnResolveResult | null | undefined | Promise<OnResolveResult | null | undefined>)): void;
|
|
200
|
+
onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) =>
|
|
201
|
+
(OnLoadResult | null | undefined | Promise<OnLoadResult | null | undefined>)): void;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface OnStartResult {
|
|
205
|
+
errors?: PartialMessage[];
|
|
206
|
+
warnings?: PartialMessage[];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface OnResolveOptions {
|
|
210
|
+
filter: RegExp;
|
|
211
|
+
namespace?: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface OnResolveArgs {
|
|
215
|
+
path: string;
|
|
216
|
+
importer: string;
|
|
217
|
+
namespace: string;
|
|
218
|
+
resolveDir: string;
|
|
219
|
+
kind: ImportKind;
|
|
220
|
+
pluginData: any;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export type ImportKind =
|
|
224
|
+
| 'entry-point'
|
|
225
|
+
|
|
226
|
+
// JS
|
|
227
|
+
| 'import-statement'
|
|
228
|
+
| 'require-call'
|
|
229
|
+
| 'dynamic-import'
|
|
230
|
+
| 'require-resolve'
|
|
231
|
+
|
|
232
|
+
// CSS
|
|
233
|
+
| 'import-rule'
|
|
234
|
+
| 'url-token'
|
|
235
|
+
|
|
236
|
+
export interface OnResolveResult {
|
|
237
|
+
pluginName?: string;
|
|
238
|
+
|
|
239
|
+
errors?: PartialMessage[];
|
|
240
|
+
warnings?: PartialMessage[];
|
|
241
|
+
|
|
242
|
+
path?: string;
|
|
243
|
+
external?: boolean;
|
|
244
|
+
sideEffects?: boolean;
|
|
245
|
+
namespace?: string;
|
|
246
|
+
pluginData?: any;
|
|
247
|
+
|
|
248
|
+
watchFiles?: string[];
|
|
249
|
+
watchDirs?: string[];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface OnLoadOptions {
|
|
253
|
+
filter: RegExp;
|
|
254
|
+
namespace?: string;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface OnLoadArgs {
|
|
258
|
+
path: string;
|
|
259
|
+
namespace: string;
|
|
260
|
+
pluginData: any;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface OnLoadResult {
|
|
264
|
+
pluginName?: string;
|
|
265
|
+
|
|
266
|
+
errors?: PartialMessage[];
|
|
267
|
+
warnings?: PartialMessage[];
|
|
268
|
+
|
|
269
|
+
contents?: string | Uint8Array;
|
|
270
|
+
resolveDir?: string;
|
|
271
|
+
loader?: Loader;
|
|
272
|
+
pluginData?: any;
|
|
273
|
+
|
|
274
|
+
watchFiles?: string[];
|
|
275
|
+
watchDirs?: string[];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface PartialMessage {
|
|
279
|
+
pluginName?: string;
|
|
280
|
+
text?: string;
|
|
281
|
+
location?: Partial<Location> | null;
|
|
282
|
+
notes?: PartialNote[];
|
|
283
|
+
detail?: any;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface PartialNote {
|
|
287
|
+
text?: string;
|
|
288
|
+
location?: Partial<Location> | null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export interface Metafile {
|
|
292
|
+
inputs: {
|
|
293
|
+
[path: string]: {
|
|
294
|
+
bytes: number
|
|
295
|
+
imports: {
|
|
296
|
+
path: string
|
|
297
|
+
kind: ImportKind
|
|
298
|
+
}[]
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
outputs: {
|
|
302
|
+
[path: string]: {
|
|
303
|
+
bytes: number
|
|
304
|
+
inputs: {
|
|
305
|
+
[path: string]: {
|
|
306
|
+
bytesInOutput: number
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
imports: {
|
|
310
|
+
path: string
|
|
311
|
+
kind: ImportKind
|
|
312
|
+
}[]
|
|
313
|
+
exports: string[]
|
|
314
|
+
entryPoint?: string
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface FormatMessagesOptions {
|
|
320
|
+
kind: 'error' | 'warning';
|
|
321
|
+
color?: boolean;
|
|
322
|
+
terminalWidth?: number;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// This function invokes the "esbuild" command-line tool for you. It returns a
|
|
326
|
+
// promise that either resolves with a "BuildResult" object or rejects with a
|
|
327
|
+
// "BuildFailure" object.
|
|
328
|
+
//
|
|
329
|
+
// Works in node: yes
|
|
330
|
+
// Works in browser: yes
|
|
331
|
+
export declare function build(options: BuildOptions & { write: false }): Promise<BuildResult & { outputFiles: OutputFile[] }>;
|
|
332
|
+
export declare function build(options: BuildOptions & { incremental: true }): Promise<BuildIncremental>;
|
|
333
|
+
export declare function build(options: BuildOptions): Promise<BuildResult>;
|
|
334
|
+
|
|
335
|
+
// This function is similar to "build" but it serves the resulting files over
|
|
336
|
+
// HTTP on a localhost address with the specified port.
|
|
337
|
+
//
|
|
338
|
+
// Works in node: yes
|
|
339
|
+
// Works in browser: no
|
|
340
|
+
export declare function serve(serveOptions: ServeOptions, buildOptions: BuildOptions): Promise<ServeResult>;
|
|
341
|
+
|
|
342
|
+
// This function transforms a single JavaScript file. It can be used to minify
|
|
343
|
+
// JavaScript, convert TypeScript/JSX to JavaScript, or convert newer JavaScript
|
|
344
|
+
// to older JavaScript. It returns a promise that is either resolved with a
|
|
345
|
+
// "TransformResult" object or rejected with a "TransformFailure" object.
|
|
346
|
+
//
|
|
347
|
+
// Works in node: yes
|
|
348
|
+
// Works in browser: yes
|
|
349
|
+
export declare function transform(input: string, options?: TransformOptions): Promise<TransformResult>;
|
|
350
|
+
|
|
351
|
+
// Converts log messages to formatted message strings suitable for printing in
|
|
352
|
+
// the terminal. This allows you to reuse the built-in behavior of esbuild's
|
|
353
|
+
// log message formatter. This is a batch-oriented API for efficiency.
|
|
354
|
+
//
|
|
355
|
+
// Works in node: yes
|
|
356
|
+
// Works in browser: yes
|
|
357
|
+
export declare function formatMessages(messages: PartialMessage[], options: FormatMessagesOptions): Promise<string[]>;
|
|
358
|
+
|
|
359
|
+
// A synchronous version of "build".
|
|
360
|
+
//
|
|
361
|
+
// Works in node: yes
|
|
362
|
+
// Works in browser: no
|
|
363
|
+
export declare function buildSync(options: BuildOptions & { write: false }): BuildResult & { outputFiles: OutputFile[] };
|
|
364
|
+
export declare function buildSync(options: BuildOptions): BuildResult;
|
|
365
|
+
|
|
366
|
+
// A synchronous version of "transform".
|
|
367
|
+
//
|
|
368
|
+
// Works in node: yes
|
|
369
|
+
// Works in browser: no
|
|
370
|
+
export declare function transformSync(input: string, options?: TransformOptions): TransformResult;
|
|
371
|
+
|
|
372
|
+
// A synchronous version of "formatMessages".
|
|
373
|
+
//
|
|
374
|
+
// Works in node: yes
|
|
375
|
+
// Works in browser: no
|
|
376
|
+
export declare function formatMessagesSync(messages: PartialMessage[], options: FormatMessagesOptions): string[];
|
|
377
|
+
|
|
378
|
+
// This configures the browser-based version of esbuild. It is necessary to
|
|
379
|
+
// call this first and wait for the returned promise to be resolved before
|
|
380
|
+
// making other API calls when using esbuild in the browser.
|
|
381
|
+
//
|
|
382
|
+
// Works in node: yes
|
|
383
|
+
// Works in browser: yes ("options" is required)
|
|
384
|
+
export declare function initialize(options: InitializeOptions): Promise<void>;
|
|
385
|
+
|
|
386
|
+
export interface InitializeOptions {
|
|
387
|
+
// The URL of the "esbuild.wasm" file. This must be provided when running
|
|
388
|
+
// esbuild in the browser.
|
|
389
|
+
wasmURL?: string
|
|
390
|
+
|
|
391
|
+
// By default esbuild runs the WebAssembly-based browser API in a web worker
|
|
392
|
+
// to avoid blocking the UI thread. This can be disabled by setting "worker"
|
|
393
|
+
// to false.
|
|
394
|
+
worker?: boolean
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export let version: string;
|