loader.js 83 KB

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