@sqliteai/sqlite-sync 0.9.63 → 0.9.82
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.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var fs = require('fs');
|
|
7
|
+
var module$1 = require('module');
|
|
7
8
|
var os = require('os');
|
|
8
9
|
var child_process = require('child_process');
|
|
9
10
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
}) : x)(function(x) {
|
|
13
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
14
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
15
|
-
});
|
|
11
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
12
|
+
// src/index.ts
|
|
16
13
|
var PLATFORM_EXTENSIONS = {
|
|
17
14
|
darwin: ".dylib",
|
|
18
15
|
linux: ".so",
|
|
@@ -98,6 +95,7 @@ function getBinaryName() {
|
|
|
98
95
|
}
|
|
99
96
|
|
|
100
97
|
// src/index.ts
|
|
98
|
+
var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
|
|
101
99
|
var ExtensionNotFoundError = class extends Error {
|
|
102
100
|
constructor(message) {
|
|
103
101
|
super(message);
|
|
@@ -107,7 +105,7 @@ var ExtensionNotFoundError = class extends Error {
|
|
|
107
105
|
function tryLoadPlatformPackage() {
|
|
108
106
|
try {
|
|
109
107
|
const packageName = getPlatformPackageName();
|
|
110
|
-
const platformPackage =
|
|
108
|
+
const platformPackage = require2(packageName);
|
|
111
109
|
if ((platformPackage == null ? void 0 : platformPackage.path) && typeof platformPackage.path === "string") {
|
|
112
110
|
if (fs.existsSync(platformPackage.path)) {
|
|
113
111
|
return platformPackage.path;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/platform.ts","../src/index.ts"],"names":["platform","existsSync","execSync","readFileSync","arch","resolve"],"mappings":";;;;;;;;;;;;;;;AAmBO,IAAM,mBAAA,GAA8C;AAAA,EACzD,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO,KAAA;AAAA,EACP,KAAA,EAAO;AACT,CAAA;AAMO,SAAS,MAAA,GAAkB;AA7BlC,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA+BE,EAAA,IAAIA,WAAA,OAAe,OAAA,EAAS;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,0BAAA;AAAA,IACA,2BAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,QAAQ,SAAA,EAAW;AAC5B,IAAA,IAAIC,aAAA,CAAW,IAAI,CAAA,EAAG;AACpB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,IAAI;AACF,IAAA,MAAM,UAAA,GAAaC,uBAAS,oBAAA,EAAsB;AAAA,MAChD,QAAA,EAAU,OAAA;AAAA,MACV,KAAA,EAAO,CAAC,MAAA,EAAQ,MAAA,EAAQ,MAAM;AAAA,KAC/B,CAAA;AAED,IAAA,IAAI,UAAA,CAAW,QAAA,CAAS,MAAM,CAAA,EAAG;AAC/B,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAGA,EAAA,IAAI;AACF,IAAA,IAAID,aAAA,CAAW,iBAAiB,CAAA,EAAG;AACjC,MAAA,MAAM,SAAA,GAAYE,eAAA,CAAa,iBAAA,EAAmB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AAA,CAAgB,IAAI,CAAA,EAAG;AACpC,QAAA,OAAO,eAAA,CAAgB,IAAA;AAAA,MACzB;AAAA,IACF;AAAA,EACF,SAAS,KAAA,EAAO;AAAA,EAGhB;AAEA,EAAA,OAAO,IAAA;AACT;AAgBO,SAAS,gBAAA,GAA2B;AAEzC,EAAA,MAAM,eAAe,sBAAA,EAAuB;AAC5C,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAOI,aAAQ,YAAY,CAAA;AAAA,EAC7B;AAGA,EAAA,MAAM,kBAAkB,kBAAA,EAAmB;AAC3C,EAAA,MAAM,cAAc,sBAAA,EAAuB;AAE3C,EAAA,MAAM,IAAI,sBAAA;AAAA,IACR,iDAAiD,eAAe;;AAAA,+BAAA,EAC9B,WAAW,CAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,gCAAA;AAAA,GAM/C;AACF;AAmCO,SAAS,gBAAA,GAAkC;AAChD,EAAA,OAAO;AAAA,IACL,UAAU,kBAAA,EAAmB;AAAA,IAC7B,aAAa,sBAAA,EAAuB;AAAA,IACpC,YAAY,aAAA,EAAc;AAAA,IAC1B,MAAM,gBAAA;AAAiB,GACzB;AACF;AAGA,IAAO,aAAA,GAAQ;AAAA,EACb,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF","file":"index.js","sourcesContent":["import { platform, arch } from 'node:os';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\n\n/**\n * Supported platform identifiers\n */\nexport type Platform =\n | 'darwin-arm64'\n | 'darwin-x86_64'\n | 'linux-arm64'\n | 'linux-arm64-musl'\n | 'linux-x86_64'\n | 'linux-x86_64-musl'\n | 'win32-x86_64';\n\n/**\n * Binary extension for each platform\n */\nexport const PLATFORM_EXTENSIONS: Record<string, string> = {\n darwin: '.dylib',\n linux: '.so',\n win32: '.dll',\n} as const;\n\n/**\n * Detects if the system uses musl libc (Alpine Linux, etc.)\n * Uses multiple detection strategies for reliability\n */\nexport function isMusl(): boolean {\n // Only relevant for Linux\n if (platform() !== 'linux') {\n return false;\n }\n\n // Strategy 1: Check for musl-specific files\n const muslFiles = [\n '/lib/ld-musl-x86_64.so.1',\n '/lib/ld-musl-aarch64.so.1',\n '/lib/ld-musl-armhf.so.1',\n ];\n\n for (const file of muslFiles) {\n if (existsSync(file)) {\n return true;\n }\n }\n\n // Strategy 2: Check ldd version output\n try {\n const lddVersion = execSync('ldd --version 2>&1', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n if (lddVersion.includes('musl')) {\n return true;\n }\n } catch {\n // ldd command failed, continue to next strategy\n }\n\n // Strategy 3: Check /etc/os-release for Alpine\n try {\n if (existsSync('/etc/os-release')) {\n const osRelease = readFileSync('/etc/os-release', 'utf-8');\n if (osRelease.includes('Alpine') || osRelease.includes('musl')) {\n return true;\n }\n }\n } catch {\n // File read failed, continue to next strategy\n }\n\n // Strategy 4: Check process.report.getReport() for musl\n try {\n const report = (process as any).report?.getReport?.();\n if (report?.header?.glibcVersionRuntime === '') {\n // Empty glibc version often indicates musl\n return true;\n }\n } catch {\n // Report not available\n }\n\n return false;\n}\n\n/**\n * Gets the current platform identifier\n * @throws {Error} If the platform is unsupported\n */\nexport function getCurrentPlatform(): Platform {\n const platformName = platform();\n const archName = arch();\n\n // macOS\n if (platformName === 'darwin') {\n if (archName === 'arm64') return 'darwin-arm64';\n if (archName === 'x64' || archName === 'ia32') return 'darwin-x86_64';\n }\n\n // Linux (with musl detection)\n if (platformName === 'linux') {\n const muslSuffix = isMusl() ? '-musl' : '';\n\n if (archName === 'arm64') {\n return `linux-arm64${muslSuffix}` as Platform;\n }\n if (archName === 'x64' || archName === 'ia32') {\n return `linux-x86_64${muslSuffix}` as Platform;\n }\n }\n\n // Windows\n if (platformName === 'win32') {\n if (archName === 'x64' || archName === 'ia32') return 'win32-x86_64';\n }\n\n // Unsupported platform\n throw new Error(\n `Unsupported platform: ${platformName}-${archName}. ` +\n `Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 ` +\n `(with glibc or musl support for Linux)`\n );\n}\n\n/**\n * Gets the package name for the current platform\n */\nexport function getPlatformPackageName(): string {\n const currentPlatform = getCurrentPlatform();\n return `@sqliteai/sqlite-sync-${currentPlatform}`;\n}\n\n/**\n * Gets the binary filename for the current platform\n */\nexport function getBinaryName(): string {\n const platformName = platform();\n const extension = PLATFORM_EXTENSIONS[platformName];\n\n if (!extension) {\n throw new Error(`Unknown platform: ${platformName}`);\n }\n\n return `cloudsync${extension}`;\n}\n","import { resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport {\n getCurrentPlatform,\n getPlatformPackageName,\n getBinaryName,\n type Platform\n} from './platform.js';\n\n/**\n * Error thrown when the SQLite Sync extension cannot be found\n */\nexport class ExtensionNotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ExtensionNotFoundError';\n }\n}\n\n/**\n * Attempts to load the platform-specific package\n * @returns The path to the extension binary, or null if not found\n */\nfunction tryLoadPlatformPackage(): string | null {\n try {\n const packageName = getPlatformPackageName();\n\n // Try to dynamically import the platform package\n // This works in both CommonJS and ESM\n const platformPackage = require(packageName);\n\n if (platformPackage?.path && typeof platformPackage.path === 'string') {\n if (existsSync(platformPackage.path)) {\n return platformPackage.path;\n }\n }\n } catch (error) {\n // Platform package not installed or failed to load\n // This is expected when optionalDependencies fail\n }\n\n return null;\n}\n\n/**\n * Gets the absolute path to the SQLite Sync extension binary for the current platform\n *\n * @returns Absolute path to the extension binary (.so, .dylib, or .dll)\n * @throws {ExtensionNotFoundError} If the extension binary cannot be found\n *\n * @example\n * ```typescript\n * import { getExtensionPath } from '@sqliteai/sqlite-sync';\n *\n * const extensionPath = getExtensionPath();\n * // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-sync-darwin-arm64/cloudsync.dylib\n * ```\n */\nexport function getExtensionPath(): string {\n // Try to load from platform-specific package\n const platformPath = tryLoadPlatformPackage();\n if (platformPath) {\n return resolve(platformPath);\n }\n\n // If we reach here, the platform package wasn't installed\n const currentPlatform = getCurrentPlatform();\n const packageName = getPlatformPackageName();\n\n throw new ExtensionNotFoundError(\n `SQLite Sync extension not found for platform: ${currentPlatform}\\n\\n` +\n `The platform-specific package \"${packageName}\" is not installed.\\n` +\n `This usually happens when:\\n` +\n ` 1. Your platform is not supported\\n` +\n ` 2. npm failed to install optional dependencies\\n` +\n ` 3. You're installing with --no-optional flag\\n\\n` +\n `Try running: npm install --force`\n );\n}\n\n/**\n * Information about the current platform and extension\n */\nexport interface ExtensionInfo {\n /** Current platform identifier (e.g., 'darwin-arm64') */\n platform: Platform;\n /** Name of the platform-specific npm package */\n packageName: string;\n /** Filename of the binary (e.g., 'cloudsync.dylib') */\n binaryName: string;\n /** Full path to the extension binary */\n path: string;\n}\n\n/**\n * Gets detailed information about the SQLite Sync extension\n *\n * @returns Extension information object\n *\n * @example\n * ```typescript\n * import { getExtensionInfo } from '@sqliteai/sqlite-sync';\n *\n * const info = getExtensionInfo();\n * console.log(info);\n * // {\n * // platform: 'darwin-arm64',\n * // packageName: '@sqliteai/sqlite-sync-darwin-arm64',\n * // binaryName: 'cloudsync.dylib',\n * // path: '/path/to/cloudsync.dylib'\n * // }\n * ```\n */\nexport function getExtensionInfo(): ExtensionInfo {\n return {\n platform: getCurrentPlatform(),\n packageName: getPlatformPackageName(),\n binaryName: getBinaryName(),\n path: getExtensionPath(),\n };\n}\n\n// Default export for CommonJS compatibility\nexport default {\n getExtensionPath,\n getExtensionInfo,\n ExtensionNotFoundError,\n};\n\n// Re-export platform utilities\nexport { getCurrentPlatform, getPlatformPackageName, getBinaryName, isMusl } from './platform.js';\nexport type { Platform } from './platform.js';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/platform.ts","../src/index.ts"],"names":["platform","existsSync","execSync","readFileSync","arch","require","createRequire","resolve"],"mappings":";;;;;;;;;;;;AAmBO,IAAM,mBAAA,GAA8C;AAAA,EACzD,MAAA,EAAQ,QAAA;AAAA,EACR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A;AAAA,EAC7B;AAGA,EAAA,MAAM,kBAAkB,kBAAA,EAAmB;AAC3C,EAAA,MAAM,cAAc,sBAAA,EAAuB;AAE3C,EAAA,MAAM,IAAI,sBAAA;AAAA,IACR,iDAAiD,eAAe;;AAAA,+BAAA,EAC9B,WAAW,CAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,gCAAA;AAAA,GAM/C;AACF;AAmCO,SAAS,gBAAA,GAAkC;AAChD,EAAA,OAAO;AAAA,IACL,UAAU,kBAAA,EAAmB;AAAA,IAC7B,aAAa,sBAAA,EAAuB;AAAA,IACpC,YAAY,aAAA,EAAc;AAAA,IAC1B,MAAM,gBAAA;AAAiB,GACzB;AACF;AAGA,IAAO,aAAA,GAAQ;AAAA,EACb,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF","file":"index.js","sourcesContent":["import { platform, arch } from 'node:os';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\n\n/**\n * Supported platform identifiers\n */\nexport type Platform =\n | 'darwin-arm64'\n | 'darwin-x86_64'\n | 'linux-arm64'\n | 'linux-arm64-musl'\n | 'linux-x86_64'\n | 'linux-x86_64-musl'\n | 'win32-x86_64';\n\n/**\n * Binary extension for each platform\n */\nexport const PLATFORM_EXTENSIONS: Record<string, string> = {\n darwin: '.dylib',\n linux: '.so',\n win32: '.dll',\n} as const;\n\n/**\n * Detects if the system uses musl libc (Alpine Linux, etc.)\n * Uses multiple detection strategies for reliability\n */\nexport function isMusl(): boolean {\n // Only relevant for Linux\n if (platform() !== 'linux') {\n return false;\n }\n\n // Strategy 1: Check for musl-specific files\n const muslFiles = [\n '/lib/ld-musl-x86_64.so.1',\n '/lib/ld-musl-aarch64.so.1',\n '/lib/ld-musl-armhf.so.1',\n ];\n\n for (const file of muslFiles) {\n if (existsSync(file)) {\n return true;\n }\n }\n\n // Strategy 2: Check ldd version output\n try {\n const lddVersion = execSync('ldd --version 2>&1', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n if (lddVersion.includes('musl')) {\n return true;\n }\n } catch {\n // ldd command failed, continue to next strategy\n }\n\n // Strategy 3: Check /etc/os-release for Alpine\n try {\n if (existsSync('/etc/os-release')) {\n const osRelease = readFileSync('/etc/os-release', 'utf-8');\n if (osRelease.includes('Alpine') || osRelease.includes('musl')) {\n return true;\n }\n }\n } catch {\n // File read failed, continue to next strategy\n }\n\n // Strategy 4: Check process.report.getReport() for musl\n try {\n const report = (process as any).report?.getReport?.();\n if (report?.header?.glibcVersionRuntime === '') {\n // Empty glibc version often indicates musl\n return true;\n }\n } catch {\n // Report not available\n }\n\n return false;\n}\n\n/**\n * Gets the current platform identifier\n * @throws {Error} If the platform is unsupported\n */\nexport function getCurrentPlatform(): Platform {\n const platformName = platform();\n const archName = arch();\n\n // macOS\n if (platformName === 'darwin') {\n if (archName === 'arm64') return 'darwin-arm64';\n if (archName === 'x64' || archName === 'ia32') return 'darwin-x86_64';\n }\n\n // Linux (with musl detection)\n if (platformName === 'linux') {\n const muslSuffix = isMusl() ? '-musl' : '';\n\n if (archName === 'arm64') {\n return `linux-arm64${muslSuffix}` as Platform;\n }\n if (archName === 'x64' || archName === 'ia32') {\n return `linux-x86_64${muslSuffix}` as Platform;\n }\n }\n\n // Windows\n if (platformName === 'win32') {\n if (archName === 'x64' || archName === 'ia32') return 'win32-x86_64';\n }\n\n // Unsupported platform\n throw new Error(\n `Unsupported platform: ${platformName}-${archName}. ` +\n `Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 ` +\n `(with glibc or musl support for Linux)`\n );\n}\n\n/**\n * Gets the package name for the current platform\n */\nexport function getPlatformPackageName(): string {\n const currentPlatform = getCurrentPlatform();\n return `@sqliteai/sqlite-sync-${currentPlatform}`;\n}\n\n/**\n * Gets the binary filename for the current platform\n */\nexport function getBinaryName(): string {\n const platformName = platform();\n const extension = PLATFORM_EXTENSIONS[platformName];\n\n if (!extension) {\n throw new Error(`Unknown platform: ${platformName}`);\n }\n\n return `cloudsync${extension}`;\n}\n","import { resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport {\n getCurrentPlatform,\n getPlatformPackageName,\n getBinaryName,\n type Platform\n} from './platform.js';\n\n// Create a require function that works in both CommonJS and ESM\nconst require = createRequire(import.meta.url);\n\n/**\n * Error thrown when the SQLite Sync extension cannot be found\n */\nexport class ExtensionNotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ExtensionNotFoundError';\n }\n}\n\n/**\n * Attempts to load the platform-specific package\n * @returns The path to the extension binary, or null if not found\n */\nfunction tryLoadPlatformPackage(): string | null {\n try {\n const packageName = getPlatformPackageName();\n\n const platformPackage = require(packageName);\n\n if (platformPackage?.path && typeof platformPackage.path === 'string') {\n if (existsSync(platformPackage.path)) {\n return platformPackage.path;\n }\n }\n } catch (error) {\n // Platform package not installed or failed to load\n // This is expected when optionalDependencies fail\n }\n\n return null;\n}\n\n/**\n * Gets the absolute path to the SQLite Sync extension binary for the current platform\n *\n * @returns Absolute path to the extension binary (.so, .dylib, or .dll)\n * @throws {ExtensionNotFoundError} If the extension binary cannot be found\n *\n * @example\n * ```typescript\n * import { getExtensionPath } from '@sqliteai/sqlite-sync';\n *\n * const extensionPath = getExtensionPath();\n * // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-sync-darwin-arm64/cloudsync.dylib\n * ```\n */\nexport function getExtensionPath(): string {\n // Try to load from platform-specific package\n const platformPath = tryLoadPlatformPackage();\n if (platformPath) {\n return resolve(platformPath);\n }\n\n // If we reach here, the platform package wasn't installed\n const currentPlatform = getCurrentPlatform();\n const packageName = getPlatformPackageName();\n\n throw new ExtensionNotFoundError(\n `SQLite Sync extension not found for platform: ${currentPlatform}\\n\\n` +\n `The platform-specific package \"${packageName}\" is not installed.\\n` +\n `This usually happens when:\\n` +\n ` 1. Your platform is not supported\\n` +\n ` 2. npm failed to install optional dependencies\\n` +\n ` 3. You're installing with --no-optional flag\\n\\n` +\n `Try running: npm install --force`\n );\n}\n\n/**\n * Information about the current platform and extension\n */\nexport interface ExtensionInfo {\n /** Current platform identifier (e.g., 'darwin-arm64') */\n platform: Platform;\n /** Name of the platform-specific npm package */\n packageName: string;\n /** Filename of the binary (e.g., 'cloudsync.dylib') */\n binaryName: string;\n /** Full path to the extension binary */\n path: string;\n}\n\n/**\n * Gets detailed information about the SQLite Sync extension\n *\n * @returns Extension information object\n *\n * @example\n * ```typescript\n * import { getExtensionInfo } from '@sqliteai/sqlite-sync';\n *\n * const info = getExtensionInfo();\n * console.log(info);\n * // {\n * // platform: 'darwin-arm64',\n * // packageName: '@sqliteai/sqlite-sync-darwin-arm64',\n * // binaryName: 'cloudsync.dylib',\n * // path: '/path/to/cloudsync.dylib'\n * // }\n * ```\n */\nexport function getExtensionInfo(): ExtensionInfo {\n return {\n platform: getCurrentPlatform(),\n packageName: getPlatformPackageName(),\n binaryName: getBinaryName(),\n path: getExtensionPath(),\n };\n}\n\n// Default export for CommonJS compatibility\nexport default {\n getExtensionPath,\n getExtensionInfo,\n ExtensionNotFoundError,\n};\n\n// Re-export platform utilities\nexport { getCurrentPlatform, getPlatformPackageName, getBinaryName, isMusl } from './platform.js';\nexport type { Platform } from './platform.js';\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { createRequire } from 'module';
|
|
3
4
|
import { platform, arch } from 'os';
|
|
4
5
|
import { execSync } from 'child_process';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
8
|
-
}) : x)(function(x) {
|
|
9
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
10
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
11
|
-
});
|
|
7
|
+
// src/index.ts
|
|
12
8
|
var PLATFORM_EXTENSIONS = {
|
|
13
9
|
darwin: ".dylib",
|
|
14
10
|
linux: ".so",
|
|
@@ -94,6 +90,7 @@ function getBinaryName() {
|
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
// src/index.ts
|
|
93
|
+
var require2 = createRequire(import.meta.url);
|
|
97
94
|
var ExtensionNotFoundError = class extends Error {
|
|
98
95
|
constructor(message) {
|
|
99
96
|
super(message);
|
|
@@ -103,7 +100,7 @@ var ExtensionNotFoundError = class extends Error {
|
|
|
103
100
|
function tryLoadPlatformPackage() {
|
|
104
101
|
try {
|
|
105
102
|
const packageName = getPlatformPackageName();
|
|
106
|
-
const platformPackage =
|
|
103
|
+
const platformPackage = require2(packageName);
|
|
107
104
|
if ((platformPackage == null ? void 0 : platformPackage.path) && typeof platformPackage.path === "string") {
|
|
108
105
|
if (existsSync(platformPackage.path)) {
|
|
109
106
|
return platformPackage.path;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/platform.ts","../src/index.ts"],"names":["existsSync"],"mappings":";;;;;;;;;;;AAmBO,IAAM,mBAAA,GAA8C;AAAA,EACzD,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO,KAAA;AAAA,EACP,KAAA,EAAO;AACT,CAAA;AAMO,SAAS,MAAA,GAAkB;AA7BlC,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA+BE,EAAA,IAAI,QAAA,OAAe,OAAA,EAAS;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,0BAAA;AAAA,IACA,2BAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,QAAQ,SAAA,EAAW;AAC5B,IAAA,IAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACpB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,IAAI;AACF,IAAA,MAAM,UAAA,GAAa,SAAS,oB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Sync } from 'node:fs';\nimport { execSync } from 'node:child_process';\n\n/**\n * Supported platform identifiers\n */\nexport type Platform =\n | 'darwin-arm64'\n | 'darwin-x86_64'\n | 'linux-arm64'\n | 'linux-arm64-musl'\n | 'linux-x86_64'\n | 'linux-x86_64-musl'\n | 'win32-x86_64';\n\n/**\n * Binary extension for each platform\n */\nexport const PLATFORM_EXTENSIONS: Record<string, string> = {\n darwin: '.dylib',\n linux: '.so',\n win32: '.dll',\n} as const;\n\n/**\n * Detects if the system uses musl libc (Alpine Linux, etc.)\n * Uses multiple detection strategies for reliability\n */\nexport function isMusl(): boolean {\n // Only relevant for Linux\n if (platform() !== 'linux') {\n return false;\n }\n\n // Strategy 1: Check for musl-specific files\n const muslFiles = [\n '/lib/ld-musl-x86_64.so.1',\n '/lib/ld-musl-aarch64.so.1',\n '/lib/ld-musl-armhf.so.1',\n ];\n\n for (const file of muslFiles) {\n if (existsSync(file)) {\n return true;\n }\n }\n\n // Strategy 2: Check ldd version output\n try {\n const lddVersion = execSync('ldd --version 2>&1', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n if (lddVersion.includes('musl')) {\n return true;\n }\n } catch {\n // ldd command failed, continue to next strategy\n }\n\n // Strategy 3: Check /etc/os-release for Alpine\n try {\n if (existsSync('/etc/os-release')) {\n const osRelease = readFileSync('/etc/os-release', 'utf-8');\n if (osRelease.includes('Alpine') || osRelease.includes('musl')) {\n return true;\n }\n }\n } catch {\n // File read failed, continue to next strategy\n }\n\n // Strategy 4: Check process.report.getReport() for musl\n try {\n const report = (process as any).report?.getReport?.();\n if (report?.header?.glibcVersionRuntime === '') {\n // Empty glibc version often indicates musl\n return true;\n }\n } catch {\n // Report not available\n }\n\n return false;\n}\n\n/**\n * Gets the current platform identifier\n * @throws {Error} If the platform is unsupported\n */\nexport function getCurrentPlatform(): Platform {\n const platformName = platform();\n const archName = arch();\n\n // macOS\n if (platformName === 'darwin') {\n if (archName === 'arm64') return 'darwin-arm64';\n if (archName === 'x64' || archName === 'ia32') return 'darwin-x86_64';\n }\n\n // Linux (with musl detection)\n if (platformName === 'linux') {\n const muslSuffix = isMusl() ? '-musl' : '';\n\n if (archName === 'arm64') {\n return `linux-arm64${muslSuffix}` as Platform;\n }\n if (archName === 'x64' || archName === 'ia32') {\n return `linux-x86_64${muslSuffix}` as Platform;\n }\n }\n\n // Windows\n if (platformName === 'win32') {\n if (archName === 'x64' || archName === 'ia32') return 'win32-x86_64';\n }\n\n // Unsupported platform\n throw new Error(\n `Unsupported platform: ${platformName}-${archName}. ` +\n `Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 ` +\n `(with glibc or musl support for Linux)`\n );\n}\n\n/**\n * Gets the package name for the current platform\n */\nexport function getPlatformPackageName(): string {\n const currentPlatform = getCurrentPlatform();\n return `@sqliteai/sqlite-sync-${currentPlatform}`;\n}\n\n/**\n * Gets the binary filename for the current platform\n */\nexport function getBinaryName(): string {\n const platformName = platform();\n const extension = PLATFORM_EXTENSIONS[platformName];\n\n if (!extension) {\n throw new Error(`Unknown platform: ${platformName}`);\n }\n\n return `cloudsync${extension}`;\n}\n","import { resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport {\n getCurrentPlatform,\n getPlatformPackageName,\n getBinaryName,\n type Platform\n} from './platform.js';\n\n/**\n * Error thrown when the SQLite Sync extension cannot be found\n */\nexport class ExtensionNotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ExtensionNotFoundError';\n }\n}\n\n/**\n * Attempts to load the platform-specific package\n * @returns The path to the extension binary, or null if not found\n */\nfunction tryLoadPlatformPackage(): string | null {\n try {\n const packageName = getPlatformPackageName();\n\n // Try to dynamically import the platform package\n // This works in both CommonJS and ESM\n const platformPackage = require(packageName);\n\n if (platformPackage?.path && typeof platformPackage.path === 'string') {\n if (existsSync(platformPackage.path)) {\n return platformPackage.path;\n }\n }\n } catch (error) {\n // Platform package not installed or failed to load\n // This is expected when optionalDependencies fail\n }\n\n return null;\n}\n\n/**\n * Gets the absolute path to the SQLite Sync extension binary for the current platform\n *\n * @returns Absolute path to the extension binary (.so, .dylib, or .dll)\n * @throws {ExtensionNotFoundError} If the extension binary cannot be found\n *\n * @example\n * ```typescript\n * import { getExtensionPath } from '@sqliteai/sqlite-sync';\n *\n * const extensionPath = getExtensionPath();\n * // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-sync-darwin-arm64/cloudsync.dylib\n * ```\n */\nexport function getExtensionPath(): string {\n // Try to load from platform-specific package\n const platformPath = tryLoadPlatformPackage();\n if (platformPath) {\n return resolve(platformPath);\n }\n\n // If we reach here, the platform package wasn't installed\n const currentPlatform = getCurrentPlatform();\n const packageName = getPlatformPackageName();\n\n throw new ExtensionNotFoundError(\n `SQLite Sync extension not found for platform: ${currentPlatform}\\n\\n` +\n `The platform-specific package \"${packageName}\" is not installed.\\n` +\n `This usually happens when:\\n` +\n ` 1. Your platform is not supported\\n` +\n ` 2. npm failed to install optional dependencies\\n` +\n ` 3. You're installing with --no-optional flag\\n\\n` +\n `Try running: npm install --force`\n );\n}\n\n/**\n * Information about the current platform and extension\n */\nexport interface ExtensionInfo {\n /** Current platform identifier (e.g., 'darwin-arm64') */\n platform: Platform;\n /** Name of the platform-specific npm package */\n packageName: string;\n /** Filename of the binary (e.g., 'cloudsync.dylib') */\n binaryName: string;\n /** Full path to the extension binary */\n path: string;\n}\n\n/**\n * Gets detailed information about the SQLite Sync extension\n *\n * @returns Extension information object\n *\n * @example\n * ```typescript\n * import { getExtensionInfo } from '@sqliteai/sqlite-sync';\n *\n * const info = getExtensionInfo();\n * console.log(info);\n * // {\n * // platform: 'darwin-arm64',\n * // packageName: '@sqliteai/sqlite-sync-darwin-arm64',\n * // binaryName: 'cloudsync.dylib',\n * // path: '/path/to/cloudsync.dylib'\n * // }\n * ```\n */\nexport function getExtensionInfo(): ExtensionInfo {\n return {\n platform: getCurrentPlatform(),\n packageName: getPlatformPackageName(),\n binaryName: getBinaryName(),\n path: getExtensionPath(),\n };\n}\n\n// Default export for CommonJS compatibility\nexport default {\n getExtensionPath,\n getExtensionInfo,\n ExtensionNotFoundError,\n};\n\n// Re-export platform utilities\nexport { getCurrentPlatform, getPlatformPackageName, getBinaryName, isMusl } from './platform.js';\nexport type { Platform } from './platform.js';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/platform.ts","../src/index.ts"],"names":["require","existsSync"],"mappings":";;;;;;;AAmBO,IAAM,mBAAA,GAA8C;AAAA,EACzD,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO,KAAA;AAAA,EACP,KAAA,EAAO;AACT,CAAA;AAMO,SAAS,MAAA,GAAkB;AA7BlC,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AA+BE,EAAA,IAAI,QAAA,OAAe,OAAA,EAAS;AAC1B,IAAA,OAAO,KAAA;AAAA,EACT;AAGA,EAAA,MAAM,SAAA,GAAY;AAAA,IAChB,0BAAA;AAAA,IACA,2BAAA;AAAA,IACA;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,QAAQ,SAAA,EAAW;AAC5B,IAAA,IAAI,UAAA,CAAW,IAAI,CAAA,EAAG;AACpB,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,IAAI;AACF,IAAA,MAAM,UAAA,GAAa,SAAS,oBAAA,EAAsB;AAAA,MAChD,QAAA,EAAU,OAAA;AAAA,MACV,KAAA,EAAO,CAAC,MAAA,EAAQ,MAAA,EAAQ,MAAM;AAAA,KAC/B,CAAA;AAED,IAAA,IAAI,UAAA,CAAW,QAAA,CAAS,MAAM,CAAA,EAAG;AAC/B,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AAGA,EAAA,IAAI;AACF,IAAA,IAAI,UAAA,CAAW,iBAAiB,CAAA,EAAG;AACjC,MAAA,MAAM,SAAA,GAAY,YAAA,CAAa,iBAAA,EAAmB,OAAO,CAAA;AACzD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B,SAAS,QAAA,EAAU;AACrE,MAAA,IAAIC,UAAAA,CAAW,eAAA,CAAgB,IAAI,CAAA,EAAG;AACpC,QAAA,OAAO,eAAA,CAAgB,IAAA;AAAA,MACzB;AAAA,IACF;AAAA,EACF,SAAS,KAAA,EAAO;AAAA,EAGhB;AAEA,EAAA,OAAO,IAAA;AACT;AAgBO,SAAS,gBAAA,GAA2B;AAEzC,EAAA,MAAM,eAAe,sBAAA,EAAuB;AAC5C,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,OAAO,QAAQ,YAAY,CAAA;AAAA,EAC7B;AAGA,EAAA,MAAM,kBAAkB,kBAAA,EAAmB;AAC3C,EAAA,MAAM,cAAc,sBAAA,EAAuB;AAE3C,EAAA,MAAM,IAAI,sBAAA;AAAA,IACR,iDAAiD,eAAe;;AAAA,+BAAA,EAC9B,WAAW,CAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,gCAAA;AAAA,GAM/C;AACF;AAmCO,SAAS,gBAAA,GAAkC;AAChD,EAAA,OAAO;AAAA,IACL,UAAU,kBAAA,EAAmB;AAAA,IAC7B,aAAa,sBAAA,EAAuB;AAAA,IACpC,YAAY,aAAA,EAAc;AAAA,IAC1B,MAAM,gBAAA;AAAiB,GACzB;AACF;AAGA,IAAO,aAAA,GAAQ;AAAA,EACb,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF","file":"index.mjs","sourcesContent":["import { platform, arch } from 'node:os';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\n\n/**\n * Supported platform identifiers\n */\nexport type Platform =\n | 'darwin-arm64'\n | 'darwin-x86_64'\n | 'linux-arm64'\n | 'linux-arm64-musl'\n | 'linux-x86_64'\n | 'linux-x86_64-musl'\n | 'win32-x86_64';\n\n/**\n * Binary extension for each platform\n */\nexport const PLATFORM_EXTENSIONS: Record<string, string> = {\n darwin: '.dylib',\n linux: '.so',\n win32: '.dll',\n} as const;\n\n/**\n * Detects if the system uses musl libc (Alpine Linux, etc.)\n * Uses multiple detection strategies for reliability\n */\nexport function isMusl(): boolean {\n // Only relevant for Linux\n if (platform() !== 'linux') {\n return false;\n }\n\n // Strategy 1: Check for musl-specific files\n const muslFiles = [\n '/lib/ld-musl-x86_64.so.1',\n '/lib/ld-musl-aarch64.so.1',\n '/lib/ld-musl-armhf.so.1',\n ];\n\n for (const file of muslFiles) {\n if (existsSync(file)) {\n return true;\n }\n }\n\n // Strategy 2: Check ldd version output\n try {\n const lddVersion = execSync('ldd --version 2>&1', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n if (lddVersion.includes('musl')) {\n return true;\n }\n } catch {\n // ldd command failed, continue to next strategy\n }\n\n // Strategy 3: Check /etc/os-release for Alpine\n try {\n if (existsSync('/etc/os-release')) {\n const osRelease = readFileSync('/etc/os-release', 'utf-8');\n if (osRelease.includes('Alpine') || osRelease.includes('musl')) {\n return true;\n }\n }\n } catch {\n // File read failed, continue to next strategy\n }\n\n // Strategy 4: Check process.report.getReport() for musl\n try {\n const report = (process as any).report?.getReport?.();\n if (report?.header?.glibcVersionRuntime === '') {\n // Empty glibc version often indicates musl\n return true;\n }\n } catch {\n // Report not available\n }\n\n return false;\n}\n\n/**\n * Gets the current platform identifier\n * @throws {Error} If the platform is unsupported\n */\nexport function getCurrentPlatform(): Platform {\n const platformName = platform();\n const archName = arch();\n\n // macOS\n if (platformName === 'darwin') {\n if (archName === 'arm64') return 'darwin-arm64';\n if (archName === 'x64' || archName === 'ia32') return 'darwin-x86_64';\n }\n\n // Linux (with musl detection)\n if (platformName === 'linux') {\n const muslSuffix = isMusl() ? '-musl' : '';\n\n if (archName === 'arm64') {\n return `linux-arm64${muslSuffix}` as Platform;\n }\n if (archName === 'x64' || archName === 'ia32') {\n return `linux-x86_64${muslSuffix}` as Platform;\n }\n }\n\n // Windows\n if (platformName === 'win32') {\n if (archName === 'x64' || archName === 'ia32') return 'win32-x86_64';\n }\n\n // Unsupported platform\n throw new Error(\n `Unsupported platform: ${platformName}-${archName}. ` +\n `Supported platforms: darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64, win32-x86_64 ` +\n `(with glibc or musl support for Linux)`\n );\n}\n\n/**\n * Gets the package name for the current platform\n */\nexport function getPlatformPackageName(): string {\n const currentPlatform = getCurrentPlatform();\n return `@sqliteai/sqlite-sync-${currentPlatform}`;\n}\n\n/**\n * Gets the binary filename for the current platform\n */\nexport function getBinaryName(): string {\n const platformName = platform();\n const extension = PLATFORM_EXTENSIONS[platformName];\n\n if (!extension) {\n throw new Error(`Unknown platform: ${platformName}`);\n }\n\n return `cloudsync${extension}`;\n}\n","import { resolve } from 'node:path';\nimport { existsSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport {\n getCurrentPlatform,\n getPlatformPackageName,\n getBinaryName,\n type Platform\n} from './platform.js';\n\n// Create a require function that works in both CommonJS and ESM\nconst require = createRequire(import.meta.url);\n\n/**\n * Error thrown when the SQLite Sync extension cannot be found\n */\nexport class ExtensionNotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ExtensionNotFoundError';\n }\n}\n\n/**\n * Attempts to load the platform-specific package\n * @returns The path to the extension binary, or null if not found\n */\nfunction tryLoadPlatformPackage(): string | null {\n try {\n const packageName = getPlatformPackageName();\n\n const platformPackage = require(packageName);\n\n if (platformPackage?.path && typeof platformPackage.path === 'string') {\n if (existsSync(platformPackage.path)) {\n return platformPackage.path;\n }\n }\n } catch (error) {\n // Platform package not installed or failed to load\n // This is expected when optionalDependencies fail\n }\n\n return null;\n}\n\n/**\n * Gets the absolute path to the SQLite Sync extension binary for the current platform\n *\n * @returns Absolute path to the extension binary (.so, .dylib, or .dll)\n * @throws {ExtensionNotFoundError} If the extension binary cannot be found\n *\n * @example\n * ```typescript\n * import { getExtensionPath } from '@sqliteai/sqlite-sync';\n *\n * const extensionPath = getExtensionPath();\n * // On macOS ARM64: /path/to/node_modules/@sqliteai/sqlite-sync-darwin-arm64/cloudsync.dylib\n * ```\n */\nexport function getExtensionPath(): string {\n // Try to load from platform-specific package\n const platformPath = tryLoadPlatformPackage();\n if (platformPath) {\n return resolve(platformPath);\n }\n\n // If we reach here, the platform package wasn't installed\n const currentPlatform = getCurrentPlatform();\n const packageName = getPlatformPackageName();\n\n throw new ExtensionNotFoundError(\n `SQLite Sync extension not found for platform: ${currentPlatform}\\n\\n` +\n `The platform-specific package \"${packageName}\" is not installed.\\n` +\n `This usually happens when:\\n` +\n ` 1. Your platform is not supported\\n` +\n ` 2. npm failed to install optional dependencies\\n` +\n ` 3. You're installing with --no-optional flag\\n\\n` +\n `Try running: npm install --force`\n );\n}\n\n/**\n * Information about the current platform and extension\n */\nexport interface ExtensionInfo {\n /** Current platform identifier (e.g., 'darwin-arm64') */\n platform: Platform;\n /** Name of the platform-specific npm package */\n packageName: string;\n /** Filename of the binary (e.g., 'cloudsync.dylib') */\n binaryName: string;\n /** Full path to the extension binary */\n path: string;\n}\n\n/**\n * Gets detailed information about the SQLite Sync extension\n *\n * @returns Extension information object\n *\n * @example\n * ```typescript\n * import { getExtensionInfo } from '@sqliteai/sqlite-sync';\n *\n * const info = getExtensionInfo();\n * console.log(info);\n * // {\n * // platform: 'darwin-arm64',\n * // packageName: '@sqliteai/sqlite-sync-darwin-arm64',\n * // binaryName: 'cloudsync.dylib',\n * // path: '/path/to/cloudsync.dylib'\n * // }\n * ```\n */\nexport function getExtensionInfo(): ExtensionInfo {\n return {\n platform: getCurrentPlatform(),\n packageName: getPlatformPackageName(),\n binaryName: getBinaryName(),\n path: getExtensionPath(),\n };\n}\n\n// Default export for CommonJS compatibility\nexport default {\n getExtensionPath,\n getExtensionInfo,\n ExtensionNotFoundError,\n};\n\n// Re-export platform utilities\nexport { getCurrentPlatform, getPlatformPackageName, getBinaryName, isMusl } from './platform.js';\nexport type { Platform } from './platform.js';\n"]}
|
package/package.json
CHANGED