@corsa-bind/napi 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ApiClientOptions, ApiMode, CapabilitiesResponse, ConfigResponse, DiagnosticsCapabilities, DocumentIdentifier, EditorCapabilities, FileChangeSummary, FileChanges, FileDiagnosticsResponse, InitializeResponse, NativeLintDiagnostic, NativeLintFix, NativeLintNode, NativeLintRange, NativeLintRuleMeta, NativeLintSuggestion, OverlayCapabilities, OverlayChanges, OverlayUpdate, ProjectDiagnosticsResponse, ProjectResponse, RuntimeCapabilities, SnapshotDiagnosticsResponse, SymbolResponse, TypeResponse, TypeTextKind, UnsafeTypeFlowInput, UpdateSnapshotParams, UpdateSnapshotResponse, VirtualChange, VirtualDocumentState } from "./types.mjs";
2
- import * as ___index_js0 from "../index.js";
2
+ import * as _$___index_js0 from "../index.js";
3
3
 
4
4
  //#region index.d.ts
5
- declare const binding: typeof ___index_js0;
5
+ declare const binding: typeof _$___index_js0;
6
6
  declare function isUnsafeAssignment(input: UnsafeTypeFlowInput): boolean;
7
7
  declare function isUnsafeReturn(input: UnsafeTypeFlowInput): boolean;
8
8
  declare function runNativeLintRule(ruleName: string, node: NativeLintNode): NativeLintDiagnostic[];
@@ -79,7 +79,7 @@ declare class CorsaDistributedOrchestrator {
79
79
  closeVirtualDocument(uri: string): void;
80
80
  private requireLeader;
81
81
  }
82
- declare const version: typeof ___index_js0.version;
82
+ declare const version: typeof _$___index_js0.version;
83
83
  //#endregion
84
84
  export { ApiClientOptions, ApiMode, CapabilitiesResponse, ConfigResponse, CorsaApiClient, CorsaApiClient as TsgoApiClient, CorsaDistributedOrchestrator, CorsaDistributedOrchestrator as TsgoDistributedOrchestrator, CorsaVirtualDocument, CorsaVirtualDocument as TsgoVirtualDocument, DiagnosticsCapabilities, DocumentIdentifier, EditorCapabilities, FileChangeSummary, FileChanges, FileDiagnosticsResponse, InitializeResponse, NativeLintDiagnostic, NativeLintFix, NativeLintNode, NativeLintRange, NativeLintRuleMeta, NativeLintSuggestion, OverlayCapabilities, OverlayChanges, OverlayUpdate, ProjectDiagnosticsResponse, ProjectResponse, RuntimeCapabilities, SnapshotDiagnosticsResponse, SymbolResponse, TypeResponse, TypeTextKind, UnsafeTypeFlowInput, UpdateSnapshotParams, UpdateSnapshotResponse, Utils, VirtualChange, VirtualDocumentState, classifyTypeText, binding as default, isAnyLikeTypeTexts, isArrayLikeTypeTexts, isBigIntLikeTypeTexts, isErrorLikeTypeTexts, isNumberLikeTypeTexts, isPromiseLikeTypeTexts, isStringArrayLikeTypeTexts, isStringLikeTypeTexts, isUnknownLikeTypeTexts, isUnsafeAssignment, isUnsafeReturn, nativeLintRuleMetas, runNativeLintRule, splitTopLevelTypeText, splitTypeText, version };
85
85
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["#inner"],"sources":["../ts/index.ts"],"sourcesContent":["import * as nativeModule from \"../index.js\";\n\nimport type {\n ApiClientOptions,\n ConfigResponse,\n InitializeResponse,\n NativeLintDiagnostic,\n NativeLintNode,\n NativeLintRuleMeta,\n SymbolResponse,\n TypeTextKind,\n TypeResponse,\n UnsafeTypeFlowInput,\n UpdateSnapshotParams,\n UpdateSnapshotResponse,\n VirtualChange,\n VirtualDocumentState,\n} from \"./types\";\n\nconst binding = (\n \"default\" in nativeModule ? nativeModule.default : nativeModule\n) as typeof import(\"../index.js\");\n\ntype NativeApiClient = InstanceType<typeof binding.TsgoApiClient>;\ntype NativeDistributedOrchestrator = InstanceType<typeof binding.TsgoDistributedOrchestrator>;\ntype NativeVirtualDocument = InstanceType<typeof binding.TsgoVirtualDocument>;\n\nfunction fromJson<T>(value: string): T {\n return JSON.parse(value) as T;\n}\n\nfunction toJson(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n\nexport function isUnsafeAssignment(input: UnsafeTypeFlowInput): boolean {\n return binding.isUnsafeAssignment(toJson(input));\n}\n\nexport function isUnsafeReturn(input: UnsafeTypeFlowInput): boolean {\n return binding.isUnsafeReturn(toJson(input));\n}\n\nexport function runNativeLintRule(ruleName: string, node: NativeLintNode): NativeLintDiagnostic[] {\n return fromJson(binding.runNativeLintRule(ruleName, toJson(node)));\n}\n\nexport function nativeLintRuleMetas(): NativeLintRuleMeta[] {\n return fromJson(binding.nativeLintRuleMetasJson());\n}\n\nexport function classifyTypeText(text?: string): TypeTextKind {\n return binding.classifyTypeText(text) as TypeTextKind;\n}\n\nexport function splitTopLevelTypeText(text: string, delimiter: string): string[] {\n return binding.splitTopLevelTypeText(text, delimiter);\n}\n\nexport function splitTypeText(text: string): string[] {\n return binding.splitTypeText(text);\n}\n\nexport function isStringLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isStringLikeTypeTexts([...typeTexts]);\n}\n\nexport function isNumberLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isNumberLikeTypeTexts([...typeTexts]);\n}\n\nexport function isBigIntLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isBigIntLikeTypeTexts([...typeTexts]);\n}\n\nexport function isAnyLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isAnyLikeTypeTexts([...typeTexts]);\n}\n\nexport function isUnknownLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isUnknownLikeTypeTexts([...typeTexts]);\n}\n\nexport function isArrayLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isArrayLikeTypeTexts([...typeTexts]);\n}\n\nexport function isStringArrayLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isStringArrayLikeTypeTexts([...typeTexts]);\n}\n\nexport function isPromiseLikeTypeTexts(\n typeTexts: readonly string[],\n propertyNames: readonly string[] = [],\n): boolean {\n return binding.isPromiseLikeTypeTexts([...typeTexts], [...propertyNames]);\n}\n\nexport function isErrorLikeTypeTexts(\n typeTexts: readonly string[],\n propertyNames: readonly string[] = [],\n): boolean {\n return binding.isErrorLikeTypeTexts([...typeTexts], [...propertyNames]);\n}\n\nexport const Utils = Object.freeze({\n classifyTypeText,\n splitTopLevelTypeText,\n splitTypeText,\n isStringLikeTypeTexts,\n isNumberLikeTypeTexts,\n isBigIntLikeTypeTexts,\n isAnyLikeTypeTexts,\n isUnknownLikeTypeTexts,\n isArrayLikeTypeTexts,\n isStringArrayLikeTypeTexts,\n isPromiseLikeTypeTexts,\n isErrorLikeTypeTexts,\n});\n\nexport class CorsaApiClient {\n readonly #inner: NativeApiClient;\n\n private constructor(inner: NativeApiClient) {\n this.#inner = inner;\n }\n\n static spawn(options: ApiClientOptions): CorsaApiClient {\n return new CorsaApiClient(binding.TsgoApiClient.spawn(toJson(options)));\n }\n\n initialize(): InitializeResponse {\n return fromJson(this.#inner.initializeJson());\n }\n\n parseConfigFile(file: string): ConfigResponse {\n return fromJson(this.#inner.parseConfigFileJson(file));\n }\n\n updateSnapshot(params?: UpdateSnapshotParams): UpdateSnapshotResponse {\n return fromJson(this.#inner.updateSnapshotJson(params ? toJson(params) : undefined));\n }\n\n getSourceFile(snapshot: string, project: string, file: string): Uint8Array | null {\n return this.#inner.getSourceFile(snapshot, project, file) ?? null;\n }\n\n getStringType(snapshot: string, project: string): TypeResponse {\n return fromJson(this.#inner.getStringTypeJson(snapshot, project));\n }\n\n getTypeAtPosition(\n snapshot: string,\n project: string,\n file: string,\n position: number,\n ): TypeResponse | undefined {\n return (\n fromJson<TypeResponse | null>(\n this.#inner.getTypeAtPositionJson(snapshot, project, file, position),\n ) ?? undefined\n );\n }\n\n getSymbolAtPosition(\n snapshot: string,\n project: string,\n file: string,\n position: number,\n ): SymbolResponse | undefined {\n return (\n fromJson<SymbolResponse | null>(\n this.#inner.getSymbolAtPositionJson(snapshot, project, file, position),\n ) ?? undefined\n );\n }\n\n getTypeArguments(\n snapshot: string,\n project: string,\n typeHandle: string,\n objectFlags?: number,\n ): TypeResponse[] {\n return fromJson(this.#inner.getTypeArgumentsJson(snapshot, project, typeHandle, objectFlags));\n }\n\n getTypeOfSymbol(snapshot: string, project: string, symbol: string): TypeResponse | undefined {\n return (\n fromJson<TypeResponse | null>(this.#inner.getTypeOfSymbolJson(snapshot, project, symbol)) ??\n undefined\n );\n }\n\n getDeclaredTypeOfSymbol(\n snapshot: string,\n project: string,\n symbol: string,\n ): TypeResponse | undefined {\n return (\n fromJson<TypeResponse | null>(\n this.#inner.getDeclaredTypeOfSymbolJson(snapshot, project, symbol),\n ) ?? undefined\n );\n }\n\n typeToString(\n snapshot: string,\n project: string,\n typeHandle: string,\n location?: string,\n flags?: number,\n ): string {\n return this.#inner.typeToString(snapshot, project, typeHandle, location, flags);\n }\n\n callJson<T>(method: string, params?: unknown): T {\n return fromJson(this.#inner.callJson(method, params ? toJson(params) : undefined));\n }\n\n callBinary(method: string, params?: unknown): Uint8Array | null {\n return this.#inner.callBinary(method, params ? toJson(params) : undefined) ?? null;\n }\n\n releaseHandle(handle: string): void {\n this.#inner.releaseHandle(handle);\n }\n\n close(): void {\n this.#inner.close();\n }\n}\n\nexport class CorsaVirtualDocument {\n readonly #inner: NativeVirtualDocument;\n\n private constructor(inner: NativeVirtualDocument) {\n this.#inner = inner;\n }\n\n static untitled(path: string, languageId: string, text: string): CorsaVirtualDocument {\n return new CorsaVirtualDocument(binding.TsgoVirtualDocument.untitled(path, languageId, text));\n }\n\n static inMemory(\n authority: string,\n path: string,\n languageId: string,\n text: string,\n ): CorsaVirtualDocument {\n return new CorsaVirtualDocument(\n binding.TsgoVirtualDocument.inMemory(authority, path, languageId, text),\n );\n }\n\n get uri(): string {\n return this.#inner.uri;\n }\n\n get languageId(): string {\n return this.#inner.languageId;\n }\n\n get version(): number {\n return this.#inner.version;\n }\n\n get text(): string {\n return this.#inner.text;\n }\n\n state(): VirtualDocumentState {\n return fromJson(this.#inner.stateJson());\n }\n\n replace(text: string): void {\n this.#inner.replace(text);\n }\n\n applyChanges(changes: VirtualChange[]): unknown[] {\n return fromJson(this.#inner.applyChangesJson(toJson(changes)));\n }\n}\n\nexport class CorsaDistributedOrchestrator {\n readonly #inner: NativeDistributedOrchestrator;\n\n constructor(nodeIds: string[]) {\n this.#inner = new binding.TsgoDistributedOrchestrator(nodeIds);\n }\n\n campaign(nodeId: string): number {\n return this.#inner.campaign(nodeId);\n }\n\n leaderId(): string | undefined {\n return this.#inner.leaderId() ?? undefined;\n }\n\n state<T>(): T | undefined {\n const value = this.#inner.stateJson();\n return value ? fromJson<T>(value) : undefined;\n }\n\n nodeState<T>(nodeId: string): T | undefined {\n const value = this.#inner.nodeStateJson(nodeId);\n return value ? fromJson<T>(value) : undefined;\n }\n\n document(nodeId: string, uri: string): VirtualDocumentState | undefined {\n const value = this.#inner.documentJson(nodeId, uri);\n return value ? fromJson<VirtualDocumentState>(value) : undefined;\n }\n\n openVirtualDocument(document: VirtualDocumentState): VirtualDocumentState {\n return fromJson(this.#inner.openVirtualDocumentJson(this.requireLeader(), toJson(document)));\n }\n\n changeVirtualDocument(uri: string, changes: VirtualChange[]): VirtualDocumentState {\n return fromJson(\n this.#inner.changeVirtualDocumentJson(this.requireLeader(), uri, toJson(changes)),\n );\n }\n\n closeVirtualDocument(uri: string): void {\n this.#inner.closeVirtualDocument(this.requireLeader(), uri);\n }\n\n private requireLeader(): string {\n const leaderId = this.leaderId();\n if (!leaderId) {\n throw new Error(\"raft leader has not been elected\");\n }\n return leaderId;\n }\n}\n\nexport {\n CorsaApiClient as TsgoApiClient,\n CorsaDistributedOrchestrator as TsgoDistributedOrchestrator,\n CorsaVirtualDocument as TsgoVirtualDocument,\n};\n\nexport default binding;\nexport const version = binding.version;\nexport type * from \"./types\";\n"],"mappings":";;AAmBA,MAAM,UACJ,aAAa,eAAe,aAAa,UAAU;AAOrD,SAAS,SAAY,OAAkB;AACrC,QAAO,KAAK,MAAM,MAAM;;AAG1B,SAAS,OAAO,OAAwB;AACtC,QAAO,KAAK,UAAU,SAAS,KAAK;;AAGtC,SAAgB,mBAAmB,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Ab,MAA0C;CACxC;CAEA,YAAY,SAAmB;AAC7B,QAAA,QAAc,IAAI,QAAQ,4BAA4B,QAAQ;;CAGhE,SAAS,QAAwB;AAC/B,SAAO,MAAA,MAAY,SAAS,OAAO;;CAGrC,WAA+B;AAC7B,SAAO,MAAA,MAAY,UAAU,IAAI,KAAA;;CAGnC,QAA0B;EACxB,MAAM,QAAQ,MAAA,MAAY,WAAW;AACrC,SAAO,QAAQ,SAAY,MAAM,GAAG,KAAA;;CAGtC,UAAa,QAA+B;EAC1C,MAAM,QAAQ,MAAA,MAAY,cAAc,OAAO;AAC/C,SAAO,QAAQ,SAAY,MAAM,GAAG,KAAA;;CAGtC,SAAS,QAAgB,KAA+C;EACtE,MAAM,QAAQ,MAAA,MAAY,aAAa,QAAQ,IAAI;AACnD,SAAO,QAAQ,SAA+B,MAAM,GAAG,KAAA;;CAGzD,oBAAoB,UAAsD;AACxE,SAAO,SAAS,MAAA,MAAY,wBAAwB,KAAK,eAAe,EAAE,OAAO,SAAS,CAAC,CAAC;;CAG9F,sBAAsB,KAAa,SAAgD;AACjF,SAAO,SACL,MAAA,MAAY,0BAA0B,KAAK,eAAe,EAAE,KAAK,OAAO,QAAQ,CAAC,CAClF;;CAGH,qBAAqB,KAAmB;AACtC,QAAA,MAAY,qBAAqB,KAAK,eAAe,EAAE,IAAI;;CAG7D,gBAAgC;EAC9B,MAAM,WAAW,KAAK,UAAU;AAChC,MAAI,CAAC,SACH,OAAM,IAAI,MAAM,mCAAmC;AAErD,SAAO;;;AAWX,MAAa,UAAU,QAAQ"}
1
+ {"version":3,"file":"index.mjs","names":["#inner"],"sources":["../ts/index.ts"],"sourcesContent":["import * as nativeModule from \"../index.js\";\n\nimport type {\n ApiClientOptions,\n ConfigResponse,\n InitializeResponse,\n NativeLintDiagnostic,\n NativeLintNode,\n NativeLintRuleMeta,\n SymbolResponse,\n TypeTextKind,\n TypeResponse,\n UnsafeTypeFlowInput,\n UpdateSnapshotParams,\n UpdateSnapshotResponse,\n VirtualChange,\n VirtualDocumentState,\n} from \"./types\";\n\nconst binding = (\n \"default\" in nativeModule ? nativeModule.default : nativeModule\n) as typeof import(\"../index.js\");\n\ntype NativeApiClient = InstanceType<typeof binding.TsgoApiClient>;\ntype NativeDistributedOrchestrator = InstanceType<typeof binding.TsgoDistributedOrchestrator>;\ntype NativeVirtualDocument = InstanceType<typeof binding.TsgoVirtualDocument>;\n\nfunction fromJson<T>(value: string): T {\n return JSON.parse(value) as T;\n}\n\nfunction toJson(value: unknown): string {\n return JSON.stringify(value ?? null);\n}\n\nexport function isUnsafeAssignment(input: UnsafeTypeFlowInput): boolean {\n return binding.isUnsafeAssignment(toJson(input));\n}\n\nexport function isUnsafeReturn(input: UnsafeTypeFlowInput): boolean {\n return binding.isUnsafeReturn(toJson(input));\n}\n\nexport function runNativeLintRule(ruleName: string, node: NativeLintNode): NativeLintDiagnostic[] {\n return fromJson(binding.runNativeLintRule(ruleName, toJson(node)));\n}\n\nexport function nativeLintRuleMetas(): NativeLintRuleMeta[] {\n return fromJson(binding.nativeLintRuleMetasJson());\n}\n\nexport function classifyTypeText(text?: string): TypeTextKind {\n return binding.classifyTypeText(text) as TypeTextKind;\n}\n\nexport function splitTopLevelTypeText(text: string, delimiter: string): string[] {\n return binding.splitTopLevelTypeText(text, delimiter);\n}\n\nexport function splitTypeText(text: string): string[] {\n return binding.splitTypeText(text);\n}\n\nexport function isStringLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isStringLikeTypeTexts([...typeTexts]);\n}\n\nexport function isNumberLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isNumberLikeTypeTexts([...typeTexts]);\n}\n\nexport function isBigIntLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isBigIntLikeTypeTexts([...typeTexts]);\n}\n\nexport function isAnyLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isAnyLikeTypeTexts([...typeTexts]);\n}\n\nexport function isUnknownLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isUnknownLikeTypeTexts([...typeTexts]);\n}\n\nexport function isArrayLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isArrayLikeTypeTexts([...typeTexts]);\n}\n\nexport function isStringArrayLikeTypeTexts(typeTexts: readonly string[]): boolean {\n return binding.isStringArrayLikeTypeTexts([...typeTexts]);\n}\n\nexport function isPromiseLikeTypeTexts(\n typeTexts: readonly string[],\n propertyNames: readonly string[] = [],\n): boolean {\n return binding.isPromiseLikeTypeTexts([...typeTexts], [...propertyNames]);\n}\n\nexport function isErrorLikeTypeTexts(\n typeTexts: readonly string[],\n propertyNames: readonly string[] = [],\n): boolean {\n return binding.isErrorLikeTypeTexts([...typeTexts], [...propertyNames]);\n}\n\nexport const Utils = Object.freeze({\n classifyTypeText,\n splitTopLevelTypeText,\n splitTypeText,\n isStringLikeTypeTexts,\n isNumberLikeTypeTexts,\n isBigIntLikeTypeTexts,\n isAnyLikeTypeTexts,\n isUnknownLikeTypeTexts,\n isArrayLikeTypeTexts,\n isStringArrayLikeTypeTexts,\n isPromiseLikeTypeTexts,\n isErrorLikeTypeTexts,\n});\n\nexport class CorsaApiClient {\n readonly #inner: NativeApiClient;\n\n private constructor(inner: NativeApiClient) {\n this.#inner = inner;\n }\n\n static spawn(options: ApiClientOptions): CorsaApiClient {\n return new CorsaApiClient(binding.TsgoApiClient.spawn(toJson(options)));\n }\n\n initialize(): InitializeResponse {\n return fromJson(this.#inner.initializeJson());\n }\n\n parseConfigFile(file: string): ConfigResponse {\n return fromJson(this.#inner.parseConfigFileJson(file));\n }\n\n updateSnapshot(params?: UpdateSnapshotParams): UpdateSnapshotResponse {\n return fromJson(this.#inner.updateSnapshotJson(params ? toJson(params) : undefined));\n }\n\n getSourceFile(snapshot: string, project: string, file: string): Uint8Array | null {\n return this.#inner.getSourceFile(snapshot, project, file) ?? null;\n }\n\n getStringType(snapshot: string, project: string): TypeResponse {\n return fromJson(this.#inner.getStringTypeJson(snapshot, project));\n }\n\n getTypeAtPosition(\n snapshot: string,\n project: string,\n file: string,\n position: number,\n ): TypeResponse | undefined {\n return (\n fromJson<TypeResponse | null>(\n this.#inner.getTypeAtPositionJson(snapshot, project, file, position),\n ) ?? undefined\n );\n }\n\n getSymbolAtPosition(\n snapshot: string,\n project: string,\n file: string,\n position: number,\n ): SymbolResponse | undefined {\n return (\n fromJson<SymbolResponse | null>(\n this.#inner.getSymbolAtPositionJson(snapshot, project, file, position),\n ) ?? undefined\n );\n }\n\n getTypeArguments(\n snapshot: string,\n project: string,\n typeHandle: string,\n objectFlags?: number,\n ): TypeResponse[] {\n return fromJson(this.#inner.getTypeArgumentsJson(snapshot, project, typeHandle, objectFlags));\n }\n\n getTypeOfSymbol(snapshot: string, project: string, symbol: string): TypeResponse | undefined {\n return (\n fromJson<TypeResponse | null>(this.#inner.getTypeOfSymbolJson(snapshot, project, symbol)) ??\n undefined\n );\n }\n\n getDeclaredTypeOfSymbol(\n snapshot: string,\n project: string,\n symbol: string,\n ): TypeResponse | undefined {\n return (\n fromJson<TypeResponse | null>(\n this.#inner.getDeclaredTypeOfSymbolJson(snapshot, project, symbol),\n ) ?? undefined\n );\n }\n\n typeToString(\n snapshot: string,\n project: string,\n typeHandle: string,\n location?: string,\n flags?: number,\n ): string {\n return this.#inner.typeToString(snapshot, project, typeHandle, location, flags);\n }\n\n callJson<T>(method: string, params?: unknown): T {\n return fromJson(this.#inner.callJson(method, params ? toJson(params) : undefined));\n }\n\n callBinary(method: string, params?: unknown): Uint8Array | null {\n return this.#inner.callBinary(method, params ? toJson(params) : undefined) ?? null;\n }\n\n releaseHandle(handle: string): void {\n this.#inner.releaseHandle(handle);\n }\n\n close(): void {\n this.#inner.close();\n }\n}\n\nexport class CorsaVirtualDocument {\n readonly #inner: NativeVirtualDocument;\n\n private constructor(inner: NativeVirtualDocument) {\n this.#inner = inner;\n }\n\n static untitled(path: string, languageId: string, text: string): CorsaVirtualDocument {\n return new CorsaVirtualDocument(binding.TsgoVirtualDocument.untitled(path, languageId, text));\n }\n\n static inMemory(\n authority: string,\n path: string,\n languageId: string,\n text: string,\n ): CorsaVirtualDocument {\n return new CorsaVirtualDocument(\n binding.TsgoVirtualDocument.inMemory(authority, path, languageId, text),\n );\n }\n\n get uri(): string {\n return this.#inner.uri;\n }\n\n get languageId(): string {\n return this.#inner.languageId;\n }\n\n get version(): number {\n return this.#inner.version;\n }\n\n get text(): string {\n return this.#inner.text;\n }\n\n state(): VirtualDocumentState {\n return fromJson(this.#inner.stateJson());\n }\n\n replace(text: string): void {\n this.#inner.replace(text);\n }\n\n applyChanges(changes: VirtualChange[]): unknown[] {\n return fromJson(this.#inner.applyChangesJson(toJson(changes)));\n }\n}\n\nexport class CorsaDistributedOrchestrator {\n readonly #inner: NativeDistributedOrchestrator;\n\n constructor(nodeIds: string[]) {\n this.#inner = new binding.TsgoDistributedOrchestrator(nodeIds);\n }\n\n campaign(nodeId: string): number {\n return this.#inner.campaign(nodeId);\n }\n\n leaderId(): string | undefined {\n return this.#inner.leaderId() ?? undefined;\n }\n\n state<T>(): T | undefined {\n const value = this.#inner.stateJson();\n return value ? fromJson<T>(value) : undefined;\n }\n\n nodeState<T>(nodeId: string): T | undefined {\n const value = this.#inner.nodeStateJson(nodeId);\n return value ? fromJson<T>(value) : undefined;\n }\n\n document(nodeId: string, uri: string): VirtualDocumentState | undefined {\n const value = this.#inner.documentJson(nodeId, uri);\n return value ? fromJson<VirtualDocumentState>(value) : undefined;\n }\n\n openVirtualDocument(document: VirtualDocumentState): VirtualDocumentState {\n return fromJson(this.#inner.openVirtualDocumentJson(this.requireLeader(), toJson(document)));\n }\n\n changeVirtualDocument(uri: string, changes: VirtualChange[]): VirtualDocumentState {\n return fromJson(\n this.#inner.changeVirtualDocumentJson(this.requireLeader(), uri, toJson(changes)),\n );\n }\n\n closeVirtualDocument(uri: string): void {\n this.#inner.closeVirtualDocument(this.requireLeader(), uri);\n }\n\n private requireLeader(): string {\n const leaderId = this.leaderId();\n if (!leaderId) {\n throw new Error(\"raft leader has not been elected\");\n }\n return leaderId;\n }\n}\n\nexport {\n CorsaApiClient as TsgoApiClient,\n CorsaDistributedOrchestrator as TsgoDistributedOrchestrator,\n CorsaVirtualDocument as TsgoVirtualDocument,\n};\n\nexport default binding;\nexport const version = binding.version;\nexport type * from \"./types\";\n"],"mappings":";;AAmBA,MAAM,UACJ,aAAa,eAAe,aAAa,UAAU;AAOrD,SAAS,SAAY,OAAkB;CACrC,OAAO,KAAK,MAAM,MAAM;;AAG1B,SAAS,OAAO,OAAwB;CACtC,OAAO,KAAK,UAAU,SAAS,KAAK;;AAGtC,SAAgB,mBAAmB,OAAqC;CACtE,OAAO,QAAQ,mBAAmB,OAAO,MAAM,CAAC;;AAGlD,SAAgB,eAAe,OAAqC;CAClE,OAAO,QAAQ,eAAe,OAAO,MAAM,CAAC;;AAG9C,SAAgB,kBAAkB,UAAkB,MAA8C;CAChG,OAAO,SAAS,QAAQ,kBAAkB,UAAU,OAAO,KAAK,CAAC,CAAC;;AAGpE,SAAgB,sBAA4C;CAC1D,OAAO,SAAS,QAAQ,yBAAyB,CAAC;;AAGpD,SAAgB,iBAAiB,MAA6B;CAC5D,OAAO,QAAQ,iBAAiB,KAAK;;AAGvC,SAAgB,sBAAsB,MAAc,WAA6B;CAC/E,OAAO,QAAQ,sBAAsB,MAAM,UAAU;;AAGvD,SAAgB,cAAc,MAAwB;CACpD,OAAO,QAAQ,cAAc,KAAK;;AAGpC,SAAgB,sBAAsB,WAAuC;CAC3E,OAAO,QAAQ,sBAAsB,CAAC,GAAG,UAAU,CAAC;;AAGtD,SAAgB,sBAAsB,WAAuC;CAC3E,OAAO,QAAQ,sBAAsB,CAAC,GAAG,UAAU,CAAC;;AAGtD,SAAgB,sBAAsB,WAAuC;CAC3E,OAAO,QAAQ,sBAAsB,CAAC,GAAG,UAAU,CAAC;;AAGtD,SAAgB,mBAAmB,WAAuC;CACxE,OAAO,QAAQ,mBAAmB,CAAC,GAAG,UAAU,CAAC;;AAGnD,SAAg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AK,eAAe,EAAE,IAAI;;CAG7D,gBAAgC;EAC9B,MAAM,WAAW,KAAK,UAAU;EAChC,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,mCAAmC;EAErD,OAAO;;;AAWX,MAAa,UAAU,QAAQ"}
package/index.d.ts CHANGED
@@ -1,34 +1,5 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
-
4
1
  /* auto-generated by NAPI-RS */
5
-
6
- export declare function runNativeLintRule(ruleName: string, nodeJson: string): string
7
- export declare function nativeLintRuleMetasJson(): string
8
- export declare function isUnsafeAssignment(inputJson: string): boolean
9
- export declare function isUnsafeReturn(inputJson: string): boolean
10
- export declare function classifyTypeText(text?: string | undefined | null): string
11
- export declare function splitTopLevelTypeText(text: string, delimiter: string): Array<string>
12
- export declare function splitTypeText(text: string): Array<string>
13
- export declare function isStringLikeTypeTexts(typeTexts: Array<string>): boolean
14
- export declare function isNumberLikeTypeTexts(typeTexts: Array<string>): boolean
15
- export declare function isBigIntLikeTypeTexts(typeTexts: Array<string>): boolean
16
- export declare function isAnyLikeTypeTexts(typeTexts: Array<string>): boolean
17
- export declare function isUnknownLikeTypeTexts(typeTexts: Array<string>): boolean
18
- export declare function isArrayLikeTypeTexts(typeTexts: Array<string>): boolean
19
- export declare function isStringArrayLikeTypeTexts(typeTexts: Array<string>): boolean
20
- export declare function isPromiseLikeTypeTexts(typeTexts: Array<string>, propertyNames?: Array<string> | undefined | null): boolean
21
- export declare function isErrorLikeTypeTexts(typeTexts: Array<string>, propertyNames?: Array<string> | undefined | null): boolean
22
- /**
23
- * Returns the package version exposed by the native addon.
24
- *
25
- * # Examples
26
- *
27
- * ```
28
- * assert_eq!(corsa_node::version(), env!("CARGO_PKG_VERSION"));
29
- * ```
30
- */
31
- export declare function version(): string
2
+ /* eslint-disable */
32
3
  /** Thin synchronous wrapper around the Rust stdio API client. */
33
4
  export declare class TsgoApiClient {
34
5
  /** Spawns a new client from a JSON-encoded spawn config. */
@@ -64,27 +35,7 @@ export declare class TsgoApiClient {
64
35
  /** Closes the underlying worker process. */
65
36
  close(): void
66
37
  }
67
- /** Mutable virtual document mirrored through the LSP overlay layer. */
68
- export declare class TsgoVirtualDocument {
69
- /** Creates an `untitled:` document. */
70
- static untitled(path: string, languageId: string, text: string): TsgoVirtualDocument
71
- /** Creates an in-memory `corsa://` document. */
72
- static inMemory(authority: string, path: string, languageId: string, text: string): TsgoVirtualDocument
73
- /** Returns the document URI. */
74
- get uri(): string
75
- /** Returns the language identifier. */
76
- get languageId(): string
77
- /** Returns the current version number. */
78
- get version(): number
79
- /** Returns the current full text. */
80
- get text(): string
81
- /** Serializes the full document state. */
82
- stateJson(): string
83
- /** Replaces the entire document text. */
84
- replace(text: string): void
85
- /** Applies a batch of JSON-encoded LSP changes. */
86
- applyChangesJson(changesJson: string): string
87
- }
38
+
88
39
  /** N-API wrapper for the distributed orchestration layer. */
89
40
  export declare class TsgoDistributedOrchestrator {
90
41
  /** Creates a new in-process Raft cluster. */
@@ -106,3 +57,68 @@ export declare class TsgoDistributedOrchestrator {
106
57
  /** Removes a replicated document. */
107
58
  closeVirtualDocument(leaderId: string, uri: string): void
108
59
  }
60
+
61
+ /** Mutable virtual document mirrored through the LSP overlay layer. */
62
+ export declare class TsgoVirtualDocument {
63
+ /** Creates an `untitled:` document. */
64
+ static untitled(path: string, languageId: string, text: string): TsgoVirtualDocument
65
+ /** Creates an in-memory `corsa://` document. */
66
+ static inMemory(authority: string, path: string, languageId: string, text: string): TsgoVirtualDocument
67
+ /** Returns the document URI. */
68
+ get uri(): string
69
+ /** Returns the language identifier. */
70
+ get languageId(): string
71
+ /** Returns the current version number. */
72
+ get version(): number
73
+ /** Returns the current full text. */
74
+ get text(): string
75
+ /** Serializes the full document state. */
76
+ stateJson(): string
77
+ /** Replaces the entire document text. */
78
+ replace(text: string): void
79
+ /** Applies a batch of JSON-encoded LSP changes. */
80
+ applyChangesJson(changesJson: string): string
81
+ }
82
+
83
+ export declare function classifyTypeText(text?: string | undefined | null): string
84
+
85
+ export declare function isAnyLikeTypeTexts(typeTexts: Array<string>): boolean
86
+
87
+ export declare function isArrayLikeTypeTexts(typeTexts: Array<string>): boolean
88
+
89
+ export declare function isBigIntLikeTypeTexts(typeTexts: Array<string>): boolean
90
+
91
+ export declare function isErrorLikeTypeTexts(typeTexts: Array<string>, propertyNames?: Array<string> | undefined | null): boolean
92
+
93
+ export declare function isNumberLikeTypeTexts(typeTexts: Array<string>): boolean
94
+
95
+ export declare function isPromiseLikeTypeTexts(typeTexts: Array<string>, propertyNames?: Array<string> | undefined | null): boolean
96
+
97
+ export declare function isStringArrayLikeTypeTexts(typeTexts: Array<string>): boolean
98
+
99
+ export declare function isStringLikeTypeTexts(typeTexts: Array<string>): boolean
100
+
101
+ export declare function isUnknownLikeTypeTexts(typeTexts: Array<string>): boolean
102
+
103
+ export declare function isUnsafeAssignment(inputJson: string): boolean
104
+
105
+ export declare function isUnsafeReturn(inputJson: string): boolean
106
+
107
+ export declare function nativeLintRuleMetasJson(): string
108
+
109
+ export declare function runNativeLintRule(ruleName: string, nodeJson: string): string
110
+
111
+ export declare function splitTopLevelTypeText(text: string, delimiter: string): Array<string>
112
+
113
+ export declare function splitTypeText(text: string): Array<string>
114
+
115
+ /**
116
+ * Returns the package version exposed by the native addon.
117
+ *
118
+ * # Examples
119
+ *
120
+ * ```
121
+ * assert_eq!(corsa_node::version(), env!("CARGO_PKG_VERSION"));
122
+ * ```
123
+ */
124
+ export declare function version(): string
package/index.js CHANGED
@@ -1,334 +1,598 @@
1
- /* tslint:disable */
1
+ // prettier-ignore
2
2
  /* eslint-disable */
3
- /* prettier-ignore */
4
-
3
+ // @ts-nocheck
5
4
  /* auto-generated by NAPI-RS */
6
5
 
7
- const { existsSync, readFileSync } = require('fs')
8
- const { join } = require('path')
6
+ const { readFileSync } = require('node:fs')
7
+ let nativeBinding = null
8
+ const loadErrors = []
9
9
 
10
- const { platform, arch } = process
10
+ const isMusl = () => {
11
+ let musl = false
12
+ if (process.platform === 'linux') {
13
+ musl = isMuslFromFilesystem()
14
+ if (musl === null) {
15
+ musl = isMuslFromReport()
16
+ }
17
+ if (musl === null) {
18
+ musl = isMuslFromChildProcess()
19
+ }
20
+ }
21
+ return musl
22
+ }
11
23
 
12
- let nativeBinding = null
13
- let localFileExisted = false
14
- let loadError = null
24
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
15
25
 
16
- function isMusl() {
17
- // For Node 10
18
- if (!process.report || typeof process.report.getReport !== 'function') {
19
- try {
20
- const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
- return readFileSync(lddPath, 'utf8').includes('musl')
22
- } catch (e) {
26
+ const isMuslFromFilesystem = () => {
27
+ try {
28
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
29
+ } catch {
30
+ return null
31
+ }
32
+ }
33
+
34
+ const isMuslFromReport = () => {
35
+ let report = null
36
+ if (typeof process.report?.getReport === 'function') {
37
+ process.report.excludeNetwork = true
38
+ report = process.report.getReport()
39
+ }
40
+ if (!report) {
41
+ return null
42
+ }
43
+ if (report.header && report.header.glibcVersionRuntime) {
44
+ return false
45
+ }
46
+ if (Array.isArray(report.sharedObjects)) {
47
+ if (report.sharedObjects.some(isFileMusl)) {
23
48
  return true
24
49
  }
25
- } else {
26
- const { glibcVersionRuntime } = process.report.getReport().header
27
- return !glibcVersionRuntime
28
50
  }
51
+ return false
29
52
  }
30
53
 
31
- switch (platform) {
32
- case 'android':
33
- switch (arch) {
34
- case 'arm64':
35
- localFileExisted = existsSync(join(__dirname, 'corsa_node.android-arm64.node'))
54
+ const isMuslFromChildProcess = () => {
55
+ try {
56
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
57
+ } catch (e) {
58
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
59
+ return false
60
+ }
61
+ }
62
+
63
+ function requireNative() {
64
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
65
+ try {
66
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
67
+ } catch (err) {
68
+ loadErrors.push(err)
69
+ }
70
+ } else if (process.platform === 'android') {
71
+ if (process.arch === 'arm64') {
72
+ try {
73
+ return require('./corsa_node.android-arm64.node')
74
+ } catch (e) {
75
+ loadErrors.push(e)
76
+ }
77
+ try {
78
+ const binding = require('@corsa-bind/napi-android-arm64')
79
+ const bindingPackageVersion = require('@corsa-bind/napi-android-arm64/package.json').version
80
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
+ }
83
+ return binding
84
+ } catch (e) {
85
+ loadErrors.push(e)
86
+ }
87
+ } else if (process.arch === 'arm') {
88
+ try {
89
+ return require('./corsa_node.android-arm-eabi.node')
90
+ } catch (e) {
91
+ loadErrors.push(e)
92
+ }
93
+ try {
94
+ const binding = require('@corsa-bind/napi-android-arm-eabi')
95
+ const bindingPackageVersion = require('@corsa-bind/napi-android-arm-eabi/package.json').version
96
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
+ }
99
+ return binding
100
+ } catch (e) {
101
+ loadErrors.push(e)
102
+ }
103
+ } else {
104
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
105
+ }
106
+ } else if (process.platform === 'win32') {
107
+ if (process.arch === 'x64') {
108
+ if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
36
109
  try {
37
- if (localFileExisted) {
38
- nativeBinding = require('./corsa_node.android-arm64.node')
39
- } else {
40
- nativeBinding = require('@corsa-bind/napi-android-arm64')
41
- }
110
+ return require('./corsa_node.win32-x64-gnu.node')
111
+ } catch (e) {
112
+ loadErrors.push(e)
113
+ }
114
+ try {
115
+ const binding = require('@corsa-bind/napi-win32-x64-gnu')
116
+ const bindingPackageVersion = require('@corsa-bind/napi-win32-x64-gnu/package.json').version
117
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
+ }
120
+ return binding
121
+ } catch (e) {
122
+ loadErrors.push(e)
123
+ }
124
+ } else {
125
+ try {
126
+ return require('./corsa_node.win32-x64-msvc.node')
127
+ } catch (e) {
128
+ loadErrors.push(e)
129
+ }
130
+ try {
131
+ const binding = require('@corsa-bind/napi-win32-x64-msvc')
132
+ const bindingPackageVersion = require('@corsa-bind/napi-win32-x64-msvc/package.json').version
133
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
+ }
136
+ return binding
137
+ } catch (e) {
138
+ loadErrors.push(e)
139
+ }
140
+ }
141
+ } else if (process.arch === 'ia32') {
142
+ try {
143
+ return require('./corsa_node.win32-ia32-msvc.node')
144
+ } catch (e) {
145
+ loadErrors.push(e)
146
+ }
147
+ try {
148
+ const binding = require('@corsa-bind/napi-win32-ia32-msvc')
149
+ const bindingPackageVersion = require('@corsa-bind/napi-win32-ia32-msvc/package.json').version
150
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
+ }
153
+ return binding
154
+ } catch (e) {
155
+ loadErrors.push(e)
156
+ }
157
+ } else if (process.arch === 'arm64') {
158
+ try {
159
+ return require('./corsa_node.win32-arm64-msvc.node')
160
+ } catch (e) {
161
+ loadErrors.push(e)
162
+ }
163
+ try {
164
+ const binding = require('@corsa-bind/napi-win32-arm64-msvc')
165
+ const bindingPackageVersion = require('@corsa-bind/napi-win32-arm64-msvc/package.json').version
166
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
+ }
169
+ return binding
170
+ } catch (e) {
171
+ loadErrors.push(e)
172
+ }
173
+ } else {
174
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
175
+ }
176
+ } else if (process.platform === 'darwin') {
177
+ try {
178
+ return require('./corsa_node.darwin-universal.node')
179
+ } catch (e) {
180
+ loadErrors.push(e)
181
+ }
182
+ try {
183
+ const binding = require('@corsa-bind/napi-darwin-universal')
184
+ const bindingPackageVersion = require('@corsa-bind/napi-darwin-universal/package.json').version
185
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
+ }
188
+ return binding
189
+ } catch (e) {
190
+ loadErrors.push(e)
191
+ }
192
+ if (process.arch === 'x64') {
193
+ try {
194
+ return require('./corsa_node.darwin-x64.node')
195
+ } catch (e) {
196
+ loadErrors.push(e)
197
+ }
198
+ try {
199
+ const binding = require('@corsa-bind/napi-darwin-x64')
200
+ const bindingPackageVersion = require('@corsa-bind/napi-darwin-x64/package.json').version
201
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
+ }
204
+ return binding
205
+ } catch (e) {
206
+ loadErrors.push(e)
207
+ }
208
+ } else if (process.arch === 'arm64') {
209
+ try {
210
+ return require('./corsa_node.darwin-arm64.node')
211
+ } catch (e) {
212
+ loadErrors.push(e)
213
+ }
214
+ try {
215
+ const binding = require('@corsa-bind/napi-darwin-arm64')
216
+ const bindingPackageVersion = require('@corsa-bind/napi-darwin-arm64/package.json').version
217
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
+ }
220
+ return binding
221
+ } catch (e) {
222
+ loadErrors.push(e)
223
+ }
224
+ } else {
225
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
226
+ }
227
+ } else if (process.platform === 'freebsd') {
228
+ if (process.arch === 'x64') {
229
+ try {
230
+ return require('./corsa_node.freebsd-x64.node')
231
+ } catch (e) {
232
+ loadErrors.push(e)
233
+ }
234
+ try {
235
+ const binding = require('@corsa-bind/napi-freebsd-x64')
236
+ const bindingPackageVersion = require('@corsa-bind/napi-freebsd-x64/package.json').version
237
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
+ }
240
+ return binding
241
+ } catch (e) {
242
+ loadErrors.push(e)
243
+ }
244
+ } else if (process.arch === 'arm64') {
245
+ try {
246
+ return require('./corsa_node.freebsd-arm64.node')
247
+ } catch (e) {
248
+ loadErrors.push(e)
249
+ }
250
+ try {
251
+ const binding = require('@corsa-bind/napi-freebsd-arm64')
252
+ const bindingPackageVersion = require('@corsa-bind/napi-freebsd-arm64/package.json').version
253
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
+ }
256
+ return binding
257
+ } catch (e) {
258
+ loadErrors.push(e)
259
+ }
260
+ } else {
261
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
262
+ }
263
+ } else if (process.platform === 'linux') {
264
+ if (process.arch === 'x64') {
265
+ if (isMusl()) {
266
+ try {
267
+ return require('./corsa_node.linux-x64-musl.node')
42
268
  } catch (e) {
43
- loadError = e
269
+ loadErrors.push(e)
44
270
  }
45
- break
46
- case 'arm':
47
- localFileExisted = existsSync(join(__dirname, 'corsa_node.android-arm-eabi.node'))
48
271
  try {
49
- if (localFileExisted) {
50
- nativeBinding = require('./corsa_node.android-arm-eabi.node')
51
- } else {
52
- nativeBinding = require('@corsa-bind/napi-android-arm-eabi')
272
+ const binding = require('@corsa-bind/napi-linux-x64-musl')
273
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-x64-musl/package.json').version
274
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
53
276
  }
277
+ return binding
54
278
  } catch (e) {
55
- loadError = e
279
+ loadErrors.push(e)
56
280
  }
57
- break
58
- default:
59
- throw new Error(`Unsupported architecture on Android ${arch}`)
60
- }
61
- break
62
- case 'win32':
63
- switch (arch) {
64
- case 'x64':
65
- localFileExisted = existsSync(
66
- join(__dirname, 'corsa_node.win32-x64-msvc.node')
67
- )
281
+ } else {
68
282
  try {
69
- if (localFileExisted) {
70
- nativeBinding = require('./corsa_node.win32-x64-msvc.node')
71
- } else {
72
- nativeBinding = require('@corsa-bind/napi-win32-x64-msvc')
73
- }
283
+ return require('./corsa_node.linux-x64-gnu.node')
74
284
  } catch (e) {
75
- loadError = e
285
+ loadErrors.push(e)
76
286
  }
77
- break
78
- case 'ia32':
79
- localFileExisted = existsSync(
80
- join(__dirname, 'corsa_node.win32-ia32-msvc.node')
81
- )
82
287
  try {
83
- if (localFileExisted) {
84
- nativeBinding = require('./corsa_node.win32-ia32-msvc.node')
85
- } else {
86
- nativeBinding = require('@corsa-bind/napi-win32-ia32-msvc')
288
+ const binding = require('@corsa-bind/napi-linux-x64-gnu')
289
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-x64-gnu/package.json').version
290
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
87
292
  }
293
+ return binding
88
294
  } catch (e) {
89
- loadError = e
295
+ loadErrors.push(e)
90
296
  }
91
- break
92
- case 'arm64':
93
- localFileExisted = existsSync(
94
- join(__dirname, 'corsa_node.win32-arm64-msvc.node')
95
- )
297
+ }
298
+ } else if (process.arch === 'arm64') {
299
+ if (isMusl()) {
96
300
  try {
97
- if (localFileExisted) {
98
- nativeBinding = require('./corsa_node.win32-arm64-msvc.node')
99
- } else {
100
- nativeBinding = require('@corsa-bind/napi-win32-arm64-msvc')
301
+ return require('./corsa_node.linux-arm64-musl.node')
302
+ } catch (e) {
303
+ loadErrors.push(e)
304
+ }
305
+ try {
306
+ const binding = require('@corsa-bind/napi-linux-arm64-musl')
307
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-arm64-musl/package.json').version
308
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
101
310
  }
311
+ return binding
102
312
  } catch (e) {
103
- loadError = e
313
+ loadErrors.push(e)
104
314
  }
105
- break
106
- default:
107
- throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
- }
109
- break
110
- case 'darwin':
111
- localFileExisted = existsSync(join(__dirname, 'corsa_node.darwin-universal.node'))
112
- try {
113
- if (localFileExisted) {
114
- nativeBinding = require('./corsa_node.darwin-universal.node')
115
315
  } else {
116
- nativeBinding = require('@corsa-bind/napi-darwin-universal')
117
- }
118
- break
119
- } catch {}
120
- switch (arch) {
121
- case 'x64':
122
- localFileExisted = existsSync(join(__dirname, 'corsa_node.darwin-x64.node'))
123
316
  try {
124
- if (localFileExisted) {
125
- nativeBinding = require('./corsa_node.darwin-x64.node')
126
- } else {
127
- nativeBinding = require('@corsa-bind/napi-darwin-x64')
128
- }
317
+ return require('./corsa_node.linux-arm64-gnu.node')
129
318
  } catch (e) {
130
- loadError = e
319
+ loadErrors.push(e)
131
320
  }
132
- break
133
- case 'arm64':
134
- localFileExisted = existsSync(
135
- join(__dirname, 'corsa_node.darwin-arm64.node')
136
- )
137
321
  try {
138
- if (localFileExisted) {
139
- nativeBinding = require('./corsa_node.darwin-arm64.node')
140
- } else {
141
- nativeBinding = require('@corsa-bind/napi-darwin-arm64')
322
+ const binding = require('@corsa-bind/napi-linux-arm64-gnu')
323
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-arm64-gnu/package.json').version
324
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
142
326
  }
327
+ return binding
143
328
  } catch (e) {
144
- loadError = e
329
+ loadErrors.push(e)
145
330
  }
146
- break
147
- default:
148
- throw new Error(`Unsupported architecture on macOS: ${arch}`)
149
- }
150
- break
151
- case 'freebsd':
152
- if (arch !== 'x64') {
153
- throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154
- }
155
- localFileExisted = existsSync(join(__dirname, 'corsa_node.freebsd-x64.node'))
156
- try {
157
- if (localFileExisted) {
158
- nativeBinding = require('./corsa_node.freebsd-x64.node')
159
- } else {
160
- nativeBinding = require('@corsa-bind/napi-freebsd-x64')
161
331
  }
162
- } catch (e) {
163
- loadError = e
164
- }
165
- break
166
- case 'linux':
167
- switch (arch) {
168
- case 'x64':
169
- if (isMusl()) {
170
- localFileExisted = existsSync(
171
- join(__dirname, 'corsa_node.linux-x64-musl.node')
172
- )
173
- try {
174
- if (localFileExisted) {
175
- nativeBinding = require('./corsa_node.linux-x64-musl.node')
176
- } else {
177
- nativeBinding = require('@corsa-bind/napi-linux-x64-musl')
178
- }
179
- } catch (e) {
180
- loadError = e
181
- }
182
- } else {
183
- localFileExisted = existsSync(
184
- join(__dirname, 'corsa_node.linux-x64-gnu.node')
185
- )
186
- try {
187
- if (localFileExisted) {
188
- nativeBinding = require('./corsa_node.linux-x64-gnu.node')
189
- } else {
190
- nativeBinding = require('@corsa-bind/napi-linux-x64-gnu')
191
- }
192
- } catch (e) {
193
- loadError = e
194
- }
332
+ } else if (process.arch === 'arm') {
333
+ if (isMusl()) {
334
+ try {
335
+ return require('./corsa_node.linux-arm-musleabihf.node')
336
+ } catch (e) {
337
+ loadErrors.push(e)
195
338
  }
196
- break
197
- case 'arm64':
198
- if (isMusl()) {
199
- localFileExisted = existsSync(
200
- join(__dirname, 'corsa_node.linux-arm64-musl.node')
201
- )
202
- try {
203
- if (localFileExisted) {
204
- nativeBinding = require('./corsa_node.linux-arm64-musl.node')
205
- } else {
206
- nativeBinding = require('@corsa-bind/napi-linux-arm64-musl')
207
- }
208
- } catch (e) {
209
- loadError = e
210
- }
211
- } else {
212
- localFileExisted = existsSync(
213
- join(__dirname, 'corsa_node.linux-arm64-gnu.node')
214
- )
215
- try {
216
- if (localFileExisted) {
217
- nativeBinding = require('./corsa_node.linux-arm64-gnu.node')
218
- } else {
219
- nativeBinding = require('@corsa-bind/napi-linux-arm64-gnu')
220
- }
221
- } catch (e) {
222
- loadError = e
339
+ try {
340
+ const binding = require('@corsa-bind/napi-linux-arm-musleabihf')
341
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-arm-musleabihf/package.json').version
342
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
344
  }
345
+ return binding
346
+ } catch (e) {
347
+ loadErrors.push(e)
348
+ }
349
+ } else {
350
+ try {
351
+ return require('./corsa_node.linux-arm-gnueabihf.node')
352
+ } catch (e) {
353
+ loadErrors.push(e)
224
354
  }
225
- break
226
- case 'arm':
227
- if (isMusl()) {
228
- localFileExisted = existsSync(
229
- join(__dirname, 'corsa_node.linux-arm-musleabihf.node')
230
- )
231
- try {
232
- if (localFileExisted) {
233
- nativeBinding = require('./corsa_node.linux-arm-musleabihf.node')
234
- } else {
235
- nativeBinding = require('@corsa-bind/napi-linux-arm-musleabihf')
236
- }
237
- } catch (e) {
238
- loadError = e
355
+ try {
356
+ const binding = require('@corsa-bind/napi-linux-arm-gnueabihf')
357
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-arm-gnueabihf/package.json').version
358
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
360
  }
240
- } else {
241
- localFileExisted = existsSync(
242
- join(__dirname, 'corsa_node.linux-arm-gnueabihf.node')
243
- )
244
- try {
245
- if (localFileExisted) {
246
- nativeBinding = require('./corsa_node.linux-arm-gnueabihf.node')
247
- } else {
248
- nativeBinding = require('@corsa-bind/napi-linux-arm-gnueabihf')
249
- }
250
- } catch (e) {
251
- loadError = e
361
+ return binding
362
+ } catch (e) {
363
+ loadErrors.push(e)
364
+ }
365
+ }
366
+ } else if (process.arch === 'loong64') {
367
+ if (isMusl()) {
368
+ try {
369
+ return require('./corsa_node.linux-loong64-musl.node')
370
+ } catch (e) {
371
+ loadErrors.push(e)
372
+ }
373
+ try {
374
+ const binding = require('@corsa-bind/napi-linux-loong64-musl')
375
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-loong64-musl/package.json').version
376
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
252
378
  }
379
+ return binding
380
+ } catch (e) {
381
+ loadErrors.push(e)
253
382
  }
254
- break
255
- case 'riscv64':
256
- if (isMusl()) {
257
- localFileExisted = existsSync(
258
- join(__dirname, 'corsa_node.linux-riscv64-musl.node')
259
- )
260
- try {
261
- if (localFileExisted) {
262
- nativeBinding = require('./corsa_node.linux-riscv64-musl.node')
263
- } else {
264
- nativeBinding = require('@corsa-bind/napi-linux-riscv64-musl')
265
- }
266
- } catch (e) {
267
- loadError = e
383
+ } else {
384
+ try {
385
+ return require('./corsa_node.linux-loong64-gnu.node')
386
+ } catch (e) {
387
+ loadErrors.push(e)
388
+ }
389
+ try {
390
+ const binding = require('@corsa-bind/napi-linux-loong64-gnu')
391
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-loong64-gnu/package.json').version
392
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
268
394
  }
269
- } else {
270
- localFileExisted = existsSync(
271
- join(__dirname, 'corsa_node.linux-riscv64-gnu.node')
272
- )
273
- try {
274
- if (localFileExisted) {
275
- nativeBinding = require('./corsa_node.linux-riscv64-gnu.node')
276
- } else {
277
- nativeBinding = require('@corsa-bind/napi-linux-riscv64-gnu')
278
- }
279
- } catch (e) {
280
- loadError = e
395
+ return binding
396
+ } catch (e) {
397
+ loadErrors.push(e)
398
+ }
399
+ }
400
+ } else if (process.arch === 'riscv64') {
401
+ if (isMusl()) {
402
+ try {
403
+ return require('./corsa_node.linux-riscv64-musl.node')
404
+ } catch (e) {
405
+ loadErrors.push(e)
406
+ }
407
+ try {
408
+ const binding = require('@corsa-bind/napi-linux-riscv64-musl')
409
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-riscv64-musl/package.json').version
410
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
281
412
  }
413
+ return binding
414
+ } catch (e) {
415
+ loadErrors.push(e)
416
+ }
417
+ } else {
418
+ try {
419
+ return require('./corsa_node.linux-riscv64-gnu.node')
420
+ } catch (e) {
421
+ loadErrors.push(e)
282
422
  }
283
- break
284
- case 's390x':
285
- localFileExisted = existsSync(
286
- join(__dirname, 'corsa_node.linux-s390x-gnu.node')
287
- )
288
423
  try {
289
- if (localFileExisted) {
290
- nativeBinding = require('./corsa_node.linux-s390x-gnu.node')
291
- } else {
292
- nativeBinding = require('@corsa-bind/napi-linux-s390x-gnu')
424
+ const binding = require('@corsa-bind/napi-linux-riscv64-gnu')
425
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-riscv64-gnu/package.json').version
426
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
293
428
  }
429
+ return binding
294
430
  } catch (e) {
295
- loadError = e
431
+ loadErrors.push(e)
432
+ }
433
+ }
434
+ } else if (process.arch === 'ppc64') {
435
+ try {
436
+ return require('./corsa_node.linux-ppc64-gnu.node')
437
+ } catch (e) {
438
+ loadErrors.push(e)
439
+ }
440
+ try {
441
+ const binding = require('@corsa-bind/napi-linux-ppc64-gnu')
442
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-ppc64-gnu/package.json').version
443
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
445
  }
297
- break
298
- default:
299
- throw new Error(`Unsupported architecture on Linux: ${arch}`)
446
+ return binding
447
+ } catch (e) {
448
+ loadErrors.push(e)
449
+ }
450
+ } else if (process.arch === 's390x') {
451
+ try {
452
+ return require('./corsa_node.linux-s390x-gnu.node')
453
+ } catch (e) {
454
+ loadErrors.push(e)
455
+ }
456
+ try {
457
+ const binding = require('@corsa-bind/napi-linux-s390x-gnu')
458
+ const bindingPackageVersion = require('@corsa-bind/napi-linux-s390x-gnu/package.json').version
459
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
+ }
462
+ return binding
463
+ } catch (e) {
464
+ loadErrors.push(e)
465
+ }
466
+ } else {
467
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
300
468
  }
301
- break
302
- default:
303
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
469
+ } else if (process.platform === 'openharmony') {
470
+ if (process.arch === 'arm64') {
471
+ try {
472
+ return require('./corsa_node.openharmony-arm64.node')
473
+ } catch (e) {
474
+ loadErrors.push(e)
475
+ }
476
+ try {
477
+ const binding = require('@corsa-bind/napi-openharmony-arm64')
478
+ const bindingPackageVersion = require('@corsa-bind/napi-openharmony-arm64/package.json').version
479
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
+ }
482
+ return binding
483
+ } catch (e) {
484
+ loadErrors.push(e)
485
+ }
486
+ } else if (process.arch === 'x64') {
487
+ try {
488
+ return require('./corsa_node.openharmony-x64.node')
489
+ } catch (e) {
490
+ loadErrors.push(e)
491
+ }
492
+ try {
493
+ const binding = require('@corsa-bind/napi-openharmony-x64')
494
+ const bindingPackageVersion = require('@corsa-bind/napi-openharmony-x64/package.json').version
495
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
+ }
498
+ return binding
499
+ } catch (e) {
500
+ loadErrors.push(e)
501
+ }
502
+ } else if (process.arch === 'arm') {
503
+ try {
504
+ return require('./corsa_node.openharmony-arm.node')
505
+ } catch (e) {
506
+ loadErrors.push(e)
507
+ }
508
+ try {
509
+ const binding = require('@corsa-bind/napi-openharmony-arm')
510
+ const bindingPackageVersion = require('@corsa-bind/napi-openharmony-arm/package.json').version
511
+ if (bindingPackageVersion !== '0.8.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.8.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
+ }
514
+ return binding
515
+ } catch (e) {
516
+ loadErrors.push(e)
517
+ }
518
+ } else {
519
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
520
+ }
521
+ } else {
522
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
523
+ }
524
+ }
525
+
526
+ nativeBinding = requireNative()
527
+
528
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
529
+ let wasiBinding = null
530
+ let wasiBindingError = null
531
+ try {
532
+ wasiBinding = require('./corsa_node.wasi.cjs')
533
+ nativeBinding = wasiBinding
534
+ } catch (err) {
535
+ if (process.env.NAPI_RS_FORCE_WASI) {
536
+ wasiBindingError = err
537
+ }
538
+ }
539
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
540
+ try {
541
+ wasiBinding = require('@corsa-bind/napi-wasm32-wasi')
542
+ nativeBinding = wasiBinding
543
+ } catch (err) {
544
+ if (process.env.NAPI_RS_FORCE_WASI) {
545
+ if (!wasiBindingError) {
546
+ wasiBindingError = err
547
+ } else {
548
+ wasiBindingError.cause = err
549
+ }
550
+ loadErrors.push(err)
551
+ }
552
+ }
553
+ }
554
+ if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
555
+ const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
556
+ error.cause = wasiBindingError
557
+ throw error
558
+ }
304
559
  }
305
560
 
306
561
  if (!nativeBinding) {
307
- if (loadError) {
308
- throw loadError
562
+ if (loadErrors.length > 0) {
563
+ throw new Error(
564
+ `Cannot find native binding. ` +
565
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
566
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
567
+ {
568
+ cause: loadErrors.reduce((err, cur) => {
569
+ cur.cause = err
570
+ return cur
571
+ }),
572
+ },
573
+ )
309
574
  }
310
575
  throw new Error(`Failed to load native binding`)
311
576
  }
312
577
 
313
- const { TsgoApiClient, TsgoVirtualDocument, runNativeLintRule, nativeLintRuleMetasJson, TsgoDistributedOrchestrator, isUnsafeAssignment, isUnsafeReturn, classifyTypeText, splitTopLevelTypeText, splitTypeText, isStringLikeTypeTexts, isNumberLikeTypeTexts, isBigIntLikeTypeTexts, isAnyLikeTypeTexts, isUnknownLikeTypeTexts, isArrayLikeTypeTexts, isStringArrayLikeTypeTexts, isPromiseLikeTypeTexts, isErrorLikeTypeTexts, version } = nativeBinding
314
-
315
- module.exports.TsgoApiClient = TsgoApiClient
316
- module.exports.TsgoVirtualDocument = TsgoVirtualDocument
317
- module.exports.runNativeLintRule = runNativeLintRule
318
- module.exports.nativeLintRuleMetasJson = nativeLintRuleMetasJson
319
- module.exports.TsgoDistributedOrchestrator = TsgoDistributedOrchestrator
320
- module.exports.isUnsafeAssignment = isUnsafeAssignment
321
- module.exports.isUnsafeReturn = isUnsafeReturn
322
- module.exports.classifyTypeText = classifyTypeText
323
- module.exports.splitTopLevelTypeText = splitTopLevelTypeText
324
- module.exports.splitTypeText = splitTypeText
325
- module.exports.isStringLikeTypeTexts = isStringLikeTypeTexts
326
- module.exports.isNumberLikeTypeTexts = isNumberLikeTypeTexts
327
- module.exports.isBigIntLikeTypeTexts = isBigIntLikeTypeTexts
328
- module.exports.isAnyLikeTypeTexts = isAnyLikeTypeTexts
329
- module.exports.isUnknownLikeTypeTexts = isUnknownLikeTypeTexts
330
- module.exports.isArrayLikeTypeTexts = isArrayLikeTypeTexts
331
- module.exports.isStringArrayLikeTypeTexts = isStringArrayLikeTypeTexts
332
- module.exports.isPromiseLikeTypeTexts = isPromiseLikeTypeTexts
333
- module.exports.isErrorLikeTypeTexts = isErrorLikeTypeTexts
334
- module.exports.version = version
578
+ module.exports = nativeBinding
579
+ module.exports.TsgoApiClient = nativeBinding.TsgoApiClient
580
+ module.exports.TsgoDistributedOrchestrator = nativeBinding.TsgoDistributedOrchestrator
581
+ module.exports.TsgoVirtualDocument = nativeBinding.TsgoVirtualDocument
582
+ module.exports.classifyTypeText = nativeBinding.classifyTypeText
583
+ module.exports.isAnyLikeTypeTexts = nativeBinding.isAnyLikeTypeTexts
584
+ module.exports.isArrayLikeTypeTexts = nativeBinding.isArrayLikeTypeTexts
585
+ module.exports.isBigIntLikeTypeTexts = nativeBinding.isBigIntLikeTypeTexts
586
+ module.exports.isErrorLikeTypeTexts = nativeBinding.isErrorLikeTypeTexts
587
+ module.exports.isNumberLikeTypeTexts = nativeBinding.isNumberLikeTypeTexts
588
+ module.exports.isPromiseLikeTypeTexts = nativeBinding.isPromiseLikeTypeTexts
589
+ module.exports.isStringArrayLikeTypeTexts = nativeBinding.isStringArrayLikeTypeTexts
590
+ module.exports.isStringLikeTypeTexts = nativeBinding.isStringLikeTypeTexts
591
+ module.exports.isUnknownLikeTypeTexts = nativeBinding.isUnknownLikeTypeTexts
592
+ module.exports.isUnsafeAssignment = nativeBinding.isUnsafeAssignment
593
+ module.exports.isUnsafeReturn = nativeBinding.isUnsafeReturn
594
+ module.exports.nativeLintRuleMetasJson = nativeBinding.nativeLintRuleMetasJson
595
+ module.exports.runNativeLintRule = nativeBinding.runNativeLintRule
596
+ module.exports.splitTopLevelTypeText = nativeBinding.splitTopLevelTypeText
597
+ module.exports.splitTypeText = nativeBinding.splitTypeText
598
+ module.exports.version = nativeBinding.version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corsa-bind/napi",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Native Node.js bindings for corsa and typescript-go stdio workflows",
5
5
  "homepage": "https://github.com/ubugeeei/corsa-bind/tree/main/src/bindings/nodejs/corsa_node",
6
6
  "bugs": {
@@ -46,13 +46,13 @@
46
46
  "node": ">=22"
47
47
  },
48
48
  "optionalDependencies": {
49
- "@corsa-bind/napi-win32-x64-msvc": "0.7.1",
50
- "@corsa-bind/napi-darwin-x64": "0.7.1",
51
- "@corsa-bind/napi-linux-x64-gnu": "0.7.1",
52
- "@corsa-bind/napi-darwin-arm64": "0.7.1",
53
- "@corsa-bind/napi-win32-arm64-msvc": "0.7.1",
54
- "@corsa-bind/napi-linux-x64-musl": "0.7.1",
55
- "@corsa-bind/napi-linux-arm64-gnu": "0.7.1",
56
- "@corsa-bind/napi-linux-arm64-musl": "0.7.1"
49
+ "@corsa-bind/napi-win32-x64-msvc": "0.8.0",
50
+ "@corsa-bind/napi-darwin-x64": "0.8.0",
51
+ "@corsa-bind/napi-linux-x64-gnu": "0.8.0",
52
+ "@corsa-bind/napi-darwin-arm64": "0.8.0",
53
+ "@corsa-bind/napi-win32-arm64-msvc": "0.8.0",
54
+ "@corsa-bind/napi-linux-x64-musl": "0.8.0",
55
+ "@corsa-bind/napi-linux-arm64-gnu": "0.8.0",
56
+ "@corsa-bind/napi-linux-arm64-musl": "0.8.0"
57
57
  }
58
58
  }