ima2-gen 1.0.9 → 1.0.10

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.
@@ -1,6 +1,6 @@
1
1
  import { mkdir, readdir, copyFile, stat } from "node:fs/promises";
2
2
  import { existsSync } from "node:fs";
3
- import { dirname, join, resolve, sep } from "node:path";
3
+ import { dirname, isAbsolute, join, resolve, sep } from "node:path";
4
4
  import { homedir } from "node:os";
5
5
 
6
6
  const PACKAGE_NAME = "ima2-gen";
@@ -76,16 +76,44 @@ export async function migrateGeneratedStorage(ctx, options = {}) {
76
76
  }
77
77
 
78
78
  export function getLegacyGeneratedCandidates(ctx, env = process.env) {
79
- const home = homedir();
80
- const nodePrefix = dirname(dirname(process.execPath));
81
- const npmPrefix = env.npm_config_prefix || nodePrefix;
79
+ const home = env.IMA2_TEST_HOME || homedir();
80
+ const execPath = env.IMA2_TEST_EXEC_PATH || process.execPath;
81
+ const argv1 = env.IMA2_TEST_ARGV1 || process.argv[1] || "";
82
+ const nodePrefix = dirname(dirname(execPath));
83
+ const prefixes = getGlobalPrefixCandidates({ env, execPath, argv1 });
82
84
  const appData = env.APPDATA || join(home, "AppData", "Roaming");
83
- return Array.from(new Set([
85
+
86
+ const candidates = [
84
87
  join(ctx.rootDir, "generated"),
85
- join(npmPrefix, "lib", "node_modules", PACKAGE_NAME, "generated"),
86
- join(npmPrefix, "node_modules", PACKAGE_NAME, "generated"),
87
88
  join(appData, "npm", "node_modules", PACKAGE_NAME, "generated"),
88
89
  join(home, ".npm-global", "lib", "node_modules", PACKAGE_NAME, "generated"),
89
90
  join(home, ".nvm", "versions", "node", process.version, "lib", "node_modules", PACKAGE_NAME, "generated"),
90
- ].map((p) => resolve(p))));
91
+ join(home, ".volta", "tools", "image", "packages", PACKAGE_NAME, "lib", "node_modules", PACKAGE_NAME, "generated"),
92
+ join(home, ".fnm", "node-versions", process.version, "installation", "lib", "node_modules", PACKAGE_NAME, "generated"),
93
+ ];
94
+
95
+ for (const prefix of prefixes) {
96
+ candidates.push(join(prefix, "lib", "node_modules", PACKAGE_NAME, "generated"));
97
+ candidates.push(join(prefix, "node_modules", PACKAGE_NAME, "generated"));
98
+ }
99
+
100
+ candidates.push(join(nodePrefix, "lib", "node_modules", PACKAGE_NAME, "generated"));
101
+ return Array.from(new Set(candidates.map((p) => resolve(p))));
102
+ }
103
+
104
+ function getGlobalPrefixCandidates({ env, execPath, argv1 }) {
105
+ const prefixes = new Set();
106
+ if (env.npm_config_prefix) prefixes.add(env.npm_config_prefix);
107
+ if (isAbsolute(argv1)) prefixes.add(dirname(dirname(argv1)));
108
+ prefixes.add(dirname(dirname(execPath)));
109
+ addHomebrewPrefix(prefixes, execPath);
110
+ prefixes.add("/opt/homebrew");
111
+ prefixes.add("/usr/local");
112
+ return Array.from(prefixes);
113
+ }
114
+
115
+ function addHomebrewPrefix(prefixes, execPath) {
116
+ const marker = `${sep}Cellar${sep}node`;
117
+ const idx = execPath.indexOf(marker);
118
+ if (idx > 0) prefixes.add(execPath.slice(0, idx));
91
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ima2-gen",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "GPT Image 2 generator with OAuth & API key support",
5
5
  "type": "module",
6
6
  "bin": {