Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
}
like image 296
JGoodgive Avatar asked Oct 17 '18 07:10

JGoodgive


2 Answers

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 } }),
    ...
]
like image 122
ian Avatar answered Nov 14 '22 00:11

ian


Rollup bundles everything that is needed into output files. What you see there are Typescript helpers from tslib module.

You can replace that code (and get rid of MS license) with tslib library imports.

Add to your rollup.config.js following setting: external: ["tslib"]. Unfortunatelly you need to add tslib module to your dependencies (or peerDependencies) to your project.

check following conversations for more details: https://github.com/ezolenko/rollup-plugin-typescript2/issues/58 (about external setting)

https://github.com/ReactiveX/rxjs/issues/2436#issuecomment-371585945 (about issues with dependency vs peerDependency)

and here about helpers: https://mariusschulz.com/blog/external-helpers-library-in-typescript

like image 5
Marek R. Avatar answered Nov 13 '22 23:11

Marek R.