License detector for UglifyJS that identifies and preserves license comments during minification
Overall
score
98%
Build a command-line tool that processes JavaScript files and identifies which comments would be preserved as license comments during minification.
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.
A comment should be identified as a license comment if it meets ANY of these conditions:
Contains license-related patterns (case-insensitive):
@preserve, @cc_onMIT, MPL, GPL, BSD, ISCL(c), Copyright, LicenseIs a block comment starting with ! (e.g., /*! ... */)
Appears on the first line of the file
Appears immediately following another identified license comment (consecutive license blocks)
For each identified license comment, output a JSON object with:
line: The line number where the comment appearstype: The comment type ("line" for // comments, "block" for /* */ comments)value: The comment text contentGiven 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
@generates
/**
* 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 };Provides license detection functionality for identifying which comments should be preserved during minification.
Install with Tessl CLI
npx tessl i tessl/npm-uglify-save-licensedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10