Skip to content
Merged
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions src/SqliteExtensions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import path from 'path';
import {resolve} from 'path';
// __dirname is not available in ES modules, so we define it here
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states that __dirname is not available in ES modules, but the code attempts to reference it before defining it. In CommonJS (the current module system used by this package according to package.json), __dirname IS available as a global. In true ES modules, __dirname would cause a ReferenceError.

This comment is misleading because:

  1. The source files use ES6 import/export syntax but are transpiled to CommonJS by Babel/Rollup
  2. When running in CommonJS (the default format), __dirname is already available
  3. When running as an ES module, import.meta.dirname may not be available in older Node.js versions (it was added in Node.js 20.11.0)

The comment should clarify the actual use case or be updated to reflect the correct fallback strategy.

Copilot uses AI. Check for mistakes.
const __dirname = __dirname || import.meta.dirname;
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has a logical error: const __dirname = __dirname || import.meta.dirname; references __dirname on the right side before it's defined. This will result in a ReferenceError when __dirname is not available (i.e., in ES modules).

For ES module compatibility, the correct approach is to use import.meta.url with the fileURLToPath and dirname functions from the 'path' and 'url' modules:

import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __dirname = import.meta.url ? dirname(fileURLToPath(import.meta.url)) : __dirname;

Alternatively, if using Node.js 20.11.0 or later where import.meta.dirname is available, use a try-catch or conditional check that doesn't reference the undefined variable.

Suggested change
import {resolve} from 'path';
// __dirname is not available in ES modules, so we define it here
const __dirname = __dirname || import.meta.dirname;
import {resolve, dirname} from 'path';
import {fileURLToPath} from 'url';
// __dirname is not available in ES modules, so we define it here
const __dirname = typeof __dirname !== 'undefined'
? __dirname
: dirname(fileURLToPath(import.meta.url));

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of import.meta.dirname requires Node.js 20.11.0 or later, but package.json specifies "engines": { "node": ">=12" }. This creates a version compatibility issue.

In Node.js versions 12-20.10.x, import.meta.dirname is undefined, which would cause the fallback logic to fail (even if the fallback logic itself weren't broken). Consider either:

  1. Using import.meta.url with fileURLToPath and dirname for broader compatibility
  2. Updating the minimum Node.js version requirement in package.json to 20.11.0 or later

Note that import.meta.dirname was only added in Node.js 20.11.0 (released January 2024) and 21.2.0.

Suggested change
import {resolve} from 'path';
// __dirname is not available in ES modules, so we define it here
const __dirname = __dirname || import.meta.dirname;
import {resolve, dirname} from 'path';
import {fileURLToPath} from 'url';
// __dirname is not available in ES modules, so we define it here
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Copilot uses AI. Check for mistakes.

const SqliteExtensions = {
uuid: path.resolve(__dirname, '../lib/uuid'), // Universally Unique Identifiers
crypto: path.resolve(__dirname, '../lib/crypto'), // hashing, encoding and decoding data
regexp: path.resolve(__dirname, '../lib/regexp') // regular expressions
uuid: resolve(__dirname, '../lib/uuid'), // Universally Unique Identifiers
crypto: resolve(__dirname, '../lib/crypto'), // hashing, encoding and decoding data
regexp: resolve(__dirname, '../lib/regexp') // regular expressions
}

export {
Expand Down
Loading