Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/DBSQLClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './utils/thriftCompat';
import thrift from 'thrift';
import Int64 from 'node-int64';

Expand Down
1 change: 1 addition & 0 deletions lib/connection/connections/HttpConnection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../../utils/thriftCompat';
import thrift from 'thrift';
import https from 'https';
import http from 'http';
Expand Down
1 change: 1 addition & 0 deletions lib/connection/connections/ThriftHttpConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { EventEmitter } from 'events';
import '../../utils/thriftCompat';
import { TBinaryProtocol, TBufferedTransport, Thrift, TProtocol, TProtocolConstructor, TTransport } from 'thrift';
import fetch, { RequestInit, HeadersInit, Request, Response, FetchError } from 'node-fetch';
// @ts-expect-error TS7016: Could not find a declaration file for module
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Don't move this import - it should be placed before any other
import './polyfills';
import './utils/thriftCompat';

import { Thrift } from 'thrift';
import TCLIService from '../thrift/TCLIService';
Expand Down
25 changes: 25 additions & 0 deletions lib/utils/thriftCompat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Module from 'module';

type InternalModuleLoader = {
_load: (request: string, parent: NodeJS.Module | undefined, isMain: boolean) => unknown;
};

const PATCH_KEY = Symbol.for('databricks.sql.thriftUuidCompatInstalled');
const globalState = globalThis as typeof globalThis & { [PATCH_KEY]?: boolean };

if (!globalState[PATCH_KEY]) {
const moduleWithLoader = Module as unknown as InternalModuleLoader;
const originalLoad = moduleWithLoader._load.bind(Module);

moduleWithLoader._load = (request, parent, isMain) => {
if (request === 'uuid' && parent?.filename && /[\\/]node_modules[\\/]thrift[\\/]/.test(parent.filename)) {
// thrift 0.23.x still loads uuid using require(), which fails with uuid@13 on older Node.js.
// Force thrift internals to use our direct uuid dependency (v9, CommonJS-compatible).
return require('uuid'); // eslint-disable-line global-require
}

return originalLoad(request, parent, isMain);
};

globalState[PATCH_KEY] = true;
}
Loading