@wroud/di-tools-codemod
Version:
@wroud/di-tools-codemod is a codemod utility that automates the migration of your codebase from Inversify to @wroud/di. It streamlines the transformation process, allowing for effortless and customizable transitions through configuration support.
41 lines • 1.36 kB
JavaScript
import { transformDecorators } from "./transformDecorators.js";
import { transformImports } from "./transformImports.js";
import { addServiceToModule } from "./addServiceToModule.js";
export const parser = "tsx";
export default function transform(file, api, cliOptions) {
const options = {
generateModule: true,
...cliOptions,
transformer: {
esm: false,
...cliOptions?.transformer,
},
};
const j = api.jscodeshift;
const root = j(file.source);
const packages = getSupportedPackages(options);
const replacingPackage = transformImports(j, root, packages);
if (replacingPackage) {
const decoratedClasses = transformDecorators(j, root, replacingPackage);
if (decoratedClasses.length && options.generateModule) {
addServiceToModule(file, j, options.transformer, decoratedClasses, replacingPackage);
}
}
return root.toSource();
}
function getSupportedPackages(options) {
if (options?.supportedPackages) {
return options.supportedPackages;
}
return basePackages;
}
const basePackages = [
{
name: "inversify",
replace: "@wroud/di",
injectableDecorator: "injectable",
injectDecorator: "inject",
multiInjectDecorator: "multiInject",
},
];
//# sourceMappingURL=index.js.map