Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
compatfactory
Advanced tools
A library that unifies the TypeScript Compiler API factory functions across all versions of TypeScript and makes them conform with the Node Factory API
A library that unifies the TypeScript Compiler API factory functions across all versions of TypeScript and makes them conform with the Node Factory API
TypeScript's Compiler APIs are constantly evolving. With the release of TypeScript 4.0, the TypeScript team announced that they would move away from the old set of factory functions for creating and updating nodes, and over to a new Node Factory API. With the release of TypeScript 5.0, the old factory functions were removed entirely.
Nowadays, if you maintain a library or a tool that needs to work across multiple versions of TypeScript and you use any of TypeScript's Compiler APIs, you're going to have a really tough time. It will be error prone, difficult to read, and hard to maintain. There are many differences between the signatures of these methods across all versions of TypeScript, and many may not even exist.
This library exists to fix this problem. It simply provides a helper function, ensureNodeFactory
, which takes a NodeFactory
or a typescript object, and then returns an object conforming to the NodeFactory
interface.
In case a NodeFactory
is passed to it, or if one could be found via the typescript.factory
property, it will patch any inconsistencies there may be between the signatures of the factory functions across TypeScript versions and most often simply return the existing one with no further edits. For older TypeScript versions, it will
wrap its factory functions with the new API such that you can simply use one API for all your operations! 🎉
$ npm install compatfactory
$ yarn add compatfactory
$ pnpm add compatfactory
compatfactory
depends on typescript
, so you need to manually install this as well.
Simply import ensureNodeFactory
and use it in place of the Node Factory you would otherwise be working with.
One very basic example could be:
import {ensureNodeFactory} from "compatfactory";
// Will use typescript.factory if available, and otherwise return an object that wraps typescript's helper functions
// but makes them conform with the Node Factory API
const factory = ensureNodeFactory(typescript);
factory.createClassDeclaration(/* ... */);
A more realistic example would be inside a Custom Transformer context:
import {ensureNodeFactory} from "compatfactory";
import type TS from "typescript";
function getCustomTransformers(typescript: typeof TS): TS.CustomTransformers {
return {
before: [
context => {
const factory = ensureNodeFactory(context.factory ?? typescript);
return sourceFile => {
return factory.updateSourceFile(
sourceFile
// ...
);
};
}
]
};
}
Do you want to contribute? Awesome! Please follow these recommendations.
Frederik Wessberg Twitter: @FredWessberg Github: @wessberg Lead Developer |
MIT © Frederik Wessberg (@FredWessberg) (Website)
FAQs
A library that unifies the TypeScript Compiler API factory functions across all versions of TypeScript and makes them conform with the Node Factory API
The npm package compatfactory receives a total of 65,872 weekly downloads. As such, compatfactory popularity was classified as popular.
We found that compatfactory demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.