homura-runtime 0.2.9 → 0.2.11

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: d41fae3606bacf17566d5d2b423547fffcb490a70fde78bb9e0e34e9cff357cd
4
- data.tar.gz: 2c7f98a9cfa158acdb8287788176af5515d3bf736c791de2d849e8ee4c29d06d
3
+ metadata.gz: 7426d1447a4eca3f4ae0b8826e8dfaee809c9868d99314e381ae5b0e338defc3
4
+ data.tar.gz: d42df70713ac5bf410d91ccd77ade2c3500464a2280c769ee5475449ce427231
5
5
  SHA512:
6
- metadata.gz: adeef4db820e46d80748ebd3aa9ebc8d8224d1e3a796a07582d47c73eee6ea21541805b087d1aa16a6dbfb19434b4fe9f3c7ff2ab36943d01df1b8263fc22137
7
- data.tar.gz: a3b35377f1d55af94598f1728edec1a6a06acc9f42ffe02090116dfa022a2548349c5da1fa5b061d96cf5b734372ce54c6b3dbbf5192b78e0988a7464ddfb210
6
+ metadata.gz: f92aca6718eeb4440a60a45611378e0fa4669116fbe56f56f4663705f6440e9010e92d9d30f09c5faac5b2d7de47798a2c26dba69f9995012ce655b861831c9e
7
+ data.tar.gz: 9686bae18cd4c9f858f8056c807d47e068130710b44d73b796b21119b102a176f9c5154f9f5e40b95f0e4b5c6a846e6b37a16a00677c208820cef5263c7b4e27
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.11 (2026-04-25)
4
+
5
+ - Normalize bare JS `undefined` / `null` values to Ruby `nil` while converting
6
+ D1 rows into Ruby Hashes, preventing first-row crashes when a nullable column
7
+ is present in the result shape.
8
+
9
+ ## 0.2.10 (2026-04-24)
10
+
11
+ - Derive `worker.entrypoint.mjs` import paths relative to the actual
12
+ `--entrypoint-out` location, so standalone builds keep working when apps move
13
+ the bundle and entrypoint under custom output directories.
14
+
3
15
  ## 0.2.9 (2026-04-24)
4
16
 
5
17
  - Skip auto-await rewrites when the source expression is already followed by
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudflareWorkers
4
- VERSION = '0.2.9'
4
+ VERSION = '0.2.11'
5
5
  end
@@ -504,8 +504,13 @@ module Cloudflare
504
504
  while i < len
505
505
  k = `#{keys}[#{i}]`
506
506
  v = `#{js_obj}[#{k}]`
507
+ # Normalize bare JS null/undefined to Ruby nil before storing them.
508
+ if `#{v} == null`
509
+ v = nil
507
510
  # Recurse for nested plain objects (but not Arrays, Dates, etc.)
508
- v = js_object_to_hash(v) if `typeof #{v} === 'object' && #{v} != null && !Array.isArray(#{v}) && !(#{v} instanceof Date)`
511
+ elsif `typeof #{v} === 'object' && !Array.isArray(#{v}) && !(#{v} instanceof Date)`
512
+ v = js_object_to_hash(v)
513
+ end
509
514
  h[k] = v
510
515
  i += 1
511
516
  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.9
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuhiro Homma