forked from Flipkart/DUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
854 lines (507 loc) · 23.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};function _toArray(arr) {return Array.isArray(arr) ? arr : Array.from(arr);}function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return Promise.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};}
const assert = require('assert');
const crypto = require('crypto');
const debug = require('debug')('Metro:Bundler');
const emptyFunction = require('fbjs/lib/emptyFunction');
const fs = require('fs');
const Transformer = require('../JSTransformer');
const Resolver = require('../Resolver');
const Bundle = require('./Bundle');
const HMRBundle = require('./HMRBundle');
const ModuleTransport = require('../lib/ModuleTransport');
const imageSize = require('image-size');
const path = require('path');
const denodeify = require('denodeify');
const defaults = require('../defaults');
const toLocalPath = require('../node-haste/lib/toLocalPath');var _require =
require('./util');const generateAssetTransformResult = _require.generateAssetTransformResult,isAssetTypeAnImage = _require.isAssetTypeAnImage;var _require2 =
require('path');const pathSeparator = _require2.sep,joinPath = _require2.join,pathDirname = _require2.dirname,extname = _require2.extname;
const VERSION = require('../../package.json').version;
const sizeOf = denodeify(imageSize);var _require3 =
require('../Logger');const createActionStartEntry = _require3.createActionStartEntry,createActionEndEntry = _require3.createActionEndEntry,log = _require3.log;const
hasOwnProperty = Object.hasOwnProperty;
class Bundler {
constructor(opts) {
this._opts = opts;
opts.projectRoots.forEach(verifyRootExists);
const transformModuleStr = fs.readFileSync(opts.transformModulePath);
const transformModuleHash =
crypto.createHash('sha1').update(transformModuleStr).digest('hex');
const stableProjectRoots = opts.projectRoots.map(p => {
return path.relative(path.join(__dirname, '../../../..'), p);
});
const cacheKeyParts = [
'react-packager-cache',
VERSION,
opts.cacheVersion,
stableProjectRoots.join(',').split(pathSeparator).join('-'),
transformModuleHash];
this._getModuleId = createModuleIdFactory();
let getCacheKey = options => '';
if (opts.transformModulePath) {
/* $FlowFixMe: dynamic requires prevent static typing :'( */
const transformer = require(opts.transformModulePath);
if (typeof transformer.getCacheKey !== 'undefined') {
getCacheKey = transformer.getCacheKey;
}
}
const transformCacheKey = crypto.createHash('sha1').update(
cacheKeyParts.join('$')).
digest('hex');
debug(`Using transform cache key "${transformCacheKey}"`);
this._transformer = new Transformer(
opts.transformModulePath,
opts.maxWorkers,
{
stdoutChunk: chunk => opts.reporter.update({ type: 'worker_stdout_chunk', chunk }),
stderrChunk: chunk => opts.reporter.update({ type: 'worker_stderr_chunk', chunk }) },
opts.workerPath);
const getTransformCacheKey = options => {
return transformCacheKey + getCacheKey(options);
};
this._resolverPromise = Resolver.load({
assetExts: opts.assetExts,
blacklistRE: opts.blacklistRE,
extraNodeModules: opts.extraNodeModules,
getTransformCacheKey,
globalTransformCache: opts.globalTransformCache,
hasteImpl: opts.hasteImpl,
maxWorkers: opts.maxWorkers,
minifyCode: this._transformer.minify,
postMinifyProcess: this._opts.postMinifyProcess,
platforms: new Set(opts.platforms),
polyfillModuleNames: opts.polyfillModuleNames,
projectRoots: opts.projectRoots,
providesModuleNodeModules:
opts.providesModuleNodeModules || defaults.providesModuleNodeModules,
reporter: opts.reporter,
resetCache: opts.resetCache,
sourceExts: opts.sourceExts,
transformCode:
(module, code, transformCodeOptions) => this._transformer.transformFile(
module.path,
module.localPath,
code,
transformCodeOptions),
transformCache: opts.transformCache,
watch: opts.watch });
this._projectRoots = opts.projectRoots;
this._assetServer = opts.assetServer;
this._getTransformOptions = opts.getTransformOptions;
}
end() {
this._transformer.kill();
return this._resolverPromise.then(
resolver => resolver.getDependencyGraph().getWatcher().end());
}
bundle(options)
{const
dev = options.dev,minify = options.minify,unbundle = options.unbundle;
return this._resolverPromise.then(
resolver => resolver.getModuleSystemDependencies({ dev, unbundle })).
then(moduleSystemDeps => this._bundle(_extends({},
options, {
bundle: new Bundle({ dev, minify, sourceMapUrl: options.sourceMapUrl }),
moduleSystemDeps })));
}
_sourceHMRURL(platform, hmrpath) {
return this._hmrURL(
'',
platform,
'bundle',
hmrpath);
}
_sourceMappingHMRURL(platform, hmrpath) {
// Chrome expects `sourceURL` when eval'ing code
return this._hmrURL(
'\/\/# sourceURL=',
platform,
'map',
hmrpath);
}
_hmrURL(prefix, platform, extensionOverride, filePath) {
const matchingRoot = this._projectRoots.find(root => filePath.startsWith(root));
if (!matchingRoot) {
throw new Error('No matching project root for ' + filePath);
}
// Replaces '\' with '/' for Windows paths.
if (pathSeparator === '\\') {
filePath = filePath.replace(/\\/g, '/');
}
const extensionStart = filePath.lastIndexOf('.');
const resource = filePath.substring(
matchingRoot.length,
extensionStart !== -1 ? extensionStart : undefined);
return (
prefix + resource +
'.' + extensionOverride + '?' +
'platform=' + (platform || '') + '&runModule=false&entryModuleOnly=true&hot=true');
}
hmrBundle(options, host, port) {
return this._bundle(_extends({},
options, {
bundle: new HMRBundle({
sourceURLFn: this._sourceHMRURL.bind(this, options.platform),
sourceMappingURLFn: this._sourceMappingHMRURL.bind(
this,
options.platform) }),
hot: true,
dev: true }));
}
_bundle(_ref)
{let assetPlugins = _ref.assetPlugins,bundle = _ref.bundle,dev = _ref.dev,entryFile = _ref.entryFile,entryModuleOnly = _ref.entryModuleOnly,generateSourceMaps = _ref.generateSourceMaps,hot = _ref.hot,isolateModuleIDs = _ref.isolateModuleIDs,minify = _ref.minify;var _ref$moduleSystemDeps = _ref.moduleSystemDeps;let moduleSystemDeps = _ref$moduleSystemDeps === undefined ? [] : _ref$moduleSystemDeps,onProgress = _ref.onProgress,platform = _ref.platform,resolutionResponse = _ref.resolutionResponse,runBeforeMainModule = _ref.runBeforeMainModule,runModule = _ref.runModule,unbundle = _ref.unbundle;
const onResolutionResponse = response => {
/* $FlowFixMe: looks like ResolutionResponse is monkey-patched
* with `getModuleId`. */
bundle.setMainModuleId(response.getModuleId(getMainModule(response)));
if (entryModuleOnly && entryFile) {
response.dependencies = response.dependencies.filter(module =>
module.path.endsWith(entryFile || ''));
} else {
response.dependencies = moduleSystemDeps.concat(response.dependencies);
}
};
const finalizeBundle = (_ref2) => {let finalBundle = _ref2.bundle,transformedModules = _ref2.transformedModules,response = _ref2.response,modulesByName = _ref2.modulesByName;return (
this._resolverPromise.then(resolver => Promise.all(
transformedModules.map((_ref3) => {let module = _ref3.module,transformed = _ref3.transformed;return (
finalBundle.addModule(resolver, response, module, transformed));}))).
then(() => {
const runBeforeMainModuleIds = Array.isArray(runBeforeMainModule) ?
runBeforeMainModule.
map(name => modulesByName[name]).
filter(Boolean).
map(response.getModuleId) :
undefined;
finalBundle.finalize({
runModule,
runBeforeMainModule: runBeforeMainModuleIds,
allowUpdates: this._opts.allowBundleUpdates });
return finalBundle;
}));};
return this._buildBundle({
entryFile,
dev,
minify,
platform,
bundle,
hot,
unbundle,
resolutionResponse,
onResolutionResponse,
finalizeBundle,
isolateModuleIDs,
generateSourceMaps,
assetPlugins,
onProgress });
}
_buildBundle(_ref4)
{let entryFile = _ref4.entryFile,dev = _ref4.dev,minify = _ref4.minify,platform = _ref4.platform,bundle = _ref4.bundle,hot = _ref4.hot,unbundle = _ref4.unbundle,resolutionResponse = _ref4.resolutionResponse,isolateModuleIDs = _ref4.isolateModuleIDs,generateSourceMaps = _ref4.generateSourceMaps,assetPlugins = _ref4.assetPlugins;var _ref4$onResolutionRes = _ref4.onResolutionResponse;let onResolutionResponse = _ref4$onResolutionRes === undefined ? emptyFunction : _ref4$onResolutionRes;var _ref4$onModuleTransfo = _ref4.onModuleTransformed;let onModuleTransformed = _ref4$onModuleTransfo === undefined ? emptyFunction : _ref4$onModuleTransfo;var _ref4$finalizeBundle = _ref4.finalizeBundle;let finalizeBundle = _ref4$finalizeBundle === undefined ? emptyFunction : _ref4$finalizeBundle;var _ref4$onProgress = _ref4.onProgress;let onProgress = _ref4$onProgress === undefined ? emptyFunction : _ref4$onProgress;
const transformingFilesLogEntry =
log(createActionStartEntry({
action_name: 'Transforming files',
entry_point: entryFile,
environment: dev ? 'dev' : 'prod' }));
const modulesByName = Object.create(null);
if (!resolutionResponse) {
resolutionResponse = this.getDependencies({
entryFile,
dev,
platform,
hot,
onProgress,
minify,
isolateModuleIDs,
generateSourceMaps: unbundle || minify || generateSourceMaps });
}
return Promise.all(
[this._resolverPromise, resolutionResponse]).
then((_ref5) => {var _ref6 = _slicedToArray(_ref5, 2);let resolver = _ref6[0],response = _ref6[1];
bundle.setRamGroups(response.options.ramGroups);
log(createActionEndEntry(transformingFilesLogEntry));
onResolutionResponse(response);
// get entry file complete path (`entryFile` is a local path, i.e. relative to roots)
let entryFilePath;
if (response.dependencies.length > 1) {// skip HMR requests
const numModuleSystemDependencies =
resolver.getModuleSystemDependencies({ dev, unbundle }).length;
const dependencyIndex =
(response.numPrependedDependencies || 0) + numModuleSystemDependencies;
if (dependencyIndex in response.dependencies) {
entryFilePath = response.dependencies[dependencyIndex].path;
}
}
const modulesByTransport = new Map();
const toModuleTransport =
module =>
this._toModuleTransport({
module,
bundle,
entryFilePath,
assetPlugins,
options: response.options,
/* $FlowFixMe: `getModuleId` is monkey-patched */
getModuleId: response.getModuleId,
dependencyPairs: response.getResolvedDependencyPairs(module) }).
then(transformed => {
modulesByTransport.set(transformed, module);
modulesByName[transformed.name] = module;
onModuleTransformed({
module,
response,
bundle,
transformed });
return transformed;
});
const p = this._opts.postProcessModules;
const postProcess = p ?
modules => p(modules, entryFile, { dev, minify, platform }) :
null;
return Promise.all(response.dependencies.map(toModuleTransport)).
then(postProcess).
then(moduleTransports => {
const transformedModules = moduleTransports.map(transformed => ({
module: modulesByTransport.get(transformed),
transformed }));
return finalizeBundle({ bundle, transformedModules, response, modulesByName });
}).then(() => bundle);
});
}
getShallowDependencies(_ref7)
{let entryFile = _ref7.entryFile,platform = _ref7.platform;var _ref7$dev = _ref7.dev;let dev = _ref7$dev === undefined ? true : _ref7$dev;var _ref7$minify = _ref7.minify;let minify = _ref7$minify === undefined ? !dev : _ref7$minify;var _ref7$hot = _ref7.hot;let hot = _ref7$hot === undefined ? false : _ref7$hot;var _ref7$generateSourceM = _ref7.generateSourceMaps;let generateSourceMaps = _ref7$generateSourceM === undefined ? false : _ref7$generateSourceM;
return this.getTransformOptions(
entryFile,
{
dev,
generateSourceMaps,
hot,
minify,
platform,
projectRoots: this._projectRoots }).
then(bundlingOptions =>
this._resolverPromise.then(resolver =>
resolver.getShallowDependencies(entryFile, bundlingOptions.transformer)));
}
getModuleForPath(entryFile) {
return this._resolverPromise.then(resolver => resolver.getModuleForPath(entryFile));
}
getDependencies(_ref8)
{var _this = this;let entryFile = _ref8.entryFile,platform = _ref8.platform;var _ref8$dev = _ref8.dev;let dev = _ref8$dev === undefined ? true : _ref8$dev;var _ref8$minify = _ref8.minify;let minify = _ref8$minify === undefined ? !dev : _ref8$minify;var _ref8$hot = _ref8.hot;let hot = _ref8$hot === undefined ? false : _ref8$hot;var _ref8$recursive = _ref8.recursive;let recursive = _ref8$recursive === undefined ? true : _ref8$recursive;var _ref8$generateSourceM = _ref8.generateSourceMaps;let generateSourceMaps = _ref8$generateSourceM === undefined ? false : _ref8$generateSourceM;var _ref8$isolateModuleID = _ref8.isolateModuleIDs;let isolateModuleIDs = _ref8$isolateModuleID === undefined ? false : _ref8$isolateModuleID,onProgress = _ref8.onProgress;return _asyncToGenerator(function* () {
const bundlingOptions = yield _this.getTransformOptions(
entryFile,
{
dev,
platform,
hot,
generateSourceMaps,
minify,
projectRoots: _this._projectRoots });
const resolver = yield _this._resolverPromise;
const response = yield resolver.getDependencies(
entryFile,
{ dev, platform, recursive },
bundlingOptions,
onProgress,
isolateModuleIDs ? createModuleIdFactory() : _this._getModuleId);
return response;})();
}
getOrderedDependencyPaths(_ref9)
{let entryFile = _ref9.entryFile,dev = _ref9.dev,platform = _ref9.platform,minify = _ref9.minify,generateSourceMaps = _ref9.generateSourceMaps;
return this.getDependencies({ entryFile, dev, platform, minify, generateSourceMaps }).then(
(_ref10) => {let dependencies = _ref10.dependencies;
const ret = [];
const promises = [];
const placeHolder = {};
dependencies.forEach(dep => {
if (dep.isAsset()) {
const localPath = toLocalPath(
this._projectRoots,
dep.path);
promises.push(
this._assetServer.getAssetData(localPath, platform));
ret.push(placeHolder);
} else {
ret.push(dep.path);
}
});
return Promise.all(promises).then(assetsData => {
assetsData.forEach((_ref11) => {let files = _ref11.files;
const index = ret.indexOf(placeHolder);
ret.splice(index, 1, ...files);
});
return ret;
});
});
}
_toModuleTransport(_ref12)
{let module = _ref12.module,bundle = _ref12.bundle,entryFilePath = _ref12.entryFilePath,options = _ref12.options,getModuleId = _ref12.getModuleId,dependencyPairs = _ref12.dependencyPairs,assetPlugins = _ref12.assetPlugins;
let moduleTransport;
const moduleId = getModuleId(module);
const transformOptions = options.transformer;
if (module.isAsset()) {
moduleTransport = this._generateAssetModule(
bundle, module, moduleId, assetPlugins, transformOptions.platform);
}
if (moduleTransport) {
return Promise.resolve(moduleTransport);
}
return Promise.all([
module.getName(),
module.read(transformOptions)]).
then((_ref13) =>
{var _ref14 = _slicedToArray(_ref13, 2);let name = _ref14[0];var _ref14$ = _ref14[1];let code = _ref14$.code,dependencies = _ref14$.dependencies,dependencyOffsets = _ref14$.dependencyOffsets,map = _ref14$.map,source = _ref14$.source;const
preloadedModules = options.preloadedModules;
const isPolyfill = module.isPolyfill();
const preloaded =
module.path === entryFilePath ||
isPolyfill ||
preloadedModules && hasOwnProperty.call(preloadedModules, module.path);
return new ModuleTransport({
name,
id: moduleId,
code,
map,
meta: { dependencies, dependencyOffsets, preloaded, dependencyPairs },
polyfill: isPolyfill,
sourceCode: source,
sourcePath: module.path });
});
}
_generateAssetObjAndCode(
module,
assetPlugins)
{let platform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
const localPath = toLocalPath(this._projectRoots, module.path);
var assetUrlPath = joinPath('/assets', pathDirname(localPath));
// On Windows, change backslashes to slashes to get proper URL path from file path.
if (pathSeparator === '\\') {
assetUrlPath = assetUrlPath.replace(/\\/g, '/');
}
const isImage = isAssetTypeAnImage(extname(module.path).slice(1));
return this._assetServer.getAssetData(localPath, platform).then(assetData => {
return Promise.all([isImage ? sizeOf(assetData.files[0]) : null, assetData]);
}).then(res => {
const dimensions = res[0];
const assetData = res[1];
const scale = assetData.scales[0];
const asset = {
__packager_asset: true,
fileSystemLocation: pathDirname(module.path),
httpServerLocation: assetUrlPath,
width: dimensions ? dimensions.width / scale : undefined,
height: dimensions ? dimensions.height / scale : undefined,
scales: assetData.scales,
files: assetData.files,
hash: assetData.hash,
name: assetData.name,
type: assetData.type };
return this._applyAssetPlugins(assetPlugins, asset);
}).then(asset => {var _generateAssetTransfo =
generateAssetTransformResult(asset);const code = _generateAssetTransfo.code,dependencies = _generateAssetTransfo.dependencies,dependencyOffsets = _generateAssetTransfo.dependencyOffsets;
return {
asset,
code,
meta: { dependencies, dependencyOffsets, preloaded: null } };
});
}
_applyAssetPlugins(
assetPlugins,
asset)
{
if (!assetPlugins.length) {
return asset;
}var _assetPlugins = _toArray(
assetPlugins);const currentAssetPlugin = _assetPlugins[0],remainingAssetPlugins = _assetPlugins.slice(1);
/* $FlowFixMe: dynamic requires prevent static typing :'( */
const assetPluginFunction = require(currentAssetPlugin);
const result = assetPluginFunction(asset);
// If the plugin was an async function, wait for it to fulfill before
// applying the remaining plugins
if (typeof result.then === 'function') {
return result.then(resultAsset =>
this._applyAssetPlugins(remainingAssetPlugins, resultAsset));
} else {
return this._applyAssetPlugins(remainingAssetPlugins, result);
}
}
_generateAssetModule(
bundle,
module,
moduleId)
{let assetPlugins = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];let platform = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
return Promise.all([
module.getName(),
this._generateAssetObjAndCode(module, assetPlugins, platform)]).
then((_ref15) => {var _ref16 = _slicedToArray(_ref15, 2);let name = _ref16[0];var _ref16$ = _ref16[1];let asset = _ref16$.asset,code = _ref16$.code,meta = _ref16$.meta;
bundle.addAsset(asset);
return new ModuleTransport({
name,
id: moduleId,
code,
meta,
sourceCode: code,
sourcePath: module.path,
virtual: true });
});
}
getTransformOptions(
mainModuleName,
options)
{var _this2 = this;return _asyncToGenerator(function* () {
const getDependencies = function (entryFile) {return (
_this2.getDependencies(_extends({}, options, { entryFile })).
then(function (r) {return r.dependencies.map(function (d) {return d.path;});}));};const
dev = options.dev,hot = options.hot,platform = options.platform;
const extraOptions = _this2._getTransformOptions ?
yield _this2._getTransformOptions(mainModuleName, { dev, hot, platform }, getDependencies) :
{};var _extraOptions$transfo =
extraOptions.transform;const transform = _extraOptions$transfo === undefined ? {} : _extraOptions$transfo;
return {
transformer: {
dev,
minify: options.minify,
platform,
transform: {
dev,
generateSourceMaps: options.generateSourceMaps,
hot,
inlineRequires: transform.inlineRequires || false,
platform,
projectRoot: options.projectRoots[0] } },
preloadedModules: extraOptions.preloadedModules,
ramGroups: extraOptions.ramGroups };})();
}
getResolver() {
return this._resolverPromise;
}}
function verifyRootExists(root) {
// Verify that the root exists.
assert(fs.statSync(root).isDirectory(), 'Root has to be a valid directory');
}
function hashCode(str) {
return str.split('').reduce((prevHash, currVal) =>
((prevHash << 5) - prevHash) + currVal.charCodeAt(0), 0);
}
function createModuleIdFactory() {
const fileToIdMap = Object.create(null);
return (_ref17) => {let modulePath = _ref17.path;
if (!(modulePath in fileToIdMap)) {
var moddedPath = modulePath.substring(modulePath.indexOf('fk-react-native'), modulePath.length);
fileToIdMap[modulePath] = hashCode(moddedPath);
}
return fileToIdMap[modulePath];
};
}
function getMainModule(_ref18) {let dependencies = _ref18.dependencies;var _ref18$numPrependedDe = _ref18.numPrependedDependencies;let numPrependedDependencies = _ref18$numPrependedDe === undefined ? 0 : _ref18$numPrependedDe;
return dependencies[numPrependedDependencies];
}
module.exports = Bundler;