bootstrap-amd.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. //@ts-check
  6. 'use strict';
  7. // Store the node.js require function in a variable
  8. // before loading our AMD loader to avoid issues
  9. // when this file is bundled with other files.
  10. const nodeRequire = require;
  11. // VSCODE_GLOBALS: node_modules
  12. globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => nodeRequire(String(mod)) });
  13. // VSCODE_GLOBALS: package/product.json
  14. /** @type Record<string, any> */
  15. globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
  16. if (process.env['VSCODE_DEV']) {
  17. // Patch product overrides when running out of sources
  18. try {
  19. // @ts-ignore
  20. const overrides = require('../product.overrides.json');
  21. globalThis._VSCODE_PRODUCT_JSON = Object.assign(globalThis._VSCODE_PRODUCT_JSON, overrides);
  22. } catch (error) { /* ignore */ }
  23. }
  24. globalThis._VSCODE_PACKAGE_JSON = require('../package.json');
  25. // @ts-ignore
  26. const loader = require('./vs/loader');
  27. const bootstrap = require('./bootstrap');
  28. const performance = require('./vs/base/common/performance');
  29. // Bootstrap: NLS
  30. const nlsConfig = bootstrap.setupNLS();
  31. // Bootstrap: Loader
  32. loader.config({
  33. baseUrl: bootstrap.fileUriFromPath(__dirname, { isWindows: process.platform === 'win32' }),
  34. catchError: true,
  35. nodeRequire,
  36. 'vs/nls': nlsConfig,
  37. amdModulesPattern: /^vs\//,
  38. recordStats: true
  39. });
  40. // Running in Electron
  41. if (process.env['ELECTRON_RUN_AS_NODE'] || process.versions['electron']) {
  42. loader.define('fs', ['original-fs'], function (/** @type {import('fs')} */originalFS) {
  43. return originalFS; // replace the patched electron fs with the original node fs for all AMD code
  44. });
  45. }
  46. // Pseudo NLS support
  47. if (nlsConfig && nlsConfig.pseudo) {
  48. loader(['vs/nls'], function (/** @type {import('vs/nls')} */nlsPlugin) {
  49. nlsPlugin.setPseudoTranslation(!!nlsConfig.pseudo);
  50. });
  51. }
  52. /**
  53. * @param {string=} entrypoint
  54. * @param {(value: any) => void=} onLoad
  55. * @param {(err: Error) => void=} onError
  56. */
  57. exports.load = function (entrypoint, onLoad, onError) {
  58. if (!entrypoint) {
  59. return;
  60. }
  61. // code cache config
  62. if (process.env['VSCODE_CODE_CACHE_PATH']) {
  63. loader.config({
  64. nodeCachedData: {
  65. path: process.env['VSCODE_CODE_CACHE_PATH'],
  66. seed: entrypoint
  67. }
  68. });
  69. }
  70. onLoad = onLoad || function () { };
  71. onError = onError || function (err) { console.error(err); };
  72. performance.mark('code/fork/willLoadCode');
  73. loader([entrypoint], onLoad, onError);
  74. };