Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@atlaskit/codemod-utils

atlassian237.7kApache-2.04.2.4TypeScript support: included

jscodeshift-compatible codemod utilities

readme

Home for codemods

As part of lite mode conversion for components in atlaskit, we found codemods with jscodeshift are extremely helpful for migrating some breaking changes for our consumers. However, one pain point for us who need to write and maintain them is that we have to copy-paste the code snippet in many places.

So the purpose of this package is to relief that pain and centric all reusable codemods snippets into a single place, and all the further changes should happen in this repo only.

The goal is to release this repo as a npm package, so our users can simply introduce those generic functions and compose in their codebase.

Examples

For example, when you want to depracate a prop called isLoading from your consumer's codebase, you can introduce some helper function into a file transformer.ts from @atlaskit/codemod-utils:

import {
  createRemoveFuncFor,
  createTransformer,
} from '@atlaskit/codemod-utils';

const removeIsLoading = createRemoveFuncFor(
  '@atlaskit/fancycomponent',
  'ComponentName',
  'isLoading',
);

const transformer = createTransformer([removeIsLoading]);

export default transformer;

And then run the transformer like:

npx jscodeshift -t transformer.ts  --ignore-pattern node_modules --parser babel --extensions ts path/to/your/codebase

Advanced usage

If you need more than one mutation against your codebase and want to apply all of them in one go, it's recommended to structure them properly into a separate folder.

For example, if you need 3 separate steps:

  • remove isLoading prop
  • rename isDefaultChecked to defaultChecked
  • add a new prop title

then you can have a folder called migrates that contains:

  • remove-isLoading.ts
  • rename-isDefaultChecked-to-defaultChecked.ts
  • add-title.ts

and for each file, you can have some code like:

import { createAddingPropFor } from '@atlaskit/codemod-utils';

export const addTitle = createAddingPropFor('@atlaskit/fancycomponent', {
  prop: 'title',
  defaultValue: '',
});

and in your entrypoint for jscodeshift to pick up, you can introduce all those migrates:

import { addTitle } from './migrates/add-title';
import { removeIsLoading } from './migrates/remove-isLoading';
import { renameDefaultChecked } from './migrates/rename-isDefaultChecked-to-defaultChecked.ts';

import { createTransformer } from './utils';

const transformer = createTransformer([
  renameDefaultChecked,
  removeIsLoading,
  addTitle,
]);

export default transformer;

This way, you can easily test those migrates separately with all the possible scenario, and compose them freely as well to see if they can work together to make the whole transform.

changelog

@atlaskit/codemod-utils

4.2.4

Patch Changes

4.2.3

Patch Changes

4.2.2

Patch Changes

4.2.1

Patch Changes

4.2.0

Minor Changes

4.1.3

Patch Changes

4.1.2

Patch Changes

4.1.1

Patch Changes

  • #23836 edc6fef0c8f - Fix printf format specifier matching within matchesStringWithFormatSpecifier for fuzzy matching interpolated placeholder values

4.1.0

Minor Changes

  • #21570 e4624adcb2f - ED-14608: Update codemod-utils to support type import entry point changes in changeImportEntryPoint, remove adf-utils from repo stricter lint exclusion lists

4.0.2

Patch Changes

  • #21152 9358d42eeaa - NO-ISSUE: fixed codemod utils tryCreateImport() and addToImport() causing multiple insert in certain scenarios

4.0.1

Patch Changes

4.0.0

Major Changes

  • #20033 b29ce16dad8 - [ED-14606] Move bitbucket schema, confluence schema, jira schema, and default schema from @atlaskit/adf-schema to their own entry points. These new entry points are as follows

    @atlaskit/adf-schema/schema-bitbucket for:

    • bitbucketSchema

    @atlaskit/adf-schema/schema-confluence for:

    • confluenceSchema
    • confluenceSchemaWithMediaSingle

    @atlaskit/adf-schema/schema-jira for:

    • default as createJIRASchema
    • isSchemaWithLists
    • isSchemaWithMentions
    • isSchemaWithEmojis
    • isSchemaWithLinks
    • isSchemaWithAdvancedTextFormattingMarks
    • isSchemaWithCodeBlock
    • isSchemaWithBlockQuotes
    • isSchemaWithMedia
    • isSchemaWithSubSupMark
    • isSchemaWithTextColor
    • isSchemaWithTables

    @atlaskit/adf-schema/schema-default for:

    • defaultSchema
    • getSchemaBasedOnStage
    • defaultSchemaConfig

    This change also includes codemods in @atlaskit/adf-schema to update these entry points. It also introduces a new util function "changeImportEntryPoint" to @atlaskit/codemod-utils to handle this scenario.

3.4.0

Minor Changes

  • #14319 cf853e39278 - Adds new util hasImportDeclarationFromAnyPackageEntrypoint. It works just like hasImportDeclaration, but instead of searching for an import declaration that has strict equality with a supplied import path (e.g. @atlaskit/theme), it looks for an import declaration that starts with the supplied import path. With that same example, it will match both @atlaskit/theme and @atlaskit/theme/typography — making it easy to choose to run a codemod on a usage regardless of the way in which it was imported.

3.3.0

Minor Changes

  • #13864 9729143f07b - Add support functions getDynamicImportName, isCallExpressionCalleeImportType, isCallExpressionArgumentStringLiteralType, isCallExpressionArgumentValueMatches and addDynamicImport.

3.2.2

Patch Changes

3.2.1

Patch Changes

  • #11911 d0ef46dee01 - Removes ts-node / cjs bundle switcher from main entrypoint of codemod-utils and updated codemod-cli scripts to support

3.2.0

Minor Changes

Patch Changes

3.1.0

Minor Changes

  • #10787 2ec9e608acc - Update addCommentBefore helper method to:

    • Make the message prefix optional.
      • The default remains as TODO: (from codemod) for backwards compatibility
    • Support both block & line comment output.
      • The default remains as block for backwards compatibility

3.0.0

Major Changes

  • #10179 284a374eed8 - Removed createSkipTest & createSkipTestTransformer transformer from the API. This is a breaking change!

    If you rely on this transformer, you can now depend on it via a new package @af/skip-inconsistent-tests.

2.2.1

Patch Changes

  • #9756 1300c88e2cc - Add shouldApplyTransform to createTransformer so there is a check before transforms are run.
  • 1b6bf93be84 - Migrate helper functions into codemod-utils

2.2.0

Minor Changes

  • #9940 2474e09dc7f - Add new method to create a custom Transformer for skip test

2.1.2

Patch Changes

2.1.1

Patch Changes

2.1.0

Minor Changes

  • #8169 7e295f4d9da - Added more lower level helpers for writing codemod:

    • getDefaultSpecifier
    • getNamedSpecifier
    • hasJSXAttributesByName
    • hasImportDeclaration
    • addCommentBefore
    • addCommentToStartOfFile
    • callExpressionArgMatchesString
    • testMethodVariantEach

    They are used quite frequently as basic build blocks, so export them to consumers.

2.0.1

Patch Changes

2.0.0

Major Changes