1/* 2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { throwError } from "../../utils" 17import { KNativePointer } from "@koalaui/interop" 18import { initEs2panda, Es2pandaNativeModule, initGeneratedEs2panda } from "../../Es2pandaNativeModule" 19import { Es2pandaNativeModule as GeneratedEs2pandaNativeModule } from "../../generated/Es2pandaNativeModule" 20import { initInterop, InteropNativeModule } from "../../InteropNativeModule" 21import type { Context } from "../peers/Context" 22 23export class global { 24 public static filePath: string = "./plugins/input/main.sts" 25 26 private static _config?: KNativePointer 27 public static set config(config: KNativePointer) { 28 if (global._config !== undefined) { 29 throwError('Global.config already initialized') 30 } 31 global._config = config 32 } 33 public static get config(): KNativePointer { 34 return global._config ?? throwError('Global.config not initialized') 35 } 36 public static configIsInitialized(): boolean { 37 return global._config !== undefined 38 } 39 40 // TODO: rename to contextPeer 41 public static get context(): KNativePointer { 42 return global.compilerContext?.peer ?? throwError('Global.context not initialized') 43 } 44 45 // unsafe - could be undefined 46 public static compilerContext: Context | undefined 47 48 public static clearContext(): void { 49 this.compilerContext = undefined; 50 } 51 52 private static _es2panda: Es2pandaNativeModule | undefined = undefined 53 public static get es2panda(): Es2pandaNativeModule { 54 if (this._es2panda === undefined) { 55 this._es2panda = initEs2panda() 56 } 57 return this._es2panda 58 } 59 60 private static _generatedEs2panda: GeneratedEs2pandaNativeModule | undefined = undefined 61 public static get generatedEs2panda(): GeneratedEs2pandaNativeModule { 62 if (this._generatedEs2panda === undefined) { 63 this._generatedEs2panda = initGeneratedEs2panda() 64 } 65 return this._generatedEs2panda 66 } 67 68 private static _interop: InteropNativeModule | undefined = undefined 69 public static get interop(): InteropNativeModule { 70 if (this._interop === undefined) this._interop = initInterop() 71 return this._interop 72 } 73 74 public static resetConfig() { 75 global._config = undefined; 76 } 77} 78