CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-uglify-save-license

License detector for UglifyJS that identifies and preserves license comments during minification

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-2/

License Comment Filter

Build a command-line tool that processes JavaScript files and identifies which comments would be preserved as license comments during minification.

Requirements

Your tool should accept a JavaScript file path as input and output a JSON array containing all comments that should be preserved based on license detection criteria.

Detection Criteria

A comment should be identified as a license comment if it meets ANY of these conditions:

  1. Contains license-related patterns (case-insensitive):

    • Preservation directives: @preserve, @cc_on
    • License type identifiers: MIT, MPL, GPL, BSD, ISCL
    • Copyright indicators: (c), Copyright, License
  2. Is a block comment starting with ! (e.g., /*! ... */)

  3. Appears on the first line of the file

  4. Appears immediately following another identified license comment (consecutive license blocks)

Output Format

For each identified license comment, output a JSON object with:

  • line: The line number where the comment appears
  • type: The comment type ("line" for // comments, "block" for /* */ comments)
  • value: The comment text content

Test Cases

  • Given a file with a comment containing "MIT License" on line 5, that comment is identified as a license comment @test

  • Given a file with a block comment starting with /*! on line 10, that comment is identified as a license comment @test

  • Given a file where line 1 contains any comment, that comment is identified as a license comment regardless of content @test

  • Given a file with a comment containing "(c) 2024" on line 3 followed by a regular comment on line 4, both comments are identified as license comments @test

Implementation

@generates

API

/**
 * Processes a JavaScript file and identifies license comments
 * @param {string} filePath - Path to the JavaScript file to analyze
 * @returns {Array<{line: number, type: string, value: string}>} Array of identified license comments
 */
function identifyLicenseComments(filePath);

module.exports = { identifyLicenseComments };

Dependencies { .dependencies }

uglify-save-license { .dependency }

Provides license detection functionality for identifying which comments should be preserved during minification.

Install with Tessl CLI

npx tessl i tessl/npm-uglify-save-license

tile.json