@atlaskit/codemod-utils
Advanced tools
Comparing version
# @atlaskit/codemod-utils | ||
## 3.4.0 | ||
### Minor Changes | ||
- [`cf853e39278`](https://bitbucket.org/atlassian/atlassian-frontend/commits/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 | ||
@@ -4,0 +10,0 @@ |
@@ -108,2 +108,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "hasImportDeclarationFromAnyPackageEntrypoint", { | ||
enumerable: true, | ||
get: function get() { | ||
return _support.hasImportDeclarationFromAnyPackageEntrypoint; | ||
} | ||
}); | ||
Object.defineProperty(exports, "addCommentBefore", { | ||
@@ -110,0 +116,0 @@ enumerable: true, |
@@ -15,3 +15,3 @@ "use strict"; | ||
exports.getSafeImportName = getSafeImportName; | ||
exports.addDynamicImport = exports.getDynamicImportName = exports.testMethodVariantEach = exports.callExpressionArgMatchesString = exports.debug = exports.isEmpty = exports.shiftDefaultImport = exports.doesIdentifierExist = exports.addCommentToStartOfFile = exports.hasImportDeclaration = exports.hasJSXAttributesByName = exports.getJSXAttributesByName = exports.getDefaultSpecifier = void 0; | ||
exports.addDynamicImport = exports.getDynamicImportName = exports.testMethodVariantEach = exports.callExpressionArgMatchesString = exports.debug = exports.isEmpty = exports.shiftDefaultImport = exports.doesIdentifierExist = exports.addCommentToStartOfFile = exports.hasImportDeclarationFromAnyPackageEntrypoint = exports.hasImportDeclaration = exports.hasJSXAttributesByName = exports.getJSXAttributesByName = exports.getDefaultSpecifier = void 0; | ||
@@ -161,2 +161,15 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var hasImportDeclarationFromAnyPackageEntrypoint = function hasImportDeclarationFromAnyPackageEntrypoint(j, source, packageName) { | ||
var imports = source.find(j.ImportDeclaration).filter(function (path) { | ||
var _path$node, _path$node$source; | ||
return (// @ts-ignore | ||
path === null || path === void 0 ? void 0 : (_path$node = path.node) === null || _path$node === void 0 ? void 0 : (_path$node$source = _path$node.source) === null || _path$node$source === void 0 ? void 0 : _path$node$source.value.toString().startsWith(packageName) | ||
); | ||
}); | ||
return Boolean(imports.length); | ||
}; | ||
exports.hasImportDeclarationFromAnyPackageEntrypoint = hasImportDeclarationFromAnyPackageEntrypoint; | ||
var debug = function debug(component) { | ||
@@ -163,0 +176,0 @@ return function (j, source) { |
{ | ||
"name": "@atlaskit/codemod-utils", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"sideEffects": false | ||
} |
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor } from './utils'; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } from './utils/support'; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } from './utils/support'; |
@@ -115,2 +115,13 @@ function getNamedSpecifier(j, source, specifier, importName) { | ||
const hasImportDeclarationFromAnyPackageEntrypoint = (j, source, packageName) => { | ||
const imports = source.find(j.ImportDeclaration).filter(path => { | ||
var _path$node, _path$node$source; | ||
return (// @ts-ignore | ||
path === null || path === void 0 ? void 0 : (_path$node = path.node) === null || _path$node === void 0 ? void 0 : (_path$node$source = _path$node.source) === null || _path$node$source === void 0 ? void 0 : _path$node$source.value.toString().startsWith(packageName) | ||
); | ||
}); | ||
return Boolean(imports.length); | ||
}; | ||
const debug = component => (j, source) => { | ||
@@ -249,2 +260,2 @@ const defaultSpecifier = getDefaultSpecifier(j, source, component); | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport }; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport }; |
{ | ||
"name": "@atlaskit/codemod-utils", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"sideEffects": false | ||
} |
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor } from './utils'; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } from './utils/support'; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } from './utils/support'; |
@@ -131,2 +131,13 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
var hasImportDeclarationFromAnyPackageEntrypoint = function hasImportDeclarationFromAnyPackageEntrypoint(j, source, packageName) { | ||
var imports = source.find(j.ImportDeclaration).filter(function (path) { | ||
var _path$node, _path$node$source; | ||
return (// @ts-ignore | ||
path === null || path === void 0 ? void 0 : (_path$node = path.node) === null || _path$node === void 0 ? void 0 : (_path$node$source = _path$node.source) === null || _path$node$source === void 0 ? void 0 : _path$node$source.value.toString().startsWith(packageName) | ||
); | ||
}); | ||
return Boolean(imports.length); | ||
}; | ||
var debug = function debug(component) { | ||
@@ -282,2 +293,2 @@ return function (j, source) { | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport }; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport }; |
{ | ||
"name": "@atlaskit/codemod-utils", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"sideEffects": false | ||
} |
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, } from './utils'; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport, } from './utils/support'; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport, } from './utils/support'; |
@@ -1,2 +0,2 @@ | ||
import core, { ASTPath, CallExpression, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSXElement, Program, VariableDeclaration, VariableDeclarator } from 'jscodeshift'; | ||
import core, { ASTPath, CallExpression, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSXAttribute, JSXElement, Program, VariableDeclaration, VariableDeclarator } from 'jscodeshift'; | ||
import { Collection } from 'jscodeshift/src/Collection'; | ||
@@ -14,5 +14,6 @@ declare function getNamedSpecifier(j: core.JSCodeshift, source: Collection<Node>, specifier: string, importName: string): string | null; | ||
declare const getDefaultSpecifier: (j: core.JSCodeshift, source: Collection<Node>, specifier: string) => string | null; | ||
declare const getJSXAttributesByName: any; | ||
declare const getJSXAttributesByName: (j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) => Collection<JSXAttribute>; | ||
declare const isEmpty: any; | ||
declare const hasImportDeclaration: (j: core.JSCodeshift, source: Collection<Node>, importPath: string) => boolean; | ||
declare const hasImportDeclarationFromAnyPackageEntrypoint: (j: core.JSCodeshift, source: Collection<Node>, packageName: string) => boolean; | ||
declare const debug: (component: string) => (j: core.JSCodeshift, source: Collection<Node>) => void; | ||
@@ -34,2 +35,2 @@ declare const callExpressionArgMatchesString: (arg: CallExpression['arguments'][number], str: string) => boolean; | ||
}): string; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport, }; | ||
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport, }; |
{ | ||
"name": "@atlaskit/codemod-utils", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"author": "Atlassian Pty Ltd", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
84664
3.98%1581
2.26%