How to use the tslib/package.json.module function in tslib

To help you get started, we’ve selected a few tslib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ezolenko / rollup-plugin-typescript2 / src / tslib.ts View on Github external
import { readFileSync } from "fs";

// The injected id for helpers.
export const TSLIB = "tslib";
export const TSLIB_VIRTUAL = "\0tslib.js";
export let tslibSource: string;
export let tslibVersion: string;
try
{
	// tslint:disable-next-line:no-string-literal no-var-requires
	const tslibPackage = require("tslib/package.json");
	const tslibPath = require.resolve("tslib/" + tslibPackage.module);
	tslibSource = readFileSync(tslibPath, "utf8");
	tslibVersion = tslibPackage.version;
} catch (e)
{
	console.warn("Error loading `tslib` helper library.");
	throw e;
}