@atlaskit/modal-dialog 14.14.4 → 14.14.6

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/modal-dialog
2
2
 
3
+ ## 14.14.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 14.14.5
10
+
11
+ ### Patch Changes
12
+
13
+ - [`02483200273ec`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/02483200273ec) -
14
+ Enrol all Design System UI packages into the React Compiler with platform gating via
15
+ isReactCompilerActivePlatform.
16
+ - Updated dependencies
17
+
3
18
  ## 14.14.4
4
19
 
5
20
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { createRemoveFuncIfBooleanFor } from '../utils';
1
+ import { createRemoveFuncIfBooleanFor } from '../utils/create-remove-func-if-boolean-for';
2
2
 
3
3
  export const removeAutoFocus: (
4
4
  j: import('jscodeshift/src/core').JSCodeshift,
@@ -1,7 +1,7 @@
1
1
  import type { API, FileInfo, Options } from 'jscodeshift';
2
2
 
3
3
  import { removeAutoFocus } from './migrations/remove-props';
4
- import { createTransformer } from './utils';
4
+ import { createTransformer } from './utils/create-transformer';
5
5
 
6
6
  const transformer: (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => string =
7
7
  createTransformer('@atlaskit/modal-dialog', [removeAutoFocus]);
@@ -0,0 +1,40 @@
1
+ import { type ASTPath, type ImportDeclaration, type JSCodeshift, type Program } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ // not replacing newlines (which \s does)
5
+ const spacesAndTabs: RegExp = /[ \t]{2,}/g;
6
+ const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
7
+
8
+ function clean(value: string): string {
9
+ return (
10
+ value
11
+ .replace(spacesAndTabs, ' ')
12
+ .replace(lineStartWithSpaces, '')
13
+ // using .trim() to clear the any newlines before the first text and after last text
14
+ .trim()
15
+ );
16
+ }
17
+
18
+ export function addCommentBefore({
19
+ j,
20
+ target,
21
+ message,
22
+ }: {
23
+ j: JSCodeshift;
24
+ target: Collection<Program> | Collection<ImportDeclaration>;
25
+ message: string;
26
+ }): void {
27
+ const content: string = ` TODO: (from codemod) ${clean(message)} `;
28
+ target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
29
+ path.value.comments = path.value.comments || [];
30
+
31
+ const exists = path.value.comments.find((comment) => comment.value === content);
32
+
33
+ // avoiding duplicates of the same comment
34
+ if (exists) {
35
+ return;
36
+ }
37
+
38
+ path.value.comments.push(j.commentBlock(content));
39
+ });
40
+ }
@@ -0,0 +1,20 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { addCommentBefore } from './add-comment-before';
5
+
6
+ export function addCommentToStartOfFile({
7
+ j,
8
+ base,
9
+ message,
10
+ }: {
11
+ j: JSCodeshift;
12
+ base: Collection<Node>;
13
+ message: string;
14
+ }): void {
15
+ addCommentBefore({
16
+ j,
17
+ target: base.find(j.Program),
18
+ message,
19
+ });
20
+ }
@@ -0,0 +1,32 @@
1
+ import { type ImportDefaultSpecifier, type ImportSpecifier, type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function addToImport({
5
+ j,
6
+ base,
7
+ importSpecifier,
8
+ packageName,
9
+ }: {
10
+ j: JSCodeshift;
11
+ base: Collection<any>;
12
+ importSpecifier: ImportSpecifier | ImportDefaultSpecifier;
13
+ packageName: string;
14
+ }): void {
15
+ base
16
+ .find(j.ImportDeclaration)
17
+ .filter((path) => path.value.source.value === packageName)
18
+ .replaceWith((declaration) => {
19
+ return j.importDeclaration(
20
+ [
21
+ // we are appending to the existing specifiers
22
+ // We are doing a filter hear because sometimes specifiers can be removed
23
+ // but they hand around in the declaration
24
+ ...(declaration.value.specifiers || []).filter(
25
+ (item) => item.type === 'ImportSpecifier' && item.imported != null,
26
+ ),
27
+ importSpecifier,
28
+ ],
29
+ j.literal(packageName),
30
+ );
31
+ });
32
+ }
@@ -0,0 +1,44 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { addCommentToStartOfFile } from './add-comment-to-start-of-file';
5
+ import { getDefaultSpecifier } from './get-default-specifier';
6
+ import { getJSXAttributesByName } from './get-jsx-attributes-by-name';
7
+ import { getNamedSpecifier } from './get-named-specifier';
8
+
9
+ export const createRemoveFuncIfBooleanFor: (
10
+ component: string,
11
+ importName: string,
12
+ prop: string,
13
+ comment?: string,
14
+ ) => (j: JSCodeshift, source: Collection<Node>) => void =
15
+ (component: string, importName: string, prop: string, comment?: string) =>
16
+ (j: JSCodeshift, source: Collection<Node>) => {
17
+ const specifier =
18
+ getNamedSpecifier(j, source, component, importName) ||
19
+ getDefaultSpecifier(j, source, component);
20
+
21
+ if (!specifier) {
22
+ return;
23
+ }
24
+
25
+ source.findJSXElements(specifier).forEach((element) => {
26
+ getJSXAttributesByName(j, element, prop).forEach((attribute) => {
27
+ const el = attribute.parent.value;
28
+ if (
29
+ // Verify the element we are working on is the element we want
30
+ el.type === 'JSXOpeningElement' &&
31
+ el.name.type === 'JSXIdentifier' &&
32
+ el.name.name === specifier &&
33
+ (attribute.value.value === null ||
34
+ (attribute.value.value?.type === 'JSXExpressionContainer' &&
35
+ attribute.value.value.expression.type === 'BooleanLiteral'))
36
+ ) {
37
+ j(attribute).remove();
38
+ if (comment) {
39
+ addCommentToStartOfFile({ j, base: source, message: comment });
40
+ }
41
+ }
42
+ });
43
+ });
44
+ };
@@ -0,0 +1,83 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { addCommentToStartOfFile } from './add-comment-to-start-of-file';
5
+ import { type Nullable } from './types';
6
+
7
+ export const createRemoveImportsFor: ({
8
+ importsToRemove,
9
+ packagePath,
10
+ comment,
11
+ }: {
12
+ importsToRemove: string[];
13
+ packagePath: string;
14
+ comment: string;
15
+ }) => (j: JSCodeshift, source: Collection<Node>) => void =
16
+ ({
17
+ importsToRemove,
18
+ packagePath,
19
+ comment,
20
+ }: {
21
+ importsToRemove: string[];
22
+ packagePath: string;
23
+ comment: string;
24
+ }) =>
25
+ (j: JSCodeshift, source: Collection<Node>) => {
26
+ const isUsingName: boolean =
27
+ source.find(j.ImportDeclaration).filter((path) => path.node.source.value === packagePath)
28
+ .length > 0;
29
+ if (!isUsingName) {
30
+ return;
31
+ }
32
+
33
+ const existingAlias: Nullable<string> =
34
+ source
35
+ .find(j.ImportDeclaration)
36
+ .filter((path) => path.node.source.value === packagePath)
37
+ .find(j.ImportSpecifier)
38
+ .nodes()
39
+ .map((specifier): Nullable<string> => {
40
+ if (!importsToRemove.includes(specifier.imported.name)) {
41
+ return null;
42
+ }
43
+ // If aliased: return the alias
44
+ if (specifier.local && !importsToRemove.includes(specifier.local.name)) {
45
+ return specifier.local.name;
46
+ }
47
+
48
+ return null;
49
+ })
50
+ .filter(Boolean)[0] || null;
51
+
52
+ // Remove imports
53
+ source
54
+ .find(j.ImportDeclaration)
55
+ .filter((path) => path.node.source.value === packagePath)
56
+ .find(j.ImportSpecifier)
57
+ .find(j.Identifier)
58
+ .filter((identifier) => {
59
+ if (
60
+ importsToRemove.includes(identifier.value.name) ||
61
+ identifier.value.name === existingAlias
62
+ ) {
63
+ addCommentToStartOfFile({ j, base: source, message: comment });
64
+ return true;
65
+ }
66
+ return false;
67
+ })
68
+ .remove();
69
+
70
+ // Remove entire import if it is empty
71
+ const isEmptyImport =
72
+ source
73
+ .find(j.ImportDeclaration)
74
+ .filter((path) => path.node.source.value === packagePath)
75
+ .find(j.ImportSpecifier)
76
+ .find(j.Identifier).length === 0;
77
+ if (isEmptyImport) {
78
+ source
79
+ .find(j.ImportDeclaration)
80
+ .filter((path) => path.node.source.value === packagePath)
81
+ .remove();
82
+ }
83
+ };
@@ -0,0 +1,42 @@
1
+ import { type JSCodeshift, type VariableDeclaration } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { findIdentifierAndReplaceAttribute } from './find-identifier-and-replace-attribute';
5
+ import { getJSXAttributesByName } from './get-jsx-attributes-by-name';
6
+ import { getNamedSpecifier } from './get-named-specifier';
7
+ import { hasVariableAssignment } from './has-variable-assignment';
8
+
9
+ export const createRenameFuncFor: (
10
+ component: string,
11
+ importName: string,
12
+ from: string,
13
+ to: string,
14
+ ) => (j: JSCodeshift, source: Collection<Node>) => void =
15
+ (component: string, importName: string, from: string, to: string) =>
16
+ (j: JSCodeshift, source: Collection<Node>) => {
17
+ const specifier = getNamedSpecifier(j, source, component, importName);
18
+
19
+ if (!specifier) {
20
+ return;
21
+ }
22
+
23
+ source.findJSXElements(specifier).forEach((element) => {
24
+ getJSXAttributesByName(j, element, from).forEach((attribute) => {
25
+ j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(to), attribute.node.value));
26
+ });
27
+ });
28
+
29
+ let variable = hasVariableAssignment(j, source, specifier);
30
+ if (variable) {
31
+ (variable as Collection<VariableDeclaration>)
32
+ .find(j.VariableDeclarator)
33
+ .forEach((declarator) => {
34
+ j(declarator)
35
+ .find(j.Identifier)
36
+ .filter((identifier) => identifier.name === 'id')
37
+ .forEach((ids) => {
38
+ findIdentifierAndReplaceAttribute(j, source, ids.node.name, from, to);
39
+ });
40
+ });
41
+ }
42
+ };
@@ -0,0 +1,97 @@
1
+ import { type ImportDefaultSpecifier, type ImportSpecifier, type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { addToImport } from './add-to-import';
5
+ import { tryCreateImport } from './try-create-import';
6
+ import { type Nullable } from './types';
7
+
8
+ export const createRenameImportFor: ({
9
+ componentName,
10
+ newComponentName,
11
+ oldPackagePath,
12
+ newPackagePath,
13
+ }: {
14
+ componentName: string;
15
+ newComponentName?: string;
16
+ oldPackagePath: string;
17
+ newPackagePath: string;
18
+ }) => (j: JSCodeshift, source: Collection<Node>) => void =
19
+ ({
20
+ componentName,
21
+ newComponentName,
22
+ oldPackagePath,
23
+ newPackagePath,
24
+ }: {
25
+ componentName: string;
26
+ newComponentName?: string;
27
+ oldPackagePath: string;
28
+ newPackagePath: string;
29
+ }) =>
30
+ (j: JSCodeshift, source: Collection<Node>) => {
31
+ const isUsingName: boolean =
32
+ source
33
+ .find(j.ImportDeclaration)
34
+ .filter((path) => path.node.source.value === oldPackagePath)
35
+ .find(j.ImportSpecifier)
36
+ .nodes()
37
+ .filter((specifier) => specifier.imported && specifier.imported.name === componentName)
38
+ .length > 0;
39
+ if (!isUsingName) {
40
+ return;
41
+ }
42
+
43
+ const existingAlias: Nullable<string> =
44
+ source
45
+ .find(j.ImportDeclaration)
46
+ .filter((path) => path.node.source.value === oldPackagePath)
47
+ .find(j.ImportSpecifier)
48
+ .nodes()
49
+ .map((specifier): Nullable<string> => {
50
+ if (specifier.imported && specifier.imported.name !== componentName) {
51
+ return null;
52
+ }
53
+ // If aliased: return the alias
54
+ if (specifier.local && specifier.local.name !== componentName) {
55
+ return specifier.local.name;
56
+ }
57
+
58
+ return null;
59
+ })
60
+ .filter(Boolean)[0] || null;
61
+
62
+ // Check to see if need to create new package path
63
+ // Try create an import declaration just before the old import
64
+ tryCreateImport({
65
+ j,
66
+ base: source,
67
+ relativeToPackage: oldPackagePath,
68
+ packageName: newPackagePath,
69
+ });
70
+
71
+ const newSpecifier: ImportSpecifier | ImportDefaultSpecifier = (() => {
72
+ // If there's a new name use that
73
+ if (newComponentName) {
74
+ return j.importSpecifier(j.identifier(newComponentName), j.identifier(newComponentName));
75
+ }
76
+
77
+ if (existingAlias) {
78
+ return j.importSpecifier(j.identifier(componentName), j.identifier(existingAlias));
79
+ }
80
+
81
+ // Add specifier
82
+ return j.importSpecifier(j.identifier(componentName), j.identifier(componentName));
83
+ })();
84
+
85
+ addToImport({
86
+ j,
87
+ base: source,
88
+ importSpecifier: newSpecifier,
89
+ packageName: newPackagePath,
90
+ });
91
+
92
+ // Remove old path
93
+ source
94
+ .find(j.ImportDeclaration)
95
+ .filter((path) => path.node.source.value === oldPackagePath)
96
+ .remove();
97
+ };
@@ -0,0 +1,23 @@
1
+ import { type API, type FileInfo, type JSCodeshift, type Options } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { hasImportDeclaration } from './has-import-declaration';
5
+
6
+ export const createTransformer: (
7
+ component: string,
8
+ migrates: {
9
+ (j: JSCodeshift, source: Collection<Node>): void;
10
+ }[],
11
+ ) => (fileInfo: FileInfo, api: API, options: Options) => string =
12
+ (component: string, migrates: { (j: JSCodeshift, source: Collection<Node>): void }[]) =>
13
+ (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
14
+ const source: Collection<Node> = j(fileInfo.source);
15
+
16
+ if (!hasImportDeclaration(j, source, component)) {
17
+ return fileInfo.source;
18
+ }
19
+
20
+ migrates.forEach((tf) => tf(j, source));
21
+
22
+ return source.toSource(options.printOptions || { quote: 'single' });
23
+ };
@@ -0,0 +1,27 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+
3
+ export function findIdentifierAndReplaceAttribute(
4
+ j: JSCodeshift,
5
+ source: ReturnType<typeof j>,
6
+ identifierName: string,
7
+ searchAttr: string,
8
+ replaceWithAttr: string,
9
+ ): void {
10
+ source
11
+ .find(j.JSXElement)
12
+ .find(j.JSXOpeningElement)
13
+ .filter((path) => {
14
+ return !!j(path.node)
15
+ .find(j.JSXIdentifier)
16
+ .filter((identifier) => identifier.value.name === identifierName);
17
+ })
18
+ .forEach((element) => {
19
+ j(element)
20
+ .find(j.JSXAttribute)
21
+ .find(j.JSXIdentifier)
22
+ .filter((attr) => attr.node.name === searchAttr)
23
+ .forEach((attribute) => {
24
+ j(attribute).replaceWith(j.jsxIdentifier(replaceWithAttr));
25
+ });
26
+ });
27
+ }
@@ -0,0 +1,17 @@
1
+ import { type ASTPath, type ImportDeclaration, type JSCodeshift } from 'jscodeshift';
2
+
3
+ export function getDefaultSpecifier(
4
+ j: JSCodeshift,
5
+ source: ReturnType<typeof j>,
6
+ specifier: string,
7
+ ): string | null {
8
+ const specifiers = source
9
+ .find(j.ImportDeclaration)
10
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
11
+ .find(j.ImportDefaultSpecifier);
12
+
13
+ if (!specifiers.length) {
14
+ return null;
15
+ }
16
+ return specifiers.nodes()[0]!.local!.name;
17
+ }
@@ -0,0 +1,18 @@
1
+ import { type ASTPath, type JSCodeshift, type JSXAttribute } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function getJSXAttributesByName(
5
+ j: JSCodeshift,
6
+ element: ASTPath<any>,
7
+ attributeName: string,
8
+ ): Collection<JSXAttribute> {
9
+ return j(element)
10
+ .find(j.JSXOpeningElement)
11
+ .find(j.JSXAttribute)
12
+ .filter((attribute) => {
13
+ const matches = j(attribute)
14
+ .find(j.JSXIdentifier)
15
+ .filter((identifier) => identifier.value.name === attributeName);
16
+ return Boolean(matches.length);
17
+ });
18
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ type ASTPath,
3
+ type ImportDeclaration,
4
+ type ImportSpecifier,
5
+ type JSCodeshift,
6
+ } from 'jscodeshift';
7
+
8
+ export function getNamedSpecifier(
9
+ j: JSCodeshift,
10
+ source: any,
11
+ specifier: string,
12
+ importName: string,
13
+ ): any {
14
+ const specifiers = source
15
+ .find(j.ImportDeclaration)
16
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
17
+ .find(j.ImportSpecifier)
18
+ .filter((path: ASTPath<ImportSpecifier>) => path.node.imported.name === importName);
19
+
20
+ if (!specifiers.length) {
21
+ return null;
22
+ }
23
+ return specifiers.nodes()[0]!.local!.name;
24
+ }
@@ -0,0 +1,12 @@
1
+ import { type ASTPath, type ImportDeclaration, type JSCodeshift } from 'jscodeshift';
2
+
3
+ export function hasImportDeclaration(j: JSCodeshift, source: any, importPath: string): boolean {
4
+ const imports = source
5
+ .find(j.ImportDeclaration)
6
+ .filter(
7
+ (path: ASTPath<ImportDeclaration>) =>
8
+ typeof path.node.source.value === 'string' && path.node.source.value.startsWith(importPath),
9
+ );
10
+
11
+ return Boolean(imports.length);
12
+ }
@@ -0,0 +1,18 @@
1
+ import { type JSCodeshift, type VariableDeclaration } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function hasVariableAssignment(
5
+ j: JSCodeshift,
6
+ source: ReturnType<typeof j>,
7
+ identifierName: string,
8
+ ): Collection<VariableDeclaration> | boolean {
9
+ const occurance = source.find(j.VariableDeclaration).filter((path) => {
10
+ return !!j(path.node)
11
+ .find(j.VariableDeclarator)
12
+ .find(j.Identifier)
13
+ .filter((identifier) => {
14
+ return identifier.node.name === identifierName;
15
+ }).length;
16
+ });
17
+ return !!occurance.length ? occurance : false;
18
+ }
@@ -0,0 +1,27 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function tryCreateImport({
5
+ j,
6
+ base,
7
+ relativeToPackage,
8
+ packageName,
9
+ }: {
10
+ j: JSCodeshift;
11
+ base: Collection<any>;
12
+ relativeToPackage: string;
13
+ packageName: string;
14
+ }): void {
15
+ const exists: boolean =
16
+ base.find(j.ImportDeclaration).filter((path) => path.value.source.value === packageName)
17
+ .length > 0;
18
+
19
+ if (exists) {
20
+ return;
21
+ }
22
+
23
+ base
24
+ .find(j.ImportDeclaration)
25
+ .filter((path) => path.value.source.value === relativeToPackage)
26
+ .insertBefore(j.importDeclaration([], j.literal(packageName)));
27
+ }
@@ -0,0 +1 @@
1
+ export type Nullable<T> = T | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/modal-dialog",
3
- "version": "14.14.4",
3
+ "version": "14.14.6",
4
4
  "description": "A modal dialog displays content that requires user interaction, in a layer above the page.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -17,6 +17,13 @@
17
17
  ],
18
18
  "atlaskit:src": "src/index.tsx",
19
19
  "atlassian": {
20
+ "react-compiler": {
21
+ "enabled": true,
22
+ "gating": {
23
+ "source": "@atlassian/react-compiler-gating",
24
+ "importSpecifierName": "isReactCompilerActivePlatform"
25
+ }
26
+ },
20
27
  "team": "Design System Team",
21
28
  "website": {
22
29
  "name": "Modal dialog",
@@ -29,7 +36,7 @@
29
36
  "dependencies": {
30
37
  "@atlaskit/analytics-next": "^11.2.0",
31
38
  "@atlaskit/blanket": "^15.0.0",
32
- "@atlaskit/button": "^23.10.0",
39
+ "@atlaskit/button": "^23.11.0",
33
40
  "@atlaskit/css": "^0.19.0",
34
41
  "@atlaskit/ds-lib": "^6.0.0",
35
42
  "@atlaskit/icon": "^34.0.0",
@@ -39,7 +46,7 @@
39
46
  "@atlaskit/portal": "^5.4.0",
40
47
  "@atlaskit/pragmatic-drag-and-drop": "^1.7.0",
41
48
  "@atlaskit/primitives": "^18.1.0",
42
- "@atlaskit/theme": "^22.0.0",
49
+ "@atlaskit/theme": "^23.0.0",
43
50
  "@atlaskit/tokens": "^11.4.0",
44
51
  "@babel/runtime": "^7.0.0",
45
52
  "@compiled/react": "^0.20.0",
@@ -56,7 +63,7 @@
56
63
  "@af/integration-testing": "workspace:^",
57
64
  "@af/visual-regression": "workspace:^",
58
65
  "@atlaskit/avatar": "^25.11.0",
59
- "@atlaskit/avatar-group": "^12.5.0",
66
+ "@atlaskit/avatar-group": "^12.6.0",
60
67
  "@atlaskit/banner": "^14.0.0",
61
68
  "@atlaskit/breadcrumbs": "^16.0.0",
62
69
  "@atlaskit/checkbox": "^17.3.0",
@@ -66,16 +73,17 @@
66
73
  "@atlaskit/dropdown-menu": "^16.8.0",
67
74
  "@atlaskit/flag": "^17.9.0",
68
75
  "@atlaskit/form": "^15.5.0",
69
- "@atlaskit/heading": "^5.3.0",
70
- "@atlaskit/link": "^3.3.0",
76
+ "@atlaskit/heading": "^5.4.0",
77
+ "@atlaskit/link": "^3.4.0",
71
78
  "@atlaskit/popup": "^4.16.0",
72
- "@atlaskit/radio": "^8.4.0",
79
+ "@atlaskit/radio": "^8.5.0",
73
80
  "@atlaskit/section-message": "^8.12.0",
74
81
  "@atlaskit/select": "^21.10.0",
75
82
  "@atlaskit/spotlight": "^0.11.0",
76
- "@atlaskit/textfield": "^8.2.0",
83
+ "@atlaskit/textfield": "^8.3.0",
77
84
  "@atlaskit/tooltip": "^21.1.0",
78
85
  "@atlassian/feature-flags-test-utils": "^1.0.0",
86
+ "@atlassian/react-compiler-gating": "workspace:^",
79
87
  "@atlassian/ssr-tests": "workspace:^",
80
88
  "@atlassian/structured-docs-types": "workspace:^",
81
89
  "@atlassian/testing-library": "^0.5.0",
@@ -1,488 +0,0 @@
1
- import type {
2
- API,
3
- ASTPath,
4
- default as core,
5
- FileInfo,
6
- ImportDeclaration,
7
- ImportDefaultSpecifier,
8
- ImportSpecifier,
9
- JSXAttribute,
10
- Options,
11
- Program,
12
- VariableDeclaration,
13
- } from 'jscodeshift';
14
- import { type Collection } from 'jscodeshift/src/Collection';
15
-
16
- export type Nullable<T> = T | null;
17
-
18
- export function getNamedSpecifier(
19
- j: core.JSCodeshift,
20
- source: any,
21
- specifier: string,
22
- importName: string,
23
- ): any {
24
- const specifiers = source
25
- .find(j.ImportDeclaration)
26
- .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
27
- .find(j.ImportSpecifier)
28
- .filter((path: ASTPath<ImportSpecifier>) => path.node.imported.name === importName);
29
-
30
- if (!specifiers.length) {
31
- return null;
32
- }
33
- return specifiers.nodes()[0]!.local!.name;
34
- }
35
-
36
- function getDefaultSpecifier(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
37
- const specifiers = source
38
- .find(j.ImportDeclaration)
39
- .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
40
- .find(j.ImportDefaultSpecifier);
41
-
42
- if (!specifiers.length) {
43
- return null;
44
- }
45
- return specifiers.nodes()[0]!.local!.name;
46
- }
47
-
48
- export function getJSXAttributesByName(
49
- j: core.JSCodeshift,
50
- element: ASTPath<any>,
51
- attributeName: string,
52
- ): Collection<JSXAttribute> {
53
- return j(element)
54
- .find(j.JSXOpeningElement)
55
- .find(j.JSXAttribute)
56
- .filter((attribute) => {
57
- const matches = j(attribute)
58
- .find(j.JSXIdentifier)
59
- .filter((identifier) => identifier.value.name === attributeName);
60
- return Boolean(matches.length);
61
- });
62
- }
63
-
64
- export function hasImportDeclaration(
65
- j: core.JSCodeshift,
66
- source: any,
67
- importPath: string,
68
- ): boolean {
69
- const imports = source
70
- .find(j.ImportDeclaration)
71
- .filter(
72
- (path: ASTPath<ImportDeclaration>) =>
73
- typeof path.node.source.value === 'string' && path.node.source.value.startsWith(importPath),
74
- );
75
-
76
- return Boolean(imports.length);
77
- }
78
-
79
- export function findIdentifierAndReplaceAttribute(
80
- j: core.JSCodeshift,
81
- source: ReturnType<typeof j>,
82
- identifierName: string,
83
- searchAttr: string,
84
- replaceWithAttr: string,
85
- ): void {
86
- source
87
- .find(j.JSXElement)
88
- .find(j.JSXOpeningElement)
89
- .filter((path) => {
90
- return !!j(path.node)
91
- .find(j.JSXIdentifier)
92
- .filter((identifier) => identifier.value.name === identifierName);
93
- })
94
- .forEach((element) => {
95
- j(element)
96
- .find(j.JSXAttribute)
97
- .find(j.JSXIdentifier)
98
- .filter((attr) => attr.node.name === searchAttr)
99
- .forEach((attribute) => {
100
- j(attribute).replaceWith(j.jsxIdentifier(replaceWithAttr));
101
- });
102
- });
103
- }
104
-
105
- export function hasVariableAssignment(
106
- j: core.JSCodeshift,
107
- source: ReturnType<typeof j>,
108
- identifierName: string,
109
- ): Collection<VariableDeclaration> | boolean {
110
- const occurance = source.find(j.VariableDeclaration).filter((path) => {
111
- return !!j(path.node)
112
- .find(j.VariableDeclarator)
113
- .find(j.Identifier)
114
- .filter((identifier) => {
115
- return identifier.node.name === identifierName;
116
- }).length;
117
- });
118
- return !!occurance.length ? occurance : false;
119
- }
120
-
121
- // not replacing newlines (which \s does)
122
- const spacesAndTabs: RegExp = /[ \t]{2,}/g;
123
- const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
124
-
125
- function clean(value: string): string {
126
- return (
127
- value
128
- .replace(spacesAndTabs, ' ')
129
- .replace(lineStartWithSpaces, '')
130
- // using .trim() to clear the any newlines before the first text and after last text
131
- .trim()
132
- );
133
- }
134
-
135
- export function addCommentToStartOfFile({
136
- j,
137
- base,
138
- message,
139
- }: {
140
- j: core.JSCodeshift;
141
- base: Collection<Node>;
142
- message: string;
143
- }): void {
144
- addCommentBefore({
145
- j,
146
- target: base.find(j.Program),
147
- message,
148
- });
149
- }
150
-
151
- export function addCommentBefore({
152
- j,
153
- target,
154
- message,
155
- }: {
156
- j: core.JSCodeshift;
157
- target: Collection<Program> | Collection<ImportDeclaration>;
158
- message: string;
159
- }): void {
160
- const content: string = ` TODO: (from codemod) ${clean(message)} `;
161
- target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
162
- path.value.comments = path.value.comments || [];
163
-
164
- const exists = path.value.comments.find((comment) => comment.value === content);
165
-
166
- // avoiding duplicates of the same comment
167
- if (exists) {
168
- return;
169
- }
170
-
171
- path.value.comments.push(j.commentBlock(content));
172
- });
173
- }
174
-
175
- export function tryCreateImport({
176
- j,
177
- base,
178
- relativeToPackage,
179
- packageName,
180
- }: {
181
- j: core.JSCodeshift;
182
- base: Collection<any>;
183
- relativeToPackage: string;
184
- packageName: string;
185
- }): void {
186
- const exists: boolean =
187
- base.find(j.ImportDeclaration).filter((path) => path.value.source.value === packageName)
188
- .length > 0;
189
-
190
- if (exists) {
191
- return;
192
- }
193
-
194
- base
195
- .find(j.ImportDeclaration)
196
- .filter((path) => path.value.source.value === relativeToPackage)
197
- .insertBefore(j.importDeclaration([], j.literal(packageName)));
198
- }
199
-
200
- export function addToImport({
201
- j,
202
- base,
203
- importSpecifier,
204
- packageName,
205
- }: {
206
- j: core.JSCodeshift;
207
- base: Collection<any>;
208
- importSpecifier: ImportSpecifier | ImportDefaultSpecifier;
209
- packageName: string;
210
- }): void {
211
- base
212
- .find(j.ImportDeclaration)
213
- .filter((path) => path.value.source.value === packageName)
214
- .replaceWith((declaration) => {
215
- return j.importDeclaration(
216
- [
217
- // we are appending to the existing specifiers
218
- // We are doing a filter hear because sometimes specifiers can be removed
219
- // but they hand around in the declaration
220
- ...(declaration.value.specifiers || []).filter(
221
- (item) => item.type === 'ImportSpecifier' && item.imported != null,
222
- ),
223
- importSpecifier,
224
- ],
225
- j.literal(packageName),
226
- );
227
- });
228
- }
229
-
230
- export const createRenameFuncFor: (
231
- component: string,
232
- importName: string,
233
- from: string,
234
- to: string,
235
- ) => (j: core.JSCodeshift, source: Collection<Node>) => void =
236
- (component: string, importName: string, from: string, to: string) =>
237
- (j: core.JSCodeshift, source: Collection<Node>) => {
238
- const specifier = getNamedSpecifier(j, source, component, importName);
239
-
240
- if (!specifier) {
241
- return;
242
- }
243
-
244
- source.findJSXElements(specifier).forEach((element) => {
245
- getJSXAttributesByName(j, element, from).forEach((attribute) => {
246
- j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(to), attribute.node.value));
247
- });
248
- });
249
-
250
- let variable = hasVariableAssignment(j, source, specifier);
251
- if (variable) {
252
- (variable as Collection<VariableDeclaration>)
253
- .find(j.VariableDeclarator)
254
- .forEach((declarator) => {
255
- j(declarator)
256
- .find(j.Identifier)
257
- .filter((identifier) => identifier.name === 'id')
258
- .forEach((ids) => {
259
- findIdentifierAndReplaceAttribute(j, source, ids.node.name, from, to);
260
- });
261
- });
262
- }
263
- };
264
-
265
- export const createRemoveFuncIfBooleanFor: (
266
- component: string,
267
- importName: string,
268
- prop: string,
269
- comment?: string,
270
- ) => (j: core.JSCodeshift, source: Collection<Node>) => void =
271
- (component: string, importName: string, prop: string, comment?: string) =>
272
- (j: core.JSCodeshift, source: Collection<Node>) => {
273
- const specifier =
274
- getNamedSpecifier(j, source, component, importName) ||
275
- getDefaultSpecifier(j, source, component);
276
-
277
- if (!specifier) {
278
- return;
279
- }
280
-
281
- source.findJSXElements(specifier).forEach((element) => {
282
- getJSXAttributesByName(j, element, prop).forEach((attribute) => {
283
- const el = attribute.parent.value;
284
- if (
285
- // Verify the element we are working on is the element we want
286
- el.type === 'JSXOpeningElement' &&
287
- el.name.type === 'JSXIdentifier' &&
288
- el.name.name === specifier &&
289
- (attribute.value.value === null ||
290
- (attribute.value.value?.type === 'JSXExpressionContainer' &&
291
- attribute.value.value.expression.type === 'BooleanLiteral'))
292
- ) {
293
- j(attribute).remove();
294
- if (comment) {
295
- addCommentToStartOfFile({ j, base: source, message: comment });
296
- }
297
- }
298
- });
299
- });
300
- };
301
-
302
- export const createRenameImportFor: ({
303
- componentName,
304
- newComponentName,
305
- oldPackagePath,
306
- newPackagePath,
307
- }: {
308
- componentName: string;
309
- newComponentName?: string;
310
- oldPackagePath: string;
311
- newPackagePath: string;
312
- }) => (j: core.JSCodeshift, source: Collection<Node>) => void =
313
- ({
314
- componentName,
315
- newComponentName,
316
- oldPackagePath,
317
- newPackagePath,
318
- }: {
319
- componentName: string;
320
- newComponentName?: string;
321
- oldPackagePath: string;
322
- newPackagePath: string;
323
- }) =>
324
- (j: core.JSCodeshift, source: Collection<Node>) => {
325
- const isUsingName: boolean =
326
- source
327
- .find(j.ImportDeclaration)
328
- .filter((path) => path.node.source.value === oldPackagePath)
329
- .find(j.ImportSpecifier)
330
- .nodes()
331
- .filter((specifier) => specifier.imported && specifier.imported.name === componentName)
332
- .length > 0;
333
- if (!isUsingName) {
334
- return;
335
- }
336
-
337
- const existingAlias: Nullable<string> =
338
- source
339
- .find(j.ImportDeclaration)
340
- .filter((path) => path.node.source.value === oldPackagePath)
341
- .find(j.ImportSpecifier)
342
- .nodes()
343
- .map((specifier): Nullable<string> => {
344
- if (specifier.imported && specifier.imported.name !== componentName) {
345
- return null;
346
- }
347
- // If aliased: return the alias
348
- if (specifier.local && specifier.local.name !== componentName) {
349
- return specifier.local.name;
350
- }
351
-
352
- return null;
353
- })
354
- .filter(Boolean)[0] || null;
355
-
356
- // Check to see if need to create new package path
357
- // Try create an import declaration just before the old import
358
- tryCreateImport({
359
- j,
360
- base: source,
361
- relativeToPackage: oldPackagePath,
362
- packageName: newPackagePath,
363
- });
364
-
365
- const newSpecifier: ImportSpecifier | ImportDefaultSpecifier = (() => {
366
- // If there's a new name use that
367
- if (newComponentName) {
368
- return j.importSpecifier(j.identifier(newComponentName), j.identifier(newComponentName));
369
- }
370
-
371
- if (existingAlias) {
372
- return j.importSpecifier(j.identifier(componentName), j.identifier(existingAlias));
373
- }
374
-
375
- // Add specifier
376
- return j.importSpecifier(j.identifier(componentName), j.identifier(componentName));
377
- })();
378
-
379
- addToImport({
380
- j,
381
- base: source,
382
- importSpecifier: newSpecifier,
383
- packageName: newPackagePath,
384
- });
385
-
386
- // Remove old path
387
- source
388
- .find(j.ImportDeclaration)
389
- .filter((path) => path.node.source.value === oldPackagePath)
390
- .remove();
391
- };
392
-
393
- export const createRemoveImportsFor: ({
394
- importsToRemove,
395
- packagePath,
396
- comment,
397
- }: {
398
- importsToRemove: string[];
399
- packagePath: string;
400
- comment: string;
401
- }) => (j: core.JSCodeshift, source: Collection<Node>) => void =
402
- ({
403
- importsToRemove,
404
- packagePath,
405
- comment,
406
- }: {
407
- importsToRemove: string[];
408
- packagePath: string;
409
- comment: string;
410
- }) =>
411
- (j: core.JSCodeshift, source: Collection<Node>) => {
412
- const isUsingName: boolean =
413
- source.find(j.ImportDeclaration).filter((path) => path.node.source.value === packagePath)
414
- .length > 0;
415
- if (!isUsingName) {
416
- return;
417
- }
418
-
419
- const existingAlias: Nullable<string> =
420
- source
421
- .find(j.ImportDeclaration)
422
- .filter((path) => path.node.source.value === packagePath)
423
- .find(j.ImportSpecifier)
424
- .nodes()
425
- .map((specifier): Nullable<string> => {
426
- if (!importsToRemove.includes(specifier.imported.name)) {
427
- return null;
428
- }
429
- // If aliased: return the alias
430
- if (specifier.local && !importsToRemove.includes(specifier.local.name)) {
431
- return specifier.local.name;
432
- }
433
-
434
- return null;
435
- })
436
- .filter(Boolean)[0] || null;
437
-
438
- // Remove imports
439
- source
440
- .find(j.ImportDeclaration)
441
- .filter((path) => path.node.source.value === packagePath)
442
- .find(j.ImportSpecifier)
443
- .find(j.Identifier)
444
- .filter((identifier) => {
445
- if (
446
- importsToRemove.includes(identifier.value.name) ||
447
- identifier.value.name === existingAlias
448
- ) {
449
- addCommentToStartOfFile({ j, base: source, message: comment });
450
- return true;
451
- }
452
- return false;
453
- })
454
- .remove();
455
-
456
- // Remove entire import if it is empty
457
- const isEmptyImport =
458
- source
459
- .find(j.ImportDeclaration)
460
- .filter((path) => path.node.source.value === packagePath)
461
- .find(j.ImportSpecifier)
462
- .find(j.Identifier).length === 0;
463
- if (isEmptyImport) {
464
- source
465
- .find(j.ImportDeclaration)
466
- .filter((path) => path.node.source.value === packagePath)
467
- .remove();
468
- }
469
- };
470
-
471
- export const createTransformer: (
472
- component: string,
473
- migrates: {
474
- (j: core.JSCodeshift, source: Collection<Node>): void;
475
- }[],
476
- ) => (fileInfo: FileInfo, api: API, options: Options) => string =
477
- (component: string, migrates: { (j: core.JSCodeshift, source: Collection<Node>): void }[]) =>
478
- (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
479
- const source: Collection<Node> = j(fileInfo.source);
480
-
481
- if (!hasImportDeclaration(j, source, component)) {
482
- return fileInfo.source;
483
- }
484
-
485
- migrates.forEach((tf) => tf(j, source));
486
-
487
- return source.toSource(options.printOptions || { quote: 'single' });
488
- };