@ailuntz/minilink 0.9.8 → 0.9.9

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/package.json +1 -1
  2. package/src/install.mjs +8 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ailuntz/minilink",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "description": "Use your Codex profiles in the Desktop model menu.",
5
5
  "type": "module",
6
6
  "license": "MIT AND Apache-2.0",
package/src/install.mjs CHANGED
@@ -20,7 +20,7 @@ export function installation(root = installRoot()) {
20
20
 
21
21
  export function ensureInstalled({ state = installation(), source = sourceRoot, activate = installDesktop } = {}) {
22
22
  try {
23
- if (state?.source === source && JSON.parse(readFileSync(join(state.runtime, 'package.json'), 'utf8')).version === VERSION) return state;
23
+ if (state?.source === source && state.packageVersion === VERSION && JSON.parse(readFileSync(join(state.runtime, 'package.json'), 'utf8')).version === VERSION) return state;
24
24
  } catch {}
25
25
  return activate();
26
26
  }
@@ -89,7 +89,7 @@ function installLinux({ root = installRoot(), source = sourceRoot, home = codexH
89
89
  const wrapper = join(root, 'minilink');
90
90
  mkdirSync(root, { recursive: true, mode: 0o700 });
91
91
  atomicFile(wrapper, `#!/bin/sh\nif [ ! -f ${shellQuote(join(source, 'package.json'))} ]; then exec ${shellQuote(native)} "$@"; fi\nexport CODEX_HOME=${shellQuote(home)}\nexport MINILINK_CONFIG=${shellQuote(config)}\nexec ${shellQuote(node)} ${shellQuote(join(source, 'bin/minilink.mjs'))} "$@"\n`, 0o755);
92
- const state = { version: 3, platform: 'linux', source, runtime: source, wrapper, node, codexHome: home, configPath: config, installedAt: new Date().toISOString() };
92
+ const state = { version: 3, platform: 'linux', packageVersion: VERSION, source, runtime: source, wrapper, node, codexHome: home, configPath: config, installedAt: new Date().toISOString() };
93
93
  atomicJSON(join(root, 'installation.json'), state);
94
94
  return state;
95
95
  }
@@ -107,20 +107,20 @@ function syncWindows({ state = installation(), enabled } = {}) {
107
107
  if (enabled == null) enabled = readConfig(state.configPath).enabled;
108
108
  const current = windowsEnvironment();
109
109
  if (enabled) {
110
- if (current && current !== state.wrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
111
- if (!current) setWindowsEnvironment(state.wrapper);
110
+ if (current && current !== state.wrapper && current !== state.previousWrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
111
+ if (current !== state.wrapper) setWindowsEnvironment(state.wrapper);
112
112
  } else if (current === state.wrapper) setWindowsEnvironment(state.previousEnv || null);
113
113
  }
114
114
 
115
115
  function installWindows({ root = installRoot(), source = sourceRoot, home = codexHome(), config = configPath(), node = process.execPath } = {}) {
116
116
  const native = resolveRealCodex(join(source, 'bin/minilink.mjs'));
117
- const previous = installation(root), wrapper = join(root, 'MiniLinkLauncher.exe');
117
+ const previous = installation(root), wrapper = join(root, `MiniLinkLauncher-${VERSION}.exe`);
118
118
  const current = windowsEnvironment();
119
- if (current && current !== wrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
119
+ if (current && current !== wrapper && current !== previous?.wrapper) throw new Error('CODEX_CLI_PATH 已指向其他程序。');
120
120
  mkdirSync(root, { recursive: true, mode: 0o700 });
121
121
  if (!existsSync(wrapper)) powershell(`Add-Type -Path ${psQuote(join(source, 'src/platform/windows/MiniLinkLauncher.cs'))} -OutputAssembly ${psQuote(wrapper)} -OutputType ConsoleApplication`);
122
122
  atomicFile(join(root, 'launcher.paths'), [node, join(source, 'bin/minilink.mjs'), native, home, config].join('\n') + '\n', 0o600);
123
- const state = { version: 3, platform: 'win32', source, runtime: source, wrapper, node, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || null, installedAt: new Date().toISOString() };
123
+ const state = { version: 3, platform: 'win32', packageVersion: VERSION, source, runtime: source, wrapper, node, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || null, previousWrapper: current === previous?.wrapper ? current : null, installedAt: new Date().toISOString() };
124
124
  atomicJSON(join(root, 'installation.json'), state);
125
125
  return state;
126
126
  }
@@ -161,7 +161,7 @@ export function install({ root = installRoot(), plist = defaultPlist(), source =
161
161
  }
162
162
  if (JSON.parse(readFileSync(join(dependency, 'package.json'), 'utf8')).name !== 'smol-toml') throw new Error('smol-toml 依赖路径无效。');
163
163
  cpSync(dependency, join(runtime, 'node_modules/smol-toml'), { recursive: true });
164
- const state = { version: 2, source, runtime, wrapper, node, npm: packageManager.npm || previous?.npm, prefix: packageManager.prefix || previous?.prefix, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || legacy?.state.previousEnv || null, installedAt: new Date().toISOString() };
164
+ const state = { version: 2, packageVersion: VERSION, source, runtime, wrapper, node, npm: packageManager.npm || previous?.npm, prefix: packageManager.prefix || previous?.prefix, codexHome: home, configPath: config, previousEnv: previous?.previousEnv || legacy?.state.previousEnv || null, installedAt: new Date().toISOString() };
165
165
  // A Desktop process can retain this launcher after npm removes the state.
166
166
  const fallback = `if [ ! -f ${shellQuote(stateFile)} ]; then\n exec "\${CODEX_DESKTOP_APP:-/Applications/ChatGPT.app}/${bundledCodexRelativePath}" "$@"\nfi`;
167
167
  atomicFile(wrapper, `#!/bin/sh\n${fallback}\nexport CODEX_HOME=${shellQuote(home)}\nexport MINILINK_CONFIG=${shellQuote(config)}\nexec ${shellQuote(node)} ${shellQuote(join(runtime, 'bin/minilink.mjs'))} "$@"\n`, 0o755);