forge-sql-orm 1.0.11 → 1.0.13

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.
@@ -4,36 +4,47 @@ const path = require("path");
4
4
  const fs = require("fs");
5
5
  const os = require("os");
6
6
 
7
- // Get all command-line arguments except the first two (node and script path)
7
+ // Get CLI arguments (excluding "node" and script path)
8
8
  const args = process.argv.slice(2).join(" ");
9
9
 
10
- // Resolve the path to cli.ts
10
+ // Resolve the path to cli.ts (your TypeScript entry file)
11
11
  const cliPath = path.resolve(__dirname, "cli.js");
12
12
 
13
- // Determine the path to the local ts-node in node_modules/.bin
14
- let localTsNode = path.resolve(__dirname, "../node_modules/.bin/ts-node");
13
+ // Detect platform-specific `ts-node` binary paths
14
+ const localTsNode = path.resolve(__dirname, "../node_modules/.bin/ts-node") + (os.platform() === "win32" ? ".cmd" : "");
15
15
 
16
- // On Windows, the ts-node binary is named ts-node.cmd
17
- if (os.platform() === "win32") {
18
- localTsNode += ".cmd";
19
- }
20
-
21
- // Function to execute a shell command
16
+ // Function to run a command
22
17
  const runCommand = (cmd) => {
23
18
  try {
24
- // Execute the command with inherited stdio for proper CLI output
25
19
  execSync(cmd, { stdio: "inherit", shell: true });
26
- process.exit(0); // Exit successfully after execution
20
+ process.exit(0);
27
21
  } catch (e) {
28
22
  console.error("⚠️ Command execution failed:", e.message);
29
- process.exit(1); // Exit with an error code
23
+ process.exit(1);
30
24
  }
31
25
  };
32
26
 
33
- // If local ts-node exists, use it
27
+ // **1. Check if `ts-node` is globally installed**
28
+ const isGlobalTsNodeInstalled = (() => {
29
+ try {
30
+ execSync("ts-node --version", { stdio: "ignore" }); // Check if `ts-node` runs without error
31
+ return true;
32
+ } catch {
33
+ return false;
34
+ }
35
+ })();
36
+
37
+ if (isGlobalTsNodeInstalled) {
38
+ console.log("✅ Using global ts-node");
39
+ runCommand(`ts-node ${cliPath} ${args}`);
40
+ }
41
+
42
+ // **2. If not, check for local ts-node**
34
43
  if (fs.existsSync(localTsNode)) {
44
+ console.log("✅ Using local ts-node");
35
45
  runCommand(`"${localTsNode}" ${cliPath} ${args}`);
36
- } else {
37
- console.warn("⚠️ Local ts-node not found, trying npx ts-node...");
38
- runCommand(`npx ts-node ${cliPath} ${args}`);
39
46
  }
47
+
48
+ // **3. If neither found, fallback to npx**
49
+ console.warn("⚠️ Neither global nor local ts-node found, using npx...");
50
+ runCommand(`node -r ts-node/register ${cliPath} ${args}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-sql-orm",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Mikro-ORM integration for Forge-SQL in Atlassian Forge applications.",
5
5
  "main": "dist/ForgeSQLORM.js",
6
6
  "module": "dist/ForgeSQLORM.mjs",