function uglifyWithCopyrights() {
    const preserveComments = (f) => {
        return (_node, comment) => {
            const text = comment.value;
            const type = comment.type;
            if (/@minifier_do_not_preserve/.test(text)) {
                return false;
            }
            const isOurCopyright = IS_OUR_COPYRIGHT_REGEXP.test(text);
            if (isOurCopyright) {
                if (f.__hasOurCopyright) {
                    return false;
                }
                f.__hasOurCopyright = true;
                return true;
            }
            if ('comment2' === type) {
                // check for /*!. Note that text doesn't contain leading /*
                return (text.length > 0 && text[0] === '!') || /@preserve|license|@cc_on|copyright/i.test(text);
            }
            else if ('comment1' === type) {
                return /license|copyright/i.test(text);
            }
            return false;
        };
    };
    const minify = composer(uglifyes);
    const input = es.through();
    const output = input
        .pipe(flatmap((stream, f) => {
        return stream.pipe(minify({
            output: {
                comments: preserveComments(f),
                max_line_len: 1024
            }
        }));
    }));
    return es.duplex(input, output);
}
function uglifyWithCopyrights() {
    const preserveComments = (f) => {
        return (_node, comment) => {
            const text = comment.value;
            const type = comment.type;
            if (/@minifier_do_not_preserve/.test(text)) {
                return false;
            }
            const isOurCopyright = IS_OUR_COPYRIGHT_REGEXP.test(text);
            if (isOurCopyright) {
                if (f.__hasOurCopyright) {
                    return false;
                }
                f.__hasOurCopyright = true;
                return true;
            }
            if ('comment2' === type) {
                // check for /*!. Note that text doesn't contain leading /*
                return (text.length > 0 && text[0] === '!') || /@preserve|license|@cc_on|copyright/i.test(text);
            }
            else if ('comment1' === type) {
                return /license|copyright/i.test(text);
            }
            return false;
        };
    };
    const minify = composer(uglifyes);
    const input = es.through();
    const output = input
        .pipe(flatmap((stream, f) => {
        return stream.pipe(minify({
            output: {
                comments: preserveComments(f),
                max_line_len: 1024
            }
        }));
    }));
    return es.duplex(input, output);
}
function uglifyWithCopyrights ( ) { const preserveComments = ( f ) => { return ( _node , comment ) => { const text = comment . value ; const type = comment . type ; if ( / @minifier_do_not_preserve / . test ( text ) ) { return false ; } const isOurCopyright = IS_OUR_COPYRIGHT_REGEXP . test ( text ) ; if ( isOurCopyright ) { if ( f . __hasOurCopyright ) { return false ; } f . __hasOurCopyright = true ; return true ; } if ( 'comment2' === type ) { // check for /*!. Note that text doesn't contain leading /* return ( text . length > 0 && text [ 0 ] === '!' ) || / @preserve|license|@cc_on|copyright / i . test ( text ) ; } else if ( 'comment1' === type ) { return / license|copyright / i . test ( text ) ; } return false ; } ; } ; const minify = composer ( uglifyes ) ; const input = es . through ( ) ; const output = input . pipe ( flatmap ( ( stream , f ) => { return stream . pipe ( minify ( { output : { comments : preserveComments ( f ) , max_line_len : 1024 } } ) ) ; } ) ) ; return es . duplex ( input , output ) ; }
Wrap around uglify and allow the preserveComments function
to have a file "context" to include our copyright only once per file.
Wrap around uglify and allow the preserveComments function to have a file context to include our copyright only once per file .
Uglify with copyright comments