@atlaskit/textfield 6.3.1 → 6.4.1

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.
@@ -1,376 +1,335 @@
1
- import core, {
2
- API,
3
- ASTPath,
4
- FileInfo,
5
- Identifier,
6
- ImportDeclaration,
7
- ImportSpecifier,
8
- JSXAttribute,
9
- Options,
10
- Program,
1
+ import {
2
+ type API,
3
+ type ASTPath,
4
+ type default as core,
5
+ type FileInfo,
6
+ type Identifier,
7
+ type ImportDeclaration,
8
+ type ImportSpecifier,
9
+ type JSXAttribute,
10
+ type Options,
11
+ type Program,
11
12
  } from 'jscodeshift';
12
- import { Collection } from 'jscodeshift/src/Collection';
13
+ import { type Collection } from 'jscodeshift/src/Collection';
13
14
 
14
15
  export type Nullable<T> = T | null;
15
16
 
16
- export function getDefaultSpecifier(
17
- j: core.JSCodeshift,
18
- source: any,
19
- specifier: string,
20
- ) {
21
- const specifiers = source
22
- .find(j.ImportDeclaration)
23
- .filter(
24
- (path: ASTPath<ImportDeclaration>) =>
25
- path.node.source.value === specifier,
26
- )
27
- .find(j.ImportDefaultSpecifier);
28
-
29
- if (!specifiers.length) {
30
- return null;
31
- }
32
- return specifiers.nodes()[0]!.local!.name;
17
+ export function getDefaultSpecifier(j: core.JSCodeshift, source: any, specifier: string) {
18
+ const specifiers = source
19
+ .find(j.ImportDeclaration)
20
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
21
+ .find(j.ImportDefaultSpecifier);
22
+
23
+ if (!specifiers.length) {
24
+ return null;
25
+ }
26
+ return specifiers.nodes()[0]!.local!.name;
33
27
  }
34
28
  export function getNamedSpecifier(
35
- j: core.JSCodeshift,
36
- source: any,
37
- specifier: string,
38
- importName: string,
29
+ j: core.JSCodeshift,
30
+ source: any,
31
+ specifier: string,
32
+ importName: string,
39
33
  ) {
40
- const specifiers = source
41
- .find(j.ImportDeclaration)
42
- .filter(
43
- (path: ASTPath<ImportDeclaration>) =>
44
- path.node.source.value === specifier,
45
- )
46
- .find(j.ImportSpecifier)
47
- .filter(
48
- (path: ASTPath<ImportSpecifier>) =>
49
- path.node.imported.name === importName,
50
- );
51
-
52
- if (!specifiers.length) {
53
- return null;
54
- }
55
- return specifiers.nodes()[0]!.local!.name;
34
+ const specifiers = source
35
+ .find(j.ImportDeclaration)
36
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
37
+ .find(j.ImportSpecifier)
38
+ .filter((path: ASTPath<ImportSpecifier>) => path.node.imported.name === importName);
39
+
40
+ if (!specifiers.length) {
41
+ return null;
42
+ }
43
+ return specifiers.nodes()[0]!.local!.name;
56
44
  }
57
45
 
58
46
  export function getJSXAttributesByName(
59
- j: core.JSCodeshift,
60
- element: ASTPath<any>,
61
- attributeName: string,
47
+ j: core.JSCodeshift,
48
+ element: ASTPath<any>,
49
+ attributeName: string,
62
50
  ): Collection<JSXAttribute> {
63
- return j(element)
64
- .find(j.JSXOpeningElement)
65
- .find(j.JSXAttribute)
66
- .filter((attribute) => {
67
- const matches = j(attribute)
68
- .find(j.JSXIdentifier)
69
- .filter((identifier) => identifier.value.name === attributeName);
70
- return Boolean(matches.length);
71
- });
51
+ return j(element)
52
+ .find(j.JSXOpeningElement)
53
+ .find(j.JSXAttribute)
54
+ .filter((attribute) => {
55
+ const matches = j(attribute)
56
+ .find(j.JSXIdentifier)
57
+ .filter((identifier) => identifier.value.name === attributeName);
58
+ return Boolean(matches.length);
59
+ });
72
60
  }
73
61
 
74
- export function hasImportDeclaration(
75
- j: core.JSCodeshift,
76
- source: any,
77
- importPath: string,
78
- ) {
79
- const imports = source
80
- .find(j.ImportDeclaration)
81
- .filter(
82
- (path: ASTPath<ImportDeclaration>) =>
83
- typeof path.node.source.value === 'string' &&
84
- path.node.source.value.startsWith(importPath),
85
- );
86
-
87
- return Boolean(imports.length);
62
+ export function hasImportDeclaration(j: core.JSCodeshift, source: any, importPath: string) {
63
+ const imports = source
64
+ .find(j.ImportDeclaration)
65
+ .filter(
66
+ (path: ASTPath<ImportDeclaration>) =>
67
+ typeof path.node.source.value === 'string' && path.node.source.value.startsWith(importPath),
68
+ );
69
+
70
+ return Boolean(imports.length);
88
71
  }
89
72
  // not replacing newlines (which \s does)
90
73
  const spacesAndTabs: RegExp = /[ \t]{2,}/g;
91
74
  const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
92
75
 
93
76
  function clean(value: string): string {
94
- return (
95
- value
96
- .replace(spacesAndTabs, ' ')
97
- .replace(lineStartWithSpaces, '')
98
- // using .trim() to clear the any newlines before the first text and after last text
99
- .trim()
100
- );
77
+ return (
78
+ value
79
+ .replace(spacesAndTabs, ' ')
80
+ .replace(lineStartWithSpaces, '')
81
+ // using .trim() to clear the any newlines before the first text and after last text
82
+ .trim()
83
+ );
101
84
  }
102
85
 
103
86
  export function addCommentToStartOfFile({
104
- j,
105
- base,
106
- message,
87
+ j,
88
+ base,
89
+ message,
107
90
  }: {
108
- j: core.JSCodeshift;
109
- base: Collection<Node>;
110
- message: string;
91
+ j: core.JSCodeshift;
92
+ base: Collection<Node>;
93
+ message: string;
111
94
  }) {
112
- addCommentBefore({
113
- j,
114
- target: base.find(j.Program),
115
- message,
116
- });
95
+ addCommentBefore({
96
+ j,
97
+ target: base.find(j.Program),
98
+ message,
99
+ });
117
100
  }
118
101
 
119
102
  export function addCommentBefore({
120
- j,
121
- target,
122
- message,
103
+ j,
104
+ target,
105
+ message,
123
106
  }: {
124
- j: core.JSCodeshift;
125
- target: Collection<Program> | Collection<ImportDeclaration>;
126
- message: string;
107
+ j: core.JSCodeshift;
108
+ target: Collection<Program> | Collection<ImportDeclaration>;
109
+ message: string;
127
110
  }) {
128
- const content: string = ` TODO: (from codemod) ${clean(message)} `;
129
- target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
130
- path.value.comments = path.value.comments || [];
111
+ const content: string = ` TODO: (from codemod) ${clean(message)} `;
112
+ target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
113
+ path.value.comments = path.value.comments || [];
131
114
 
132
- const exists = path.value.comments.find(
133
- (comment) => comment.value === content,
134
- );
115
+ const exists = path.value.comments.find((comment) => comment.value === content);
135
116
 
136
- // avoiding duplicates of the same comment
137
- if (exists) {
138
- return;
139
- }
117
+ // avoiding duplicates of the same comment
118
+ if (exists) {
119
+ return;
120
+ }
140
121
 
141
- path.value.comments.push(j.commentBlock(content));
142
- });
122
+ path.value.comments.push(j.commentBlock(content));
123
+ });
143
124
  }
144
125
 
145
126
  export function doesIdentifierExist({
146
- j,
147
- base,
148
- name,
127
+ j,
128
+ base,
129
+ name,
149
130
  }: {
150
- j: core.JSCodeshift;
151
- base: Collection<any>;
152
- name: string;
131
+ j: core.JSCodeshift;
132
+ base: Collection<any>;
133
+ name: string;
153
134
  }): boolean {
154
- return (
155
- base
156
- .find(j.Identifier)
157
- .filter((identifer: ASTPath<Identifier>) => identifer.value.name === name)
158
- .length > 0
159
- );
135
+ return (
136
+ base
137
+ .find(j.Identifier)
138
+ .filter((identifer: ASTPath<Identifier>) => identifer.value.name === name).length > 0
139
+ );
160
140
  }
161
141
 
162
142
  export function getSafeImportName({
163
- j,
164
- base,
165
- currentDefaultSpecifierName,
166
- desiredName,
167
- fallbackName,
143
+ j,
144
+ base,
145
+ currentDefaultSpecifierName,
146
+ desiredName,
147
+ fallbackName,
168
148
  }: {
169
- j: core.JSCodeshift;
170
- base: Collection<any>;
171
- currentDefaultSpecifierName: string;
172
- desiredName: string;
173
- fallbackName: string;
149
+ j: core.JSCodeshift;
150
+ base: Collection<any>;
151
+ currentDefaultSpecifierName: string;
152
+ desiredName: string;
153
+ fallbackName: string;
174
154
  }) {
175
- if (currentDefaultSpecifierName === desiredName) {
176
- return desiredName;
177
- }
155
+ if (currentDefaultSpecifierName === desiredName) {
156
+ return desiredName;
157
+ }
178
158
 
179
- const isUsed: boolean = doesIdentifierExist({ j, base, name: desiredName });
159
+ const isUsed: boolean = doesIdentifierExist({ j, base, name: desiredName });
180
160
 
181
- return isUsed ? fallbackName : desiredName;
161
+ return isUsed ? fallbackName : desiredName;
182
162
  }
183
163
 
184
164
  export const createRemoveFuncFor =
185
- (component: string, prop: string, comment?: string) =>
186
- (j: core.JSCodeshift, source: Collection<Node>) => {
187
- const defaultSpecifier = getDefaultSpecifier(j, source, component);
188
-
189
- if (!defaultSpecifier) {
190
- return;
191
- }
192
-
193
- source.findJSXElements(defaultSpecifier).forEach((element) => {
194
- getJSXAttributesByName(j, element, prop).forEach((attribute) => {
195
- j(attribute).remove();
196
- if (comment) {
197
- addCommentToStartOfFile({ j, base: source, message: comment });
198
- }
199
- });
200
- });
201
- };
165
+ (component: string, prop: string, comment?: string) =>
166
+ (j: core.JSCodeshift, source: Collection<Node>) => {
167
+ const defaultSpecifier = getDefaultSpecifier(j, source, component);
168
+
169
+ if (!defaultSpecifier) {
170
+ return;
171
+ }
172
+
173
+ source.findJSXElements(defaultSpecifier).forEach((element) => {
174
+ getJSXAttributesByName(j, element, prop).forEach((attribute) => {
175
+ j(attribute).remove();
176
+ if (comment) {
177
+ addCommentToStartOfFile({ j, base: source, message: comment });
178
+ }
179
+ });
180
+ });
181
+ };
202
182
 
203
183
  export const createRemoveImportsFor =
204
- ({
205
- importsToRemove,
206
- packagePath,
207
- comment,
208
- }: {
209
- importsToRemove: string[];
210
- packagePath: string;
211
- comment: string;
212
- }) =>
213
- (j: core.JSCodeshift, source: Collection<Node>) => {
214
- const isUsingName: boolean =
215
- source
216
- .find(j.ImportDeclaration)
217
- .filter((path) => path.node.source.value === packagePath).length > 0;
218
- if (!isUsingName) {
219
- return;
220
- }
221
-
222
- const existingAliases: Nullable<string>[] =
223
- source
224
- .find(j.ImportDeclaration)
225
- .filter((path) => path.node.source.value === packagePath)
226
- .find(j.ImportSpecifier)
227
- .nodes()
228
- .map((specifier): Nullable<string> => {
229
- if (!importsToRemove.includes(specifier.imported.name)) {
230
- return null;
231
- }
232
- // If aliased: return the alias
233
- if (
234
- specifier.local &&
235
- !importsToRemove.includes(specifier.local.name)
236
- ) {
237
- return specifier.local.name;
238
- }
239
-
240
- return null;
241
- })
242
- .filter(Boolean) || null;
243
-
244
- // Add comments
245
- source
246
- .find(j.ImportDeclaration)
247
- .filter((path) => path.node.source.value === packagePath)
248
- .find(j.ImportSpecifier)
249
- .filter((importSpecifier) => {
250
- const identifier = j(importSpecifier).find(j.Identifier).get();
251
- if (
252
- importsToRemove.includes(identifier.value.name) ||
253
- existingAliases.includes(identifier.value.name)
254
- ) {
255
- addCommentToStartOfFile({ j, base: source, message: comment });
256
- return true;
257
- }
258
- return false;
259
- })
260
- .remove();
261
-
262
- // Remove entire import if it is empty
263
- const isEmptyNamedImport =
264
- source
265
- .find(j.ImportDeclaration)
266
- .filter((path) => path.node.source.value === packagePath)
267
- .find(j.ImportSpecifier)
268
- .find(j.Identifier).length === 0;
269
-
270
- if (isEmptyNamedImport) {
271
- const isEmptyDefaultImport =
272
- source
273
- .find(j.ImportDeclaration)
274
- .filter((path) => path.node.source.value === packagePath)
275
- .find(j.ImportDefaultSpecifier)
276
- .find(j.Identifier).length === 0;
277
-
278
- isEmptyDefaultImport
279
- ? source
280
- .find(j.ImportDeclaration)
281
- .filter((path) => path.node.source.value === packagePath)
282
- .remove()
283
- : source
284
- .find(j.ImportDeclaration)
285
- .filter((path) => path.node.source.value === packagePath)
286
- .find(j.ImportSpecifier)
287
- .remove();
288
- }
289
- };
184
+ ({
185
+ importsToRemove,
186
+ packagePath,
187
+ comment,
188
+ }: {
189
+ importsToRemove: string[];
190
+ packagePath: string;
191
+ comment: string;
192
+ }) =>
193
+ (j: core.JSCodeshift, source: Collection<Node>) => {
194
+ const isUsingName: boolean =
195
+ source.find(j.ImportDeclaration).filter((path) => path.node.source.value === packagePath)
196
+ .length > 0;
197
+ if (!isUsingName) {
198
+ return;
199
+ }
200
+
201
+ const existingAliases: Nullable<string>[] =
202
+ source
203
+ .find(j.ImportDeclaration)
204
+ .filter((path) => path.node.source.value === packagePath)
205
+ .find(j.ImportSpecifier)
206
+ .nodes()
207
+ .map((specifier): Nullable<string> => {
208
+ if (!importsToRemove.includes(specifier.imported.name)) {
209
+ return null;
210
+ }
211
+ // If aliased: return the alias
212
+ if (specifier.local && !importsToRemove.includes(specifier.local.name)) {
213
+ return specifier.local.name;
214
+ }
215
+
216
+ return null;
217
+ })
218
+ .filter(Boolean) || null;
219
+
220
+ // Add comments
221
+ source
222
+ .find(j.ImportDeclaration)
223
+ .filter((path) => path.node.source.value === packagePath)
224
+ .find(j.ImportSpecifier)
225
+ .filter((importSpecifier) => {
226
+ const identifier = j(importSpecifier).find(j.Identifier).get();
227
+ if (
228
+ importsToRemove.includes(identifier.value.name) ||
229
+ existingAliases.includes(identifier.value.name)
230
+ ) {
231
+ addCommentToStartOfFile({ j, base: source, message: comment });
232
+ return true;
233
+ }
234
+ return false;
235
+ })
236
+ .remove();
237
+
238
+ // Remove entire import if it is empty
239
+ const isEmptyNamedImport =
240
+ source
241
+ .find(j.ImportDeclaration)
242
+ .filter((path) => path.node.source.value === packagePath)
243
+ .find(j.ImportSpecifier)
244
+ .find(j.Identifier).length === 0;
245
+
246
+ if (isEmptyNamedImport) {
247
+ const isEmptyDefaultImport =
248
+ source
249
+ .find(j.ImportDeclaration)
250
+ .filter((path) => path.node.source.value === packagePath)
251
+ .find(j.ImportDefaultSpecifier)
252
+ .find(j.Identifier).length === 0;
253
+
254
+ isEmptyDefaultImport
255
+ ? source
256
+ .find(j.ImportDeclaration)
257
+ .filter((path) => path.node.source.value === packagePath)
258
+ .remove()
259
+ : source
260
+ .find(j.ImportDeclaration)
261
+ .filter((path) => path.node.source.value === packagePath)
262
+ .find(j.ImportSpecifier)
263
+ .remove();
264
+ }
265
+ };
290
266
 
291
267
  export const createRenameJSXFunc =
292
- (
293
- packagePath: string,
294
- from: string,
295
- to: string,
296
- fallback: string | undefined = undefined,
297
- ) =>
298
- (j: core.JSCodeshift, source: any) => {
299
- const namedSpecifier = getNamedSpecifier(j, source, packagePath, from);
300
-
301
- const toName = fallback
302
- ? getSafeImportName({
303
- j,
304
- base: source,
305
- currentDefaultSpecifierName: namedSpecifier,
306
- desiredName: to,
307
- fallbackName: fallback,
308
- })
309
- : to;
310
-
311
- const existingAlias: Nullable<string> =
312
- source
313
- .find(j.ImportDeclaration)
314
- .filter(
315
- (path: ASTPath<ImportDeclaration>) =>
316
- path.node.source.value === packagePath,
317
- )
318
- .find(j.ImportSpecifier)
319
- .nodes()
320
- .map((specifier: ImportSpecifier): Nullable<string> => {
321
- if (from !== specifier.imported.name) {
322
- return null;
323
- }
324
- // If aliased: return the alias
325
- if (specifier.local && from !== specifier.local.name) {
326
- return specifier.local.name;
327
- }
328
-
329
- return null;
330
- })
331
- .filter(Boolean)[0] || null;
332
-
333
- source
334
- .find(j.ImportDeclaration)
335
- .filter(
336
- (path: ASTPath<ImportDeclaration>) =>
337
- path.node.source.value === packagePath,
338
- )
339
- .find(j.ImportSpecifier)
340
- .filter((importSpecifier: ImportSpecifier) => {
341
- const identifier = j(importSpecifier).find(j.Identifier).get();
342
- if (
343
- from === identifier.value.name ||
344
- existingAlias === identifier.value.name
345
- ) {
346
- return true;
347
- }
348
- return false;
349
- })
350
- .replaceWith(
351
- [
352
- j.importSpecifier(
353
- j.identifier(toName),
354
- existingAlias ? j.identifier(existingAlias) : null,
355
- ),
356
- ],
357
- j.literal(packagePath),
358
- );
359
- };
268
+ (packagePath: string, from: string, to: string, fallback: string | undefined = undefined) =>
269
+ (j: core.JSCodeshift, source: any) => {
270
+ const namedSpecifier = getNamedSpecifier(j, source, packagePath, from);
271
+
272
+ const toName = fallback
273
+ ? getSafeImportName({
274
+ j,
275
+ base: source,
276
+ currentDefaultSpecifierName: namedSpecifier,
277
+ desiredName: to,
278
+ fallbackName: fallback,
279
+ })
280
+ : to;
281
+
282
+ const existingAlias: Nullable<string> =
283
+ source
284
+ .find(j.ImportDeclaration)
285
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === packagePath)
286
+ .find(j.ImportSpecifier)
287
+ .nodes()
288
+ .map((specifier: ImportSpecifier): Nullable<string> => {
289
+ if (from !== specifier.imported.name) {
290
+ return null;
291
+ }
292
+ // If aliased: return the alias
293
+ if (specifier.local && from !== specifier.local.name) {
294
+ return specifier.local.name;
295
+ }
296
+
297
+ return null;
298
+ })
299
+ .filter(Boolean)[0] || null;
300
+
301
+ source
302
+ .find(j.ImportDeclaration)
303
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === packagePath)
304
+ .find(j.ImportSpecifier)
305
+ .filter((importSpecifier: ImportSpecifier) => {
306
+ const identifier = j(importSpecifier).find(j.Identifier).get();
307
+ if (from === identifier.value.name || existingAlias === identifier.value.name) {
308
+ return true;
309
+ }
310
+ return false;
311
+ })
312
+ .replaceWith(
313
+ [
314
+ j.importSpecifier(
315
+ j.identifier(toName),
316
+ existingAlias ? j.identifier(existingAlias) : null,
317
+ ),
318
+ ],
319
+ j.literal(packagePath),
320
+ );
321
+ };
360
322
 
361
323
  export const createTransformer =
362
- (
363
- component: string,
364
- migrates: { (j: core.JSCodeshift, source: Collection<Node>): void }[],
365
- ) =>
366
- (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
367
- const source: Collection<Node> = j(fileInfo.source);
324
+ (component: string, migrates: { (j: core.JSCodeshift, source: Collection<Node>): void }[]) =>
325
+ (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
326
+ const source: Collection<Node> = j(fileInfo.source);
368
327
 
369
- if (!hasImportDeclaration(j, source, component)) {
370
- return fileInfo.source;
371
- }
328
+ if (!hasImportDeclaration(j, source, component)) {
329
+ return fileInfo.source;
330
+ }
372
331
 
373
- migrates.forEach((tf) => tf(j, source));
332
+ migrates.forEach((tf) => tf(j, source));
374
333
 
375
- return source.toSource(options.printOptions || { quote: 'single' });
376
- };
334
+ return source.toSource(options.printOptions || { quote: 'single' });
335
+ };
@@ -128,7 +128,7 @@ var inputStyles = exports.inputStyles = function inputStyles() {
128
128
  outline: 'none',
129
129
  width: '100%',
130
130
  '&[data-monospaced]': {
131
- fontFamily: "var(--ds-font-family-monospace, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
131
+ fontFamily: "var(--ds-font-family-code, ui-monospace, Menlo, \"Segoe UI Mono\", \"Ubuntu Mono\", monospace)"
132
132
  },
133
133
  '&[data-compact]': {
134
134
  padding: "var(--ds-space-050, 4px)".concat(" ", "var(--ds-space-075, 6px)")