open-in-editor-bridge 0.2.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/README.md +103 -54
- data/lib/open_in_editor_bridge/docker.rb +172 -0
- data/lib/open_in_editor_bridge/version.rb +1 -1
- data/lib/open_in_editor_bridge/vite.mjs +79 -0
- data/lib/open_in_editor_bridge.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eaaf6a230a717d29cee22bd54955b4602c9fef5779499808bdc8732b379de7fc
|
|
4
|
+
data.tar.gz: 28e77df9eb6041a821ce65d784d30cb31cbd7a3a08c3e8f9e1695c8947a4d290
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 23f9ee5e974031a4b05bfa1a47d15f85eac1748265e829879fcc322926062268f52503e08295d2b1d4d9034b93262662c336e079dcb3247800ba1214cea932af
|
|
7
|
+
data.tar.gz: a441abf55c7ababc5061eaf7d9e8d2b5dec7497c623e478dd5fcd9f29f11919beaf9907c9d35f487a8f6a27bb8837a31b0c7d19949495f9dc14482ae960f84a8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0 — 2026-10-10
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Retained opt-in `rake test:docker` gate for real multi-checkout routing, editor invocation, configuration parity, and cleanup, including consumer Vite 5.4.20 / 8.0.9 and the prior 6.0.0 reference.
|
|
8
|
+
- The same runtime gate can exercise a clean installed gem via `OPEN_IN_EDITOR_BRIDGE_TEST_LIB`.
|
|
9
|
+
- Explicit public/internal API boundaries and evidence-based versioning/1.0 promotion policy.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `up --wait` / `--wait=true` now retain detached editor registration after services become ready, rather than stopping the broker while containers remain running.
|
|
14
|
+
- Compose's native canonical configuration replaces handwritten file discovery, honoring `.env` / `--env-file` / `COMPOSE_FILE` and preserving project identity, paths, profiles, interpolation, and literal dollar values.
|
|
15
|
+
- Invalid Compose configuration fails before acquiring a broker lease.
|
|
16
|
+
|
|
17
|
+
### Compatibility
|
|
18
|
+
|
|
19
|
+
- Docker startup requires Compose's `config --format json` and `config --environment` capabilities. Broker protocol, explicit network exposure, host-only control credentials, and existing Ruby lifecycle APIs are unchanged.
|
|
20
|
+
- This is a development minor release, not an API freeze. Prefer `~> 0.4.0` for the tested release line.
|
|
21
|
+
|
|
22
|
+
## 0.3.0 — 2026-10-09
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- `OpenInEditorBridge.compose` for library-owned Docker/Vite integration: generated service overrides mount a bundled Vite plugin and checkout identity, without session environment/query plumbing in applications.
|
|
27
|
+
- Development-only Vite plugin that routes editor requests to the mounted checkout, replacing duplicate caller selectors while preserving encoded file paths and line/column.
|
|
28
|
+
- Minimal adoption instructions and an ELCC migration path for removing its bespoke session transport.
|
|
29
|
+
|
|
30
|
+
### Security and Lifecycle
|
|
31
|
+
|
|
32
|
+
- Docker startup still requires explicit network-exposure opt-in. Only non-secret identity/target data and plugin code are mounted read-only; lifecycle credentials stay on the host.
|
|
33
|
+
- Missing/malformed Vite identity fails startup safely; only the editor endpoint is proxied.
|
|
34
|
+
- Foreground cleanup and idempotent detached registration reuse the existing lease protocol. Failed startup releases only a new registration, and failed shutdown retains the active registration.
|
|
35
|
+
- Unrelated Compose commands and production Vite builds do not require editor setup.
|
|
36
|
+
|
|
3
37
|
## 0.2.0 — 2026-10-09
|
|
4
38
|
|
|
5
39
|
### Added
|
data/README.md
CHANGED
|
@@ -5,95 +5,104 @@ A Ruby gem that runs a shared local HTTP bridge for opening container files in t
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```ruby
|
|
8
|
-
gem "open-in-editor-bridge", "~> 0.
|
|
8
|
+
gem "open-in-editor-bridge", "~> 0.4.0"
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
gem install open-in-editor-bridge
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Docker and Vite Integration
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Use the host-side Compose adapter and the gem's mounted Vite plugin. The library owns checkout identity transport, the host-gateway entry, and the editor proxy; **do not export a session variable or write a request rewrite**.
|
|
18
|
+
|
|
19
|
+
Replace the development Compose startup/shutdown call:
|
|
18
20
|
|
|
19
21
|
```ruby
|
|
20
22
|
require "open_in_editor_bridge"
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
# Explicit network-exposure opt-in; use only on a trusted development network.
|
|
25
|
+
ENV["OPEN_IN_EDITOR_BRIDGE_BIND_ADDRESS"] = "0.0.0.0"
|
|
26
|
+
ENV["OPEN_IN_EDITOR_COMMAND"] = "code"
|
|
27
|
+
|
|
28
|
+
OpenInEditorBridge.compose("up", service: "web")
|
|
29
|
+
# Detached startup: OpenInEditorBridge.compose("up", "-d", service: "web")
|
|
30
|
+
# Shutdown: OpenInEditorBridge.compose("down", service: "web")
|
|
26
31
|
```
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
Add the plugin to your existing Vite configuration for Docker development:
|
|
29
34
|
|
|
30
|
-
|
|
35
|
+
```js
|
|
36
|
+
import { defineConfig } from "vite";
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
export default defineConfig(async ({ command, mode }) => {
|
|
39
|
+
const plugins = [];
|
|
40
|
+
if (command === "serve" && mode === "development") {
|
|
41
|
+
const integrationPath = "/open-in-editor-bridge/vite.mjs";
|
|
42
|
+
const { default: openInEditorBridge } = await import(integrationPath);
|
|
43
|
+
plugins.push(openInEditorBridge());
|
|
44
|
+
}
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
return { plugins, server: { host: "0.0.0.0" } };
|
|
47
|
+
});
|
|
48
|
+
```
|
|
35
49
|
|
|
36
|
-
|
|
37
|
-
require "open_in_editor_bridge"
|
|
50
|
+
Keep your application's existing plugins and other Vite settings. The variable-based dynamic import is intentional: production builds and test-mode configuration can load without Docker's development mounts. This path supports Docker-hosted Vite development; native-host Vite and custom development modes need their own explicit opt-in condition. The plugin requires a valid mounted manifest when enabled and fails startup if it is missing or malformed. The retained Docker gate covers the consumer versions Vite 5.4.20, 6.0.0, and 8.0.9.
|
|
38
51
|
|
|
39
|
-
|
|
40
|
-
ENV["OPEN_IN_EDITOR_SESSION_ID"] = OpenInEditorBridge.session_id
|
|
41
|
-
system("docker", "compose", "up", "-d", exception: true)
|
|
42
|
-
```
|
|
52
|
+
### Application Configuration That Remains
|
|
43
53
|
|
|
44
|
-
|
|
54
|
+
- Select the Vite service (`service: "web"` by default); retain its image, command, source mounts, ports, and normal environment.
|
|
55
|
+
- Select Compose files/project options when necessary, for example `compose_options: ["-f", "docker-compose.development.yaml", "-p", "my-checkout"]`. Pass subcommand options after `"up"` / `"down"`, not in `compose_options`.
|
|
56
|
+
- Select checkout/container/host roots and the editor through the existing bridge configuration below. `project_root:` defaults to the current checkout; `env:` supplies bridge configuration and child-process environment overrides.
|
|
57
|
+
- Explicitly select a Docker-reachable bind address. The adapter rejects loopback startup and never changes the default binding itself.
|
|
45
58
|
|
|
46
|
-
|
|
47
|
-
OpenInEditorBridge.with_running(ensure_running: false) do
|
|
48
|
-
system("docker", "compose", "down", exception: true)
|
|
49
|
-
end
|
|
50
|
-
```
|
|
59
|
+
Compose itself resolves the original project configuration before the adapter adds its mounts: default file discovery, `.env` / `--env-file`, `COMPOSE_FILE` / `COMPOSE_PATH_SEPARATOR`, explicit multi-file inputs, project name, source-relative paths, interpolation, and active profiles remain Compose-owned. The adapter reuses Compose's canonical JSON model in a private host-only temporary file, preserving Compose's literal-dollar escaping instead of merging the original sources a second time. `compose_options` retains other global options, and the original subcommand arguments still select services. Compose runs in `project_root:` and inherits normal process input/output. Failures raise; successful commands return `true`.
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
Only `up` adds editor setup. Foreground `up` owns an independent lease and releases it even on failure. `up -d` / `up --detach` and `up --wait` / `up --wait=true` use the existing idempotent detached registration: readiness-based startup returns while containers remain running, so the editor registration must remain too. Failed detached startup releases a newly acquired registration but preserves one that was already active. Successful `down` releases that checkout's detached registration; failed `down` keeps it. Other commands (`config`, `build`, `exec`, `run`, `logs`, and so on) execute ordinary Compose without editor setup or requiring an editor. `stop` does not release detached registration; use `down` or `--shutdown` when done. If a new container needs the editor mounts, create it through `up`.
|
|
53
62
|
|
|
54
|
-
|
|
63
|
+
The generated override mounts just two read-only files at `/open-in-editor-bridge`: the packaged `vite.mjs` and a checkout-specific `session.json` containing identity and target URL. It never mounts broker state, the whole private runtime directory, or lifecycle control credentials. Temporary Compose overrides are removed after each invocation; non-secret manifests remain in the private host runtime directory for existing detached containers.
|
|
55
64
|
|
|
56
|
-
|
|
65
|
+
All checkouts share the standard host port `3333`, bind address, and private runtime directory. Each may use the same container directory `/usr/src/web`: the plugin selects its own host checkout from its mounted identity. It replaces all caller-supplied `session` selectors, including duplicates and encoded selector names, without rewriting other query bytes. Only `/__open-in-editor` is proxied; health and lifecycle endpoints are not. Existing exact editor proxy entries are replaced, and editor routing takes precedence over broader application proxy entries.
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
export OPEN_IN_EDITOR_COMMAND='code'
|
|
60
|
-
# Explicit opt-in for Docker bridge-network access; read the security section.
|
|
61
|
-
export OPEN_IN_EDITOR_BRIDGE_BIND_ADDRESS=0.0.0.0
|
|
62
|
-
export OPEN_IN_EDITOR_SESSION_ID="$(open-in-editor-bridge --session-id)"
|
|
63
|
-
open-in-editor-bridge --ensure-running
|
|
64
|
-
docker compose up -d
|
|
67
|
+
### Adopting in ELCC
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
docker compose down
|
|
68
|
-
open-in-editor-bridge --shutdown
|
|
69
|
-
```
|
|
69
|
+
After installing 0.4.0, ELCC can replace the editor lifecycle/Compose `up` and `down` path in `bin/dev` with `OpenInEditorBridge.compose`, passing its existing development/gateway `-f` options, project name, host user/group variables, and gateway hostname. Keep gateway lifecycle ownership and pipe-input handling for unrelated commands unchanged.
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
Remove the `OPEN_IN_EDITOR_SESSION_ID` export from `dynamic_environment_variables`, its web-service pass-through in `docker-compose.development.yaml`, and the handwritten `/__open-in-editor` target/rewrite in `web/vite.config.js`. Add the mounted plugin to the existing Vue/Vuetify/gateway plugin list under the development-only condition above. The adapter supplies the host-gateway entry, so an editor-only `extra_hosts` entry is no longer necessary. Keep the explicit trusted-network bind opt-in and existing root/editor settings. No consumer files are changed automatically.
|
|
72
72
|
|
|
73
|
-
##
|
|
73
|
+
## Low-Level Ruby API
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
For non-Compose applications or custom integrations:
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
```ruby
|
|
78
|
+
require "open_in_editor_bridge"
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- "host.docker.internal:host-gateway"
|
|
84
|
-
environment:
|
|
85
|
-
OPEN_IN_EDITOR_SESSION_ID: "${OPEN_IN_EDITOR_SESSION_ID:?Set the host checkout session ID}"
|
|
80
|
+
OpenInEditorBridge.with_running do |session_id|
|
|
81
|
+
# A custom integration may use session_id to select this checkout.
|
|
82
|
+
system("./bin/app", exception: true)
|
|
83
|
+
end
|
|
86
84
|
```
|
|
87
85
|
|
|
88
|
-
The
|
|
86
|
+
The block returns its normal result. Its checkout lease is released in `ensure`, including when the block raises; cleanup does not replace the original exception. Overlapping wrappers have independent leases, even in the same checkout. Finishing one wrapper never releases another wrapper or an existing detached registration.
|
|
87
|
+
|
|
88
|
+
`OpenInEditorBridge.session_id` returns the stable ID without starting the bridge. `OpenInEditorBridge.new(env: ..., project_root: ...)` supports explicit configuration. `call("--ensure-running")` registers a detached checkout; `call("--shutdown")` releases it. Repeated registration is idempotent. `with_running(ensure_running: false)` runs its block without acquiring a lease and releases detached registration afterward. Do not wrap detached startup in a foreground lease.
|
|
89
|
+
|
|
90
|
+
## CLI and Session Protocol
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
Run lifecycle commands from the host checkout (or set `OPEN_IN_EDITOR_PROJECT_ROOT`):
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
open-in-editor-bridge --session-id
|
|
96
|
+
open-in-editor-bridge --ensure-running
|
|
97
|
+
# Later, with the same configuration:
|
|
98
|
+
open-in-editor-bridge --shutdown
|
|
92
99
|
```
|
|
93
100
|
|
|
94
|
-
|
|
101
|
+
The CLI is the low-level lifecycle interface, not a substitute for the Docker/Vite adapter. `--serve` runs a foreground broker and registers the current checkout; it requires a free port. Manually interrupting it stops all sessions. Prefer the managed API for sharing.
|
|
102
|
+
|
|
103
|
+
`GET /health` reports PID, protocol, bind address, and active checkout IDs. `GET /__open-in-editor?file=<encoded-target>&session=<checkout-id>` spawns that checkout's editor with `--goto <translated-target>`, preserving optional `:line:column`. Paths equal to or below `/usr/src/web` map to the host `web` directory; other paths pass through unchanged. Query encoding is decoded exactly once, preserving literal percent sequences in filenames.
|
|
95
104
|
|
|
96
|
-
With exactly one checkout,
|
|
105
|
+
Custom integrations may use the same session protocol. With exactly one checkout, links without `session` work. With multiple checkouts, missing identity returns HTTP 400 rather than guessing; unknown IDs return HTTP 404. Conflicting roots/editor settings for an active checkout are rejected. Foreground and detached leases are independent; the last released lease shuts down the listener.
|
|
97
106
|
|
|
98
107
|
## Configuration
|
|
99
108
|
|
|
@@ -120,12 +129,52 @@ A failed or timed-out health probe does not discard a still-listening broker's c
|
|
|
120
129
|
|
|
121
130
|
Version 0.2 replaces checkout-local PID/log files with shared runtime state. Stop any 0.1.x bridge using its original installed version before upgrading; it cannot share the new protocol. Sessions live in the broker's memory. After a broker crash or deliberate manual stop, rerun `--ensure-running` for detached applications. Abruptly killed foreground clients cannot execute `ensure`; stop that broker manually and re-register surviving checkouts if their leases become orphaned.
|
|
122
131
|
|
|
132
|
+
## Public Contract and Versioning
|
|
133
|
+
|
|
134
|
+
Supported entrypoints are the documented Ruby class methods `compose`, `with_running`, `call`, `session_id`, and `new(env:, project_root:)`; instance `call` / `session_id`; the CLI lifecycle commands; and the health/editor HTTP endpoints. Their documented routing, cleanup, configuration, and error semantics are the consumer contract. `StartupError` identifies broker startup/control failures; Compose process failures raise rather than return a false success.
|
|
135
|
+
|
|
136
|
+
`Configuration`, `Client`, `Server`, `Docker`, raw lease methods, control-request signing, runtime file layout, generated Compose inputs, and proxy implementation details are internal, even where Ruby permits direct access. Do not build a consumer on those details or put control credentials in containers. HTTP error text, status-log wording, checkout-ID derivation details, and temporary filenames are not compatibility interfaces.
|
|
137
|
+
|
|
138
|
+
This project follows [Semantic Versioning](https://semver.org/). **0.4.0 remains a development release, not a claim that the integration is frozen.** Use `~> 0.4.0` to stay within the tested minor release line; `~> 0.4` would permit future 0.x minor changes.
|
|
139
|
+
|
|
140
|
+
**1.0 is a public-API compatibility commitment, not a feature-count milestone.** The Ruby lifecycle is already used by consumers, but the Compose/Vite path is recent and this cycle found configuration-selection and readiness-lifetime defects. Promotion should follow an explicit freeze of the supported API, platform/tool prerequisites, and upgrade policy after real consumer adoption confirms the integration shape and the retained installed-artifact gate passes. No additional feature backlog or arbitrary sequence through 0.5–0.9 is required; the next stable-contract release can go directly to 1.0.
|
|
141
|
+
|
|
142
|
+
Verified release environments are Linux with Docker Compose supporting `config --format json` and `config --environment` (5.6.0 exercised here), Node 22 with Vite 5.4.20 / 6.0.0, and Node 24 with Vite 8.0.9. Other platforms/tool versions are not implied by this evidence. These capabilities are needed only for the Docker adapter; unrelated Compose commands do not resolve editor configuration.
|
|
143
|
+
|
|
123
144
|
## Development and Release
|
|
124
145
|
|
|
146
|
+
Commit the root `Gemfile.lock` to keep development and release-test dependencies reproducible. Regenerate it with Bundler after changing `Gemfile`, and commit both files together when both change. This development lockfile is not included in the gem package and does not constrain applications installing this gem; those applications resolve the gemspec's dependencies using their own lockfiles.
|
|
147
|
+
|
|
148
|
+
Keep generated `*.gem` packages, `.ruby-lsp/` editor state, and local `pkg/` / `tmp/` artifacts out of version control.
|
|
149
|
+
|
|
150
|
+
Development checks require Node.js 18+ for the bundled Vite plugin's dependency-free tests; the Ruby library itself remains dependency-free. `rake test` runs both Ruby and Node checks.
|
|
151
|
+
|
|
125
152
|
```sh
|
|
126
153
|
bundle install
|
|
127
154
|
bundle exec rake test
|
|
128
155
|
gem build open-in-editor-bridge.gemspec
|
|
129
156
|
```
|
|
130
157
|
|
|
131
|
-
Release changes on an issue-linked branch and pull request, including the version and changelog. Self-review and
|
|
158
|
+
Release changes on an issue-linked branch and pull request, including the version and changelog. Self-review and run the normal test gate plus the real Docker gate below before merging. From synchronized `main`, build and push the gem with the maintainer's RubyGems credentials, then create a matching GitHub tag/release. Install the published version from RubyGems into a clean `GEM_HOME`, confirm `OpenInEditorBridge::VERSION`, and run the same Docker gate against its installed library. A recorded editor process proves invocation and arguments, not that an editor window rendered.
|
|
159
|
+
|
|
160
|
+
### Retained Docker and Vite Gate
|
|
161
|
+
|
|
162
|
+
```sh
|
|
163
|
+
bundle exec rake test:docker
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The opt-in gate creates isolated temporary Compose projects and requires host port 3333 to be free. It exercises two checkout mappings for each pinned Vite version, encoded paths/locations and hostile selectors, credential isolation, native configuration parity, readiness-based detached lifetime, foreground/error cleanup, ordinary commands, and production builds without editor mounts. It does not run as part of the fast `rake test` gate. Docker and npm registry access are required to prepare the Node/Vite fixture images; projects, leases, networks, and temporary directories are cleaned on exit. Images may be reused between QA runs.
|
|
167
|
+
|
|
168
|
+
To repeat it against the released gem while retaining the checkout's test tooling:
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
release_home="$(mktemp -d)"
|
|
172
|
+
GEM_HOME="$release_home" GEM_PATH="$release_home" \
|
|
173
|
+
gem install open-in-editor-bridge --version 0.4.0 \
|
|
174
|
+
--clear-sources --source https://rubygems.org --no-document
|
|
175
|
+
GEM_HOME="$release_home" GEM_PATH="$release_home" \
|
|
176
|
+
ruby -ropen_in_editor_bridge -e 'puts OpenInEditorBridge::VERSION'
|
|
177
|
+
OPEN_IN_EDITOR_BRIDGE_TEST_LIB="$release_home/gems/open-in-editor-bridge-0.4.0/lib" \
|
|
178
|
+
bundle exec rake test:docker
|
|
179
|
+
rm -rf "$release_home"
|
|
180
|
+
```
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
require "tempfile"
|
|
5
|
+
|
|
6
|
+
class OpenInEditorBridge
|
|
7
|
+
class Docker
|
|
8
|
+
CONTAINER_DIRECTORY = "/open-in-editor-bridge"
|
|
9
|
+
|
|
10
|
+
def initialize(env:, project_root:, service:, compose_options:)
|
|
11
|
+
@env = env.to_h
|
|
12
|
+
@project_root = File.expand_path(project_root || @env.fetch("OPEN_IN_EDITOR_PROJECT_ROOT", Dir.pwd))
|
|
13
|
+
@service = service
|
|
14
|
+
@compose_options = compose_options
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def call(*args)
|
|
18
|
+
return up(args) if args.first == "up"
|
|
19
|
+
|
|
20
|
+
result = run(args)
|
|
21
|
+
bridge.call("--shutdown") if args.first == "down"
|
|
22
|
+
result
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def configuration
|
|
28
|
+
@configuration ||= Configuration.new(env: @env, project_root: @project_root)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def bridge
|
|
32
|
+
@bridge ||= OpenInEditorBridge.new(env: @env, project_root: @project_root)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def up(args)
|
|
36
|
+
if %w[127.0.0.1 ::1 localhost].include?(configuration.bind_address)
|
|
37
|
+
raise ArgumentError, "Docker editor access requires explicit OPEN_IN_EDITOR_BRIDGE_BIND_ADDRESS (for example 0.0.0.0 on a trusted network)."
|
|
38
|
+
end
|
|
39
|
+
raise ArgumentError, "Select a Compose service for the Vite integration" if @service.to_s.empty?
|
|
40
|
+
|
|
41
|
+
# Resolve source files once with Compose, before acquiring a lease. Reuse
|
|
42
|
+
# its canonical model rather than trying to reproduce file discovery.
|
|
43
|
+
with_resolved_configuration do |resolved_file, profiles|
|
|
44
|
+
with_override do |override|
|
|
45
|
+
options = compose_options_for_resolved_configuration(profiles) +
|
|
46
|
+
["-f", resolved_file, "-f", override]
|
|
47
|
+
detached?(args) ? detached_up(args, options) : foreground_up(args, options)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def foreground_up(args, options)
|
|
53
|
+
lease = SecureRandom.hex(16)
|
|
54
|
+
bridge.start_session(lease)
|
|
55
|
+
begin
|
|
56
|
+
run(args, options)
|
|
57
|
+
ensure
|
|
58
|
+
release_preserving_error(lease)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def detached_up(args, options)
|
|
63
|
+
registration = bridge.start_session("detached")
|
|
64
|
+
run(args, options)
|
|
65
|
+
rescue StandardError
|
|
66
|
+
release_preserving_error("detached") if registration == :started
|
|
67
|
+
raise
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def release_preserving_error(lease)
|
|
71
|
+
original_error = $!
|
|
72
|
+
bridge.stop_session(lease)
|
|
73
|
+
rescue StandardError
|
|
74
|
+
raise unless original_error
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def detached?(args)
|
|
78
|
+
wait_flag = args.reverse_each.find { |arg| %w[--wait --wait=true --wait=false].include?(arg) }
|
|
79
|
+
return true if wait_flag && wait_flag != "--wait=false"
|
|
80
|
+
|
|
81
|
+
flags = args.select { |arg| %w[-d --detach --detach=true --detach=false -d=true -d=false].include?(arg) }
|
|
82
|
+
!flags.empty? && !%w[--detach=false -d=false].include?(flags.last)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def run(args, compose_options = @compose_options)
|
|
86
|
+
system(@env, "docker", "compose", *compose_options, *args,
|
|
87
|
+
chdir: @project_root, exception: true)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def with_resolved_configuration
|
|
91
|
+
Tempfile.create(["compose-resolved-", ".json"]) do |file|
|
|
92
|
+
system(@env, "docker", "compose", *@compose_options, "config", "--format", "json",
|
|
93
|
+
chdir: @project_root, out: file, exception: true)
|
|
94
|
+
file.flush
|
|
95
|
+
yield file.path, active_profiles
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def active_profiles
|
|
100
|
+
output, error, status = Open3.capture3(@env, "docker", "compose", *@compose_options,
|
|
101
|
+
"config", "--environment", chdir: @project_root)
|
|
102
|
+
unless status.success?
|
|
103
|
+
raise "Docker Compose config --environment failed (exit #{status.exitstatus}): #{error.strip}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
profiles = output.lines.find { |line| line.start_with?("COMPOSE_PROFILES=") }
|
|
107
|
+
return [] unless profiles
|
|
108
|
+
|
|
109
|
+
profiles.delete_prefix("COMPOSE_PROFILES=").strip.split(",").reject(&:empty?)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def compose_options_for_resolved_configuration(profiles)
|
|
113
|
+
options = []
|
|
114
|
+
skip_next = false
|
|
115
|
+
@compose_options.each do |option|
|
|
116
|
+
if skip_next
|
|
117
|
+
skip_next = false
|
|
118
|
+
next
|
|
119
|
+
end
|
|
120
|
+
if %w[-f --file --env-file].include?(option)
|
|
121
|
+
skip_next = true
|
|
122
|
+
elsif option.start_with?("--file=", "--env-file=") || option.match?(/\A-f.+/)
|
|
123
|
+
next
|
|
124
|
+
else
|
|
125
|
+
options << option
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
unless options.any? { |option| option == "--project-directory" || option.start_with?("--project-directory=") }
|
|
129
|
+
options.concat(["--project-directory", @project_root])
|
|
130
|
+
end
|
|
131
|
+
profiles.each { |profile| options.concat(["--profile", profile]) }
|
|
132
|
+
options
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def with_override
|
|
136
|
+
configuration.ensure_runtime_directory
|
|
137
|
+
manifest = write_manifest
|
|
138
|
+
mounts = [
|
|
139
|
+
file_mount(File.join(__dir__, "vite.mjs"), "vite.mjs"),
|
|
140
|
+
file_mount(manifest, "session.json"),
|
|
141
|
+
]
|
|
142
|
+
override = { "services" => { @service => {
|
|
143
|
+
"extra_hosts" => { "host.docker.internal" => "host-gateway" },
|
|
144
|
+
"volumes" => mounts,
|
|
145
|
+
} } }
|
|
146
|
+
Tempfile.create(["compose-", ".json"], configuration.runtime_directory) do |file|
|
|
147
|
+
file.write(JSON.generate(override))
|
|
148
|
+
file.flush
|
|
149
|
+
yield file.path
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def file_mount(source, name)
|
|
154
|
+
{ "type" => "bind", "source" => File.expand_path(source),
|
|
155
|
+
"target" => "#{CONTAINER_DIRECTORY}/#{name}", "read_only" => true,
|
|
156
|
+
"bind" => { "create_host_path" => false } }
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def write_manifest
|
|
160
|
+
path = File.join(configuration.runtime_directory, "docker-#{configuration.port}-#{configuration.session_id}.json")
|
|
161
|
+
payload = { "session" => configuration.session_id, "target" => "http://host.docker.internal:#{configuration.port}" }
|
|
162
|
+
# Atomic replacement keeps simultaneous starts from exposing a partial identity file.
|
|
163
|
+
Tempfile.create(["session-", ".json"], configuration.runtime_directory) do |file|
|
|
164
|
+
file.write(JSON.generate(payload))
|
|
165
|
+
file.flush
|
|
166
|
+
file.chmod(0o644)
|
|
167
|
+
File.rename(file.path, path)
|
|
168
|
+
end
|
|
169
|
+
path
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
const sessionManifestPath = new URL("./session.json", import.meta.url);
|
|
4
|
+
const editorRouteKey = "^/__open-in-editor(?:\\?|$)";
|
|
5
|
+
|
|
6
|
+
function readSession() {
|
|
7
|
+
try {
|
|
8
|
+
const manifest = JSON.parse(readFileSync(sessionManifestPath, "utf8"));
|
|
9
|
+
if (
|
|
10
|
+
!manifest ||
|
|
11
|
+
typeof manifest.session !== "string" ||
|
|
12
|
+
!/^[a-f0-9]{64}$/.test(manifest.session) ||
|
|
13
|
+
typeof manifest.target !== "string"
|
|
14
|
+
) {
|
|
15
|
+
throw new Error("Invalid checkout identity");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const target = new URL(manifest.target);
|
|
19
|
+
if (
|
|
20
|
+
target.protocol !== "http:" ||
|
|
21
|
+
!target.hostname ||
|
|
22
|
+
target.username ||
|
|
23
|
+
target.password ||
|
|
24
|
+
target.pathname !== "/" ||
|
|
25
|
+
target.search ||
|
|
26
|
+
target.hash
|
|
27
|
+
) {
|
|
28
|
+
throw new Error("Invalid bridge target");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { session: manifest.session, target: target.origin };
|
|
32
|
+
} catch (cause) {
|
|
33
|
+
throw new Error("OpenInEditorBridge requires a valid Docker session manifest; start Vite through OpenInEditorBridge.compose.", { cause });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function withSession(requestUrl, session) {
|
|
38
|
+
const queryStart = requestUrl.indexOf("?");
|
|
39
|
+
if (queryStart === -1) return `${requestUrl}?session=${encodeURIComponent(session)}`;
|
|
40
|
+
|
|
41
|
+
const path = requestUrl.slice(0, queryStart);
|
|
42
|
+
const query = requestUrl.slice(queryStart + 1);
|
|
43
|
+
const retained = query.split("&").filter((part) => {
|
|
44
|
+
const separator = part.indexOf("=");
|
|
45
|
+
const rawName = separator === -1 ? part : part.slice(0, separator);
|
|
46
|
+
try {
|
|
47
|
+
return decodeURIComponent(rawName.replace(/\+/g, " ")) !== "session";
|
|
48
|
+
} catch {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
retained.push(`session=${encodeURIComponent(session)}`);
|
|
53
|
+
return `${path}?${retained.join("&")}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default function openInEditorBridge() {
|
|
57
|
+
const identity = readSession();
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
name: "open-in-editor-bridge",
|
|
61
|
+
enforce: "post",
|
|
62
|
+
config(config) {
|
|
63
|
+
const existing = { ...config.server?.proxy };
|
|
64
|
+
delete existing["/__open-in-editor"];
|
|
65
|
+
delete existing["^/__open-in-editor$"];
|
|
66
|
+
delete existing[editorRouteKey];
|
|
67
|
+
|
|
68
|
+
config.server ??= {};
|
|
69
|
+
config.server.proxy = {
|
|
70
|
+
[editorRouteKey]: {
|
|
71
|
+
target: identity.target,
|
|
72
|
+
changeOrigin: true,
|
|
73
|
+
rewrite: (requestUrl) => withSession(requestUrl, identity.session),
|
|
74
|
+
},
|
|
75
|
+
...existing,
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -14,6 +14,10 @@ class OpenInEditorBridge
|
|
|
14
14
|
new.session_id
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
def self.compose(*args, service: "web", compose_options: [], env: ENV, project_root: nil)
|
|
18
|
+
Docker.new(env: env, project_root: project_root, service: service, compose_options: compose_options).call(*args)
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
def self.with_running(ensure_running: true)
|
|
18
22
|
bridge = new
|
|
19
23
|
lease = SecureRandom.hex(16) if ensure_running
|
|
@@ -69,5 +73,6 @@ require_relative "open_in_editor_bridge/configuration"
|
|
|
69
73
|
require_relative "open_in_editor_bridge/authentication"
|
|
70
74
|
require_relative "open_in_editor_bridge/server"
|
|
71
75
|
require_relative "open_in_editor_bridge/client"
|
|
76
|
+
require_relative "open_in_editor_bridge/docker"
|
|
72
77
|
|
|
73
78
|
OpenInEditorBridge.call(*ARGV) if $PROGRAM_NAME == __FILE__
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: open-in-editor-bridge
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marlen Brunner
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Ruby API and CLI for serving local open-in-editor requests during development.
|
|
14
14
|
email:
|
|
@@ -26,8 +26,10 @@ files:
|
|
|
26
26
|
- lib/open_in_editor_bridge/authentication.rb
|
|
27
27
|
- lib/open_in_editor_bridge/client.rb
|
|
28
28
|
- lib/open_in_editor_bridge/configuration.rb
|
|
29
|
+
- lib/open_in_editor_bridge/docker.rb
|
|
29
30
|
- lib/open_in_editor_bridge/server.rb
|
|
30
31
|
- lib/open_in_editor_bridge/version.rb
|
|
32
|
+
- lib/open_in_editor_bridge/vite.mjs
|
|
31
33
|
homepage: https://github.com/klondikemarlen/open-in-editor-bridge
|
|
32
34
|
licenses:
|
|
33
35
|
- MIT
|