loader.js 91 KB

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