Remove the plugin entry older releases wrote into opencode.json. The entry was the bare path ``.opencode/plugins/graphify.js``. OpenCode loads every file in ``.opencode/plugins/`` on its own, so the entry was never needed, and OpenCode 2 reads a bare path as an npm package name and
(opencode_dir: Path)
| 1954 | return False |
| 1955 | return f'"{_OPENCODE_PLUGIN_PATH.as_posix()}"' in raw |
| 1956 | def _drop_opencode_config_entry(opencode_dir: Path) -> bool: |
| 1957 | """Remove the plugin entry older releases wrote into opencode.json. |
| 1958 | |
| 1959 | The entry was the bare path ``.opencode/plugins/graphify.js``. OpenCode |
| 1960 | loads every file in ``.opencode/plugins/`` on its own, so the entry was |
| 1961 | never needed, and OpenCode 2 reads a bare path as an npm package name and |
| 1962 | fails to install it (#3732). Returns True when the config changed. |
| 1963 | """ |
| 1964 | config_file = opencode_dir / _OPENCODE_CONFIG_PATH.name |
| 1965 | entry = _OPENCODE_PLUGIN_PATH.as_posix() |
| 1966 | try: |
| 1967 | raw = config_file.read_text(encoding="utf-8") |
| 1968 | except (OSError, UnicodeDecodeError): |
| 1969 | return False |
| 1970 | try: |
| 1971 | config = json.loads(raw) |
| 1972 | except ValueError: |
| 1973 | # OpenCode accepts comments in this file, json does not. Rewriting it |
| 1974 | # would drop them, so say what to remove instead. |
| 1975 | if f'"{entry}"' in raw: |
| 1976 | print( |
| 1977 | f" {config_file} -> not plain JSON, left as is; " |
| 1978 | f'remove "{entry}" from its plugin list by hand' |
| 1979 | ) |
| 1980 | return False |
| 1981 | if not isinstance(config, dict): |
| 1982 | return False |
| 1983 | changed = False |
| 1984 | for key in ("plugin", "plugins"): |
| 1985 | plugins = config.get(key) |
| 1986 | if isinstance(plugins, list) and entry in plugins: |
| 1987 | config[key] = [p for p in plugins if p != entry] |
| 1988 | if not config[key]: |
| 1989 | config.pop(key) |
| 1990 | changed = True |
| 1991 | if changed: |
| 1992 | # ensure_ascii=False: keep the user's non-ASCII values readable. |
| 1993 | _write_text_atomic(config_file, json.dumps(config, indent=2, ensure_ascii=False)) |
| 1994 | return changed |
| 1995 | def _install_opencode_plugin(opencode_dir: Path) -> None: |
| 1996 | """Write graphify.js into <opencode_dir>/plugins/, where OpenCode discovers it. |
| 1997 |
no test coverage detected