@scriptdb/vm 1.0.0 → 1.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +10 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,18 +11,18 @@ class VM {
11
11
  ctx;
12
12
  registerModules;
13
13
  DATABASE_DIR = path.join(os.homedir(), ".scriptdb", "databases");
14
- PLUGIN_DIR = path.join(os.homedir(), ".scriptdb", "plugins");
15
- pkgPlugin = {};
14
+ SCRIPTDB_DIR = path.join(os.homedir(), ".scriptdb");
15
+ pkgScriptDB = {};
16
16
  constructor(options) {
17
17
  if (!fs.existsSync(this.DATABASE_DIR)) {
18
18
  fs.mkdirSync(this.DATABASE_DIR, { recursive: true });
19
19
  }
20
- if (!fs.existsSync(this.PLUGIN_DIR)) {
21
- fs.mkdirSync(this.PLUGIN_DIR, { recursive: true });
20
+ if (!fs.existsSync(this.SCRIPTDB_DIR)) {
21
+ fs.mkdirSync(this.SCRIPTDB_DIR, { recursive: true });
22
22
  }
23
- const pkgPath = path.join(this.PLUGIN_DIR, "package.json");
23
+ const pkgPath = path.join(this.SCRIPTDB_DIR, "package.json");
24
24
  if (fs.existsSync(pkgPath)) {
25
- this.pkgPlugin = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
25
+ this.pkgScriptDB = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
26
26
  }
27
27
  this.transpiler = new Bun.Transpiler({
28
28
  loader: options?.language || "ts"
@@ -67,10 +67,10 @@ class VM {
67
67
  throw err;
68
68
  }
69
69
  }
70
- const allowedPackages = Object.keys(this.pkgPlugin.dependencies || {});
70
+ const allowedPackages = Object.keys(this.pkgScriptDB.dependencies || {});
71
71
  if (allowedPackages.includes(specifier)) {
72
72
  try {
73
- const modulePath = path.join(this.PLUGIN_DIR, "node_modules", specifier);
73
+ const modulePath = path.join(this.SCRIPTDB_DIR, "node_modules", specifier);
74
74
  const actualModule = await import(modulePath);
75
75
  const exportNames = Object.keys(actualModule);
76
76
  return new vm.SyntheticModule(exportNames, function() {
@@ -79,7 +79,7 @@ class VM {
79
79
  });
80
80
  }, { identifier: specifier, context: referencingModule.context });
81
81
  } catch (err) {
82
- console.error(`Failed to load plugin module ${specifier}:`, err);
82
+ console.error(`Failed to load workspace module ${specifier}:`, err);
83
83
  throw err;
84
84
  }
85
85
  }
@@ -95,7 +95,7 @@ class VM {
95
95
  console: customConsole
96
96
  });
97
97
  const js = this.transpiler.transformSync(code);
98
- const mod = new vm.SourceTextModule(js, { context: this.ctx, identifier: path.join(this.PLUGIN_DIR, "virtual-entry.js") });
98
+ const mod = new vm.SourceTextModule(js, { context: this.ctx, identifier: path.join(this.SCRIPTDB_DIR, "virtual-entry.js") });
99
99
  await mod.link(this.moduleLinker.bind(this));
100
100
  await mod.evaluate();
101
101
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scriptdb/vm",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Virtual machine package for script database",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",