source: trip-planner-front/node_modules/esbuild/install.js@ 6fe77af

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

primeNG components

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