1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.DO_NOT_USE_HARD_LINKS = exports.FileCopier = exports.walk = exports.exists = exports.statOrNull = exports.CONCURRENCY = exports.MAX_FILE_REQUESTS = undefined;
|
7 |
|
8 | var _bluebirdLst;
|
9 |
|
10 | function _load_bluebirdLst() {
|
11 | return _bluebirdLst = require("bluebird-lst");
|
12 | }
|
13 |
|
14 | var _bluebirdLst2;
|
15 |
|
16 | function _load_bluebirdLst2() {
|
17 | return _bluebirdLst2 = _interopRequireDefault(require("bluebird-lst"));
|
18 | }
|
19 |
|
20 | let statOrNull = exports.statOrNull = (() => {
|
21 | var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (file) {
|
22 | return (0, (_promise || _load_promise()).orNullIfFileNotExist)((0, (_fsExtraP || _load_fsExtraP()).stat)(file));
|
23 | });
|
24 |
|
25 | return function statOrNull(_x) {
|
26 | return _ref.apply(this, arguments);
|
27 | };
|
28 | })();
|
29 |
|
30 | let exists = exports.exists = (() => {
|
31 | var _ref2 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (file) {
|
32 | try {
|
33 | yield (0, (_fsExtraP || _load_fsExtraP()).access)(file);
|
34 | return true;
|
35 | } catch (e) {
|
36 | return false;
|
37 | }
|
38 | });
|
39 |
|
40 | return function exists(_x2) {
|
41 | return _ref2.apply(this, arguments);
|
42 | };
|
43 | })();
|
44 |
|
45 | let walk = exports.walk = (() => {
|
46 | var _ref3 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (initialDirPath, filter, consumer) {
|
47 | let result = [];
|
48 | const queue = [initialDirPath];
|
49 | let addDirToResult = false;
|
50 | const isIncludeDir = consumer == null ? false : consumer.isIncludeDir === true;
|
51 | while (queue.length > 0) {
|
52 | const dirPath = queue.pop();
|
53 | if (isIncludeDir) {
|
54 | if (addDirToResult) {
|
55 | result.push(dirPath);
|
56 | } else {
|
57 | addDirToResult = true;
|
58 | }
|
59 | }
|
60 | const childNames = yield (0, (_fsExtraP || _load_fsExtraP()).readdir)(dirPath);
|
61 | childNames.sort();
|
62 | let nodeModuleContent = null;
|
63 | const dirs = [];
|
64 |
|
65 | const sortedFilePaths = yield (_bluebirdLst2 || _load_bluebirdLst2()).default.map(childNames, function (name) {
|
66 | if (name === ".DS_Store" || name === ".gitkeep") {
|
67 | return null;
|
68 | }
|
69 | const filePath = dirPath + _path.sep + name;
|
70 | return (0, (_fsExtraP || _load_fsExtraP()).lstat)(filePath).then(function (stat) {
|
71 | if (filter != null && !filter(filePath, stat)) {
|
72 | return null;
|
73 | }
|
74 | const consumerResult = consumer == null ? null : consumer.consume(filePath, stat, dirPath, childNames);
|
75 | if (consumerResult == null || !("then" in consumerResult)) {
|
76 | if (stat.isDirectory()) {
|
77 | dirs.push(name);
|
78 | return null;
|
79 | } else {
|
80 | return filePath;
|
81 | }
|
82 | } else {
|
83 | return consumerResult.then(function (it) {
|
84 | if (it != null && Array.isArray(it)) {
|
85 | nodeModuleContent = it;
|
86 | return null;
|
87 | }
|
88 |
|
89 | if ((it != null && "isDirectory" in it ? it : stat).isDirectory()) {
|
90 | dirs.push(name);
|
91 | return null;
|
92 | } else {
|
93 | return filePath;
|
94 | }
|
95 | });
|
96 | }
|
97 | });
|
98 | }, CONCURRENCY);
|
99 | for (const child of sortedFilePaths) {
|
100 | if (child != null) {
|
101 | result.push(child);
|
102 | }
|
103 | }
|
104 | dirs.sort();
|
105 | for (const child of dirs) {
|
106 | queue.push(dirPath + _path.sep + child);
|
107 | }
|
108 | if (nodeModuleContent != null) {
|
109 | result = result.concat(nodeModuleContent);
|
110 | }
|
111 | }
|
112 | return result;
|
113 | });
|
114 |
|
115 | return function walk(_x3, _x4, _x5) {
|
116 | return _ref3.apply(this, arguments);
|
117 | };
|
118 | })();
|
119 |
|
120 | exports.unlinkIfExists = unlinkIfExists;
|
121 | exports.copyFile = copyFile;
|
122 | exports.copyOrLinkFile = copyOrLinkFile;
|
123 | exports.copyDir = copyDir;
|
124 |
|
125 | var _fcopyPreBundled;
|
126 |
|
127 | function _load_fcopyPreBundled() {
|
128 | return _fcopyPreBundled = _interopRequireDefault(require("fcopy-pre-bundled"));
|
129 | }
|
130 |
|
131 | var _fsExtraP;
|
132 |
|
133 | function _load_fsExtraP() {
|
134 | return _fsExtraP = require("fs-extra-p");
|
135 | }
|
136 |
|
137 | var _isCi;
|
138 |
|
139 | function _load_isCi() {
|
140 | return _isCi = _interopRequireDefault(require("is-ci"));
|
141 | }
|
142 |
|
143 | var _path = _interopRequireWildcard(require("path"));
|
144 |
|
145 | var _statMode;
|
146 |
|
147 | function _load_statMode() {
|
148 | return _statMode = _interopRequireDefault(require("stat-mode"));
|
149 | }
|
150 |
|
151 | var _promise;
|
152 |
|
153 | function _load_promise() {
|
154 | return _promise = require("./promise");
|
155 | }
|
156 |
|
157 | var _util;
|
158 |
|
159 | function _load_util() {
|
160 | return _util = require("./util");
|
161 | }
|
162 |
|
163 | 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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
164 |
|
165 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
166 |
|
167 | const MAX_FILE_REQUESTS = exports.MAX_FILE_REQUESTS = 8;
|
168 | const CONCURRENCY = exports.CONCURRENCY = { concurrency: MAX_FILE_REQUESTS };
|
169 | function unlinkIfExists(file) {
|
170 | return (0, (_fsExtraP || _load_fsExtraP()).unlink)(file).catch(() => {});
|
171 | }
|
172 |
|
173 | const _isUseHardLink = process.platform !== "win32" && process.env.USE_HARD_LINKS !== "false" && ((_isCi || _load_isCi()).default || process.env.USE_HARD_LINKS === "true");
|
174 | function copyFile(src, dest) {
|
175 | let isEnsureDir = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
176 |
|
177 | return (isEnsureDir ? (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(_path.dirname(dest)) : (_bluebirdLst2 || _load_bluebirdLst2()).default.resolve()).then(() => copyOrLinkFile(src, dest, null, false));
|
178 | }
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | function copyOrLinkFile(src, dest, stats) {
|
186 | let isUseHardLink = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _isUseHardLink;
|
187 |
|
188 | if (stats != null) {
|
189 | const originalModeNumber = stats.mode;
|
190 | const mode = new (_statMode || _load_statMode()).default(stats);
|
191 | if (mode.owner.execute) {
|
192 | mode.group.execute = true;
|
193 | mode.others.execute = true;
|
194 | }
|
195 | mode.group.read = true;
|
196 | mode.others.read = true;
|
197 | if (originalModeNumber !== stats.mode) {
|
198 | if ((_util || _load_util()).debug.enabled) {
|
199 | const oldMode = new (_statMode || _load_statMode()).default(Object.assign({}, stats, { mode: originalModeNumber }));
|
200 | (0, (_util || _load_util()).debug)(`${dest} permissions fixed from ${oldMode.toOctal()} (${oldMode.toString()}) to ${mode.toOctal()} (${mode.toString()})`);
|
201 | }
|
202 |
|
203 |
|
204 |
|
205 | if (isUseHardLink) {
|
206 | isUseHardLink = false;
|
207 | (0, (_util || _load_util()).debug)(`${dest} will be copied, but not linked, because file permissions need to be fixed`);
|
208 | }
|
209 | }
|
210 | }
|
211 | if (isUseHardLink) {
|
212 | return (0, (_fsExtraP || _load_fsExtraP()).link)(src, dest);
|
213 | }
|
214 | return new (_bluebirdLst2 || _load_bluebirdLst2()).default((resolve, reject) => {
|
215 | (0, (_fcopyPreBundled || _load_fcopyPreBundled()).default)(src, dest, stats == null ? undefined : { mode: stats.mode }, error => error == null ? resolve() : reject(error));
|
216 | });
|
217 | }
|
218 | class FileCopier {
|
219 | constructor(isUseHardLinkFunction, transformer) {
|
220 | this.isUseHardLinkFunction = isUseHardLinkFunction;
|
221 | this.transformer = transformer;
|
222 | this.isUseHardLink = _isUseHardLink && isUseHardLinkFunction !== DO_NOT_USE_HARD_LINKS;
|
223 | }
|
224 | copy(src, dest, stat) {
|
225 | var _this = this;
|
226 |
|
227 | return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
|
228 | try {
|
229 | if (_this.transformer != null && stat != null && stat.isFile()) {
|
230 | let data = _this.transformer(src);
|
231 | if (data != null) {
|
232 | if (typeof data.then === "function") {
|
233 | data = yield data;
|
234 | }
|
235 | if (data != null) {
|
236 | yield (0, (_fsExtraP || _load_fsExtraP()).writeFile)(dest, data);
|
237 | return;
|
238 | }
|
239 | }
|
240 | }
|
241 | yield copyOrLinkFile(src, dest, stat, !_this.isUseHardLink || _this.isUseHardLinkFunction == null ? _this.isUseHardLink : _this.isUseHardLinkFunction(dest));
|
242 | } catch (e) {
|
243 |
|
244 | if (e.code === "EXDEV") {
|
245 |
|
246 | if (_this.isUseHardLink) {
|
247 | (0, (_util || _load_util()).debug)(`Cannot copy using hard link: ${e}`);
|
248 | _this.isUseHardLink = false;
|
249 | }
|
250 | yield copyOrLinkFile(src, dest, stat, false);
|
251 | } else {
|
252 | throw e;
|
253 | }
|
254 | }
|
255 | })();
|
256 | }
|
257 | }
|
258 | exports.FileCopier = FileCopier; |
259 |
|
260 |
|
261 |
|
262 |
|
263 | function copyDir(src, destination, filter, transformer, isUseHardLink) {
|
264 | const fileCopier = new FileCopier(isUseHardLink, transformer);
|
265 | if ((_util || _load_util()).debug.enabled) {
|
266 | (0, (_util || _load_util()).debug)(`Copying ${src} to ${destination}${fileCopier.isUseHardLink ? " using hard links" : ""}`);
|
267 | }
|
268 | const createdSourceDirs = new Set();
|
269 | const links = [];
|
270 | return walk(src, filter, {
|
271 | consume: (() => {
|
272 | var _ref4 = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (file, stat, parent) {
|
273 | if (!stat.isFile() && !stat.isSymbolicLink()) {
|
274 | return;
|
275 | }
|
276 | if (!createdSourceDirs.has(parent)) {
|
277 | yield (0, (_fsExtraP || _load_fsExtraP()).ensureDir)(parent.replace(src, destination));
|
278 | createdSourceDirs.add(parent);
|
279 | }
|
280 | const destFile = file.replace(src, destination);
|
281 | if (stat.isFile()) {
|
282 | yield fileCopier.copy(file, destFile, stat);
|
283 | } else {
|
284 | links.push({ file: destFile, link: yield (0, (_fsExtraP || _load_fsExtraP()).readlink)(file) });
|
285 | }
|
286 | });
|
287 |
|
288 | return function consume(_x8, _x9, _x10) {
|
289 | return _ref4.apply(this, arguments);
|
290 | };
|
291 | })()
|
292 | }).then(() => (_bluebirdLst2 || _load_bluebirdLst2()).default.map(links, it => (0, (_fsExtraP || _load_fsExtraP()).symlink)(it.link, it.file), CONCURRENCY));
|
293 | }
|
294 | const DO_NOT_USE_HARD_LINKS = exports.DO_NOT_USE_HARD_LINKS = file => false;
|
295 |
|
\ | No newline at end of file |