loader.js 88 KB

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