@atlaskit/codemod-cli 0.27.2 → 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.
Files changed (65) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/main.js +85 -33
  3. package/dist/cjs/presets/index.js +2 -1
  4. package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +225 -0
  5. package/dist/cjs/presets/remove-token-fallbacks/types.js +5 -0
  6. package/dist/cjs/presets/remove-token-fallbacks/utils/all-tokens.js +44 -0
  7. package/dist/cjs/presets/remove-token-fallbacks/utils/color-utils.js +93 -0
  8. package/dist/cjs/presets/remove-token-fallbacks/utils/get-team-info.js +51 -0
  9. package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +113 -0
  10. package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-imports.js +61 -0
  11. package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-variables.js +37 -0
  12. package/dist/cjs/presets/remove-token-fallbacks/utils/reporter.js +310 -0
  13. package/dist/cjs/presets/remove-token-fallbacks/utils/token-processor.js +632 -0
  14. package/dist/cjs/presets/remove-token-fallbacks/utils/update-comments.js +58 -0
  15. package/dist/es2019/main.js +24 -0
  16. package/dist/es2019/presets/index.js +2 -1
  17. package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +130 -0
  18. package/dist/es2019/presets/remove-token-fallbacks/types.js +1 -0
  19. package/dist/es2019/presets/remove-token-fallbacks/utils/all-tokens.js +30 -0
  20. package/dist/es2019/presets/remove-token-fallbacks/utils/color-utils.js +84 -0
  21. package/dist/es2019/presets/remove-token-fallbacks/utils/get-team-info.js +22 -0
  22. package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +104 -0
  23. package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-imports.js +51 -0
  24. package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
  25. package/dist/es2019/presets/remove-token-fallbacks/utils/reporter.js +118 -0
  26. package/dist/es2019/presets/remove-token-fallbacks/utils/token-processor.js +377 -0
  27. package/dist/es2019/presets/remove-token-fallbacks/utils/update-comments.js +46 -0
  28. package/dist/esm/main.js +85 -33
  29. package/dist/esm/presets/index.js +2 -1
  30. package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +215 -0
  31. package/dist/esm/presets/remove-token-fallbacks/types.js +1 -0
  32. package/dist/esm/presets/remove-token-fallbacks/utils/all-tokens.js +38 -0
  33. package/dist/esm/presets/remove-token-fallbacks/utils/color-utils.js +86 -0
  34. package/dist/esm/presets/remove-token-fallbacks/utils/get-team-info.js +44 -0
  35. package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +107 -0
  36. package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-imports.js +55 -0
  37. package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
  38. package/dist/esm/presets/remove-token-fallbacks/utils/reporter.js +302 -0
  39. package/dist/esm/presets/remove-token-fallbacks/utils/token-processor.js +625 -0
  40. package/dist/esm/presets/remove-token-fallbacks/utils/update-comments.js +51 -0
  41. package/dist/types/presets/index.d.ts +1 -0
  42. package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
  43. package/dist/types/presets/remove-token-fallbacks/types.d.ts +39 -0
  44. package/dist/types/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
  45. package/dist/types/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
  46. package/dist/types/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
  47. package/dist/types/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
  48. package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
  49. package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
  50. package/dist/types/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
  51. package/dist/types/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
  52. package/dist/types/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
  53. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  54. package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
  55. package/dist/types-ts4.5/presets/remove-token-fallbacks/types.d.ts +39 -0
  56. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
  57. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
  58. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
  59. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
  60. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
  61. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
  62. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
  63. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
  64. package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
  65. package/package.json +8 -3
@@ -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;
@@ -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,3 @@
1
+ export declare const compareHex: (hex: string, hex2: string) => number;
2
+ export declare function isValidColor(color: string): boolean;
3
+ export declare function colorToHex(color: 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,2 @@
1
+ import { ASTPath, ImportDeclaration, JSCodeshift } from 'jscodeshift';
2
+ export declare function removeUnusedImports(importDeclarations: ASTPath<ImportDeclaration>[], j: JSCodeshift): void;
@@ -0,0 +1,2 @@
1
+ import { ASTPath, JSCodeshift, VariableDeclarator } from 'jscodeshift';
2
+ export declare function removeUnusedVariables(variableDeclarations: ASTPath<VariableDeclarator>[], j: JSCodeshift): void;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import type { ASTPath, CallExpression, JSCodeshift } from 'jscodeshift';
2
+ export declare function addOrUpdateEslintIgnoreComment(j: JSCodeshift, tokenValue: string, fallbackValue: string | undefined, callPath: ASTPath<CallExpression>): void;
@@ -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;
@@ -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,3 @@
1
+ export declare const compareHex: (hex: string, hex2: string) => number;
2
+ export declare function isValidColor(color: string): boolean;
3
+ export declare function colorToHex(color: 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,2 @@
1
+ import { ASTPath, ImportDeclaration, JSCodeshift } from 'jscodeshift';
2
+ export declare function removeUnusedImports(importDeclarations: ASTPath<ImportDeclaration>[], j: JSCodeshift): void;
@@ -0,0 +1,2 @@
1
+ import { ASTPath, JSCodeshift, VariableDeclarator } from 'jscodeshift';
2
+ export declare function removeUnusedVariables(variableDeclarations: ASTPath<VariableDeclarator>[], j: JSCodeshift): void;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import type { ASTPath, CallExpression, JSCodeshift } from 'jscodeshift';
2
+ export declare function addOrUpdateEslintIgnoreComment(j: JSCodeshift, tokenValue: string, fallbackValue: string | undefined, callPath: ASTPath<CallExpression>): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-cli",
3
- "version": "0.27.2",
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": "^3.2.0",
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"