1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createLazyProductionDeps = createLazyProductionDeps;
|
7 | exports.getProductionDependencies = 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 _promise() {
|
40 | const data = require("builder-util/out/promise");
|
41 |
|
42 | _promise = function () {
|
43 | return data;
|
44 | };
|
45 |
|
46 | return data;
|
47 | }
|
48 |
|
49 | function _fsExtraP() {
|
50 | const data = require("fs-extra-p");
|
51 |
|
52 | _fsExtraP = function () {
|
53 | return data;
|
54 | };
|
55 |
|
56 | return data;
|
57 | }
|
58 |
|
59 | function _lazyVal() {
|
60 | const data = require("lazy-val");
|
61 |
|
62 | _lazyVal = function () {
|
63 | return data;
|
64 | };
|
65 |
|
66 | return data;
|
67 | }
|
68 |
|
69 | var path = _interopRequireWildcard(require("path"));
|
70 |
|
71 | let readNodeModulesDir = (() => {
|
72 | var _ref2 = (0, _bluebirdLst().coroutine)(function* (dir) {
|
73 | let files;
|
74 |
|
75 | try {
|
76 | files = (yield (0, _fsExtraP().readdir)(dir)).filter(it => !it.startsWith(".") && !knownAlwaysIgnoredDevDeps.has(it));
|
77 | } catch (e) {
|
78 |
|
79 | return null;
|
80 | }
|
81 |
|
82 | files.sort();
|
83 | const scopes = files.filter(it => it.startsWith("@"));
|
84 |
|
85 | if (scopes.length === 0) {
|
86 | return files;
|
87 | }
|
88 |
|
89 | const result = files.filter(it => !it.startsWith("@"));
|
90 | const scopeFileList = yield _bluebirdLst().default.map(scopes, it => (0, _fsExtraP().readdir)(path.join(dir, it)));
|
91 |
|
92 | for (let i = 0; i < scopes.length; i++) {
|
93 | const list = scopeFileList[i];
|
94 | list.sort();
|
95 |
|
96 | for (const file of list) {
|
97 | if (!file.startsWith(".")) {
|
98 | result.push(`${scopes[i]}/${file}`);
|
99 | }
|
100 | }
|
101 | }
|
102 |
|
103 | return result;
|
104 | });
|
105 |
|
106 | return function readNodeModulesDir(_x2) {
|
107 | return _ref2.apply(this, arguments);
|
108 | };
|
109 | })(); 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; } }
|
110 |
|
111 |
|
112 | const knownAlwaysIgnoredDevDeps = new Set(["electron-builder-tslint-config", "electron-download", "libui-download", "electron-forge", "electron-packager", "electron-compilers", "prebuild-install", "nan", "electron-webpack", "electron-webpack-ts", "electron-webpack-vue", "@types"]);
|
113 |
|
114 | function createLazyProductionDeps(projectDir) {
|
115 | return new (_lazyVal().Lazy)(() => getProductionDependencies(projectDir));
|
116 | }
|
117 |
|
118 |
|
119 |
|
120 | let getProductionDependencies = (() => {
|
121 | var _ref = (0, _bluebirdLst().coroutine)(function* (folder) {
|
122 | const result = [];
|
123 | computeSortedPaths((yield new Collector().collect(folder)), result, false);
|
124 | return result;
|
125 | });
|
126 |
|
127 | return function getProductionDependencies(_x) {
|
128 | return _ref.apply(this, arguments);
|
129 | };
|
130 | })();
|
131 |
|
132 | exports.getProductionDependencies = getProductionDependencies;
|
133 | const ignoredProperties = new Set(["description", "author", "bugs", "engines", "repository", "build", "main", "license", "homepage", "scripts", "maintainers", "contributors", "keywords", "devDependencies", "files", "typings", "types", "xo", "resolutions"]);
|
134 |
|
135 | function readJson(file) {
|
136 | return (0, _fsExtraP().readFile)(file, "utf-8").then(it => JSON.parse(it, (key, value) => ignoredProperties.has(key) ? undefined : value));
|
137 | }
|
138 |
|
139 | function computeSortedPaths(parent, result, isExtraneous) {
|
140 | const dependencies = parent.dependencies;
|
141 |
|
142 | if (dependencies == null) {
|
143 | return;
|
144 | }
|
145 |
|
146 | for (const dep of dependencies.values()) {
|
147 | if (dep.extraneous === isExtraneous) {
|
148 | result.push(dep);
|
149 | computeSortedPaths(dep, result, isExtraneous);
|
150 | }
|
151 | }
|
152 | }
|
153 |
|
154 | class Collector {
|
155 | constructor() {
|
156 | this.pathToMetadata = new Map();
|
157 | this.unresolved = new Map();
|
158 | }
|
159 |
|
160 | collect(dir) {
|
161 | var _this = this;
|
162 |
|
163 | return (0, _bluebirdLst().coroutine)(function* () {
|
164 | const rootDependency = yield readJson(path.join(dir, "package.json"));
|
165 | yield _this.readInstalled(path.join(dir, "node_modules"), rootDependency, rootDependency.name);
|
166 |
|
167 | _this.unmarkExtraneous(rootDependency);
|
168 |
|
169 | if (_this.unresolved.size > 0) {
|
170 | _builderUtil().log.debug({
|
171 | unresolved: Array.from(_this.unresolved.keys()).join(", ")
|
172 | }, "unresolved dependencies after first round");
|
173 |
|
174 | yield _this.resolveUnresolvedHoisted(rootDependency, dir);
|
175 | }
|
176 |
|
177 | return rootDependency;
|
178 | })();
|
179 | }
|
180 |
|
181 | resolveUnresolvedHoisted(rootDependency, dir) {
|
182 | var _this2 = this;
|
183 |
|
184 | return (0, _bluebirdLst().coroutine)(function* () {
|
185 | let nameToMetadata = rootDependency.dependencies;
|
186 |
|
187 | if (nameToMetadata == null) {
|
188 | rootDependency.dependencies = new Map();
|
189 | nameToMetadata = rootDependency.dependencies;
|
190 | }
|
191 |
|
192 | let parentDir = dir;
|
193 |
|
194 | do {
|
195 | parentDir = path.dirname(parentDir);
|
196 |
|
197 | if (parentDir === "" || parentDir.endsWith("/") || parentDir.endsWith("\\")) {
|
198 |
|
199 | const list = Array.from(_this2.unresolved.keys()).filter(it => !_this2.unresolved.get(it));
|
200 |
|
201 | if (list.length === 1 && list[0] === "proton-native") {
|
202 |
|
203 | parentDir = process.cwd();
|
204 | } else {
|
205 | if (list.length !== 0) {
|
206 | const message = `Unresolved node modules: ${list.join(", ")}`;
|
207 |
|
208 | if ((0, _builderUtil().isEnvTrue)(process.env.ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES)) {
|
209 | _builderUtil().log.warn(message);
|
210 | } else {
|
211 | throw new Error(message);
|
212 | }
|
213 | }
|
214 |
|
215 | break;
|
216 | }
|
217 | }
|
218 |
|
219 | const parentNodeModulesDir = parentDir + path.sep + "node_modules";
|
220 | const dirStat = yield (0, _fs().statOrNull)(parentNodeModulesDir);
|
221 |
|
222 | if (dirStat == null || !dirStat.isDirectory()) {
|
223 | if (dirStat == null || !dirStat.isDirectory()) {
|
224 | continue;
|
225 | }
|
226 | }
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | while (true) {
|
232 | const unresolved = Array.from(_this2.unresolved.keys());
|
233 |
|
234 | _this2.unresolved.clear();
|
235 |
|
236 | const resolved = yield _bluebirdLst().default.map(unresolved, it => {
|
237 | return _this2.readChildPackage(it, parentNodeModulesDir, rootDependency).catch(e => {
|
238 | if (e.code === "ENOENT") {
|
239 | return null;
|
240 | } else {
|
241 | throw e;
|
242 | }
|
243 | });
|
244 | }, _fs().CONCURRENCY);
|
245 | let hasResolved = false;
|
246 |
|
247 | for (const dep of resolved) {
|
248 | if (dep != null) {
|
249 | hasResolved = true;
|
250 |
|
251 | _this2.unmarkExtraneous(dep);
|
252 |
|
253 | nameToMetadata.set(dep.realName, dep);
|
254 | }
|
255 | }
|
256 |
|
257 | if (!hasResolved) {
|
258 | break;
|
259 | }
|
260 |
|
261 | _this2.unmarkExtraneous(rootDependency);
|
262 |
|
263 | if (_this2.unresolved.size === 0) {
|
264 | return;
|
265 | }
|
266 | }
|
267 | } while (_this2.unresolved.size > 0);
|
268 | })();
|
269 | }
|
270 |
|
271 | readInstalled(nodeModulesDir, dependency, name) {
|
272 | var _this3 = this;
|
273 |
|
274 | return (0, _bluebirdLst().coroutine)(function* () {
|
275 | dependency.realName = name;
|
276 | dependency.directDependencyNames = dependency.dependencies == null ? null : Object.keys(dependency.dependencies);
|
277 |
|
278 |
|
279 | dependency.extraneous = true;
|
280 | dependency.optional = true;
|
281 |
|
282 | if (dependency.dependencies == null && dependency.optionalDependencies == null) {
|
283 |
|
284 | dependency.dependencies = null;
|
285 | return;
|
286 | }
|
287 |
|
288 | const childModules = yield readNodeModulesDir(nodeModulesDir);
|
289 |
|
290 | if (childModules == null) {
|
291 | dependency.dependencies = null;
|
292 | return;
|
293 | }
|
294 |
|
295 | const deps = yield _bluebirdLst().default.map(childModules, it => _this3.readChildPackage(it, nodeModulesDir, dependency), _fs().CONCURRENCY);
|
296 |
|
297 | if (deps.length === 0) {
|
298 | dependency.dependencies = null;
|
299 | return;
|
300 | }
|
301 |
|
302 | const nameToMetadata = new Map();
|
303 |
|
304 | for (const dep of deps) {
|
305 | if (dep != null) {
|
306 | nameToMetadata.set(dep.realName, dep);
|
307 | }
|
308 | }
|
309 |
|
310 | dependency.dependencies = nameToMetadata;
|
311 | })();
|
312 | }
|
313 |
|
314 | readChildPackage(name, nodeModulesDir, parent) {
|
315 | var _this4 = this;
|
316 |
|
317 | return (0, _bluebirdLst().coroutine)(function* () {
|
318 | const rawDir = path.join(nodeModulesDir, name);
|
319 | let dir = rawDir;
|
320 | const stat = yield (0, _fsExtraP().lstat)(dir);
|
321 | const isSymbolicLink = stat.isSymbolicLink();
|
322 |
|
323 | if (isSymbolicLink) {
|
324 | dir = yield (0, _promise().orNullIfFileNotExist)((0, _fsExtraP().realpath)(dir));
|
325 |
|
326 | if (dir == null) {
|
327 | _builderUtil().log.debug({
|
328 | path: rawDir
|
329 | }, "broken symlink");
|
330 |
|
331 | return null;
|
332 | }
|
333 | }
|
334 |
|
335 | const processed = _this4.pathToMetadata.get(dir);
|
336 |
|
337 | if (processed != null) {
|
338 | return processed;
|
339 | }
|
340 |
|
341 | const metadata = yield (0, _promise().orNullIfFileNotExist)(readJson(path.join(dir, "package.json")));
|
342 |
|
343 | if (metadata == null) {
|
344 | return null;
|
345 | }
|
346 |
|
347 | if (isSymbolicLink) {
|
348 | metadata.link = dir;
|
349 | metadata.stat = stat;
|
350 | } else {
|
351 | metadata.parent = parent;
|
352 |
|
353 | metadata.link = undefined;
|
354 | }
|
355 |
|
356 | metadata.path = rawDir;
|
357 |
|
358 | _this4.pathToMetadata.set(dir, metadata);
|
359 |
|
360 | yield _this4.readInstalled(dir + path.sep + "node_modules", metadata, name);
|
361 | return metadata;
|
362 | })();
|
363 | }
|
364 |
|
365 | unmark(deps, obj, unsetOptional, isOptional) {
|
366 | for (const name of deps) {
|
367 | const dep = this.findDep(obj, name, isOptional);
|
368 |
|
369 | if (dep != null) {
|
370 | if (unsetOptional) {
|
371 | dep.optional = false;
|
372 | }
|
373 |
|
374 | if (dep.extraneous) {
|
375 | this.unmarkExtraneous(dep);
|
376 | }
|
377 | }
|
378 | }
|
379 | }
|
380 |
|
381 | unmarkExtraneous(obj) {
|
382 |
|
383 |
|
384 |
|
385 | obj.extraneous = false;
|
386 |
|
387 | if (obj.directDependencyNames != null) {
|
388 | this.unmark(obj.directDependencyNames, obj, true, false);
|
389 | }
|
390 |
|
391 | if (obj.peerDependencies != null) {
|
392 | this.unmark(Object.keys(obj.peerDependencies), obj, true, false);
|
393 | }
|
394 |
|
395 | if (obj.optionalDependencies != null) {
|
396 | this.unmark(Object.keys(obj.optionalDependencies), obj, false, true);
|
397 | }
|
398 | }
|
399 |
|
400 |
|
401 | findDep(obj, name, isOptional) {
|
402 | if (isIgnoredDep(name)) {
|
403 | return null;
|
404 | }
|
405 |
|
406 | let r = obj;
|
407 | let found = null;
|
408 |
|
409 | while (r != null && found == null) {
|
410 |
|
411 |
|
412 | found = r.dependencies == null ? null : r.dependencies.get(name);
|
413 |
|
414 | if (found == null && r.realName === name) {
|
415 | found = r;
|
416 | }
|
417 |
|
418 | r = r.link == null ? r.parent : null;
|
419 | }
|
420 |
|
421 | if (found == null) {
|
422 | this.unresolved.set(name, isOptional);
|
423 | }
|
424 |
|
425 | return found;
|
426 | }
|
427 |
|
428 | }
|
429 |
|
430 | function isIgnoredDep(name) {
|
431 | return knownAlwaysIgnoredDevDeps.has(name) || name.startsWith("@types/");
|
432 | }
|
433 |
|
\ | No newline at end of file |