typescriptbundling-and-minificationrollupjscopyright-display

How to handle Copyright notice in javascript bundle?


I was writing a couple of small demos to explain decorators (in typescript) to colleagues when I noticed that my bundle had a Microsoft Copyright notice that kind of make my entire file free for all (and made by MS).

How should this be handled effectivly (if I create something that isn't free)?

I used Typescript 3.1 to compile and rollup for bundling.

code:

import { isNotUndefined, isNotNullOrUndefined } from "goodcore/Test";

function deprecated<S>(instead?: string, message?: string) {
    // Logic removed for brevity...
}

class Car {
    @deprecated()
    public turnIgnitionKey() {
        this.start();
    }
    public pressStartButton() {
        this.start();
    }
    private start() {
        console.log("Running!");
    }
}

let car = new Car();
car.turnIgnitionKey();
car.pressStartButton();

and bundle beginning (where the last function is mine and those before are MS):

'use strict';

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

function __decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}

function __metadata(metadataKey, metadataValue) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}

function isNullOrUndefined(arg) {
    return arg === undefined || arg === null;
}

Solution

  • I added rollup-plugin-terser in my rollup config and set comments to false so all comments are removed.

    ...
    import { terser } from 'rollup-plugin-terser';
    ...
    plugins: [
        ...
        terser({ format: { comments: false } }),
        ...
    ]