or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-6/

CommonJS Module Reexport Analyzer

Build a tool that analyzes CommonJS JavaScript files to identify which modules are being reexported. This is useful for understanding module dependency chains and detecting proxy modules in a codebase.

Requirements

Your tool should analyze JavaScript source code files and identify all module reexports - cases where a module directly forwards another module's exports without modification.

Core Functionality

Create a function that:

  1. Accepts a JavaScript source code string as input
  2. Detects patterns where modules reexport other modules (e.g., module.exports = require('./other'))
  3. Returns a list of all detected reexport targets (the module specifiers being reexported)
  4. Handles various reexport patterns including:
    • Direct reexports
    • Reexports within object spreads
    • Conditional reexports

Input/Output Format

  • Input: A string containing JavaScript source code
  • Output: An array of strings representing the module specifiers being reexported

Edge Cases

  • Empty source code should return an empty array
  • Source code with no reexports should return an empty array
  • Source code with multiple reexport patterns should capture all reexport targets

Implementation

@generates

API

/**
 * Analyzes JavaScript source code to detect module reexports
 * @param {string} sourceCode - The JavaScript source code to analyze
 * @returns {string[]} Array of module specifiers being reexported
 */
function analyzeReexports(sourceCode) {
  // Implementation here
}

module.exports = { analyzeReexports };

Test Cases

  • When given source code with a direct reexport module.exports = require('./utils'), it returns ['./utils'] @test

  • When given source code with object spread reexports module.exports = { ...require('lodash'), ...require('./helpers') }, it returns ['lodash', './helpers'] @test

  • When given source code with no reexports (only named exports like exports.foo = 'bar'), it returns an empty array @test

  • When given empty source code, it returns an empty array @test

Dependencies { .dependencies }

cjs-module-lexer { .dependency }

Provides CommonJS module lexical analysis capabilities for detecting exports and reexports from JavaScript source code.