CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-coffeescript

tessl install tessl/npm-coffeescript@2.7.0

A programming language that compiles into JavaScript, offering more concise and readable syntax while maintaining full JavaScript compatibility.

Agent Success

Agent success rate when using this tile

77%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.01x

Baseline

Agent success rate without this tile

76%

task.mdevals/scenario-9/

Multi-Extension Module Loader

Create a module loader utility that enables Node.js to require files with multi-dot extensions (e.g., .spec.js, .config.json, .test.ts).

Problem

Node.js's module system only recognizes the last extension in a filename. For example, with a file named config.production.json, Node.js only sees .json and doesn't recognize .production.json as a valid extension handler. This limitation prevents custom extension handlers from working with multi-dot filenames.

Your task is to implement a module loader that patches Node.js's module loading mechanism to support multi-dot extensions.

Requirements

Core Functionality

The loader must:

  1. Register custom extension handlers for multi-dot extensions (e.g., .test.js, .config.json)
  2. Correctly resolve and load files with multi-dot extensions when using require()
  3. Check all possible extension combinations, starting from the longest to shortest
  4. Fall back to Node.js's default behavior for single-dot extensions
  5. Maintain compatibility with existing single-extension handlers

Behavior

  • When requiring a file ./config.production.json, the loader should first check if .production.json has a registered handler, then check .json
  • Extension handlers should receive the module and filename and be responsible for loading the module's content
  • The loader should not break existing Node.js module loading functionality

Test Cases

  • Registering and using a .test.js extension handler successfully loads a file named example.test.js @test
  • When a file has multiple dot extensions, the loader tries the longest extension first, then progressively shorter ones @test
  • Files with single-dot extensions continue to work with Node.js's default handlers @test
  • Requiring a file with an unregistered multi-dot extension falls back to checking the shorter extension @test

Implementation

@generates

API

/**
 * Registers a custom handler for a multi-dot extension.
 *
 * @param {string} extension - The extension to register (e.g., '.test.js', '.config.json')
 * @param {function} handler - Function that takes (module, filename) and loads the content
 */
function registerExtension(extension, handler) {
  // IMPLEMENTATION HERE
}

/**
 * Patches Node.js's module system to support multi-dot extensions.
 * Must be called before requiring any files with multi-dot extensions.
 */
function patchModuleLoader() {
  // IMPLEMENTATION HERE
}

module.exports = {
  registerExtension,
  patchModuleLoader
};

Dependencies { .dependencies }

coffeescript { .dependency }

Provides CoffeeScript compilation and module loading capabilities.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coffeescript@2.7.x
tile.json