1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var path = require('path');
|
6 | var fs = require('fs');
|
7 | var util = require('util');
|
8 | var url$1 = require('url');
|
9 | var https = require('https');
|
10 |
|
11 | var _defineProperty = (function (obj, key, value) {
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | if (key in obj) {
|
18 | Object.defineProperty(obj, key, {
|
19 | value: value,
|
20 | enumerable: true,
|
21 | configurable: true,
|
22 | writable: true
|
23 | });
|
24 | } else {
|
25 | obj[key] = value;
|
26 | }
|
27 |
|
28 | return obj;
|
29 | });
|
30 |
|
31 | var nativeTypeOf = function nativeTypeOf(obj) {
|
32 | return typeof obj;
|
33 | };
|
34 |
|
35 | var customTypeOf = function customTypeOf(obj) {
|
36 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
37 | };
|
38 |
|
39 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? nativeTypeOf : customTypeOf;
|
40 |
|
41 | var startsWithWindowsDriveLetter = function startsWithWindowsDriveLetter(string) {
|
42 | var firstChar = string[0];
|
43 | if (!/[a-zA-Z]/.test(firstChar)) return false;
|
44 | var secondChar = string[1];
|
45 | if (secondChar !== ":") return false;
|
46 | return true;
|
47 | };
|
48 |
|
49 | var replaceSlashesWithBackSlashes = function replaceSlashesWithBackSlashes(string) {
|
50 | return string.replace(/\//g, "\\");
|
51 | };
|
52 |
|
53 | var pathnameToOperatingSystemPath = function pathnameToOperatingSystemPath(pathname) {
|
54 | if (pathname[0] !== "/") throw new Error("pathname must start with /, got ".concat(pathname));
|
55 | var pathnameWithoutLeadingSlash = pathname.slice(1);
|
56 |
|
57 | if (startsWithWindowsDriveLetter(pathnameWithoutLeadingSlash) && pathnameWithoutLeadingSlash[2] === "/") {
|
58 | return replaceSlashesWithBackSlashes(pathnameWithoutLeadingSlash);
|
59 | }
|
60 |
|
61 |
|
62 | return pathname;
|
63 | };
|
64 |
|
65 | var isWindowsPath = function isWindowsPath(path) {
|
66 | return startsWithWindowsDriveLetter(path) && path[2] === "\\";
|
67 | };
|
68 |
|
69 | var replaceBackSlashesWithSlashes = function replaceBackSlashesWithSlashes(string) {
|
70 | return string.replace(/\\/g, "/");
|
71 | };
|
72 |
|
73 | var operatingSystemPathToPathname = function operatingSystemPathToPathname(operatingSystemPath) {
|
74 | if (isWindowsPath(operatingSystemPath)) {
|
75 | return "/".concat(replaceBackSlashesWithSlashes(operatingSystemPath));
|
76 | }
|
77 |
|
78 |
|
79 | return operatingSystemPath;
|
80 | };
|
81 |
|
82 | var pathnameToRelativePathname = function pathnameToRelativePathname(pathname, otherPathname) {
|
83 | return pathname.slice(otherPathname.length);
|
84 | };
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | var babelCompatMap = {
|
94 | "transform-template-literals": {
|
95 | chrome: "41",
|
96 | edge: "13",
|
97 | firefox: "34",
|
98 | node: "4",
|
99 | samsung: "3.4",
|
100 | opera: "28",
|
101 | electron: "0.24"
|
102 | },
|
103 | "transform-literals": {
|
104 | chrome: "44",
|
105 | edge: "12",
|
106 | firefox: "53",
|
107 | safari: "9",
|
108 | node: "4",
|
109 | ios: "9",
|
110 | samsung: "4",
|
111 | opera: "31",
|
112 | electron: "0.31"
|
113 | },
|
114 | "transform-function-name": {
|
115 | chrome: "51",
|
116 | firefox: "53",
|
117 | safari: "10",
|
118 | node: "6.5",
|
119 | ios: "10",
|
120 | samsung: "5",
|
121 | opera: "38",
|
122 | electron: "1.2"
|
123 | },
|
124 | "transform-arrow-functions": {
|
125 | chrome: "47",
|
126 | edge: "13",
|
127 | firefox: "45",
|
128 | safari: "10",
|
129 | node: "6",
|
130 | ios: "10",
|
131 | samsung: "5",
|
132 | opera: "34",
|
133 | electron: "0.36"
|
134 | },
|
135 | "transform-block-scoped-functions": {
|
136 | chrome: "41",
|
137 | edge: "12",
|
138 | firefox: "46",
|
139 | safari: "10",
|
140 | node: "4",
|
141 | ie: "11",
|
142 | ios: "10",
|
143 | samsung: "3.4",
|
144 | opera: "28",
|
145 | electron: "0.24"
|
146 | },
|
147 | "transform-classes": {
|
148 | chrome: "46",
|
149 | edge: "13",
|
150 | firefox: "45",
|
151 | safari: "10",
|
152 | node: "5",
|
153 | ios: "10",
|
154 | samsung: "5",
|
155 | opera: "33",
|
156 | electron: "0.36"
|
157 | },
|
158 | "transform-object-super": {
|
159 | chrome: "46",
|
160 | edge: "13",
|
161 | firefox: "45",
|
162 | safari: "10",
|
163 | node: "5",
|
164 | ios: "10",
|
165 | samsung: "5",
|
166 | opera: "33",
|
167 | electron: "0.36"
|
168 | },
|
169 | "transform-shorthand-properties": {
|
170 | chrome: "43",
|
171 | edge: "12",
|
172 | firefox: "33",
|
173 | safari: "9",
|
174 | node: "4",
|
175 | ios: "9",
|
176 | samsung: "4",
|
177 | opera: "30",
|
178 | electron: "0.29"
|
179 | },
|
180 | "transform-duplicate-keys": {
|
181 | chrome: "42",
|
182 | edge: "12",
|
183 | firefox: "34",
|
184 | safari: "9",
|
185 | node: "4",
|
186 | ios: "9",
|
187 | samsung: "3.4",
|
188 | opera: "29",
|
189 | electron: "0.27"
|
190 | },
|
191 | "transform-computed-properties": {
|
192 | chrome: "44",
|
193 | edge: "12",
|
194 | firefox: "34",
|
195 | safari: "7.1",
|
196 | node: "4",
|
197 | ios: "8",
|
198 | samsung: "4",
|
199 | opera: "31",
|
200 | electron: "0.31"
|
201 | },
|
202 | "transform-for-of": {
|
203 | chrome: "51",
|
204 | edge: "15",
|
205 | firefox: "53",
|
206 | safari: "10",
|
207 | node: "6.5",
|
208 | ios: "10",
|
209 | samsung: "5",
|
210 | opera: "38",
|
211 | electron: "1.2"
|
212 | },
|
213 | "transform-sticky-regex": {
|
214 | chrome: "49",
|
215 | edge: "13",
|
216 | firefox: "3",
|
217 | safari: "10",
|
218 | node: "6",
|
219 | ios: "10",
|
220 | samsung: "5",
|
221 | opera: "36",
|
222 | electron: "1"
|
223 | },
|
224 | "transform-dotall-regex": {
|
225 | chrome: "62",
|
226 | safari: "11.1",
|
227 | node: "8.10",
|
228 | ios: "11.3",
|
229 | samsung: "8.2",
|
230 | opera: "49",
|
231 | electron: "3.1"
|
232 | },
|
233 | "transform-unicode-regex": {
|
234 | chrome: "50",
|
235 | edge: "13",
|
236 | firefox: "46",
|
237 | safari: "12",
|
238 | node: "6",
|
239 | ios: "12",
|
240 | samsung: "5",
|
241 | opera: "37",
|
242 | electron: "1.1"
|
243 | },
|
244 | "transform-spread": {
|
245 | chrome: "46",
|
246 | edge: "13",
|
247 | firefox: "36",
|
248 | safari: "10",
|
249 | node: "5",
|
250 | ios: "10",
|
251 | samsung: "5",
|
252 | opera: "33",
|
253 | electron: "0.36"
|
254 | },
|
255 | "transform-parameters": {
|
256 | chrome: "49",
|
257 | edge: "18",
|
258 | firefox: "53",
|
259 | safari: "10",
|
260 | node: "6",
|
261 | ios: "10",
|
262 | samsung: "5",
|
263 | opera: "36",
|
264 | electron: "1"
|
265 | },
|
266 | "transform-destructuring": {
|
267 | chrome: "51",
|
268 | edge: "15",
|
269 | firefox: "53",
|
270 | safari: "10",
|
271 | node: "6.5",
|
272 | ios: "10",
|
273 | samsung: "5",
|
274 | opera: "38",
|
275 | electron: "1.2"
|
276 | },
|
277 | "transform-block-scoping": {
|
278 | chrome: "49",
|
279 | edge: "14",
|
280 | firefox: "51",
|
281 | safari: "11",
|
282 | node: "6",
|
283 | ios: "11",
|
284 | samsung: "5",
|
285 | opera: "36",
|
286 | electron: "1"
|
287 | },
|
288 | "transform-typeof-symbol": {
|
289 | chrome: "38",
|
290 | edge: "12",
|
291 | firefox: "36",
|
292 | safari: "9",
|
293 | node: "0.12",
|
294 | ios: "9",
|
295 | samsung: "3",
|
296 | opera: "25",
|
297 | electron: "0.2"
|
298 | },
|
299 | "transform-new-target": {
|
300 | chrome: "46",
|
301 | edge: "14",
|
302 | firefox: "41",
|
303 | safari: "10",
|
304 | node: "5",
|
305 | ios: "10",
|
306 | samsung: "5",
|
307 | opera: "33",
|
308 | electron: "0.36"
|
309 | },
|
310 | "transform-regenerator": {
|
311 | chrome: "50",
|
312 | edge: "13",
|
313 | firefox: "53",
|
314 | safari: "10",
|
315 | node: "6",
|
316 | ios: "10",
|
317 | samsung: "5",
|
318 | opera: "37",
|
319 | electron: "1.1"
|
320 | },
|
321 | "transform-exponentiation-operator": {
|
322 | chrome: "52",
|
323 | edge: "14",
|
324 | firefox: "52",
|
325 | safari: "10.1",
|
326 | node: "7",
|
327 | ios: "10.3",
|
328 | samsung: "6.2",
|
329 | opera: "39",
|
330 | electron: "1.3"
|
331 | },
|
332 | "transform-async-to-generator": {
|
333 | chrome: "55",
|
334 | edge: "15",
|
335 | firefox: "52",
|
336 | safari: "11",
|
337 | node: "7.6",
|
338 | ios: "11",
|
339 | samsung: "6.2",
|
340 | opera: "42",
|
341 | electron: "1.6"
|
342 | },
|
343 |
|
344 |
|
345 |
|
346 | "transform-async-to-promises": {
|
347 | chrome: "55",
|
348 | edge: "15",
|
349 | firefox: "52",
|
350 | safari: "11",
|
351 | node: "7.6",
|
352 | ios: "11",
|
353 | samsung: "6.2",
|
354 | opera: "42",
|
355 | electron: "1.6"
|
356 | },
|
357 | "proposal-async-generator-functions": {
|
358 | chrome: "63",
|
359 | firefox: "57",
|
360 | safari: "12",
|
361 | node: "10",
|
362 | ios: "12",
|
363 | samsung: "8.2",
|
364 | opera: "50",
|
365 | electron: "3.1"
|
366 | },
|
367 | "proposal-object-rest-spread": {
|
368 | chrome: "60",
|
369 | firefox: "55",
|
370 | safari: "11.1",
|
371 | node: "8.3",
|
372 | ios: "11.3",
|
373 | samsung: "8.2",
|
374 | opera: "47",
|
375 | electron: "2.1"
|
376 | },
|
377 | "proposal-optional-chaining": {},
|
378 | "proposal-unicode-property-regex": {
|
379 | chrome: "64",
|
380 | safari: "11.1",
|
381 | node: "10",
|
382 | ios: "11.3",
|
383 | opera: "51",
|
384 | electron: "3.1"
|
385 | },
|
386 | "proposal-json-strings": {
|
387 | chrome: "66",
|
388 | firefox: "62",
|
389 | safari: "12",
|
390 | node: "10",
|
391 | ios: "12",
|
392 | opera: "53",
|
393 | electron: "3.1"
|
394 | },
|
395 | "proposal-optional-catch-binding": {
|
396 | chrome: "66",
|
397 | firefox: "58",
|
398 | safari: "11.1",
|
399 | node: "10",
|
400 | ios: "11.3",
|
401 | opera: "53",
|
402 | electron: "3.1"
|
403 | },
|
404 | "transform-named-capturing-groups-regex": {
|
405 | chrome: "64",
|
406 | safari: "11.1",
|
407 | node: "10",
|
408 | ios: "11.3",
|
409 | opera: "51",
|
410 | electron: "3.1"
|
411 | },
|
412 | "transform-member-expression-literals": {
|
413 | chrome: "7",
|
414 | opera: "12",
|
415 | edge: "12",
|
416 | firefox: "2",
|
417 | safari: "5.1",
|
418 | node: "0.10",
|
419 | ie: "9",
|
420 | android: "4",
|
421 | ios: "6",
|
422 | phantom: "2",
|
423 | samsung: "2.1",
|
424 | electron: "5"
|
425 | },
|
426 | "transform-property-literals": {
|
427 | chrome: "7",
|
428 | opera: "12",
|
429 | edge: "12",
|
430 | firefox: "2",
|
431 | safari: "5.1",
|
432 | node: "0.10",
|
433 | ie: "9",
|
434 | android: "4",
|
435 | ios: "6",
|
436 | phantom: "2",
|
437 | samsung: "2.1",
|
438 | electron: "5"
|
439 | },
|
440 | "transform-reserved-words": {
|
441 | chrome: "13",
|
442 | opera: "10.50",
|
443 | edge: "12",
|
444 | firefox: "2",
|
445 | safari: "3.1",
|
446 | node: "0.10",
|
447 | ie: "9",
|
448 | android: "4.4",
|
449 | ios: "6",
|
450 | phantom: "2",
|
451 | samsung: "2.1",
|
452 | electron: "0.2"
|
453 | }
|
454 | };
|
455 |
|
456 | var hrefToScheme = function hrefToScheme(href) {
|
457 | var colonIndex = href.indexOf(":");
|
458 | if (colonIndex === -1) return "";
|
459 | return href.slice(0, colonIndex);
|
460 | };
|
461 |
|
462 | var hrefToOrigin = function hrefToOrigin(href) {
|
463 | var scheme = hrefToScheme(href);
|
464 |
|
465 | if (scheme === "file") {
|
466 | return "file://";
|
467 | }
|
468 |
|
469 | if (scheme === "http" || scheme === "https") {
|
470 | var secondProtocolSlashIndex = scheme.length + "://".length;
|
471 | var pathnameSlashIndex = href.indexOf("/", secondProtocolSlashIndex);
|
472 | if (pathnameSlashIndex === -1) return href;
|
473 | return href.slice(0, pathnameSlashIndex);
|
474 | }
|
475 |
|
476 | return href.slice(0, scheme.length + 1);
|
477 | };
|
478 |
|
479 | var hrefToPathname = function hrefToPathname(href) {
|
480 | return ressourceToPathname(hrefToRessource(href));
|
481 | };
|
482 |
|
483 | var hrefToRessource = function hrefToRessource(href) {
|
484 | var scheme = hrefToScheme(href);
|
485 |
|
486 | if (scheme === "file") {
|
487 | return href.slice("file://".length);
|
488 | }
|
489 |
|
490 | if (scheme === "https" || scheme === "http") {
|
491 |
|
492 | var afterProtocol = href.slice(scheme.length + "://".length);
|
493 | var pathnameSlashIndex = afterProtocol.indexOf("/", "://".length);
|
494 | return afterProtocol.slice(pathnameSlashIndex);
|
495 | }
|
496 |
|
497 | return href.slice(scheme.length + 1);
|
498 | };
|
499 |
|
500 | var ressourceToPathname = function ressourceToPathname(ressource) {
|
501 | var searchSeparatorIndex = ressource.indexOf("?");
|
502 | return searchSeparatorIndex === -1 ? ressource : ressource.slice(0, searchSeparatorIndex);
|
503 | };
|
504 |
|
505 | var pathnameIsInside = function pathnameIsInside(pathname, otherPathname) {
|
506 | return pathname.startsWith("".concat(otherPathname, "/"));
|
507 | };
|
508 |
|
509 | var pathnameToDirname = function pathnameToDirname(pathname) {
|
510 | var slashLastIndex = pathname.lastIndexOf("/");
|
511 | if (slashLastIndex === -1) return "";
|
512 | return pathname.slice(0, slashLastIndex);
|
513 | };
|
514 |
|
515 | var pathnameToExtension = function pathnameToExtension(pathname) {
|
516 | var slashLastIndex = pathname.lastIndexOf("/");
|
517 |
|
518 | if (slashLastIndex !== -1) {
|
519 | pathname = pathname.slice(slashLastIndex + 1);
|
520 | }
|
521 |
|
522 | var dotLastIndex = pathname.lastIndexOf(".");
|
523 | if (dotLastIndex === -1) return "";
|
524 |
|
525 | return pathname.slice(dotLastIndex);
|
526 | };
|
527 |
|
528 | var pathnameToRelativePath = function pathnameToRelativePath(pathname, otherPathname) {
|
529 | return pathname.slice(otherPathname.length);
|
530 | };
|
531 |
|
532 | var nativeTypeOf$1 = function nativeTypeOf(obj) {
|
533 | return typeof obj;
|
534 | };
|
535 |
|
536 | var customTypeOf$1 = function customTypeOf(obj) {
|
537 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
538 | };
|
539 |
|
540 | var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? nativeTypeOf$1 : customTypeOf$1;
|
541 |
|
542 | var _defineProperty$1 = (function (obj, key, value) {
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 | if (key in obj) {
|
549 | Object.defineProperty(obj, key, {
|
550 | value: value,
|
551 | enumerable: true,
|
552 | configurable: true,
|
553 | writable: true
|
554 | });
|
555 | } else {
|
556 | obj[key] = value;
|
557 | }
|
558 |
|
559 | return obj;
|
560 | });
|
561 |
|
562 | function _objectSpread (target) {
|
563 | for (var i = 1; i < arguments.length; i++) {
|
564 |
|
565 | var source = arguments[i] === null ? {} : arguments[i];
|
566 |
|
567 | if (i % 2) {
|
568 |
|
569 | ownKeys(source, true).forEach(function (key) {
|
570 | _defineProperty$1(target, key, source[key]);
|
571 | });
|
572 | } else if (Object.getOwnPropertyDescriptors) {
|
573 | Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
574 | } else {
|
575 |
|
576 | ownKeys(source).forEach(function (key) {
|
577 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
578 | });
|
579 | }
|
580 | }
|
581 |
|
582 | return target;
|
583 | }
|
584 |
|
585 |
|
586 |
|
587 | function ownKeys(object, enumerableOnly) {
|
588 | var keys = Object.keys(object);
|
589 |
|
590 | if (Object.getOwnPropertySymbols) {
|
591 | var symbols = Object.getOwnPropertySymbols(object);
|
592 | if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
593 | return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
594 | });
|
595 |
|
596 | keys.push.apply(keys, symbols);
|
597 | }
|
598 |
|
599 | return keys;
|
600 | }
|
601 |
|
602 |
|
603 | var nodeRequire = require;
|
604 | var filenameContainsBackSlashes = __filename.indexOf("\\") > -1;
|
605 | var url = filenameContainsBackSlashes ? "file://".concat(__filename.replace(/\\/g, "/")) : "file://".concat(__filename);
|
606 |
|
607 | var jsenvCorePath;
|
608 |
|
609 | if (typeof __filename === "string") {
|
610 | jsenvCorePath = path.resolve(__filename, "../../../");
|
611 | } else {
|
612 | var selfPathname = hrefToPathname(url);
|
613 | var selfPath = pathnameToOperatingSystemPath(selfPathname);
|
614 | jsenvCorePath = path.resolve(selfPath, "../../../");
|
615 | }
|
616 | var jsenvCorePathname = operatingSystemPathToPathname(jsenvCorePath);
|
617 |
|
618 | var _require2 = nodeRequire("@babel/helpers"),
|
619 | list = _require2.list;
|
620 | list.forEach(function (babelHelperName) {
|
621 | });
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 | var browserScoreMap = {
|
629 | android: 0.001,
|
630 | chrome: {
|
631 | "71": 0.3,
|
632 | "69": 0.19,
|
633 | "0": 0.01
|
634 |
|
635 | },
|
636 | firefox: {
|
637 | "61": 0.3
|
638 | },
|
639 | edge: {
|
640 | "12": 0.1
|
641 | },
|
642 | electron: 0.001,
|
643 | ios: 0.001,
|
644 | opera: 0.001,
|
645 | other: 0.001,
|
646 | safari: {
|
647 | "10": 0.1
|
648 | }
|
649 | };
|
650 |
|
651 |
|
652 | var firstOperationMatching = function firstOperationMatching(_ref) {
|
653 | var array = _ref.array,
|
654 | start = _ref.start,
|
655 | predicate = _ref.predicate;
|
656 | if (_typeof(array) !== "object") throw new TypeError(createArrayErrorMessage({
|
657 | array: array
|
658 | }));
|
659 | if (typeof start !== "function") throw new TypeError(createStartErrorMessage({
|
660 | start: start
|
661 | }));
|
662 | if (typeof predicate !== "function") throw new TypeError(createPredicateErrorMessage({
|
663 | predicate: predicate
|
664 | }));
|
665 | return new Promise(function (resolve, reject) {
|
666 | var visit = function visit(index) {
|
667 | if (index >= array.length) {
|
668 | return resolve();
|
669 | }
|
670 |
|
671 | var input = array[index];
|
672 | var returnValue = start(input);
|
673 | return Promise.resolve(returnValue).then(function (output) {
|
674 | if (predicate(output)) {
|
675 | return resolve(output);
|
676 | }
|
677 |
|
678 | return visit(index + 1);
|
679 | }, reject);
|
680 | };
|
681 |
|
682 | visit(0);
|
683 | });
|
684 | };
|
685 |
|
686 | var createArrayErrorMessage = function createArrayErrorMessage(_ref2) {
|
687 | var array = _ref2.array;
|
688 | return "array must be an object.\narray: ".concat(array);
|
689 | };
|
690 |
|
691 | var createStartErrorMessage = function createStartErrorMessage(_ref3) {
|
692 | var start = _ref3.start;
|
693 | return "start must be a function.\nstart: ".concat(start);
|
694 | };
|
695 |
|
696 | var createPredicateErrorMessage = function createPredicateErrorMessage(_ref4) {
|
697 | var predicate = _ref4.predicate;
|
698 | return "predicate must be a function.\npredicate: ".concat(predicate);
|
699 | };
|
700 |
|
701 | function _objectSpread$1 (target) {
|
702 | for (var i = 1; i < arguments.length; i++) {
|
703 |
|
704 | var source = arguments[i] === null ? {} : arguments[i];
|
705 |
|
706 | if (i % 2) {
|
707 |
|
708 | ownKeys$1(source, true).forEach(function (key) {
|
709 | _defineProperty(target, key, source[key]);
|
710 | });
|
711 | } else if (Object.getOwnPropertyDescriptors) {
|
712 | Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
713 | } else {
|
714 |
|
715 | ownKeys$1(source).forEach(function (key) {
|
716 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
717 | });
|
718 | }
|
719 | }
|
720 |
|
721 | return target;
|
722 | }
|
723 |
|
724 |
|
725 |
|
726 | function ownKeys$1(object, enumerableOnly) {
|
727 | var keys = Object.keys(object);
|
728 |
|
729 | if (Object.getOwnPropertySymbols) {
|
730 | var symbols = Object.getOwnPropertySymbols(object);
|
731 | if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
732 | return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
733 | });
|
734 |
|
735 | keys.push.apply(keys, symbols);
|
736 | }
|
737 |
|
738 | return keys;
|
739 | }
|
740 |
|
741 | function _await(value, then, direct) {
|
742 | if (direct) {
|
743 | return then ? then(value) : value;
|
744 | }
|
745 |
|
746 | if (!value || !value.then) {
|
747 | value = Promise.resolve(value);
|
748 | }
|
749 |
|
750 | return then ? value.then(then) : value;
|
751 | }
|
752 |
|
753 | function _empty() {}
|
754 |
|
755 | function _awaitIgnored(value, direct) {
|
756 | if (!direct) {
|
757 | return value && value.then ? value.then(_empty) : Promise.resolve();
|
758 | }
|
759 | }
|
760 |
|
761 | function _call(body, then, direct) {
|
762 | if (direct) {
|
763 | return then ? then(body()) : body();
|
764 | }
|
765 |
|
766 | try {
|
767 | var result = Promise.resolve(body());
|
768 | return then ? result.then(then) : result;
|
769 | } catch (e) {
|
770 | return Promise.reject(e);
|
771 | }
|
772 | }
|
773 |
|
774 | function _async(f) {
|
775 | return function () {
|
776 | for (var args = [], i = 0; i < arguments.length; i++) {
|
777 | args[i] = arguments[i];
|
778 | }
|
779 |
|
780 | try {
|
781 | return Promise.resolve(f.apply(this, args));
|
782 | } catch (e) {
|
783 | return Promise.reject(e);
|
784 | }
|
785 | };
|
786 | }
|
787 |
|
788 | var promiseSequence = function promiseSequence(callbackArray) {
|
789 | var values = [];
|
790 |
|
791 | var visit = _async(function (index) {
|
792 | if (index === callbackArray.length) return;
|
793 | var callback = callbackArray[index];
|
794 | return _call(callback, function (value) {
|
795 | values.push(value);
|
796 | return _awaitIgnored(visit(index + 1));
|
797 | });
|
798 | });
|
799 |
|
800 | return _await(visit(0), function () {
|
801 | return values;
|
802 | });
|
803 | };
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 | function _await$1(value, then, direct) {
|
822 | if (direct) {
|
823 | return then ? then(value) : value;
|
824 | }
|
825 |
|
826 | if (!value || !value.then) {
|
827 | value = Promise.resolve(value);
|
828 | }
|
829 |
|
830 | return then ? value.then(then) : value;
|
831 | }
|
832 |
|
833 | function _empty$1() {}
|
834 |
|
835 | function _invokeIgnored(body) {
|
836 | var result = body();
|
837 |
|
838 | if (result && result.then) {
|
839 | return result.then(_empty$1);
|
840 | }
|
841 | }
|
842 |
|
843 | function _async$1(f) {
|
844 | return function () {
|
845 | for (var args = [], i = 0; i < arguments.length; i++) {
|
846 | args[i] = arguments[i];
|
847 | }
|
848 |
|
849 | try {
|
850 | return Promise.resolve(f.apply(this, args));
|
851 | } catch (e) {
|
852 | return Promise.reject(e);
|
853 | }
|
854 | };
|
855 | }
|
856 |
|
857 | var fileMakeDirname = function fileMakeDirname(file) {
|
858 | var fileNormalized = normalizeSeparation(file);
|
859 |
|
860 |
|
861 |
|
862 | var fileStartsWithSlash = fileNormalized[0] === "/";
|
863 | var pathname = fileStartsWithSlash ? fileNormalized.slice(1) : fileNormalized;
|
864 | var folders = pathname.split("/");
|
865 | folders.pop();
|
866 | return promiseSequence(folders.map(function (_, index) {
|
867 | return function () {
|
868 | var folder = folders.slice(0, index + 1).join("/");
|
869 | return folderMake("".concat(fileStartsWithSlash ? "/" : "").concat(folder));
|
870 | };
|
871 | }));
|
872 | };
|
873 |
|
874 | var normalizeSeparation = function normalizeSeparation(file) {
|
875 | return file.replace(/\\/g, "/");
|
876 | };
|
877 |
|
878 | var folderMake = function folderMake(folder) {
|
879 | return new Promise(function (resolve, reject) {
|
880 | fs.mkdir(folder, _async$1(function (error) {
|
881 | return _invokeIgnored(function () {
|
882 | if (error) {
|
883 |
|
884 | return _invokeIgnored(function () {
|
885 | if (error.code === "EEXIST") {
|
886 | return _await$1(fileLastStat(folder), function (stat) {
|
887 | if (stat.isDirectory()) {
|
888 | resolve();
|
889 | } else {
|
890 | reject({
|
891 | status: 500,
|
892 | reason: "expect a directory"
|
893 | });
|
894 | }
|
895 | });
|
896 | } else {
|
897 | reject({
|
898 | status: 500,
|
899 | reason: error.code
|
900 | });
|
901 | }
|
902 | });
|
903 | } else {
|
904 | resolve();
|
905 | }
|
906 | });
|
907 | }));
|
908 | });
|
909 | };
|
910 |
|
911 | var fileLastStat = function fileLastStat(path) {
|
912 | return new Promise(function (resolve, reject) {
|
913 | fs.lstat(path, function (error, lstat) {
|
914 | if (error) {
|
915 | reject({
|
916 | status: 500,
|
917 | reason: error.code
|
918 | });
|
919 | } else {
|
920 | resolve(lstat);
|
921 | }
|
922 | });
|
923 | });
|
924 | };
|
925 |
|
926 | var copyFilePromisified = util.promisify(fs.copyFile);
|
927 |
|
928 | function _await$2(value, then, direct) {
|
929 | if (direct) {
|
930 | return then ? then(value) : value;
|
931 | }
|
932 |
|
933 | if (!value || !value.then) {
|
934 | value = Promise.resolve(value);
|
935 | }
|
936 |
|
937 | return then ? value.then(then) : value;
|
938 | }
|
939 |
|
940 | var readFilePromisified = util.promisify(fs.readFile);
|
941 |
|
942 | function _async$2(f) {
|
943 | return function () {
|
944 | for (var args = [], i = 0; i < arguments.length; i++) {
|
945 | args[i] = arguments[i];
|
946 | }
|
947 |
|
948 | try {
|
949 | return Promise.resolve(f.apply(this, args));
|
950 | } catch (e) {
|
951 | return Promise.reject(e);
|
952 | }
|
953 | };
|
954 | }
|
955 |
|
956 | var fileRead = _async$2(function (file) {
|
957 | return _await$2(readFilePromisified(file), function (buffer) {
|
958 | return buffer.toString();
|
959 | });
|
960 | });
|
961 |
|
962 | var statPromisified = util.promisify(fs.stat);
|
963 |
|
964 | var lstatPromisified = util.promisify(fs.lstat);
|
965 |
|
966 | function _await$3(value, then, direct) {
|
967 | if (direct) {
|
968 | return then ? then(value) : value;
|
969 | }
|
970 |
|
971 | if (!value || !value.then) {
|
972 | value = Promise.resolve(value);
|
973 | }
|
974 |
|
975 | return then ? value.then(then) : value;
|
976 | }
|
977 |
|
978 | var writeFilePromisified = util.promisify(fs.writeFile);
|
979 |
|
980 | function _async$3(f) {
|
981 | return function () {
|
982 | for (var args = [], i = 0; i < arguments.length; i++) {
|
983 | args[i] = arguments[i];
|
984 | }
|
985 |
|
986 | try {
|
987 | return Promise.resolve(f.apply(this, args));
|
988 | } catch (e) {
|
989 | return Promise.reject(e);
|
990 | }
|
991 | };
|
992 | }
|
993 |
|
994 | var fileWrite = _async$3(function (file, content) {
|
995 | return _await$3(fileMakeDirname(file), function () {
|
996 | return writeFilePromisified(file, content);
|
997 | });
|
998 | });
|
999 |
|
1000 | var readdirPromisified = util.promisify(fs.readdir);
|
1001 |
|
1002 | var rimraf = nodeRequire("rimraf");
|
1003 |
|
1004 | var BEST_ID = "best";
|
1005 | var OTHERWISE_ID = "otherwise";
|
1006 |
|
1007 | var _require2$1 = nodeRequire("@babel/core"),
|
1008 | buildExternalHelpers = _require2$1.buildExternalHelpers;
|
1009 |
|
1010 | var _require3 = nodeRequire("@babel/helpers"),
|
1011 | getDependencies = _require3.getDependencies;
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 | var polyfillCompatMap = {};
|
1019 |
|
1020 |
|
1021 | var arrayWithoutHoles = (function (arr) {
|
1022 | if (Array.isArray(arr)) {
|
1023 | var i = 0;
|
1024 | var arr2 = new Array(arr.length);
|
1025 |
|
1026 | for (; i < arr.length; i++) {
|
1027 | arr2[i] = arr[i];
|
1028 | }
|
1029 |
|
1030 | return arr2;
|
1031 | }
|
1032 | });
|
1033 |
|
1034 |
|
1035 | var iterableToArray = (function (iter) {
|
1036 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
1037 | });
|
1038 |
|
1039 | var nonIterableSpread = (function () {
|
1040 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
1041 | });
|
1042 |
|
1043 | var _toConsumableArray = (function (arr) {
|
1044 | return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
|
1045 | });
|
1046 |
|
1047 | var valueToVersion = function valueToVersion(value) {
|
1048 | if (typeof value === "number") {
|
1049 | return numberToVersion(value);
|
1050 | }
|
1051 |
|
1052 | if (typeof value === "string") {
|
1053 | return stringToVersion(value);
|
1054 | }
|
1055 |
|
1056 | throw new TypeError(createValueErrorMessage({
|
1057 | version: value
|
1058 | }));
|
1059 | };
|
1060 |
|
1061 | var numberToVersion = function numberToVersion(number) {
|
1062 | return {
|
1063 | major: number,
|
1064 | minor: 0,
|
1065 | patch: 0
|
1066 | };
|
1067 | };
|
1068 |
|
1069 | var stringToVersion = function stringToVersion(string) {
|
1070 | if (string.indexOf(".") > -1) {
|
1071 | var parts = string.split(".");
|
1072 | return {
|
1073 | major: Number(parts[0]),
|
1074 | minor: parts[1] ? Number(parts[1]) : 0,
|
1075 | patch: parts[2] ? Number(parts[2]) : 0
|
1076 | };
|
1077 | }
|
1078 |
|
1079 | if (isNaN(string)) {
|
1080 | return {
|
1081 | major: 0,
|
1082 | minor: 0,
|
1083 | patch: 0
|
1084 | };
|
1085 | }
|
1086 |
|
1087 | return {
|
1088 | major: Number(string),
|
1089 | minor: 0,
|
1090 | patch: 0
|
1091 | };
|
1092 | };
|
1093 |
|
1094 | var createValueErrorMessage = function createValueErrorMessage(_ref) {
|
1095 | var value = _ref.value;
|
1096 | return "value must be a number or a string.\nvalue: ".concat(value);
|
1097 | };
|
1098 |
|
1099 | var versionCompare = function versionCompare(versionA, versionB) {
|
1100 | var semanticVersionA = valueToVersion(versionA);
|
1101 | var semanticVersionB = valueToVersion(versionB);
|
1102 | var majorDiff = semanticVersionA.major - semanticVersionB.major;
|
1103 |
|
1104 | if (majorDiff > 0) {
|
1105 | return majorDiff;
|
1106 | }
|
1107 |
|
1108 | if (majorDiff < 0) {
|
1109 | return majorDiff;
|
1110 | }
|
1111 |
|
1112 | var minorDiff = semanticVersionA.minor - semanticVersionB.minor;
|
1113 |
|
1114 | if (minorDiff > 0) {
|
1115 | return minorDiff;
|
1116 | }
|
1117 |
|
1118 | if (minorDiff < 0) {
|
1119 | return minorDiff;
|
1120 | }
|
1121 |
|
1122 | var patchDiff = semanticVersionA.patch - semanticVersionB.patch;
|
1123 |
|
1124 | if (patchDiff > 0) {
|
1125 | return patchDiff;
|
1126 | }
|
1127 |
|
1128 | if (patchDiff < 0) {
|
1129 | return patchDiff;
|
1130 | }
|
1131 |
|
1132 | return 0;
|
1133 | };
|
1134 |
|
1135 | var versionIsBelow = function versionIsBelow(versionSupposedBelow, versionSupposedAbove) {
|
1136 | return versionCompare(versionSupposedBelow, versionSupposedAbove) < 0;
|
1137 | };
|
1138 |
|
1139 | var findHighestVersion = function findHighestVersion() {
|
1140 | for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
1141 | values[_key] = arguments[_key];
|
1142 | }
|
1143 |
|
1144 | if (values.length === 0) throw new Error("missing argument");
|
1145 | return values.reduce(function (highestVersion, value) {
|
1146 | if (versionIsBelow(highestVersion, value)) {
|
1147 | return value;
|
1148 | }
|
1149 |
|
1150 | return highestVersion;
|
1151 | });
|
1152 | };
|
1153 |
|
1154 | var computeIncompatibleNameArray = function computeIncompatibleNameArray(_ref) {
|
1155 | var featureCompatMap = _ref.featureCompatMap,
|
1156 | platformName = _ref.platformName,
|
1157 | platformVersion = _ref.platformVersion;
|
1158 | var incompatibleNameArray = [];
|
1159 | Object.keys(featureCompatMap).forEach(function (featureName) {
|
1160 | var compatible = platformIsCompatibleWithFeature({
|
1161 | platformName: platformName,
|
1162 | platformVersion: platformVersion,
|
1163 | featureCompat: featureName in featureCompatMap ? featureCompatMap[featureName] : {}
|
1164 | });
|
1165 |
|
1166 | if (!compatible) {
|
1167 | incompatibleNameArray.push(featureName);
|
1168 | }
|
1169 | });
|
1170 | return incompatibleNameArray;
|
1171 | };
|
1172 |
|
1173 | var platformIsCompatibleWithFeature = function platformIsCompatibleWithFeature(_ref2) {
|
1174 | var platformName = _ref2.platformName,
|
1175 | platformVersion = _ref2.platformVersion,
|
1176 | featureCompat = _ref2.featureCompat;
|
1177 | var platformCompatibleVersion = computePlatformCompatibleVersion({
|
1178 | featureCompat: featureCompat,
|
1179 | platformName: platformName
|
1180 | });
|
1181 | var highestVersion = findHighestVersion(platformVersion, platformCompatibleVersion);
|
1182 | return highestVersion === platformVersion;
|
1183 | };
|
1184 |
|
1185 | var computePlatformCompatibleVersion = function computePlatformCompatibleVersion(_ref3) {
|
1186 | var featureCompat = _ref3.featureCompat,
|
1187 | platformName = _ref3.platformName;
|
1188 | return platformName in featureCompat ? featureCompat[platformName] : "Infinity";
|
1189 | };
|
1190 |
|
1191 | var generatePlatformGroupArray = function generatePlatformGroupArray(_ref) {
|
1192 | var featureCompatMap = _ref.featureCompatMap,
|
1193 | platformName = _ref.platformName;
|
1194 | var featureNameArray = Object.keys(featureCompatMap);
|
1195 | var featureNameArrayWithCompat = featureNameArray.filter(function (featureName) {
|
1196 | return platformName in featureCompatMap[featureName];
|
1197 | });
|
1198 | var versionArray = featureNameArrayWithCompat
|
1199 | .map(function (featureName) {
|
1200 | return String(featureCompatMap[featureName][platformName]);
|
1201 | }).concat("0.0.0")
|
1202 |
|
1203 | .filter(function (version, index, array) {
|
1204 | return array.indexOf(version) === index;
|
1205 | }).sort(versionCompare);
|
1206 | var platformGroupArray = [];
|
1207 | versionArray.forEach(function (version) {
|
1208 | var incompatibleNameArray = computeIncompatibleNameArray({
|
1209 | featureCompatMap: featureCompatMap,
|
1210 | platformName: platformName,
|
1211 | platformVersion: version
|
1212 | }).sort();
|
1213 | var groupWithSameIncompatibleFeatures = platformGroupArray.find(function (platformGroup) {
|
1214 | return platformGroup.incompatibleNameArray.join("") === incompatibleNameArray.join("");
|
1215 | });
|
1216 |
|
1217 | if (groupWithSameIncompatibleFeatures) {
|
1218 | groupWithSameIncompatibleFeatures.platformCompatMap[platformName] = findHighestVersion(groupWithSameIncompatibleFeatures.platformCompatMap[platformName], version);
|
1219 | } else {
|
1220 | platformGroupArray.push({
|
1221 | incompatibleNameArray: incompatibleNameArray.slice(),
|
1222 | platformCompatMap: _defineProperty$1({}, platformName, version)
|
1223 | });
|
1224 | }
|
1225 | });
|
1226 | return platformGroupArray;
|
1227 | };
|
1228 |
|
1229 | var composePlatformCompatMap = function composePlatformCompatMap(platformCompatMap, secondPlatformCompatMap) {
|
1230 | return objectComposeValue(normalizePlatformCompatMapVersions(platformCompatMap), normalizePlatformCompatMapVersions(secondPlatformCompatMap), function (version, secondVersion) {
|
1231 | return findHighestVersion(version, secondVersion);
|
1232 | });
|
1233 | };
|
1234 |
|
1235 | var normalizePlatformCompatMapVersions = function normalizePlatformCompatMapVersions(platformCompatibility) {
|
1236 | return objectMapValue(platformCompatibility, function (version) {
|
1237 | return String(version);
|
1238 | });
|
1239 | };
|
1240 |
|
1241 | var objectMapValue = function objectMapValue(object, callback) {
|
1242 | var mapped = {};
|
1243 | Object.keys(object).forEach(function (key) {
|
1244 | mapped[key] = callback(object[key], key, object);
|
1245 | });
|
1246 | return mapped;
|
1247 | };
|
1248 |
|
1249 | var objectComposeValue = function objectComposeValue(previous, object, callback) {
|
1250 | var composed = _objectSpread({}, previous);
|
1251 |
|
1252 | Object.keys(object).forEach(function (key) {
|
1253 | composed[key] = key in composed ? callback(composed[key], object[key]) : object[key];
|
1254 | });
|
1255 | return composed;
|
1256 | };
|
1257 |
|
1258 | var composeGroupArray = function composeGroupArray() {
|
1259 | for (var _len = arguments.length, arrayOfGroupArray = new Array(_len), _key = 0; _key < _len; _key++) {
|
1260 | arrayOfGroupArray[_key] = arguments[_key];
|
1261 | }
|
1262 |
|
1263 | return arrayOfGroupArray.reduce(groupArrayReducer, []);
|
1264 | };
|
1265 |
|
1266 | var groupArrayReducer = function groupArrayReducer(previousGroupArray, groupArray) {
|
1267 | var reducedGroupArray = [];
|
1268 | previousGroupArray.forEach(function (group) {
|
1269 | reducedGroupArray.push({
|
1270 | incompatibleNameArray: group.incompatibleNameArray.slice(),
|
1271 | platformCompatMap: _objectSpread({}, group.platformCompatMap)
|
1272 | });
|
1273 | });
|
1274 | groupArray.forEach(function (group) {
|
1275 | var groupWithSameIncompatibleFeature = reducedGroupArray.find(function (existingGroupCandidate) {
|
1276 | return groupHaveSameIncompatibleFeatures(group, existingGroupCandidate);
|
1277 | });
|
1278 |
|
1279 | if (groupWithSameIncompatibleFeature) {
|
1280 | groupWithSameIncompatibleFeature.platformCompatMap = composePlatformCompatMap(groupWithSameIncompatibleFeature.platformCompatMap, group.platformCompatMap);
|
1281 | } else {
|
1282 | reducedGroupArray.push({
|
1283 | incompatibleNameArray: group.incompatibleNameArray.slice(),
|
1284 | platformCompatMap: _objectSpread({}, group.platformCompatMap)
|
1285 | });
|
1286 | }
|
1287 | });
|
1288 | return reducedGroupArray;
|
1289 | };
|
1290 |
|
1291 | var groupHaveSameIncompatibleFeatures = function groupHaveSameIncompatibleFeatures(groupA, groupB) {
|
1292 | return groupA.incompatibleNameArray.join("") === groupB.incompatibleNameArray.join("");
|
1293 | };
|
1294 |
|
1295 | var generateAllPlatformGroupArray = function generateAllPlatformGroupArray(_ref) {
|
1296 | var featureCompatMap = _ref.featureCompatMap,
|
1297 | platformNames = _ref.platformNames;
|
1298 | var arrayOfGroupArray = platformNames.map(function (platformName) {
|
1299 | return generatePlatformGroupArray({
|
1300 | featureCompatMap: featureCompatMap,
|
1301 | platformName: platformName
|
1302 | });
|
1303 | });
|
1304 | var groupArray = composeGroupArray.apply(void 0, _toConsumableArray(arrayOfGroupArray));
|
1305 | return groupArray;
|
1306 | };
|
1307 |
|
1308 | var platformCompatMapToScore = function platformCompatMapToScore(platformCompatMap, platformScoreMap) {
|
1309 | return Object.keys(platformCompatMap).reduce(function (previous, platformName) {
|
1310 | var platformVersion = platformCompatMap[platformName];
|
1311 | return previous + platformToScore(platformName, platformVersion, platformScoreMap);
|
1312 | }, 0);
|
1313 | };
|
1314 |
|
1315 | var platformToScore = function platformToScore(platformName, platformVersion, platformScoreMap) {
|
1316 | if (platformName in platformScoreMap === false) return platformScoreMap.other || 0;
|
1317 | var versionUsageMap = platformScoreMap[platformName];
|
1318 | var versionArray = Object.keys(versionUsageMap);
|
1319 | if (versionArray.length === 0) return platformScoreMap.other || 0;
|
1320 | var versionArrayAscending = versionArray.sort(versionCompare);
|
1321 | var highestVersion = versionArrayAscending[versionArray.length - 1];
|
1322 | if (findHighestVersion(platformVersion, highestVersion) === platformVersion) return versionUsageMap[highestVersion];
|
1323 | var closestVersion = versionArrayAscending.reverse().find(function (version) {
|
1324 | return findHighestVersion(platformVersion, version) === platformVersion;
|
1325 | });
|
1326 | if (!closestVersion) return platformScoreMap.other || 0;
|
1327 | return versionUsageMap[closestVersion];
|
1328 | };
|
1329 |
|
1330 | var generateGroupMap = function generateGroupMap(_ref) {
|
1331 | var babelPluginMap = _ref.babelPluginMap,
|
1332 | _ref$babelCompatMap = _ref.babelCompatMap,
|
1333 | babelCompatMap$1 = _ref$babelCompatMap === void 0 ? babelCompatMap : _ref$babelCompatMap,
|
1334 | _ref$polyfillConfigMa = _ref.polyfillConfigMap,
|
1335 | polyfillConfigMap = _ref$polyfillConfigMa === void 0 ? {} : _ref$polyfillConfigMa,
|
1336 | _ref$polyfillCompatMa = _ref.polyfillCompatMap,
|
1337 | polyfillCompatMap$1 = _ref$polyfillCompatMa === void 0 ? polyfillCompatMap : _ref$polyfillCompatMa,
|
1338 | platformScoreMap = _ref.platformScoreMap,
|
1339 | _ref$groupCount = _ref.groupCount,
|
1340 | groupCount = _ref$groupCount === void 0 ? 1 : _ref$groupCount,
|
1341 | _ref$platformAlwaysIn = _ref.platformAlwaysInsidePlatformScoreMap,
|
1342 | platformAlwaysInsidePlatformScoreMap = _ref$platformAlwaysIn === void 0 ? false : _ref$platformAlwaysIn,
|
1343 | _ref$platformWillAlwa = _ref.platformWillAlwaysBeKnown,
|
1344 | platformWillAlwaysBeKnown = _ref$platformWillAlwa === void 0 ? false : _ref$platformWillAlwa;
|
1345 | var groupMap = generateFeatureGroupMap({
|
1346 |
|
1347 | featureConfigMap: _objectSpread({}, babelPluginMap, {}, polyfillConfigMap),
|
1348 |
|
1349 | featureCompatMap: _objectSpread({}, babelCompatMap$1, {}, polyfillCompatMap$1),
|
1350 | platformScoreMap: platformScoreMap,
|
1351 | groupCount: groupCount,
|
1352 | platformAlwaysInsidePlatformScoreMap: platformAlwaysInsidePlatformScoreMap,
|
1353 | platformWillAlwaysBeKnown: platformWillAlwaysBeKnown
|
1354 | });
|
1355 | return groupMap;
|
1356 | };
|
1357 |
|
1358 | var generateFeatureGroupMap = function generateFeatureGroupMap(_ref2) {
|
1359 | var featureConfigMap = _ref2.featureConfigMap,
|
1360 | featureCompatMap = _ref2.featureCompatMap,
|
1361 | platformScoreMap = _ref2.platformScoreMap,
|
1362 | groupCount = _ref2.groupCount,
|
1363 | platformAlwaysInsidePlatformScoreMap = _ref2.platformAlwaysInsidePlatformScoreMap,
|
1364 | platformWillAlwaysBeKnown = _ref2.platformWillAlwaysBeKnown;
|
1365 | if (_typeof$1(featureConfigMap) !== "object") throw new TypeError("featureConfigMap must be an object, got ".concat(featureConfigMap));
|
1366 | if (_typeof$1(featureCompatMap) !== "object") throw new TypeError("featureCompatMap must be an object, got ".concat(featureCompatMap));
|
1367 | if (_typeof$1(platformScoreMap) !== "object") throw new TypeError("platformScoreMap must be an object, got ".concat(platformScoreMap));
|
1368 | if (_typeof$1(groupCount) < 1) throw new TypeError("groupCount must be above 1, got ".concat(groupCount));
|
1369 | var featureNameArray = Object.keys(featureConfigMap);
|
1370 | var groupWithoutFeature = {
|
1371 | incompatibleNameArray: featureNameArray,
|
1372 | platformCompatMap: {}
|
1373 | };
|
1374 |
|
1375 |
|
1376 |
|
1377 | if (groupCount === 1 && !platformAlwaysInsidePlatformScoreMap) {
|
1378 | return _defineProperty$1({}, OTHERWISE_ID, groupWithoutFeature);
|
1379 | }
|
1380 |
|
1381 | var featureCompatMapWithoutHole = {};
|
1382 | featureNameArray.forEach(function (featureName) {
|
1383 | featureCompatMapWithoutHole[featureName] = featureName in featureCompatMap ? featureCompatMap[featureName] : {};
|
1384 | });
|
1385 | var allPlatformGroupArray = generateAllPlatformGroupArray({
|
1386 | featureCompatMap: featureCompatMapWithoutHole,
|
1387 | platformNames: arrayWithoutValue(Object.keys(platformScoreMap), "other")
|
1388 | });
|
1389 |
|
1390 | if (allPlatformGroupArray.length === 0) {
|
1391 | return _defineProperty$1({}, OTHERWISE_ID, groupWithoutFeature);
|
1392 | }
|
1393 |
|
1394 | var groupToScore = function groupToScore(_ref5) {
|
1395 | var platformCompatMap = _ref5.platformCompatMap;
|
1396 | return platformCompatMapToScore(platformCompatMap, platformScoreMap);
|
1397 | };
|
1398 |
|
1399 | var allPlatformGroupArraySortedByScore = allPlatformGroupArray.sort(function (a, b) {
|
1400 | return groupToScore(b) - groupToScore(a);
|
1401 | });
|
1402 | var length = allPlatformGroupArraySortedByScore.length;
|
1403 |
|
1404 |
|
1405 |
|
1406 | if (groupCount === 1) {
|
1407 | return _defineProperty$1({}, BEST_ID, allPlatformGroupArraySortedByScore[length - 1]);
|
1408 | }
|
1409 |
|
1410 | var addOtherwiseToBeSafe = !platformAlwaysInsidePlatformScoreMap || !platformWillAlwaysBeKnown;
|
1411 | var lastGroupIndex = addOtherwiseToBeSafe ? groupCount - 1 : groupCount;
|
1412 | var groupArray = length + 1 > groupCount ? allPlatformGroupArraySortedByScore.slice(0, lastGroupIndex) : allPlatformGroupArraySortedByScore;
|
1413 | var groupMap = {};
|
1414 | groupArray.forEach(function (group, index) {
|
1415 | if (index === 0) {
|
1416 | groupMap[BEST_ID] = group;
|
1417 | } else {
|
1418 | groupMap["intermediate-".concat(index + 1)] = group;
|
1419 | }
|
1420 | });
|
1421 |
|
1422 | if (addOtherwiseToBeSafe) {
|
1423 | groupMap[OTHERWISE_ID] = groupWithoutFeature;
|
1424 | }
|
1425 |
|
1426 | return groupMap;
|
1427 | };
|
1428 |
|
1429 | var arrayWithoutValue = function arrayWithoutValue(array, value) {
|
1430 | return array.filter(function (valueCandidate) {
|
1431 | return valueCandidate !== value;
|
1432 | });
|
1433 | };
|
1434 |
|
1435 | var LOG_LEVEL_OFF = "off";
|
1436 | var LOG_LEVEL_ERROR = "error";
|
1437 | var LOG_LEVEL_WARN = "warn";
|
1438 | var LOG_LEVEL_INFO = "info";
|
1439 | var LOG_LEVEL_TRACE = "trace";
|
1440 |
|
1441 | var createLogger = function createLogger() {
|
1442 | var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
1443 | _ref$logLevel = _ref.logLevel,
|
1444 | logLevel = _ref$logLevel === void 0 ? LOG_LEVEL_INFO : _ref$logLevel;
|
1445 |
|
1446 | if (logLevel === LOG_LEVEL_TRACE) {
|
1447 | return {
|
1448 | trace: trace,
|
1449 | info: info,
|
1450 | warn: warn,
|
1451 | error: error
|
1452 | };
|
1453 | }
|
1454 |
|
1455 | if (logLevel === LOG_LEVEL_INFO) {
|
1456 | return {
|
1457 | trace: traceDisabled,
|
1458 | info: info,
|
1459 | warn: warn,
|
1460 | error: error
|
1461 | };
|
1462 | }
|
1463 |
|
1464 | if (logLevel === LOG_LEVEL_WARN) {
|
1465 | return {
|
1466 | trace: traceDisabled,
|
1467 | info: infoDisabled,
|
1468 | warn: warn,
|
1469 | error: error
|
1470 | };
|
1471 | }
|
1472 |
|
1473 | if (logLevel === LOG_LEVEL_ERROR) {
|
1474 | return {
|
1475 | trace: traceDisabled,
|
1476 | info: infoDisabled,
|
1477 | warn: warnDisabled,
|
1478 | error: error
|
1479 | };
|
1480 | }
|
1481 |
|
1482 | if (logLevel === LOG_LEVEL_OFF) {
|
1483 | return {
|
1484 | trace: traceDisabled,
|
1485 | info: infoDisabled,
|
1486 | warn: warnDisabled,
|
1487 | error: errorDisabled
|
1488 | };
|
1489 | }
|
1490 |
|
1491 | throw new Error(createUnexpectedLogLevelMessage({
|
1492 | logLevel: logLevel
|
1493 | }));
|
1494 | };
|
1495 |
|
1496 | var createUnexpectedLogLevelMessage = function createUnexpectedLogLevelMessage(_ref2) {
|
1497 | var logLevel = _ref2.logLevel;
|
1498 | return "unexpected logLevel.\n--- logLevel ---\n".concat(logLevel, "\n--- allowed log levels ---\n").concat(LOG_LEVEL_OFF, "\n").concat(LOG_LEVEL_ERROR, "\n").concat(LOG_LEVEL_WARN, "\n").concat(LOG_LEVEL_INFO, "\n").concat(LOG_LEVEL_TRACE, "\n");
|
1499 | };
|
1500 |
|
1501 | var trace = console.trace;
|
1502 |
|
1503 | var traceDisabled = function traceDisabled() {};
|
1504 |
|
1505 | var info = console.log;
|
1506 |
|
1507 | var infoDisabled = function infoDisabled() {};
|
1508 |
|
1509 | var warn = console.warn;
|
1510 |
|
1511 | var warnDisabled = function warnDisabled() {};
|
1512 |
|
1513 | var error = console.error;
|
1514 |
|
1515 | var errorDisabled = function errorDisabled() {};
|
1516 |
|
1517 | var _require2$2 = nodeRequire("@dmail/server"),
|
1518 | bufferToEtag = _require2$2.bufferToEtag;
|
1519 |
|
1520 | var _require2$3 = nodeRequire("@dmail/server"),
|
1521 | bufferToEtag$1 = _require2$3.bufferToEtag;
|
1522 |
|
1523 | var lockfile = nodeRequire("proper-lockfile");
|
1524 |
|
1525 |
|
1526 | var nodeVersionScoreMap = {
|
1527 | "0.10": 0.02,
|
1528 | "0.12": 0.01,
|
1529 | 4: 0.1,
|
1530 | 6: 0.25,
|
1531 | 7: 0.1,
|
1532 | 8: 1,
|
1533 | 9: 0.1,
|
1534 | 10: 0.5,
|
1535 | 11: 0.25
|
1536 | };
|
1537 |
|
1538 | var assertImportMap = function assertImportMap(value) {
|
1539 | if (value === null) {
|
1540 | throw new TypeError("an importMap must be an object, got null");
|
1541 | }
|
1542 |
|
1543 | var type = _typeof$1(value);
|
1544 |
|
1545 | if (type !== "object") {
|
1546 | throw new TypeError("an importMap must be an object, received ".concat(value));
|
1547 | }
|
1548 |
|
1549 | if (Array.isArray(value)) {
|
1550 | throw new TypeError("an importMap must be an object, received array ".concat(value));
|
1551 | }
|
1552 | };
|
1553 |
|
1554 |
|
1555 | var isWindowsDriveLetter = function isWindowsDriveLetter(specifier) {
|
1556 | var firstChar = specifier[0];
|
1557 | if (!/[a-zA-Z]/.test(firstChar)) return false;
|
1558 | var secondChar = specifier[1];
|
1559 | if (secondChar !== ":") return false;
|
1560 | var thirdChar = specifier[2];
|
1561 | return thirdChar === "/";
|
1562 | };
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 | var isAbsoluteSpecifier = function isAbsoluteSpecifier(specifier) {
|
1568 |
|
1569 |
|
1570 |
|
1571 | if (isWindowsDriveLetter(specifier.slice(0, 3))) return false;
|
1572 | return /^[a-zA-Z]+:/.test(specifier);
|
1573 | };
|
1574 | var resolveAbsoluteSpecifier = function resolveAbsoluteSpecifier(specifier) {
|
1575 | return specifier;
|
1576 | };
|
1577 |
|
1578 | var assertUrlLike = function assertUrlLike(value) {
|
1579 | var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "specifier";
|
1580 |
|
1581 | if (typeof value !== "string") {
|
1582 | throw new TypeError("".concat(name, " must be a string, got ").concat(value));
|
1583 | }
|
1584 |
|
1585 | if (!isAbsoluteSpecifier(value)) {
|
1586 | throw new Error("".concat(name, " must be an url and no scheme found, got ").concat(value));
|
1587 | }
|
1588 | };
|
1589 |
|
1590 | var applyImportMap = function applyImportMap(_ref) {
|
1591 | var importMap = _ref.importMap,
|
1592 | href = _ref.href,
|
1593 | importerHref = _ref.importerHref;
|
1594 | assertImportMap(importMap);
|
1595 | assertUrlLike(href, "href");
|
1596 |
|
1597 | if (importerHref) {
|
1598 | assertUrlLike(importerHref, "importerHref");
|
1599 | }
|
1600 |
|
1601 | var scopes = importMap.scopes;
|
1602 |
|
1603 | if (scopes && importerHref) {
|
1604 | var scopeKeyMatching = Object.keys(scopes).find(function (scopeKey) {
|
1605 | return scopeKey === importerHref || specifierIsPrefixOf(scopeKey, importerHref);
|
1606 | });
|
1607 |
|
1608 | if (scopeKeyMatching) {
|
1609 | var scopeValue = scopes[scopeKeyMatching];
|
1610 | var remappingFromScopeImports = applyImports(href, scopeValue);
|
1611 |
|
1612 | if (remappingFromScopeImports !== null) {
|
1613 | return remappingFromScopeImports;
|
1614 | }
|
1615 | }
|
1616 | }
|
1617 |
|
1618 | var imports = importMap.imports;
|
1619 |
|
1620 | if (imports) {
|
1621 | var remappingFromImports = applyImports(href, imports);
|
1622 |
|
1623 | if (remappingFromImports !== null) {
|
1624 | return remappingFromImports;
|
1625 | }
|
1626 | }
|
1627 |
|
1628 | return href;
|
1629 | };
|
1630 |
|
1631 | var applyImports = function applyImports(href, imports) {
|
1632 | var importKeyArray = Object.keys(imports);
|
1633 | var i = 0;
|
1634 |
|
1635 | while (i < importKeyArray.length) {
|
1636 | var importKey = importKeyArray[i];
|
1637 | i++;
|
1638 |
|
1639 | if (importKey === href) {
|
1640 | var importValue = imports[importKey];
|
1641 | return importValue;
|
1642 | }
|
1643 |
|
1644 | if (specifierIsPrefixOf(importKey, href)) {
|
1645 | var _importValue = imports[importKey];
|
1646 | var afterImportKey = href.slice(importKey.length);
|
1647 | return _importValue + afterImportKey;
|
1648 | }
|
1649 | }
|
1650 |
|
1651 | return null;
|
1652 | };
|
1653 |
|
1654 | var specifierIsPrefixOf = function specifierIsPrefixOf(specifierHref, href) {
|
1655 | return specifierHref[specifierHref.length - 1] === "/" && href.startsWith(specifierHref);
|
1656 | };
|
1657 |
|
1658 | var composeTwoImportMaps = function composeTwoImportMaps(leftImportMap, rightImportMap) {
|
1659 | assertImportMap(leftImportMap);
|
1660 | assertImportMap(rightImportMap);
|
1661 | return {
|
1662 | imports: composeTwoImports(leftImportMap.imports, rightImportMap.imports),
|
1663 | scopes: composeTwoScopes(leftImportMap.scopes, rightImportMap.scopes)
|
1664 | };
|
1665 | };
|
1666 |
|
1667 | var composeTwoImports = function composeTwoImports() {
|
1668 | var leftImports = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
1669 | var rightImports = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1670 | return _objectSpread({}, leftImports, {}, rightImports);
|
1671 | };
|
1672 |
|
1673 | var composeTwoScopes = function composeTwoScopes() {
|
1674 | var leftScopes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
1675 | var rightScopes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1676 |
|
1677 | var scopes = _objectSpread({}, leftScopes);
|
1678 |
|
1679 | Object.keys(rightScopes).forEach(function (scopeKey) {
|
1680 | if (scopes.hasOwnProperty(scopeKey)) {
|
1681 | scopes[scopeKey] = _objectSpread({}, scopes[scopeKey], {}, rightScopes[scopeKey]);
|
1682 | } else {
|
1683 | scopes[scopeKey] = _objectSpread({}, rightScopes[scopeKey]);
|
1684 | }
|
1685 | });
|
1686 | return scopes;
|
1687 | };
|
1688 |
|
1689 | var isSchemeRelativeSpecifier = function isSchemeRelativeSpecifier(specifier) {
|
1690 | return specifier.slice(0, 2) === "//";
|
1691 | };
|
1692 | var resolveSchemeRelativeSpecifier = function resolveSchemeRelativeSpecifier(specifier, importer) {
|
1693 | return "".concat(hrefToScheme(importer), ":").concat(specifier);
|
1694 | };
|
1695 |
|
1696 | var isOriginRelativeSpecifier = function isOriginRelativeSpecifier(specifier) {
|
1697 | var firstChar = specifier[0];
|
1698 | if (firstChar !== "/") return false;
|
1699 | var secondChar = specifier[1];
|
1700 | if (secondChar === "/") return false;
|
1701 | return true;
|
1702 | };
|
1703 | var resolveOriginRelativeSpecifier = function resolveOriginRelativeSpecifier(specifier, importer) {
|
1704 | var importerOrigin = hrefToOrigin(importer);
|
1705 | return "".concat(importerOrigin, "/").concat(specifier.slice(1));
|
1706 | };
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 | var isPathnameRelativeSpecifier = function isPathnameRelativeSpecifier(specifier) {
|
1712 | if (specifier.slice(0, 2) === "./") return true;
|
1713 | if (specifier.slice(0, 3) === "../") return true;
|
1714 | return false;
|
1715 | };
|
1716 | var resolvePathnameRelativeSpecifier = function resolvePathnameRelativeSpecifier(specifier, importer) {
|
1717 | var importerPathname = hrefToPathname(importer);
|
1718 |
|
1719 |
|
1720 |
|
1721 | if (specifier.slice(0, 2) === "./") {
|
1722 | var _importerOrigin = hrefToOrigin(importer);
|
1723 |
|
1724 | var importerDirname = pathnameToDirname(importerPathname);
|
1725 | return "".concat(_importerOrigin).concat(importerDirname, "/").concat(specifier.slice(2));
|
1726 | }
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 | var unresolvedPathname = specifier;
|
1733 | var importerFolders = importerPathname.split("/");
|
1734 | importerFolders.pop();
|
1735 |
|
1736 | while (unresolvedPathname.slice(0, 3) === "../") {
|
1737 |
|
1738 |
|
1739 | if (importerFolders.length) {
|
1740 | importerFolders.pop();
|
1741 | }
|
1742 |
|
1743 | unresolvedPathname = unresolvedPathname.slice(3);
|
1744 | }
|
1745 |
|
1746 | var importerOrigin = hrefToOrigin(importer);
|
1747 | var resolvedPathname = "".concat(importerFolders.join("/"), "/").concat(unresolvedPathname);
|
1748 | return "".concat(importerOrigin).concat(resolvedPathname);
|
1749 | };
|
1750 |
|
1751 | var resolveBareSpecifier = function resolveBareSpecifier(specifier, importer) {
|
1752 | var importerOrigin = hrefToOrigin(importer);
|
1753 | return "".concat(importerOrigin, "/").concat(specifier);
|
1754 | };
|
1755 |
|
1756 |
|
1757 | var resolveSpecifier = function resolveSpecifier(specifier, importer) {
|
1758 | if (isAbsoluteSpecifier(specifier)) {
|
1759 | return resolveAbsoluteSpecifier(specifier);
|
1760 | }
|
1761 |
|
1762 | if (!importer) {
|
1763 | throw new Error(createMissingImporterMessage(specifier, importer));
|
1764 | }
|
1765 |
|
1766 | if (isSchemeRelativeSpecifier(specifier)) {
|
1767 | return resolveSchemeRelativeSpecifier(specifier, importer);
|
1768 | }
|
1769 |
|
1770 | if (isOriginRelativeSpecifier(specifier)) {
|
1771 | return resolveOriginRelativeSpecifier(specifier, importer);
|
1772 | }
|
1773 |
|
1774 | if (isPathnameRelativeSpecifier(specifier)) {
|
1775 | return resolvePathnameRelativeSpecifier(specifier, importer);
|
1776 | }
|
1777 |
|
1778 | return resolveBareSpecifier(specifier, importer);
|
1779 | };
|
1780 |
|
1781 | var createMissingImporterMessage = function createMissingImporterMessage(specifier, importer) {
|
1782 | return "missing importer to resolve relative specifier.\n--- specifier ---\n".concat(specifier, "\n--- importer ---\n").concat(importer);
|
1783 | };
|
1784 |
|
1785 | var normalizeImportMap = function normalizeImportMap(importMap, href) {
|
1786 | assertImportMap(importMap);
|
1787 |
|
1788 | if (typeof href !== "string") {
|
1789 | throw new TypeError("href must be a string, got ".concat(href));
|
1790 | }
|
1791 |
|
1792 | var imports = importMap.imports,
|
1793 | scopes = importMap.scopes;
|
1794 | return {
|
1795 | imports: imports ? normalizeImports(imports, href) : undefined,
|
1796 | scopes: scopes ? normalizeScopes(scopes, href) : undefined
|
1797 | };
|
1798 | };
|
1799 |
|
1800 | var normalizeImports = function normalizeImports(imports, href) {
|
1801 | var importsNormalized = {};
|
1802 | Object.keys(imports).forEach(function (importKey) {
|
1803 | var importValue = imports[importKey];
|
1804 | var importKeyNormalized = resolveSpecifier(importKey, href);
|
1805 | var importValueNormalized = resolveSpecifier(importValue, href);
|
1806 | importsNormalized[importKeyNormalized] = importValueNormalized;
|
1807 | });
|
1808 | return sortImports(importsNormalized);
|
1809 | };
|
1810 |
|
1811 | var normalizeScopes = function normalizeScopes(scopes, href) {
|
1812 | var scopesNormalized = {};
|
1813 | Object.keys(scopes).forEach(function (scopeKey) {
|
1814 | var scopeValue = scopes[scopeKey];
|
1815 | var scopeKeyNormalized = resolveSpecifier(scopeKey, href);
|
1816 | var scopeValueNormalized = normalizeImports(scopeValue, href);
|
1817 | scopesNormalized[scopeKeyNormalized] = scopeValueNormalized;
|
1818 | });
|
1819 | return sortScopes(scopesNormalized);
|
1820 | };
|
1821 |
|
1822 | var sortImports = function sortImports(imports) {
|
1823 | var sortedImports = {};
|
1824 | Object.keys(imports).sort(compareLengthOrLocaleCompare).forEach(function (name) {
|
1825 | sortedImports[name] = imports[name];
|
1826 | });
|
1827 | return sortedImports;
|
1828 | };
|
1829 |
|
1830 | var sortScopes = function sortScopes(scopes) {
|
1831 | var sortedScopes = {};
|
1832 | Object.keys(scopes).sort(compareLengthOrLocaleCompare).forEach(function (scopeName) {
|
1833 | sortedScopes[scopeName] = sortImports(scopes[scopeName]);
|
1834 | });
|
1835 | return sortedScopes;
|
1836 | };
|
1837 |
|
1838 | var compareLengthOrLocaleCompare = function compareLengthOrLocaleCompare(a, b) {
|
1839 | return b.length - a.length || a.localeCompare(b);
|
1840 | };
|
1841 |
|
1842 |
|
1843 | var resolveImport = function resolveImport(_ref) {
|
1844 | var specifier = _ref.specifier,
|
1845 | importer = _ref.importer,
|
1846 | importMap = _ref.importMap,
|
1847 | _ref$defaultExtension = _ref.defaultExtension,
|
1848 | defaultExtension = _ref$defaultExtension === void 0 ? true : _ref$defaultExtension;
|
1849 | var specifierResolved = resolveSpecifier(specifier, importer);
|
1850 | var specifierRemapped = importMap ? applyImportMap({
|
1851 | importMap: importMap,
|
1852 | href: specifierResolved,
|
1853 | importerHref: importer
|
1854 | }) : specifierResolved;
|
1855 |
|
1856 | if (typeof defaultExtension === "string") {
|
1857 | var extension = pathnameToExtension(specifierRemapped);
|
1858 |
|
1859 | if (extension === "") {
|
1860 | return "".concat(specifierRemapped).concat(defaultExtension);
|
1861 | }
|
1862 | }
|
1863 |
|
1864 | if (defaultExtension === true) {
|
1865 | var _extension = pathnameToExtension(specifierRemapped);
|
1866 |
|
1867 | if (_extension === "") {
|
1868 | if (importer) {
|
1869 | var importerPathname = hrefToPathname(importer);
|
1870 | var importerExtension = pathnameToExtension(importerPathname);
|
1871 | return "".concat(specifierRemapped).concat(importerExtension);
|
1872 | }
|
1873 | }
|
1874 | }
|
1875 |
|
1876 | return specifierRemapped;
|
1877 | };
|
1878 |
|
1879 |
|
1880 |
|
1881 | var _require2$4 = nodeRequire("@babel/core"),
|
1882 | template = _require2$4.template,
|
1883 | t = _require2$4.types;
|
1884 |
|
1885 | var _require3$1 = nodeRequire("@babel/helper-plugin-utils"),
|
1886 | declare = _require3$1.declare;
|
1887 |
|
1888 | var _require4 = nodeRequire("@babel/helper-hoist-variables"),
|
1889 | hoistVariables = _require4.default;
|
1890 |
|
1891 | var buildTemplate = template("\n SYSTEM_REGISTER(MODULE_NAME, SOURCES, function (EXPORT_IDENTIFIER, CONTEXT_IDENTIFIER) {\n \"use strict\";\n BEFORE_BODY;\n return {\n setters: SETTERS,\n execute: EXECUTE\n };\n });\n");
|
1892 | var buildExportAll = template("\n for (var KEY in TARGET) {\n if (KEY !== \"default\" && KEY !== \"__esModule\") EXPORT_OBJ[KEY] = TARGET[KEY];\n }\n");
|
1893 |
|
1894 | function constructExportCall(path, exportIdent, exportNames, exportValues, exportStarTarget) {
|
1895 | var statements = [];
|
1896 |
|
1897 | if (exportNames.length === 1) {
|
1898 | statements.push(t.expressionStatement(t.callExpression(exportIdent, [t.stringLiteral(exportNames[0]), exportValues[0]])));
|
1899 | } else if (!exportStarTarget) {
|
1900 | var objectProperties = [];
|
1901 |
|
1902 | for (var i = 0; i < exportNames.length; i++) {
|
1903 | var exportName = exportNames[i];
|
1904 | var exportValue = exportValues[i];
|
1905 | objectProperties.push(t.objectProperty(t.identifier(exportName), exportValue));
|
1906 | }
|
1907 |
|
1908 | statements.push(t.expressionStatement(t.callExpression(exportIdent, [t.objectExpression(objectProperties)])));
|
1909 | } else {
|
1910 | var exportObj = path.scope.generateUid("exportObj");
|
1911 | statements.push(t.variableDeclaration("var", [t.variableDeclarator(t.identifier(exportObj), t.objectExpression([]))]));
|
1912 | statements.push(buildExportAll({
|
1913 | KEY: path.scope.generateUidIdentifier("key"),
|
1914 | EXPORT_OBJ: t.identifier(exportObj),
|
1915 | TARGET: exportStarTarget
|
1916 | }));
|
1917 |
|
1918 | for (var _i = 0; _i < exportNames.length; _i++) {
|
1919 | var _exportName = exportNames[_i];
|
1920 | var _exportValue = exportValues[_i];
|
1921 | statements.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier(exportObj), t.identifier(_exportName)), _exportValue)));
|
1922 | }
|
1923 |
|
1924 | statements.push(t.expressionStatement(t.callExpression(exportIdent, [t.identifier(exportObj)])));
|
1925 | }
|
1926 |
|
1927 | return statements;
|
1928 | }
|
1929 |
|
1930 | var TYPE_IMPORT = "Import";
|
1931 | declare(function (api, options) {
|
1932 | api.assertVersion(7);
|
1933 | var _options$systemGlobal = options.systemGlobal,
|
1934 | systemGlobal = _options$systemGlobal === void 0 ? "System" : _options$systemGlobal;
|
1935 | var IGNORE_REASSIGNMENT_SYMBOL = Symbol();
|
1936 | var reassignmentVisitor = {
|
1937 | "AssignmentExpression|UpdateExpression": function AssignmentExpressionUpdateExpression(path) {
|
1938 | if (path.node[IGNORE_REASSIGNMENT_SYMBOL]) return;
|
1939 | path.node[IGNORE_REASSIGNMENT_SYMBOL] = true;
|
1940 | var arg = path.get(path.isAssignmentExpression() ? "left" : "argument");
|
1941 |
|
1942 | if (arg.isObjectPattern() || arg.isArrayPattern()) {
|
1943 | var exprs = [path.node];
|
1944 |
|
1945 | for (var _i2 = 0, _Object$keys = Object.keys(arg.getBindingIdentifiers()); _i2 < _Object$keys.length; _i2++) {
|
1946 | var _name = _Object$keys[_i2];
|
1947 |
|
1948 | if (this.scope.getBinding(_name) !== path.scope.getBinding(_name)) {
|
1949 | return;
|
1950 | }
|
1951 |
|
1952 | var _exportedNames = this.exports[_name];
|
1953 | if (!_exportedNames) return;
|
1954 | var _iteratorNormalCompletion = true;
|
1955 | var _didIteratorError = false;
|
1956 | var _iteratorError = undefined;
|
1957 |
|
1958 | try {
|
1959 | for (var _iterator = _exportedNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
1960 | var _exportedName = _step.value;
|
1961 | exprs.push(this.buildCall(_exportedName, t.identifier(_name)).expression);
|
1962 | }
|
1963 | } catch (err) {
|
1964 | _didIteratorError = true;
|
1965 | _iteratorError = err;
|
1966 | } finally {
|
1967 | try {
|
1968 | if (!_iteratorNormalCompletion && _iterator.return != null) {
|
1969 | _iterator.return();
|
1970 | }
|
1971 | } finally {
|
1972 | if (_didIteratorError) {
|
1973 | throw _iteratorError;
|
1974 | }
|
1975 | }
|
1976 | }
|
1977 | }
|
1978 |
|
1979 | path.replaceWith(t.sequenceExpression(exprs));
|
1980 | return;
|
1981 | }
|
1982 |
|
1983 | if (!arg.isIdentifier()) return;
|
1984 | var name = arg.node.name;
|
1985 |
|
1986 | if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;
|
1987 | var exportedNames = this.exports[name];
|
1988 | if (!exportedNames) return;
|
1989 | var node = path.node;
|
1990 |
|
1991 |
|
1992 |
|
1993 | var isPostUpdateExpression = path.isUpdateExpression({
|
1994 | prefix: false
|
1995 | });
|
1996 |
|
1997 | if (isPostUpdateExpression) {
|
1998 | node = t.binaryExpression(node.operator[0], t.unaryExpression("+", t.cloneNode(node.argument)), t.numericLiteral(1));
|
1999 | }
|
2000 |
|
2001 | var _iteratorNormalCompletion2 = true;
|
2002 | var _didIteratorError2 = false;
|
2003 | var _iteratorError2 = undefined;
|
2004 |
|
2005 | try {
|
2006 | for (var _iterator2 = exportedNames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
2007 | var _exportedName3 = _step2.value;
|
2008 | node = this.buildCall(_exportedName3, node).expression;
|
2009 | }
|
2010 | } catch (err) {
|
2011 | _didIteratorError2 = true;
|
2012 | _iteratorError2 = err;
|
2013 | } finally {
|
2014 | try {
|
2015 | if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
2016 | _iterator2.return();
|
2017 | }
|
2018 | } finally {
|
2019 | if (_didIteratorError2) {
|
2020 | throw _iteratorError2;
|
2021 | }
|
2022 | }
|
2023 | }
|
2024 |
|
2025 | if (isPostUpdateExpression) {
|
2026 | node = t.sequenceExpression([node, path.node]);
|
2027 | }
|
2028 |
|
2029 | path.replaceWith(node);
|
2030 | }
|
2031 | };
|
2032 | return {
|
2033 | name: "transform-modules-systemjs",
|
2034 | visitor: {
|
2035 | CallExpression: function CallExpression(path, state) {
|
2036 | if (path.node.callee.type === TYPE_IMPORT) {
|
2037 | path.replaceWith(t.callExpression(t.memberExpression(t.identifier(state.contextIdent), t.identifier("import")), path.node.arguments));
|
2038 | }
|
2039 | },
|
2040 | MetaProperty: function MetaProperty(path, state) {
|
2041 | if (path.node.meta.name === "import" && path.node.property.name === "meta") {
|
2042 | path.replaceWith(t.memberExpression(t.identifier(state.contextIdent), t.identifier("meta")));
|
2043 | }
|
2044 | },
|
2045 | ReferencedIdentifier: function ReferencedIdentifier(path, state) {
|
2046 | if (path.node.name === "__moduleName" && !path.scope.hasBinding("__moduleName")) {
|
2047 | path.replaceWith(t.memberExpression(t.identifier(state.contextIdent), t.identifier("id")));
|
2048 | }
|
2049 | },
|
2050 | Program: {
|
2051 | enter: function enter(path, state) {
|
2052 | state.contextIdent = path.scope.generateUid("context");
|
2053 | },
|
2054 | exit: function exit(path, state) {
|
2055 | var undefinedIdent = path.scope.buildUndefinedNode();
|
2056 | var exportIdent = path.scope.generateUid("export");
|
2057 | var contextIdent = state.contextIdent;
|
2058 | var exportMap = Object.create(null);
|
2059 | var modules = [];
|
2060 | var beforeBody = [];
|
2061 | var setters = [];
|
2062 | var sources = [];
|
2063 | var variableIds = [];
|
2064 | var removedPaths = [];
|
2065 |
|
2066 | function addExportName(key, val) {
|
2067 | exportMap[key] = exportMap[key] || [];
|
2068 | exportMap[key].push(val);
|
2069 | }
|
2070 |
|
2071 | function pushModule(source, key, specifiers) {
|
2072 | var module;
|
2073 | modules.forEach(function (m) {
|
2074 | if (m.key === source) {
|
2075 | module = m;
|
2076 | }
|
2077 | });
|
2078 |
|
2079 | if (!module) {
|
2080 | modules.push(module = {
|
2081 | key: source,
|
2082 | imports: [],
|
2083 | exports: []
|
2084 | });
|
2085 | }
|
2086 |
|
2087 | module[key] = module[key].concat(specifiers);
|
2088 | }
|
2089 |
|
2090 | function buildExportCall(name, val) {
|
2091 | return t.expressionStatement(t.callExpression(t.identifier(exportIdent), [t.stringLiteral(name), val]));
|
2092 | }
|
2093 |
|
2094 | var exportNames = [];
|
2095 | var exportValues = [];
|
2096 | var body = path.get("body");
|
2097 | var _iteratorNormalCompletion3 = true;
|
2098 | var _didIteratorError3 = false;
|
2099 | var _iteratorError3 = undefined;
|
2100 |
|
2101 | try {
|
2102 | for (var _iterator3 = body[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
2103 | var _path3 = _step3.value;
|
2104 |
|
2105 | if (_path3.isFunctionDeclaration()) {
|
2106 | beforeBody.push(_path3.node);
|
2107 | removedPaths.push(_path3);
|
2108 | } else if (_path3.isClassDeclaration()) {
|
2109 | variableIds.push(_path3.node.id);
|
2110 |
|
2111 | _path3.replaceWith(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(_path3.node.id), t.toExpression(_path3.node))));
|
2112 | } else if (_path3.isImportDeclaration()) {
|
2113 | var source = _path3.node.source.value;
|
2114 | pushModule(source, "imports", _path3.node.specifiers);
|
2115 |
|
2116 | for (var _i4 = 0, _Object$keys2 = Object.keys(_path3.getBindingIdentifiers()); _i4 < _Object$keys2.length; _i4++) {
|
2117 | var name = _Object$keys2[_i4];
|
2118 |
|
2119 | _path3.scope.removeBinding(name);
|
2120 |
|
2121 | variableIds.push(t.identifier(name));
|
2122 | }
|
2123 |
|
2124 | _path3.remove();
|
2125 | } else if (_path3.isExportAllDeclaration()) {
|
2126 | pushModule(_path3.node.source.value, "exports", _path3.node);
|
2127 |
|
2128 | _path3.remove();
|
2129 | } else if (_path3.isExportDefaultDeclaration()) {
|
2130 | var declar = _path3.get("declaration");
|
2131 |
|
2132 | var id = declar.node.id;
|
2133 |
|
2134 | if (declar.isClassDeclaration()) {
|
2135 | if (id) {
|
2136 | exportNames.push("default");
|
2137 | exportValues.push(undefinedIdent);
|
2138 | variableIds.push(id);
|
2139 | addExportName(id.name, "default");
|
2140 |
|
2141 | _path3.replaceWith(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(id), t.toExpression(declar.node))));
|
2142 | } else {
|
2143 | exportNames.push("default");
|
2144 | exportValues.push(t.toExpression(declar.node));
|
2145 | removedPaths.push(_path3);
|
2146 | }
|
2147 | } else if (declar.isFunctionDeclaration()) {
|
2148 | if (id) {
|
2149 | beforeBody.push(declar.node);
|
2150 | exportNames.push("default");
|
2151 | exportValues.push(t.cloneNode(id));
|
2152 | addExportName(id.name, "default");
|
2153 | } else {
|
2154 | exportNames.push("default");
|
2155 | exportValues.push(t.toExpression(declar.node));
|
2156 | }
|
2157 |
|
2158 | removedPaths.push(_path3);
|
2159 | } else {
|
2160 | _path3.replaceWith(buildExportCall("default", declar.node));
|
2161 | }
|
2162 | } else if (_path3.isExportNamedDeclaration()) {
|
2163 | var _declar = _path3.get("declaration");
|
2164 |
|
2165 | if (_declar.node) {
|
2166 | _path3.replaceWith(_declar);
|
2167 |
|
2168 | if (_path3.isFunction()) {
|
2169 | var node = _declar.node;
|
2170 | var _name2 = node.id.name;
|
2171 | addExportName(_name2, _name2);
|
2172 | beforeBody.push(node);
|
2173 | exportNames.push(_name2);
|
2174 | exportValues.push(t.cloneNode(node.id));
|
2175 | removedPaths.push(_path3);
|
2176 | } else if (_path3.isClass()) {
|
2177 | var _name3 = _declar.node.id.name;
|
2178 | exportNames.push(_name3);
|
2179 | exportValues.push(undefinedIdent);
|
2180 | variableIds.push(_declar.node.id);
|
2181 |
|
2182 | _path3.replaceWith(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(_declar.node.id), t.toExpression(_declar.node))));
|
2183 |
|
2184 | addExportName(_name3, _name3);
|
2185 | } else {
|
2186 | for (var _i5 = 0, _Object$keys3 = Object.keys(_declar.getBindingIdentifiers()); _i5 < _Object$keys3.length; _i5++) {
|
2187 | var _name4 = _Object$keys3[_i5];
|
2188 | addExportName(_name4, _name4);
|
2189 | }
|
2190 | }
|
2191 | } else {
|
2192 | var specifiers = _path3.node.specifiers;
|
2193 |
|
2194 | if (specifiers && specifiers.length) {
|
2195 | if (_path3.node.source) {
|
2196 | pushModule(_path3.node.source.value, "exports", specifiers);
|
2197 |
|
2198 | _path3.remove();
|
2199 | } else {
|
2200 | var nodes = [];
|
2201 | var _iteratorNormalCompletion6 = true;
|
2202 | var _didIteratorError6 = false;
|
2203 | var _iteratorError6 = undefined;
|
2204 |
|
2205 | try {
|
2206 | for (var _iterator6 = specifiers[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
2207 | var _specifier2 = _step6.value;
|
2208 |
|
2209 | var binding = _path3.scope.getBinding(_specifier2.local.name);
|
2210 |
|
2211 |
|
2212 | if (binding && t.isFunctionDeclaration(binding.path.node)) {
|
2213 | exportNames.push(_specifier2.exported.name);
|
2214 | exportValues.push(t.cloneNode(_specifier2.local));
|
2215 | }
|
2216 | else if (!binding) {
|
2217 | nodes.push(buildExportCall(_specifier2.exported.name, _specifier2.local));
|
2218 | }
|
2219 |
|
2220 | addExportName(_specifier2.local.name, _specifier2.exported.name);
|
2221 | }
|
2222 | } catch (err) {
|
2223 | _didIteratorError6 = true;
|
2224 | _iteratorError6 = err;
|
2225 | } finally {
|
2226 | try {
|
2227 | if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
|
2228 | _iterator6.return();
|
2229 | }
|
2230 | } finally {
|
2231 | if (_didIteratorError6) {
|
2232 | throw _iteratorError6;
|
2233 | }
|
2234 | }
|
2235 | }
|
2236 |
|
2237 | _path3.replaceWithMultiple(nodes);
|
2238 | }
|
2239 | }
|
2240 | }
|
2241 | }
|
2242 | }
|
2243 | } catch (err) {
|
2244 | _didIteratorError3 = true;
|
2245 | _iteratorError3 = err;
|
2246 | } finally {
|
2247 | try {
|
2248 | if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
2249 | _iterator3.return();
|
2250 | }
|
2251 | } finally {
|
2252 | if (_didIteratorError3) {
|
2253 | throw _iteratorError3;
|
2254 | }
|
2255 | }
|
2256 | }
|
2257 |
|
2258 | modules.forEach(function (specifiers) {
|
2259 | var setterBody = [];
|
2260 | var target = path.scope.generateUid(specifiers.key);
|
2261 | var _iteratorNormalCompletion4 = true;
|
2262 | var _didIteratorError4 = false;
|
2263 | var _iteratorError4 = undefined;
|
2264 |
|
2265 | try {
|
2266 | for (var _iterator4 = specifiers.imports[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
2267 | var _specifier = _step4.value;
|
2268 |
|
2269 | if (t.isImportNamespaceSpecifier(_specifier)) {
|
2270 | setterBody.push(t.expressionStatement(t.assignmentExpression("=", _specifier.local, t.identifier(target))));
|
2271 | } else if (t.isImportDefaultSpecifier(_specifier)) {
|
2272 | _specifier = t.importSpecifier(_specifier.local, t.identifier("default"));
|
2273 | }
|
2274 |
|
2275 | if (t.isImportSpecifier(_specifier)) {
|
2276 | setterBody.push(t.expressionStatement(t.assignmentExpression("=", _specifier.local, t.memberExpression(t.identifier(target), _specifier.imported))));
|
2277 | }
|
2278 | }
|
2279 | } catch (err) {
|
2280 | _didIteratorError4 = true;
|
2281 | _iteratorError4 = err;
|
2282 | } finally {
|
2283 | try {
|
2284 | if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
2285 | _iterator4.return();
|
2286 | }
|
2287 | } finally {
|
2288 | if (_didIteratorError4) {
|
2289 | throw _iteratorError4;
|
2290 | }
|
2291 | }
|
2292 | }
|
2293 |
|
2294 | if (specifiers.exports.length) {
|
2295 | var _exportNames = [];
|
2296 | var _exportValues = [];
|
2297 | var hasExportStar = false;
|
2298 | var _iteratorNormalCompletion5 = true;
|
2299 | var _didIteratorError5 = false;
|
2300 | var _iteratorError5 = undefined;
|
2301 |
|
2302 | try {
|
2303 | for (var _iterator5 = specifiers.exports[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
2304 | var _node = _step5.value;
|
2305 |
|
2306 | if (t.isExportAllDeclaration(_node)) {
|
2307 | hasExportStar = true;
|
2308 | } else if (t.isExportSpecifier(_node)) {
|
2309 | _exportNames.push(_node.exported.name);
|
2310 |
|
2311 | _exportValues.push(t.memberExpression(t.identifier(target), _node.local));
|
2312 | } else {
|
2313 | }
|
2314 | }
|
2315 | } catch (err) {
|
2316 | _didIteratorError5 = true;
|
2317 | _iteratorError5 = err;
|
2318 | } finally {
|
2319 | try {
|
2320 | if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
|
2321 | _iterator5.return();
|
2322 | }
|
2323 | } finally {
|
2324 | if (_didIteratorError5) {
|
2325 | throw _iteratorError5;
|
2326 | }
|
2327 | }
|
2328 | }
|
2329 |
|
2330 | setterBody = setterBody.concat(constructExportCall(path, t.identifier(exportIdent), _exportNames, _exportValues, hasExportStar ? t.identifier(target) : null));
|
2331 | }
|
2332 |
|
2333 | sources.push(t.stringLiteral(specifiers.key));
|
2334 | setters.push(t.functionExpression(null, [t.identifier(target)], t.blockStatement(setterBody)));
|
2335 | });
|
2336 | var moduleName = this.getModuleName();
|
2337 | if (moduleName) moduleName = t.stringLiteral(moduleName);
|
2338 | hoistVariables(path, function (id, name, hasInit) {
|
2339 | variableIds.push(id);
|
2340 |
|
2341 | if (!hasInit) {
|
2342 | exportNames.push(name);
|
2343 | exportValues.push(undefinedIdent);
|
2344 | }
|
2345 | }, null);
|
2346 |
|
2347 | if (variableIds.length) {
|
2348 | beforeBody.unshift(t.variableDeclaration("var", variableIds.map(function (id) {
|
2349 | return t.variableDeclarator(id);
|
2350 | })));
|
2351 | }
|
2352 |
|
2353 | if (exportNames.length) {
|
2354 | beforeBody = beforeBody.concat(constructExportCall(path, t.identifier(exportIdent), exportNames, exportValues, null));
|
2355 | }
|
2356 |
|
2357 | path.traverse(reassignmentVisitor, {
|
2358 | exports: exportMap,
|
2359 | buildCall: buildExportCall,
|
2360 | scope: path.scope
|
2361 | });
|
2362 |
|
2363 | for (var _i3 = 0, _removedPaths = removedPaths; _i3 < _removedPaths.length; _i3++) {
|
2364 | var _path2 = _removedPaths[_i3];
|
2365 |
|
2366 | _path2.remove();
|
2367 | }
|
2368 |
|
2369 | path.node.body = [buildTemplate({
|
2370 | SYSTEM_REGISTER: t.memberExpression(t.identifier(systemGlobal), t.identifier("register")),
|
2371 | BEFORE_BODY: beforeBody,
|
2372 | MODULE_NAME: moduleName,
|
2373 | SETTERS: t.arrayExpression(setters),
|
2374 | SOURCES: t.arrayExpression(sources),
|
2375 | EXECUTE: t.functionExpression(null, [], t.blockStatement(path.node.body), false, options.topLevelAwait && programUsesTopLevelAwait(path)),
|
2376 | EXPORT_IDENTIFIER: t.identifier(exportIdent),
|
2377 | CONTEXT_IDENTIFIER: t.identifier(contextIdent)
|
2378 | })];
|
2379 | }
|
2380 | }
|
2381 | }
|
2382 | };
|
2383 | });
|
2384 |
|
2385 | var programUsesTopLevelAwait = function programUsesTopLevelAwait(path) {
|
2386 | var hasTopLevelAwait = false;
|
2387 | path.traverse({
|
2388 | AwaitExpression: function AwaitExpression(path) {
|
2389 | var parent = path.getFunctionParent();
|
2390 | if (!parent || parent.type === "Program") hasTopLevelAwait = true;
|
2391 | }
|
2392 | });
|
2393 | return hasTopLevelAwait;
|
2394 | };
|
2395 |
|
2396 |
|
2397 |
|
2398 | var Convert = nodeRequire("ansi-to-html");
|
2399 |
|
2400 | var _require2$5 = nodeRequire("@babel/helper-module-imports"),
|
2401 | addSideEffect = _require2$5.addSideEffect;
|
2402 |
|
2403 | var _require2$6 = nodeRequire("@babel/helper-module-imports"),
|
2404 | addSideEffect$1 = _require2$6.addSideEffect;
|
2405 |
|
2406 | var _require2$7 = nodeRequire("@babel/helper-module-imports"),
|
2407 | addDefault = _require2$7.addDefault;
|
2408 |
|
2409 | var _require2$8 = nodeRequire("@babel/core"),
|
2410 | transformAsync = _require2$8.transformAsync,
|
2411 | transformFromAstAsync = _require2$8.transformFromAstAsync;
|
2412 |
|
2413 | var syntaxDynamicImport = nodeRequire("@babel/plugin-syntax-dynamic-import");
|
2414 |
|
2415 | var syntaxImportMeta = nodeRequire("@babel/plugin-syntax-import-meta");
|
2416 |
|
2417 |
|
2418 | var arrayWithoutHoles$1 = (function (arr) {
|
2419 | if (Array.isArray(arr)) {
|
2420 | var i = 0;
|
2421 | var arr2 = new Array(arr.length);
|
2422 |
|
2423 | for (; i < arr.length; i++) {
|
2424 | arr2[i] = arr[i];
|
2425 | }
|
2426 |
|
2427 | return arr2;
|
2428 | }
|
2429 | });
|
2430 |
|
2431 |
|
2432 | var iterableToArray$1 = (function (iter) {
|
2433 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
2434 | });
|
2435 |
|
2436 | var nonIterableSpread$1 = (function () {
|
2437 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
2438 | });
|
2439 |
|
2440 | var _toConsumableArray$1 = (function (arr) {
|
2441 | return arrayWithoutHoles$1(arr) || iterableToArray$1(arr) || nonIterableSpread$1();
|
2442 | });
|
2443 |
|
2444 |
|
2445 |
|
2446 | var arrayWithout = function arrayWithout(array, item) {
|
2447 | var arrayWithoutItem = [];
|
2448 | var i = 0;
|
2449 |
|
2450 | while (i < array.length) {
|
2451 | var value = array[i];
|
2452 | i++;
|
2453 |
|
2454 | if (value === item) {
|
2455 | continue;
|
2456 | }
|
2457 |
|
2458 | arrayWithoutItem.push(value);
|
2459 | }
|
2460 |
|
2461 | return arrayWithoutItem;
|
2462 | };
|
2463 |
|
2464 | var createCancelError = function createCancelError(reason) {
|
2465 | var cancelError = new Error("canceled because ".concat(reason));
|
2466 | cancelError.name = "CANCEL_ERROR";
|
2467 | cancelError.reason = reason;
|
2468 | return cancelError;
|
2469 | };
|
2470 | var isCancelError = function isCancelError(value) {
|
2471 | return value && _typeof(value) === "object" && value.name === "CANCEL_ERROR";
|
2472 | };
|
2473 | var createCancellationSource = function createCancellationSource() {
|
2474 | var requested = false;
|
2475 | var cancelError;
|
2476 | var registrationArray = [];
|
2477 |
|
2478 | var cancel = function cancel(reason) {
|
2479 | if (requested) return;
|
2480 | requested = true;
|
2481 | cancelError = createCancelError(reason);
|
2482 | var registrationArrayCopy = registrationArray.slice();
|
2483 | registrationArray.length = 0;
|
2484 | registrationArrayCopy.forEach(function (registration) {
|
2485 | registration.callback(cancelError);
|
2486 | });
|
2487 | };
|
2488 |
|
2489 | var register = function register(callback) {
|
2490 | if (typeof callback !== "function") {
|
2491 | throw new Error("callback must be a function, got ".concat(callback));
|
2492 | }
|
2493 |
|
2494 | var existingRegistration = registrationArray.find(function (registration) {
|
2495 | return registration.callback === callback;
|
2496 | });
|
2497 |
|
2498 | if (existingRegistration) {
|
2499 | return existingRegistration;
|
2500 | }
|
2501 |
|
2502 | var registration = {
|
2503 | callback: callback,
|
2504 | unregister: function unregister() {
|
2505 | registrationArray = arrayWithout(registrationArray, registration);
|
2506 | }
|
2507 | };
|
2508 | registrationArray = [registration].concat(_toConsumableArray$1(registrationArray));
|
2509 | return registration;
|
2510 | };
|
2511 |
|
2512 | var throwIfRequested = function throwIfRequested() {
|
2513 | if (requested) {
|
2514 | throw cancelError;
|
2515 | }
|
2516 | };
|
2517 |
|
2518 | return {
|
2519 | token: {
|
2520 | register: register,
|
2521 |
|
2522 | get cancellationRequested() {
|
2523 | return requested;
|
2524 | },
|
2525 |
|
2526 | throwIfRequested: throwIfRequested
|
2527 | },
|
2528 | cancel: cancel
|
2529 | };
|
2530 | };
|
2531 | var createCancellationToken = function createCancellationToken() {
|
2532 | var register = function register(callback) {
|
2533 | if (typeof callback !== "function") {
|
2534 | throw new Error("callback must be a function, got ".concat(callback));
|
2535 | }
|
2536 |
|
2537 | return {
|
2538 | callback: callback,
|
2539 | unregister: function unregister() {}
|
2540 | };
|
2541 | };
|
2542 |
|
2543 | var throwIfRequested = function throwIfRequested() {
|
2544 | return undefined;
|
2545 | };
|
2546 |
|
2547 | return {
|
2548 | register: register,
|
2549 | cancellationRequested: false,
|
2550 | throwIfRequested: throwIfRequested
|
2551 | };
|
2552 | };
|
2553 |
|
2554 | var objectWithoutPropertiesLoose = (function (source, excluded) {
|
2555 | if (source === null) return {};
|
2556 | var target = {};
|
2557 | var sourceKeys = Object.keys(source);
|
2558 | var key;
|
2559 | var i;
|
2560 |
|
2561 | for (i = 0; i < sourceKeys.length; i++) {
|
2562 | key = sourceKeys[i];
|
2563 | if (excluded.indexOf(key) >= 0) continue;
|
2564 | target[key] = source[key];
|
2565 | }
|
2566 |
|
2567 | return target;
|
2568 | });
|
2569 |
|
2570 | var _objectWithoutProperties = (function (source, excluded) {
|
2571 | if (source === null) return {};
|
2572 | var target = objectWithoutPropertiesLoose(source, excluded);
|
2573 | var key;
|
2574 | var i;
|
2575 |
|
2576 | if (Object.getOwnPropertySymbols) {
|
2577 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
2578 |
|
2579 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
2580 | key = sourceSymbolKeys[i];
|
2581 | if (excluded.indexOf(key) >= 0) continue;
|
2582 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
2583 | target[key] = source[key];
|
2584 | }
|
2585 | }
|
2586 |
|
2587 | return target;
|
2588 | });
|
2589 |
|
2590 | var createOperation = function createOperation(_ref) {
|
2591 | var _ref$cancellationToke = _ref.cancellationToken,
|
2592 | cancellationToken = _ref$cancellationToke === void 0 ? createCancellationToken() : _ref$cancellationToke,
|
2593 | start = _ref.start,
|
2594 | rest = _objectWithoutProperties(_ref, ["cancellationToken", "start"]);
|
2595 |
|
2596 | ensureExactParameters(rest);
|
2597 | cancellationToken.throwIfRequested();
|
2598 | var promise = new Promise(function (resolve) {
|
2599 | resolve(start());
|
2600 | });
|
2601 | var cancelPromise = new Promise(function (resolve, reject) {
|
2602 | var cancelRegistration = cancellationToken.register(function (cancelError) {
|
2603 | cancelRegistration.unregister();
|
2604 | reject(cancelError);
|
2605 | });
|
2606 | promise.then(cancelRegistration.unregister, function () {});
|
2607 | });
|
2608 | var operationPromise = Promise.race([promise, cancelPromise]);
|
2609 | return operationPromise;
|
2610 | };
|
2611 |
|
2612 | var ensureExactParameters = function ensureExactParameters(extraParameters) {
|
2613 | var extraParamNames = Object.keys(extraParameters);
|
2614 | if (extraParamNames.length) throw new Error("createOperation expect only cancellationToken, start. Got ".concat(extraParamNames));
|
2615 | };
|
2616 |
|
2617 | var catchAsyncFunctionCancellation = function catchAsyncFunctionCancellation(asyncFunction) {
|
2618 | return asyncFunction().catch(function (error) {
|
2619 | if (isCancelError(error)) return;
|
2620 | throw error;
|
2621 | });
|
2622 | };
|
2623 | var createProcessInterruptionCancellationToken = function createProcessInterruptionCancellationToken() {
|
2624 | var SIGINTCancelSource = createCancellationSource();
|
2625 | process.on("SIGINT", function () {
|
2626 | return SIGINTCancelSource.cancel("process interruption");
|
2627 | });
|
2628 | return SIGINTCancelSource.token;
|
2629 | };
|
2630 |
|
2631 | var jsenvBundlingProjectPath;
|
2632 |
|
2633 | if (typeof __filename === "string") {
|
2634 | jsenvBundlingProjectPath = path.resolve(__filename, "../../../");
|
2635 | } else {
|
2636 | var selfPathname$1 = hrefToPathname(url);
|
2637 | var selfPath$1 = pathnameToOperatingSystemPath(selfPathname$1);
|
2638 | jsenvBundlingProjectPath = path.resolve(selfPath$1, "../../");
|
2639 | }
|
2640 | var jsenvBundlingProjectPathname = operatingSystemPathToPathname(jsenvBundlingProjectPath);
|
2641 | var jsenvBundlingRelativePathInception = function jsenvBundlingRelativePathInception(_ref) {
|
2642 | var jsenvBundlingRelativePath = _ref.jsenvBundlingRelativePath,
|
2643 | projectPathname = _ref.projectPathname;
|
2644 | var jsenvPathname = "".concat(jsenvBundlingProjectPathname).concat(jsenvBundlingRelativePath);
|
2645 | var relativePath = pathnameToRelativePath(jsenvPathname, projectPathname);
|
2646 | return relativePath;
|
2647 | };
|
2648 |
|
2649 | function _await$4(value, then, direct) {
|
2650 | if (direct) {
|
2651 | return then ? then(value) : value;
|
2652 | }
|
2653 |
|
2654 | if (!value || !value.then) {
|
2655 | value = Promise.resolve(value);
|
2656 | }
|
2657 |
|
2658 | return then ? value.then(then) : value;
|
2659 | }
|
2660 |
|
2661 | function _async$4(f) {
|
2662 | return function () {
|
2663 | for (var args = [], i = 0; i < arguments.length; i++) {
|
2664 | args[i] = arguments[i];
|
2665 | }
|
2666 |
|
2667 | try {
|
2668 | return Promise.resolve(f.apply(this, args));
|
2669 | } catch (e) {
|
2670 | return Promise.reject(e);
|
2671 | }
|
2672 | };
|
2673 | }
|
2674 |
|
2675 | var assertFolder = _async$4(function (path) {
|
2676 | return _await$4(pathToFilesystemEntry(path), function (filesystemEntry) {
|
2677 | if (!filesystemEntry) {
|
2678 | throw new Error("folder not found on filesystem.\npath: ".concat(path));
|
2679 | }
|
2680 |
|
2681 | var type = filesystemEntry.type;
|
2682 |
|
2683 | if (type !== "folder") {
|
2684 | throw new Error("folder expected but found something else on filesystem.\npath: ".concat(path, "\nfound: ").concat(type));
|
2685 | }
|
2686 | });
|
2687 | });
|
2688 | var assertFile = _async$4(function (path) {
|
2689 | return _await$4(pathToFilesystemEntry(path), function (filesystemEntry) {
|
2690 | if (!filesystemEntry) {
|
2691 | throw new Error("file not found on filesystem.\npath: ".concat(path));
|
2692 | }
|
2693 |
|
2694 | var type = filesystemEntry.type;
|
2695 |
|
2696 | if (type !== "file") {
|
2697 | throw new Error("file expected but found something else on filesystem.\npath: ".concat(path, "\nfound: ").concat(type));
|
2698 | }
|
2699 | });
|
2700 | });
|
2701 |
|
2702 | var pathToFilesystemEntry = function pathToFilesystemEntry(path) {
|
2703 | return new Promise(function (resolve, reject) {
|
2704 | fs.stat(path, function (error, stats) {
|
2705 | if (error) {
|
2706 | if (error.code === "ENOENT") resolve(null);else reject(error);
|
2707 | } else {
|
2708 | resolve({
|
2709 | type: statsToEntry(stats),
|
2710 | stats: stats
|
2711 | });
|
2712 | }
|
2713 | });
|
2714 | });
|
2715 | };
|
2716 |
|
2717 | var statsToEntry = function statsToEntry(stats) {
|
2718 | if (stats.isFile()) {
|
2719 | return "file";
|
2720 | }
|
2721 |
|
2722 | if (stats.isDirectory()) {
|
2723 | return "folder";
|
2724 | }
|
2725 |
|
2726 | return "other";
|
2727 | };
|
2728 |
|
2729 | var assertImportMap$1 = function assertImportMap(value) {
|
2730 | if (value === null) {
|
2731 | throw new TypeError("an importMap must be an object, got null");
|
2732 | }
|
2733 |
|
2734 | var type = _typeof$1(value);
|
2735 |
|
2736 | if (type !== "object") {
|
2737 | throw new TypeError("an importMap must be an object, received ".concat(value));
|
2738 | }
|
2739 |
|
2740 | if (Array.isArray(value)) {
|
2741 | throw new TypeError("an importMap must be an object, received array ".concat(value));
|
2742 | }
|
2743 | };
|
2744 |
|
2745 |
|
2746 | var sortImportMap = function sortImportMap(importMap) {
|
2747 | assertImportMap$1(importMap);
|
2748 | var imports = importMap.imports,
|
2749 | scopes = importMap.scopes;
|
2750 | var orderedImportMap = {
|
2751 | imports: imports ? sortImportMapImports(imports) : {},
|
2752 | scopes: scopes ? sortImportMapScopes(scopes) : {}
|
2753 | };
|
2754 | return orderedImportMap;
|
2755 | };
|
2756 |
|
2757 | var sortImportMapImports = function sortImportMapImports(imports) {
|
2758 | var sortedImports = {};
|
2759 | Object.keys(imports).sort(compareLengthOrLocaleCompare$1).forEach(function (name) {
|
2760 | sortedImports[name] = imports[name];
|
2761 | });
|
2762 | return sortedImports;
|
2763 | };
|
2764 |
|
2765 | var sortImportMapScopes = function sortImportMapScopes(scopes) {
|
2766 | var sortedScopes = {};
|
2767 | Object.keys(scopes).sort(compareLengthOrLocaleCompare$1).forEach(function (scopeName) {
|
2768 | sortedScopes[scopeName] = sortScopedImports(scopes[scopeName]);
|
2769 | });
|
2770 | return sortedScopes;
|
2771 | };
|
2772 |
|
2773 | var compareLengthOrLocaleCompare$1 = function compareLengthOrLocaleCompare(a, b) {
|
2774 | return b.length - a.length || a.localeCompare(b);
|
2775 | };
|
2776 |
|
2777 | var sortScopedImports = function sortScopedImports(scopedImports) {
|
2778 | var compareScopedImport = function compareScopedImport(a, b) {
|
2779 |
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 | return compareLengthOrLocaleCompare$1(a, b);
|
2790 | };
|
2791 |
|
2792 | var sortedScopedImports = {};
|
2793 | Object.keys(scopedImports).sort(compareScopedImport).forEach(function (name) {
|
2794 | sortedScopedImports[name] = scopedImports[name];
|
2795 | });
|
2796 | return sortedScopedImports;
|
2797 | };
|
2798 |
|
2799 | var pathnameToDirname$1 = function pathnameToDirname(pathname) {
|
2800 | var slashLastIndex = pathname.lastIndexOf("/");
|
2801 | if (slashLastIndex === -1) return "";
|
2802 | return pathname.slice(0, slashLastIndex);
|
2803 | };
|
2804 |
|
2805 | function _await$5(value, then, direct) {
|
2806 | if (direct) {
|
2807 | return then ? then(value) : value;
|
2808 | }
|
2809 |
|
2810 | if (!value || !value.then) {
|
2811 | value = Promise.resolve(value);
|
2812 | }
|
2813 |
|
2814 | return then ? value.then(then) : value;
|
2815 | }
|
2816 |
|
2817 | function _async$5(f) {
|
2818 | return function () {
|
2819 | for (var args = [], i = 0; i < arguments.length; i++) {
|
2820 | args[i] = arguments[i];
|
2821 | }
|
2822 |
|
2823 | try {
|
2824 | return Promise.resolve(f.apply(this, args));
|
2825 | } catch (e) {
|
2826 | return Promise.reject(e);
|
2827 | }
|
2828 | };
|
2829 | }
|
2830 |
|
2831 | var readPackageData = _async$5(function (_ref) {
|
2832 | var path = _ref.path;
|
2833 | return _await$5(fileRead(path), function (packageString) {
|
2834 | var packageData = JSON.parse(packageString);
|
2835 | return packageData;
|
2836 | });
|
2837 | });
|
2838 |
|
2839 | function _await$6(value, then, direct) {
|
2840 | if (direct) {
|
2841 | return then ? then(value) : value;
|
2842 | }
|
2843 |
|
2844 | if (!value || !value.then) {
|
2845 | value = Promise.resolve(value);
|
2846 | }
|
2847 |
|
2848 | return then ? value.then(then) : value;
|
2849 | }
|
2850 |
|
2851 | function _async$6(f) {
|
2852 | return function () {
|
2853 | for (var args = [], i = 0; i < arguments.length; i++) {
|
2854 | args[i] = arguments[i];
|
2855 | }
|
2856 |
|
2857 | try {
|
2858 | return Promise.resolve(f.apply(this, args));
|
2859 | } catch (e) {
|
2860 | return Promise.reject(e);
|
2861 | }
|
2862 | };
|
2863 | }
|
2864 |
|
2865 | function _catch(body, recover) {
|
2866 | try {
|
2867 | var result = body();
|
2868 | } catch (e) {
|
2869 | return recover(e);
|
2870 | }
|
2871 |
|
2872 | if (result && result.then) {
|
2873 | return result.then(void 0, recover);
|
2874 | }
|
2875 |
|
2876 | return result;
|
2877 | }
|
2878 |
|
2879 | var resolveNodeModule = _async$6(function (_ref) {
|
2880 | var rootPathname = _ref.rootPathname,
|
2881 | packagePathname = _ref.packagePathname,
|
2882 | packageData = _ref.packageData,
|
2883 | dependencyName = _ref.dependencyName,
|
2884 | dependencyVersionPattern = _ref.dependencyVersionPattern,
|
2885 | dependencyType = _ref.dependencyType,
|
2886 | onWarn = _ref.onWarn;
|
2887 | var packageFolderPathname = pathnameToDirname$1(packagePathname);
|
2888 | var packageFolderRelativePath = pathnameToRelativePathname(packageFolderPathname, rootPathname);
|
2889 | var nodeModuleCandidateArray = [].concat(_toConsumableArray(getCandidateArrayFromPackageFolder(packageFolderRelativePath)), ["node_modules"]);
|
2890 | return _await$6(firstOperationMatching({
|
2891 | array: nodeModuleCandidateArray,
|
2892 | start: _async$6(function (nodeModuleCandidate) {
|
2893 | var packagePathname = "".concat(rootPathname, "/").concat(nodeModuleCandidate, "/").concat(dependencyName, "/package.json");
|
2894 | return _catch(function () {
|
2895 | return _await$6(readPackageData({
|
2896 | path: pathnameToOperatingSystemPath(packagePathname)
|
2897 | }), function (packageData) {
|
2898 | return {
|
2899 | packagePathname: packagePathname,
|
2900 | packageData: packageData
|
2901 | };
|
2902 | });
|
2903 | }, function (e) {
|
2904 | if (e.code === "ENOENT") {
|
2905 | return {};
|
2906 | }
|
2907 |
|
2908 | if (e.name === "SyntaxError") {
|
2909 | throw createDependencyPackageParsingError({
|
2910 | parsingError: e,
|
2911 | packagePathname: packagePathname
|
2912 | });
|
2913 | }
|
2914 |
|
2915 | throw e;
|
2916 | });
|
2917 | }),
|
2918 | predicate: function predicate(_ref2) {
|
2919 | var packageData = _ref2.packageData;
|
2920 | return Boolean(packageData);
|
2921 | }
|
2922 | }), function (result) {
|
2923 | if (!result) {
|
2924 | onWarn({
|
2925 | code: "DEPENDENCY_NOT_FOUND",
|
2926 | message: createDendencyNotFoundMessage({
|
2927 | dependencyName: dependencyName,
|
2928 | dependencyType: dependencyType,
|
2929 | dependencyVersionPattern: dependencyVersionPattern,
|
2930 | packagePathname: packagePathname,
|
2931 | packageData: packageData
|
2932 | }),
|
2933 | data: {
|
2934 | packagePathname: packagePathname,
|
2935 | packageData: packageData,
|
2936 | dependencyName: dependencyName,
|
2937 | dependencyType: dependencyType
|
2938 | }
|
2939 | });
|
2940 | }
|
2941 |
|
2942 | return result;
|
2943 | });
|
2944 | });
|
2945 |
|
2946 | var getCandidateArrayFromPackageFolder = function getCandidateArrayFromPackageFolder(packageFolderRelativePath) {
|
2947 | if (packageFolderRelativePath === "") return [];
|
2948 | var candidateArray = [];
|
2949 | var relativeFolderNameArray = packageFolderRelativePath.split("/node_modules/");
|
2950 |
|
2951 | relativeFolderNameArray.shift();
|
2952 | var i = relativeFolderNameArray.length;
|
2953 |
|
2954 | while (i--) {
|
2955 | candidateArray.push("node_modules/".concat(relativeFolderNameArray.slice(0, i + 1).join("/node_modules/"), "/node_modules"));
|
2956 | }
|
2957 |
|
2958 | return candidateArray;
|
2959 | };
|
2960 |
|
2961 | var createDependencyPackageParsingError = function createDependencyPackageParsingError(_ref3) {
|
2962 | var parsingError = _ref3.parsingError,
|
2963 | packagePathname = _ref3.packagePathname;
|
2964 | return new SyntaxError("error while parsing dependency package.json.\n--- parsing error message ---\n".concat(parsingError.message, "\n--- package.json path ---\n").concat(pathnameToOperatingSystemPath(packagePathname), "\n"));
|
2965 | };
|
2966 |
|
2967 | var createDendencyNotFoundMessage = function createDendencyNotFoundMessage(_ref4) {
|
2968 | var dependencyName = _ref4.dependencyName,
|
2969 | dependencyType = _ref4.dependencyType,
|
2970 | dependencyVersionPattern = _ref4.dependencyVersionPattern,
|
2971 | packageData = _ref4.packageData,
|
2972 | packagePathname = _ref4.packagePathname;
|
2973 | return "cannot find a ".concat(dependencyType, ".\n--- ").concat(dependencyType, " ---\n").concat(dependencyName, "@").concat(dependencyVersionPattern, "\n--- required by ---\n").concat(packageData.name, "@").concat(packageData.version, "\n--- package.json path ---\n").concat(pathnameToOperatingSystemPath(packagePathname), "\n");
|
2974 | };
|
2975 |
|
2976 | function _await$7(value, then, direct) {
|
2977 | if (direct) {
|
2978 | return then ? then(value) : value;
|
2979 | }
|
2980 |
|
2981 | if (!value || !value.then) {
|
2982 | value = Promise.resolve(value);
|
2983 | }
|
2984 |
|
2985 | return then ? value.then(then) : value;
|
2986 | }
|
2987 |
|
2988 | function _invoke(body, then) {
|
2989 | var result = body();
|
2990 |
|
2991 | if (result && result.then) {
|
2992 | return result.then(then);
|
2993 | }
|
2994 |
|
2995 | return then(result);
|
2996 | }
|
2997 |
|
2998 | function _async$7(f) {
|
2999 | return function () {
|
3000 | for (var args = [], i = 0; i < arguments.length; i++) {
|
3001 | args[i] = arguments[i];
|
3002 | }
|
3003 |
|
3004 | try {
|
3005 | return Promise.resolve(f.apply(this, args));
|
3006 | } catch (e) {
|
3007 | return Promise.reject(e);
|
3008 | }
|
3009 | };
|
3010 | }
|
3011 |
|
3012 | var resolvePackageMain = function resolvePackageMain(_ref) {
|
3013 | var packageData = _ref.packageData,
|
3014 | packagePathname = _ref.packagePathname,
|
3015 | onWarn = _ref.onWarn;
|
3016 |
|
3017 | if ("module" in packageData) {
|
3018 | return resolveMainFile({
|
3019 | from: "module",
|
3020 | main: packageData.module,
|
3021 | packagePathname: packagePathname,
|
3022 | onWarn: onWarn
|
3023 | });
|
3024 | }
|
3025 |
|
3026 | if ("jsnext:main" in packageData) {
|
3027 | return resolveMainFile({
|
3028 | from: "jsnext:main",
|
3029 | main: packageData["jsnext:main"],
|
3030 | packagePathname: packagePathname,
|
3031 | onWarn: onWarn
|
3032 | });
|
3033 | }
|
3034 |
|
3035 | if ("main" in packageData) {
|
3036 | return resolveMainFile({
|
3037 | from: "main",
|
3038 | main: packageData.main,
|
3039 | packagePathname: packagePathname,
|
3040 | onWarn: onWarn
|
3041 | });
|
3042 | }
|
3043 |
|
3044 | return resolveMainFile({
|
3045 | from: "default",
|
3046 | main: "index",
|
3047 | packagePathname: packagePathname,
|
3048 | onWarn: onWarn
|
3049 | });
|
3050 | };
|
3051 | var extensionCandidateArray = ["js", "json", "node"];
|
3052 |
|
3053 | var resolveMainFile = _async$7(function (_ref2) {
|
3054 | var _exit = false;
|
3055 | var main = _ref2.main,
|
3056 | packagePathname = _ref2.packagePathname,
|
3057 | onWarn = _ref2.onWarn;
|
3058 |
|
3059 |
|
3060 | if (main === "") return "";
|
3061 | if (main.slice(0, 2) === "./") main = main.slice(2);
|
3062 | if (main[0] === "/") main = main.slice(1);
|
3063 | var packageDirname = pathnameToDirname$1(packagePathname);
|
3064 | var extension = path.extname(main);
|
3065 | return _invoke(function () {
|
3066 | if (extension === "") {
|
3067 | var fileWithoutExtensionPathname = "".concat(packageDirname, "/").concat(main);
|
3068 | return _await$7(firstOperationMatching({
|
3069 | array: extensionCandidateArray,
|
3070 | start: _async$7(function (extensionCandidate) {
|
3071 | var path = pathnameToOperatingSystemPath("".concat(fileWithoutExtensionPathname, ".").concat(extensionCandidate));
|
3072 | return _await$7(pathLeadsToAFile(path), function (isFile) {
|
3073 | return isFile ? extensionCandidate : null;
|
3074 | });
|
3075 | }),
|
3076 | predicate: function predicate(extension) {
|
3077 | return Boolean(extension);
|
3078 | }
|
3079 | }), function (extensionLeadingToFile) {
|
3080 | if (extensionLeadingToFile) {
|
3081 | _exit = true;
|
3082 | return "".concat(main, ".").concat(extensionLeadingToFile);
|
3083 | }
|
3084 |
|
3085 | onWarn({
|
3086 | code: "MAIN_FILE_NOT_FOUND",
|
3087 | message: createMainFileNotFoundMessage({
|
3088 | mainPathname: fileWithoutExtensionPathname,
|
3089 | packagePathname: packagePathname
|
3090 | }),
|
3091 | data: {
|
3092 | main: main,
|
3093 | packagePathname: packagePathname
|
3094 | }
|
3095 | });
|
3096 | _exit = true;
|
3097 | return "".concat(main, ".js");
|
3098 | });
|
3099 | }
|
3100 | }, function (_result) {
|
3101 | if (_exit) return _result;
|
3102 | var mainPathname = "".concat(packageDirname, "/").concat(main);
|
3103 | return _await$7(pathLeadsToAFile(mainPathname), function (isFile) {
|
3104 | if (!isFile) {
|
3105 | onWarn({
|
3106 | code: "MAIN_FILE_NOT_FOUND",
|
3107 | message: createMainFileNotFoundMessage({
|
3108 | mainPathname: mainPathname,
|
3109 | packagePathname: packagePathname
|
3110 | }),
|
3111 | data: {
|
3112 | main: main,
|
3113 | packagePathname: packagePathname
|
3114 | }
|
3115 | });
|
3116 | }
|
3117 |
|
3118 | return main;
|
3119 | });
|
3120 | });
|
3121 | });
|
3122 |
|
3123 | var pathLeadsToAFile = function pathLeadsToAFile(path) {
|
3124 | return new Promise(function (resolve, reject) {
|
3125 | fs.stat(path, function (error, statObject) {
|
3126 | if (error) {
|
3127 | if (error.code === "ENOENT") resolve(false);else reject(error);
|
3128 | } else {
|
3129 | resolve(statObject.isFile());
|
3130 | }
|
3131 | });
|
3132 | });
|
3133 | };
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 | var createMainFileNotFoundMessage = function createMainFileNotFoundMessage(_ref3) {
|
3139 | var mainPathname = _ref3.mainPathname,
|
3140 | packagePathname = _ref3.packagePathname;
|
3141 | return "cannot find a module main file.\n--- extensions tried ---\n".concat(extensionCandidateArray.join(","), "\n--- main path ---\n").concat(pathnameToOperatingSystemPath(mainPathname), "\n--- package.json path ---\n").concat(pathnameToOperatingSystemPath(packagePathname));
|
3142 | };
|
3143 |
|
3144 | function _await$8(value, then, direct) {
|
3145 | if (direct) {
|
3146 | return then ? then(value) : value;
|
3147 | }
|
3148 |
|
3149 | if (!value || !value.then) {
|
3150 | value = Promise.resolve(value);
|
3151 | }
|
3152 |
|
3153 | return then ? value.then(then) : value;
|
3154 | }
|
3155 |
|
3156 | function _async$8(f) {
|
3157 | return function () {
|
3158 | for (var args = [], i = 0; i < arguments.length; i++) {
|
3159 | args[i] = arguments[i];
|
3160 | }
|
3161 |
|
3162 | try {
|
3163 | return Promise.resolve(f.apply(this, args));
|
3164 | } catch (e) {
|
3165 | return Promise.reject(e);
|
3166 | }
|
3167 | };
|
3168 | }
|
3169 |
|
3170 | function _empty$2() {}
|
3171 |
|
3172 | function _awaitIgnored$1(value, direct) {
|
3173 | if (!direct) {
|
3174 | return value && value.then ? value.then(_empty$2) : Promise.resolve();
|
3175 | }
|
3176 | }
|
3177 |
|
3178 | var generateImportMapForPackage = _async$8(function (_ref) {
|
3179 | var projectPath = _ref.projectPath,
|
3180 | _ref$rootProjectPath = _ref.rootProjectPath,
|
3181 | rootProjectPath = _ref$rootProjectPath === void 0 ? projectPath : _ref$rootProjectPath,
|
3182 | _ref$includeDevDepend = _ref.includeDevDependencies,
|
3183 | includeDevDependencies = _ref$includeDevDepend === void 0 ? false : _ref$includeDevDepend,
|
3184 | _ref$onWarn = _ref.onWarn,
|
3185 | onWarn = _ref$onWarn === void 0 ? function (_ref2) {
|
3186 | var message = _ref2.message;
|
3187 | console.warn(message);
|
3188 | } : _ref$onWarn;
|
3189 | var projectPathname = operatingSystemPathToPathname(projectPath);
|
3190 | var projectPackagePathname = "".concat(projectPathname, "/package.json");
|
3191 | var rootProjectPathname = operatingSystemPathToPathname(rootProjectPath);
|
3192 | var rootImporterName = path.basename(rootProjectPathname);
|
3193 | var rootPackagePathname = "".concat(rootProjectPathname, "/package.json");
|
3194 | var imports = {};
|
3195 | var scopes = {};
|
3196 | var seen = {};
|
3197 |
|
3198 | var markPackageAsSeen = function markPackageAsSeen(packagePathname, importerPackagePathname) {
|
3199 | if (packagePathname in seen) {
|
3200 | seen[packagePathname].push(importerPackagePathname);
|
3201 | } else {
|
3202 | seen[packagePathname] = [importerPackagePathname];
|
3203 | }
|
3204 | };
|
3205 |
|
3206 | var packageIsSeen = function packageIsSeen(packagePathname, importerPackagePathname) {
|
3207 | return packagePathname in seen && seen[packagePathname].includes(importerPackagePathname);
|
3208 | };
|
3209 |
|
3210 | var visit = function visit(_ref3) {
|
3211 | var packagePathname = _ref3.packagePathname,
|
3212 | packageData = _ref3.packageData,
|
3213 | includeDevDependencies = _ref3.includeDevDependencies,
|
3214 | packageName = _ref3.packageName,
|
3215 | importerPackagePathname = _ref3.importerPackagePathname;
|
3216 | return _await$8(visitPackage({
|
3217 | packagePathname: packagePathname,
|
3218 | packageData: packageData,
|
3219 | packageName: packageName,
|
3220 | importerPackagePathname: importerPackagePathname
|
3221 | }), function () {
|
3222 | return _awaitIgnored$1(visitDependencies({
|
3223 | packagePathname: packagePathname,
|
3224 | packageData: packageData,
|
3225 | includeDevDependencies: includeDevDependencies
|
3226 | }));
|
3227 | });
|
3228 | };
|
3229 |
|
3230 | var visitPackage = _async$8(function (_ref4) {
|
3231 | var packagePathname = _ref4.packagePathname,
|
3232 | packageData = _ref4.packageData,
|
3233 | packageName = _ref4.packageName,
|
3234 | importerPackagePathname = _ref4.importerPackagePathname;
|
3235 | var packagePathInfo = computePackagePathInfo({
|
3236 | packagePathname: packagePathname,
|
3237 | packageName: packageName,
|
3238 | importerPackagePathname: importerPackagePathname
|
3239 | });
|
3240 | return _await$8(visitPackageMain({
|
3241 | packagePathname: packagePathname,
|
3242 | packageName: packageName,
|
3243 | packageData: packageData,
|
3244 | packagePathInfo: packagePathInfo
|
3245 | }), function () {
|
3246 | if ("imports" in packageData) {
|
3247 | visitPackageImports({
|
3248 | packagePathname: packagePathname,
|
3249 | packageName: packageName,
|
3250 | packageData: packageData,
|
3251 | packagePathInfo: packagePathInfo
|
3252 | });
|
3253 | }
|
3254 |
|
3255 | if ("exports" in packageData) {
|
3256 | visitPackageExports({
|
3257 | packagePathname: packagePathname,
|
3258 | packageName: packageName,
|
3259 | packageData: packageData,
|
3260 | packagePathInfo: packagePathInfo
|
3261 | });
|
3262 | }
|
3263 | });
|
3264 | });
|
3265 |
|
3266 | var visitPackageMain = _async$8(function (_ref5) {
|
3267 | var packagePathname = _ref5.packagePathname,
|
3268 | packageData = _ref5.packageData,
|
3269 | packageName = _ref5.packageName,
|
3270 | _ref5$packagePathInfo = _ref5.packagePathInfo,
|
3271 | packageIsRoot = _ref5$packagePathInfo.packageIsRoot,
|
3272 | packageIsProject = _ref5$packagePathInfo.packageIsProject,
|
3273 | importerPackageIsRoot = _ref5$packagePathInfo.importerPackageIsRoot,
|
3274 | importerName = _ref5$packagePathInfo.importerName,
|
3275 | actualRelativePath = _ref5$packagePathInfo.actualRelativePath,
|
3276 | expectedRelativePath = _ref5$packagePathInfo.expectedRelativePath;
|
3277 | if (packageIsRoot) return;
|
3278 | if (packageIsProject) return;
|
3279 | return _await$8(resolvePackageMain({
|
3280 | packagePathname: packagePathname,
|
3281 | packageData: packageData,
|
3282 | onWarn: function onWarn() {}
|
3283 | }), function (main) {
|
3284 | if (!main) return;
|
3285 | var from = packageName;
|
3286 | var to = "".concat(actualRelativePath, "/").concat(main);
|
3287 |
|
3288 | if (importerPackageIsRoot) {
|
3289 | addImportMapping({
|
3290 | from: from,
|
3291 | to: to
|
3292 | });
|
3293 | } else {
|
3294 | addScopedImportMapping({
|
3295 | scope: "/".concat(importerName, "/"),
|
3296 | from: from,
|
3297 | to: to
|
3298 | });
|
3299 | }
|
3300 |
|
3301 | if (actualRelativePath !== expectedRelativePath) {
|
3302 | addScopedImportMapping({
|
3303 | scope: "/".concat(importerName, "/"),
|
3304 | from: from,
|
3305 | to: to
|
3306 | });
|
3307 | }
|
3308 | });
|
3309 |
|
3310 |
|
3311 | });
|
3312 |
|
3313 | var visitPackageImports = function visitPackageImports(_ref6) {
|
3314 | var packagePathname = _ref6.packagePathname,
|
3315 | packageData = _ref6.packageData,
|
3316 | packagePathInfo = _ref6.packagePathInfo;
|
3317 | var packageImports = packageData.imports;
|
3318 |
|
3319 | if (_typeof$1(packageImports) !== "object" || packageImports === null) {
|
3320 | onWarn(createUnexpectedPackageImportsWarning({
|
3321 | packageImports: packageImports,
|
3322 | packagePathname: packagePathname
|
3323 | }));
|
3324 | return;
|
3325 | }
|
3326 |
|
3327 | var packageIsRoot = packagePathInfo.packageIsRoot,
|
3328 | actualRelativePath = packagePathInfo.actualRelativePath;
|
3329 | Object.keys(packageImports).forEach(function (key) {
|
3330 | var resolvedKey = resolvePathInPackage(key, packagePathname);
|
3331 | if (!resolvedKey) return;
|
3332 | var resolvedValue = resolvePathInPackage(packageImports[key], packagePathname);
|
3333 | if (!resolvedValue) return;
|
3334 |
|
3335 | if (packageIsRoot) {
|
3336 | addImportMapping({
|
3337 | from: resolvedKey,
|
3338 | to: resolvedValue
|
3339 | });
|
3340 | } else {
|
3341 | addScopedImportMapping({
|
3342 | scope: "".concat(actualRelativePath, "/"),
|
3343 | from: resolvedKey,
|
3344 | to: "".concat(actualRelativePath).concat(resolvedValue)
|
3345 | });
|
3346 | }
|
3347 | });
|
3348 |
|
3349 | if (!packageIsRoot) {
|
3350 |
|
3351 | addScopedImportMapping({
|
3352 | scope: "".concat(actualRelativePath, "/"),
|
3353 | from: "".concat(actualRelativePath, "/"),
|
3354 | to: "".concat(actualRelativePath, "/")
|
3355 | });
|
3356 | }
|
3357 | };
|
3358 |
|
3359 | var visitPackageExports = function visitPackageExports(_ref7) {
|
3360 | var packagePathname = _ref7.packagePathname,
|
3361 | packageName = _ref7.packageName,
|
3362 | packageData = _ref7.packageData,
|
3363 | _ref7$packagePathInfo = _ref7.packagePathInfo,
|
3364 | importerName = _ref7$packagePathInfo.importerName,
|
3365 | packageIsRoot = _ref7$packagePathInfo.packageIsRoot,
|
3366 | actualRelativePath = _ref7$packagePathInfo.actualRelativePath,
|
3367 | expectedRelativePath = _ref7$packagePathInfo.expectedRelativePath;
|
3368 | if (packageIsRoot) return;
|
3369 | var packageExports = packageData.exports;
|
3370 |
|
3371 | if (_typeof$1(packageExports) !== "object" || packageExports === null) {
|
3372 | onWarn(createUnexpectedPackageExportsWarning({
|
3373 | packageExports: packageExports,
|
3374 | packagePathname: packagePathname
|
3375 | }));
|
3376 | return;
|
3377 | }
|
3378 |
|
3379 | Object.keys(packageExports).forEach(function (key) {
|
3380 | var resolvedKey = resolvePathInPackage(key, packagePathname);
|
3381 | if (!resolvedKey) return;
|
3382 | var resolvedValue = resolvePathInPackage(packageExports[key], packagePathname);
|
3383 | if (!resolvedValue) return;
|
3384 | var from = "".concat(packageName).concat(resolvedKey);
|
3385 | var to = "".concat(actualRelativePath).concat(resolvedValue);
|
3386 |
|
3387 | if (importerName === rootImporterName) {
|
3388 | addImportMapping({
|
3389 | from: from,
|
3390 | to: to
|
3391 | });
|
3392 | } else {
|
3393 | addScopedImportMapping({
|
3394 | scope: "/".concat(importerName, "/"),
|
3395 | from: from,
|
3396 | to: to
|
3397 | });
|
3398 | }
|
3399 |
|
3400 | if (actualRelativePath !== expectedRelativePath) {
|
3401 | addScopedImportMapping({
|
3402 | scope: "/".concat(importerName, "/"),
|
3403 | from: from,
|
3404 | to: to
|
3405 | });
|
3406 | }
|
3407 | });
|
3408 | };
|
3409 |
|
3410 | var visitDependencies = _async$8(function (_ref8) {
|
3411 | var packagePathname = _ref8.packagePathname,
|
3412 | packageData = _ref8.packageData,
|
3413 | includeDevDependencies = _ref8.includeDevDependencies;
|
3414 | var dependencyMap = {};
|
3415 | var _packageData$dependen = packageData.dependencies,
|
3416 | dependencies = _packageData$dependen === void 0 ? {} : _packageData$dependen;
|
3417 | Object.keys(dependencies).forEach(function (dependencyName) {
|
3418 | dependencyMap[dependencyName] = {
|
3419 | type: "dependency",
|
3420 | versionPattern: dependencies[dependencyName]
|
3421 | };
|
3422 | });
|
3423 | var _packageData$peerDepe = packageData.peerDependencies,
|
3424 | peerDependencies = _packageData$peerDepe === void 0 ? {} : _packageData$peerDepe;
|
3425 | Object.keys(peerDependencies).forEach(function (dependencyName) {
|
3426 | dependencyMap[dependencyName] = {
|
3427 | type: "peerDependency",
|
3428 | versionPattern: peerDependencies[dependencyName]
|
3429 | };
|
3430 | });
|
3431 | var isProjectPackage = packagePathname === projectPackagePathname;
|
3432 |
|
3433 | if (includeDevDependencies && isProjectPackage) {
|
3434 | var _packageData$devDepen = packageData.devDependencies,
|
3435 | devDependencies = _packageData$devDepen === void 0 ? {} : _packageData$devDepen;
|
3436 | Object.keys(devDependencies).forEach(function (dependencyName) {
|
3437 | if (!dependencyMap.hasOwnProperty(dependencyName)) {
|
3438 | dependencyMap[dependencyName] = {
|
3439 | type: "devDependency",
|
3440 | versionPattern: devDependencies[dependencyName]
|
3441 | };
|
3442 | }
|
3443 | });
|
3444 | }
|
3445 |
|
3446 | return _awaitIgnored$1(Promise.all(Object.keys(dependencyMap).map(_async$8(function (dependencyName) {
|
3447 | var dependency = dependencyMap[dependencyName];
|
3448 | return _awaitIgnored$1(visitDependency({
|
3449 | packagePathname: packagePathname,
|
3450 | packageData: packageData,
|
3451 | dependencyName: dependencyName,
|
3452 | dependencyType: dependency.type,
|
3453 | dependencyVersionPattern: dependency.versionPattern
|
3454 | }));
|
3455 | }))));
|
3456 | });
|
3457 |
|
3458 | var visitDependency = _async$8(function (_ref9) {
|
3459 | var packagePathname = _ref9.packagePathname,
|
3460 | packageData = _ref9.packageData,
|
3461 | dependencyName = _ref9.dependencyName,
|
3462 | dependencyType = _ref9.dependencyType,
|
3463 | dependencyVersionPattern = _ref9.dependencyVersionPattern;
|
3464 | return _await$8(findDependency({
|
3465 | packagePathname: packagePathname,
|
3466 | packageData: packageData,
|
3467 | dependencyName: dependencyName,
|
3468 | dependencyType: dependencyType,
|
3469 | dependencyVersionPattern: dependencyVersionPattern
|
3470 | }), function (dependencyData) {
|
3471 | if (!dependencyData) {
|
3472 | return;
|
3473 | }
|
3474 |
|
3475 | var dependencyPackagePathname = dependencyData.packagePathname,
|
3476 | dependencyPackageData = dependencyData.packageData;
|
3477 |
|
3478 | if (packageIsSeen(dependencyPackagePathname, packagePathname)) {
|
3479 | return;
|
3480 | }
|
3481 |
|
3482 | markPackageAsSeen(dependencyPackagePathname, packagePathname);
|
3483 | return _awaitIgnored$1(visit({
|
3484 | packagePathname: dependencyPackagePathname,
|
3485 | packageData: dependencyPackageData,
|
3486 | packageName: dependencyName,
|
3487 | importerPackagePathname: packagePathname
|
3488 | }));
|
3489 | });
|
3490 | });
|
3491 |
|
3492 | var computePackagePathInfo = function computePackagePathInfo(_ref10) {
|
3493 | var packagePathname = _ref10.packagePathname,
|
3494 | packageName = _ref10.packageName,
|
3495 | importerPackagePathname = _ref10.importerPackagePathname;
|
3496 | var packageIsRoot = packagePathname === rootPackagePathname;
|
3497 | var packageIsProject = packagePathname === projectPackagePathname;
|
3498 | var importerPackageIsRoot = importerPackagePathname === rootPackagePathname;
|
3499 | var importerPackageIsProject = importerPackagePathname === projectPackagePathname;
|
3500 | var importerName = importerPackageIsRoot ? rootImporterName : pathnameToDirname$1(pathnameToRelativePathname(importerPackagePathname, rootProjectPathname)).slice(1);
|
3501 | var actualPathname = pathnameToDirname$1(packagePathname);
|
3502 | var actualRelativePath = pathnameToRelativePathname(actualPathname, rootProjectPathname);
|
3503 | var expectedPathname;
|
3504 |
|
3505 | if (packageIsProject && !packageIsRoot) {
|
3506 | expectedPathname = pathnameToDirname$1(importerPackagePathname);
|
3507 | } else {
|
3508 | expectedPathname = "".concat(pathnameToDirname$1(importerPackagePathname), "/node_modules/").concat(packageName);
|
3509 | }
|
3510 |
|
3511 | var expectedRelativePath = pathnameToRelativePathname(expectedPathname, rootProjectPathname);
|
3512 | return {
|
3513 | importerPackageIsRoot: importerPackageIsRoot,
|
3514 | importerPackageIsProject: importerPackageIsProject,
|
3515 | importerName: importerName,
|
3516 | packageIsRoot: packageIsRoot,
|
3517 | packageIsProject: packageIsProject,
|
3518 | actualRelativePath: actualRelativePath,
|
3519 | expectedRelativePath: expectedRelativePath
|
3520 | };
|
3521 | };
|
3522 |
|
3523 | var resolvePathInPackage = function resolvePathInPackage(path, packagePathname) {
|
3524 | if (path[0] === "/") return path;
|
3525 | if (path.slice(0, 2) === "./") return path.slice(1);
|
3526 | onWarn(createInvalidPackageRelativePathWarning({
|
3527 | path: path,
|
3528 | packagePathname: packagePathname
|
3529 | }));
|
3530 | return "";
|
3531 | };
|
3532 |
|
3533 | var addImportMapping = function addImportMapping(_ref11) {
|
3534 | var from = _ref11.from,
|
3535 | to = _ref11.to;
|
3536 |
|
3537 |
|
3538 |
|
3539 |
|
3540 | if (from === to) {
|
3541 | |
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 |
|
3551 | if (from === "/") return;
|
3552 | }
|
3553 |
|
3554 | imports[from] = to;
|
3555 | };
|
3556 |
|
3557 | var addScopedImportMapping = function addScopedImportMapping(_ref12) {
|
3558 | var scope = _ref12.scope,
|
3559 | from = _ref12.from,
|
3560 | to = _ref12.to;
|
3561 | scopes[scope] = _objectSpread({}, scopes[scope] || {}, _defineProperty$1({}, from, to));
|
3562 | };
|
3563 |
|
3564 | var dependenciesCache = {};
|
3565 |
|
3566 | var findDependency = function findDependency(_ref13) {
|
3567 | var packagePathname = _ref13.packagePathname,
|
3568 | packageData = _ref13.packageData,
|
3569 | dependencyName = _ref13.dependencyName,
|
3570 | dependencyType = _ref13.dependencyType,
|
3571 | dependencyVersionPattern = _ref13.dependencyVersionPattern;
|
3572 |
|
3573 | if (packagePathname in dependenciesCache === false) {
|
3574 | dependenciesCache[packagePathname] = {};
|
3575 | }
|
3576 |
|
3577 | if (dependencyName in dependenciesCache[packagePathname]) {
|
3578 | return dependenciesCache[packagePathname][dependencyName];
|
3579 | }
|
3580 |
|
3581 | var dependencyPromise = resolveNodeModule({
|
3582 | rootPathname: rootProjectPathname,
|
3583 | packagePathname: packagePathname,
|
3584 | packageData: packageData,
|
3585 | dependencyName: dependencyName,
|
3586 | dependencyType: dependencyType,
|
3587 | dependencyVersionPattern: dependencyVersionPattern,
|
3588 | onWarn: onWarn
|
3589 | });
|
3590 | dependenciesCache[packagePathname][dependencyName] = dependencyPromise;
|
3591 | return dependencyPromise;
|
3592 | };
|
3593 |
|
3594 | return _await$8(readPackageData({
|
3595 | path: pathnameToOperatingSystemPath(projectPackagePathname),
|
3596 | onWarn: onWarn
|
3597 | }), function (projectPackageData) {
|
3598 | markPackageAsSeen(projectPackagePathname, projectPackagePathname);
|
3599 | return _await$8(visit({
|
3600 | packagePathname: projectPackagePathname,
|
3601 | packageData: projectPackageData,
|
3602 | includeDevDependencies: includeDevDependencies,
|
3603 | packageName: projectPackageData.name,
|
3604 | importerPackagePathname: projectPackagePathname
|
3605 | }), function () {
|
3606 | return sortImportMap({
|
3607 | imports: imports,
|
3608 | scopes: scopes
|
3609 | });
|
3610 | });
|
3611 | });
|
3612 | });
|
3613 |
|
3614 | var createInvalidPackageRelativePathWarning = function createInvalidPackageRelativePathWarning(_ref14) {
|
3615 | var path = _ref14.path,
|
3616 | packagePathname = _ref14.packagePathname;
|
3617 | return {
|
3618 | code: "INVALID_PATH_RELATIVE_TO_PACKAGE",
|
3619 | message: "\ninvalid path relative to package.\n--- path ---\n".concat(path, "\n--- package.json path ---\n").concat(pathnameToOperatingSystemPath(packagePathname), "\n"),
|
3620 | data: {
|
3621 | packagePathname: packagePathname,
|
3622 | path: path
|
3623 | }
|
3624 | };
|
3625 | };
|
3626 |
|
3627 | var createUnexpectedPackageImportsWarning = function createUnexpectedPackageImportsWarning(_ref15) {
|
3628 | var packageImports = _ref15.packageImports,
|
3629 | packagePathname = _ref15.packagePathname;
|
3630 | return {
|
3631 | code: "UNEXPECTED_PACKAGE_IMPORTS",
|
3632 | message: "\npackage.imports must be an object.\n--- package.json imports ---\n".concat(packageImports, "\n--- package.json path ---\n").concat(pathnameToOperatingSystemPath(packagePathname), "\n"),
|
3633 | data: {
|
3634 | packagePathname: packagePathname,
|
3635 | packageImports: packageImports
|
3636 | }
|
3637 | };
|
3638 | };
|
3639 |
|
3640 | var createUnexpectedPackageExportsWarning = function createUnexpectedPackageExportsWarning(_ref16) {
|
3641 | var packageExports = _ref16.packageExports,
|
3642 | packagePathname = _ref16.packagePathname;
|
3643 | return {
|
3644 | code: "UNEXPECTED_PACKAGE_EXPORTS",
|
3645 | message: "\npackage.exports must be an object.\n--- package.json exports ---\n".concat(packageExports, "\n--- package.json path ---\n").concat(pathnameToOperatingSystemPath(packagePathname), "\n"),
|
3646 | data: {
|
3647 | packagePathname: packagePathname,
|
3648 | packageExports: packageExports
|
3649 | }
|
3650 | };
|
3651 | };
|
3652 |
|
3653 |
|
3654 | var _require2$9 = nodeRequire("@babel/helper-module-imports"),
|
3655 | addNamed = _require2$9.addNamed;
|
3656 |
|
3657 | var createImportMetaUrlNamedImportBabelPlugin = function createImportMetaUrlNamedImportBabelPlugin(_ref) {
|
3658 | var importMetaFacadePath = _ref.importMetaFacadePath;
|
3659 | return function () {
|
3660 | return {
|
3661 | visitor: {
|
3662 | Program: function Program(programPath) {
|
3663 | var metaPropertyMap = {};
|
3664 | programPath.traverse({
|
3665 | MemberExpression: function MemberExpression(path) {
|
3666 | var node = path.node;
|
3667 | var object = node.object;
|
3668 | if (object.type !== "MetaProperty") return;
|
3669 | var objectProperty = object.property;
|
3670 | if (objectProperty.name !== "meta") return;
|
3671 | var property = node.property;
|
3672 | var name = property.name;
|
3673 |
|
3674 | if (name in metaPropertyMap) {
|
3675 | metaPropertyMap[name].push(path);
|
3676 | } else {
|
3677 | metaPropertyMap[name] = [path];
|
3678 | }
|
3679 | }
|
3680 | });
|
3681 | Object.keys(metaPropertyMap).forEach(function (propertyName) {
|
3682 | var importMetaPropertyId = propertyName;
|
3683 | var result = addNamed(programPath, importMetaPropertyId, importMetaFacadePath);
|
3684 | metaPropertyMap[propertyName].forEach(function (path) {
|
3685 | path.replaceWith(result);
|
3686 | });
|
3687 | });
|
3688 | }
|
3689 | }
|
3690 | };
|
3691 | };
|
3692 | };
|
3693 |
|
3694 | var generateBabelPluginMapOption = function generateBabelPluginMapOption(_ref) {
|
3695 | var format = _ref.format,
|
3696 | babelPluginMap = _ref.babelPluginMap,
|
3697 | featureNameArray = _ref.featureNameArray;
|
3698 | return _objectSpread$1({}, generateBabelPluginMapSubset({
|
3699 | babelPluginMap: babelPluginMap,
|
3700 | featureNameArray: featureNameArray
|
3701 | }), {}, generateBabelPluginMapForBundle({
|
3702 | format: format
|
3703 | }));
|
3704 | };
|
3705 |
|
3706 | var generateBabelPluginMapSubset = function generateBabelPluginMapSubset(_ref2) {
|
3707 | var babelPluginMap = _ref2.babelPluginMap,
|
3708 | featureNameArray = _ref2.featureNameArray;
|
3709 | var babelPluginMapSubset = {};
|
3710 | Object.keys(babelPluginMap).forEach(function (babelPluginName) {
|
3711 | if (featureNameArray.includes(babelPluginName)) {
|
3712 | babelPluginMapSubset[babelPluginName] = babelPluginMap[babelPluginName];
|
3713 | }
|
3714 | });
|
3715 | return babelPluginMapSubset;
|
3716 | };
|
3717 |
|
3718 | var generateBabelPluginMapForBundle = function generateBabelPluginMapForBundle(_ref3) {
|
3719 | var format = _ref3.format;
|
3720 | var bundleBabelPluginMap = {};
|
3721 |
|
3722 | if (format === "commonjs" || format === "global") {
|
3723 | var importMetaFacadePath = "file://".concat(jsenvBundlingProjectPathname, "/src/babel-plugin-map/import-meta-").concat(format, ".js");
|
3724 | bundleBabelPluginMap["import-meta-url-named-import"] = createImportMetaUrlNamedImportBabelPlugin({
|
3725 | importMetaFacadePath: importMetaFacadePath
|
3726 | });
|
3727 | }
|
3728 |
|
3729 | return bundleBabelPluginMap;
|
3730 | };
|
3731 |
|
3732 | function _await$9(value, then, direct) {
|
3733 | if (direct) {
|
3734 | return then ? then(value) : value;
|
3735 | }
|
3736 |
|
3737 | if (!value || !value.then) {
|
3738 | value = Promise.resolve(value);
|
3739 | }
|
3740 |
|
3741 | return then ? value.then(then) : value;
|
3742 | }
|
3743 |
|
3744 | var fetch = nodeRequire("node-fetch");
|
3745 |
|
3746 | function _invoke$1(body, then) {
|
3747 | var result = body();
|
3748 |
|
3749 | if (result && result.then) {
|
3750 | return result.then(then);
|
3751 | }
|
3752 |
|
3753 | return then(result);
|
3754 | }
|
3755 |
|
3756 | var AbortController = nodeRequire("abort-controller");
|
3757 |
|
3758 |
|
3759 | function _async$9(f) {
|
3760 | return function () {
|
3761 | for (var args = [], i = 0; i < arguments.length; i++) {
|
3762 | args[i] = arguments[i];
|
3763 | }
|
3764 |
|
3765 | try {
|
3766 | return Promise.resolve(f.apply(this, args));
|
3767 | } catch (e) {
|
3768 | return Promise.reject(e);
|
3769 | }
|
3770 | };
|
3771 | }
|
3772 |
|
3773 | https.globalAgent.options.rejectUnauthorized = false;
|
3774 | var fetchUsingHttp = _async$9(function (url) {
|
3775 | var _exit = false;
|
3776 |
|
3777 | var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
3778 |
|
3779 | var cancellationToken = _ref.cancellationToken,
|
3780 | rest = _objectWithoutProperties(_ref, ["cancellationToken"]);
|
3781 |
|
3782 | return _invoke$1(function () {
|
3783 | if (cancellationToken) {
|
3784 |
|
3785 |
|
3786 |
|
3787 | return _await$9(createOperation({
|
3788 | cancellationToken: cancellationToken,
|
3789 | start: function start() {
|
3790 | return fetch(url, _objectSpread$1({
|
3791 | signal: cancellationTokenToAbortSignal(cancellationToken)
|
3792 | }, rest));
|
3793 | }
|
3794 | }), function (response) {
|
3795 | _exit = true;
|
3796 | return normalizeResponse(response);
|
3797 | });
|
3798 | }
|
3799 | }, function (_result) {
|
3800 | return _exit ? _result : _await$9(fetch(url, rest), normalizeResponse);
|
3801 | });
|
3802 | });
|
3803 |
|
3804 | var normalizeResponse = _async$9(function (response) {
|
3805 | return _await$9(response.text(), function (text) {
|
3806 | return {
|
3807 | url: response.url,
|
3808 | status: response.status,
|
3809 | statusText: response.statusText,
|
3810 | headers: responseToHeaderMap(response),
|
3811 | body: text
|
3812 | };
|
3813 | });
|
3814 | });
|
3815 |
|
3816 |
|
3817 | var cancellationTokenToAbortSignal = function cancellationTokenToAbortSignal(cancellationToken) {
|
3818 | var abortController = new AbortController();
|
3819 | cancellationToken.register(function (reason) {
|
3820 | abortController.abort(reason);
|
3821 | });
|
3822 | return abortController.signal;
|
3823 | };
|
3824 |
|
3825 | var responseToHeaderMap = function responseToHeaderMap(response) {
|
3826 | var headerMap = {};
|
3827 | response.headers.forEach(function (value, name) {
|
3828 | headerMap[name] = value;
|
3829 | });
|
3830 | return headerMap;
|
3831 | };
|
3832 |
|
3833 | var writeSourceMappingURL = function writeSourceMappingURL(source, location) {
|
3834 | return "".concat(source, "\n", "//#", " sourceMappingURL=").concat(location);
|
3835 | };
|
3836 | var updateSourceMappingURL = function updateSourceMappingURL(source, callback) {
|
3837 | var sourceMappingUrlRegExp = /\/\/# ?sourceMappingURL=([^\s'"]+)/g;
|
3838 | var lastSourceMappingUrl;
|
3839 | var matchSourceMappingUrl;
|
3840 |
|
3841 | while (matchSourceMappingUrl = sourceMappingUrlRegExp.exec(source)) {
|
3842 | lastSourceMappingUrl = matchSourceMappingUrl;
|
3843 | }
|
3844 |
|
3845 | if (lastSourceMappingUrl) {
|
3846 | var index = lastSourceMappingUrl.index;
|
3847 | var before = source.slice(0, index);
|
3848 | var after = source.slice(index);
|
3849 | var mappedAfter = after.replace(sourceMappingUrlRegExp, function (match, firstGroup) {
|
3850 | return "//#".concat(" sourceMappingURL=", callback(firstGroup));
|
3851 | });
|
3852 | return "".concat(before).concat(mappedAfter);
|
3853 | }
|
3854 |
|
3855 | return source;
|
3856 | };
|
3857 | var readSourceMappingURL = function readSourceMappingURL(source) {
|
3858 | var sourceMappingURL;
|
3859 | updateSourceMappingURL(source, function (value) {
|
3860 | sourceMappingURL = value;
|
3861 | });
|
3862 | return sourceMappingURL;
|
3863 | };
|
3864 | var parseSourceMappingURL = function parseSourceMappingURL(source) {
|
3865 | var sourceMappingURL = readSourceMappingURL(source);
|
3866 | if (!sourceMappingURL) return null;
|
3867 | var base64Prefix = "data:application/json;charset=utf-8;base64,";
|
3868 |
|
3869 | if (sourceMappingURL.startsWith(base64Prefix)) {
|
3870 | var mapBase64Source = sourceMappingURL.slice(base64Prefix.length);
|
3871 | var sourcemapString = new Buffer(mapBase64Source, "base64").toString("utf8");
|
3872 | return {
|
3873 | sourcemapString: sourcemapString
|
3874 | };
|
3875 | }
|
3876 |
|
3877 | return {
|
3878 | sourcemapURL: sourceMappingURL
|
3879 | };
|
3880 | };
|
3881 | var writeOrUpdateSourceMappingURL = function writeOrUpdateSourceMappingURL(source, location) {
|
3882 | if (readSourceMappingURL(source)) {
|
3883 | return updateSourceMappingURL(source, location);
|
3884 | }
|
3885 |
|
3886 | return writeSourceMappingURL(source, location);
|
3887 | };
|
3888 |
|
3889 | function _empty$3() {}
|
3890 |
|
3891 | var _require2$a = nodeRequire("@jsenv/core"),
|
3892 | readProjectImportMap = _require2$a.readProjectImportMap,
|
3893 | babelHelperMap = _require2$a.babelHelperMap,
|
3894 | generateBabelHelper = _require2$a.generateBabelHelper,
|
3895 | cleanCompileCacheFolderIfObsolete = _require2$a.cleanCompileCacheFolderIfObsolete,
|
3896 | getOrGenerateCompiledFile = _require2$a.getOrGenerateCompiledFile,
|
3897 | transformJs = _require2$a.transformJs,
|
3898 | transformResultToCompilationResult = _require2$a.transformResultToCompilationResult,
|
3899 | compilationResultToTransformResult = _require2$a.compilationResultToTransformResult,
|
3900 | findAsyncPluginNameInBabelPluginMap = _require2$a.findAsyncPluginNameInBabelPluginMap;
|
3901 |
|
3902 | function _awaitIgnored$2(value, direct) {
|
3903 | if (!direct) {
|
3904 | return value && value.then ? value.then(_empty$3) : Promise.resolve();
|
3905 | }
|
3906 | }
|
3907 |
|
3908 | var _require3$2 = nodeRequire("terser"),
|
3909 | minifyCode = _require3$2.minify;
|
3910 |
|
3911 | function _invoke$2(body, then) {
|
3912 | var result = body();
|
3913 |
|
3914 | if (result && result.then) {
|
3915 | return result.then(then);
|
3916 | }
|
3917 |
|
3918 | return then(result);
|
3919 | }
|
3920 |
|
3921 | function _await$a(value, then, direct) {
|
3922 | if (direct) {
|
3923 | return then ? then(value) : value;
|
3924 | }
|
3925 |
|
3926 | if (!value || !value.then) {
|
3927 | value = Promise.resolve(value);
|
3928 | }
|
3929 |
|
3930 | return then ? value.then(then) : value;
|
3931 | }
|
3932 |
|
3933 | function _async$a(f) {
|
3934 | return function () {
|
3935 | for (var args = [], i = 0; i < arguments.length; i++) {
|
3936 | args[i] = arguments[i];
|
3937 | }
|
3938 |
|
3939 | try {
|
3940 | return Promise.resolve(f.apply(this, args));
|
3941 | } catch (e) {
|
3942 | return Promise.reject(e);
|
3943 | }
|
3944 | };
|
3945 | }
|
3946 |
|
3947 | function _call$1(body, then, direct) {
|
3948 | if (direct) {
|
3949 | return then ? then(body()) : body();
|
3950 | }
|
3951 |
|
3952 | try {
|
3953 | var result = Promise.resolve(body());
|
3954 | return then ? result.then(then) : result;
|
3955 | } catch (e) {
|
3956 | return Promise.reject(e);
|
3957 | }
|
3958 | }
|
3959 |
|
3960 | function _catch$1(body, recover) {
|
3961 | try {
|
3962 | var result = body();
|
3963 | } catch (e) {
|
3964 | return recover(e);
|
3965 | }
|
3966 |
|
3967 | if (result && result.then) {
|
3968 | return result.then(void 0, recover);
|
3969 | }
|
3970 |
|
3971 | return result;
|
3972 | }
|
3973 |
|
3974 | var createJsenvRollupPlugin = _async$a(function (_ref) {
|
3975 | var _imports;
|
3976 |
|
3977 | var cancellationToken = _ref.cancellationToken,
|
3978 | projectPathname = _ref.projectPathname,
|
3979 | bundleIntoRelativePath = _ref.bundleIntoRelativePath,
|
3980 | importDefaultExtension = _ref.importDefaultExtension,
|
3981 | importMapRelativePath = _ref.importMapRelativePath,
|
3982 | importMapForBundle = _ref.importMapForBundle,
|
3983 | importAbstractMap = _ref.importAbstractMap,
|
3984 | importFallbackMap = _ref.importFallbackMap,
|
3985 | cache = _ref.cache,
|
3986 | cacheRelativePath = _ref.cacheRelativePath,
|
3987 | babelPluginMap = _ref.babelPluginMap,
|
3988 | convertMap = _ref.convertMap,
|
3989 | featureNameArray = _ref.featureNameArray,
|
3990 | minify = _ref.minify,
|
3991 | format = _ref.format,
|
3992 | _ref$detectAndTransfo = _ref.detectAndTransformIfNeededAsyncInsertedByRollup,
|
3993 | detectAndTransformIfNeededAsyncInsertedByRollup = _ref$detectAndTransfo === void 0 ? format === "global" : _ref$detectAndTransfo,
|
3994 | entryPointMap = _ref.entryPointMap,
|
3995 | logger = _ref.logger;
|
3996 | var fakeOrigin = "http://example.com";
|
3997 | var arrayOfHrefToSkipTransform = [];
|
3998 | var arrayOfAbstractHref = [];
|
3999 |
|
4000 | var getArrayOfAbstractHref = function getArrayOfAbstractHref() {
|
4001 | return arrayOfAbstractHref;
|
4002 | };
|
4003 |
|
4004 | var importMapAbstractPath = "/.jsenv/importMap.json";
|
4005 | var bundleConstantAbstractPath = "/.jsenv/BUNDLE_CONSTANTS.js";
|
4006 | babelPluginMap = generateBabelPluginMapOption({
|
4007 | projectPathname: projectPathname,
|
4008 | format: format,
|
4009 | babelPluginMap: babelPluginMap,
|
4010 | featureNameArray: featureNameArray
|
4011 | });
|
4012 | var bundleConstantsHref = "file://".concat(jsenvBundlingProjectPathname).concat(bundleConstantAbstractPath);
|
4013 | var importMapHref = "file://".concat(projectPathname).concat(importMapRelativePath);
|
4014 | importFallbackMap = _objectSpread$1({}, importFallbackMap, _defineProperty({}, importMapHref, function () {
|
4015 | return "export default {}";
|
4016 | }));
|
4017 | var chunkId = "".concat(Object.keys(entryPointMap)[0], ".js");
|
4018 | importAbstractMap = _objectSpread$1({}, importAbstractMap, _defineProperty({}, bundleConstantsHref, function () {
|
4019 | return "export const chunkId = ".concat(JSON.stringify(chunkId));
|
4020 | }));
|
4021 | var importMapForBundling = {
|
4022 | imports: (_imports = {}, _defineProperty(_imports, bundleConstantAbstractPath, bundleConstantsHref), _defineProperty(_imports, importMapAbstractPath, importMapHref), _imports)
|
4023 | };
|
4024 | Object.keys(babelHelperMap).forEach(function (babelHelperName) {
|
4025 | var babelHelperPath = babelHelperMap[babelHelperName];
|
4026 |
|
4027 | if (babelHelperPath.startsWith("@jsenv/core")) ; else {
|
4028 | importAbstractMap[babelHelperPath] = function () {
|
4029 | return generateBabelHelper(babelHelperName);
|
4030 | };
|
4031 | }
|
4032 | });
|
4033 | return _await$a(readProjectImportMap({
|
4034 | projectPathname: projectPathname,
|
4035 | jsenvProjectPathname: jsenvBundlingProjectPathname,
|
4036 | importMapRelativePath: importMapRelativePath,
|
4037 | logger: logger
|
4038 | }), function (importMapForProject) {
|
4039 | return _await$a(generateImportMapForPackage({
|
4040 | projectPath: jsenvBundlingProjectPath,
|
4041 | rootProjectPath: pathnameToOperatingSystemPath(projectPathname),
|
4042 | onWarn: function onWarn(_ref2) {
|
4043 | var message = _ref2.message;
|
4044 | return logger.warn(message);
|
4045 | }
|
4046 | }), function (_generateImportMapFor) {
|
4047 | var importMap = normalizeImportMap([_generateImportMapFor, importMapForBundling, importMapForProject, importMapForBundle].reduce(function (previous, current) {
|
4048 | return composeTwoImportMaps(previous, current);
|
4049 | }, {}), fakeOrigin);
|
4050 | var compileCacheFolderRelativePath = "".concat(bundleIntoRelativePath).concat(cacheRelativePath);
|
4051 | return _invoke$2(function () {
|
4052 | if (cache) {
|
4053 | var cacheMeta = {
|
4054 | featureNameArray: featureNameArray,
|
4055 | convertMap: convertMap
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 | };
|
4067 | return _awaitIgnored$2(cleanCompileCacheFolderIfObsolete({
|
4068 | projectPathname: projectPathname,
|
4069 | compileCacheFolderRelativePath: compileCacheFolderRelativePath,
|
4070 | cacheMeta: cacheMeta,
|
4071 | cleanCallback: function cleanCallback(cacheFolderPath) {
|
4072 | logger.warn("remove cache folder ".concat(cacheFolderPath));
|
4073 | }
|
4074 | }));
|
4075 | }
|
4076 | }, function () {
|
4077 | var jsenvRollupPlugin = {
|
4078 | name: "jsenv",
|
4079 | resolveId: function resolveId(specifier, importer) {
|
4080 | var importerHref;
|
4081 |
|
4082 | if (importer) {
|
4083 | if (isWindowsPath(importer)) {
|
4084 | importer = operatingSystemPathToPathname(importer);
|
4085 | }
|
4086 |
|
4087 |
|
4088 |
|
4089 |
|
4090 | if (importer.startsWith("".concat(projectPathname, "/"))) {
|
4091 | importerHref = "".concat(fakeOrigin).concat(pathnameToRelativePath(importer, projectPathname));
|
4092 | } else if (hrefToScheme(importer)) {
|
4093 | if (importer.startsWith("file://".concat(projectPathname, "/"))) {
|
4094 | importerHref = "".concat(fakeOrigin).concat(pathnameToRelativePath(hrefToPathname(importer), projectPathname));
|
4095 | } else {
|
4096 |
|
4097 |
|
4098 | importerHref = importer;
|
4099 | }
|
4100 | } else {
|
4101 | throw createImporterOutsideProjectError({
|
4102 | importer: importer,
|
4103 | projectPathname: projectPathname
|
4104 | });
|
4105 | }
|
4106 | } else {
|
4107 | importerHref = fakeOrigin;
|
4108 | }
|
4109 |
|
4110 | var resolvedHref = resolveImport({
|
4111 | specifier: specifier,
|
4112 | importer: importerHref,
|
4113 | importMap: importMap,
|
4114 | defaultExtension: importDefaultExtension
|
4115 | });
|
4116 | var href;
|
4117 |
|
4118 | if (resolvedHref.startsWith("file://")) {
|
4119 | if (!pathnameIsInside(hrefToPathname(resolvedHref), projectPathname)) {
|
4120 | throw new Error(createMustBeInsideProjectMessage({
|
4121 | href: resolvedHref,
|
4122 | specifier: specifier,
|
4123 | importer: importer,
|
4124 | projectPathname: projectPathname
|
4125 | }));
|
4126 | }
|
4127 |
|
4128 | href = resolvedHref;
|
4129 | } else if (hrefToOrigin(resolvedHref) === fakeOrigin) {
|
4130 | href = "file://".concat(projectPathname).concat(hrefToPathname(resolvedHref));
|
4131 | } else {
|
4132 |
|
4133 | href = resolvedHref;
|
4134 | }
|
4135 |
|
4136 | if (href.startsWith("file://")) {
|
4137 |
|
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 |
|
4143 |
|
4144 |
|
4145 |
|
4146 |
|
4147 |
|
4148 | var filePathame = hrefToPathname(href);
|
4149 | var filePath = pathnameToOperatingSystemPath(filePathame);
|
4150 |
|
4151 | if (href in importAbstractMap) {
|
4152 | return filePath;
|
4153 | }
|
4154 |
|
4155 |
|
4156 | if (href in importFallbackMap) {
|
4157 | return filePath;
|
4158 | }
|
4159 |
|
4160 | var stats;
|
4161 |
|
4162 | try {
|
4163 | stats = fs.statSync(filePath);
|
4164 | } catch (e) {
|
4165 | if (e.code === "ENOENT") {
|
4166 | throw new Error(createFileNotFoundForImportMessage({
|
4167 | path: filePath,
|
4168 | specifier: specifier,
|
4169 | importer: importer
|
4170 | }));
|
4171 | }
|
4172 |
|
4173 | throw e;
|
4174 | }
|
4175 |
|
4176 | if (!stats.isFile()) {
|
4177 | throw new Error(createUnexpectedStatsForImportMessage({
|
4178 | path: filePath,
|
4179 | stats: stats,
|
4180 | specifier: specifier,
|
4181 | importer: importer
|
4182 | }));
|
4183 | }
|
4184 |
|
4185 | return filePath;
|
4186 | }
|
4187 |
|
4188 | return href;
|
4189 | },
|
4190 |
|
4191 |
|
4192 |
|
4193 | load: _async$a(function (rollupId) {
|
4194 | var href = rollupIdToHref(rollupId);
|
4195 |
|
4196 | if (href in importAbstractMap) {
|
4197 | var generateSourceForImport = importAbstractMap[href];
|
4198 |
|
4199 | if (typeof generateSourceForImport !== "function") {
|
4200 | throw new Error("importAbstractMap values must be functions, found ".concat(generateSourceForImport, " for ").concat(href));
|
4201 | }
|
4202 |
|
4203 | return generateAbstractSourceForImport(href, generateSourceForImport);
|
4204 | }
|
4205 |
|
4206 | return _await$a(fetchHref(href), function (response) {
|
4207 | var responseStatus = response.status;
|
4208 |
|
4209 | if (!responseStatusIsOk(responseStatus)) {
|
4210 | if (responseStatus === 404 && href in importFallbackMap) {
|
4211 | return generateAbstractSourceForImport(href, importFallbackMap[href]);
|
4212 | }
|
4213 |
|
4214 | throw new Error(createUnexpectedResponseStatusMessage({
|
4215 | responseStatus: responseStatus,
|
4216 | href: href
|
4217 | }));
|
4218 | }
|
4219 |
|
4220 | var source = response.body;
|
4221 |
|
4222 | if (href.endsWith(".json")) {
|
4223 | source = "export default ".concat(source);
|
4224 | }
|
4225 |
|
4226 | var sourcemapParsingResult = parseSourceMappingURL(source);
|
4227 |
|
4228 | if (!sourcemapParsingResult) {
|
4229 | return {
|
4230 | code: source
|
4231 | };
|
4232 | }
|
4233 |
|
4234 | if (sourcemapParsingResult.sourcemapString) {
|
4235 | return {
|
4236 | code: source,
|
4237 | map: JSON.parse(sourcemapParsingResult.sourcemapString)
|
4238 | };
|
4239 | }
|
4240 |
|
4241 | var resolvedSourceMappingURL = url$1.resolve(href, sourcemapParsingResult.sourcemapURL);
|
4242 | return _await$a(fetchHref(resolvedSourceMappingURL), function (sourcemapResponse) {
|
4243 | var sourcemapResponseStatus = sourcemapResponse.status;
|
4244 |
|
4245 | if (!responseStatusIsOk(sourcemapResponse)) {
|
4246 | logger.warn(createUnexpectedResponseStatusMessage({
|
4247 | responseStatus: sourcemapResponseStatus,
|
4248 | href: resolvedSourceMappingURL
|
4249 | }));
|
4250 | return {
|
4251 | code: source
|
4252 | };
|
4253 | }
|
4254 |
|
4255 | return {
|
4256 | code: source,
|
4257 | map: JSON.parse(sourcemapResponse.body)
|
4258 | };
|
4259 | });
|
4260 | });
|
4261 | }),
|
4262 |
|
4263 | transform: _async$a(function (source, rollupId) {
|
4264 | var sourceHref = rollupIdToHref(rollupId);
|
4265 |
|
4266 | if (arrayOfHrefToSkipTransform.includes(sourceHref)) {
|
4267 | return null;
|
4268 | }
|
4269 |
|
4270 | var transform = _async$a(function () {
|
4271 | return _await$a(transformJs({
|
4272 | source: source,
|
4273 | sourceHref: sourceHref,
|
4274 | projectPathname: projectPathname,
|
4275 | babelPluginMap: babelPluginMap,
|
4276 | convertMap: convertMap,
|
4277 |
|
4278 | transformModuleIntoSystemFormat: false
|
4279 | }), function (_ref3) {
|
4280 | var code = _ref3.code,
|
4281 | map = _ref3.map;
|
4282 | return {
|
4283 | code: code,
|
4284 | map: map
|
4285 | };
|
4286 | });
|
4287 | });
|
4288 |
|
4289 | if (!cache || !sourceHref.startsWith("file://".concat(projectPathname, "/"))) {
|
4290 | return transform();
|
4291 | }
|
4292 |
|
4293 | var sourcePathname = hrefToPathname(sourceHref);
|
4294 | var sourceRelativePath = pathnameToRelativePath(sourcePathname, projectPathname);
|
4295 | return _await$a(getOrGenerateCompiledFile({
|
4296 | projectPathname: projectPathname,
|
4297 | compileCacheFolderRelativePath: compileCacheFolderRelativePath,
|
4298 | sourceRelativePath: sourceRelativePath,
|
4299 | compile: function () {
|
4300 | return _call$1(transform, function (transformResult) {
|
4301 | return transformResultToCompilationResult(transformResult, {
|
4302 | source: source,
|
4303 | sourceHref: sourceHref,
|
4304 | projectPathname: projectPathname
|
4305 | });
|
4306 | });
|
4307 | }
|
4308 | }), function (_ref4) {
|
4309 | var compileResult = _ref4.compileResult;
|
4310 | return compilationResultToTransformResult(compileResult);
|
4311 | });
|
4312 | }),
|
4313 | renderChunk: function renderChunk(source) {
|
4314 | if (!minify) return null;
|
4315 |
|
4316 | var minifyOptions = format === "global" ? {
|
4317 | toplevel: false
|
4318 | } : {
|
4319 | toplevel: true
|
4320 | };
|
4321 | var result = minifyCode(source, _objectSpread$1({
|
4322 | sourceMap: true
|
4323 | }, minifyOptions));
|
4324 |
|
4325 | if (result.error) {
|
4326 | throw result.error;
|
4327 | } else {
|
4328 | return result;
|
4329 | }
|
4330 | },
|
4331 | writeBundle: _async$a(function (bundle) {
|
4332 | return _invoke$2(function () {
|
4333 | if (detectAndTransformIfNeededAsyncInsertedByRollup) {
|
4334 | return _awaitIgnored$2(transformAsyncInsertedByRollup({
|
4335 | projectPathname: projectPathname,
|
4336 | bundleIntoRelativePath: bundleIntoRelativePath,
|
4337 | babelPluginMap: babelPluginMap,
|
4338 | bundle: bundle
|
4339 | }));
|
4340 | }
|
4341 | }, function () {
|
4342 | Object.keys(bundle).forEach(function (bundleFilename) {
|
4343 | logger.info("-> ".concat(projectPathname).concat(bundleIntoRelativePath, "/").concat(bundleFilename));
|
4344 | });
|
4345 | });
|
4346 | })
|
4347 | };
|
4348 |
|
4349 | var markHrefAsAbstract = function markHrefAsAbstract(href) {
|
4350 | if (!arrayOfAbstractHref.includes(href)) {
|
4351 | arrayOfAbstractHref.push(href);
|
4352 | }
|
4353 | };
|
4354 |
|
4355 | var generateAbstractSourceForImport = _async$a(function (href, generateSource) {
|
4356 | markHrefAsAbstract(href);
|
4357 | return _call$1(generateSource, function (returnValue) {
|
4358 | if (typeof returnValue === "string") {
|
4359 | return {
|
4360 | code: returnValue
|
4361 | };
|
4362 | }
|
4363 |
|
4364 | var skipTransform = returnValue.skipTransform,
|
4365 | code = returnValue.code,
|
4366 | map = returnValue.map;
|
4367 |
|
4368 | if (skipTransform) {
|
4369 | arrayOfHrefToSkipTransform.push(href);
|
4370 | }
|
4371 |
|
4372 | return {
|
4373 | code: code,
|
4374 | map: map
|
4375 | };
|
4376 | });
|
4377 | });
|
4378 |
|
4379 | var rollupIdToHref = function rollupIdToHref(rollupId) {
|
4380 | if (isWindowsPath(rollupId)) {
|
4381 | return "file://".concat(operatingSystemPathToPathname(rollupId));
|
4382 | }
|
4383 |
|
4384 | if (hrefToScheme(rollupId)) {
|
4385 | return rollupId;
|
4386 | }
|
4387 |
|
4388 | return "file://".concat(operatingSystemPathToPathname(rollupId));
|
4389 | };
|
4390 |
|
4391 | var fetchHref = _async$a(function (href) {
|
4392 | var _exit = false;
|
4393 |
|
4394 |
|
4395 |
|
4396 | return _invoke$2(function () {
|
4397 | if (href.startsWith("http://")) {
|
4398 | return _await$a(fetchUsingHttp(href, {
|
4399 | cancellationToken: cancellationToken
|
4400 | }), function (response) {
|
4401 | _exit = true;
|
4402 | return response;
|
4403 | });
|
4404 | }
|
4405 | }, function (_result) {
|
4406 | var _exit2 = false;
|
4407 | if (_exit) return _result;
|
4408 | return _invoke$2(function () {
|
4409 | if (href.startsWith("https://")) {
|
4410 | return _await$a(fetchUsingHttp(href, {
|
4411 | cancellationToken: cancellationToken
|
4412 | }), function (response) {
|
4413 | _exit2 = true;
|
4414 | return response;
|
4415 | });
|
4416 | }
|
4417 | }, function (_result2) {
|
4418 | var _exit3 = false;
|
4419 | if (_exit2) return _result2;
|
4420 | return _invoke$2(function () {
|
4421 | if (href.startsWith("file:///")) {
|
4422 | return _catch$1(function () {
|
4423 | return _await$a(createOperation({
|
4424 | cancellationToken: cancellationToken,
|
4425 | start: function start() {
|
4426 | return fileRead(pathnameToOperatingSystemPath(hrefToPathname(href)));
|
4427 | }
|
4428 | }), function (code) {
|
4429 | _exit3 = true;
|
4430 | return {
|
4431 | status: 200,
|
4432 | body: code
|
4433 | };
|
4434 | });
|
4435 | }, function (e) {
|
4436 | if (e.code === "ENOENT") {
|
4437 | _exit3 = true;
|
4438 | return {
|
4439 | status: 404
|
4440 | };
|
4441 | }
|
4442 |
|
4443 | _exit3 = true;
|
4444 | return {
|
4445 | status: 500
|
4446 | };
|
4447 | });
|
4448 | }
|
4449 | }, function (_result3) {
|
4450 | if (_exit3) return _result3;
|
4451 | throw new Error("unsupported href: ".concat(href));
|
4452 | });
|
4453 | });
|
4454 | });
|
4455 | });
|
4456 |
|
4457 | return {
|
4458 | jsenvRollupPlugin: jsenvRollupPlugin,
|
4459 | getArrayOfAbstractHref: getArrayOfAbstractHref
|
4460 | };
|
4461 | });
|
4462 | });
|
4463 | });
|
4464 | });
|
4465 |
|
4466 | var responseStatusIsOk = function responseStatusIsOk(responseStatus) {
|
4467 | return responseStatus >= 200 && responseStatus < 300;
|
4468 | };
|
4469 |
|
4470 | var createFileNotFoundForImportMessage = function createFileNotFoundForImportMessage(_ref5) {
|
4471 | var path = _ref5.path,
|
4472 | specifier = _ref5.specifier,
|
4473 | importer = _ref5.importer;
|
4474 | return "import file not found.\n--- path ---\n".concat(path, "\n--- specifier ---\n").concat(specifier, "\n--- importer ---\n").concat(importer);
|
4475 | };
|
4476 |
|
4477 | var createUnexpectedStatsForImportMessage = function createUnexpectedStatsForImportMessage(_ref6) {
|
4478 | var path = _ref6.path,
|
4479 | stats = _ref6.stats,
|
4480 | specifier = _ref6.specifier,
|
4481 | importer = _ref6.importer;
|
4482 | return "unexpected import file stats.\n--- path ---\n".concat(path, "\n--- found ---\n").concat(stats.isDirectory(), " ? 'directory' : 'not-a-file'\n--- specifier ---\n").concat(specifier, "\n--- importer ---\n").concat(importer);
|
4483 | };
|
4484 |
|
4485 | var createUnexpectedResponseStatusMessage = function createUnexpectedResponseStatusMessage(_ref7) {
|
4486 | var responseStatus = _ref7.responseStatus,
|
4487 | href = _ref7.href;
|
4488 | return "unexpected response status.\n--- response status ---\n".concat(responseStatus, "\n--- href ---\n").concat(href);
|
4489 | };
|
4490 |
|
4491 | var createMustBeInsideProjectMessage = function createMustBeInsideProjectMessage(_ref8) {
|
4492 | var href = _ref8.href,
|
4493 | specifier = _ref8.specifier,
|
4494 | importer = _ref8.importer,
|
4495 | projectPathname = _ref8.projectPathname;
|
4496 | return "\nsource must be inside project.\n--- href ---\n".concat(href, "\n--- specifier ---\n").concat(specifier, "\n--- importer ---\n").concat(importer, "\n--- project path ---\n").concat(pathnameToOperatingSystemPath(projectPathname));
|
4497 | };
|
4498 |
|
4499 | var createImporterOutsideProjectError = function createImporterOutsideProjectError(_ref9) {
|
4500 | var importer = _ref9.importer,
|
4501 | projectPathname = _ref9.projectPathname;
|
4502 | return new Error("importer must be inside project\n importer: ".concat(importer, "\n project: ").concat(pathnameToOperatingSystemPath(projectPathname)));
|
4503 | };
|
4504 |
|
4505 | var transformAsyncInsertedByRollup = _async$a(function (_ref10) {
|
4506 | var projectPathname = _ref10.projectPathname,
|
4507 | bundleIntoRelativePath = _ref10.bundleIntoRelativePath,
|
4508 | babelPluginMap = _ref10.babelPluginMap,
|
4509 | bundle = _ref10.bundle;
|
4510 | var bundleFolderPathname = "".concat(projectPathname).concat(bundleIntoRelativePath);
|
4511 | var asyncPluginName = findAsyncPluginNameInBabelPluginMap(babelPluginMap);
|
4512 | if (!asyncPluginName) return;
|
4513 |
|
4514 |
|
4515 |
|
4516 | return _awaitIgnored$2(Promise.all(Object.keys(bundle).map(_async$a(function (bundleFilename) {
|
4517 | var bundleInfo = bundle[bundleFilename];
|
4518 | return _await$a(transformJs({
|
4519 | projectPathname: projectPathname,
|
4520 | source: bundleInfo.code,
|
4521 | sourceHref: "file://".concat(operatingSystemPathToPathname(bundleFilename)),
|
4522 | sourceMap: bundleInfo.map,
|
4523 | babelPluginMap: _defineProperty({}, asyncPluginName, babelPluginMap[asyncPluginName]),
|
4524 | transformModuleIntoSystemFormat: false,
|
4525 |
|
4526 | transformGenerator: false
|
4527 |
|
4528 | }), function (_ref11) {
|
4529 | var code = _ref11.code,
|
4530 | map = _ref11.map;
|
4531 | return _awaitIgnored$2(Promise.all([fileWrite(pathnameToOperatingSystemPath("".concat(bundleFolderPathname, "/").concat(bundleFilename)), writeSourceMappingURL(code, "./".concat(bundleFilename, ".map"))), fileWrite(pathnameToOperatingSystemPath("".concat(bundleFolderPathname, "/").concat(bundleFilename, ".map")), JSON.stringify(map))]));
|
4532 | });
|
4533 | }))));
|
4534 | });
|
4535 |
|
4536 | function _await$b(value, then, direct) {
|
4537 | if (direct) {
|
4538 | return then ? then(value) : value;
|
4539 | }
|
4540 |
|
4541 | if (!value || !value.then) {
|
4542 | value = Promise.resolve(value);
|
4543 | }
|
4544 |
|
4545 | return then ? value.then(then) : value;
|
4546 | }
|
4547 |
|
4548 | var _require2$b = nodeRequire("rollup"),
|
4549 | rollup = _require2$b.rollup;
|
4550 |
|
4551 | function _async$b(f) {
|
4552 | return function () {
|
4553 | for (var args = [], i = 0; i < arguments.length; i++) {
|
4554 | args[i] = arguments[i];
|
4555 | }
|
4556 |
|
4557 | try {
|
4558 | return Promise.resolve(f.apply(this, args));
|
4559 | } catch (e) {
|
4560 | return Promise.reject(e);
|
4561 | }
|
4562 | };
|
4563 | }
|
4564 |
|
4565 | var generateBundleUsingRollup = _async$b(function (_ref) {
|
4566 | var cancellationToken = _ref.cancellationToken,
|
4567 | rollupParseOptions = _ref.rollupParseOptions,
|
4568 | rollupGenerateOptions = _ref.rollupGenerateOptions,
|
4569 | writeOnFileSystem = _ref.writeOnFileSystem;
|
4570 | return _await$b(createOperation({
|
4571 | cancellationToken: cancellationToken,
|
4572 | start: function start() {
|
4573 | return rollup(_objectSpread$1({
|
4574 |
|
4575 |
|
4576 |
|
4577 |
|
4578 |
|
4579 |
|
4580 |
|
4581 |
|
4582 | experimentalTopLevelAwait: true,
|
4583 |
|
4584 |
|
4585 |
|
4586 | onwarn: function onwarn(warning, warn) {
|
4587 | if (warning.code === "THIS_IS_UNDEFINED") return;
|
4588 | warn(warning);
|
4589 | }
|
4590 | }, rollupParseOptions));
|
4591 | }
|
4592 | }), function (rollupBundle) {
|
4593 | return _await$b(createOperation({
|
4594 | cancellationToken: cancellationToken,
|
4595 | start: function start() {
|
4596 | if (writeOnFileSystem) {
|
4597 | return rollupBundle.write(_objectSpread$1({
|
4598 |
|
4599 | experimentalTopLevelAwait: true,
|
4600 |
|
4601 |
|
4602 | preferConst: false
|
4603 | }, rollupGenerateOptions));
|
4604 | }
|
4605 |
|
4606 | return rollupBundle.generate(_objectSpread$1({
|
4607 |
|
4608 | experimentalTopLevelAwait: true,
|
4609 |
|
4610 |
|
4611 | preferConst: false
|
4612 | }, rollupGenerateOptions));
|
4613 | }
|
4614 | }));
|
4615 | });
|
4616 | });
|
4617 |
|
4618 | var formatToRollupFormat = function formatToRollupFormat(format) {
|
4619 | if (format === "global") return "iife";
|
4620 | if (format === "commonjs") return "cjs";
|
4621 | if (format === "systemjs") return "system";
|
4622 | throw new Error("unexpected format, got ".concat(format));
|
4623 | };
|
4624 |
|
4625 | function _await$c(value, then, direct) {
|
4626 | if (direct) {
|
4627 | return then ? then(value) : value;
|
4628 | }
|
4629 |
|
4630 | if (!value || !value.then) {
|
4631 | value = Promise.resolve(value);
|
4632 | }
|
4633 |
|
4634 | return then ? value.then(then) : value;
|
4635 | }
|
4636 |
|
4637 | function _async$c(f) {
|
4638 | return function () {
|
4639 | for (var args = [], i = 0; i < arguments.length; i++) {
|
4640 | args[i] = arguments[i];
|
4641 | }
|
4642 |
|
4643 | try {
|
4644 | return Promise.resolve(f.apply(this, args));
|
4645 | } catch (e) {
|
4646 | return Promise.reject(e);
|
4647 | }
|
4648 | };
|
4649 | }
|
4650 |
|
4651 | var bundleWithoutBalancing = _async$c(function (_ref) {
|
4652 | var cancellationToken = _ref.cancellationToken,
|
4653 | projectPathname = _ref.projectPathname,
|
4654 | bundleIntoRelativePath = _ref.bundleIntoRelativePath,
|
4655 | cache = _ref.cache,
|
4656 | cacheRelativePath = _ref.cacheRelativePath,
|
4657 | importDefaultExtension = _ref.importDefaultExtension,
|
4658 | importMapRelativePath = _ref.importMapRelativePath,
|
4659 | importMapForBundle = _ref.importMapForBundle,
|
4660 | importAbstractMap = _ref.importAbstractMap,
|
4661 | importFallbackMap = _ref.importFallbackMap,
|
4662 | nativeModulePredicate = _ref.nativeModulePredicate,
|
4663 | entryPointMap = _ref.entryPointMap,
|
4664 | babelPluginMap = _ref.babelPluginMap,
|
4665 | convertMap = _ref.convertMap,
|
4666 | minify = _ref.minify,
|
4667 | logLevel = _ref.logLevel,
|
4668 | format = _ref.format,
|
4669 | formatOutputOptions = _ref.formatOutputOptions,
|
4670 | writeOnFileSystem = _ref.writeOnFileSystem;
|
4671 | var logger = createLogger({
|
4672 | logLevel: logLevel
|
4673 | });
|
4674 | var dir = pathnameToOperatingSystemPath("".concat(projectPathname).concat(bundleIntoRelativePath));
|
4675 | return _await$c(createJsenvRollupPlugin({
|
4676 | cancellationToken: cancellationToken,
|
4677 | projectPathname: projectPathname,
|
4678 | bundleIntoRelativePath: bundleIntoRelativePath,
|
4679 | cache: cache,
|
4680 | cacheRelativePath: cacheRelativePath,
|
4681 | entryPointMap: entryPointMap,
|
4682 | importDefaultExtension: importDefaultExtension,
|
4683 | importMapRelativePath: importMapRelativePath,
|
4684 | importMapForBundle: importMapForBundle,
|
4685 | importAbstractMap: importAbstractMap,
|
4686 | importFallbackMap: importFallbackMap,
|
4687 | babelPluginMap: babelPluginMap,
|
4688 | convertMap: convertMap,
|
4689 | featureNameArray: Object.keys(babelPluginMap),
|
4690 | minify: minify,
|
4691 | format: format,
|
4692 | logger: logger
|
4693 | }), function (_ref2) {
|
4694 | var jsenvRollupPlugin = _ref2.jsenvRollupPlugin,
|
4695 | getArrayOfAbstractHref = _ref2.getArrayOfAbstractHref;
|
4696 | logger.trace("\nbundle entry points without balancing.\nformat: ".concat(format, "\nentry point names: ").concat(Object.keys(entryPointMap), "\ndir: ").concat(dir, "\nminify: ").concat(minify, "\n"));
|
4697 | return _await$c(generateBundleUsingRollup({
|
4698 | cancellationToken: cancellationToken,
|
4699 | writeOnFileSystem: writeOnFileSystem,
|
4700 | rollupParseOptions: {
|
4701 | input: entryPointMap,
|
4702 | plugins: [jsenvRollupPlugin],
|
4703 | external: function external(id) {
|
4704 | return nativeModulePredicate(id);
|
4705 | }
|
4706 | },
|
4707 | rollupGenerateOptions: _objectSpread$1({
|
4708 |
|
4709 | dir: dir,
|
4710 |
|
4711 | format: formatToRollupFormat(format),
|
4712 |
|
4713 |
|
4714 | sourcemap: true,
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 | sourcemapExcludeSources: false
|
4720 | }, formatOutputOptions)
|
4721 | }), function (rollupBundle) {
|
4722 | return {
|
4723 | rollupBundle: rollupBundle,
|
4724 | arrayOfAbstractHref: getArrayOfAbstractHref()
|
4725 | };
|
4726 | });
|
4727 | });
|
4728 | });
|
4729 |
|
4730 | function _await$d(value, then, direct) {
|
4731 | if (direct) {
|
4732 | return then ? then(value) : value;
|
4733 | }
|
4734 |
|
4735 | if (!value || !value.then) {
|
4736 | value = Promise.resolve(value);
|
4737 | }
|
4738 |
|
4739 | return then ? value.then(then) : value;
|
4740 | }
|
4741 |
|
4742 | function _async$d(f) {
|
4743 | return function () {
|
4744 | for (var args = [], i = 0; i < arguments.length; i++) {
|
4745 | args[i] = arguments[i];
|
4746 | }
|
4747 |
|
4748 | try {
|
4749 | return Promise.resolve(f.apply(this, args));
|
4750 | } catch (e) {
|
4751 | return Promise.reject(e);
|
4752 | }
|
4753 | };
|
4754 | }
|
4755 |
|
4756 | var bundleWithBalancing = _async$d(function (_ref) {
|
4757 | var cancellationToken = _ref.cancellationToken,
|
4758 | projectPathname = _ref.projectPathname,
|
4759 | bundleIntoRelativePath = _ref.bundleIntoRelativePath,
|
4760 | cache = _ref.cache,
|
4761 | cacheRelativePath = _ref.cacheRelativePath,
|
4762 | importDefaultExtension = _ref.importDefaultExtension,
|
4763 | importMapRelativePath = _ref.importMapRelativePath,
|
4764 | importMapForBundle = _ref.importMapForBundle,
|
4765 | importAbstractMap = _ref.importAbstractMap,
|
4766 | importFallbackMap = _ref.importFallbackMap,
|
4767 | nativeModulePredicate = _ref.nativeModulePredicate,
|
4768 | entryPointMap = _ref.entryPointMap,
|
4769 | babelPluginMap = _ref.babelPluginMap,
|
4770 | convertMap = _ref.convertMap,
|
4771 | minify = _ref.minify,
|
4772 | logLevel = _ref.logLevel,
|
4773 | format = _ref.format,
|
4774 | formatOutputOptions = _ref.formatOutputOptions,
|
4775 | groupMap = _ref.groupMap,
|
4776 | compileId = _ref.compileId,
|
4777 | writeOnFileSystem = _ref.writeOnFileSystem;
|
4778 | var logger = createLogger({
|
4779 | logLevel: logLevel
|
4780 | });
|
4781 | var dir = pathnameToOperatingSystemPath("".concat(projectPathname).concat(bundleIntoRelativePath, "/").concat(compileId));
|
4782 | return _await$d(createJsenvRollupPlugin({
|
4783 | cancellationToken: cancellationToken,
|
4784 | projectPathname: projectPathname,
|
4785 | bundleIntoRelativePath: "".concat(bundleIntoRelativePath, "/").concat(compileId),
|
4786 | cache: cache,
|
4787 | cacheRelativePath: cacheRelativePath,
|
4788 | entryPointMap: entryPointMap,
|
4789 | importDefaultExtension: importDefaultExtension,
|
4790 | importMapRelativePath: importMapRelativePath,
|
4791 | importMapForBundle: importMapForBundle,
|
4792 | importAbstractMap: importAbstractMap,
|
4793 | importFallbackMap: importFallbackMap,
|
4794 | babelPluginMap: babelPluginMap,
|
4795 | convertMap: convertMap,
|
4796 | featureNameArray: groupMap[compileId].incompatibleNameArray,
|
4797 | minify: minify,
|
4798 | format: format,
|
4799 | logger: logger
|
4800 | }), function (_ref2) {
|
4801 | var jsenvRollupPlugin = _ref2.jsenvRollupPlugin,
|
4802 | getArrayOfAbstractHref = _ref2.getArrayOfAbstractHref;
|
4803 | logger.trace("\n bundle entry points with balancing.\n format: ".concat(format, "\n compileId: ").concat(compileId, "\n entryPointArray: ").concat(Object.keys(entryPointMap), "\n dir: ").concat(dir, "\n minify: ").concat(minify, "\n "));
|
4804 | return _await$d(generateBundleUsingRollup({
|
4805 | cancellationToken: cancellationToken,
|
4806 | writeOnFileSystem: writeOnFileSystem,
|
4807 | rollupParseOptions: {
|
4808 | input: entryPointMap,
|
4809 | plugins: [jsenvRollupPlugin],
|
4810 | external: function external(id) {
|
4811 | return nativeModulePredicate(id);
|
4812 | }
|
4813 | },
|
4814 | rollupGenerateOptions: _objectSpread$1({
|
4815 | dir: dir,
|
4816 | format: formatToRollupFormat(format),
|
4817 | sourcemap: true,
|
4818 | sourceMapExcludeSources: true
|
4819 | }, formatOutputOptions)
|
4820 | }), function (rollupBundle) {
|
4821 | return {
|
4822 | rollupBundle: rollupBundle,
|
4823 | arrayOfAbstractHref: getArrayOfAbstractHref()
|
4824 | };
|
4825 | });
|
4826 | });
|
4827 | });
|
4828 |
|
4829 | function _await$e(value, then, direct) {
|
4830 | if (direct) {
|
4831 | return then ? then(value) : value;
|
4832 | }
|
4833 |
|
4834 | if (!value || !value.then) {
|
4835 | value = Promise.resolve(value);
|
4836 | }
|
4837 |
|
4838 | return then ? value.then(then) : value;
|
4839 | }
|
4840 |
|
4841 | function _async$e(f) {
|
4842 | return function () {
|
4843 | for (var args = [], i = 0; i < arguments.length; i++) {
|
4844 | args[i] = arguments[i];
|
4845 | }
|
4846 |
|
4847 | try {
|
4848 | return Promise.resolve(f.apply(this, args));
|
4849 | } catch (e) {
|
4850 | return Promise.reject(e);
|
4851 | }
|
4852 | };
|
4853 | }
|
4854 |
|
4855 | var bundleBalancer = _async$e(function (_ref) {
|
4856 | var cancellationToken = _ref.cancellationToken,
|
4857 | projectPathname = _ref.projectPathname,
|
4858 | bundleIntoRelativePath = _ref.bundleIntoRelativePath,
|
4859 | cache = _ref.cache,
|
4860 | cacheRelativePath = _ref.cacheRelativePath,
|
4861 | importDefaultExtension = _ref.importDefaultExtension,
|
4862 | importMapRelativePath = _ref.importMapRelativePath,
|
4863 | importMapForBundle = _ref.importMapForBundle,
|
4864 | importAbstractMap = _ref.importAbstractMap,
|
4865 | importFallbackMap = _ref.importFallbackMap,
|
4866 | nativeModulePredicate = _ref.nativeModulePredicate,
|
4867 | entryPointMap = _ref.entryPointMap,
|
4868 | babelPluginMap = _ref.babelPluginMap,
|
4869 | convertMap = _ref.convertMap,
|
4870 | minify = _ref.minify,
|
4871 | logLevel = _ref.logLevel,
|
4872 | format = _ref.format,
|
4873 | balancerDataAbstractPath = _ref.balancerDataAbstractPath,
|
4874 | groupMap = _ref.groupMap,
|
4875 | writeOnFileSystem = _ref.writeOnFileSystem;
|
4876 | var logger = createLogger({
|
4877 | logLevel: logLevel
|
4878 | });
|
4879 | var entryPointName = Object.keys(entryPointMap)[0];
|
4880 | var dir = pathnameToOperatingSystemPath("".concat(projectPathname).concat(bundleIntoRelativePath));
|
4881 | var balancerDataHref = "file://".concat(jsenvBundlingProjectPathname).concat(balancerDataAbstractPath);
|
4882 | return _await$e(createJsenvRollupPlugin({
|
4883 | cancellationToken: cancellationToken,
|
4884 | projectPathname: projectPathname,
|
4885 | bundleIntoRelativePath: bundleIntoRelativePath,
|
4886 | cache: cache,
|
4887 | cacheRelativePath: cacheRelativePath,
|
4888 | entryPointMap: entryPointMap,
|
4889 | importDefaultExtension: importDefaultExtension,
|
4890 | importMapRelativePath: importMapRelativePath,
|
4891 | importMapForBundle: composeTwoImportMaps(importMapForBundle || {}, {
|
4892 | imports: _defineProperty({}, balancerDataAbstractPath, balancerDataHref)
|
4893 | }),
|
4894 | importAbstractMap: _objectSpread$1({}, importAbstractMap, _defineProperty({}, balancerDataHref, function () {
|
4895 | return "export const entryPointName = ".concat(JSON.stringify(entryPointName), "\n export const groupMap = ").concat(JSON.stringify(groupMap));
|
4896 | })),
|
4897 | importFallbackMap: importFallbackMap,
|
4898 | babelPluginMap: babelPluginMap,
|
4899 | convertMap: convertMap,
|
4900 | featureNameArray: groupMap.otherwise.incompatibleNameArray,
|
4901 | minify: minify,
|
4902 | format: format,
|
4903 | logger: logger
|
4904 | }), function (_ref2) {
|
4905 | var jsenvRollupPlugin = _ref2.jsenvRollupPlugin,
|
4906 | getArrayOfAbstractHref = _ref2.getArrayOfAbstractHref;
|
4907 | logger.trace("\n bundle balancer file.\n format: ".concat(format, "\n entryPointName: ").concat(entryPointName, "\n file: ").concat(dir, "/").concat(entryPointName, ".js\n minify: ").concat(minify, "\n "));
|
4908 | return _await$e(generateBundleUsingRollup({
|
4909 | cancellationToken: cancellationToken,
|
4910 | writeOnFileSystem: writeOnFileSystem,
|
4911 | rollupParseOptions: {
|
4912 | input: entryPointMap,
|
4913 | plugins: [jsenvRollupPlugin],
|
4914 | external: function external(id) {
|
4915 | return nativeModulePredicate(id);
|
4916 | }
|
4917 | },
|
4918 | rollupGenerateOptions: {
|
4919 | dir: dir,
|
4920 | format: "iife",
|
4921 | sourcemap: true,
|
4922 | sourcemapExcludeSources: true
|
4923 | }
|
4924 | }), function (rollupBundle) {
|
4925 | return {
|
4926 | rollupBundle: rollupBundle,
|
4927 | arrayOfAbstractHref: getArrayOfAbstractHref()
|
4928 | };
|
4929 | });
|
4930 | });
|
4931 | });
|
4932 |
|
4933 | var rimraf$1 = nodeRequire("rimraf");
|
4934 |
|
4935 | var removeFolder = function removeFolder(foldername) {
|
4936 | return new Promise(function (resolve, reject) {
|
4937 | return rimraf$1(foldername, function (error) {
|
4938 | if (error) reject(error);else resolve();
|
4939 | });
|
4940 | });
|
4941 | };
|
4942 |
|
4943 | var _require2$c = nodeRequire("@jsenv/babel-plugin-map"),
|
4944 | jsenvBabelPluginMap = _require2$c.jsenvBabelPluginMap;
|
4945 |
|
4946 | var DEFAULT_IMPORT_MAP_RELATIVE_PATH = "/importMap.json";
|
4947 | var DEFAULT_ENTRY_POINT_MAP = {
|
4948 | main: "index.js"
|
4949 | };
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 | var NATIVE_NODE_MODULE_SPECIFIER_ARRAY = ["assert", "async_hooks", "buffer_ieee754", "buffer", "child_process", "cluster", "console", "constants", "crypto", "_debugger", "dgram", "dns", "domain", "events", "freelist", "fs", "fs/promises", "_http_agent", "_http_client", "_http_common", "_http_incoming", "_http_outgoing", "_http_server", "http", "http2", "https", "inspector", "_linklist", "module", "net", "node-inspect/lib/_inspect", "node-inspect/lib/internal/inspect_client", "node-inspect/lib/internal/inspect_repl", "os", "path", "perf_hooks", "process", "punycode", "querystring", "readline", "repl", "smalloc", "_stream_duplex", "_stream_transform", "_stream_wrap", "_stream_passthrough", "_stream_readable", "_stream_writable", "stream", "string_decoder", "sys", "timers", "_tls_common", "_tls_legacy", "_tls_wrap", "tls", "trace_events", "tty", "url", "util", "v8/tools/arguments", "v8/tools/codemap", "v8/tools/consarray", "v8/tools/csvparser", "v8/tools/logreader", "v8/tools/profile_view", "v8/tools/splaytree", "v8", "vm", "worker_threads", "zlib",
|
4955 | "global"];
|
4956 | var DEFAULT_NATIVE_MODULE_PREDICATE = function DEFAULT_NATIVE_MODULE_PREDICATE(id) {
|
4957 | if (id === "global") return false;
|
4958 | if (NATIVE_NODE_MODULE_SPECIFIER_ARRAY.includes(id)) return true;
|
4959 | return false;
|
4960 | };
|
4961 | var DEFAULT_BABEL_PLUGIN_MAP = jsenvBabelPluginMap;
|
4962 | var DEFAULT_PLATFORM_SCORE_MAP = _objectSpread$1({}, browserScoreMap, {
|
4963 | node: nodeVersionScoreMap
|
4964 | });
|
4965 |
|
4966 | function _empty$4() {}
|
4967 |
|
4968 | function _awaitIgnored$3(value, direct) {
|
4969 | if (!direct) {
|
4970 | return value && value.then ? value.then(_empty$4) : Promise.resolve();
|
4971 | }
|
4972 | }
|
4973 |
|
4974 | function _await$f(value, then, direct) {
|
4975 | if (direct) {
|
4976 | return then ? then(value) : value;
|
4977 | }
|
4978 |
|
4979 | if (!value || !value.then) {
|
4980 | value = Promise.resolve(value);
|
4981 | }
|
4982 |
|
4983 | return then ? value.then(then) : value;
|
4984 | }
|
4985 |
|
4986 | function _invoke$3(body, then) {
|
4987 | var result = body();
|
4988 |
|
4989 | if (result && result.then) {
|
4990 | return result.then(then);
|
4991 | }
|
4992 |
|
4993 | return then(result);
|
4994 | }
|
4995 |
|
4996 | function _async$f(f) {
|
4997 | return function () {
|
4998 | for (var args = [], i = 0; i < arguments.length; i++) {
|
4999 | args[i] = arguments[i];
|
5000 | }
|
5001 |
|
5002 | try {
|
5003 | return Promise.resolve(f.apply(this, args));
|
5004 | } catch (e) {
|
5005 | return Promise.reject(e);
|
5006 | }
|
5007 | };
|
5008 | }
|
5009 |
|
5010 | var generateBundle = function generateBundle(_ref) {
|
5011 | var projectPath = _ref.projectPath,
|
5012 | bundleIntoRelativePath = _ref.bundleIntoRelativePath,
|
5013 | _ref$cleanBundleInto = _ref.cleanBundleInto,
|
5014 | cleanBundleInto = _ref$cleanBundleInto === void 0 ? false : _ref$cleanBundleInto,
|
5015 | _ref$cache = _ref.cache,
|
5016 | cache = _ref$cache === void 0 ? false : _ref$cache,
|
5017 | _ref$cacheRelativePat = _ref.cacheRelativePath,
|
5018 | cacheRelativePath = _ref$cacheRelativePat === void 0 ? "/.cache" : _ref$cacheRelativePat,
|
5019 | importDefaultExtension = _ref.importDefaultExtension,
|
5020 | _ref$importMapRelativ = _ref.importMapRelativePath,
|
5021 | importMapRelativePath = _ref$importMapRelativ === void 0 ? DEFAULT_IMPORT_MAP_RELATIVE_PATH : _ref$importMapRelativ,
|
5022 | _ref$importMapForBund = _ref.importMapForBundle,
|
5023 | importMapForBundle = _ref$importMapForBund === void 0 ? {} : _ref$importMapForBund,
|
5024 | _ref$importAbstractMa = _ref.importAbstractMap,
|
5025 | importAbstractMap = _ref$importAbstractMa === void 0 ? {} : _ref$importAbstractMa,
|
5026 | _ref$importFallbackMa = _ref.importFallbackMap,
|
5027 | importFallbackMap = _ref$importFallbackMa === void 0 ? {} : _ref$importFallbackMa,
|
5028 | _ref$nativeModulePred = _ref.nativeModulePredicate,
|
5029 | nativeModulePredicate = _ref$nativeModulePred === void 0 ? DEFAULT_NATIVE_MODULE_PREDICATE : _ref$nativeModulePred,
|
5030 | _ref$entryPointMap = _ref.entryPointMap,
|
5031 | entryPointMap = _ref$entryPointMap === void 0 ? DEFAULT_ENTRY_POINT_MAP : _ref$entryPointMap,
|
5032 | _ref$babelPluginMap = _ref.babelPluginMap,
|
5033 | babelPluginMap = _ref$babelPluginMap === void 0 ? DEFAULT_BABEL_PLUGIN_MAP : _ref$babelPluginMap,
|
5034 | convertMap = _ref.convertMap,
|
5035 | logLevel = _ref.logLevel,
|
5036 | _ref$minify = _ref.minify,
|
5037 | minify = _ref$minify === void 0 ? false : _ref$minify,
|
5038 | _ref$writeOnFileSyste = _ref.writeOnFileSystem,
|
5039 | writeOnFileSystem = _ref$writeOnFileSyste === void 0 ? true : _ref$writeOnFileSyste,
|
5040 | _ref$throwUnhandled = _ref.throwUnhandled,
|
5041 | throwUnhandled = _ref$throwUnhandled === void 0 ? true : _ref$throwUnhandled,
|
5042 | format = _ref.format,
|
5043 | _ref$formatOutputOpti = _ref.formatOutputOptions,
|
5044 | formatOutputOptions = _ref$formatOutputOpti === void 0 ? {} : _ref$formatOutputOpti,
|
5045 | _ref$compileGroupCoun = _ref.compileGroupCount,
|
5046 | compileGroupCount = _ref$compileGroupCoun === void 0 ? 1 : _ref$compileGroupCoun,
|
5047 | platformAlwaysInsidePlatformScoreMap = _ref.platformAlwaysInsidePlatformScoreMap,
|
5048 | balancerTemplateRelativePath = _ref.balancerTemplateRelativePath,
|
5049 | defaultBalancerTemplateHref = _ref.defaultBalancerTemplateHref,
|
5050 | balancerDataAbstractPath = _ref.balancerDataAbstractPath,
|
5051 | _ref$platformScoreMap = _ref.platformScoreMap,
|
5052 | platformScoreMap = _ref$platformScoreMap === void 0 ? DEFAULT_PLATFORM_SCORE_MAP : _ref$platformScoreMap;
|
5053 | var promise = catchAsyncFunctionCancellation(_async$f(function () {
|
5054 | if (typeof projectPath !== "string") throw new TypeError("projectPath must be a string, got ".concat(projectPath));
|
5055 | if (typeof bundleIntoRelativePath !== "string") throw new TypeError("bundleIntoRelativePath must be a string, got ".concat(bundleIntoRelativePath));
|
5056 | if (_typeof(entryPointMap) !== "object") throw new TypeError("entryPointMap must be an object, got ".concat(entryPointMap));
|
5057 | if (typeof compileGroupCount !== "number") throw new TypeError("compileGroupCount must be a number, got ".concat(compileGroupCount));
|
5058 | if (compileGroupCount < 1) throw new Error("compileGroupCount must be >= 1, got ".concat(compileGroupCount));
|
5059 | var cancellationToken = createProcessInterruptionCancellationToken();
|
5060 | var projectPathname = operatingSystemPathToPathname(projectPath);
|
5061 | return _await$f(assertFolder(projectPathname), function () {
|
5062 | return _invoke$3(function () {
|
5063 | if (cleanBundleInto) {
|
5064 | return _awaitIgnored$3(removeFolder(pathnameToOperatingSystemPath("".concat(projectPathname).concat(bundleIntoRelativePath))));
|
5065 | }
|
5066 | }, function () {
|
5067 | if (compileGroupCount === 1) {
|
5068 | return bundleWithoutBalancing({
|
5069 | cancellationToken: cancellationToken,
|
5070 | projectPathname: projectPathname,
|
5071 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5072 | cache: cache,
|
5073 | cacheRelativePath: cacheRelativePath,
|
5074 | importDefaultExtension: importDefaultExtension,
|
5075 | importMapRelativePath: importMapRelativePath,
|
5076 | importMapForBundle: importMapForBundle,
|
5077 | importAbstractMap: importAbstractMap,
|
5078 | importFallbackMap: importFallbackMap,
|
5079 | nativeModulePredicate: nativeModulePredicate,
|
5080 | entryPointMap: entryPointMap,
|
5081 | babelPluginMap: babelPluginMap,
|
5082 | convertMap: convertMap,
|
5083 | minify: minify,
|
5084 | logLevel: logLevel,
|
5085 | format: format,
|
5086 | formatOutputOptions: formatOutputOptions,
|
5087 | writeOnFileSystem: writeOnFileSystem
|
5088 | });
|
5089 | }
|
5090 |
|
5091 | if (typeof balancerTemplateRelativePath === "undefined") {
|
5092 | if (!defaultBalancerTemplateHref) {
|
5093 | throw createFormatIncompatibleWithBalancingError({
|
5094 | format: format
|
5095 | });
|
5096 | }
|
5097 |
|
5098 | balancerTemplateRelativePath = jsenvBundlingRelativePathInception({
|
5099 | jsenvBundlingRelativePath: defaultBalancerTemplateHref,
|
5100 | projectPathname: projectPathname
|
5101 | });
|
5102 | }
|
5103 |
|
5104 | var balancerTemplatePathname = "".concat(projectPathname).concat(balancerTemplateRelativePath);
|
5105 | var balancerTemplateHref = "file://".concat(balancerTemplatePathname);
|
5106 | return _await$f(assertFile(pathnameToOperatingSystemPath(balancerTemplatePathname)), function () {
|
5107 | var groupMap = generateGroupMap({
|
5108 | babelPluginMap: babelPluginMap,
|
5109 | platformScoreMap: platformScoreMap,
|
5110 | groupCount: compileGroupCount,
|
5111 | platformAlwaysInsidePlatformScoreMap: platformAlwaysInsidePlatformScoreMap
|
5112 | });
|
5113 | return _await$f(Promise.all([generateEntryPointsFolders({
|
5114 | cancellationToken: cancellationToken,
|
5115 | projectPathname: projectPathname,
|
5116 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5117 | cache: cache,
|
5118 | cacheRelativePath: cacheRelativePath,
|
5119 | importDefaultExtension: importDefaultExtension,
|
5120 | importMapRelativePath: importMapRelativePath,
|
5121 | importMapForBundle: importMapForBundle,
|
5122 | importAbstractMap: importAbstractMap,
|
5123 | importFallbackMap: importFallbackMap,
|
5124 | nativeModulePredicate: nativeModulePredicate,
|
5125 | entryPointMap: entryPointMap,
|
5126 | babelPluginMap: babelPluginMap,
|
5127 | convertMap: convertMap,
|
5128 | minify: minify,
|
5129 | logLevel: logLevel,
|
5130 | writeOnFileSystem: writeOnFileSystem,
|
5131 | format: format,
|
5132 | formatOutputOptions: formatOutputOptions,
|
5133 | groupMap: groupMap
|
5134 | }), generateEntryPointsBalancerFiles({
|
5135 | cancellationToken: cancellationToken,
|
5136 | projectPathname: projectPathname,
|
5137 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5138 | cache: cache,
|
5139 | cacheRelativePath: cacheRelativePath,
|
5140 | importDefaultExtension: importDefaultExtension,
|
5141 | importMapRelativePath: importMapRelativePath,
|
5142 | importMapForBundle: importMapForBundle,
|
5143 | importAbstractMap: importAbstractMap,
|
5144 | importFallbackMap: importFallbackMap,
|
5145 | nativeModulePredicate: nativeModulePredicate,
|
5146 | entryPointMap: entryPointMap,
|
5147 | babelPluginMap: babelPluginMap,
|
5148 | convertMap: convertMap,
|
5149 | minify: minify,
|
5150 | logLevel: logLevel,
|
5151 | writeOnFileSystem: writeOnFileSystem,
|
5152 | format: format,
|
5153 | balancerTemplateHref: balancerTemplateHref,
|
5154 | balancerDataAbstractPath: balancerDataAbstractPath,
|
5155 | groupMap: groupMap
|
5156 | })]));
|
5157 | });
|
5158 | });
|
5159 | });
|
5160 | }));
|
5161 | if (!throwUnhandled) return promise;
|
5162 | return promise.catch(function (e) {
|
5163 | setTimeout(function () {
|
5164 | throw e;
|
5165 | });
|
5166 | });
|
5167 | };
|
5168 |
|
5169 | var generateEntryPointsFolders = _async$f(function (_ref2) {
|
5170 | var cancellationToken = _ref2.cancellationToken,
|
5171 | projectPathname = _ref2.projectPathname,
|
5172 | bundleIntoRelativePath = _ref2.bundleIntoRelativePath,
|
5173 | cache = _ref2.cache,
|
5174 | cacheRelativePath = _ref2.cacheRelativePath,
|
5175 | importDefaultExtension = _ref2.importDefaultExtension,
|
5176 | importMapRelativePath = _ref2.importMapRelativePath,
|
5177 | importMapForBundle = _ref2.importMapForBundle,
|
5178 | importAbstractMap = _ref2.importAbstractMap,
|
5179 | importFallbackMap = _ref2.importFallbackMap,
|
5180 | nativeModulePredicate = _ref2.nativeModulePredicate,
|
5181 | entryPointMap = _ref2.entryPointMap,
|
5182 | babelPluginMap = _ref2.babelPluginMap,
|
5183 | convertMap = _ref2.convertMap,
|
5184 | minify = _ref2.minify,
|
5185 | logLevel = _ref2.logLevel,
|
5186 | writeOnFileSystem = _ref2.writeOnFileSystem,
|
5187 | format = _ref2.format,
|
5188 | formatOutputOptions = _ref2.formatOutputOptions,
|
5189 | groupMap = _ref2.groupMap;
|
5190 | return Promise.all(Object.keys(groupMap).map(_async$f(function (compileId) {
|
5191 | return bundleWithBalancing({
|
5192 | cancellationToken: cancellationToken,
|
5193 | projectPathname: projectPathname,
|
5194 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5195 | cache: cache,
|
5196 | cacheRelativePath: cacheRelativePath,
|
5197 | importDefaultExtension: importDefaultExtension,
|
5198 | importMapRelativePath: importMapRelativePath,
|
5199 | importMapForBundle: importMapForBundle,
|
5200 | importAbstractMap: importAbstractMap,
|
5201 | importFallbackMap: importFallbackMap,
|
5202 | nativeModulePredicate: nativeModulePredicate,
|
5203 | entryPointMap: entryPointMap,
|
5204 | babelPluginMap: babelPluginMap,
|
5205 | convertMap: convertMap,
|
5206 | minify: minify,
|
5207 | logLevel: logLevel,
|
5208 | format: format,
|
5209 | formatOutputOptions: formatOutputOptions,
|
5210 | groupMap: groupMap,
|
5211 | compileId: compileId,
|
5212 | writeOnFileSystem: writeOnFileSystem
|
5213 | });
|
5214 | })));
|
5215 | });
|
5216 |
|
5217 | var generateEntryPointsBalancerFiles = function generateEntryPointsBalancerFiles(_ref3) {
|
5218 | var cancellationToken = _ref3.cancellationToken,
|
5219 | projectPathname = _ref3.projectPathname,
|
5220 | bundleIntoRelativePath = _ref3.bundleIntoRelativePath,
|
5221 | cache = _ref3.cache,
|
5222 | cacheRelativePath = _ref3.cacheRelativePath,
|
5223 | importDefaultExtension = _ref3.importDefaultExtension,
|
5224 | importMapRelativePath = _ref3.importMapRelativePath,
|
5225 | importMapForBundle = _ref3.importMapForBundle,
|
5226 | importAbstractMap = _ref3.importAbstractMap,
|
5227 | importFallbackMap = _ref3.importFallbackMap,
|
5228 | nativeModulePredicate = _ref3.nativeModulePredicate,
|
5229 | entryPointMap = _ref3.entryPointMap,
|
5230 | babelPluginMap = _ref3.babelPluginMap,
|
5231 | convertMap = _ref3.convertMap,
|
5232 | minify = _ref3.minify,
|
5233 | logLevel = _ref3.logLevel,
|
5234 | writeOnFileSystem = _ref3.writeOnFileSystem,
|
5235 | format = _ref3.format,
|
5236 | balancerTemplateHref = _ref3.balancerTemplateHref,
|
5237 | balancerDataAbstractPath = _ref3.balancerDataAbstractPath,
|
5238 | groupMap = _ref3.groupMap;
|
5239 | return Promise.all(Object.keys(entryPointMap).map(_async$f(function (entryPointName) {
|
5240 | return bundleBalancer({
|
5241 | cancellationToken: cancellationToken,
|
5242 | projectPathname: projectPathname,
|
5243 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5244 | cache: cache,
|
5245 | cacheRelativePath: cacheRelativePath,
|
5246 | importDefaultExtension: importDefaultExtension,
|
5247 | importMapRelativePath: importMapRelativePath,
|
5248 | importMapForBundle: importMapForBundle,
|
5249 | importAbstractMap: importAbstractMap,
|
5250 | importFallbackMap: importFallbackMap,
|
5251 | nativeModulePredicate: nativeModulePredicate,
|
5252 | entryPointMap: _defineProperty({}, entryPointName, balancerTemplateHref),
|
5253 | babelPluginMap: babelPluginMap,
|
5254 | convertMap: convertMap,
|
5255 | minify: minify,
|
5256 | logLevel: logLevel,
|
5257 | format: format,
|
5258 | balancerDataAbstractPath: balancerDataAbstractPath,
|
5259 | groupMap: groupMap,
|
5260 | writeOnFileSystem: writeOnFileSystem
|
5261 | });
|
5262 | })));
|
5263 | };
|
5264 |
|
5265 | var createFormatIncompatibleWithBalancingError = function createFormatIncompatibleWithBalancingError(_ref4) {
|
5266 | var format = _ref4.format;
|
5267 | return new Error("format not compatible with balancing.\nformat: ".concat(format));
|
5268 | };
|
5269 |
|
5270 | var DEFAULT_BUNDLE_INTO_RELATIVE_PATH = "/dist/global";
|
5271 |
|
5272 | function _async$g(f) {
|
5273 | return function () {
|
5274 | for (var args = [], i = 0; i < arguments.length; i++) {
|
5275 | args[i] = arguments[i];
|
5276 | }
|
5277 |
|
5278 | try {
|
5279 | return Promise.resolve(f.apply(this, args));
|
5280 | } catch (e) {
|
5281 | return Promise.reject(e);
|
5282 | }
|
5283 | };
|
5284 | }
|
5285 |
|
5286 | var generateGlobalBundle = _async$g(function (_ref) {
|
5287 | var projectPath = _ref.projectPath,
|
5288 | _ref$bundleIntoRelati = _ref.bundleIntoRelativePath,
|
5289 | bundleIntoRelativePath = _ref$bundleIntoRelati === void 0 ? DEFAULT_BUNDLE_INTO_RELATIVE_PATH : _ref$bundleIntoRelati,
|
5290 | cleanBundleInto = _ref.cleanBundleInto,
|
5291 | cache = _ref.cache,
|
5292 | cacheRelativePath = _ref.cacheRelativePath,
|
5293 | globalName = _ref.globalName,
|
5294 | importDefaultExtension = _ref.importDefaultExtension,
|
5295 | importMapRelativePath = _ref.importMapRelativePath,
|
5296 | importMapForBundle = _ref.importMapForBundle,
|
5297 | importAbstractMap = _ref.importAbstractMap,
|
5298 | importFallbackMap = _ref.importFallbackMap,
|
5299 | entryPointMap = _ref.entryPointMap,
|
5300 | babelPluginMap = _ref.babelPluginMap,
|
5301 | convertMap = _ref.convertMap,
|
5302 | logLevel = _ref.logLevel,
|
5303 | minify = _ref.minify,
|
5304 | throwUnhandled = _ref.throwUnhandled,
|
5305 | writeOnFileSystem = _ref.writeOnFileSystem,
|
5306 | platformScoreMap = _ref.platformScoreMap,
|
5307 | platformAlwaysInsidePlatformScoreMap = _ref.platformAlwaysInsidePlatformScoreMap;
|
5308 | return generateBundle({
|
5309 | format: "global",
|
5310 | formatOutputOptions: globalName ? {
|
5311 | name: globalName
|
5312 | } : {},
|
5313 | projectPath: projectPath,
|
5314 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5315 | cleanBundleInto: cleanBundleInto,
|
5316 | cache: cache,
|
5317 | cacheRelativePath: cacheRelativePath,
|
5318 | importDefaultExtension: importDefaultExtension,
|
5319 | importMapRelativePath: importMapRelativePath,
|
5320 | importMapForBundle: importMapForBundle,
|
5321 | importAbstractMap: importAbstractMap,
|
5322 | importFallbackMap: importFallbackMap,
|
5323 | entryPointMap: entryPointMap,
|
5324 | babelPluginMap: babelPluginMap,
|
5325 | convertMap: convertMap,
|
5326 | logLevel: logLevel,
|
5327 | minify: minify,
|
5328 | throwUnhandled: throwUnhandled,
|
5329 | writeOnFileSystem: writeOnFileSystem,
|
5330 | compileGroupCount: 1,
|
5331 | platformScoreMap: platformScoreMap,
|
5332 | platformAlwaysInsidePlatformScoreMap: platformAlwaysInsidePlatformScoreMap
|
5333 | });
|
5334 | });
|
5335 |
|
5336 | var DEFAULT_BUNDLE_INTO_RELATIVE_PATH$1 = "/dist/commonjs";
|
5337 |
|
5338 | function _async$h(f) {
|
5339 | return function () {
|
5340 | for (var args = [], i = 0; i < arguments.length; i++) {
|
5341 | args[i] = arguments[i];
|
5342 | }
|
5343 |
|
5344 | try {
|
5345 | return Promise.resolve(f.apply(this, args));
|
5346 | } catch (e) {
|
5347 | return Promise.reject(e);
|
5348 | }
|
5349 | };
|
5350 | }
|
5351 |
|
5352 | var generateCommonJsBundle = _async$h(function (_ref) {
|
5353 | var projectPath = _ref.projectPath,
|
5354 | _ref$bundleIntoRelati = _ref.bundleIntoRelativePath,
|
5355 | bundleIntoRelativePath = _ref$bundleIntoRelati === void 0 ? DEFAULT_BUNDLE_INTO_RELATIVE_PATH$1 : _ref$bundleIntoRelati,
|
5356 | cleanBundleInto = _ref.cleanBundleInto,
|
5357 | cache = _ref.cache,
|
5358 | cacheRelativePath = _ref.cacheRelativePath,
|
5359 | balancerTemplateRelativePath = _ref.balancerTemplateRelativePath,
|
5360 | importDefaultExtension = _ref.importDefaultExtension,
|
5361 | importMapRelativePath = _ref.importMapRelativePath,
|
5362 | importMapForBundle = _ref.importMapForBundle,
|
5363 | importAbstractMap = _ref.importAbstractMap,
|
5364 | importFallbackMap = _ref.importFallbackMap,
|
5365 | entryPointMap = _ref.entryPointMap,
|
5366 | babelPluginMap = _ref.babelPluginMap,
|
5367 | convertMap = _ref.convertMap,
|
5368 | logLevel = _ref.logLevel,
|
5369 | minify = _ref.minify,
|
5370 | throwUnhandled = _ref.throwUnhandled,
|
5371 | writeOnFileSystem = _ref.writeOnFileSystem,
|
5372 | compileGroupCount = _ref.compileGroupCount,
|
5373 | platformScoreMap = _ref.platformScoreMap,
|
5374 | platformAlwaysInsidePlatformScoreMap = _ref.platformAlwaysInsidePlatformScoreMap;
|
5375 | return generateBundle({
|
5376 | format: "commonjs",
|
5377 | balancerTemplateRelativePath: balancerTemplateRelativePath,
|
5378 | defaultBalancerTemplateHref: "file://".concat(jsenvBundlingProjectPathname, "/src/bundle-commonjs/commonjs-balancer-template.js"),
|
5379 | balancerDataAbstractPath: "/.jsenv/commonjs-balancer-data.js",
|
5380 | projectPath: projectPath,
|
5381 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5382 | cache: cache,
|
5383 | cacheRelativePath: cacheRelativePath,
|
5384 | cleanBundleInto: cleanBundleInto,
|
5385 | importDefaultExtension: importDefaultExtension,
|
5386 | importMapRelativePath: importMapRelativePath,
|
5387 | importMapForBundle: importMapForBundle,
|
5388 | importAbstractMap: importAbstractMap,
|
5389 | importFallbackMap: importFallbackMap,
|
5390 | entryPointMap: entryPointMap,
|
5391 | babelPluginMap: babelPluginMap,
|
5392 | convertMap: convertMap,
|
5393 | logLevel: logLevel,
|
5394 | minify: minify,
|
5395 | throwUnhandled: throwUnhandled,
|
5396 | writeOnFileSystem: writeOnFileSystem,
|
5397 | compileGroupCount: compileGroupCount,
|
5398 | platformScoreMap: platformScoreMap,
|
5399 | platformAlwaysInsidePlatformScoreMap: platformAlwaysInsidePlatformScoreMap
|
5400 | });
|
5401 | });
|
5402 |
|
5403 | var DEFAULT_BUNDLE_INTO_RELATIVE_PATH$2 = "/dist/systemjs";
|
5404 |
|
5405 | function _async$i(f) {
|
5406 | return function () {
|
5407 | for (var args = [], i = 0; i < arguments.length; i++) {
|
5408 | args[i] = arguments[i];
|
5409 | }
|
5410 |
|
5411 | try {
|
5412 | return Promise.resolve(f.apply(this, args));
|
5413 | } catch (e) {
|
5414 | return Promise.reject(e);
|
5415 | }
|
5416 | };
|
5417 | }
|
5418 |
|
5419 | var generateSystemJsBundle = _async$i(function (_ref) {
|
5420 | var projectPath = _ref.projectPath,
|
5421 | _ref$bundleIntoRelati = _ref.bundleIntoRelativePath,
|
5422 | bundleIntoRelativePath = _ref$bundleIntoRelati === void 0 ? DEFAULT_BUNDLE_INTO_RELATIVE_PATH$2 : _ref$bundleIntoRelati,
|
5423 | cleanBundleInto = _ref.cleanBundleInto,
|
5424 | cache = _ref.cache,
|
5425 | cacheRelativePath = _ref.cacheRelativePath,
|
5426 | balancerTemplateRelativePath = _ref.balancerTemplateRelativePath,
|
5427 | importDefaultExtension = _ref.importDefaultExtension,
|
5428 | importMapRelativePath = _ref.importMapRelativePath,
|
5429 | importMapForBundle = _ref.importMapForBundle,
|
5430 | importAbstractMap = _ref.importAbstractMap,
|
5431 | importFallbackMap = _ref.importFallbackMap,
|
5432 | entryPointMap = _ref.entryPointMap,
|
5433 | babelPluginMap = _ref.babelPluginMap,
|
5434 | convertMap = _ref.convertMap,
|
5435 | logLevel = _ref.logLevel,
|
5436 | minify = _ref.minify,
|
5437 | throwUnhandled = _ref.throwUnhandled,
|
5438 | writeOnFileSystem = _ref.writeOnFileSystem,
|
5439 | compileGroupCount = _ref.compileGroupCount,
|
5440 | platformScoreMap = _ref.platformScoreMap,
|
5441 | platformAlwaysInsidePlatformScoreMap = _ref.platformAlwaysInsidePlatformScoreMap;
|
5442 | return generateBundle({
|
5443 | format: "systemjs",
|
5444 | balancerTemplateRelativePath: balancerTemplateRelativePath,
|
5445 | defaultBalancerTemplateHref: "file://".concat(jsenvBundlingProjectPathname, "/src/bundle-systemjs/systemjs-balancer-template.js"),
|
5446 | balancerDataAbstractPath: "/.jsenv/systemjs-balancer-data.js",
|
5447 | projectPath: projectPath,
|
5448 | bundleIntoRelativePath: bundleIntoRelativePath,
|
5449 | cleanBundleInto: cleanBundleInto,
|
5450 | cache: cache,
|
5451 | cacheRelativePath: cacheRelativePath,
|
5452 | importDefaultExtension: importDefaultExtension,
|
5453 | importMapRelativePath: importMapRelativePath,
|
5454 | importMapForBundle: importMapForBundle,
|
5455 | importAbstractMap: importAbstractMap,
|
5456 | importFallbackMap: importFallbackMap,
|
5457 | entryPointMap: entryPointMap,
|
5458 | babelPluginMap: babelPluginMap,
|
5459 | convertMap: convertMap,
|
5460 | logLevel: logLevel,
|
5461 | minify: minify,
|
5462 | throwUnhandled: throwUnhandled,
|
5463 | writeOnFileSystem: writeOnFileSystem,
|
5464 | compileGroupCount: compileGroupCount,
|
5465 | platformScoreMap: platformScoreMap,
|
5466 | platformAlwaysInsidePlatformScoreMap: platformAlwaysInsidePlatformScoreMap
|
5467 | });
|
5468 | });
|
5469 |
|
5470 | var bundleToCompilationResult = function bundleToCompilationResult(_ref, _ref2) {
|
5471 | var rollupBundle = _ref.rollupBundle,
|
5472 | arrayOfAbstractHref = _ref.arrayOfAbstractHref;
|
5473 | var projectPathname = _ref2.projectPathname,
|
5474 | entryRelativePath = _ref2.entryRelativePath,
|
5475 | sourcemapAssetPath = _ref2.sourcemapAssetPath,
|
5476 | _ref2$sourcemapPath = _ref2.sourcemapPath,
|
5477 | sourcemapPath = _ref2$sourcemapPath === void 0 ? sourcemapAssetPath : _ref2$sourcemapPath;
|
5478 | var sources = [];
|
5479 | var sourcesContent = [];
|
5480 | var assets = [];
|
5481 | var assetsContent = [];
|
5482 | var output = rollupBundle.output;
|
5483 | var main = output[0];
|
5484 | var mainRollupSourcemap = main.map;
|
5485 | var mainDependencyMap = rollupSourcemapToDependencyMap({
|
5486 | rollupSourcemap: mainRollupSourcemap,
|
5487 | projectPathname: projectPathname,
|
5488 | entryRelativePath: entryRelativePath,
|
5489 | arrayOfAbstractHref: arrayOfAbstractHref
|
5490 | });
|
5491 |
|
5492 | var addDependencyMap = function addDependencyMap(dependencyMap) {
|
5493 | Object.keys(dependencyMap).forEach(function (relativePath) {
|
5494 | if (arrayOfAbstractHref.includes("file://".concat(projectPathname).concat(relativePath))) return;
|
5495 | if (sources.includes(relativePath)) return;
|
5496 | sources.push(relativePath);
|
5497 | sourcesContent.push(dependencyMap[relativePath]);
|
5498 | });
|
5499 | };
|
5500 |
|
5501 |
|
5502 | var mainSourceContent = writeOrUpdateSourceMappingURL(main.code, sourcemapPath);
|
5503 |
|
5504 | assets.push(sourcemapAssetPath.slice(2));
|
5505 |
|
5506 | var mainSourcemap = _objectSpread$1({}, mainRollupSourcemap, {}, dependencyMapToSourcemapSubset(mainDependencyMap));
|
5507 |
|
5508 | assetsContent.push(JSON.stringify(mainSourcemap, null, " "));
|
5509 |
|
5510 | addDependencyMap(mainDependencyMap);
|
5511 | output.slice(1).forEach(function (chunk) {
|
5512 | var chunkRollupSourcemap = chunk.map;
|
5513 | var chunkDependencyMap = rollupSourcemapToDependencyMap({
|
5514 | rollupSourcemap: chunkRollupSourcemap,
|
5515 | projectPathname: projectPathname,
|
5516 | entryRelativePath: entryRelativePath,
|
5517 | arrayOfAbstractHref: arrayOfAbstractHref
|
5518 | });
|
5519 |
|
5520 | assets.push(chunk.fileName);
|
5521 | var chunkSourceContent = writeOrUpdateSourceMappingURL(chunk.code, "./".concat(chunk.fileName, ".map"));
|
5522 | assetsContent.push(chunkSourceContent);
|
5523 |
|
5524 | assets.push("".concat(chunk.fileName, ".map"));
|
5525 |
|
5526 | var chunkSourcemap = _objectSpread$1({}, chunkRollupSourcemap, {}, dependencyMapToSourcemapSubset(chunkDependencyMap));
|
5527 |
|
5528 | assetsContent.push(JSON.stringify(chunkSourcemap, null, " "));
|
5529 |
|
5530 | addDependencyMap(chunkDependencyMap);
|
5531 | });
|
5532 | return {
|
5533 | contentType: "application/javascript",
|
5534 | compiledSource: mainSourceContent,
|
5535 | sources: sources,
|
5536 | sourcesContent: sourcesContent,
|
5537 | assets: assets,
|
5538 | assetsContent: assetsContent
|
5539 | };
|
5540 | };
|
5541 |
|
5542 | var dependencyMapToSourcemapSubset = function dependencyMapToSourcemapSubset(dependencyMap) {
|
5543 | var sources = Object.keys(dependencyMap);
|
5544 | var sourcesContent = sources.map(function (source) {
|
5545 |
|
5546 |
|
5547 | if (source.endsWith(".json")) return "export default ".concat(dependencyMap[source]);
|
5548 | return dependencyMap[source];
|
5549 | });
|
5550 | return {
|
5551 | sources: sources,
|
5552 | sourcesContent: sourcesContent
|
5553 | };
|
5554 | };
|
5555 |
|
5556 | var rollupSourcemapToDependencyMap = function rollupSourcemapToDependencyMap(_ref3) {
|
5557 | var rollupSourcemap = _ref3.rollupSourcemap,
|
5558 | projectPathname = _ref3.projectPathname,
|
5559 | entryRelativePath = _ref3.entryRelativePath,
|
5560 | arrayOfAbstractHref = _ref3.arrayOfAbstractHref;
|
5561 | var dependencyMap = {};
|
5562 | rollupSourcemap.sources.forEach(function (source, index) {
|
5563 | if (hrefToScheme(source)) {
|
5564 |
|
5565 | return;
|
5566 | }
|
5567 |
|
5568 |
|
5569 | var sourcePath = path.resolve(path.dirname(pathnameToOperatingSystemPath("".concat(projectPathname).concat(entryRelativePath))), source);
|
5570 | var sourcePathname = operatingSystemPathToPathname(sourcePath);
|
5571 |
|
5572 | if (!pathnameIsInside(sourcePathname, projectPathname)) {
|
5573 | throw createSourceOutsideProjectError({
|
5574 | sourcePath: sourcePath,
|
5575 | projectPathname: projectPathname,
|
5576 | source: source,
|
5577 | file: entryRelativePath
|
5578 | });
|
5579 | }
|
5580 |
|
5581 | var sourceRelativePath = pathnameToRelativePath(sourcePathname, projectPathname);
|
5582 | var isAbstract = arrayOfAbstractHref.includes("file://".concat(projectPathname).concat(sourceRelativePath));
|
5583 | var dependencyContent;
|
5584 | var sourcesContent = rollupSourcemap.sourcesContent || [];
|
5585 |
|
5586 | if (index in sourcesContent) {
|
5587 |
|
5588 |
|
5589 | if (isAbstract) {
|
5590 | dependencyContent = sourcesContent[index];
|
5591 | }
|
5592 |
|
5593 |
|
5594 |
|
5595 | else if (sourceRelativePath.endsWith(".json")) {
|
5596 | dependencyContent = readSourceContent({
|
5597 | projectPathname: projectPathname,
|
5598 | sourceRelativePath: sourceRelativePath,
|
5599 | entryRelativePath: entryRelativePath
|
5600 | });
|
5601 | } else {
|
5602 | dependencyContent = sourcesContent[index];
|
5603 | }
|
5604 | } else {
|
5605 | if (isAbstract) {
|
5606 | throw createAbstractSourceMissingError({
|
5607 | sourceRelativePath: sourceRelativePath,
|
5608 | entryRelativePath: entryRelativePath
|
5609 | });
|
5610 | }
|
5611 |
|
5612 | dependencyContent = readSourceContent({
|
5613 | projectPathname: projectPathname,
|
5614 | sourceRelativePath: sourceRelativePath,
|
5615 | entryRelativePath: entryRelativePath
|
5616 | });
|
5617 | }
|
5618 |
|
5619 | dependencyMap[sourceRelativePath] = dependencyContent;
|
5620 | });
|
5621 | return dependencyMap;
|
5622 | };
|
5623 |
|
5624 | var readSourceContent = function readSourceContent(_ref4) {
|
5625 | var projectPathname = _ref4.projectPathname,
|
5626 | sourceRelativePath = _ref4.sourceRelativePath,
|
5627 | entryRelativePath = _ref4.entryRelativePath;
|
5628 | var sourcePath = pathnameToOperatingSystemPath("".concat(projectPathname).concat(sourceRelativePath));
|
5629 |
|
5630 |
|
5631 |
|
5632 | try {
|
5633 | var buffer = fs.readFileSync(sourcePath);
|
5634 | return String(buffer);
|
5635 | } catch (e) {
|
5636 | if (e && e.code === "ENOENT") {
|
5637 | throw createSourceNotFoundError({
|
5638 | sourcePath: sourcePath,
|
5639 | projectPathname: projectPathname,
|
5640 | source: sourceRelativePath,
|
5641 | file: entryRelativePath
|
5642 | });
|
5643 | }
|
5644 |
|
5645 | throw e;
|
5646 | }
|
5647 | };
|
5648 |
|
5649 | var createAbstractSourceMissingError = function createAbstractSourceMissingError(_ref5) {
|
5650 | var source = _ref5.source,
|
5651 | file = _ref5.file;
|
5652 | return new Error("an abstract file source content is missing.\nsource: ".concat(source, "\nfile: ").concat(file));
|
5653 | };
|
5654 |
|
5655 | var createSourceNotFoundError = function createSourceNotFoundError(_ref6) {
|
5656 | var sourcePath = _ref6.sourcePath,
|
5657 | projectPathname = _ref6.projectPathname,
|
5658 | source = _ref6.source,
|
5659 | file = _ref6.file;
|
5660 | return new Error("a file source cannot be found.\nsource path: ".concat(sourcePath, "\nproject path: ").concat(pathnameToOperatingSystemPath(projectPathname), "\nsource: ").concat(source, "\nfile: ").concat(file));
|
5661 | };
|
5662 |
|
5663 | var createSourceOutsideProjectError = function createSourceOutsideProjectError(_ref7) {
|
5664 | var sourcePath = _ref7.sourcePath,
|
5665 | projectPathname = _ref7.projectPathname,
|
5666 | source = _ref7.source,
|
5667 | file = _ref7.file;
|
5668 | return new Error("a file source is not inside project.\nsource path: ".concat(sourcePath, "\nproject path: ").concat(pathnameToOperatingSystemPath(projectPathname), "\nsource: ").concat(source, "\nfile: ").concat(file));
|
5669 | };
|
5670 |
|
5671 | exports.bundleToCompilationResult = bundleToCompilationResult;
|
5672 | exports.generateBundle = generateBundle;
|
5673 | exports.generateCommonJsBundle = generateCommonJsBundle;
|
5674 | exports.generateGlobalBundle = generateGlobalBundle;
|
5675 | exports.generateSystemJsBundle = generateSystemJsBundle;
|
5676 |
|