mirror of
https://github.com/denoland/deno.git
synced 2025-12-23 08:48:24 +00:00
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. |
||
|---|---|---|
| .. | ||
| mitata.rs | ||
| mod.rs | ||
| reporters.rs | ||