loader.js 83 KB

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