1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.NodeModuleCopyHelper = void 0;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = _interopRequireWildcard(require("bluebird-lst"));
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _fs() {
|
19 | const data = require("builder-util/out/fs");
|
20 |
|
21 | _fs = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _fsExtraP() {
|
29 | const data = require("fs-extra-p");
|
30 |
|
31 | _fsExtraP = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | var path = _interopRequireWildcard(require("path"));
|
39 |
|
40 | function _fileMatcher() {
|
41 | const data = require("../fileMatcher");
|
42 |
|
43 | _fileMatcher = function () {
|
44 | return data;
|
45 | };
|
46 |
|
47 | return data;
|
48 | }
|
49 |
|
50 | function _platformPackager() {
|
51 | const data = require("../platformPackager");
|
52 |
|
53 | _platformPackager = function () {
|
54 | return data;
|
55 | };
|
56 |
|
57 | return data;
|
58 | }
|
59 |
|
60 | function _AppFileWalker() {
|
61 | const data = require("./AppFileWalker");
|
62 |
|
63 | _AppFileWalker = function () {
|
64 | return data;
|
65 | };
|
66 |
|
67 | return data;
|
68 | }
|
69 |
|
70 | 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; } }
|
71 |
|
72 | const excludedFiles = new Set([".DS_Store", "node_modules"
|
73 |
|
74 | , "CHANGELOG.md", "ChangeLog", "changelog.md", "binding.gyp", ".npmignore"].concat(_fileMatcher().excludedNames.split(",")));
|
75 | const topLevelExcludedFiles = new Set(["test.js", "karma.conf.js", ".coveralls.yml", "README.md", "readme.markdown", "README", "readme.md", "readme", "test", "__tests__", "tests", "powered-test", "example", "examples"]);
|
76 |
|
77 |
|
78 | class NodeModuleCopyHelper extends _AppFileWalker().FileCopyHelper {
|
79 | constructor(matcher, packager) {
|
80 | super(matcher, matcher.isEmpty() ? null : matcher.createFilter(), packager);
|
81 | }
|
82 |
|
83 | collectNodeModules(baseDir, moduleNames, nodeModuleExcludedExts) {
|
84 | var _this = this;
|
85 |
|
86 | return (0, _bluebirdLst().coroutine)(function* () {
|
87 | const filter = _this.filter;
|
88 | const metadata = _this.metadata;
|
89 | const onNodeModuleFile = (0, _platformPackager().resolveFunction)(_this.packager.config.onNodeModuleFile, "onNodeModuleFile");
|
90 | const result = [];
|
91 | const queue = [];
|
92 |
|
93 | for (const moduleName of moduleNames) {
|
94 | const tmpPath = baseDir + path.sep + moduleName;
|
95 | queue.length = 1;
|
96 |
|
97 | const depPath = path.normalize(tmpPath);
|
98 | queue[0] = depPath;
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | while (queue.length > 0) {
|
107 | const dirPath = queue.pop();
|
108 | const childNames = yield (0, _fsExtraP().readdir)(dirPath);
|
109 | childNames.sort();
|
110 | const isTopLevel = dirPath === depPath;
|
111 | const dirs = [];
|
112 |
|
113 | const sortedFilePaths = yield _bluebirdLst().default.map(childNames, name => {
|
114 | if (onNodeModuleFile != null) {
|
115 | onNodeModuleFile(dirPath + path.sep + name);
|
116 | }
|
117 |
|
118 | if (excludedFiles.has(name) || name.startsWith("._")) {
|
119 | return null;
|
120 | }
|
121 |
|
122 | for (const ext of nodeModuleExcludedExts) {
|
123 | if (name.endsWith(ext)) {
|
124 | return null;
|
125 | }
|
126 | }
|
127 |
|
128 |
|
129 | if (isTopLevel && (topLevelExcludedFiles.has(name) || moduleName === "libui-node" && (name === "build" || name === "docs" || name === "src"))) {
|
130 | return null;
|
131 | }
|
132 |
|
133 | if (dirPath.endsWith("build")) {
|
134 | if (name === "gyp-mac-tool" || name === "Makefile" || name.endsWith(".mk") || name.endsWith(".gypi") || name.endsWith(".Makefile")) {
|
135 | return null;
|
136 | }
|
137 | } else if (dirPath.endsWith("Release") && (name === ".deps" || name === "obj.target")) {
|
138 | return null;
|
139 | } else if (name === "src" && (dirPath.endsWith("keytar") || dirPath.endsWith("keytar-prebuild"))) {
|
140 | return null;
|
141 | } else if (dirPath.endsWith("lzma-native") && (name === "build" || name === "deps")) {
|
142 | return null;
|
143 | }
|
144 |
|
145 | const filePath = dirPath + path.sep + name;
|
146 | return (0, _fsExtraP().lstat)(filePath).then(stat => {
|
147 | if (filter != null && !filter(filePath, stat)) {
|
148 | return null;
|
149 | }
|
150 |
|
151 | if (!stat.isDirectory()) {
|
152 | metadata.set(filePath, stat);
|
153 | }
|
154 |
|
155 | const consumerResult = _this.handleFile(filePath, dirPath, stat);
|
156 |
|
157 | if (consumerResult == null) {
|
158 | if (stat.isDirectory()) {
|
159 | dirs.push(name);
|
160 | return null;
|
161 | } else {
|
162 | return filePath;
|
163 | }
|
164 | } else {
|
165 | return consumerResult.then(it => {
|
166 |
|
167 | if ((it == null ? stat : it).isDirectory()) {
|
168 | dirs.push(name);
|
169 | return null;
|
170 | } else {
|
171 | return filePath;
|
172 | }
|
173 | });
|
174 | }
|
175 | });
|
176 | }, _fs().CONCURRENCY);
|
177 |
|
178 | for (const child of sortedFilePaths) {
|
179 | if (child != null) {
|
180 | result.push(child);
|
181 | }
|
182 | }
|
183 |
|
184 | dirs.sort();
|
185 |
|
186 | for (const child of dirs) {
|
187 | queue.push(dirPath + path.sep + child);
|
188 | }
|
189 | }
|
190 | }
|
191 |
|
192 | return result;
|
193 | })();
|
194 | }
|
195 |
|
196 | } exports.NodeModuleCopyHelper = NodeModuleCopyHelper;
|
197 |
|
\ | No newline at end of file |