1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.NodeModuleCopyHelper = void 0;
|
4 | const bluebird_lst_1 = require("bluebird-lst");
|
5 | const fs_1 = require("builder-util/out/fs");
|
6 | const fs_extra_1 = require("fs-extra");
|
7 | const path = require("path");
|
8 | const fileMatcher_1 = require("../fileMatcher");
|
9 | const platformPackager_1 = require("../platformPackager");
|
10 | const AppFileWalker_1 = require("./AppFileWalker");
|
11 | const excludedFiles = new Set([".DS_Store", "node_modules" , "CHANGELOG.md", "ChangeLog", "changelog.md", "Changelog.md", "Changelog", "binding.gyp", ".npmignore"].concat(fileMatcher_1.excludedNames.split(",")));
|
12 | const topLevelExcludedFiles = new Set([
|
13 | "test.js",
|
14 | "karma.conf.js",
|
15 | ".coveralls.yml",
|
16 | "README.md",
|
17 | "readme.markdown",
|
18 | "README",
|
19 | "readme.md",
|
20 | "Readme.md",
|
21 | "Readme",
|
22 | "readme",
|
23 | "test",
|
24 | "__tests__",
|
25 | "tests",
|
26 | "powered-test",
|
27 | "example",
|
28 | "examples",
|
29 | ".bin",
|
30 | ]);
|
31 |
|
32 | class NodeModuleCopyHelper extends AppFileWalker_1.FileCopyHelper {
|
33 | constructor(matcher, packager) {
|
34 | super(matcher, matcher.isEmpty() ? null : matcher.createFilter(), packager);
|
35 | }
|
36 | async collectNodeModules(baseDir, moduleNames, nodeModuleExcludedExts) {
|
37 | const filter = this.filter;
|
38 | const metadata = this.metadata;
|
39 | const onNodeModuleFile = platformPackager_1.resolveFunction(this.packager.config.onNodeModuleFile, "onNodeModuleFile");
|
40 | const result = [];
|
41 | const queue = [];
|
42 | for (const moduleName of moduleNames) {
|
43 | const tmpPath = baseDir + path.sep + moduleName;
|
44 | queue.length = 1;
|
45 |
|
46 | const depPath = path.normalize(tmpPath);
|
47 | queue[0] = depPath;
|
48 | while (queue.length > 0) {
|
49 | const dirPath = queue.pop();
|
50 | const childNames = await fs_extra_1.readdir(dirPath);
|
51 | childNames.sort();
|
52 | const isTopLevel = dirPath === depPath;
|
53 | const dirs = [];
|
54 |
|
55 | const sortedFilePaths = await bluebird_lst_1.default.map(childNames, name => {
|
56 | if (onNodeModuleFile != null) {
|
57 | onNodeModuleFile(dirPath + path.sep + name);
|
58 | }
|
59 | if (excludedFiles.has(name) || name.startsWith("._")) {
|
60 | return null;
|
61 | }
|
62 | for (const ext of nodeModuleExcludedExts) {
|
63 | if (name.endsWith(ext)) {
|
64 | return null;
|
65 | }
|
66 | }
|
67 |
|
68 | if (isTopLevel && (topLevelExcludedFiles.has(name) || (moduleName === "libui-node" && (name === "build" || name === "docs" || name === "src")))) {
|
69 | return null;
|
70 | }
|
71 | if (dirPath.endsWith("build")) {
|
72 | if (name === "gyp-mac-tool" || name === "Makefile" || name.endsWith(".mk") || name.endsWith(".gypi") || name.endsWith(".Makefile")) {
|
73 | return null;
|
74 | }
|
75 | }
|
76 | else if (dirPath.endsWith("Release") && (name === ".deps" || name === "obj.target")) {
|
77 | return null;
|
78 | }
|
79 | else if (name === "src" && (dirPath.endsWith("keytar") || dirPath.endsWith("keytar-prebuild"))) {
|
80 | return null;
|
81 | }
|
82 | else if (dirPath.endsWith("lzma-native") && (name === "build" || name === "deps")) {
|
83 | return null;
|
84 | }
|
85 | const filePath = dirPath + path.sep + name;
|
86 | return fs_extra_1.lstat(filePath).then(stat => {
|
87 | if (filter != null && !filter(filePath, stat)) {
|
88 | return null;
|
89 | }
|
90 | if (!stat.isDirectory()) {
|
91 | metadata.set(filePath, stat);
|
92 | }
|
93 | const consumerResult = this.handleFile(filePath, dirPath, stat);
|
94 | if (consumerResult == null) {
|
95 | if (stat.isDirectory()) {
|
96 | dirs.push(name);
|
97 | return null;
|
98 | }
|
99 | else {
|
100 | return filePath;
|
101 | }
|
102 | }
|
103 | else {
|
104 | return consumerResult.then(it => {
|
105 |
|
106 | if ((it == null ? stat : it).isDirectory()) {
|
107 | dirs.push(name);
|
108 | return null;
|
109 | }
|
110 | else {
|
111 | return filePath;
|
112 | }
|
113 | });
|
114 | }
|
115 | });
|
116 | }, fs_1.CONCURRENCY);
|
117 | for (const child of sortedFilePaths) {
|
118 | if (child != null) {
|
119 | result.push(child);
|
120 | }
|
121 | }
|
122 | dirs.sort();
|
123 | for (const child of dirs) {
|
124 | queue.push(dirPath + path.sep + child);
|
125 | }
|
126 | }
|
127 | }
|
128 | return result;
|
129 | }
|
130 | }
|
131 | exports.NodeModuleCopyHelper = NodeModuleCopyHelper;
|
132 |
|
\ | No newline at end of file |