env.mjs 643 B

123456789101112131415161718192021222324
  1. const context = (() => {
  2. if (typeof globalThis !== "undefined") {
  3. return globalThis;
  4. } else if (typeof self !== "undefined") {
  5. return self;
  6. } else if (typeof window !== "undefined") {
  7. return window;
  8. } else {
  9. return Function("return this")();
  10. }
  11. })();
  12. const defines = __DEFINES__;
  13. Object.keys(defines).forEach((key) => {
  14. const segments = key.split(".");
  15. let target = context;
  16. for (let i = 0; i < segments.length; i++) {
  17. const segment = segments[i];
  18. if (i === segments.length - 1) {
  19. target[segment] = defines[key];
  20. } else {
  21. target = target[segment] || (target[segment] = {});
  22. }
  23. }
  24. });