loader.js 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. /*!-----------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.15.5(3d42593a5844407ab71d47b348ea3a8de5fec848)
  4. * Released under the MIT license
  5. * https://github.com/Microsoft/vscode/blob/master/LICENSE.txt
  6. *-----------------------------------------------------------*/
  7. /*---------------------------------------------------------------------------------------------
  8. * Copyright (c) Microsoft Corporation. All rights reserved.
  9. * Licensed under the MIT License. See License.txt in the project root for license information.
  10. *--------------------------------------------------------------------------------------------*/
  11. 'use strict';
  12. /*---------------------------------------------------------------------------------------------
  13. * Copyright (c) Microsoft Corporation. All rights reserved.
  14. * Licensed under the MIT License. See License.txt in the project root for license information.
  15. *--------------------------------------------------------------------------------------------*/
  16. /*---------------------------------------------------------------------------------------------
  17. *---------------------------------------------------------------------------------------------
  18. *---------------------------------------------------------------------------------------------
  19. *---------------------------------------------------------------------------------------------
  20. *---------------------------------------------------------------------------------------------
  21. * Please make sure to make edits in the .ts file at https://github.com/Microsoft/vscode-loader/
  22. *---------------------------------------------------------------------------------------------
  23. *---------------------------------------------------------------------------------------------
  24. *---------------------------------------------------------------------------------------------
  25. *---------------------------------------------------------------------------------------------
  26. *--------------------------------------------------------------------------------------------*/
  27. var _amdLoaderGlobal = this;
  28. var _commonjsGlobal = typeof global === 'object' ? global : {};
  29. var AMDLoader;
  30. (function (AMDLoader) {
  31. AMDLoader.global = _amdLoaderGlobal;
  32. var Environment = (function () {
  33. function Environment() {
  34. this._detected = false;
  35. this._isWindows = false;
  36. this._isNode = false;
  37. this._isElectronRenderer = false;
  38. this._isWebWorker = false;
  39. }
  40. Object.defineProperty(Environment.prototype, "isWindows", {
  41. get: function () {
  42. this._detect();
  43. return this._isWindows;
  44. },
  45. enumerable: true,
  46. configurable: true
  47. });
  48. Object.defineProperty(Environment.prototype, "isNode", {
  49. get: function () {
  50. this._detect();
  51. return this._isNode;
  52. },
  53. enumerable: true,
  54. configurable: true
  55. });
  56. Object.defineProperty(Environment.prototype, "isElectronRenderer", {
  57. get: function () {
  58. this._detect();
  59. return this._isElectronRenderer;
  60. },
  61. enumerable: true,
  62. configurable: true
  63. });
  64. Object.defineProperty(Environment.prototype, "isWebWorker", {
  65. get: function () {
  66. this._detect();
  67. return this._isWebWorker;
  68. },
  69. enumerable: true,
  70. configurable: true
  71. });
  72. Environment.prototype._detect = function () {
  73. if (this._detected) {
  74. return;
  75. }
  76. this._detected = true;
  77. this._isWindows = Environment._isWindows();
  78. this._isNode = (typeof module !== 'undefined' && !!module.exports);
  79. this._isElectronRenderer = (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined' && process.type === 'renderer');
  80. this._isWebWorker = (typeof AMDLoader.global.importScripts === 'function');
  81. };
  82. Environment._isWindows = function () {
  83. if (typeof navigator !== 'undefined') {
  84. if (navigator.userAgent && navigator.userAgent.indexOf('Windows') >= 0) {
  85. return true;
  86. }
  87. }
  88. if (typeof process !== 'undefined') {
  89. return (process.platform === 'win32');
  90. }
  91. return false;
  92. };
  93. return Environment;
  94. }());
  95. AMDLoader.Environment = Environment;
  96. })(AMDLoader || (AMDLoader = {}));
  97. /*---------------------------------------------------------------------------------------------
  98. * Copyright (c) Microsoft Corporation. All rights reserved.
  99. * Licensed under the MIT License. See License.txt in the project root for license information.
  100. *--------------------------------------------------------------------------------------------*/
  101. var AMDLoader;
  102. (function (AMDLoader) {
  103. var LoaderEvent = (function () {
  104. function LoaderEvent(type, detail, timestamp) {
  105. this.type = type;
  106. this.detail = detail;
  107. this.timestamp = timestamp;
  108. }
  109. return LoaderEvent;
  110. }());
  111. AMDLoader.LoaderEvent = LoaderEvent;
  112. var LoaderEventRecorder = (function () {
  113. function LoaderEventRecorder(loaderAvailableTimestamp) {
  114. this._events = [new LoaderEvent(1 /* LoaderAvailable */, '', loaderAvailableTimestamp)];
  115. }
  116. LoaderEventRecorder.prototype.record = function (type, detail) {
  117. this._events.push(new LoaderEvent(type, detail, AMDLoader.Utilities.getHighPerformanceTimestamp()));
  118. };
  119. LoaderEventRecorder.prototype.getEvents = function () {
  120. return this._events;
  121. };
  122. return LoaderEventRecorder;
  123. }());
  124. AMDLoader.LoaderEventRecorder = LoaderEventRecorder;
  125. var NullLoaderEventRecorder = (function () {
  126. function NullLoaderEventRecorder() {
  127. }
  128. NullLoaderEventRecorder.prototype.record = function (type, detail) {
  129. // Nothing to do
  130. };
  131. NullLoaderEventRecorder.prototype.getEvents = function () {
  132. return [];
  133. };
  134. return NullLoaderEventRecorder;
  135. }());
  136. NullLoaderEventRecorder.INSTANCE = new NullLoaderEventRecorder();
  137. AMDLoader.NullLoaderEventRecorder = NullLoaderEventRecorder;
  138. })(AMDLoader || (AMDLoader = {}));
  139. /*---------------------------------------------------------------------------------------------
  140. * Copyright (c) Microsoft Corporation. All rights reserved.
  141. * Licensed under the MIT License. See License.txt in the project root for license information.
  142. *--------------------------------------------------------------------------------------------*/
  143. var AMDLoader;
  144. (function (AMDLoader) {
  145. var Utilities = (function () {
  146. function Utilities() {
  147. }
  148. /**
  149. * This method does not take care of / vs \
  150. */
  151. Utilities.fileUriToFilePath = function (isWindows, uri) {
  152. uri = decodeURI(uri).replace(/%23/g, '#');
  153. if (isWindows) {
  154. if (/^file:\/\/\//.test(uri)) {
  155. // This is a URI without a hostname => return only the path segment
  156. return uri.substr(8);
  157. }
  158. if (/^file:\/\//.test(uri)) {
  159. return uri.substr(5);
  160. }
  161. }
  162. else {
  163. if (/^file:\/\//.test(uri)) {
  164. return uri.substr(7);
  165. }
  166. }
  167. // Not sure...
  168. return uri;
  169. };
  170. Utilities.startsWith = function (haystack, needle) {
  171. return haystack.length >= needle.length && haystack.substr(0, needle.length) === needle;
  172. };
  173. Utilities.endsWith = function (haystack, needle) {
  174. return haystack.length >= needle.length && haystack.substr(haystack.length - needle.length) === needle;
  175. };
  176. // only check for "?" before "#" to ensure that there is a real Query-String
  177. Utilities.containsQueryString = function (url) {
  178. return /^[^\#]*\?/gi.test(url);
  179. };
  180. /**
  181. * Does `url` start with http:// or https:// or file:// or / ?
  182. */
  183. Utilities.isAbsolutePath = function (url) {
  184. return /^((http:\/\/)|(https:\/\/)|(file:\/\/)|(\/))/.test(url);
  185. };
  186. Utilities.forEachProperty = function (obj, callback) {
  187. if (obj) {
  188. var key = void 0;
  189. for (key in obj) {
  190. if (obj.hasOwnProperty(key)) {
  191. callback(key, obj[key]);
  192. }
  193. }
  194. }
  195. };
  196. Utilities.isEmpty = function (obj) {
  197. var isEmpty = true;
  198. Utilities.forEachProperty(obj, function () {
  199. isEmpty = false;
  200. });
  201. return isEmpty;
  202. };
  203. Utilities.recursiveClone = function (obj) {
  204. if (!obj || typeof obj !== 'object') {
  205. return obj;
  206. }
  207. var result = Array.isArray(obj) ? [] : {};
  208. Utilities.forEachProperty(obj, function (key, value) {
  209. if (value && typeof value === 'object') {
  210. result[key] = Utilities.recursiveClone(value);
  211. }
  212. else {
  213. result[key] = value;
  214. }
  215. });
  216. return result;
  217. };
  218. Utilities.generateAnonymousModule = function () {
  219. return '===anonymous' + (Utilities.NEXT_ANONYMOUS_ID++) + '===';
  220. };
  221. Utilities.isAnonymousModule = function (id) {
  222. return Utilities.startsWith(id, '===anonymous');
  223. };
  224. Utilities.getHighPerformanceTimestamp = function () {
  225. if (!this.PERFORMANCE_NOW_PROBED) {
  226. this.PERFORMANCE_NOW_PROBED = true;
  227. this.HAS_PERFORMANCE_NOW = (AMDLoader.global.performance && typeof AMDLoader.global.performance.now === 'function');
  228. }
  229. return (this.HAS_PERFORMANCE_NOW ? AMDLoader.global.performance.now() : Date.now());
  230. };
  231. return Utilities;
  232. }());
  233. Utilities.NEXT_ANONYMOUS_ID = 1;
  234. Utilities.PERFORMANCE_NOW_PROBED = false;
  235. Utilities.HAS_PERFORMANCE_NOW = false;
  236. AMDLoader.Utilities = Utilities;
  237. })(AMDLoader || (AMDLoader = {}));
  238. /*---------------------------------------------------------------------------------------------
  239. * Copyright (c) Microsoft Corporation. All rights reserved.
  240. * Licensed under the MIT License. See License.txt in the project root for license information.
  241. *--------------------------------------------------------------------------------------------*/
  242. var AMDLoader;
  243. (function (AMDLoader) {
  244. var ConfigurationOptionsUtil = (function () {
  245. function ConfigurationOptionsUtil() {
  246. }
  247. /**
  248. * Ensure configuration options make sense
  249. */
  250. ConfigurationOptionsUtil.validateConfigurationOptions = function (options) {
  251. function defaultOnError(err) {
  252. if (err.errorCode === 'load') {
  253. console.error('Loading "' + err.moduleId + '" failed');
  254. console.error('Detail: ', err.detail);
  255. if (err.detail && err.detail.stack) {
  256. console.error(err.detail.stack);
  257. }
  258. console.error('Here are the modules that depend on it:');
  259. console.error(err.neededBy);
  260. return;
  261. }
  262. if (err.errorCode === 'factory') {
  263. console.error('The factory method of "' + err.moduleId + '" has thrown an exception');
  264. console.error(err.detail);
  265. if (err.detail && err.detail.stack) {
  266. console.error(err.detail.stack);
  267. }
  268. return;
  269. }
  270. }
  271. options = options || {};
  272. if (typeof options.baseUrl !== 'string') {
  273. options.baseUrl = '';
  274. }
  275. if (typeof options.isBuild !== 'boolean') {
  276. options.isBuild = false;
  277. }
  278. if (typeof options.paths !== 'object') {
  279. options.paths = {};
  280. }
  281. if (typeof options.config !== 'object') {
  282. options.config = {};
  283. }
  284. if (typeof options.catchError === 'undefined') {
  285. options.catchError = false;
  286. }
  287. if (typeof options.urlArgs !== 'string') {
  288. options.urlArgs = '';
  289. }
  290. if (typeof options.onError !== 'function') {
  291. options.onError = defaultOnError;
  292. }
  293. if (typeof options.ignoreDuplicateModules !== 'object' || !Array.isArray(options.ignoreDuplicateModules)) {
  294. options.ignoreDuplicateModules = [];
  295. }
  296. if (options.baseUrl.length > 0) {
  297. if (!AMDLoader.Utilities.endsWith(options.baseUrl, '/')) {
  298. options.baseUrl += '/';
  299. }
  300. }
  301. if (typeof options.cspNonce !== 'string') {
  302. options.cspNonce = '';
  303. }
  304. if (!Array.isArray(options.nodeModules)) {
  305. options.nodeModules = [];
  306. }
  307. if (typeof options.nodeCachedDataWriteDelay !== 'number' || options.nodeCachedDataWriteDelay < 0) {
  308. options.nodeCachedDataWriteDelay = 1000 * 7;
  309. }
  310. if (typeof options.onNodeCachedData !== 'function') {
  311. options.onNodeCachedData = function (err, data) {
  312. if (!err) {
  313. // ignore
  314. }
  315. else if (err.errorCode === 'cachedDataRejected') {
  316. console.warn('Rejected cached data from file: ' + err.path);
  317. }
  318. else if (err.errorCode === 'unlink' || err.errorCode === 'writeFile') {
  319. console.error('Problems writing cached data file: ' + err.path);
  320. console.error(err.detail);
  321. }
  322. else {
  323. console.error(err);
  324. }
  325. };
  326. }
  327. return options;
  328. };
  329. ConfigurationOptionsUtil.mergeConfigurationOptions = function (overwrite, base) {
  330. if (overwrite === void 0) { overwrite = null; }
  331. if (base === void 0) { base = null; }
  332. var result = AMDLoader.Utilities.recursiveClone(base || {});
  333. // Merge known properties and overwrite the unknown ones
  334. AMDLoader.Utilities.forEachProperty(overwrite, function (key, value) {
  335. if (key === 'ignoreDuplicateModules' && typeof result.ignoreDuplicateModules !== 'undefined') {
  336. result.ignoreDuplicateModules = result.ignoreDuplicateModules.concat(value);
  337. }
  338. else if (key === 'paths' && typeof result.paths !== 'undefined') {
  339. AMDLoader.Utilities.forEachProperty(value, function (key2, value2) { return result.paths[key2] = value2; });
  340. }
  341. else if (key === 'config' && typeof result.config !== 'undefined') {
  342. AMDLoader.Utilities.forEachProperty(value, function (key2, value2) { return result.config[key2] = value2; });
  343. }
  344. else {
  345. result[key] = AMDLoader.Utilities.recursiveClone(value);
  346. }
  347. });
  348. return ConfigurationOptionsUtil.validateConfigurationOptions(result);
  349. };
  350. return ConfigurationOptionsUtil;
  351. }());
  352. AMDLoader.ConfigurationOptionsUtil = ConfigurationOptionsUtil;
  353. var Configuration = (function () {
  354. function Configuration(env, options) {
  355. this._env = env;
  356. this.options = ConfigurationOptionsUtil.mergeConfigurationOptions(options);
  357. this._createIgnoreDuplicateModulesMap();
  358. this._createNodeModulesMap();
  359. this._createSortedPathsRules();
  360. if (this.options.baseUrl === '') {
  361. if (this.options.nodeRequire && this.options.nodeRequire.main && this.options.nodeRequire.main.filename && this._env.isNode) {
  362. var nodeMain = this.options.nodeRequire.main.filename;
  363. var dirnameIndex = Math.max(nodeMain.lastIndexOf('/'), nodeMain.lastIndexOf('\\'));
  364. this.options.baseUrl = nodeMain.substring(0, dirnameIndex + 1);
  365. }
  366. if (this.options.nodeMain && this._env.isNode) {
  367. var nodeMain = this.options.nodeMain;
  368. var dirnameIndex = Math.max(nodeMain.lastIndexOf('/'), nodeMain.lastIndexOf('\\'));
  369. this.options.baseUrl = nodeMain.substring(0, dirnameIndex + 1);
  370. }
  371. }
  372. }
  373. Configuration.prototype._createIgnoreDuplicateModulesMap = function () {
  374. // Build a map out of the ignoreDuplicateModules array
  375. this.ignoreDuplicateModulesMap = {};
  376. for (var i = 0; i < this.options.ignoreDuplicateModules.length; i++) {
  377. this.ignoreDuplicateModulesMap[this.options.ignoreDuplicateModules[i]] = true;
  378. }
  379. };
  380. Configuration.prototype._createNodeModulesMap = function () {
  381. // Build a map out of nodeModules array
  382. this.nodeModulesMap = Object.create(null);
  383. for (var _i = 0, _a = this.options.nodeModules; _i < _a.length; _i++) {
  384. var nodeModule = _a[_i];
  385. this.nodeModulesMap[nodeModule] = true;
  386. }
  387. };
  388. Configuration.prototype._createSortedPathsRules = function () {
  389. var _this = this;
  390. // Create an array our of the paths rules, sorted descending by length to
  391. // result in a more specific -> less specific order
  392. this.sortedPathsRules = [];
  393. AMDLoader.Utilities.forEachProperty(this.options.paths, function (from, to) {
  394. if (!Array.isArray(to)) {
  395. _this.sortedPathsRules.push({
  396. from: from,
  397. to: [to]
  398. });
  399. }
  400. else {
  401. _this.sortedPathsRules.push({
  402. from: from,
  403. to: to
  404. });
  405. }
  406. });
  407. this.sortedPathsRules.sort(function (a, b) {
  408. return b.from.length - a.from.length;
  409. });
  410. };
  411. /**
  412. * Clone current configuration and overwrite options selectively.
  413. * @param options The selective options to overwrite with.
  414. * @result A new configuration
  415. */
  416. Configuration.prototype.cloneAndMerge = function (options) {
  417. return new Configuration(this._env, ConfigurationOptionsUtil.mergeConfigurationOptions(options, this.options));
  418. };
  419. /**
  420. * Get current options bag. Useful for passing it forward to plugins.
  421. */
  422. Configuration.prototype.getOptionsLiteral = function () {
  423. return this.options;
  424. };
  425. Configuration.prototype._applyPaths = function (moduleId) {
  426. var pathRule;
  427. for (var i = 0, len = this.sortedPathsRules.length; i < len; i++) {
  428. pathRule = this.sortedPathsRules[i];
  429. if (AMDLoader.Utilities.startsWith(moduleId, pathRule.from)) {
  430. var result = [];
  431. for (var j = 0, lenJ = pathRule.to.length; j < lenJ; j++) {
  432. result.push(pathRule.to[j] + moduleId.substr(pathRule.from.length));
  433. }
  434. return result;
  435. }
  436. }
  437. return [moduleId];
  438. };
  439. Configuration.prototype._addUrlArgsToUrl = function (url) {
  440. if (AMDLoader.Utilities.containsQueryString(url)) {
  441. return url + '&' + this.options.urlArgs;
  442. }
  443. else {
  444. return url + '?' + this.options.urlArgs;
  445. }
  446. };
  447. Configuration.prototype._addUrlArgsIfNecessaryToUrl = function (url) {
  448. if (this.options.urlArgs) {
  449. return this._addUrlArgsToUrl(url);
  450. }
  451. return url;
  452. };
  453. Configuration.prototype._addUrlArgsIfNecessaryToUrls = function (urls) {
  454. if (this.options.urlArgs) {
  455. for (var i = 0, len = urls.length; i < len; i++) {
  456. urls[i] = this._addUrlArgsToUrl(urls[i]);
  457. }
  458. }
  459. return urls;
  460. };
  461. /**
  462. * Transform a module id to a location. Appends .js to module ids
  463. */
  464. Configuration.prototype.moduleIdToPaths = function (moduleId) {
  465. if (this.nodeModulesMap[moduleId] === true) {
  466. // This is a node module...
  467. if (this.isBuild()) {
  468. // ...and we are at build time, drop it
  469. return ['empty:'];
  470. }
  471. else {
  472. // ...and at runtime we create a `shortcut`-path
  473. return ['node|' + moduleId];
  474. }
  475. }
  476. var result = moduleId;
  477. var results;
  478. if (!AMDLoader.Utilities.endsWith(result, '.js') && !AMDLoader.Utilities.isAbsolutePath(result)) {
  479. results = this._applyPaths(result);
  480. for (var i = 0, len = results.length; i < len; i++) {
  481. if (this.isBuild() && results[i] === 'empty:') {
  482. continue;
  483. }
  484. if (!AMDLoader.Utilities.isAbsolutePath(results[i])) {
  485. results[i] = this.options.baseUrl + results[i];
  486. }
  487. if (!AMDLoader.Utilities.endsWith(results[i], '.js') && !AMDLoader.Utilities.containsQueryString(results[i])) {
  488. results[i] = results[i] + '.js';
  489. }
  490. }
  491. }
  492. else {
  493. if (!AMDLoader.Utilities.endsWith(result, '.js') && !AMDLoader.Utilities.containsQueryString(result)) {
  494. result = result + '.js';
  495. }
  496. results = [result];
  497. }
  498. return this._addUrlArgsIfNecessaryToUrls(results);
  499. };
  500. /**
  501. * Transform a module id or url to a location.
  502. */
  503. Configuration.prototype.requireToUrl = function (url) {
  504. var result = url;
  505. if (!AMDLoader.Utilities.isAbsolutePath(result)) {
  506. result = this._applyPaths(result)[0];
  507. if (!AMDLoader.Utilities.isAbsolutePath(result)) {
  508. result = this.options.baseUrl + result;
  509. }
  510. }
  511. return this._addUrlArgsIfNecessaryToUrl(result);
  512. };
  513. /**
  514. * Flag to indicate if current execution is as part of a build.
  515. */
  516. Configuration.prototype.isBuild = function () {
  517. return this.options.isBuild;
  518. };
  519. /**
  520. * Test if module `moduleId` is expected to be defined multiple times
  521. */
  522. Configuration.prototype.isDuplicateMessageIgnoredFor = function (moduleId) {
  523. return this.ignoreDuplicateModulesMap.hasOwnProperty(moduleId);
  524. };
  525. /**
  526. * Get the configuration settings for the provided module id
  527. */
  528. Configuration.prototype.getConfigForModule = function (moduleId) {
  529. if (this.options.config) {
  530. return this.options.config[moduleId];
  531. }
  532. };
  533. /**
  534. * Should errors be caught when executing module factories?
  535. */
  536. Configuration.prototype.shouldCatchError = function () {
  537. return this.options.catchError;
  538. };
  539. /**
  540. * Should statistics be recorded?
  541. */
  542. Configuration.prototype.shouldRecordStats = function () {
  543. return this.options.recordStats;
  544. };
  545. /**
  546. * Forward an error to the error handler.
  547. */
  548. Configuration.prototype.onError = function (err) {
  549. this.options.onError(err);
  550. };
  551. return Configuration;
  552. }());
  553. AMDLoader.Configuration = Configuration;
  554. })(AMDLoader || (AMDLoader = {}));
  555. /*---------------------------------------------------------------------------------------------
  556. * Copyright (c) Microsoft Corporation. All rights reserved.
  557. * Licensed under the MIT License. See License.txt in the project root for license information.
  558. *--------------------------------------------------------------------------------------------*/
  559. var AMDLoader;
  560. (function (AMDLoader) {
  561. /**
  562. * Load `scriptSrc` only once (avoid multiple <script> tags)
  563. */
  564. var OnlyOnceScriptLoader = (function () {
  565. function OnlyOnceScriptLoader(env) {
  566. this._env = env;
  567. this._scriptLoader = null;
  568. this._callbackMap = {};
  569. }
  570. OnlyOnceScriptLoader.prototype.load = function (moduleManager, scriptSrc, callback, errorback) {
  571. var _this = this;
  572. if (!this._scriptLoader) {
  573. this._scriptLoader = (this._env.isWebWorker
  574. ? new WorkerScriptLoader()
  575. : this._env.isNode
  576. ? new NodeScriptLoader(this._env)
  577. : new BrowserScriptLoader());
  578. }
  579. var scriptCallbacks = {
  580. callback: callback,
  581. errorback: errorback
  582. };
  583. if (this._callbackMap.hasOwnProperty(scriptSrc)) {
  584. this._callbackMap[scriptSrc].push(scriptCallbacks);
  585. return;
  586. }
  587. this._callbackMap[scriptSrc] = [scriptCallbacks];
  588. this._scriptLoader.load(moduleManager, scriptSrc, function () { return _this.triggerCallback(scriptSrc); }, function (err) { return _this.triggerErrorback(scriptSrc, err); });
  589. };
  590. OnlyOnceScriptLoader.prototype.triggerCallback = function (scriptSrc) {
  591. var scriptCallbacks = this._callbackMap[scriptSrc];
  592. delete this._callbackMap[scriptSrc];
  593. for (var i = 0; i < scriptCallbacks.length; i++) {
  594. scriptCallbacks[i].callback();
  595. }
  596. };
  597. OnlyOnceScriptLoader.prototype.triggerErrorback = function (scriptSrc, err) {
  598. var scriptCallbacks = this._callbackMap[scriptSrc];
  599. delete this._callbackMap[scriptSrc];
  600. for (var i = 0; i < scriptCallbacks.length; i++) {
  601. scriptCallbacks[i].errorback(err);
  602. }
  603. };
  604. return OnlyOnceScriptLoader;
  605. }());
  606. var BrowserScriptLoader = (function () {
  607. function BrowserScriptLoader() {
  608. }
  609. /**
  610. * Attach load / error listeners to a script element and remove them when either one has fired.
  611. * Implemented for browssers supporting HTML5 standard 'load' and 'error' events.
  612. */
  613. BrowserScriptLoader.prototype.attachListeners = function (script, callback, errorback) {
  614. var unbind = function () {
  615. script.removeEventListener('load', loadEventListener);
  616. script.removeEventListener('error', errorEventListener);
  617. };
  618. var loadEventListener = function (e) {
  619. unbind();
  620. callback();
  621. };
  622. var errorEventListener = function (e) {
  623. unbind();
  624. errorback(e);
  625. };
  626. script.addEventListener('load', loadEventListener);
  627. script.addEventListener('error', errorEventListener);
  628. };
  629. BrowserScriptLoader.prototype.load = function (moduleManager, scriptSrc, callback, errorback) {
  630. var script = document.createElement('script');
  631. script.setAttribute('async', 'async');
  632. script.setAttribute('type', 'text/javascript');
  633. this.attachListeners(script, callback, errorback);
  634. script.setAttribute('src', scriptSrc);
  635. // Propagate CSP nonce to dynamically created script tag.
  636. var cspNonce = moduleManager.getConfig().getOptionsLiteral().cspNonce;
  637. if (cspNonce) {
  638. script.setAttribute('nonce', cspNonce);
  639. }
  640. document.getElementsByTagName('head')[0].appendChild(script);
  641. };
  642. return BrowserScriptLoader;
  643. }());
  644. var WorkerScriptLoader = (function () {
  645. function WorkerScriptLoader() {
  646. }
  647. WorkerScriptLoader.prototype.load = function (moduleManager, scriptSrc, callback, errorback) {
  648. try {
  649. importScripts(scriptSrc);
  650. callback();
  651. }
  652. catch (e) {
  653. errorback(e);
  654. }
  655. };
  656. return WorkerScriptLoader;
  657. }());
  658. var NodeScriptLoader = (function () {
  659. function NodeScriptLoader(env) {
  660. this._env = env;
  661. this._didInitialize = false;
  662. this._didPatchNodeRequire = false;
  663. }
  664. NodeScriptLoader.prototype._init = function (nodeRequire) {
  665. if (this._didInitialize) {
  666. return;
  667. }
  668. this._didInitialize = true;
  669. // capture node modules
  670. this._fs = nodeRequire('fs');
  671. this._vm = nodeRequire('vm');
  672. this._path = nodeRequire('path');
  673. this._crypto = nodeRequire('crypto');
  674. // js-flags have an impact on cached data
  675. this._jsflags = '';
  676. for (var _i = 0, _a = process.argv; _i < _a.length; _i++) {
  677. var arg = _a[_i];
  678. if (arg.indexOf('--js-flags=') === 0) {
  679. this._jsflags = arg;
  680. break;
  681. }
  682. }
  683. };
  684. // patch require-function of nodejs such that we can manually create a script
  685. // from cached data. this is done by overriding the `Module._compile` function
  686. NodeScriptLoader.prototype._initNodeRequire = function (nodeRequire, moduleManager) {
  687. var nodeCachedDataDir = moduleManager.getConfig().getOptionsLiteral().nodeCachedDataDir;
  688. if (!nodeCachedDataDir || this._didPatchNodeRequire) {
  689. return;
  690. }
  691. this._didPatchNodeRequire = true;
  692. var that = this;
  693. var Module = nodeRequire('module');
  694. function makeRequireFunction(mod) {
  695. var Module = mod.constructor;
  696. var require = function require(path) {
  697. try {
  698. return mod.require(path);
  699. }
  700. finally {
  701. // nothing
  702. }
  703. };
  704. require.resolve = function resolve(request) {
  705. return Module._resolveFilename(request, mod);
  706. };
  707. require.main = process.mainModule;
  708. require.extensions = Module._extensions;
  709. require.cache = Module._cache;
  710. return require;
  711. }
  712. Module.prototype._compile = function (content, filename) {
  713. // remove shebang
  714. content = content.replace(/^#!.*/, '');
  715. // create wrapper function
  716. var wrapper = Module.wrap(content);
  717. var cachedDataPath = that._getCachedDataPath(nodeCachedDataDir, filename);
  718. var options = { filename: filename };
  719. try {
  720. options.cachedData = that._fs.readFileSync(cachedDataPath);
  721. }
  722. catch (e) {
  723. options.produceCachedData = true;
  724. }
  725. var script = new that._vm.Script(wrapper, options);
  726. var compileWrapper = script.runInThisContext(options);
  727. var dirname = that._path.dirname(filename);
  728. var require = makeRequireFunction(this);
  729. var args = [this.exports, require, this, filename, dirname, process, _commonjsGlobal, Buffer];
  730. var result = compileWrapper.apply(this.exports, args);
  731. that._processCachedData(moduleManager, script, cachedDataPath);
  732. return result;
  733. };
  734. };
  735. NodeScriptLoader.prototype.load = function (moduleManager, scriptSrc, callback, errorback) {
  736. var _this = this;
  737. var opts = moduleManager.getConfig().getOptionsLiteral();
  738. var nodeRequire = (opts.nodeRequire || AMDLoader.global.nodeRequire);
  739. var nodeInstrumenter = (opts.nodeInstrumenter || function (c) { return c; });
  740. this._init(nodeRequire);
  741. this._initNodeRequire(nodeRequire, moduleManager);
  742. var recorder = moduleManager.getRecorder();
  743. if (/^node\|/.test(scriptSrc)) {
  744. var pieces = scriptSrc.split('|');
  745. var moduleExports_1 = null;
  746. try {
  747. moduleExports_1 = nodeRequire(pieces[1]);
  748. }
  749. catch (err) {
  750. errorback(err);
  751. return;
  752. }
  753. moduleManager.enqueueDefineAnonymousModule([], function () { return moduleExports_1; });
  754. callback();
  755. }
  756. else {
  757. scriptSrc = AMDLoader.Utilities.fileUriToFilePath(this._env.isWindows, scriptSrc);
  758. this._fs.readFile(scriptSrc, { encoding: 'utf8' }, function (err, data) {
  759. if (err) {
  760. errorback(err);
  761. return;
  762. }
  763. var normalizedScriptSrc = _this._path.normalize(scriptSrc);
  764. var vmScriptSrc = normalizedScriptSrc;
  765. // Make the script src friendly towards electron
  766. if (_this._env.isElectronRenderer) {
  767. var driveLetterMatch = vmScriptSrc.match(/^([a-z])\:(.*)/i);
  768. if (driveLetterMatch) {
  769. // windows
  770. vmScriptSrc = "file:///" + (driveLetterMatch[1].toUpperCase() + ':' + driveLetterMatch[2]).replace(/\\/g, '/');
  771. }
  772. else {
  773. // nix
  774. vmScriptSrc = "file://" + vmScriptSrc;
  775. }
  776. }
  777. var contents, prefix = '(function (require, define, __filename, __dirname) { ', suffix = '\n});';
  778. if (data.charCodeAt(0) === NodeScriptLoader._BOM) {
  779. contents = prefix + data.substring(1) + suffix;
  780. }
  781. else {
  782. contents = prefix + data + suffix;
  783. }
  784. contents = nodeInstrumenter(contents, normalizedScriptSrc);
  785. if (!opts.nodeCachedDataDir) {
  786. _this._loadAndEvalScript(moduleManager, scriptSrc, vmScriptSrc, contents, { filename: vmScriptSrc }, recorder, callback, errorback);
  787. }
  788. else {
  789. var cachedDataPath_1 = _this._getCachedDataPath(opts.nodeCachedDataDir, scriptSrc);
  790. _this._fs.readFile(cachedDataPath_1, function (err, cachedData) {
  791. // create script options
  792. var options = {
  793. filename: vmScriptSrc,
  794. produceCachedData: typeof cachedData === 'undefined',
  795. cachedData: cachedData
  796. };
  797. var script = _this._loadAndEvalScript(moduleManager, scriptSrc, vmScriptSrc, contents, options, recorder, callback, errorback);
  798. _this._processCachedData(moduleManager, script, cachedDataPath_1);
  799. });
  800. }
  801. });
  802. }
  803. };
  804. NodeScriptLoader.prototype._loadAndEvalScript = function (moduleManager, scriptSrc, vmScriptSrc, contents, options, recorder, callback, errorback) {
  805. // create script, run script
  806. recorder.record(31 /* NodeBeginEvaluatingScript */, scriptSrc);
  807. var script = new this._vm.Script(contents, options);
  808. var r = script.runInThisContext(options);
  809. var globalDefineFunc = moduleManager.getGlobalAMDDefineFunc();
  810. var receivedDefineCall = false;
  811. var localDefineFunc = function () {
  812. receivedDefineCall = true;
  813. return globalDefineFunc.apply(null, arguments);
  814. };
  815. localDefineFunc.amd = globalDefineFunc.amd;
  816. r.call(AMDLoader.global, moduleManager.getGlobalAMDRequireFunc(), localDefineFunc, vmScriptSrc, this._path.dirname(scriptSrc));
  817. // signal done
  818. recorder.record(32 /* NodeEndEvaluatingScript */, scriptSrc);
  819. if (receivedDefineCall) {
  820. callback();
  821. }
  822. else {
  823. errorback(new Error("Didn't receive define call in " + scriptSrc + "!"));
  824. }
  825. return script;
  826. };
  827. NodeScriptLoader.prototype._getCachedDataPath = function (basedir, filename) {
  828. var hash = this._crypto.createHash('md5').update(filename, 'utf8').update(this._jsflags, 'utf8').digest('hex');
  829. var basename = this._path.basename(filename).replace(/\.js$/, '');
  830. return this._path.join(basedir, basename + "-" + hash + ".code");
  831. };
  832. NodeScriptLoader.prototype._processCachedData = function (moduleManager, script, cachedDataPath) {
  833. var _this = this;
  834. if (script.cachedDataRejected) {
  835. // data rejected => delete cache file
  836. moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
  837. errorCode: 'cachedDataRejected',
  838. path: cachedDataPath
  839. });
  840. NodeScriptLoader._runSoon(function () {
  841. return _this._fs.unlink(cachedDataPath, function (err) {
  842. if (err) {
  843. moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
  844. errorCode: 'unlink',
  845. path: cachedDataPath,
  846. detail: err
  847. });
  848. }
  849. });
  850. }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
  851. }
  852. else if (script.cachedDataProduced) {
  853. // data produced => tell outside world
  854. moduleManager.getConfig().getOptionsLiteral().onNodeCachedData(undefined, {
  855. path: cachedDataPath,
  856. length: script.cachedData.length
  857. });
  858. // data produced => write cache file
  859. NodeScriptLoader._runSoon(function () {
  860. return _this._fs.writeFile(cachedDataPath, script.cachedData, function (err) {
  861. if (err) {
  862. moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
  863. errorCode: 'writeFile',
  864. path: cachedDataPath,
  865. detail: err
  866. });
  867. }
  868. });
  869. }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
  870. }
  871. };
  872. NodeScriptLoader._runSoon = function (callback, minTimeout) {
  873. var timeout = minTimeout + Math.ceil(Math.random() * minTimeout);
  874. setTimeout(callback, timeout);
  875. };
  876. return NodeScriptLoader;
  877. }());
  878. NodeScriptLoader._BOM = 0xFEFF;
  879. function createScriptLoader(env) {
  880. return new OnlyOnceScriptLoader(env);
  881. }
  882. AMDLoader.createScriptLoader = createScriptLoader;
  883. })(AMDLoader || (AMDLoader = {}));
  884. /*---------------------------------------------------------------------------------------------
  885. * Copyright (c) Microsoft Corporation. All rights reserved.
  886. * Licensed under the MIT License. See License.txt in the project root for license information.
  887. *--------------------------------------------------------------------------------------------*/
  888. var AMDLoader;
  889. (function (AMDLoader) {
  890. // ------------------------------------------------------------------------
  891. // ModuleIdResolver
  892. var ModuleIdResolver = (function () {
  893. function ModuleIdResolver(fromModuleId) {
  894. var lastSlash = fromModuleId.lastIndexOf('/');
  895. if (lastSlash !== -1) {
  896. this.fromModulePath = fromModuleId.substr(0, lastSlash + 1);
  897. }
  898. else {
  899. this.fromModulePath = '';
  900. }
  901. }
  902. /**
  903. * Normalize 'a/../name' to 'name', etc.
  904. */
  905. ModuleIdResolver._normalizeModuleId = function (moduleId) {
  906. var r = moduleId, pattern;
  907. // replace /./ => /
  908. pattern = /\/\.\//;
  909. while (pattern.test(r)) {
  910. r = r.replace(pattern, '/');
  911. }
  912. // replace ^./ => nothing
  913. r = r.replace(/^\.\//g, '');
  914. // replace /aa/../ => / (BUT IGNORE /../../)
  915. pattern = /\/(([^\/])|([^\/][^\/\.])|([^\/\.][^\/])|([^\/][^\/][^\/]+))\/\.\.\//;
  916. while (pattern.test(r)) {
  917. r = r.replace(pattern, '/');
  918. }
  919. // replace ^aa/../ => nothing (BUT IGNORE ../../)
  920. r = r.replace(/^(([^\/])|([^\/][^\/\.])|([^\/\.][^\/])|([^\/][^\/][^\/]+))\/\.\.\//, '');
  921. return r;
  922. };
  923. /**
  924. * Resolve relative module ids
  925. */
  926. ModuleIdResolver.prototype.resolveModule = function (moduleId) {
  927. var result = moduleId;
  928. if (!AMDLoader.Utilities.isAbsolutePath(result)) {
  929. if (AMDLoader.Utilities.startsWith(result, './') || AMDLoader.Utilities.startsWith(result, '../')) {
  930. result = ModuleIdResolver._normalizeModuleId(this.fromModulePath + result);
  931. }
  932. }
  933. return result;
  934. };
  935. return ModuleIdResolver;
  936. }());
  937. ModuleIdResolver.ROOT = new ModuleIdResolver('');
  938. AMDLoader.ModuleIdResolver = ModuleIdResolver;
  939. // ------------------------------------------------------------------------
  940. // Module
  941. var Module = (function () {
  942. function Module(id, strId, dependencies, callback, errorback, moduleIdResolver) {
  943. this.id = id;
  944. this.strId = strId;
  945. this.dependencies = dependencies;
  946. this._callback = callback;
  947. this._errorback = errorback;
  948. this.moduleIdResolver = moduleIdResolver;
  949. this.exports = {};
  950. this.exportsPassedIn = false;
  951. this.unresolvedDependenciesCount = this.dependencies.length;
  952. this._isComplete = false;
  953. }
  954. Module._safeInvokeFunction = function (callback, args) {
  955. try {
  956. return {
  957. returnedValue: callback.apply(AMDLoader.global, args),
  958. producedError: null
  959. };
  960. }
  961. catch (e) {
  962. return {
  963. returnedValue: null,
  964. producedError: e
  965. };
  966. }
  967. };
  968. Module._invokeFactory = function (config, strModuleId, callback, dependenciesValues) {
  969. if (config.isBuild() && !AMDLoader.Utilities.isAnonymousModule(strModuleId)) {
  970. return {
  971. returnedValue: null,
  972. producedError: null
  973. };
  974. }
  975. if (config.shouldCatchError()) {
  976. return this._safeInvokeFunction(callback, dependenciesValues);
  977. }
  978. return {
  979. returnedValue: callback.apply(AMDLoader.global, dependenciesValues),
  980. producedError: null
  981. };
  982. };
  983. Module.prototype.complete = function (recorder, config, dependenciesValues) {
  984. this._isComplete = true;
  985. var producedError = null;
  986. if (this._callback) {
  987. if (typeof this._callback === 'function') {
  988. recorder.record(21 /* BeginInvokeFactory */, this.strId);
  989. var r = Module._invokeFactory(config, this.strId, this._callback, dependenciesValues);
  990. producedError = r.producedError;
  991. recorder.record(22 /* EndInvokeFactory */, this.strId);
  992. if (!producedError && typeof r.returnedValue !== 'undefined' && (!this.exportsPassedIn || AMDLoader.Utilities.isEmpty(this.exports))) {
  993. this.exports = r.returnedValue;
  994. }
  995. }
  996. else {
  997. this.exports = this._callback;
  998. }
  999. }
  1000. if (producedError) {
  1001. config.onError({
  1002. errorCode: 'factory',
  1003. moduleId: this.strId,
  1004. detail: producedError
  1005. });
  1006. }
  1007. this.dependencies = null;
  1008. this._callback = null;
  1009. this._errorback = null;
  1010. this.moduleIdResolver = null;
  1011. };
  1012. /**
  1013. * One of the direct dependencies or a transitive dependency has failed to load.
  1014. */
  1015. Module.prototype.onDependencyError = function (err) {
  1016. if (this._errorback) {
  1017. this._errorback(err);
  1018. return true;
  1019. }
  1020. return false;
  1021. };
  1022. /**
  1023. * Is the current module complete?
  1024. */
  1025. Module.prototype.isComplete = function () {
  1026. return this._isComplete;
  1027. };
  1028. return Module;
  1029. }());
  1030. AMDLoader.Module = Module;
  1031. var ModuleIdProvider = (function () {
  1032. function ModuleIdProvider() {
  1033. this._nextId = 0;
  1034. this._strModuleIdToIntModuleId = new Map();
  1035. this._intModuleIdToStrModuleId = [];
  1036. // Ensure values 0, 1, 2 are assigned accordingly with ModuleId
  1037. this.getModuleId('exports');
  1038. this.getModuleId('module');
  1039. this.getModuleId('require');
  1040. }
  1041. ModuleIdProvider.prototype.getMaxModuleId = function () {
  1042. return this._nextId;
  1043. };
  1044. ModuleIdProvider.prototype.getModuleId = function (strModuleId) {
  1045. var id = this._strModuleIdToIntModuleId.get(strModuleId);
  1046. if (typeof id === 'undefined') {
  1047. id = this._nextId++;
  1048. this._strModuleIdToIntModuleId.set(strModuleId, id);
  1049. this._intModuleIdToStrModuleId[id] = strModuleId;
  1050. }
  1051. return id;
  1052. };
  1053. ModuleIdProvider.prototype.getStrModuleId = function (moduleId) {
  1054. return this._intModuleIdToStrModuleId[moduleId];
  1055. };
  1056. return ModuleIdProvider;
  1057. }());
  1058. var RegularDependency = (function () {
  1059. function RegularDependency(id) {
  1060. this.id = id;
  1061. }
  1062. return RegularDependency;
  1063. }());
  1064. RegularDependency.EXPORTS = new RegularDependency(0 /* EXPORTS */);
  1065. RegularDependency.MODULE = new RegularDependency(1 /* MODULE */);
  1066. RegularDependency.REQUIRE = new RegularDependency(2 /* REQUIRE */);
  1067. AMDLoader.RegularDependency = RegularDependency;
  1068. var PluginDependency = (function () {
  1069. function PluginDependency(id, pluginId, pluginParam) {
  1070. this.id = id;
  1071. this.pluginId = pluginId;
  1072. this.pluginParam = pluginParam;
  1073. }
  1074. return PluginDependency;
  1075. }());
  1076. AMDLoader.PluginDependency = PluginDependency;
  1077. var ModuleManager = (function () {
  1078. function ModuleManager(env, scriptLoader, defineFunc, requireFunc, loaderAvailableTimestamp) {
  1079. if (loaderAvailableTimestamp === void 0) { loaderAvailableTimestamp = 0; }
  1080. this._env = env;
  1081. this._scriptLoader = scriptLoader;
  1082. this._loaderAvailableTimestamp = loaderAvailableTimestamp;
  1083. this._defineFunc = defineFunc;
  1084. this._requireFunc = requireFunc;
  1085. this._moduleIdProvider = new ModuleIdProvider();
  1086. this._config = new AMDLoader.Configuration(this._env);
  1087. this._modules2 = [];
  1088. this._knownModules2 = [];
  1089. this._inverseDependencies2 = [];
  1090. this._inversePluginDependencies2 = new Map();
  1091. this._currentAnnonymousDefineCall = null;
  1092. this._recorder = null;
  1093. this._buildInfoPath = [];
  1094. this._buildInfoDefineStack = [];
  1095. this._buildInfoDependencies = [];
  1096. }
  1097. ModuleManager.prototype.reset = function () {
  1098. return new ModuleManager(this._env, this._scriptLoader, this._defineFunc, this._requireFunc, this._loaderAvailableTimestamp);
  1099. };
  1100. ModuleManager.prototype.getGlobalAMDDefineFunc = function () {
  1101. return this._defineFunc;
  1102. };
  1103. ModuleManager.prototype.getGlobalAMDRequireFunc = function () {
  1104. return this._requireFunc;
  1105. };
  1106. ModuleManager._findRelevantLocationInStack = function (needle, stack) {
  1107. var normalize = function (str) { return str.replace(/\\/g, '/'); };
  1108. var normalizedPath = normalize(needle);
  1109. var stackPieces = stack.split(/\n/);
  1110. for (var i = 0; i < stackPieces.length; i++) {
  1111. var m = stackPieces[i].match(/(.*):(\d+):(\d+)\)?$/);
  1112. if (m) {
  1113. var stackPath = m[1];
  1114. var stackLine = m[2];
  1115. var stackColumn = m[3];
  1116. var trimPathOffset = Math.max(stackPath.lastIndexOf(' ') + 1, stackPath.lastIndexOf('(') + 1);
  1117. stackPath = stackPath.substr(trimPathOffset);
  1118. stackPath = normalize(stackPath);
  1119. if (stackPath === normalizedPath) {
  1120. var r = {
  1121. line: parseInt(stackLine, 10),
  1122. col: parseInt(stackColumn, 10)
  1123. };
  1124. if (r.line === 1) {
  1125. r.col -= '(function (require, define, __filename, __dirname) { '.length;
  1126. }
  1127. return r;
  1128. }
  1129. }
  1130. }
  1131. throw new Error('Could not correlate define call site for needle ' + needle);
  1132. };
  1133. ModuleManager.prototype.getBuildInfo = function () {
  1134. if (!this._config.isBuild()) {
  1135. return null;
  1136. }
  1137. var result = [], resultLen = 0;
  1138. for (var i = 0, len = this._modules2.length; i < len; i++) {
  1139. var m = this._modules2[i];
  1140. if (!m) {
  1141. continue;
  1142. }
  1143. var location_1 = this._buildInfoPath[m.id] || null;
  1144. var defineStack = this._buildInfoDefineStack[m.id] || null;
  1145. var dependencies = this._buildInfoDependencies[m.id];
  1146. result[resultLen++] = {
  1147. id: m.strId,
  1148. path: location_1,
  1149. defineLocation: (location_1 && defineStack ? ModuleManager._findRelevantLocationInStack(location_1, defineStack) : null),
  1150. dependencies: dependencies,
  1151. shim: null,
  1152. exports: m.exports
  1153. };
  1154. }
  1155. return result;
  1156. };
  1157. ModuleManager.prototype.getRecorder = function () {
  1158. if (!this._recorder) {
  1159. if (this._config.shouldRecordStats()) {
  1160. this._recorder = new AMDLoader.LoaderEventRecorder(this._loaderAvailableTimestamp);
  1161. }
  1162. else {
  1163. this._recorder = AMDLoader.NullLoaderEventRecorder.INSTANCE;
  1164. }
  1165. }
  1166. return this._recorder;
  1167. };
  1168. ModuleManager.prototype.getLoaderEvents = function () {
  1169. return this.getRecorder().getEvents();
  1170. };
  1171. /**
  1172. * Defines an anonymous module (without an id). Its name will be resolved as we receive a callback from the scriptLoader.
  1173. * @param dependecies @see defineModule
  1174. * @param callback @see defineModule
  1175. */
  1176. ModuleManager.prototype.enqueueDefineAnonymousModule = function (dependencies, callback) {
  1177. if (this._currentAnnonymousDefineCall !== null) {
  1178. throw new Error('Can only have one anonymous define call per script file');
  1179. }
  1180. var stack = null;
  1181. if (this._config.isBuild()) {
  1182. stack = new Error('StackLocation').stack;
  1183. }
  1184. this._currentAnnonymousDefineCall = {
  1185. stack: stack,
  1186. dependencies: dependencies,
  1187. callback: callback
  1188. };
  1189. };
  1190. /**
  1191. * Creates a module and stores it in _modules. The manager will immediately begin resolving its dependencies.
  1192. * @param strModuleId An unique and absolute id of the module. This must not collide with another module's id
  1193. * @param dependencies An array with the dependencies of the module. Special keys are: "require", "exports" and "module"
  1194. * @param callback if callback is a function, it will be called with the resolved dependencies. if callback is an object, it will be considered as the exports of the module.
  1195. */
  1196. ModuleManager.prototype.defineModule = function (strModuleId, dependencies, callback, errorback, stack, moduleIdResolver) {
  1197. var _this = this;
  1198. if (moduleIdResolver === void 0) { moduleIdResolver = new ModuleIdResolver(strModuleId); }
  1199. var moduleId = this._moduleIdProvider.getModuleId(strModuleId);
  1200. if (this._modules2[moduleId]) {
  1201. if (!this._config.isDuplicateMessageIgnoredFor(strModuleId)) {
  1202. console.warn('Duplicate definition of module \'' + strModuleId + '\'');
  1203. }
  1204. // Super important! Completely ignore duplicate module definition
  1205. return;
  1206. }
  1207. var m = new Module(moduleId, strModuleId, this._normalizeDependencies(dependencies, moduleIdResolver), callback, errorback, moduleIdResolver);
  1208. this._modules2[moduleId] = m;
  1209. if (this._config.isBuild()) {
  1210. this._buildInfoDefineStack[moduleId] = stack;
  1211. this._buildInfoDependencies[moduleId] = m.dependencies.map(function (dep) { return _this._moduleIdProvider.getStrModuleId(dep.id); });
  1212. }
  1213. // Resolving of dependencies is immediate (not in a timeout). If there's a need to support a packer that concatenates in an
  1214. // unordered manner, in order to finish processing the file, execute the following method in a timeout
  1215. this._resolve(m);
  1216. };
  1217. ModuleManager.prototype._normalizeDependency = function (dependency, moduleIdResolver) {
  1218. if (dependency === 'exports') {
  1219. return RegularDependency.EXPORTS;
  1220. }
  1221. if (dependency === 'module') {
  1222. return RegularDependency.MODULE;
  1223. }
  1224. if (dependency === 'require') {
  1225. return RegularDependency.REQUIRE;
  1226. }
  1227. // Normalize dependency and then request it from the manager
  1228. var bangIndex = dependency.indexOf('!');
  1229. if (bangIndex >= 0) {
  1230. var strPluginId = moduleIdResolver.resolveModule(dependency.substr(0, bangIndex));
  1231. var pluginParam = moduleIdResolver.resolveModule(dependency.substr(bangIndex + 1));
  1232. var dependencyId = this._moduleIdProvider.getModuleId(strPluginId + '!' + pluginParam);
  1233. var pluginId = this._moduleIdProvider.getModuleId(strPluginId);
  1234. return new PluginDependency(dependencyId, pluginId, pluginParam);
  1235. }
  1236. return new RegularDependency(this._moduleIdProvider.getModuleId(moduleIdResolver.resolveModule(dependency)));
  1237. };
  1238. ModuleManager.prototype._normalizeDependencies = function (dependencies, moduleIdResolver) {
  1239. var result = [], resultLen = 0;
  1240. for (var i = 0, len = dependencies.length; i < len; i++) {
  1241. result[resultLen++] = this._normalizeDependency(dependencies[i], moduleIdResolver);
  1242. }
  1243. return result;
  1244. };
  1245. ModuleManager.prototype._relativeRequire = function (moduleIdResolver, dependencies, callback, errorback) {
  1246. if (typeof dependencies === 'string') {
  1247. return this.synchronousRequire(dependencies, moduleIdResolver);
  1248. }
  1249. this.defineModule(AMDLoader.Utilities.generateAnonymousModule(), dependencies, callback, errorback, null, moduleIdResolver);
  1250. };
  1251. /**
  1252. * Require synchronously a module by its absolute id. If the module is not loaded, an exception will be thrown.
  1253. * @param id The unique and absolute id of the required module
  1254. * @return The exports of module 'id'
  1255. */
  1256. ModuleManager.prototype.synchronousRequire = function (_strModuleId, moduleIdResolver) {
  1257. if (moduleIdResolver === void 0) { moduleIdResolver = new ModuleIdResolver(_strModuleId); }
  1258. var dependency = this._normalizeDependency(_strModuleId, moduleIdResolver);
  1259. var m = this._modules2[dependency.id];
  1260. if (!m) {
  1261. throw new Error('Check dependency list! Synchronous require cannot resolve module \'' + _strModuleId + '\'. This is the first mention of this module!');
  1262. }
  1263. if (!m.isComplete()) {
  1264. throw new Error('Check dependency list! Synchronous require cannot resolve module \'' + _strModuleId + '\'. This module has not been resolved completely yet.');
  1265. }
  1266. return m.exports;
  1267. };
  1268. ModuleManager.prototype.configure = function (params, shouldOverwrite) {
  1269. var oldShouldRecordStats = this._config.shouldRecordStats();
  1270. if (shouldOverwrite) {
  1271. this._config = new AMDLoader.Configuration(this._env, params);
  1272. }
  1273. else {
  1274. this._config = this._config.cloneAndMerge(params);
  1275. }
  1276. if (this._config.shouldRecordStats() && !oldShouldRecordStats) {
  1277. this._recorder = null;
  1278. }
  1279. };
  1280. ModuleManager.prototype.getConfig = function () {
  1281. return this._config;
  1282. };
  1283. /**
  1284. * Callback from the scriptLoader when a module has been loaded.
  1285. * This means its code is available and has been executed.
  1286. */
  1287. ModuleManager.prototype._onLoad = function (moduleId) {
  1288. if (this._currentAnnonymousDefineCall !== null) {
  1289. var defineCall = this._currentAnnonymousDefineCall;
  1290. this._currentAnnonymousDefineCall = null;
  1291. // Hit an anonymous define call
  1292. this.defineModule(this._moduleIdProvider.getStrModuleId(moduleId), defineCall.dependencies, defineCall.callback, null, defineCall.stack);
  1293. }
  1294. };
  1295. ModuleManager.prototype._createLoadError = function (moduleId, err) {
  1296. var _this = this;
  1297. var strModuleId = this._moduleIdProvider.getStrModuleId(moduleId);
  1298. var neededBy = (this._inverseDependencies2[moduleId] || []).map(function (intModuleId) { return _this._moduleIdProvider.getStrModuleId(intModuleId); });
  1299. return {
  1300. errorCode: 'load',
  1301. moduleId: strModuleId,
  1302. neededBy: neededBy,
  1303. detail: err
  1304. };
  1305. };
  1306. /**
  1307. * Callback from the scriptLoader when a module hasn't been loaded.
  1308. * This means that the script was not found (e.g. 404) or there was an error in the script.
  1309. */
  1310. ModuleManager.prototype._onLoadError = function (moduleId, err) {
  1311. var error = this._createLoadError(moduleId, err);
  1312. // Find any 'local' error handlers, walk the entire chain of inverse dependencies if necessary.
  1313. var seenModuleId = [];
  1314. for (var i = 0, len = this._moduleIdProvider.getMaxModuleId(); i < len; i++) {
  1315. seenModuleId[i] = false;
  1316. }
  1317. var someoneNotified = false;
  1318. var queue = [];
  1319. queue.push(moduleId);
  1320. seenModuleId[moduleId] = true;
  1321. while (queue.length > 0) {
  1322. var queueElement = queue.shift();
  1323. var m = this._modules2[queueElement];
  1324. if (m) {
  1325. someoneNotified = m.onDependencyError(error) || someoneNotified;
  1326. }
  1327. var inverseDeps = this._inverseDependencies2[queueElement];
  1328. if (inverseDeps) {
  1329. for (var i = 0, len = inverseDeps.length; i < len; i++) {
  1330. var inverseDep = inverseDeps[i];
  1331. if (!seenModuleId[inverseDep]) {
  1332. queue.push(inverseDep);
  1333. seenModuleId[inverseDep] = true;
  1334. }
  1335. }
  1336. }
  1337. }
  1338. if (!someoneNotified) {
  1339. this._config.onError(error);
  1340. }
  1341. };
  1342. /**
  1343. * Walks (recursively) the dependencies of 'from' in search of 'to'.
  1344. * Returns true if there is such a path or false otherwise.
  1345. * @param from Module id to start at
  1346. * @param to Module id to look for
  1347. */
  1348. ModuleManager.prototype._hasDependencyPath = function (fromId, toId) {
  1349. var from = this._modules2[fromId];
  1350. if (!from) {
  1351. return false;
  1352. }
  1353. var inQueue = [];
  1354. for (var i = 0, len = this._moduleIdProvider.getMaxModuleId(); i < len; i++) {
  1355. inQueue[i] = false;
  1356. }
  1357. var queue = [];
  1358. // Insert 'from' in queue
  1359. queue.push(from);
  1360. inQueue[fromId] = true;
  1361. while (queue.length > 0) {
  1362. // Pop first inserted element of queue
  1363. var element = queue.shift();
  1364. var dependencies = element.dependencies;
  1365. if (dependencies) {
  1366. // Walk the element's dependencies
  1367. for (var i = 0, len = dependencies.length; i < len; i++) {
  1368. var dependency = dependencies[i];
  1369. if (dependency.id === toId) {
  1370. // There is a path to 'to'
  1371. return true;
  1372. }
  1373. var dependencyModule = this._modules2[dependency.id];
  1374. if (dependencyModule && !inQueue[dependency.id]) {
  1375. // Insert 'dependency' in queue
  1376. inQueue[dependency.id] = true;
  1377. queue.push(dependencyModule);
  1378. }
  1379. }
  1380. }
  1381. }
  1382. // There is no path to 'to'
  1383. return false;
  1384. };
  1385. /**
  1386. * Walks (recursively) the dependencies of 'from' in search of 'to'.
  1387. * Returns cycle as array.
  1388. * @param from Module id to start at
  1389. * @param to Module id to look for
  1390. */
  1391. ModuleManager.prototype._findCyclePath = function (fromId, toId, depth) {
  1392. if (fromId === toId || depth === 50) {
  1393. return [fromId];
  1394. }
  1395. var from = this._modules2[fromId];
  1396. if (!from) {
  1397. return null;
  1398. }
  1399. // Walk the element's dependencies
  1400. var dependencies = from.dependencies;
  1401. for (var i = 0, len = dependencies.length; i < len; i++) {
  1402. var path = this._findCyclePath(dependencies[i].id, toId, depth + 1);
  1403. if (path !== null) {
  1404. path.push(fromId);
  1405. return path;
  1406. }
  1407. }
  1408. return null;
  1409. };
  1410. /**
  1411. * Create the local 'require' that is passed into modules
  1412. */
  1413. ModuleManager.prototype._createRequire = function (moduleIdResolver) {
  1414. var _this = this;
  1415. var result = (function (dependencies, callback, errorback) {
  1416. return _this._relativeRequire(moduleIdResolver, dependencies, callback, errorback);
  1417. });
  1418. result.toUrl = function (id) {
  1419. return _this._config.requireToUrl(moduleIdResolver.resolveModule(id));
  1420. };
  1421. result.getStats = function () {
  1422. return _this.getLoaderEvents();
  1423. };
  1424. result.__$__nodeRequire = AMDLoader.global.nodeRequire;
  1425. return result;
  1426. };
  1427. ModuleManager.prototype._loadModule = function (moduleId) {
  1428. var _this = this;
  1429. if (this._modules2[moduleId] || this._knownModules2[moduleId]) {
  1430. // known module
  1431. return;
  1432. }
  1433. this._knownModules2[moduleId] = true;
  1434. var strModuleId = this._moduleIdProvider.getStrModuleId(moduleId);
  1435. var paths = this._config.moduleIdToPaths(strModuleId);
  1436. var scopedPackageRegex = /^@[^\/]+\/[^\/]+$/; // matches @scope/package-name
  1437. if (this._env.isNode && (strModuleId.indexOf('/') === -1 || scopedPackageRegex.test(strModuleId))) {
  1438. paths.push('node|' + strModuleId);
  1439. }
  1440. var lastPathIndex = -1;
  1441. var loadNextPath = function (err) {
  1442. lastPathIndex++;
  1443. if (lastPathIndex >= paths.length) {
  1444. // No more paths to try
  1445. _this._onLoadError(moduleId, err);
  1446. }
  1447. else {
  1448. var currentPath_1 = paths[lastPathIndex];
  1449. var recorder_1 = _this.getRecorder();
  1450. if (_this._config.isBuild() && currentPath_1 === 'empty:') {
  1451. _this._buildInfoPath[moduleId] = currentPath_1;
  1452. _this.defineModule(_this._moduleIdProvider.getStrModuleId(moduleId), [], null, null, null);
  1453. _this._onLoad(moduleId);
  1454. return;
  1455. }
  1456. recorder_1.record(10 /* BeginLoadingScript */, currentPath_1);
  1457. _this._scriptLoader.load(_this, currentPath_1, function () {
  1458. if (_this._config.isBuild()) {
  1459. _this._buildInfoPath[moduleId] = currentPath_1;
  1460. }
  1461. recorder_1.record(11 /* EndLoadingScriptOK */, currentPath_1);
  1462. _this._onLoad(moduleId);
  1463. }, function (err) {
  1464. recorder_1.record(12 /* EndLoadingScriptError */, currentPath_1);
  1465. loadNextPath(err);
  1466. });
  1467. }
  1468. };
  1469. loadNextPath(null);
  1470. };
  1471. /**
  1472. * Resolve a plugin dependency with the plugin loaded & complete
  1473. * @param module The module that has this dependency
  1474. * @param pluginDependency The semi-normalized dependency that appears in the module. e.g. 'vs/css!./mycssfile'. Only the plugin part (before !) is normalized
  1475. * @param plugin The plugin (what the plugin exports)
  1476. */
  1477. ModuleManager.prototype._loadPluginDependency = function (plugin, pluginDependency) {
  1478. var _this = this;
  1479. if (this._modules2[pluginDependency.id] || this._knownModules2[pluginDependency.id]) {
  1480. // known module
  1481. return;
  1482. }
  1483. this._knownModules2[pluginDependency.id] = true;
  1484. // Delegate the loading of the resource to the plugin
  1485. var load = (function (value) {
  1486. _this.defineModule(_this._moduleIdProvider.getStrModuleId(pluginDependency.id), [], value, null, null);
  1487. });
  1488. load.error = function (err) {
  1489. _this._config.onError(_this._createLoadError(pluginDependency.id, err));
  1490. };
  1491. plugin.load(pluginDependency.pluginParam, this._createRequire(ModuleIdResolver.ROOT), load, this._config.getOptionsLiteral());
  1492. };
  1493. /**
  1494. * Examine the dependencies of module 'module' and resolve them as needed.
  1495. */
  1496. ModuleManager.prototype._resolve = function (module) {
  1497. var _this = this;
  1498. var dependencies = module.dependencies;
  1499. for (var i = 0, len = dependencies.length; i < len; i++) {
  1500. var dependency = dependencies[i];
  1501. if (dependency === RegularDependency.EXPORTS) {
  1502. module.exportsPassedIn = true;
  1503. module.unresolvedDependenciesCount--;
  1504. continue;
  1505. }
  1506. if (dependency === RegularDependency.MODULE) {
  1507. module.unresolvedDependenciesCount--;
  1508. continue;
  1509. }
  1510. if (dependency === RegularDependency.REQUIRE) {
  1511. module.unresolvedDependenciesCount--;
  1512. continue;
  1513. }
  1514. var dependencyModule = this._modules2[dependency.id];
  1515. if (dependencyModule && dependencyModule.isComplete()) {
  1516. module.unresolvedDependenciesCount--;
  1517. continue;
  1518. }
  1519. if (this._hasDependencyPath(dependency.id, module.id)) {
  1520. console.warn('There is a dependency cycle between \'' + this._moduleIdProvider.getStrModuleId(dependency.id) + '\' and \'' + this._moduleIdProvider.getStrModuleId(module.id) + '\'. The cyclic path follows:');
  1521. var cyclePath = this._findCyclePath(dependency.id, module.id, 0);
  1522. cyclePath.reverse();
  1523. cyclePath.push(dependency.id);
  1524. console.warn(cyclePath.map(function (id) { return _this._moduleIdProvider.getStrModuleId(id); }).join(' => \n'));
  1525. // Break the cycle
  1526. module.unresolvedDependenciesCount--;
  1527. continue;
  1528. }
  1529. // record inverse dependency
  1530. this._inverseDependencies2[dependency.id] = this._inverseDependencies2[dependency.id] || [];
  1531. this._inverseDependencies2[dependency.id].push(module.id);
  1532. if (dependency instanceof PluginDependency) {
  1533. var plugin = this._modules2[dependency.pluginId];
  1534. if (plugin && plugin.isComplete()) {
  1535. this._loadPluginDependency(plugin.exports, dependency);
  1536. continue;
  1537. }
  1538. // Record dependency for when the plugin gets loaded
  1539. var inversePluginDeps = this._inversePluginDependencies2.get(dependency.pluginId);
  1540. if (!inversePluginDeps) {
  1541. inversePluginDeps = [];
  1542. this._inversePluginDependencies2.set(dependency.pluginId, inversePluginDeps);
  1543. }
  1544. inversePluginDeps.push(dependency);
  1545. this._loadModule(dependency.pluginId);
  1546. continue;
  1547. }
  1548. this._loadModule(dependency.id);
  1549. }
  1550. if (module.unresolvedDependenciesCount === 0) {
  1551. this._onModuleComplete(module);
  1552. }
  1553. };
  1554. ModuleManager.prototype._onModuleComplete = function (module) {
  1555. var _this = this;
  1556. var recorder = this.getRecorder();
  1557. if (module.isComplete()) {
  1558. // already done
  1559. return;
  1560. }
  1561. var dependencies = module.dependencies;
  1562. var dependenciesValues = [];
  1563. for (var i = 0, len = dependencies.length; i < len; i++) {
  1564. var dependency = dependencies[i];
  1565. if (dependency === RegularDependency.EXPORTS) {
  1566. dependenciesValues[i] = module.exports;
  1567. continue;
  1568. }
  1569. if (dependency === RegularDependency.MODULE) {
  1570. dependenciesValues[i] = {
  1571. id: module.strId,
  1572. config: function () {
  1573. return _this._config.getConfigForModule(module.strId);
  1574. }
  1575. };
  1576. continue;
  1577. }
  1578. if (dependency === RegularDependency.REQUIRE) {
  1579. dependenciesValues[i] = this._createRequire(module.moduleIdResolver);
  1580. continue;
  1581. }
  1582. var dependencyModule = this._modules2[dependency.id];
  1583. if (dependencyModule) {
  1584. dependenciesValues[i] = dependencyModule.exports;
  1585. continue;
  1586. }
  1587. dependenciesValues[i] = null;
  1588. }
  1589. module.complete(recorder, this._config, dependenciesValues);
  1590. // Fetch and clear inverse dependencies
  1591. var inverseDeps = this._inverseDependencies2[module.id];
  1592. this._inverseDependencies2[module.id] = null;
  1593. if (inverseDeps) {
  1594. // Resolve one inverse dependency at a time, always
  1595. // on the lookout for a completed module.
  1596. for (var i = 0, len = inverseDeps.length; i < len; i++) {
  1597. var inverseDependencyId = inverseDeps[i];
  1598. var inverseDependency = this._modules2[inverseDependencyId];
  1599. inverseDependency.unresolvedDependenciesCount--;
  1600. if (inverseDependency.unresolvedDependenciesCount === 0) {
  1601. this._onModuleComplete(inverseDependency);
  1602. }
  1603. }
  1604. }
  1605. var inversePluginDeps = this._inversePluginDependencies2.get(module.id);
  1606. if (inversePluginDeps) {
  1607. // This module is used as a plugin at least once
  1608. // Fetch and clear these inverse plugin dependencies
  1609. this._inversePluginDependencies2.delete(module.id);
  1610. // Resolve plugin dependencies one at a time
  1611. for (var i = 0, len = inversePluginDeps.length; i < len; i++) {
  1612. this._loadPluginDependency(module.exports, inversePluginDeps[i]);
  1613. }
  1614. }
  1615. };
  1616. return ModuleManager;
  1617. }());
  1618. AMDLoader.ModuleManager = ModuleManager;
  1619. })(AMDLoader || (AMDLoader = {}));
  1620. var define;
  1621. var AMDLoader;
  1622. (function (AMDLoader) {
  1623. var env = new AMDLoader.Environment();
  1624. var moduleManager = null;
  1625. var DefineFunc = function (id, dependencies, callback) {
  1626. if (typeof id !== 'string') {
  1627. callback = dependencies;
  1628. dependencies = id;
  1629. id = null;
  1630. }
  1631. if (typeof dependencies !== 'object' || !Array.isArray(dependencies)) {
  1632. callback = dependencies;
  1633. dependencies = null;
  1634. }
  1635. if (!dependencies) {
  1636. dependencies = ['require', 'exports', 'module'];
  1637. }
  1638. if (id) {
  1639. moduleManager.defineModule(id, dependencies, callback, null, null);
  1640. }
  1641. else {
  1642. moduleManager.enqueueDefineAnonymousModule(dependencies, callback);
  1643. }
  1644. };
  1645. DefineFunc.amd = {
  1646. jQuery: true
  1647. };
  1648. var _requireFunc_config = function (params, shouldOverwrite) {
  1649. if (shouldOverwrite === void 0) { shouldOverwrite = false; }
  1650. moduleManager.configure(params, shouldOverwrite);
  1651. };
  1652. var RequireFunc = function () {
  1653. if (arguments.length === 1) {
  1654. if ((arguments[0] instanceof Object) && !Array.isArray(arguments[0])) {
  1655. _requireFunc_config(arguments[0]);
  1656. return;
  1657. }
  1658. if (typeof arguments[0] === 'string') {
  1659. return moduleManager.synchronousRequire(arguments[0]);
  1660. }
  1661. }
  1662. if (arguments.length === 2 || arguments.length === 3) {
  1663. if (Array.isArray(arguments[0])) {
  1664. moduleManager.defineModule(AMDLoader.Utilities.generateAnonymousModule(), arguments[0], arguments[1], arguments[2], null);
  1665. return;
  1666. }
  1667. }
  1668. throw new Error('Unrecognized require call');
  1669. };
  1670. RequireFunc.config = _requireFunc_config;
  1671. RequireFunc.getConfig = function () {
  1672. return moduleManager.getConfig().getOptionsLiteral();
  1673. };
  1674. RequireFunc.reset = function () {
  1675. moduleManager = moduleManager.reset();
  1676. };
  1677. RequireFunc.getBuildInfo = function () {
  1678. return moduleManager.getBuildInfo();
  1679. };
  1680. RequireFunc.getStats = function () {
  1681. return moduleManager.getLoaderEvents();
  1682. };
  1683. RequireFunc.define = function () {
  1684. return DefineFunc.apply(null, arguments);
  1685. };
  1686. function init() {
  1687. if (typeof AMDLoader.global.require !== 'undefined' || typeof require !== 'undefined') {
  1688. var _nodeRequire_1 = (AMDLoader.global.require || require);
  1689. if (typeof _nodeRequire_1 === 'function' && typeof _nodeRequire_1.resolve === 'function') {
  1690. // re-expose node's require function
  1691. var nodeRequire = function (what) {
  1692. moduleManager.getRecorder().record(33 /* NodeBeginNativeRequire */, what);
  1693. try {
  1694. return _nodeRequire_1(what);
  1695. }
  1696. finally {
  1697. moduleManager.getRecorder().record(34 /* NodeEndNativeRequire */, what);
  1698. }
  1699. };
  1700. AMDLoader.global.nodeRequire = nodeRequire;
  1701. RequireFunc.nodeRequire = nodeRequire;
  1702. RequireFunc.__$__nodeRequire = nodeRequire;
  1703. }
  1704. }
  1705. if (env.isNode && !env.isElectronRenderer) {
  1706. module.exports = RequireFunc;
  1707. require = RequireFunc;
  1708. }
  1709. else {
  1710. if (!env.isElectronRenderer) {
  1711. AMDLoader.global.define = DefineFunc;
  1712. }
  1713. AMDLoader.global.require = RequireFunc;
  1714. }
  1715. }
  1716. AMDLoader.init = init;
  1717. if (typeof AMDLoader.global.define !== 'function' || !AMDLoader.global.define.amd) {
  1718. moduleManager = new AMDLoader.ModuleManager(env, AMDLoader.createScriptLoader(env), DefineFunc, RequireFunc, AMDLoader.Utilities.getHighPerformanceTimestamp());
  1719. // The global variable require can configure the loader
  1720. if (typeof AMDLoader.global.require !== 'undefined' && typeof AMDLoader.global.require !== 'function') {
  1721. RequireFunc.config(AMDLoader.global.require);
  1722. }
  1723. // This define is for the local closure defined in node in the case that the loader is concatenated
  1724. define = function () {
  1725. return DefineFunc.apply(null, arguments);
  1726. };
  1727. define.amd = DefineFunc.amd;
  1728. if (typeof doNotInitLoader === 'undefined') {
  1729. init();
  1730. }
  1731. }
  1732. })(AMDLoader || (AMDLoader = {}));
  1733. //# sourceMappingURL=loader.js.map