@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
31 lines (28 loc) • 934 B
text/typescript
import type core from 'jscodeshift';
import type { Collection } from 'jscodeshift/src/Collection';
/**
* Generate a codemod to move component from Editor to
* EditorMigrationComponent
* Ref: ED-16826
*/
export const createUpdateEditorToMigrationComponent = (pkg: string, component: string) => {
return (j: core.JSCodeshift, source: Collection<unknown>) => {
source
.find(j.ImportDeclaration, { source: { value: pkg } })
.filter(
(path) =>
j(path).find(j.ImportSpecifier, {
imported: { type: 'Identifier', name: component },
}).length > 0,
)
.find(j.ImportSpecifier)
.filter((path) => path.node.imported.name === component)
.replaceWith((currentImport) =>
j.importSpecifier(j.identifier('EditorMigrationComponent'), currentImport.node.local),
);
};
};
export const renameEditorToMigrationComponent = createUpdateEditorToMigrationComponent(
'@atlaskit/editor-core',
'Editor',
);