source: trip-planner-front/node_modules/esbuild/install.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.0 KB
Line 
1var __create = Object.create;
2var __defProp = Object.defineProperty;
3var __defProps = Object.defineProperties;
4var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6var __getOwnPropNames = Object.getOwnPropertyNames;
7var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8var __getProtoOf = Object.getPrototypeOf;
9var __hasOwnProp = Object.prototype.hasOwnProperty;
10var __propIsEnum = Object.prototype.propertyIsEnumerable;
11var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12var __spreadValues = (a, b) => {
13 for (var prop in b || (b = {}))
14 if (__hasOwnProp.call(b, prop))
15 __defNormalProp(a, prop, b[prop]);
16 if (__getOwnPropSymbols)
17 for (var prop of __getOwnPropSymbols(b)) {
18 if (__propIsEnum.call(b, prop))
19 __defNormalProp(a, prop, b[prop]);
20 }
21 return a;
22};
23var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25var __reExport = (target, module2, desc) => {
26 if (module2 && typeof module2 === "object" || typeof module2 === "function") {
27 for (let key of __getOwnPropNames(module2))
28 if (!__hasOwnProp.call(target, key) && key !== "default")
29 __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
30 }
31 return target;
32};
33var __toModule = (module2) => {
34 return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
35};
36
37// lib/npm/node-platform.ts
38var fs = require("fs");
39var os = require("os");
40var path = require("path");
41var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
42var knownWindowsPackages = {
43 "win32 arm64 LE": "esbuild-windows-arm64",
44 "win32 ia32 LE": "esbuild-windows-32",
45 "win32 x64 LE": "esbuild-windows-64"
46};
47var knownUnixlikePackages = {
48 "android arm64 LE": "esbuild-android-arm64",
49 "darwin arm64 LE": "esbuild-darwin-arm64",
50 "darwin x64 LE": "esbuild-darwin-64",
51 "freebsd arm64 LE": "esbuild-freebsd-arm64",
52 "freebsd x64 LE": "esbuild-freebsd-64",
53 "openbsd x64 LE": "esbuild-openbsd-64",
54 "linux arm LE": "esbuild-linux-arm",
55 "linux arm64 LE": "esbuild-linux-arm64",
56 "linux ia32 LE": "esbuild-linux-32",
57 "linux mips64el LE": "esbuild-linux-mips64le",
58 "linux ppc64 LE": "esbuild-linux-ppc64le",
59 "linux x64 LE": "esbuild-linux-64",
60 "sunos x64 LE": "esbuild-sunos-64"
61};
62function pkgAndSubpathForCurrentPlatform() {
63 let pkg;
64 let subpath;
65 let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
66 if (platformKey in knownWindowsPackages) {
67 pkg = knownWindowsPackages[platformKey];
68 subpath = "esbuild.exe";
69 } else if (platformKey in knownUnixlikePackages) {
70 pkg = knownUnixlikePackages[platformKey];
71 subpath = "bin/esbuild";
72 } else {
73 throw new Error(`Unsupported platform: ${platformKey}`);
74 }
75 return { pkg, subpath };
76}
77function downloadedBinPath(pkg, subpath) {
78 const esbuildLibDir = path.dirname(require.resolve("esbuild"));
79 return path.join(esbuildLibDir, `downloaded-${pkg}-${path.basename(subpath)}`);
80}
81
82// lib/npm/node-install.ts
83var fs2 = require("fs");
84var os2 = require("os");
85var path2 = require("path");
86var zlib = require("zlib");
87var https = require("https");
88var child_process = require("child_process");
89var toPath = path2.join(__dirname, "bin", "esbuild");
90var isToPathJS = true;
91function validateBinaryVersion(...command) {
92 command.push("--version");
93 const stdout = child_process.execFileSync(command.shift(), command).toString().trim();
94 if (stdout !== "0.13.4") {
95 throw new Error(`Expected ${JSON.stringify("0.13.4")} but got ${JSON.stringify(stdout)}`);
96 }
97}
98function isYarn() {
99 const { npm_config_user_agent } = process.env;
100 if (npm_config_user_agent) {
101 return /\byarn\//.test(npm_config_user_agent);
102 }
103 return false;
104}
105function fetch(url) {
106 return new Promise((resolve, reject) => {
107 https.get(url, (res) => {
108 if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
109 return fetch(res.headers.location).then(resolve, reject);
110 if (res.statusCode !== 200)
111 return reject(new Error(`Server responded with ${res.statusCode}`));
112 let chunks = [];
113 res.on("data", (chunk) => chunks.push(chunk));
114 res.on("end", () => resolve(Buffer.concat(chunks)));
115 }).on("error", reject);
116 });
117}
118function extractFileFromTarGzip(buffer, subpath) {
119 try {
120 buffer = zlib.unzipSync(buffer);
121 } catch (err) {
122 throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
123 }
124 let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
125 let offset = 0;
126 subpath = `package/${subpath}`;
127 while (offset < buffer.length) {
128 let name = str(offset, 100);
129 let size = parseInt(str(offset + 124, 12), 8);
130 offset += 512;
131 if (!isNaN(size)) {
132 if (name === subpath)
133 return buffer.subarray(offset, offset + size);
134 offset += size + 511 & ~511;
135 }
136 }
137 throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
138}
139function installUsingNPM(pkg, subpath, binPath) {
140 const env = __spreadProps(__spreadValues({}, process.env), { npm_config_global: void 0 });
141 const esbuildLibDir = path2.dirname(require.resolve("esbuild"));
142 const installDir = path2.join(esbuildLibDir, "npm-install");
143 fs2.mkdirSync(installDir);
144 try {
145 fs2.writeFileSync(path2.join(installDir, "package.json"), "{}");
146 child_process.execSync(`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${"0.13.4"}`, { cwd: installDir, stdio: "pipe", env });
147 const installedBinPath = path2.join(installDir, "node_modules", pkg, subpath);
148 fs2.renameSync(installedBinPath, binPath);
149 } finally {
150 try {
151 removeRecursive(installDir);
152 } catch (e) {
153 }
154 }
155}
156function removeRecursive(dir) {
157 for (const entry of fs2.readdirSync(dir)) {
158 const entryPath = path2.join(dir, entry);
159 let stats;
160 try {
161 stats = fs2.lstatSync(entryPath);
162 } catch (e) {
163 continue;
164 }
165 if (stats.isDirectory())
166 removeRecursive(entryPath);
167 else
168 fs2.unlinkSync(entryPath);
169 }
170 fs2.rmdirSync(dir);
171}
172function applyManualBinaryPathOverride(overridePath) {
173 const pathString = JSON.stringify(overridePath);
174 fs2.writeFileSync(toPath, `#!/usr/bin/env node
175require('child_process').execFileSync(${pathString}, process.argv.slice(2), { stdio: 'inherit' });
176`);
177 const libMain = path2.join(__dirname, "lib", "main.js");
178 const code = fs2.readFileSync(libMain, "utf8");
179 fs2.writeFileSync(libMain, `var ESBUILD_BINARY_PATH = ${pathString};
180${code}`);
181}
182function maybeOptimizePackage(binPath) {
183 if (os2.platform() !== "win32" && !isYarn()) {
184 const tempPath = path2.join(__dirname, "bin-esbuild");
185 try {
186 fs2.linkSync(binPath, tempPath);
187 fs2.renameSync(tempPath, toPath);
188 isToPathJS = false;
189 } catch (e) {
190 }
191 }
192}
193async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
194 const url = `https://registry.npmjs.org/${pkg}/-/${pkg}-${"0.13.4"}.tgz`;
195 console.error(`[esbuild] Trying to download ${JSON.stringify(url)}`);
196 try {
197 fs2.writeFileSync(binPath, extractFileFromTarGzip(await fetch(url), subpath));
198 fs2.chmodSync(binPath, 493);
199 } catch (e) {
200 console.error(`[esbuild] Failed to download ${JSON.stringify(url)}: ${e && e.message || e}`);
201 throw e;
202 }
203}
204async function checkAndPreparePackage() {
205 if (process.env.ESBUILD_BINARY_PATH) {
206 applyManualBinaryPathOverride(process.env.ESBUILD_BINARY_PATH);
207 return;
208 }
209 const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
210 let binPath;
211 try {
212 binPath = require.resolve(`${pkg}/${subpath}`);
213 } catch (e) {
214 console.error(`[esbuild] Failed to find package "${pkg}" on the file system
215
216This can happen if you use the "--no-optional" flag. The "optionalDependencies"
217package.json feature is used by esbuild to install the correct binary executable
218for your current platform. This install script will now attempt to work around
219this. If that fails, you need to remove the "--no-optional" flag to use esbuild.
220`);
221 binPath = downloadedBinPath(pkg, subpath);
222 try {
223 console.error(`[esbuild] Trying to install package "${pkg}" using npm`);
224 installUsingNPM(pkg, subpath, binPath);
225 } catch (e2) {
226 console.error(`[esbuild] Failed to install package "${pkg}" using npm: ${e2 && e2.message || e2}`);
227 try {
228 await downloadDirectlyFromNPM(pkg, subpath, binPath);
229 } catch (e3) {
230 throw new Error(`Failed to install package "${pkg}"`);
231 }
232 }
233 }
234 maybeOptimizePackage(binPath);
235}
236checkAndPreparePackage().then(() => {
237 if (isToPathJS) {
238 validateBinaryVersion("node", toPath);
239 } else {
240 validateBinaryVersion(toPath);
241 }
242});
Note: See TracBrowser for help on using the repository browser.