loader.js 78 KB

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