@runeditrun/rer 0.2.13 → 0.2.14

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.
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.14
4
+
5
+ - Workerd container and hosted demo builds admit native `cloudflare:workers` imports, Durable Object definitions, `WebSocketPair`, `crypto.subtle.timingSafeEqual` and `ctx.passThroughOnException`. Node-engine restrictions are unchanged.
6
+ - Container packaging requires configured Durable Objects to be local and exported by the built Worker. External namespace bindings and missing exports fail before packaging. Raw sockets and the existing container isolation restrictions remain refused.
7
+
8
+ ### Upgrade notes
9
+
10
+ - Update rer and rebuild the demo image to receive the workerd admission fix. Durable Object namespaces still need local Wrangler bindings and exported classes. Allowing `WebSocketPair` does not add WebSocket upgrade handling to the container HTTP host.
11
+
3
12
  ## 0.2.13
4
13
 
5
14
  - `rer deploy --remove` accepts empty owned R2 object listings without pagination metadata, fixing the 0.2.9 regression. Populated or malformed listings still require complete pagination proof before deletion.
@@ -12,11 +12,37 @@ at the intended memory limit. A retained-public-snapshot cache contract is
12
12
  selected through `cacheContract` when the seed implements that contract. This
13
13
  is not a general Durable Object adapter. A seed requiring KV or other
14
14
  Cloudflare-only APIs cannot use Node.
15
- The import boundary rejects those APIs and new Cloudflare imports outside the
15
+ For Node, the import boundary rejects those APIs and new Cloudflare imports outside the
16
16
  platform binding/cache boundary. The one other file it admits is an exported
17
17
  seed's demo guard, `src/modules/demo/index.mjs`, and there only
18
18
  `import { env } from 'cloudflare:workers'` (it reads `RER_DEMO`).
19
19
 
20
+ The workerd engine admits exact `cloudflare:workers` static imports, literal
21
+ dynamic imports and re-exports, plus `HTMLRewriter`, `WebSocketPair`,
22
+ `crypto.subtle.timingSafeEqual` and `ctx.passThroughOnException`. Other
23
+ `cloudflare:` modules (including sockets), `require()` or arbitrary calls with
24
+ Cloudflare module strings, `email()`, `caches.default` and `request.cf` remain
25
+ outside the container boundary.
26
+ Other Cloudflare modules have no admitted host adapters; raw sockets would also
27
+ bypass the host's routed fetch egress. Native `email()` has no configured host
28
+ delivery, `caches.default` has no declared container cache contract, and the host
29
+ disables request CF metadata (`cf: false`). The module import rule admits native
30
+ ES module loading, not arbitrary calls carrying module strings. Admitting
31
+ `WebSocketPair` does not add HTTP upgrade transport or qualify a complete live
32
+ WebSocket flow through the container host.
33
+
34
+ The workerd source boundary permits Durable Object definitions, including export
35
+ aliases and indirect inheritance. Unbound definitions create no namespace. The
36
+ seed's Vite build selects and renders its configuration; before packaging, the
37
+ container builder checks each namespace in the emitted
38
+ `dist/server/wrangler.json`. It rejects `script_name` and `environment`, because
39
+ the host binds only local namespaces, and requires each configured class name in
40
+ the bundler's exports for the emitted Worker entry. This validates the binding
41
+ contract without inferring source class names. Workerd readiness alone does not
42
+ reject a missing class export; actual class behavior still needs runtime
43
+ qualification. Node's binding, retained-cache and demo-guard exceptions are
44
+ unchanged.
45
+
20
46
  The entrypoint holds a Linux kernel `flock` for the lifetime of the host. Each
21
47
  installation has one local data volume and one writer. The lock inode retains
22
48
  PID/heartbeat diagnostics and is never unlinked. The host applies hashed
@@ -21,15 +21,15 @@ export async function checkBoundary(root, { engine='node', cacheContract }={}) {
21
21
  if(module.startsWith('cloudflare:')){
22
22
  const imports=node.importClause?.namedBindings;
23
23
  const allowed=module==='cloudflare:workers'&&imports&&ts.isNamedImports(imports)&&imports.elements.every(element=>(demo&&!node.importClause.name&&!element.propertyName&&element.name.text==='env')||(bindings&&(element.propertyName??element.name).text==='env')||(cache&&(element.propertyName??element.name).text==='DurableObject'));
24
- if(!allowed)fail('Cloudflare import outside binding/cache contract');
24
+ if(!allowed&&!(engine==='workerd'&&module==='cloudflare:workers'))fail('Cloudflare import outside binding/cache contract');
25
25
  }
26
26
  }
27
- if(ts.isCallExpression(node)&&node.arguments.some(arg=>ts.isStringLiteral(arg)&&arg.text.startsWith('cloudflare:')))fail('Dynamic Cloudflare import');
28
- if(ts.isIdentifier(node)&&(['WebSocketPair','passThroughOnException','timingSafeEqual'].includes(node.text)||(node.text==='HTMLRewriter'&&engine!=='workerd')))fail(node.text);
27
+ if(ts.isCallExpression(node)&&node.arguments.some((arg,index)=>ts.isStringLiteral(arg)&&arg.text.startsWith('cloudflare:')&&!(engine==='workerd'&&node.expression.kind===ts.SyntaxKind.ImportKeyword&&index===0&&arg.text==='cloudflare:workers')))fail('Dynamic Cloudflare import');
28
+ if(ts.isIdentifier(node)&&engine!=='workerd'&&['WebSocketPair','passThroughOnException','timingSafeEqual','HTMLRewriter'].includes(node.text))fail(node.text);
29
29
  if(ts.isCallExpression(node)&&ts.isIdentifier(node.expression)&&node.expression.text==='email'&&!localNames.has('email'))fail('email()');
30
30
  if(ts.isPropertyAccessExpression(node)&&((node.expression.getText(tree)==='caches'&&node.name.text==='default')||(node.expression.getText(tree)==='request'&&node.name.text==='cf')))fail(node.getText(tree));
31
31
  if(ts.isElementAccessExpression(node)&&ts.isStringLiteral(node.argumentExpression)&&((node.expression.getText(tree)==='caches'&&node.argumentExpression.text==='default')||(node.expression.getText(tree)==='request'&&node.argumentExpression.text==='cf')))fail(node.getText(tree));
32
- if(ts.isHeritageClause(node)&&node.token===ts.SyntaxKind.ExtendsKeyword&&node.types.some(type=>/DurableObject/.test(type.expression.getText(tree)))&&!cache)fail('New Durable Object');
32
+ if(engine!=='workerd'&&ts.isHeritageClause(node)&&node.token===ts.SyntaxKind.ExtendsKeyword&&node.types.some(type=>/DurableObject/.test(type.expression.getText(tree)))&&!cache)fail('New Durable Object');
33
33
  ts.forEachChild(node,visit);
34
34
  }
35
35
  visit(tree);
@@ -1,11 +1,12 @@
1
- import { readFile, writeFile, readdir, cp, mkdir, rm } from 'node:fs/promises';
2
- import { join, resolve } from 'node:path';
1
+ import { readFile, writeFile, readdir, realpath, cp, mkdir, rm } from 'node:fs/promises';
2
+ import { dirname, join, resolve } from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { createHash } from 'node:crypto';
6
6
  import { parseJsonc } from '../../cli/jsonc.mjs';
7
7
  import { portabilityPlan } from './portability-schema.mjs';
8
8
  import { checkBoundary } from './boundary.mjs';
9
+ import { localDurableObjects } from './durable-objects.mjs';
9
10
  import { readMigrationRewrites, withRewrites } from '../deploy-kit/migrations.mjs';
10
11
  const hash = source => createHash('sha256').update(source).digest('hex');
11
12
  export async function buildContainer(root, options={}) {
@@ -21,6 +22,13 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
21
22
  const vite = await import(pathToFileURL(require.resolve('vite'))), loaded = await vite.loadConfigFromFile({ command:'build',mode:'production' },undefined,root);
22
23
  if (!loaded) throw new Error('Vite configuration missing');
23
24
  const config = loaded.config;
25
+ const outputExports = new Map();
26
+ if (engine === 'workerd') config.plugins = [...(config.plugins ?? []), {
27
+ name:'rer-container-exports',
28
+ async writeBundle(output,bundle) {
29
+ for (const chunk of Object.values(bundle)) if (chunk.type === 'chunk' && chunk.isEntry) outputExports.set(await realpath(resolve(root,output.dir ?? dirname(output.file),chunk.fileName)),new Set(chunk.exports));
30
+ },
31
+ }];
24
32
  if (engine === 'node') {
25
33
  const plugins = (await Promise.all(config.plugins.flat(Infinity))).filter(plugin => plugin && !plugin.name.startsWith('vite-plugin-cloudflare') && plugin.name !== 'tanstack-start-core:post-build');
26
34
  const bindingShim = resolve(import.meta.dirname,'bindings.mjs');
@@ -34,7 +42,10 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
34
42
  // Apply the same local-only bundle guard before packaging any container image.
35
43
  await (await import('../../cli/dev-identity.mjs')).refuseDevLayerOutput(root);
36
44
  let workerConfig;
37
- if (engine === 'workerd') workerConfig = JSON.parse(await readFile(join(root,'dist/server/wrangler.json'),'utf8'));
45
+ if (engine === 'workerd') {
46
+ workerConfig = JSON.parse(await readFile(join(root,'dist/server/wrangler.json'),'utf8'));
47
+ localDurableObjects(workerConfig,outputExports.get(await realpath(resolve(root,'dist/server',workerConfig.main))));
48
+ }
38
49
  else workerConfig = parseJsonc(await readFile(join(root,'wrangler.jsonc'),'utf8'));
39
50
  const { unstable_splitSqlQuery:split } = require('wrangler');
40
51
  const migrations = {}, rewrites = await readMigrationRewrites(root);
@@ -0,0 +1,15 @@
1
+ // worker-engine binds every namespace to a class in this Worker. Never silently
2
+ // reinterpret a cross-worker namespace as a local one. Check the bundler's actual
3
+ // entry exports: workerd readiness alone does not reject missing class exports.
4
+ export function localDurableObjects(config, exports) {
5
+ const bindings=config.durable_objects?.bindings??[];
6
+ if(!Array.isArray(bindings))throw new Error('Container Durable Object bindings must be an array');
7
+ for(const binding of bindings) {
8
+ if(!binding||typeof binding.name!=='string'||!binding.name||typeof binding.class_name!=='string'||!binding.class_name)throw new Error('Container Durable Object binding requires name and class_name');
9
+ if(Object.hasOwn(binding,'script_name')||Object.hasOwn(binding,'environment'))throw new Error('Container Durable Object bindings do not support script_name or environment');
10
+ }
11
+ const classes=new Set(bindings.map(binding=>binding.class_name));
12
+ if(classes.size&&!exports)throw new Error('Built container Worker entry exports are unavailable');
13
+ for(const name of classes)if(!exports.has(name))throw new Error('Built container Worker does not export configured Durable Object class: '+name);
14
+ return classes;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",