homura-runtime 0.2.8 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2a642d762f1d0c562e0c54d9fc9b1a5299833ad7f58620af82421022f9c6f46
4
- data.tar.gz: b2858fc319f7e895221437cfafedcf6f559cc7cdddfdc8659ef5195b7f2e4bb5
3
+ metadata.gz: 64648aa358cfa6cd1c65fff6da71068b244c136017c896aa002308eb391a571b
4
+ data.tar.gz: 7c02ed80302c02f183e7927c9bd15c25dc1389a2e3921ebbc7bd60cc2622a574
5
5
  SHA512:
6
- metadata.gz: 0c6b623fb0618ff32c105ea8dfd104963e85967c154e4fb9b28beb7ce87d625d7889bda1c658133671305bc2c312b569742c90c4b544db646d5cf701de5ea13c
7
- data.tar.gz: 3a69ce9560b4ef766a247e26f12fc173c56239842aee7fa78e16b7af2679885bc2ef762445b69d89c5c916911968ea817937adee64ac133f00a4c9e44cf1413b
6
+ metadata.gz: 2d41fbab3ad2faef7a283e824f66918fbbeb71ce38b3c82597109df9d69cdb5b7f7e89ddb6beca6aa1965f71e26c1791d44019b46217eebfdb6760b9daddac1e
7
+ data.tar.gz: ad1208ab207ed735d5effacb6f26a4df562652cf0f53e96acee461e7d6c4fdc397cb5d46016e515077bf0c84065918e6daae29e378a000a0b279b062fe061e1e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.10 (2026-04-24)
4
+
5
+ - Derive `worker.entrypoint.mjs` import paths relative to the actual
6
+ `--entrypoint-out` location, so standalone builds keep working when apps move
7
+ the bundle and entrypoint under custom output directories.
8
+
9
+ ## 0.2.9 (2026-04-24)
10
+
11
+ - Skip auto-await rewrites when the source expression is already followed by
12
+ `.__await__`, avoiding noisy double-application in rewritten standalone app
13
+ code.
14
+
3
15
  ## 0.2.8 (2026-04-24)
4
16
 
5
17
  - Compile standalone `config.ru` inputs from `build/auto_await/` so ordinary
data/README.md CHANGED
@@ -9,14 +9,14 @@ Core Ruby + Module Worker glue for [Opal](https://opalrb.com/) on [Cloudflare Wo
9
9
  - `runtime/worker_module.mjs` — fetch / scheduled / queue / DO adapters (**no Opal bundle import**).
10
10
  - `runtime/worker.mjs` — thin bootstrap (crypto shim → bundle → `worker_module`) for legacy layouts.
11
11
  - `runtime/setup-node-crypto.mjs` — `node:crypto` on `globalThis` before the Opal bundle loads.
12
- - `homura build` — single build pipeline (ERB → assets → Opal → patch → `worker.entrypoint.mjs`). Use `--standalone` in generated apps; it now restores `cf-runtime/` automatically and derives standalone template/asset namespaces from the project name by default.
12
+ - `homura build` — single build pipeline (ERB → assets → Opal → patch → `worker.entrypoint.mjs`). Use `--standalone` in generated apps; it restores `cf-runtime/` automatically, derives standalone template/asset namespaces from the project name, and computes entrypoint import paths relative to the actual `--entrypoint-out` location.
13
13
  - `docs/ARCHITECTURE.md` — wrangler `main`, codegen entrypoint, and fixed-import policy.
14
14
 
15
15
  ## Quick start (homura monorepo)
16
16
 
17
17
  1. `Gemfile`: `gem 'homura-runtime', path: 'gems/homura-runtime'` and `gem 'opal-homura', '= 1.8.3.rc1.3', require: 'opal'` (path or exact pin).
18
- 2. `bundle exec homura build` — writes `build/hello.no-exit.mjs` and `build/worker.entrypoint.mjs`.
19
- 3. `wrangler.toml`: `main = "build/worker.entrypoint.mjs"`, `compatibility_flags = ["nodejs_compat"]`.
18
+ 2. `bundle exec homura build` — in generated standalone apps, writes `build/hello.no-exit.mjs` plus root-level `worker.entrypoint.mjs`; in the monorepo it writes `build/worker.entrypoint.mjs`.
19
+ 3. `wrangler.toml`: generated apps use `main = "worker.entrypoint.mjs"` and `compatibility_flags = ["nodejs_compat"]`.
20
20
 
21
21
  ## Support matrix (indicative)
22
22
 
data/docs/ARCHITECTURE.md CHANGED
@@ -5,7 +5,7 @@
5
5
  | レイヤ | 役割 |
6
6
  |--------|------|
7
7
  | `wrangler.toml` の `main` | **Workers Module のエントリ**(`fetch` / `scheduled` / `queue` / DO クラスを export) |
8
- | `worker.entrypoint.mjs`(生成物) | `setup-node-crypto` → **Opal bundle(副作用)** → `worker_module.mjs` の順で import。パスはプロジェクトごとに **固定文字列**(codegen) |
8
+ | `worker.entrypoint.mjs`(生成物) | `setup-node-crypto` → **Opal bundle(副作用)** → `worker_module.mjs` の順で import。import path は entrypoint 出力位置からの **相対パス** に自動調整される |
9
9
  | Opal bundle(例: `build/hello.no-exit.mjs`) | **ビルド成果物**。Rack ディスパッチャ等を `globalThis` に登録 |
10
10
  | `worker_module.mjs`(gem 同梱) | Rack / Cron / Queue / DO への **純粋な JS アダプタ**(Opal bundle を import しない) |
11
11
 
@@ -37,6 +37,7 @@ flowchart LR
37
37
  - プロジェクト直下に `worker.entrypoint.mjs`(`main` と一致)。
38
38
  - `cf-runtime/` に `setup-node-crypto.mjs` と `worker_module.mjs` をコピー(gem から)。
39
39
  - `bundle exec homura build --standalone` が consumer 向けパイプラインを実行し、`Gemfile` の `path:` から homura の `vendor/` を追加ロードパスへ取り込み(digest / zlib 等の Workers 向け補助ファイル)。
40
+ - low-level `--output` / `--entrypoint-out` を変えても、entrypoint 内 import は出力先からの相対パスに自動調整される。
40
41
 
41
42
  ## Phase 17 — Email Service(`SEND_EMAIL`)
42
43
 
data/exe/homura-build CHANGED
@@ -77,14 +77,14 @@ options[:assets_namespace] ||= CloudflareWorkers::BuildSupport.standalone_namesp
77
77
 
78
78
  if options[:standalone]
79
79
  Dir.chdir(root) { require 'bundler/setup' }
80
- options[:setup_import] ||= './cf-runtime/setup-node-crypto.mjs'
81
- options[:bundle_import] ||= './build/hello.no-exit.mjs'
82
- options[:worker_module_import] ||= './cf-runtime/worker_module.mjs'
80
+ options[:setup_import] ||= 'cf-runtime/setup-node-crypto.mjs'
81
+ options[:bundle_import] ||= options[:opal_output]
82
+ options[:worker_module_import] ||= 'cf-runtime/worker_module.mjs'
83
83
  options[:entrypoint_out] ||= 'worker.entrypoint.mjs'
84
84
  else
85
- options[:setup_import] ||= '../gems/homura-runtime/runtime/setup-node-crypto.mjs'
86
- options[:bundle_import] ||= './hello.no-exit.mjs'
87
- options[:worker_module_import] ||= '../gems/homura-runtime/runtime/worker_module.mjs'
85
+ options[:setup_import] ||= 'gems/homura-runtime/runtime/setup-node-crypto.mjs'
86
+ options[:bundle_import] ||= options[:opal_output]
87
+ options[:worker_module_import] ||= 'gems/homura-runtime/runtime/worker_module.mjs'
88
88
  options[:entrypoint_out] ||= 'build/worker.entrypoint.mjs'
89
89
  end
90
90
 
@@ -139,13 +139,20 @@ def run_opal_standalone!(root, opal_input, opal_output, with_db:)
139
139
  end
140
140
 
141
141
  def write_entrypoint!(root, out_path, setup:, bundle:, worker_mod:)
142
+ out_file = root.join(out_path)
143
+ out_dir = out_file.dirname
142
144
  body = <<~JS
143
145
  // GENERATED by homura build — do not edit by hand.
144
- import "#{setup}";
145
- import "#{bundle}";
146
- export { default, HomuraCounterDO } from "#{worker_mod}";
146
+ import "#{relative_import_spec(out_dir, root.join(setup))}";
147
+ import "#{relative_import_spec(out_dir, root.join(bundle))}";
148
+ export { default, HomuraCounterDO } from "#{relative_import_spec(out_dir, root.join(worker_mod))}";
147
149
  JS
148
- File.write(root.join(out_path), body)
150
+ File.write(out_file, body)
151
+ end
152
+
153
+ def relative_import_spec(from_dir, target_path)
154
+ rel = Pathname(target_path).relative_path_from(Pathname(from_dir)).to_s
155
+ rel.start_with?('.', '/') ? rel : "./#{rel}"
149
156
  end
150
157
 
151
158
  def resolve_opal_input(root, explicit_input)
@@ -10,10 +10,15 @@ module CloudflareWorkers
10
10
  await_nodes.each do |node|
11
11
  range = node.loc.expression
12
12
  next unless range
13
+ next if already_awaited?(buffer, range)
13
14
  rewriter.replace(range, "#{range.source}.__await__")
14
15
  end
15
16
  rewriter.process
16
17
  end
18
+
19
+ def self.already_awaited?(buffer, range)
20
+ buffer.source[range.end_pos..]&.match?(/\A\s*\.__await__\b/)
21
+ end
17
22
  end
18
23
  end
19
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudflareWorkers
4
- VERSION = '0.2.8'
4
+ VERSION = '0.2.10'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: homura-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuhiro Homma