@atlaskit/code 15.7.1 → 15.7.2

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,13 @@
1
1
  # @atlaskit/code
2
2
 
3
+ ## 15.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#114336](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/114336)
8
+ [`f09cd799e466a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f09cd799e466a) -
9
+ Update dependencies and remove old codemods.
10
+
3
11
  ## 15.7.1
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/code",
3
- "version": "15.7.1",
3
+ "version": "15.7.2",
4
4
  "description": "Code highlights short strings of code snippets inline with body text.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -50,7 +50,7 @@
50
50
  "@atlaskit/ds-lib": "^3.5.0",
51
51
  "@atlaskit/form": "^11.1.0",
52
52
  "@atlaskit/link": "*",
53
- "@atlaskit/primitives": "^13.4.0",
53
+ "@atlaskit/primitives": "^13.5.0",
54
54
  "@atlaskit/section-message": "*",
55
55
  "@atlaskit/ssr": "*",
56
56
  "@atlaskit/toggle": "^14.1.0",
@@ -60,7 +60,6 @@
60
60
  "@types/refractor": "^3.0.2",
61
61
  "color-contrast-checker": "^1.5.0",
62
62
  "css-loader": "^2.0.0",
63
- "jscodeshift": "^0.13.0",
64
63
  "prismjs": "^1.25.0",
65
64
  "react-dom": "^18.2.0",
66
65
  "style-loader": "^0.16.1",
@@ -1,84 +0,0 @@
1
- import { type API, type FileInfo, type JSCodeshift, type Options } from 'jscodeshift';
2
- import { type Collection } from 'jscodeshift/src/Collection';
3
-
4
- import {
5
- getImportDeclarationCollection,
6
- getImportSpecifierCollection,
7
- getImportSpecifierName,
8
- getJSXAttributesByName,
9
- getJSXSpreadIdentifierAttributesByName,
10
- getJSXSpreadObjectExpressionAttributesByName,
11
- hasImportDeclaration,
12
- } from './utils/helpers';
13
-
14
- const importPath = '@atlaskit/code';
15
- const importName = 'Code';
16
- const propsToBeRemoved = ['lineNumberContainerStyle', 'showLineNumbers', 'highlight'];
17
-
18
- function removeProps(
19
- j: JSCodeshift,
20
- collection: Collection<any>,
21
- elementName: string,
22
- propName: string,
23
- ) {
24
- collection.findJSXElements(elementName).forEach((jsxElementPath) => {
25
- const jsxAttributeCollection = getJSXAttributesByName(j, jsxElementPath, propName);
26
- if (jsxAttributeCollection) {
27
- jsxAttributeCollection.remove();
28
- }
29
-
30
- const jsxSpreadIdentifierPropertyCollection = getJSXSpreadIdentifierAttributesByName(
31
- j,
32
- collection,
33
- jsxElementPath,
34
- propName,
35
- );
36
- if (jsxSpreadIdentifierPropertyCollection) {
37
- jsxSpreadIdentifierPropertyCollection.remove();
38
- }
39
-
40
- const jsxSpreadExpressionPropertyCollection = getJSXSpreadObjectExpressionAttributesByName(
41
- j,
42
- jsxElementPath,
43
- propName,
44
- );
45
- if (jsxSpreadExpressionPropertyCollection) {
46
- jsxSpreadExpressionPropertyCollection.remove();
47
- }
48
- });
49
- }
50
-
51
- function removePropsForImportSpecifiers(
52
- j: JSCodeshift,
53
- collection: Collection<any>,
54
- propName: string,
55
- ) {
56
- const importDeclarationCollection = getImportDeclarationCollection(j, collection, importPath);
57
- const importSpecifierCollection = getImportSpecifierCollection(
58
- j,
59
- importDeclarationCollection,
60
- importName,
61
- );
62
- const importSpecifierName = getImportSpecifierName(importSpecifierCollection);
63
-
64
- if (importSpecifierName === null) {
65
- return;
66
- }
67
-
68
- removeProps(j, collection, importSpecifierName, propName);
69
- }
70
-
71
- export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
72
- const { source } = fileInfo;
73
- const collection = j(source);
74
-
75
- if (!hasImportDeclaration(j, collection, importPath)) {
76
- return source;
77
- }
78
-
79
- propsToBeRemoved.forEach((propToRemove) => {
80
- removePropsForImportSpecifiers(j, collection, propToRemove);
81
- });
82
-
83
- return collection.toSource(options.printOptions || { quote: 'single' });
84
- }
@@ -1,248 +0,0 @@
1
- import {
2
- type API,
3
- type ASTPath,
4
- type FileInfo,
5
- type Identifier,
6
- type ImportSpecifier,
7
- type JSCodeshift,
8
- type Options,
9
- } from 'jscodeshift';
10
- import { type Collection } from 'jscodeshift/src/Collection';
11
-
12
- import {
13
- getDynamicImportCollection,
14
- getImportDeclarationCollection,
15
- getImportSpecifierCollection,
16
- getImportSpecifierName,
17
- hasDynamicImport,
18
- hasImportDeclaration,
19
- isClassDeclarationIdentifierPresent,
20
- isFunctionDeclarationIdentifierPresent,
21
- isImportDeclarationIdentifierPresent,
22
- isVariableDeclaratorIdentifierPresent,
23
- } from './utils/helpers';
24
-
25
- const importPath = '@atlaskit/code';
26
- const importsMapping = {
27
- oldImports: {
28
- Code: 'AkCode',
29
- CodeBlock: 'AkCodeBlock',
30
- },
31
- newImports: {
32
- Code: 'Code',
33
- CodeBlock: 'CodeBlock',
34
- },
35
- };
36
-
37
- function renameNamedImports(
38
- j: JSCodeshift,
39
- collection: Collection<any>,
40
- {
41
- fromImportName,
42
- toImportName,
43
- }: {
44
- fromImportName: string;
45
- toImportName: string;
46
- },
47
- ) {
48
- const importDeclarationCollection = getImportDeclarationCollection(j, collection, importPath);
49
- const importSpecifierCollection = getImportSpecifierCollection(
50
- j,
51
- importDeclarationCollection,
52
- fromImportName,
53
- );
54
- const importSpecifierName = getImportSpecifierName(importSpecifierCollection);
55
-
56
- if (importSpecifierName === null) {
57
- return;
58
- }
59
-
60
- importSpecifierCollection.forEach((importSpecifierPath) => {
61
- renameBasedOnImportAlias(j, collection, importSpecifierPath, importSpecifierName, {
62
- fromImportName,
63
- toImportName,
64
- });
65
- });
66
- }
67
-
68
- function renameBasedOnImportAlias(
69
- j: JSCodeshift,
70
- collection: Collection<any>,
71
- importSpecifierPath: ASTPath<ImportSpecifier>,
72
- importSpecifierName: string,
73
- {
74
- fromImportName,
75
- toImportName,
76
- }: {
77
- fromImportName: string;
78
- toImportName: string;
79
- },
80
- ) {
81
- const isImportAliasPresent = importSpecifierName !== fromImportName;
82
-
83
- if (isImportAliasPresent) {
84
- return renameOnlyImportName(j, importSpecifierPath, importSpecifierName, {
85
- toImportName,
86
- });
87
- }
88
-
89
- const isToImportNameIdentifierPresentInSourceCode =
90
- isVariableDeclaratorIdentifierPresent(j, collection, toImportName) ||
91
- isFunctionDeclarationIdentifierPresent(j, collection, toImportName) ||
92
- isClassDeclarationIdentifierPresent(j, collection, toImportName) ||
93
- isImportDeclarationIdentifierPresent(j, collection, toImportName);
94
-
95
- if (isToImportNameIdentifierPresentInSourceCode) {
96
- return renameOnlyImportNameWithAliasAddition(j, importSpecifierPath, {
97
- fromImportName,
98
- toImportName,
99
- });
100
- }
101
-
102
- return renameImportNameWithItsUsage(j, collection, importSpecifierPath, {
103
- fromImportName,
104
- toImportName,
105
- });
106
- }
107
-
108
- function renameOnlyImportName(
109
- j: JSCodeshift,
110
- importSpecifierPath: ASTPath<ImportSpecifier>,
111
- importSpecifierName: string,
112
- {
113
- toImportName,
114
- }: {
115
- toImportName: string;
116
- },
117
- ) {
118
- j(importSpecifierPath).replaceWith(
119
- j.importSpecifier(j.identifier(toImportName), j.identifier(importSpecifierName)),
120
- );
121
- }
122
-
123
- function renameOnlyImportNameWithAliasAddition(
124
- j: JSCodeshift,
125
- importSpecifierPath: ASTPath<ImportSpecifier>,
126
- {
127
- fromImportName,
128
- toImportName,
129
- }: {
130
- fromImportName: string;
131
- toImportName: string;
132
- },
133
- ) {
134
- j(importSpecifierPath).replaceWith(
135
- j.importSpecifier(j.identifier(toImportName), j.identifier(fromImportName)),
136
- );
137
- }
138
-
139
- function renameImportNameWithItsUsage(
140
- j: JSCodeshift,
141
- collection: Collection<any>,
142
- importSpecifierPath: ASTPath<ImportSpecifier>,
143
- {
144
- fromImportName,
145
- toImportName,
146
- }: {
147
- fromImportName: string;
148
- toImportName: string;
149
- },
150
- ) {
151
- j(importSpecifierPath).replaceWith(
152
- j.importSpecifier(j.identifier(toImportName), j.identifier(toImportName)),
153
- );
154
-
155
- collection
156
- .find(j.JSXIdentifier)
157
- .filter((jsxIdentifierPath) => jsxIdentifierPath.node.name === fromImportName)
158
- .forEach((jsxIdentifierPath) => {
159
- j(jsxIdentifierPath).replaceWith(j.identifier(toImportName));
160
- });
161
-
162
- collection.find(j.CallExpression).forEach((callExpressionPath) => {
163
- const { arguments: callExpressionArguments } = callExpressionPath.node;
164
-
165
- callExpressionPath.node.arguments = callExpressionArguments.map((argument) => {
166
- if (argument.type === 'Identifier' && argument.name === fromImportName) {
167
- return j.identifier(toImportName);
168
- }
169
-
170
- return argument;
171
- });
172
- });
173
-
174
- collection.find(j.VariableDeclarator).forEach((variableDeclaratorPath) => {
175
- const { init } = variableDeclaratorPath.node;
176
-
177
- if (init && init.type === 'Identifier' && (init as Identifier).name === fromImportName) {
178
- variableDeclaratorPath.node.init = j.identifier(toImportName);
179
- }
180
- });
181
- }
182
-
183
- function addPromiseThenIdentifier(j: JSCodeshift, collection: Collection<any>) {
184
- const thenArgument = 'module';
185
-
186
- getDynamicImportCollection(j, collection, importPath).forEach((callExpressionPath) => {
187
- j(callExpressionPath).replaceWith(
188
- j.callExpression(j.memberExpression(callExpressionPath.node, j.identifier('then')), [
189
- j.arrowFunctionExpression(
190
- [j.identifier(thenArgument)],
191
- j.objectExpression([
192
- j.objectProperty(
193
- j.identifier(importsMapping.oldImports.Code),
194
- j.memberExpression(
195
- j.identifier(thenArgument),
196
- j.identifier(importsMapping.newImports.Code),
197
- ),
198
- ),
199
- j.objectProperty(
200
- j.identifier(importsMapping.oldImports.CodeBlock),
201
- j.memberExpression(
202
- j.identifier(thenArgument),
203
- j.identifier(importsMapping.newImports.CodeBlock),
204
- ),
205
- ),
206
- ]),
207
- ),
208
- ]),
209
- );
210
- });
211
- }
212
-
213
- export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
214
- const { source } = fileInfo;
215
- const collection = j(source);
216
-
217
- const hasCodeImportDeclaration = hasImportDeclaration(j, collection, importPath);
218
-
219
- const hasDynamicImportCode = hasDynamicImport(j, collection, importPath);
220
-
221
- if (!hasCodeImportDeclaration && !hasDynamicImportCode) {
222
- return source;
223
- }
224
-
225
- if (hasCodeImportDeclaration) {
226
- [
227
- {
228
- fromImportName: importsMapping.oldImports.Code,
229
- toImportName: importsMapping.newImports.Code,
230
- },
231
- {
232
- fromImportName: importsMapping.oldImports.CodeBlock,
233
- toImportName: importsMapping.newImports.CodeBlock,
234
- },
235
- ].forEach(({ fromImportName, toImportName }) => {
236
- renameNamedImports(j, collection, {
237
- fromImportName,
238
- toImportName,
239
- });
240
- });
241
- }
242
-
243
- if (hasDynamicImportCode) {
244
- addPromiseThenIdentifier(j, collection);
245
- }
246
-
247
- return collection.toSource(options.printOptions || { quote: 'single' });
248
- }
@@ -1,14 +0,0 @@
1
- import { type JSCodeshift } from 'jscodeshift';
2
- import { type Collection } from 'jscodeshift/src/Collection';
3
-
4
- import { createTransformer, hasImportDeclaration } from '@atlaskit/codemod-utils';
5
-
6
- import removeLanguage from './migrations/14.0.0-lite-mode/remove-language';
7
- import textToChild from './migrations/14.0.0-lite-mode/text-to-child';
8
-
9
- const transformer = createTransformer(
10
- [removeLanguage, textToChild],
11
- (j: JSCodeshift, source: Collection<Node>) => hasImportDeclaration(j, source, '@atlaskit/code'),
12
- );
13
-
14
- export default transformer;
@@ -1,201 +0,0 @@
1
- jest.autoMockOff();
2
-
3
- import transformer from '../13.0.0-remove-unnecessary-code-props';
4
-
5
- const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
6
-
7
- const removePropsMapping = {
8
- lineNumberContainerStyle: 'lineNumberContainerStyle',
9
- showLineNumbers: 'lineNumberContainerStyle',
10
- highlight: 'highlight',
11
- };
12
-
13
- describe('Remove props', () => {
14
- defineInlineTest(
15
- { default: transformer, parser: 'tsx' },
16
- {},
17
- `import React from 'react';`,
18
- `import React from 'react';`,
19
- 'should not transform if imports are not present',
20
- );
21
-
22
- defineInlineTest(
23
- { default: transformer, parser: 'tsx' },
24
- {},
25
- `
26
- import React from 'react';
27
- import { Code } from '@atlaskit/code';
28
-
29
- const Component1 = () => <Code prop="abc" />;
30
-
31
- const Component2 = () => <><Code prop="abc">text</Code></>;
32
-
33
- class Component3 extends React.Component { render() { return <div><Code prop="abc" /></div>; } }
34
-
35
- const element = <Code prop="abc" />;
36
- `,
37
- `
38
- import React from 'react';
39
- import { Code } from '@atlaskit/code';
40
-
41
- const Component1 = () => <Code prop="abc" />;
42
-
43
- const Component2 = () => <><Code prop="abc">text</Code></>;
44
-
45
- class Component3 extends React.Component { render() { return <div><Code prop="abc" /></div>; } }
46
-
47
- const element = <Code prop="abc" />;
48
- `,
49
- 'should not transform if removable props are not preset',
50
- );
51
-
52
- describe('when only one prop present', () => {
53
- defineInlineTest(
54
- { default: transformer, parser: 'tsx' },
55
- {},
56
- `
57
- import React from 'react';
58
- import { Code } from '@atlaskit/code';
59
-
60
- const Component1 = () => <Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} />;
61
-
62
- const Component2 = () => <><Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }}>text</Code></>;
63
-
64
- class Component3 extends React.Component { render() { return <div><Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} /></div>; } }
65
-
66
- const element = <Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} />;
67
- `,
68
- `
69
- import React from 'react';
70
- import { Code } from '@atlaskit/code';
71
-
72
- const Component1 = () => <Code prop="abc" />;
73
-
74
- const Component2 = () => <><Code prop="abc">text</Code></>;
75
-
76
- class Component3 extends React.Component { render() { return <div><Code prop="abc" /></div>; } }
77
-
78
- const element = <Code prop="abc" />;
79
- `,
80
- `removes "${removePropsMapping.lineNumberContainerStyle}" "JSXAttribute" prop`,
81
- );
82
-
83
- defineInlineTest(
84
- { default: transformer, parser: 'tsx' },
85
- {},
86
- `
87
- import React from 'react';
88
- import { Code } from '@atlaskit/code';
89
-
90
- const foo = {
91
- key: 'some value',
92
- ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '14px' }
93
- };
94
-
95
- const bar = {
96
- ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '20px' }
97
- };
98
-
99
- const Component1 = () => <Code prop="abc" {...foo} {...bar} />;
100
-
101
- const Component2 = () => <Code prop="abc" {...foo} { ...{ ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '24px' } } } {...bar} />;
102
-
103
- const Component3 = () => <Code prop="abc" {...foo} { ...{ ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '24px' }, key: 'hello' } } {...bar} />;
104
- `,
105
- `
106
- import React from 'react';
107
- import { Code } from '@atlaskit/code';
108
-
109
- const foo = {
110
- key: 'some value'
111
- };
112
-
113
- const bar = {};
114
-
115
- const Component1 = () => <Code prop="abc" {...foo} {...bar} />;
116
-
117
- const Component2 = () => <Code prop="abc" {...foo} { ...{} } {...bar} />;
118
-
119
- const Component3 = () => <Code prop="abc" {...foo} { ...{
120
- key: 'hello'
121
- } } {...bar} />;
122
- `,
123
- `removes "${removePropsMapping.lineNumberContainerStyle}" "JSXSpreadAttribute" prop`,
124
- );
125
- });
126
-
127
- defineInlineTest(
128
- { default: transformer, parser: 'tsx' },
129
- {},
130
- `
131
- import React from 'react';
132
- import { Code } from '@atlaskit/code';
133
-
134
- const Component1 = () => <Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} ${removePropsMapping.showLineNumbers} />;
135
-
136
- const Component2 = () =>
137
- <>
138
- <Code
139
- prop="abc"
140
- ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }}
141
- ${removePropsMapping.showLineNumbers}={false}
142
- >
143
- text
144
- </Code>
145
- </>;
146
-
147
- class Component3 extends React.Component { render() { return <div><Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} /></div>; } }
148
-
149
- const foo = {
150
- key: 'some value',
151
- ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '14px' },
152
- ${removePropsMapping.showLineNumbers}: true
153
- };
154
-
155
- const bar = {
156
- ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '20px' },
157
- ${removePropsMapping.highlight}: '1-5,7,10,15-20'
158
- };
159
-
160
- const Component4 = () => <Code prop="abc" {...foo} {...bar} ${removePropsMapping.highlight}="2" />;
161
-
162
- const Component5 = () => <Code prop="abc" {...foo} { ...{ ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '24px' } } } {...bar} />;
163
-
164
- const Component6 = () => <Code prop="abc" {...foo} { ...{ ${removePropsMapping.lineNumberContainerStyle}: { fontSize: '24px' }, key: 'hello' } } {...bar} />;
165
-
166
- const element = <Code prop="abc" ${removePropsMapping.lineNumberContainerStyle}={{ fontSize: '14px' }} ${removePropsMapping.highlight}="2-4" />;
167
- `,
168
- `
169
- import React from 'react';
170
- import { Code } from '@atlaskit/code';
171
-
172
- const Component1 = () => <Code prop="abc" />;
173
-
174
- const Component2 = () =>
175
- <>
176
- <Code prop="abc">
177
- text
178
- </Code>
179
- </>;
180
-
181
- class Component3 extends React.Component { render() { return <div><Code prop="abc" /></div>; } }
182
-
183
- const foo = {
184
- key: 'some value'
185
- };
186
-
187
- const bar = {};
188
-
189
- const Component4 = () => <Code prop="abc" {...foo} {...bar} />;
190
-
191
- const Component5 = () => <Code prop="abc" {...foo} { ...{} } {...bar} />;
192
-
193
- const Component6 = () => <Code prop="abc" {...foo} { ...{
194
- key: 'hello'
195
- } } {...bar} />;
196
-
197
- const element = <Code prop="abc" />;
198
- `,
199
- 'removes mixture of removable props',
200
- );
201
- });