1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getDestinationPath = getDestinationPath;
|
7 | exports.computeNodeModuleFileSets = exports.computeFileSets = exports.transformFiles = exports.copyAppFiles = exports.ELECTRON_COMPILE_SHIM_FILENAME = void 0;
|
8 |
|
9 | function _bluebirdLst() {
|
10 | const data = _interopRequireWildcard(require("bluebird-lst"));
|
11 |
|
12 | _bluebirdLst = function () {
|
13 | return data;
|
14 | };
|
15 |
|
16 | return data;
|
17 | }
|
18 |
|
19 | function _builderUtil() {
|
20 | const data = require("builder-util");
|
21 |
|
22 | _builderUtil = function () {
|
23 | return data;
|
24 | };
|
25 |
|
26 | return data;
|
27 | }
|
28 |
|
29 | function _fs() {
|
30 | const data = require("builder-util/out/fs");
|
31 |
|
32 | _fs = function () {
|
33 | return data;
|
34 | };
|
35 |
|
36 | return data;
|
37 | }
|
38 |
|
39 | function _fsExtraP() {
|
40 | const data = require("fs-extra-p");
|
41 |
|
42 | _fsExtraP = function () {
|
43 | return data;
|
44 | };
|
45 |
|
46 | return data;
|
47 | }
|
48 |
|
49 | var path = _interopRequireWildcard(require("path"));
|
50 |
|
51 | function _unpackDetector() {
|
52 | const data = require("../asar/unpackDetector");
|
53 |
|
54 | _unpackDetector = function () {
|
55 | return data;
|
56 | };
|
57 |
|
58 | return data;
|
59 | }
|
60 |
|
61 | function _core() {
|
62 | const data = require("../core");
|
63 |
|
64 | _core = function () {
|
65 | return data;
|
66 | };
|
67 |
|
68 | return data;
|
69 | }
|
70 |
|
71 | function _fileMatcher() {
|
72 | const data = require("../fileMatcher");
|
73 |
|
74 | _fileMatcher = function () {
|
75 | return data;
|
76 | };
|
77 |
|
78 | return data;
|
79 | }
|
80 |
|
81 | function _fileTransformer() {
|
82 | const data = require("../fileTransformer");
|
83 |
|
84 | _fileTransformer = function () {
|
85 | return data;
|
86 | };
|
87 |
|
88 | return data;
|
89 | }
|
90 |
|
91 | function _AppFileWalker() {
|
92 | const data = require("./AppFileWalker");
|
93 |
|
94 | _AppFileWalker = function () {
|
95 | return data;
|
96 | };
|
97 |
|
98 | return data;
|
99 | }
|
100 |
|
101 | function _NodeModuleCopyHelper() {
|
102 | const data = require("./NodeModuleCopyHelper");
|
103 |
|
104 | _NodeModuleCopyHelper = function () {
|
105 | return data;
|
106 | };
|
107 |
|
108 | return data;
|
109 | }
|
110 |
|
111 | let compileUsingElectronCompile = (() => {
|
112 | var _ref6 = (0, _bluebirdLst().coroutine)(function* (mainFileSet, packager) {
|
113 | _builderUtil().log.info("compiling using electron-compile");
|
114 |
|
115 | const electronCompileCache = yield packager.tempDirManager.getTempDir({
|
116 | prefix: "electron-compile-cache"
|
117 | });
|
118 | const cacheDir = path.join(electronCompileCache, ".cache");
|
119 |
|
120 | yield (0, _fsExtraP().ensureDir)(cacheDir);
|
121 | const compilerHost = yield (0, _fileTransformer().createElectronCompilerHost)(mainFileSet.src, cacheDir);
|
122 | const nextSlashIndex = mainFileSet.src.length + 1;
|
123 |
|
124 | yield _bluebirdLst().default.map(mainFileSet.files, file => {
|
125 | if (file.includes(_fileTransformer().NODE_MODULES_PATTERN) || file.includes(BOWER_COMPONENTS_PATTERN) || !file.includes(path.sep, nextSlashIndex)
|
126 | || !mainFileSet.metadata.get(file).isFile()) {
|
127 | return null;
|
128 | }
|
129 |
|
130 | return compilerHost.compile(file).then(() => null);
|
131 | }, _fs().CONCURRENCY);
|
132 | yield compilerHost.saveConfiguration();
|
133 | const metadata = new Map();
|
134 | const cacheFiles = yield (0, _fs().walk)(cacheDir, file => !file.startsWith("."), {
|
135 | consume: (file, fileStat) => {
|
136 | if (fileStat.isFile()) {
|
137 | metadata.set(file, fileStat);
|
138 | }
|
139 |
|
140 | return null;
|
141 | }
|
142 | });
|
143 |
|
144 | const shimPath = `${mainFileSet.src}${path.sep}${ELECTRON_COMPILE_SHIM_FILENAME}`;
|
145 | mainFileSet.files.push(shimPath);
|
146 | mainFileSet.metadata.set(shimPath, {
|
147 | isFile: () => true,
|
148 | isDirectory: () => false,
|
149 | isSymbolicLink: () => false
|
150 | });
|
151 |
|
152 | if (mainFileSet.transformedFiles == null) {
|
153 | mainFileSet.transformedFiles = new Map();
|
154 | }
|
155 |
|
156 | mainFileSet.transformedFiles.set(mainFileSet.files.length - 1, `
|
157 | 'use strict';
|
158 | require('electron-compile').init(__dirname, require('path').resolve(__dirname, '${packager.metadata.main || "index"}'), true);
|
159 | `);
|
160 | return {
|
161 | src: electronCompileCache,
|
162 | files: cacheFiles,
|
163 | metadata,
|
164 | destination: mainFileSet.destination
|
165 | };
|
166 | });
|
167 |
|
168 | return function compileUsingElectronCompile(_x13, _x14) {
|
169 | return _ref6.apply(this, arguments);
|
170 | };
|
171 | })(); function _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; } }
|
172 |
|
173 | const BOWER_COMPONENTS_PATTERN = `${path.sep}bower_components${path.sep}`;
|
174 |
|
175 |
|
176 | const ELECTRON_COMPILE_SHIM_FILENAME = "__shim.js";
|
177 | exports.ELECTRON_COMPILE_SHIM_FILENAME = ELECTRON_COMPILE_SHIM_FILENAME;
|
178 |
|
179 | function getDestinationPath(file, fileSet) {
|
180 | if (file === fileSet.src) {
|
181 | return fileSet.destination;
|
182 | } else {
|
183 | const src = fileSet.src;
|
184 | const dest = fileSet.destination;
|
185 |
|
186 | if (file.length > src.length && file.startsWith(src) && file[src.length] === path.sep) {
|
187 | return dest + file.substring(src.length);
|
188 | } else {
|
189 |
|
190 |
|
191 |
|
192 | const index = file.indexOf(_fileTransformer().NODE_MODULES_PATTERN);
|
193 |
|
194 | if (index < 0) {
|
195 | throw new Error(`File "${file}" not under the source directory "${fileSet.src}"`);
|
196 | }
|
197 |
|
198 | return dest + file.substring(index + 1
|
199 |
|
200 | );
|
201 | }
|
202 | }
|
203 | }
|
204 |
|
205 | let copyAppFiles = (() => {
|
206 | var _ref = (0, _bluebirdLst().coroutine)(function* (fileSet, packager, transformer) {
|
207 | const metadata = fileSet.metadata;
|
208 |
|
209 | const taskManager = new (_builderUtil().AsyncTaskManager)(packager.cancellationToken);
|
210 | const createdParentDirs = new Set();
|
211 | const fileCopier = new (_fs().FileCopier)(file => {
|
212 |
|
213 | return !((0, _unpackDetector().isLibOrExe)(file) || file.endsWith(".node"));
|
214 | }, transformer);
|
215 | const links = [];
|
216 |
|
217 | for (let i = 0, n = fileSet.files.length; i < n; i++) {
|
218 | const sourceFile = fileSet.files[i];
|
219 | const stat = metadata.get(sourceFile);
|
220 |
|
221 | if (stat == null) {
|
222 |
|
223 | continue;
|
224 | }
|
225 |
|
226 | const destinationFile = getDestinationPath(sourceFile, fileSet);
|
227 |
|
228 | if (stat.isSymbolicLink()) {
|
229 | links.push({
|
230 | file: destinationFile,
|
231 | link: yield (0, _fsExtraP().readlink)(sourceFile)
|
232 | });
|
233 | continue;
|
234 | }
|
235 |
|
236 | const fileParent = path.dirname(destinationFile);
|
237 |
|
238 | if (!createdParentDirs.has(fileParent)) {
|
239 | createdParentDirs.add(fileParent);
|
240 | yield (0, _fsExtraP().ensureDir)(fileParent);
|
241 | }
|
242 |
|
243 | taskManager.addTask(fileCopier.copy(sourceFile, destinationFile, stat));
|
244 |
|
245 | if (taskManager.tasks.length > _fs().MAX_FILE_REQUESTS) {
|
246 | yield taskManager.awaitTasks();
|
247 | }
|
248 | }
|
249 |
|
250 | if (taskManager.tasks.length > 0) {
|
251 | yield taskManager.awaitTasks();
|
252 | }
|
253 |
|
254 | if (links.length > 0) {
|
255 | yield _bluebirdLst().default.map(links, it => (0, _fsExtraP().symlink)(it.link, it.file), _fs().CONCURRENCY);
|
256 | }
|
257 | });
|
258 |
|
259 | return function copyAppFiles(_x, _x2, _x3) {
|
260 | return _ref.apply(this, arguments);
|
261 | };
|
262 | })();
|
263 |
|
264 |
|
265 | exports.copyAppFiles = copyAppFiles;
|
266 |
|
267 | let transformFiles = (() => {
|
268 | var _ref2 = (0, _bluebirdLst().coroutine)(function* (transformer, fileSet) {
|
269 | if (transformer == null) {
|
270 | return;
|
271 | }
|
272 |
|
273 | let transformedFiles = fileSet.transformedFiles;
|
274 |
|
275 | if (fileSet.transformedFiles == null) {
|
276 | transformedFiles = new Map();
|
277 | fileSet.transformedFiles = transformedFiles;
|
278 | }
|
279 |
|
280 | const metadata = fileSet.metadata;
|
281 | yield _bluebirdLst().default.filter(fileSet.files, (it, index) => {
|
282 | const fileStat = metadata.get(it);
|
283 |
|
284 | if (fileStat == null || !fileStat.isFile()) {
|
285 | return false;
|
286 | }
|
287 |
|
288 | const transformedValue = transformer(it);
|
289 |
|
290 | if (transformedValue == null) {
|
291 | return false;
|
292 | }
|
293 |
|
294 | if (typeof transformedValue === "object" && "then" in transformedValue) {
|
295 | return transformedValue.then(it => {
|
296 | if (it != null) {
|
297 | transformedFiles.set(index, it);
|
298 | }
|
299 |
|
300 | return false;
|
301 | });
|
302 | }
|
303 |
|
304 | transformedFiles.set(index, transformedValue);
|
305 | return false;
|
306 | }, _fs().CONCURRENCY);
|
307 | });
|
308 |
|
309 | return function transformFiles(_x4, _x5) {
|
310 | return _ref2.apply(this, arguments);
|
311 | };
|
312 | })();
|
313 |
|
314 | exports.transformFiles = transformFiles;
|
315 |
|
316 | let computeFileSets = (() => {
|
317 | var _ref3 = (0, _bluebirdLst().coroutine)(function* (matchers, transformer, platformPackager, isElectronCompile) {
|
318 | const fileSets = [];
|
319 | const packager = platformPackager.info;
|
320 |
|
321 | for (const matcher of matchers) {
|
322 | const fileWalker = new (_AppFileWalker().AppFileWalker)(matcher, packager);
|
323 | const fromStat = yield (0, _fs().statOrNull)(matcher.from);
|
324 |
|
325 | if (fromStat == null) {
|
326 | _builderUtil().log.debug({
|
327 | directory: matcher.from,
|
328 | reason: "doesn't exist"
|
329 | }, `skipped copying`);
|
330 |
|
331 | continue;
|
332 | }
|
333 |
|
334 | const files = yield (0, _fs().walk)(matcher.from, fileWalker.filter, fileWalker);
|
335 | const metadata = fileWalker.metadata;
|
336 | fileSets.push(validateFileSet({
|
337 | src: matcher.from,
|
338 | files,
|
339 | metadata,
|
340 | destination: matcher.to
|
341 | }));
|
342 | }
|
343 |
|
344 | if (isElectronCompile) {
|
345 |
|
346 | fileSets.unshift((yield compileUsingElectronCompile(fileSets[0], packager)));
|
347 | }
|
348 |
|
349 | return fileSets;
|
350 | });
|
351 |
|
352 | return function computeFileSets(_x6, _x7, _x8, _x9) {
|
353 | return _ref3.apply(this, arguments);
|
354 | };
|
355 | })();
|
356 |
|
357 | exports.computeFileSets = computeFileSets;
|
358 |
|
359 | function getNodeModuleExcludedExts(platformPackager) {
|
360 |
|
361 | const result = [".o", ".obj"].concat(_fileMatcher().excludedExts.split(",").map(it => `.${it}`));
|
362 |
|
363 | if (platformPackager.config.includePdb !== true) {
|
364 | result.push(".pdb");
|
365 | }
|
366 |
|
367 | if (platformPackager.platform !== _core().Platform.WINDOWS) {
|
368 |
|
369 | result.push(".dll");
|
370 | result.push(".exe");
|
371 | }
|
372 |
|
373 | return result;
|
374 | }
|
375 |
|
376 | function validateFileSet(fileSet) {
|
377 | if (fileSet.src == null || fileSet.src.length === 0) {
|
378 | throw new Error("fileset src is empty");
|
379 | }
|
380 |
|
381 | return fileSet;
|
382 | }
|
383 |
|
384 |
|
385 |
|
386 | let computeNodeModuleFileSets = (() => {
|
387 | var _ref4 = (0, _bluebirdLst().coroutine)(function* (platformPackager, mainMatcher) {
|
388 |
|
389 | const rawJson = yield (0, _builderUtil().executeAppBuilder)(["node-dep-tree", "--dir", platformPackager.info.appDir]);
|
390 | let data;
|
391 |
|
392 | try {
|
393 | data = JSON.parse(rawJson);
|
394 | } catch (e) {
|
395 | throw new Error(`cannot parse: ${rawJson}\n error: ${e.stack}`);
|
396 | }
|
397 |
|
398 | const deps = data;
|
399 | const nodeModuleExcludedExts = getNodeModuleExcludedExts(platformPackager);
|
400 |
|
401 | return yield _bluebirdLst().default.mapSeries(deps, (() => {
|
402 | var _ref5 = (0, _bluebirdLst().coroutine)(function* (info) {
|
403 | const source = info.dir;
|
404 | let destination;
|
405 |
|
406 | if (source.length > mainMatcher.from.length && source.startsWith(mainMatcher.from) && source[mainMatcher.from.length] === path.sep) {
|
407 | destination = getDestinationPath(source, {
|
408 | src: mainMatcher.from,
|
409 | destination: mainMatcher.to,
|
410 | files: [],
|
411 | metadata: null
|
412 | });
|
413 | } else {
|
414 | destination = mainMatcher.to + path.sep + "node_modules";
|
415 | }
|
416 |
|
417 |
|
418 |
|
419 | const matcher = new (_fileMatcher().FileMatcher)(path.dirname(source), destination, mainMatcher.macroExpander, mainMatcher.patterns);
|
420 | const copier = new (_NodeModuleCopyHelper().NodeModuleCopyHelper)(matcher, platformPackager.info);
|
421 | const names = info.deps;
|
422 | const files = yield copier.collectNodeModules(source, names, nodeModuleExcludedExts);
|
423 | return validateFileSet({
|
424 | src: source,
|
425 | destination,
|
426 | files,
|
427 | metadata: copier.metadata
|
428 | });
|
429 | });
|
430 |
|
431 | return function (_x12) {
|
432 | return _ref5.apply(this, arguments);
|
433 | };
|
434 | })());
|
435 | });
|
436 |
|
437 | return function computeNodeModuleFileSets(_x10, _x11) {
|
438 | return _ref4.apply(this, arguments);
|
439 | };
|
440 | })();
|
441 |
|
442 | exports.computeNodeModuleFileSets = computeNodeModuleFileSets;
|
443 |
|
\ | No newline at end of file |