tslib icon indicating copy to clipboard operation
tslib copied to clipboard

Add 'tslib.umd.js' to avoid global pollution

Open rbuckton opened this issue 7 years ago • 5 comments

This adds a tslib.cjs.js file as the package main to reduce the impact of global variable pollution, as well as some additional variants. Also, in an effort to avoid redundancy between each variant, this adds a script to generate all files from a single source.

This also leaves tslib.js as is as it still has a use case to support both --importHelpers for modules and scripts (which depend on the helpers being available as globals).

Fixes: #32

rbuckton avatar May 13 '18 02:05 rbuckton

This also paves the way for the possibility of supporting #33 as the generator script can be easily modified to emit each helper into its own file (current progress can be seen in https://github.com/Microsoft/tslib/tree/oneHelperPerFile).

rbuckton avatar May 13 '18 02:05 rbuckton

I've updated this to support multiple variants:

  • tslib.js - A bundle of all helpers that supports both CommonJS and AMD modules as well as adds global (for use with <script></script> tags).
  • tslib.umd.js - A bundle of all helpers that supports both CommonJS and AMD modules, but does not add global variables.
  • tslib.cjs.js - A bundle of all helpers that supports only CommonJS (this is the default variant used as "main" in package.json).
  • tslib.amd.js - A bundle of all helpers that supports only AMD.
  • tslib.es6.js - A bundle of all helpers that supports ECMAScript module syntax.
  • tslib.global.js - A bundle of all helpers that only adds globals (for use with <script></script> tags).

rbuckton avatar May 14 '18 20:05 rbuckton

@DanielRosenwasser If we end up taking this, should I also emit a copy of tslib.es6.js as tslib.mjs?

rbuckton avatar May 14 '18 20:05 rbuckton

Any action on this, global window pollution is a real problem

slaneyrw avatar Nov 21 '18 03:11 slaneyrw

Any news on this?

Clashsoft avatar Oct 02 '20 10:10 Clashsoft