UNPKG

6.72 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getGypEnv = getGypEnv;
7exports.rebuild = exports.installOrRebuild = void 0;
8
9function _bluebirdLst() {
10 const data = _interopRequireWildcard(require("bluebird-lst"));
11
12 _bluebirdLst = function () {
13 return data;
14 };
15
16 return data;
17}
18
19function _builderUtil() {
20 const data = require("builder-util");
21
22 _builderUtil = function () {
23 return data;
24 };
25
26 return data;
27}
28
29function _fs() {
30 const data = require("builder-util/out/fs");
31
32 _fs = function () {
33 return data;
34 };
35
36 return data;
37}
38
39function _os() {
40 const data = require("os");
41
42 _os = function () {
43 return data;
44 };
45
46 return data;
47}
48
49var path = _interopRequireWildcard(require("path"));
50
51function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
52
53let installOrRebuild = (() => {
54 var _ref = (0, _bluebirdLst().coroutine)(function* (config, appDir, options, forceInstall = false) {
55 const effectiveOptions = Object.assign({
56 buildFromSource: config.buildDependenciesFromSource === true,
57 additionalArgs: (0, _builderUtil().asArray)(config.npmArgs)
58 }, options);
59
60 if (forceInstall || !(yield (0, _fs().exists)(path.join(appDir, "node_modules")))) {
61 yield installDependencies(appDir, effectiveOptions);
62 } else {
63 yield rebuild(appDir, effectiveOptions);
64 }
65 });
66
67 return function installOrRebuild(_x, _x2, _x3) {
68 return _ref.apply(this, arguments);
69 };
70})();
71
72exports.installOrRebuild = installOrRebuild;
73
74function getElectronGypCacheDir() {
75 return path.join((0, _os().homedir)(), ".electron-gyp");
76}
77
78function getGypEnv(frameworkInfo, platform, arch, buildFromSource) {
79 const npmConfigArch = arch === "armv7l" ? "arm" : arch;
80 const common = Object.assign({}, process.env, {
81 npm_config_arch: npmConfigArch,
82 npm_config_target_arch: npmConfigArch,
83 npm_config_platform: platform,
84 npm_config_build_from_source: buildFromSource,
85 // required for node-pre-gyp
86 npm_config_target_platform: platform,
87 npm_config_update_binary: true,
88 npm_config_fallback_to_build: true
89 });
90
91 if (platform === "win32") {
92 common.npm_config_target_libc = "unknown";
93 }
94
95 if (!frameworkInfo.useCustomDist) {
96 return common;
97 } // https://github.com/nodejs/node-gyp/issues/21
98
99
100 return Object.assign({}, common, {
101 npm_config_disturl: "https://atom.io/download/electron",
102 npm_config_target: frameworkInfo.version,
103 npm_config_runtime: "electron",
104 npm_config_devdir: getElectronGypCacheDir()
105 });
106}
107
108function installDependencies(appDir, options) {
109 const platform = options.platform || process.platform;
110 const arch = options.arch || process.arch;
111 const additionalArgs = options.additionalArgs;
112
113 _builderUtil().log.info({
114 platform,
115 arch,
116 appDir
117 }, `installing production dependencies`);
118
119 let execPath = process.env.npm_execpath || process.env.NPM_CLI_JS;
120 const execArgs = ["install", "--production"];
121
122 if (!isYarnPath(execPath)) {
123 if (process.env.NPM_NO_BIN_LINKS === "true") {
124 execArgs.push("--no-bin-links");
125 }
126
127 execArgs.push("--cache-min", "999999999");
128 }
129
130 if (execPath == null) {
131 execPath = getPackageToolPath();
132 } else {
133 execArgs.unshift(execPath);
134 execPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node";
135 }
136
137 if (additionalArgs != null) {
138 execArgs.push(...additionalArgs);
139 }
140
141 return (0, _builderUtil().spawn)(execPath, execArgs, {
142 cwd: appDir,
143 env: getGypEnv(options.frameworkInfo, platform, arch, options.buildFromSource === true)
144 });
145}
146
147function getPackageToolPath() {
148 if (process.env.FORCE_YARN === "true") {
149 return process.platform === "win32" ? "yarn.cmd" : "yarn";
150 } else {
151 return process.platform === "win32" ? "npm.cmd" : "npm";
152 }
153}
154
155function isYarnPath(execPath) {
156 return process.env.FORCE_YARN === "true" || execPath != null && path.basename(execPath).startsWith("yarn");
157}
158/** @internal */
159
160
161let rebuild = (() => {
162 var _ref2 = (0, _bluebirdLst().coroutine)(function* (appDir, options) {
163 const nativeDeps = yield _bluebirdLst().default.filter((yield options.productionDeps.value), it => (0, _fs().exists)(path.join(it.path, "binding.gyp")), {
164 concurrency: 8
165 });
166
167 if (nativeDeps.length === 0) {
168 _builderUtil().log.info("no native production dependencies");
169
170 return;
171 }
172
173 const platform = options.platform || process.platform;
174 const arch = options.arch || process.arch;
175 const additionalArgs = options.additionalArgs;
176
177 _builderUtil().log.info({
178 platform,
179 arch
180 }, "rebuilding native production dependencies");
181
182 let execPath = process.env.npm_execpath || process.env.NPM_CLI_JS;
183 const isYarn = isYarnPath(execPath);
184 const execArgs = [];
185
186 if (execPath == null) {
187 execPath = getPackageToolPath();
188 } else {
189 execArgs.push(execPath);
190 execPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node";
191 }
192
193 const env = getGypEnv(options.frameworkInfo, platform, arch, options.buildFromSource === true);
194
195 if (isYarn) {
196 execArgs.push("run", "install");
197
198 if (additionalArgs != null) {
199 execArgs.push(...additionalArgs);
200 }
201
202 yield _bluebirdLst().default.map(nativeDeps, dep => {
203 _builderUtil().log.info({
204 name: dep.name
205 }, `rebuilding native dependency`);
206
207 return (0, _builderUtil().spawn)(execPath, execArgs, {
208 cwd: dep.path,
209 env
210 }).catch(error => {
211 if (dep.optional) {
212 _builderUtil().log.warn({
213 dep: dep.name
214 }, "cannot build optional native dep");
215 } else {
216 throw error;
217 }
218 });
219 }, {
220 concurrency: process.platform === "win32" ? 1 : 2
221 });
222 } else {
223 execArgs.push("rebuild");
224
225 if (additionalArgs != null) {
226 execArgs.push(...additionalArgs);
227 }
228
229 execArgs.push(...nativeDeps.map(it => `${it.name}@${it.version}`));
230 yield (0, _builderUtil().spawn)(execPath, execArgs, {
231 cwd: appDir,
232 env
233 });
234 }
235 });
236
237 return function rebuild(_x4, _x5) {
238 return _ref2.apply(this, arguments);
239 };
240})(); exports.rebuild = rebuild;
241//# sourceMappingURL=yarn.js.map
\No newline at end of file