bootstrap.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // This file is auto-generated from the corresponding file in /dev_mode
  2. /*
  3. * Copyright (c) Jupyter Development Team.
  4. * Distributed under the terms of the Modified BSD License.
  5. */
  6. // We copy some of the pageconfig parsing logic in @jupyterlab/coreutils
  7. // below, since this must run before any other files are loaded (including
  8. // @jupyterlab/coreutils).
  9. /**
  10. * Get global configuration data for the Jupyter application.
  11. *
  12. * @param name - The name of the configuration option.
  13. *
  14. * @returns The config value or an empty string if not found.
  15. *
  16. * #### Notes
  17. * All values are treated as strings. For browser based applications, it is
  18. * assumed that the page HTML includes a script tag with the id
  19. * `jupyter-config-data` containing the configuration as valid JSON.
  20. */
  21. let _CONFIG_DATA = null;
  22. function getOption(name) {
  23. if (_CONFIG_DATA === null) {
  24. let configData = {};
  25. // Use script tag if available.
  26. if (typeof document !== 'undefined' && document) {
  27. const el = document.getElementById('jupyter-config-data');
  28. if (el) {
  29. configData = JSON.parse(el.textContent || '{}');
  30. }
  31. }
  32. _CONFIG_DATA = configData;
  33. }
  34. return _CONFIG_DATA[name] || '';
  35. }
  36. // eslint-disable-next-line no-undef
  37. __webpack_public_path__ = getOption('fullStaticUrl') + '/';
  38. function loadScript(url) {
  39. return new Promise((resolve, reject) => {
  40. const newScript = document.createElement('script');
  41. newScript.onerror = reject;
  42. newScript.onload = resolve;
  43. newScript.async = true;
  44. document.head.appendChild(newScript);
  45. newScript.src = url;
  46. });
  47. }
  48. async function loadComponent(url, scope) {
  49. await loadScript(url);
  50. // From https://webpack.js.org/concepts/module-federation/#dynamic-remote-containers
  51. // eslint-disable-next-line no-undef
  52. await __webpack_init_sharing__('default');
  53. const container = window._JUPYTERLAB[scope];
  54. // Initialize the container, it may provide shared modules and may need ours
  55. // eslint-disable-next-line no-undef
  56. await container.init(__webpack_share_scopes__.default);
  57. }
  58. void (async function bootstrap() {
  59. // This is all the data needed to load and activate plugins. This should be
  60. // gathered by the server and put onto the initial page template.
  61. const extension_data = getOption('federated_extensions');
  62. // We first load all federated components so that the shared module
  63. // deduplication can run and figure out which shared modules from all
  64. // components should be actually used. We have to do this before importing
  65. // and using the module that actually uses these components so that all
  66. // dependencies are initialized.
  67. let labExtensionUrl = getOption('fullLabextensionsUrl');
  68. const extensions = await Promise.allSettled(
  69. extension_data.map(async data => {
  70. await loadComponent(
  71. `${labExtensionUrl}/${data.name}/${data.load}`,
  72. data.name
  73. );
  74. })
  75. );
  76. extensions.forEach(p => {
  77. if (p.status === 'rejected') {
  78. // There was an error loading the component
  79. console.error(p.reason);
  80. }
  81. });
  82. // Now that all federated containers are initialized with the main
  83. // container, we can import the main function.
  84. let main = (await import('./index.out.js')).main;
  85. window.addEventListener('load', main);
  86. })();