@tasker-systems/tasker 0.1.2 → 0.1.3

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 CHANGED
@@ -1,8 +1,9 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
2
  import pino from 'pino';
3
3
  import { existsSync } from 'fs';
4
+ import { dirname, join } from 'path';
5
+ import { fileURLToPath } from 'url';
4
6
  import { readdir } from 'fs/promises';
5
- import { join } from 'path';
6
7
 
7
8
  var __create = Object.create;
8
9
  var __defProp = Object.defineProperty;
@@ -521,8 +522,8 @@ var require_koffi19 = __commonJS2({
521
522
  data = data.subarray(0, header.size);
522
523
  if (header.type == "0" || header.type == "7") {
523
524
  let filename3 = dest_dir + "/" + header.filename;
524
- let dirname = path2.dirname(filename3);
525
- fs2.mkdirSync(dirname, { recursive: true, mode: 493 });
525
+ let dirname2 = path2.dirname(filename3);
526
+ fs2.mkdirSync(dirname2, { recursive: true, mode: 493 });
526
527
  fs2.writeFileSync(filename3, data, { mode: header.mode });
527
528
  } else if (header.type == "5") {
528
529
  let filename3 = dest_dir + "/" + header.filename;
@@ -4048,7 +4049,10 @@ var FfiLayer = class _FfiLayer {
4048
4049
  const path2 = customPath ?? this.configuredLibraryPath ?? this.discoverLibraryPath();
4049
4050
  if (!path2) {
4050
4051
  throw new Error(
4051
- "FFI library not found. TASKER_FFI_LIBRARY_PATH environment variable must be set to the path of the compiled library.\nExample: export TASKER_FFI_LIBRARY_PATH=/path/to/target/debug/libtasker_ts.dylib\nBuild the library with: cargo build -p tasker-ts"
4052
+ `FFI library not found. No bundled native library matches this platform, and TASKER_FFI_LIBRARY_PATH is not set.
4053
+ Current platform: ${process.platform}-${process.arch}
4054
+ Supported: linux-x64, linux-arm64, darwin-arm64
4055
+ Override: export TASKER_FFI_LIBRARY_PATH=/path/to/libtasker_ts.dylib`
4052
4056
  );
4053
4057
  }
4054
4058
  this.runtime = await this.createRuntime();
@@ -4102,23 +4106,27 @@ var FfiLayer = class _FfiLayer {
4102
4106
  * Static method for finding the library path without creating an instance.
4103
4107
  * Useful for test utilities and pre-flight checks.
4104
4108
  *
4105
- * REQUIRES: TASKER_FFI_LIBRARY_PATH environment variable to be set.
4106
- * This explicit requirement prevents confusion from automatic debug/release
4107
- * library discovery and ensures intentional configuration at build/runtime.
4109
+ * Resolution order:
4110
+ * 1. TASKER_FFI_LIBRARY_PATH environment variable (explicit override)
4111
+ * 2. Bundled native library in the package's native/ directory
4108
4112
  *
4109
4113
  * @param _callerDir Deprecated parameter, kept for API compatibility
4110
4114
  * @returns Path to the library if found and exists, null otherwise
4111
4115
  */
4112
4116
  static findLibraryPath(_callerDir) {
4113
4117
  const envPath = process.env.TASKER_FFI_LIBRARY_PATH;
4114
- if (!envPath) {
4115
- return null;
4118
+ if (envPath) {
4119
+ if (!existsSync(envPath)) {
4120
+ console.warn(`TASKER_FFI_LIBRARY_PATH is set to "${envPath}" but the file does not exist`);
4121
+ return null;
4122
+ }
4123
+ return envPath;
4116
4124
  }
4117
- if (!existsSync(envPath)) {
4118
- console.warn(`TASKER_FFI_LIBRARY_PATH is set to "${envPath}" but the file does not exist`);
4119
- return null;
4125
+ const bundledPath = findBundledNativeLibrary();
4126
+ if (bundledPath && existsSync(bundledPath)) {
4127
+ return bundledPath;
4120
4128
  }
4121
- return envPath;
4129
+ return null;
4122
4130
  }
4123
4131
  /**
4124
4132
  * Discover the FFI library path.
@@ -4154,6 +4162,21 @@ var FfiLayer = class _FfiLayer {
4154
4162
  }
4155
4163
  }
4156
4164
  };
4165
+ var BUNDLED_LIBRARIES = {
4166
+ "linux-x64": "libtasker_ts-linux-x64.so",
4167
+ "linux-arm64": "libtasker_ts-linux-arm64.so",
4168
+ "darwin-arm64": "libtasker_ts-darwin-arm64.dylib"
4169
+ };
4170
+ function findBundledNativeLibrary() {
4171
+ const key = `${process.platform}-${process.arch}`;
4172
+ const filename2 = BUNDLED_LIBRARIES[key];
4173
+ if (!filename2) {
4174
+ return null;
4175
+ }
4176
+ const thisDir = dirname(fileURLToPath(import.meta.url));
4177
+ const packageRoot = join(thisDir, "..", "..");
4178
+ return join(packageRoot, "native", filename2);
4179
+ }
4157
4180
 
4158
4181
  // src/ffi/index.ts
4159
4182
  init_node_runtime();