UNPKG

6.35 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.NodeModuleCopyHelper = void 0;
7
8function _bluebirdLst() {
9 const data = _interopRequireWildcard(require("bluebird-lst"));
10
11 _bluebirdLst = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _fs() {
19 const data = require("builder-util/out/fs");
20
21 _fs = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _fsExtraP() {
29 const data = require("fs-extra-p");
30
31 _fsExtraP = function () {
32 return data;
33 };
34
35 return data;
36}
37
38var path = _interopRequireWildcard(require("path"));
39
40function _fileMatcher() {
41 const data = require("../fileMatcher");
42
43 _fileMatcher = function () {
44 return data;
45 };
46
47 return data;
48}
49
50function _platformPackager() {
51 const data = require("../platformPackager");
52
53 _platformPackager = function () {
54 return data;
55 };
56
57 return data;
58}
59
60function _AppFileWalker() {
61 const data = require("./AppFileWalker");
62
63 _AppFileWalker = function () {
64 return data;
65 };
66
67 return data;
68}
69
70function _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
72const excludedFiles = new Set([".DS_Store", "node_modules"
73/* already in the queue */
74, "CHANGELOG.md", "ChangeLog", "changelog.md", "binding.gyp", ".npmignore"].concat(_fileMatcher().excludedNames.split(",")));
75const 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/** @internal */
77
78class 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; // The path should be corrected in Windows that when the moduleName is Scoped packages named.
96
97 const depPath = path.normalize(tmpPath);
98 queue[0] = depPath; // if (dep.link != null) {
99 // this.metadata.set(dep.path, dep.stat!)
100 // const r = this.handleSymlink(dep.stat!, dep.path, dep.link!)
101 // if (r != null) {
102 // await r
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 = []; // our handler is async, but we should add sorted files, so, we add file to result not in the mapper, but after map
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 } // noinspection SpellCheckingInspection
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 // asarUtil can return modified stat (symlink handling)
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//# sourceMappingURL=NodeModuleCopyHelper.js.map
\No newline at end of file