How to handle Copyright notice in javascript bundle?
Asked Answered
M

3

9

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;
}
Mindamindanao answered 17/10, 2018 at 7:55 Comment(0)
P
14

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 } }),
    ...
]
Precritical answered 20/10, 2020 at 2:44 Comment(0)
B
5

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

Bucko answered 5/9, 2019 at 14:35 Comment(0)
T
0

@JGoodgive,

You could potentially add your own custom license above every JavaScript file you create so when its bundled up together, your license file should show above your JS code.

/*! *****************************************************************************
Copyright (c) <Author>. All rights reserved.
<Custom license text here>
***************************************************************************** */

// Your JS code below your custom license 
Theadora answered 10/5, 2019 at 13:24 Comment(1)
This not works here, something alternative to external: ["tslib"]?Leif

© 2022 - 2024 — McMap. All rights reserved.