deno/cli/tools/bench
Felipe Cardozo bf5d44b7fa
feat: add --require run arg to support commonJS (#31201)
Solution for https://github.com/denoland/deno/issues/31154

This PR implements Node.js-compatible `--require` flag that allows
preloading modules before the main script executes.

Also, ensuring that any module loaded via the `--require` flag is always
treated as CommonJS.

 Example:
    deno run --require ./setup.js --require ./logger.cjs main.ts


## Implementation

  CjsTracker already handles CommonJS detection based on:
  - File extension (.cjs, .cts)
  - package.json "type" field
- IsCjsResolutionMode
(Disabled/ExplicitTypeCommonJs/ImplicitTypeCommonJs)

  This change adds a fourth dimension: explicit --require modules.

  The require_modules list flows through the system:
    CLI flags → CliOptions.require_modules() → ResolverFactoryOptions
    → ResolverFactory → CjsTracker.new(require_modules)

  When CjsTracker.is_maybe_cjs() is called, it now checks:
    1. Is this specifier in require_modules? → Return true (always CJS)
    2. Otherwise, use existing logic (extension, package.json, etc.)

This ensures early exit for --require modules before checking extension
or package.json, guaranteeing CommonJS treatment.
2025-11-24 11:57:28 -03:00
..
mitata.rs fix(bench): Make output table markdown compatible (#29532) 2025-06-24 11:27:42 +02:00
mod.rs feat: add --require run arg to support commonJS (#31201) 2025-11-24 11:57:28 -03:00
reporters.rs chore: update to edition 2024 (#29923) 2025-07-02 17:59:39 -07:00