Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

Description

The dnt WASM transformer panics when statically analyzing direct Deno.* property accesses, even within runtime-guarded conditionals. The error manifests as Reflect.get called on non-object at wasm/src/lib.rs:56:64.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Other (please describe):

Changes Made

Replace direct Deno.* accesses with dynamic property access via globalThis to bypass static analysis:

Before:

if (isDeno) {
  Deno.exit(code);  // WASM transformer attempts Reflect.get on undefined
}

After:

if (isDeno) {
  const DenoNS = (globalThis as any).Deno;  // Runtime access only
  DenoNS.exit(code);
}

Files modified:

  • src/parser.ts - Deno.cwd() access
  • cli.ts - exit, readTextFile, writeTextFile, stat, args
  • runtime.ts - readTextFile, writeTextFile, writeFile, stat

Testing

  • Tested with Deno runtime
  • Tested with Node.js runtime (if applicable)
  • Ran deno task gen successfully
  • Ran deno lint (noted any acceptable errors)
  • Ran deno check mod.ts
  • Verified deno task build:npm completes without panics
  • Verified generated npm package loads correctly

Architectural Decision Record (ADR)

  • This change requires an ADR
    • ADR has been created and included in docs/adr/
    • ADR index has been updated in docs/adr/README.md
  • This change does not require an ADR

If ADR is required but not included, please explain why:

Tactical fix for WASM transformer limitation, not an architectural decision.

Documentation

  • Documentation has been updated (if needed)
  • README updated (if needed)
  • CONTRIBUTING.md updated (if needed)
  • No documentation changes needed

Breaking Changes

None. Runtime behavior unchanged.

Related Issues

Fixes #issue_number

Additional Notes

The isDeno check pattern ("Deno" in globalThis) was already safe. The issue was that direct property access (Deno.*) triggered static analysis in dnt's WASM transformer, which calls Reflect.get before runtime guards execute.

Checklist

  • My code follows the project's coding standards
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • My changes generate no new warnings
  • I have updated the documentation accordingly
  • My changes maintain compatibility with both Deno and Node.js (where applicable)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.204/linux64/chrome-headless-shell-linux64.zip
    • Triggering command: node install.mjs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>fix this and all similar issues preventing publish</issue_title>
<issue_description>The job failed due to a panic at wasm/src/lib.rs:56:64: it called .unwrap() on an Err value with the error: Error(JsValue(TypeError: Reflect.get called on non-object). This typically happens when using Rust's .unwrap() on a Result that contains an error—here, the error is related to JavaScript object reflection in Wasm.

Solution:

  • Locate the call to .unwrap() at or near line 56 in wasm/src/lib.rs.
  • Replace .unwrap() with proper error handling. For example:
// Original (unsafe)
let value = some_result.unwrap();

// Suggested (safe)
let value = some_result.expect("Descriptive message: failed because ...");
// Or provide full error handling:
let value = match some_result {
    Ok(v) => v,
    Err(e) => {
        // Handle or log the error
        return Err(e.into());
    }
};
  • Investigate why Reflect.get is receiving a non-object and add guards or input validation to ensure the expected object is passed.

Summary: Don’t use .unwrap() on potentially failing Results; handle the error to give more context and avoid panics. This will fix the crash and make failures more informative for debugging.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: kayodebristol <3579196+kayodebristol@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic in wasm/src/lib.rs during publish Fix unsafe Deno global access causing dnt WASM transformer panics Nov 15, 2025
Copilot AI requested a review from kayodebristol November 15, 2025 00:51
@kayodebristol kayodebristol marked this pull request as ready for review November 15, 2025 02:32
@kayodebristol kayodebristol merged commit acdfd41 into main Nov 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix this and all similar issues preventing publish

2 participants