@atlaskit/codemod-cli 0.27.1 → 0.27.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/cli.js +3 -3
- package/dist/cjs/filepath.js +4 -2
- package/dist/cjs/main.js +90 -38
- package/dist/cjs/presets/index.js +2 -1
- package/dist/cjs/presets/migrate-to-link/codemods/migrate-to-link.js +2 -2
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-split-imports.js +1 -1
- package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -2
- package/dist/cjs/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +1 -1
- package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +225 -0
- package/dist/cjs/presets/remove-token-fallbacks/types.js +5 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/all-tokens.js +44 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/color-utils.js +93 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/get-team-info.js +51 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +113 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-imports.js +61 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-variables.js +37 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/reporter.js +310 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/token-processor.js +632 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/update-comments.js +58 -0
- package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +3 -3
- package/dist/cjs/sinceRef.js +2 -1
- package/dist/cjs/transforms.js +3 -1
- package/dist/cjs/types.js +2 -1
- package/dist/es2019/cli.js +3 -3
- package/dist/es2019/filepath.js +4 -2
- package/dist/es2019/main.js +30 -6
- package/dist/es2019/presets/index.js +2 -1
- package/dist/es2019/presets/migrate-to-link/codemods/migrate-to-link.js +2 -3
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +1 -1
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-split-imports.js +2 -2
- package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -2
- package/dist/es2019/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +1 -1
- package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
- package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +130 -0
- package/dist/es2019/presets/remove-token-fallbacks/types.js +1 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/all-tokens.js +30 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/color-utils.js +84 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/get-team-info.js +22 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +104 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-imports.js +51 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/reporter.js +118 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/token-processor.js +377 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/update-comments.js +46 -0
- package/dist/es2019/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +1 -1
- package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +3 -3
- package/dist/es2019/sinceRef.js +2 -1
- package/dist/es2019/transforms.js +3 -1
- package/dist/es2019/types.js +2 -1
- package/dist/esm/cli.js +3 -3
- package/dist/esm/filepath.js +4 -2
- package/dist/esm/main.js +91 -39
- package/dist/esm/presets/index.js +2 -1
- package/dist/esm/presets/migrate-to-link/codemods/migrate-to-link.js +2 -3
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-remove-unsafe-size.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-split-imports.js +2 -2
- package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +2 -2
- package/dist/esm/presets/migrate-to-new-buttons/utils/add-comment-for-custom-theme-buttons.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +1 -1
- package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +215 -0
- package/dist/esm/presets/remove-token-fallbacks/types.js +1 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/all-tokens.js +38 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/color-utils.js +86 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/get-team-info.js +44 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +107 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-imports.js +55 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/reporter.js +302 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/token-processor.js +625 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/update-comments.js +51 -0
- package/dist/esm/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +1 -1
- package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +3 -3
- package/dist/esm/sinceRef.js +2 -1
- package/dist/esm/transforms.js +3 -1
- package/dist/esm/types.js +2 -1
- package/dist/types/filepath.d.ts +3 -1
- package/dist/types/main.d.ts +1 -1
- package/dist/types/presets/index.d.ts +1 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.d.ts +1 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +1 -1
- package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
- package/dist/types/presets/remove-token-fallbacks/types.d.ts +39 -0
- package/dist/types/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
- package/dist/types/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
- package/dist/types/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
- package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
- package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
- package/dist/types/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
- package/dist/types/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
- package/dist/types/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
- package/dist/types/presets/styled-to-emotion/styled-to-emotion.d.ts +1 -1
- package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +1 -1
- package/dist/types/sinceRef.d.ts +2 -1
- package/dist/types/transforms.d.ts +3 -1
- package/dist/types/types.d.ts +3 -2
- package/dist/types-ts4.5/filepath.d.ts +3 -1
- package/dist/types-ts4.5/main.d.ts +1 -1
- package/dist/types-ts4.5/presets/index.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.d.ts +1 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/move-icon-value-from-link-button-to-link-children.d.ts +1 -1
- package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/types.d.ts +39 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
- package/dist/types-ts4.5/presets/styled-to-emotion/styled-to-emotion.d.ts +1 -1
- package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +1 -1
- package/dist/types-ts4.5/sinceRef.d.ts +2 -1
- package/dist/types-ts4.5/transforms.d.ts +3 -1
- package/dist/types-ts4.5/types.d.ts +3 -2
- package/package.json +8 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getImportDeclaration, hasImportDeclaration, insertImportSpecifier } from '@codeshift/utils';
|
|
2
2
|
import { colorReplacements } from './utils/replacements';
|
|
3
3
|
function isDecendantOfType(j, path, type) {
|
|
4
4
|
return j(path).closest(type).length > 0;
|
|
@@ -4,13 +4,13 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
5
5
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
6
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
|
-
import {
|
|
7
|
+
import { updateAutoScroll } from './transformers/auto-scroll';
|
|
8
|
+
import { shiftCanMonitorArgType } from './transformers/element-adapter-types';
|
|
8
9
|
import { moveFromFileAdapterToExternalAdapter } from './transformers/external-adapter';
|
|
9
10
|
import { moveToReactDropIndicator } from './transformers/move-to-react-drop-indicator';
|
|
10
|
-
import { updateAutoScroll } from './transformers/auto-scroll';
|
|
11
11
|
import { shiftToPointerOutsideOfPreview } from './transformers/pointer-outside-of-preview';
|
|
12
12
|
import { shiftToPreventUnhandled } from './transformers/prevent-unhandled';
|
|
13
|
-
import {
|
|
13
|
+
import { updateSafeImports } from './transformers/update-safe-imports';
|
|
14
14
|
var transformers = [updateSafeImports, moveFromFileAdapterToExternalAdapter, moveToReactDropIndicator, updateAutoScroll, shiftToPointerOutsideOfPreview, shiftToPreventUnhandled, shiftCanMonitorArgType];
|
|
15
15
|
export default function transformer(file, api) {
|
|
16
16
|
var source = file.source;
|
package/dist/esm/sinceRef.js
CHANGED
|
@@ -16,7 +16,8 @@ var parseDiffLine = function parseDiffLine(line) {
|
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Returns packages that have been upgraded in package.json since ref. The version refers to their previous
|
|
20
21
|
* version
|
|
21
22
|
*/
|
|
22
23
|
export var getPackagesSinceRef = /*#__PURE__*/function () {
|
package/dist/esm/transforms.js
CHANGED
|
@@ -13,7 +13,9 @@ export var hasTransform = function hasTransform(transformPath) {
|
|
|
13
13
|
return globSync(transformPath).length > 0;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves transforms for `packages` if provided, otherwise all transforms including presets
|
|
18
|
+
*/
|
|
17
19
|
export var getTransforms = function getTransforms(packages) {
|
|
18
20
|
var transforms = [path.join(basePath(packages), '*.@(ts|tsx|js)'), path.join(basePath(packages), '*', 'index.@(ts|tsx|js)')];
|
|
19
21
|
if (!packages) {
|
package/dist/esm/types.js
CHANGED
|
@@ -6,7 +6,8 @@ import _inherits from "@babel/runtime/helpers/inherits";
|
|
|
6
6
|
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
7
7
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
8
8
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Converts required args to optional if they have a default
|
|
10
11
|
* Example: export type UserFlags = Default<Flags, keyof typeof defaultFlags>;
|
|
11
12
|
*/
|
|
12
13
|
|
package/dist/types/filepath.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Return products packages filePaths for running codemods from specified dependent package
|
|
3
|
+
*/
|
|
2
4
|
export declare function findDependentPackagePaths(crawlPaths: string[], dependencyPackage: string): Promise<string[]>;
|
package/dist/types/main.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ import './migrate-to-link/migrate-to-link';
|
|
|
8
8
|
import './migrate-to-new-buttons/migrate-to-new-buttons';
|
|
9
9
|
import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
|
|
10
10
|
import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
11
|
+
import './remove-token-fallbacks/remove-token-fallbacks';
|
|
11
12
|
declare const presets: string[];
|
|
12
13
|
export default presets;
|
package/dist/types/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Collection, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSCodeshift } from 'jscodeshift';
|
|
2
2
|
export declare const importTypesFromNewEntryPoint: (buttonImports: Collection<ImportDeclaration>, specifiers: (ImportDefaultSpecifier | ImportSpecifier)[], j: JSCodeshift, fileSource: Collection<any>) => (ImportDefaultSpecifier | ImportSpecifier)[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type API, type ASTPath, type JSXElement, type JSXExpressionContainer } from 'jscodeshift';
|
|
2
2
|
declare const moveIcon: (j: API['jscodeshift'], path: ASTPath<JSXElement>, iconNode: JSXExpressionContainer | undefined | null, beforeOrAfter: 'iconBefore' | 'iconAfter') => void;
|
|
3
3
|
export default moveIcon;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { API, FileInfo } from 'jscodeshift';
|
|
2
|
+
import { RemoveTokenFallbackOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms the source code of a file by removing fallback values from the @atlaskit/tokens/token functions.
|
|
5
|
+
* By default removes only the fallbacks that have the same values as the tokens.
|
|
6
|
+
*
|
|
7
|
+
* @param {FileInfo} fileInfo - Information about the file to be transformed.
|
|
8
|
+
* @param {API} api - The jscodeshift API, providing utilities for AST transformations.
|
|
9
|
+
* @param {RemoveTokenFallbackOptions} options - Options for the transformation, including:
|
|
10
|
+
* @param {boolean} [options.verbose] - If true, enables verbose logging.
|
|
11
|
+
* @param {boolean} [options.forceUpdate] - If true, removes the fallbacks regardless of the difference between token and fallback. Otherwise removes only the fallbacks that are equal to the token values.
|
|
12
|
+
* @param {boolean} [options.addEslintComments] - If true, adds the eslint ignore comment for the rule @atlaskit/design-system/no-unsafe-design-token-usage for the fallbacks that weren't removed.
|
|
13
|
+
* @param {boolean} [options.useLegacyColorTheme] - If true, uses the legacy theme for color token mapping.
|
|
14
|
+
* @param {string} [options.reportFolder] - Directory path to output transformation reports. Reports will be generated only if this option is provided.
|
|
15
|
+
* @param {boolean} [options.dry] - If true, performs a dry run without modifying the files.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Promise<string>} A promise that resolves to the transformed source code as a string.
|
|
18
|
+
*/
|
|
19
|
+
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: RemoveTokenFallbackOptions): Promise<string>;
|
|
20
|
+
export declare const parser = "tsx";
|
|
21
|
+
/**
|
|
22
|
+
* Function executed before all transformations to prepare the environment by clearing the report folder.
|
|
23
|
+
*/
|
|
24
|
+
export declare function beforeAll(options: RemoveTokenFallbackOptions): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
|
|
27
|
+
* It also applies prettier to the affected files.
|
|
28
|
+
*/
|
|
29
|
+
export declare function afterAll(options: RemoveTokenFallbackOptions): Promise<void>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ASTPath, ImportDeclaration, Options, VariableDeclarator } from 'jscodeshift';
|
|
2
|
+
export interface ReplacementDetail {
|
|
3
|
+
teamInfo: TeamInfo;
|
|
4
|
+
filePath: string;
|
|
5
|
+
lineNumber: number;
|
|
6
|
+
tokenKey: string;
|
|
7
|
+
rawFallbackValue: string;
|
|
8
|
+
resolvedTokenValue: string;
|
|
9
|
+
resolvedFallbackValue: string;
|
|
10
|
+
difference?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface TransformationDetails {
|
|
13
|
+
replaced: ReplacementDetail[];
|
|
14
|
+
notReplaced: ReplacementDetail[];
|
|
15
|
+
}
|
|
16
|
+
export type TeamInfo = {
|
|
17
|
+
packageName: string;
|
|
18
|
+
teamName: string;
|
|
19
|
+
};
|
|
20
|
+
export type RemoveTokenFallbackOptions = Options & {
|
|
21
|
+
useLegacyColorTheme?: boolean;
|
|
22
|
+
reportFolder?: string;
|
|
23
|
+
addEslintComments?: boolean;
|
|
24
|
+
forceUpdate?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type WithResolvedDeclarations = {
|
|
27
|
+
resolvedImportDeclaration?: ASTPath<ImportDeclaration>;
|
|
28
|
+
resolvedLocalVarDeclaration?: ASTPath<VariableDeclarator>;
|
|
29
|
+
};
|
|
30
|
+
export type FallbackResolveResult = WithResolvedDeclarations & {
|
|
31
|
+
rawFallbackValue: string;
|
|
32
|
+
fallbackValue: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
export type WithStart = {
|
|
35
|
+
start?: number;
|
|
36
|
+
};
|
|
37
|
+
export type TokenProcessingResult = WithResolvedDeclarations & {
|
|
38
|
+
fallbackRemoved: boolean;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTokenMap(useLegacyTheme?: boolean): Record<string, string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TeamInfo } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Looks for the closest package.json and gets team and package information from it.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} filePath
|
|
6
|
+
* @returns {Promise<AtlassianTeamInfo>}
|
|
7
|
+
*/
|
|
8
|
+
export declare const getTeamInfo: (filePath: string) => Promise<TeamInfo>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function normalizeValues(tokenKey: string, tokenValue: string | undefined, fallbackValue: string | undefined): {
|
|
2
|
+
difference?: number;
|
|
3
|
+
isAcceptableDifference?: boolean;
|
|
4
|
+
tokenLogValue: string;
|
|
5
|
+
fallbackLogValue: string;
|
|
6
|
+
normalizedTokenValue: string | undefined;
|
|
7
|
+
normalizedFallbackValue: string | undefined;
|
|
8
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TransformationDetails } from '../types';
|
|
2
|
+
export declare function clearFolder(reportFolder: string): Promise<void>;
|
|
3
|
+
export declare function combineReports(reportFolder: string): Promise<void>;
|
|
4
|
+
export declare function writeReports(details: TransformationDetails, reportFolder: string): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ASTPath, CallExpression, Collection, FileInfo, JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { RemoveTokenFallbackOptions, TeamInfo, TokenProcessingResult, TransformationDetails } from '../types';
|
|
3
|
+
export declare class TokenProcessor {
|
|
4
|
+
private j;
|
|
5
|
+
private options;
|
|
6
|
+
private fileInfo;
|
|
7
|
+
private source;
|
|
8
|
+
private rootDir;
|
|
9
|
+
private details;
|
|
10
|
+
private logMessages;
|
|
11
|
+
private possibleExtensions;
|
|
12
|
+
private tokenMap;
|
|
13
|
+
private teamInfo;
|
|
14
|
+
constructor(j: JSCodeshift, options: RemoveTokenFallbackOptions, fileInfo: FileInfo, source: Collection<any>, rootDir: string, details: TransformationDetails, tokenMap: Record<string, string>, teamInfo: TeamInfo);
|
|
15
|
+
processAndLogSingleToken(callPath: ASTPath<CallExpression>): Promise<TokenProcessingResult>;
|
|
16
|
+
private logVerbose;
|
|
17
|
+
private log;
|
|
18
|
+
private logError;
|
|
19
|
+
private processSingleToken;
|
|
20
|
+
private getTokenKey;
|
|
21
|
+
private getFallbackValue;
|
|
22
|
+
private processFallbackAsStringLiteral;
|
|
23
|
+
private processFallbackAsIdentifier;
|
|
24
|
+
private processFallbackAsMemberExpression;
|
|
25
|
+
private processFallbackAsTemplateLiteral;
|
|
26
|
+
private tryResolveModulePath;
|
|
27
|
+
private tryResolveLocalPath;
|
|
28
|
+
private resolveValueFromImport;
|
|
29
|
+
private createImportFilter;
|
|
30
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type API, type FileInfo } from 'jscodeshift';
|
|
2
2
|
export default function transformer(file: FileInfo, api: API): string;
|
package/dist/types/sinceRef.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ParsedPkg } from './types';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Returns packages that have been upgraded in package.json since ref. The version refers to their previous
|
|
3
4
|
* version
|
|
4
5
|
*/
|
|
5
6
|
export declare const getPackagesSinceRef: (ref: string) => Promise<ParsedPkg[]>;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import path, { type ParsedPath } from 'path';
|
|
3
3
|
import { type ParsedPkg } from './types';
|
|
4
4
|
export declare const hasTransform: (transformPath: string) => boolean;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves transforms for `packages` if provided, otherwise all transforms including presets
|
|
7
|
+
*/
|
|
6
8
|
export declare const getTransforms: (packages?: ParsedPkg[]) => ParsedPath[];
|
|
7
9
|
export declare const parseTransformPath: (transformPath: string) => path.ParsedPath;
|
|
8
10
|
export declare const getTransformPath: ({ dir, base }: ParsedPath) => string;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type API, type FileInfo, type Options } from 'jscodeshift';
|
|
2
2
|
export type Transform = (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => string;
|
|
3
3
|
export type CliFlags = {
|
|
4
4
|
/**
|
|
@@ -48,7 +48,8 @@ export type ParsedPkg = {
|
|
|
48
48
|
name: string;
|
|
49
49
|
version: string | null;
|
|
50
50
|
};
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Converts required args to optional if they have a default
|
|
52
53
|
* Example: export type UserFlags = Default<Flags, keyof typeof defaultFlags>;
|
|
53
54
|
*/
|
|
54
55
|
export type Default<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Return products packages filePaths for running codemods from specified dependent package
|
|
3
|
+
*/
|
|
2
4
|
export declare function findDependentPackagePaths(crawlPaths: string[], dependencyPackage: string): Promise<string[]>;
|
|
@@ -8,5 +8,6 @@ import './migrate-to-link/migrate-to-link';
|
|
|
8
8
|
import './migrate-to-new-buttons/migrate-to-new-buttons';
|
|
9
9
|
import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
|
|
10
10
|
import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
11
|
+
import './remove-token-fallbacks/remove-token-fallbacks';
|
|
11
12
|
declare const presets: string[];
|
|
12
13
|
export default presets;
|
package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Collection, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSCodeshift } from 'jscodeshift';
|
|
2
2
|
export declare const importTypesFromNewEntryPoint: (buttonImports: Collection<ImportDeclaration>, specifiers: (ImportDefaultSpecifier | ImportSpecifier)[], j: JSCodeshift, fileSource: Collection<any>) => (ImportDefaultSpecifier | ImportSpecifier)[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type API, type ASTPath, type JSXElement, type JSXExpressionContainer } from 'jscodeshift';
|
|
2
2
|
declare const moveIcon: (j: API['jscodeshift'], path: ASTPath<JSXElement>, iconNode: JSXExpressionContainer | undefined | null, beforeOrAfter: 'iconBefore' | 'iconAfter') => void;
|
|
3
3
|
export default moveIcon;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { API, FileInfo } from 'jscodeshift';
|
|
2
|
+
import { RemoveTokenFallbackOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms the source code of a file by removing fallback values from the @atlaskit/tokens/token functions.
|
|
5
|
+
* By default removes only the fallbacks that have the same values as the tokens.
|
|
6
|
+
*
|
|
7
|
+
* @param {FileInfo} fileInfo - Information about the file to be transformed.
|
|
8
|
+
* @param {API} api - The jscodeshift API, providing utilities for AST transformations.
|
|
9
|
+
* @param {RemoveTokenFallbackOptions} options - Options for the transformation, including:
|
|
10
|
+
* @param {boolean} [options.verbose] - If true, enables verbose logging.
|
|
11
|
+
* @param {boolean} [options.forceUpdate] - If true, removes the fallbacks regardless of the difference between token and fallback. Otherwise removes only the fallbacks that are equal to the token values.
|
|
12
|
+
* @param {boolean} [options.addEslintComments] - If true, adds the eslint ignore comment for the rule @atlaskit/design-system/no-unsafe-design-token-usage for the fallbacks that weren't removed.
|
|
13
|
+
* @param {boolean} [options.useLegacyColorTheme] - If true, uses the legacy theme for color token mapping.
|
|
14
|
+
* @param {string} [options.reportFolder] - Directory path to output transformation reports. Reports will be generated only if this option is provided.
|
|
15
|
+
* @param {boolean} [options.dry] - If true, performs a dry run without modifying the files.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Promise<string>} A promise that resolves to the transformed source code as a string.
|
|
18
|
+
*/
|
|
19
|
+
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: RemoveTokenFallbackOptions): Promise<string>;
|
|
20
|
+
export declare const parser = "tsx";
|
|
21
|
+
/**
|
|
22
|
+
* Function executed before all transformations to prepare the environment by clearing the report folder.
|
|
23
|
+
*/
|
|
24
|
+
export declare function beforeAll(options: RemoveTokenFallbackOptions): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
|
|
27
|
+
* It also applies prettier to the affected files.
|
|
28
|
+
*/
|
|
29
|
+
export declare function afterAll(options: RemoveTokenFallbackOptions): Promise<void>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ASTPath, ImportDeclaration, Options, VariableDeclarator } from 'jscodeshift';
|
|
2
|
+
export interface ReplacementDetail {
|
|
3
|
+
teamInfo: TeamInfo;
|
|
4
|
+
filePath: string;
|
|
5
|
+
lineNumber: number;
|
|
6
|
+
tokenKey: string;
|
|
7
|
+
rawFallbackValue: string;
|
|
8
|
+
resolvedTokenValue: string;
|
|
9
|
+
resolvedFallbackValue: string;
|
|
10
|
+
difference?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface TransformationDetails {
|
|
13
|
+
replaced: ReplacementDetail[];
|
|
14
|
+
notReplaced: ReplacementDetail[];
|
|
15
|
+
}
|
|
16
|
+
export type TeamInfo = {
|
|
17
|
+
packageName: string;
|
|
18
|
+
teamName: string;
|
|
19
|
+
};
|
|
20
|
+
export type RemoveTokenFallbackOptions = Options & {
|
|
21
|
+
useLegacyColorTheme?: boolean;
|
|
22
|
+
reportFolder?: string;
|
|
23
|
+
addEslintComments?: boolean;
|
|
24
|
+
forceUpdate?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type WithResolvedDeclarations = {
|
|
27
|
+
resolvedImportDeclaration?: ASTPath<ImportDeclaration>;
|
|
28
|
+
resolvedLocalVarDeclaration?: ASTPath<VariableDeclarator>;
|
|
29
|
+
};
|
|
30
|
+
export type FallbackResolveResult = WithResolvedDeclarations & {
|
|
31
|
+
rawFallbackValue: string;
|
|
32
|
+
fallbackValue: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
export type WithStart = {
|
|
35
|
+
start?: number;
|
|
36
|
+
};
|
|
37
|
+
export type TokenProcessingResult = WithResolvedDeclarations & {
|
|
38
|
+
fallbackRemoved: boolean;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTokenMap(useLegacyTheme?: boolean): Record<string, string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TeamInfo } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Looks for the closest package.json and gets team and package information from it.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} filePath
|
|
6
|
+
* @returns {Promise<AtlassianTeamInfo>}
|
|
7
|
+
*/
|
|
8
|
+
export declare const getTeamInfo: (filePath: string) => Promise<TeamInfo>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function normalizeValues(tokenKey: string, tokenValue: string | undefined, fallbackValue: string | undefined): {
|
|
2
|
+
difference?: number;
|
|
3
|
+
isAcceptableDifference?: boolean;
|
|
4
|
+
tokenLogValue: string;
|
|
5
|
+
fallbackLogValue: string;
|
|
6
|
+
normalizedTokenValue: string | undefined;
|
|
7
|
+
normalizedFallbackValue: string | undefined;
|
|
8
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TransformationDetails } from '../types';
|
|
2
|
+
export declare function clearFolder(reportFolder: string): Promise<void>;
|
|
3
|
+
export declare function combineReports(reportFolder: string): Promise<void>;
|
|
4
|
+
export declare function writeReports(details: TransformationDetails, reportFolder: string): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ASTPath, CallExpression, Collection, FileInfo, JSCodeshift } from 'jscodeshift';
|
|
2
|
+
import { RemoveTokenFallbackOptions, TeamInfo, TokenProcessingResult, TransformationDetails } from '../types';
|
|
3
|
+
export declare class TokenProcessor {
|
|
4
|
+
private j;
|
|
5
|
+
private options;
|
|
6
|
+
private fileInfo;
|
|
7
|
+
private source;
|
|
8
|
+
private rootDir;
|
|
9
|
+
private details;
|
|
10
|
+
private logMessages;
|
|
11
|
+
private possibleExtensions;
|
|
12
|
+
private tokenMap;
|
|
13
|
+
private teamInfo;
|
|
14
|
+
constructor(j: JSCodeshift, options: RemoveTokenFallbackOptions, fileInfo: FileInfo, source: Collection<any>, rootDir: string, details: TransformationDetails, tokenMap: Record<string, string>, teamInfo: TeamInfo);
|
|
15
|
+
processAndLogSingleToken(callPath: ASTPath<CallExpression>): Promise<TokenProcessingResult>;
|
|
16
|
+
private logVerbose;
|
|
17
|
+
private log;
|
|
18
|
+
private logError;
|
|
19
|
+
private processSingleToken;
|
|
20
|
+
private getTokenKey;
|
|
21
|
+
private getFallbackValue;
|
|
22
|
+
private processFallbackAsStringLiteral;
|
|
23
|
+
private processFallbackAsIdentifier;
|
|
24
|
+
private processFallbackAsMemberExpression;
|
|
25
|
+
private processFallbackAsTemplateLiteral;
|
|
26
|
+
private tryResolveModulePath;
|
|
27
|
+
private tryResolveLocalPath;
|
|
28
|
+
private resolveValueFromImport;
|
|
29
|
+
private createImportFilter;
|
|
30
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type API, type FileInfo } from 'jscodeshift';
|
|
2
2
|
export default function transformer(file: FileInfo, api: API): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ParsedPkg } from './types';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Returns packages that have been upgraded in package.json since ref. The version refers to their previous
|
|
3
4
|
* version
|
|
4
5
|
*/
|
|
5
6
|
export declare const getPackagesSinceRef: (ref: string) => Promise<ParsedPkg[]>;
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import path, { type ParsedPath } from 'path';
|
|
3
3
|
import { type ParsedPkg } from './types';
|
|
4
4
|
export declare const hasTransform: (transformPath: string) => boolean;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves transforms for `packages` if provided, otherwise all transforms including presets
|
|
7
|
+
*/
|
|
6
8
|
export declare const getTransforms: (packages?: ParsedPkg[]) => ParsedPath[];
|
|
7
9
|
export declare const parseTransformPath: (transformPath: string) => path.ParsedPath;
|
|
8
10
|
export declare const getTransformPath: ({ dir, base }: ParsedPath) => string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type API, type FileInfo, type Options } from 'jscodeshift';
|
|
2
2
|
export type Transform = (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => string;
|
|
3
3
|
export type CliFlags = {
|
|
4
4
|
/**
|
|
@@ -48,7 +48,8 @@ export type ParsedPkg = {
|
|
|
48
48
|
name: string;
|
|
49
49
|
version: string | null;
|
|
50
50
|
};
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Converts required args to optional if they have a default
|
|
52
53
|
* Example: export type UserFlags = Default<Flags, keyof typeof defaultFlags>;
|
|
53
54
|
*/
|
|
54
55
|
export type Default<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/codemod-cli",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.3",
|
|
4
4
|
"description": "A cli for distributing codemods for atlassian-frontend components and services",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -39,22 +39,27 @@
|
|
|
39
39
|
"bin": "./bin/codemod-cli.js",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
42
|
-
"@atlaskit/tokens": "^
|
|
42
|
+
"@atlaskit/tokens": "^4.0.0",
|
|
43
43
|
"@babel/runtime": "^7.0.0",
|
|
44
44
|
"@codeshift/utils": "^0.2.4",
|
|
45
45
|
"@hypermod/utils": "^0.4.2",
|
|
46
|
+
"@manypkg/find-root": "^1.1.0",
|
|
46
47
|
"@types/jscodeshift": "^0.11.0",
|
|
47
48
|
"chalk": "^4.1.2",
|
|
49
|
+
"color-diff": "^1.2.0",
|
|
48
50
|
"enquirer": "^2.3.4",
|
|
49
51
|
"glob": "9.0.0",
|
|
50
52
|
"jscodeshift": "^0.13.0",
|
|
51
53
|
"meow": "^8.1.1",
|
|
52
54
|
"projector-spawn": "^1.0.1",
|
|
55
|
+
"read-pkg-up": "^7.0.1",
|
|
53
56
|
"semver": "^7.5.2",
|
|
54
|
-
"simple-git": "^3.16.0"
|
|
57
|
+
"simple-git": "^3.16.0",
|
|
58
|
+
"uuid": "^3.1.0"
|
|
55
59
|
},
|
|
56
60
|
"devDependencies": {
|
|
57
61
|
"@af/formatting": "*",
|
|
62
|
+
"@types/color-diff": "^1.2.1",
|
|
58
63
|
"prettier": "^3.2.5",
|
|
59
64
|
"ts-node": "^10.9.1",
|
|
60
65
|
"typescript": "~5.4.2"
|