Skip to content
forked from microsoft/tslib

Hotfix to make Jest work with ESM projects and tslib

License

Notifications You must be signed in to change notification settings

StratoKit/tslib

 
 

Repository files navigation

tslib

this is a patched version of microsoft/tslib to make Jest work in ESM-enabled projects that include tslib somehow.

The problem is that Jest will parse the tslib.js file and it can't figure out the factory pattern and decides that there are no exports. See microsoft#173

The workaround is to manually set all the exports.

To use this, convince you package manager to use https://github.com/StratoKit/tslib.git as the version for tslib.

We use pnpm and we have a .pnpmfile.cjs like:

// eslint-disable-next-line max-params
const replace = (pkg, context, name, version, regex) => {
	const dep = pkg.dependencies[name]
	if (dep && (!regex || regex.test(dep))) {
		pkg.dependencies[name] = version
		context.log(`replacing ${pkg.name}'s ${name} dep ${dep} with ${version}`)
	}
}
const readPackage = (pkg, context) => {
	if (!pkg.dependencies) return pkg
	replace(pkg, context, 'tslib', 'https://github.com/StratoKit/tslib.git')
	return pkg
}

module.exports = {hooks: {readPackage}}

About

Hotfix to make Jest work with ESM projects and tslib

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.8%
  • HTML 0.2%