@kaizen/components 1.67.10 → 1.67.12
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/codemods/migrateBrandMomentMoodToVariant/index.ts +1 -2
- package/codemods/migrateBrandMomentMoodToVariant/transformBrandMomentMoodToVariant.spec.ts +7 -3
- package/codemods/migrateCardVariantToColor/index.ts +1 -2
- package/codemods/migrateCardVariantToColor/transformCardVariantToColor.spec.ts +9 -3
- package/codemods/migrateConfirmationModalMoodsToVariant/index.ts +1 -2
- package/codemods/migrateConfirmationModalMoodsToVariant/transformConfirmationModalMoodsToVariant.spec.ts +8 -8
- package/codemods/migrateEmptyStateIllustrationTypeToVariant/index.ts +1 -2
- package/codemods/migrateEmptyStateIllustrationTypeToVariant/transformEmptyStateIllustrationTypeToVariant.spec.ts +7 -3
- package/codemods/migrateGlobalNotificationTypeToVariant/index.ts +2 -3
- package/codemods/migrateInformationTileMoodToVariant/index.ts +1 -2
- package/codemods/migrateInformationTileMoodToVariant/transformInformationTileMoodToVariant.spec.ts +7 -3
- package/codemods/migrateInlineNotificationTypeToVariant/index.ts +2 -3
- package/codemods/migrateMultiActionTileMoodToVariant/index.ts +0 -1
- package/codemods/migrateMultiActionTileMoodToVariant/transformMultiActionTileMoodToVariant.spec.ts +7 -3
- package/codemods/migrateNotificationTypeToVariant/migrateNotificationTypeToVariant.spec.ts +8 -8
- package/codemods/migrateProgressBarMoodToColor/index.ts +0 -1
- package/codemods/migrateProgressBarMoodToColor/transformProgressBarMoodToColor.spec.ts +7 -3
- package/codemods/migrateToastNotificationTypeToVariant/index.ts +1 -2
- package/codemods/migrateWellVariantToColor/index.ts +1 -2
- package/codemods/migrateWellVariantToColor/transformWellVariantToColor.spec.ts +12 -12
- package/codemods/migrateWellVariantToColor/transformWellVariantToColor.ts +2 -3
- package/codemods/removeInputEditModalMood/index.ts +1 -2
- package/codemods/removeInputEditModalMood/removeInputEditModalMood.spec.ts +4 -4
- package/codemods/removePopoverVariant/index.ts +1 -2
- package/codemods/removePopoverVariant/removePopoverVariant.spec.ts +5 -5
- package/codemods/upgradeIconV1/index.ts +5 -5
- package/codemods/upgradeIconV1/upgradeIconV1.spec.ts +5 -6
- package/codemods/upgradeIconV1/upgradeIconV1.ts +7 -5
- package/codemods/utils/__fixtures__/KaioComponent.tsx +2 -3
- package/codemods/utils/__snapshots__/emptyLineEncoder.spec.ts.snap +19 -0
- package/codemods/utils/__snapshots__/transformSource.spec.ts.snap +14 -4
- package/codemods/utils/createEncodedSourceFile.ts +15 -0
- package/codemods/utils/createProp.spec.ts +6 -8
- package/codemods/utils/emptyLineEncoder.spec.ts +25 -0
- package/codemods/utils/emptyLineEncoder.ts +18 -0
- package/codemods/utils/migrateStringProp.spec.ts +7 -3
- package/codemods/utils/migrateStringProp.ts +2 -3
- package/codemods/utils/printAst.ts +1 -0
- package/codemods/utils/removeProps.spec.ts +5 -5
- package/codemods/utils/removeProps.ts +2 -2
- package/codemods/utils/transformComponentsInDir.ts +14 -15
- package/codemods/utils/transformSource.spec.ts +63 -34
- package/codemods/utils/transformSource.ts +32 -19
- package/codemods/utils/updateKaioImports.ts +6 -3
- package/dist/cjs/__actions__/Menu/v3/Menu.cjs +1 -1
- package/dist/cjs/__actions__/Menu/v3/{Menu.module.scss.cjs → Menu.module.css.cjs} +1 -1
- package/dist/cjs/__actions__/Menu/v3/MenuItem.cjs +10 -5
- package/dist/cjs/__actions__/Menu/v3/MenuItem.module.css.cjs +8 -0
- package/dist/esm/__actions__/Menu/v3/Menu.mjs +1 -1
- package/dist/esm/__actions__/Menu/v3/{Menu.module.scss.mjs → Menu.module.css.mjs} +1 -1
- package/dist/esm/__actions__/Menu/v3/MenuItem.mjs +10 -5
- package/dist/esm/__actions__/Menu/v3/MenuItem.module.css.mjs +6 -0
- package/dist/styles.css +103 -94
- package/package.json +3 -3
- package/src/__actions__/Menu/v3/Menu.tsx +1 -1
- package/src/__actions__/Menu/v3/{MenuItem.module.scss → MenuItem.module.css} +7 -3
- package/src/__actions__/Menu/v3/MenuItem.tsx +24 -13
- package/src/__actions__/Menu/v3/_docs/ApiSpecification.mdx +10 -1
- package/src/__actions__/Menu/v3/_docs/Menu.docs.stories.tsx +0 -5
- package/src/__actions__/Menu/v3/_docs/Menu.stories.tsx +33 -1
- package/dist/cjs/__actions__/Menu/v3/MenuItem.module.scss.cjs +0 -7
- package/dist/esm/__actions__/Menu/v3/MenuItem.module.scss.mjs +0 -5
- /package/src/__actions__/Menu/v3/{Menu.module.scss → Menu.module.css} +0 -0
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { parseJsx } from "../__tests__/utils"
|
|
2
2
|
import {
|
|
3
|
-
transformSource,
|
|
4
3
|
printAst,
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
type ImportModuleNameTagsMap,
|
|
5
|
+
transformSource,
|
|
6
|
+
type TransformSourceArgs,
|
|
7
7
|
} from "../utils"
|
|
8
8
|
import { upgradeIconV1 } from "./upgradeIconV1"
|
|
9
9
|
|
|
10
10
|
const transformIcons = (
|
|
11
|
-
sourceFile:
|
|
11
|
+
sourceFile: TransformSourceArgs["sourceFile"],
|
|
12
12
|
tagNames: ImportModuleNameTagsMap
|
|
13
13
|
): string =>
|
|
14
14
|
transformSource({
|
|
15
15
|
sourceFile,
|
|
16
|
-
|
|
17
|
-
tagName: tagNames,
|
|
16
|
+
transformers: [upgradeIconV1(tagNames)],
|
|
18
17
|
})
|
|
19
18
|
|
|
20
19
|
describe("upgradeIconV1()", () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import ts from "typescript"
|
|
2
2
|
import {
|
|
3
3
|
setImportToRemove,
|
|
4
|
-
ImportModuleNameTagsMap,
|
|
4
|
+
type ImportModuleNameTagsMap,
|
|
5
5
|
updateKaioImports,
|
|
6
|
-
UpdateKaioImportsArgs,
|
|
6
|
+
type UpdateKaioImportsArgs,
|
|
7
7
|
setImportToAdd,
|
|
8
8
|
} from "../utils"
|
|
9
9
|
import { getNewIconPropsFromOldIconName } from "./getNewIconPropsFromOldIconName"
|
|
@@ -20,8 +20,9 @@ const reverseStringMap = <Key extends string, Value extends string>(
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const upgradeIconV1 =
|
|
23
|
-
(
|
|
24
|
-
|
|
23
|
+
(tagNames: ImportModuleNameTagsMap): ts.TransformerFactory<ts.SourceFile> =>
|
|
24
|
+
context =>
|
|
25
|
+
rootNode => {
|
|
25
26
|
const oldImportSource = "@kaizen/components"
|
|
26
27
|
|
|
27
28
|
const kaioTagNames = tagNames.get(oldImportSource)
|
|
@@ -85,10 +86,11 @@ export const upgradeIconV1 =
|
|
|
85
86
|
}
|
|
86
87
|
return ts.visitEachChild(node, visit, context)
|
|
87
88
|
}
|
|
89
|
+
|
|
88
90
|
const node = ts.visitNode(rootNode, visit)
|
|
89
91
|
|
|
90
92
|
return updateKaioImports({
|
|
91
93
|
importsToRemove: importsToRemove.size > 0 ? importsToRemove : undefined,
|
|
92
94
|
importsToAdd: importsToAdd.size > 0 ? importsToAdd : undefined,
|
|
93
|
-
})(context)(node)
|
|
95
|
+
})(context)(node as ts.SourceFile)
|
|
94
96
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react"
|
|
2
2
|
// @ts-ignore
|
|
3
3
|
import { Pancakes } from "@kaizen/components"
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
export const KaioComponent = (): JSX.Element => <Pancakes topping="butter" />
|
|
6
|
-
/* eslint-enable react/jsx-curly-brace-presence */
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`decodeEmptyLines() > replaces default line marker with empty line 1`] = `
|
|
4
|
+
"import React from "react"
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { Pancakes } from "@kaizen/components"
|
|
7
|
+
|
|
8
|
+
export const KaioComponent = (): JSX.Element => <Pancakes topping="butter" />
|
|
9
|
+
"
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
exports[`encodeEmptyLines() > replaces empty lines with default line marker 1`] = `
|
|
13
|
+
"import React from "react"
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import { Pancakes } from "@kaizen/components"
|
|
16
|
+
/*!--empty-line--!*/
|
|
17
|
+
export const KaioComponent = (): JSX.Element => <Pancakes topping="butter" />
|
|
18
|
+
/*!--empty-line--!*/"
|
|
19
|
+
`;
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`transformSource > updates the value of Pancakes topping to jam 1`] = `
|
|
4
|
-
"import
|
|
3
|
+
exports[`transformSource() > updates the value of Pancakes topping to jam 1`] = `
|
|
4
|
+
"import React from "react";
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
import { Pancakes } from "@kaizen/components";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
export const KaioComponent = (): JSX.Element => <Pancakes topping="jam"/>;
|
|
9
|
+
|
|
10
|
+
"
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
exports[`transformSourceForTagName > updates the value of Pancakes topping to jam 1`] = `
|
|
14
|
+
"import React from "react";
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import { Pancakes } from "@kaizen/components";
|
|
17
|
+
|
|
8
18
|
export const KaioComponent = (): JSX.Element => <Pancakes topping="jam"/>;
|
|
9
|
-
|
|
19
|
+
|
|
10
20
|
"
|
|
11
21
|
`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ts from "typescript"
|
|
2
|
+
import { encodeEmptyLines } from "./emptyLineEncoder"
|
|
3
|
+
|
|
4
|
+
export const createEncodedSourceFile = (
|
|
5
|
+
filePath: string,
|
|
6
|
+
sourceCode: string
|
|
7
|
+
): ts.SourceFile => {
|
|
8
|
+
const encodedSource = encodeEmptyLines(sourceCode)
|
|
9
|
+
return ts.createSourceFile(
|
|
10
|
+
filePath,
|
|
11
|
+
encodedSource,
|
|
12
|
+
ts.ScriptTarget.Latest,
|
|
13
|
+
true
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -2,12 +2,11 @@ import ts from "typescript"
|
|
|
2
2
|
import { parseJsx } from "../__tests__/utils/parseJsx"
|
|
3
3
|
import { createStyleProp } from "./createProp"
|
|
4
4
|
import { printAst } from "./printAst"
|
|
5
|
-
import {
|
|
5
|
+
import { TransformSourceArgs, transformSource } from "./transformSource"
|
|
6
6
|
import { updateJsxElementWithNewProps } from "./updateJsxElementWithNewProps"
|
|
7
7
|
|
|
8
|
-
export const mockedTransformer =
|
|
9
|
-
|
|
10
|
-
(rootNode: ts.Node): ts.Node => {
|
|
8
|
+
export const mockedTransformer: ts.TransformerFactory<ts.SourceFile> =
|
|
9
|
+
context => rootNode => {
|
|
11
10
|
const visit = (node: ts.Node): ts.Node => {
|
|
12
11
|
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
13
12
|
if (node.tagName.getText() === "Pancakes") {
|
|
@@ -32,16 +31,15 @@ export const mockedTransformer =
|
|
|
32
31
|
}
|
|
33
32
|
return ts.visitEachChild(node, visit, context)
|
|
34
33
|
}
|
|
35
|
-
return ts.visitNode(rootNode, visit)
|
|
34
|
+
return ts.visitNode(rootNode, visit) as ts.SourceFile
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
const testCreateStyleProp = (
|
|
39
|
-
sourceFile:
|
|
38
|
+
sourceFile: TransformSourceArgs["sourceFile"]
|
|
40
39
|
): string =>
|
|
41
40
|
transformSource({
|
|
42
41
|
sourceFile,
|
|
43
|
-
|
|
44
|
-
tagName: "Pancakes",
|
|
42
|
+
transformers: [mockedTransformer],
|
|
45
43
|
})
|
|
46
44
|
|
|
47
45
|
describe("createStyleProp()", () => {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from "fs"
|
|
2
|
+
import path from "path"
|
|
3
|
+
import { decodeEmptyLines, encodeEmptyLines } from "./emptyLineEncoder"
|
|
4
|
+
|
|
5
|
+
describe("encodeEmptyLines()", () => {
|
|
6
|
+
it("replaces empty lines with default line marker", () => {
|
|
7
|
+
const filePath = path.resolve(
|
|
8
|
+
path.join(__dirname, "./__fixtures__/KaioComponent.tsx")
|
|
9
|
+
)
|
|
10
|
+
const fileContent = fs.readFileSync(filePath, "utf8")
|
|
11
|
+
const output = encodeEmptyLines(fileContent)
|
|
12
|
+
expect(output).toMatchSnapshot()
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe("decodeEmptyLines()", () => {
|
|
17
|
+
it("replaces default line marker with empty line", () => {
|
|
18
|
+
const filePath = path.resolve(
|
|
19
|
+
path.join(__dirname, "./__fixtures__/KaioComponent.tsx")
|
|
20
|
+
)
|
|
21
|
+
const fileContent = fs.readFileSync(filePath, "utf8")
|
|
22
|
+
const output = decodeEmptyLines(fileContent)
|
|
23
|
+
expect(output).toMatchSnapshot()
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Fork of https://github.com/Serj-Tm/ts-empty-line-encoder/blob/master/encoder.ts
|
|
2
|
+
const DEFAULT_EMPTY_LINE_MARKER: string = "!--empty-line--!"
|
|
3
|
+
const DEFAULT_NEW_LINE: string = "\n"
|
|
4
|
+
|
|
5
|
+
const toComment = (marker: string): string => `/*${marker}*/`
|
|
6
|
+
|
|
7
|
+
export const encodeEmptyLines = (text: string): string => {
|
|
8
|
+
const marker = toComment(DEFAULT_EMPTY_LINE_MARKER)
|
|
9
|
+
const lines = text.split(/\r?\n/)
|
|
10
|
+
const commentedLines = lines.map(line => (line.trim() == "" ? marker : line))
|
|
11
|
+
return commentedLines.join(DEFAULT_NEW_LINE)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const decodeEmptyLines = (text: string): string => {
|
|
15
|
+
const markerRegex = toComment(DEFAULT_EMPTY_LINE_MARKER).replace(/\*/g, "\\*")
|
|
16
|
+
const decoded = text.replace(new RegExp(markerRegex, "gi"), "")
|
|
17
|
+
return decoded
|
|
18
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { parseJsx } from "../__tests__/utils"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
transformSourceForTagName,
|
|
4
|
+
printAst,
|
|
5
|
+
TransformSourceForTagNameArgs,
|
|
6
|
+
} from "../utils"
|
|
3
7
|
import { migrateStringProp } from "./migrateStringProp"
|
|
4
8
|
|
|
5
9
|
const transformTopping = (oldValue: string): string => {
|
|
@@ -12,9 +16,9 @@ const transformTopping = (oldValue: string): string => {
|
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
const testMigrateStringProp = (
|
|
15
|
-
sourceFile:
|
|
19
|
+
sourceFile: TransformSourceForTagNameArgs["sourceFile"]
|
|
16
20
|
): string =>
|
|
17
|
-
|
|
21
|
+
transformSourceForTagName({
|
|
18
22
|
sourceFile,
|
|
19
23
|
astTransformer: migrateStringProp(
|
|
20
24
|
"toppingOld",
|
|
@@ -2,7 +2,6 @@ import ts from "typescript"
|
|
|
2
2
|
import { getPropValueText } from "./getPropValueText"
|
|
3
3
|
import { updateJsxElementWithNewProps } from "./updateJsxElementWithNewProps"
|
|
4
4
|
|
|
5
|
-
/** Recurses through AST to find and update any jsx element that matched the tagName */
|
|
6
5
|
export const migrateStringProp =
|
|
7
6
|
<OldValue extends string, NewValue extends string>(
|
|
8
7
|
oldPropName: string,
|
|
@@ -10,7 +9,7 @@ export const migrateStringProp =
|
|
|
10
9
|
valueTransformer: (value: OldValue) => NewValue
|
|
11
10
|
) =>
|
|
12
11
|
(context: ts.TransformationContext, tagName: string) =>
|
|
13
|
-
(rootNode: ts.
|
|
12
|
+
(rootNode: ts.SourceFile): ts.SourceFile => {
|
|
14
13
|
const visit = (node: ts.Node): ts.Node => {
|
|
15
14
|
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
16
15
|
if (node.tagName.getText() === tagName) {
|
|
@@ -39,5 +38,5 @@ export const migrateStringProp =
|
|
|
39
38
|
}
|
|
40
39
|
return ts.visitEachChild(node, visit, context)
|
|
41
40
|
}
|
|
42
|
-
return ts.visitNode(rootNode, visit)
|
|
41
|
+
return ts.visitNode(rootNode, visit) as ts.SourceFile
|
|
43
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseJsx } from "../__tests__/utils"
|
|
2
|
-
import {
|
|
2
|
+
import { transformSourceForTagName, printAst } from "../utils"
|
|
3
3
|
import { removeProps } from "./removeProps"
|
|
4
4
|
|
|
5
5
|
describe("removeProps()", () => {
|
|
@@ -10,7 +10,7 @@ describe("removeProps()", () => {
|
|
|
10
10
|
const outputAst = parseJsx(`
|
|
11
11
|
export const TestComponent = () => <Pancakes />
|
|
12
12
|
`)
|
|
13
|
-
const transformed =
|
|
13
|
+
const transformed = transformSourceForTagName({
|
|
14
14
|
sourceFile: inputAst,
|
|
15
15
|
astTransformer: removeProps(["topping"]),
|
|
16
16
|
tagName: "Pancakes",
|
|
@@ -25,7 +25,7 @@ describe("removeProps()", () => {
|
|
|
25
25
|
const outputAst = parseJsx(`
|
|
26
26
|
export const TestComponent = () => <Pancakes />
|
|
27
27
|
`)
|
|
28
|
-
const transformed =
|
|
28
|
+
const transformed = transformSourceForTagName({
|
|
29
29
|
sourceFile: inputAst,
|
|
30
30
|
astTransformer: removeProps(["topping", "fruit"]),
|
|
31
31
|
tagName: "Pancakes",
|
|
@@ -40,7 +40,7 @@ describe("removeProps()", () => {
|
|
|
40
40
|
const outputAst = parseJsx(`
|
|
41
41
|
export const TestComponent = () => <Pancakes id="123"/>
|
|
42
42
|
`)
|
|
43
|
-
const transformed =
|
|
43
|
+
const transformed = transformSourceForTagName({
|
|
44
44
|
sourceFile: inputAst,
|
|
45
45
|
astTransformer: removeProps(["topping"]),
|
|
46
46
|
tagName: "Pancakes",
|
|
@@ -55,7 +55,7 @@ describe("removeProps()", () => {
|
|
|
55
55
|
const outputAst = parseJsx(`
|
|
56
56
|
export const TestComponent = () => <div><Pancakes /><Pancakes /></div>
|
|
57
57
|
`)
|
|
58
|
-
const transformed =
|
|
58
|
+
const transformed = transformSourceForTagName({
|
|
59
59
|
sourceFile: inputAst,
|
|
60
60
|
astTransformer: removeProps(["topping"]),
|
|
61
61
|
tagName: "Pancakes",
|
|
@@ -4,7 +4,7 @@ import { updateJsxElementWithNewProps } from "./updateJsxElementWithNewProps"
|
|
|
4
4
|
export const removeProps =
|
|
5
5
|
(propsToRemove: string[]) =>
|
|
6
6
|
(context: ts.TransformationContext, tagName: string) =>
|
|
7
|
-
(rootNode: ts.
|
|
7
|
+
(rootNode: ts.SourceFile): ts.SourceFile => {
|
|
8
8
|
function visit(node: ts.Node): ts.Node {
|
|
9
9
|
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
10
10
|
if (node.tagName.getText() === tagName) {
|
|
@@ -26,5 +26,5 @@ export const removeProps =
|
|
|
26
26
|
}
|
|
27
27
|
return ts.visitEachChild(node, visit, context)
|
|
28
28
|
}
|
|
29
|
-
return ts.visitNode(rootNode, visit)
|
|
29
|
+
return ts.visitNode(rootNode, visit) as ts.SourceFile
|
|
30
30
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import fs from "fs"
|
|
2
2
|
import path from "path"
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { createEncodedSourceFile } from "./createEncodedSourceFile"
|
|
4
|
+
import { getKaioTagName } from "./getKaioTagName"
|
|
5
|
+
import {
|
|
6
|
+
transformSourceForTagName,
|
|
7
|
+
type TransformSourceForTagNameArgs,
|
|
8
|
+
} from "./transformSource"
|
|
5
9
|
|
|
6
10
|
export const traverseDir = (
|
|
7
11
|
dir: string,
|
|
8
|
-
transformFile: (componentFilePath: string,
|
|
12
|
+
transformFile: (componentFilePath: string, sourceCode: string) => void
|
|
9
13
|
): void => {
|
|
10
14
|
if (dir.includes("node_modules")) {
|
|
11
15
|
return
|
|
@@ -19,15 +23,8 @@ export const traverseDir = (
|
|
|
19
23
|
if (fs.statSync(fullPath).isDirectory()) {
|
|
20
24
|
traverseDir(fullPath, transformFile)
|
|
21
25
|
} else if (fullPath.endsWith(".tsx")) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
fullPath,
|
|
25
|
-
source,
|
|
26
|
-
ts.ScriptTarget.Latest,
|
|
27
|
-
true
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
transformFile(fullPath, sourceFile)
|
|
26
|
+
const sourceCode = fs.readFileSync(fullPath, "utf8")
|
|
27
|
+
transformFile(fullPath, sourceCode)
|
|
31
28
|
}
|
|
32
29
|
})
|
|
33
30
|
}
|
|
@@ -35,16 +32,18 @@ export const traverseDir = (
|
|
|
35
32
|
/** Walks the directory and runs the AST transformer on the given component name */
|
|
36
33
|
export const transformComponentsInDir = (
|
|
37
34
|
dir: string,
|
|
38
|
-
transformer:
|
|
35
|
+
transformer: TransformSourceForTagNameArgs["astTransformer"],
|
|
39
36
|
componentName: string
|
|
40
37
|
): void => {
|
|
41
38
|
const transformFile = (
|
|
42
39
|
componentFilePath: string,
|
|
43
|
-
|
|
40
|
+
sourceCode: string
|
|
44
41
|
): void => {
|
|
42
|
+
const sourceFile = createEncodedSourceFile(componentFilePath, sourceCode)
|
|
43
|
+
|
|
45
44
|
const tagName = getKaioTagName(sourceFile, componentName)
|
|
46
45
|
if (tagName) {
|
|
47
|
-
const updatedSourceFile =
|
|
46
|
+
const updatedSourceFile = transformSourceForTagName({
|
|
48
47
|
sourceFile,
|
|
49
48
|
astTransformer: transformer,
|
|
50
49
|
tagName,
|
|
@@ -1,55 +1,84 @@
|
|
|
1
1
|
import fs from "fs"
|
|
2
2
|
import path from "path"
|
|
3
3
|
import ts from "typescript"
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
if (ts.isJsxSelfClosingElement(node)) {
|
|
24
|
-
return ts.factory.updateJsxSelfClosingElement(
|
|
25
|
-
node,
|
|
26
|
-
node.tagName,
|
|
27
|
-
node.typeArguments,
|
|
28
|
-
ts.factory.createJsxAttributes(newAttributes)
|
|
4
|
+
import { createEncodedSourceFile } from "./createEncodedSourceFile"
|
|
5
|
+
import {
|
|
6
|
+
TransformSourceForTagNameArgs,
|
|
7
|
+
transformSource,
|
|
8
|
+
transformSourceForTagName,
|
|
9
|
+
} from "./transformSource"
|
|
10
|
+
|
|
11
|
+
const visit =
|
|
12
|
+
(context: ts.TransformationContext, tagName: string) =>
|
|
13
|
+
(node: ts.Node): ts.Node => {
|
|
14
|
+
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
15
|
+
if (node.tagName.getText() === tagName) {
|
|
16
|
+
const newAttributes = node.attributes.properties.map(attr => {
|
|
17
|
+
if (ts.isJsxAttribute(attr) && attr.name.getText() === "topping") {
|
|
18
|
+
return ts.factory.updateJsxAttribute(
|
|
19
|
+
attr,
|
|
20
|
+
attr.name,
|
|
21
|
+
ts.factory.createStringLiteral("jam")
|
|
29
22
|
)
|
|
30
23
|
}
|
|
24
|
+
return attr
|
|
25
|
+
})
|
|
26
|
+
if (ts.isJsxSelfClosingElement(node)) {
|
|
27
|
+
return ts.factory.updateJsxSelfClosingElement(
|
|
28
|
+
node,
|
|
29
|
+
node.tagName,
|
|
30
|
+
node.typeArguments,
|
|
31
|
+
ts.factory.createJsxAttributes(newAttributes)
|
|
32
|
+
)
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
return ts.visitEachChild(node, visit, context)
|
|
34
35
|
}
|
|
35
|
-
return ts.
|
|
36
|
+
return ts.visitEachChild(node, visit(context, tagName), context)
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
describe("transformSource", () => {
|
|
39
|
+
describe("transformSource()", () => {
|
|
40
|
+
it("updates the value of Pancakes topping to jam", () => {
|
|
41
|
+
const filePath = path.resolve(
|
|
42
|
+
path.join(__dirname, "./__fixtures__/KaioComponent.tsx")
|
|
43
|
+
)
|
|
44
|
+
const fileContent = fs.readFileSync(filePath, "utf8")
|
|
45
|
+
const sourceFile = createEncodedSourceFile(filePath, fileContent)
|
|
46
|
+
const mockTransformer =
|
|
47
|
+
(tagName: string): ts.TransformerFactory<ts.SourceFile> =>
|
|
48
|
+
context =>
|
|
49
|
+
rootNode =>
|
|
50
|
+
ts.visitNode(rootNode, visit(context, tagName)) as ts.SourceFile
|
|
51
|
+
|
|
52
|
+
const transformed = transformSource({
|
|
53
|
+
sourceFile,
|
|
54
|
+
transformers: [mockTransformer("Pancakes")],
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
expect(transformed).toMatchSnapshot()
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe("transformSourceForTagName", () => {
|
|
39
62
|
it("updates the value of Pancakes topping to jam", () => {
|
|
40
63
|
const filePath = path.resolve(
|
|
41
64
|
path.join(__dirname, "./__fixtures__/KaioComponent.tsx")
|
|
42
65
|
)
|
|
43
66
|
const fileContent = fs.readFileSync(filePath, "utf8")
|
|
44
|
-
const sourceFile =
|
|
67
|
+
const sourceFile = createEncodedSourceFile(filePath, fileContent)
|
|
68
|
+
const mockTransformer =
|
|
69
|
+
(context: ts.TransformationContext, tagName: string) =>
|
|
70
|
+
(rootNode: ts.SourceFile): ts.SourceFile =>
|
|
71
|
+
ts.visitNode(rootNode, visit(context, tagName)) as ts.SourceFile
|
|
45
72
|
|
|
46
|
-
const
|
|
73
|
+
const mockTransformSourceForTagNameArgs = {
|
|
47
74
|
sourceFile,
|
|
48
|
-
astTransformer:
|
|
49
|
-
tagName: "
|
|
50
|
-
} satisfies
|
|
75
|
+
astTransformer: mockTransformer,
|
|
76
|
+
tagName: "Pancakes",
|
|
77
|
+
} satisfies TransformSourceForTagNameArgs
|
|
51
78
|
|
|
52
|
-
const transformed =
|
|
79
|
+
const transformed = transformSourceForTagName(
|
|
80
|
+
mockTransformSourceForTagNameArgs
|
|
81
|
+
)
|
|
53
82
|
|
|
54
83
|
expect(transformed).toMatchSnapshot()
|
|
55
84
|
})
|
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
import ts from "typescript"
|
|
2
|
-
import {
|
|
2
|
+
import { decodeEmptyLines } from "./emptyLineEncoder"
|
|
3
3
|
import { printAst } from "./printAst"
|
|
4
4
|
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export type TransformSourceArgs = {
|
|
6
|
+
sourceFile: ts.SourceFile
|
|
7
|
+
transformers: Array<ts.TransformerFactory<ts.SourceFile>>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const transformSource = ({
|
|
11
|
+
sourceFile,
|
|
12
|
+
transformers,
|
|
13
|
+
}: TransformSourceArgs): string => {
|
|
14
|
+
const result = ts.transform(sourceFile, transformers)
|
|
15
|
+
const transformedSource = printAst(result.transformed[0])
|
|
16
|
+
return decodeEmptyLines(transformedSource)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated - use transformSource instead of transformSourceForTagName
|
|
21
|
+
*/
|
|
22
|
+
export type TransformSourceForTagNameArgs = {
|
|
8
23
|
sourceFile: ts.SourceFile
|
|
9
24
|
astTransformer: (
|
|
10
25
|
context: ts.TransformationContext,
|
|
11
|
-
tagName:
|
|
12
|
-
) => (rootNode: ts.
|
|
13
|
-
tagName:
|
|
26
|
+
tagName: string
|
|
27
|
+
) => (rootNode: ts.SourceFile) => ts.SourceFile
|
|
28
|
+
tagName: string
|
|
14
29
|
}
|
|
15
30
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated - use transformSource instead
|
|
33
|
+
* Transforms the source file with the transformer and target import alias provided
|
|
34
|
+
*/
|
|
35
|
+
export const transformSourceForTagName = ({
|
|
20
36
|
sourceFile,
|
|
21
37
|
astTransformer,
|
|
22
38
|
tagName,
|
|
23
|
-
}:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return printAst(transformedSource)
|
|
30
|
-
}
|
|
39
|
+
}: TransformSourceForTagNameArgs): string =>
|
|
40
|
+
transformSource({
|
|
41
|
+
sourceFile,
|
|
42
|
+
transformers: [context => astTransformer(context, tagName)],
|
|
43
|
+
})
|
|
@@ -118,9 +118,12 @@ export type UpdateKaioImportsArgs = {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
export const updateKaioImports =
|
|
121
|
-
({
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
({
|
|
122
|
+
importsToRemove,
|
|
123
|
+
importsToAdd,
|
|
124
|
+
}: UpdateKaioImportsArgs): ts.TransformerFactory<ts.SourceFile> =>
|
|
125
|
+
context =>
|
|
126
|
+
rootNode => {
|
|
124
127
|
if (!ts.isSourceFile(rootNode)) return rootNode
|
|
125
128
|
|
|
126
129
|
if (!importsToRemove && !importsToAdd) return rootNode
|
|
@@ -4,7 +4,7 @@ var tslib = require('tslib');
|
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var reactAriaComponents = require('react-aria-components');
|
|
6
6
|
var mergeClassNames = require('../../../utils/mergeClassNames.cjs');
|
|
7
|
-
var Menu_module = require('./Menu.module.
|
|
7
|
+
var Menu_module = require('./Menu.module.css.cjs');
|
|
8
8
|
function _interopDefault(e) {
|
|
9
9
|
return e && e.__esModule ? e : {
|
|
10
10
|
default: e
|
|
@@ -4,7 +4,7 @@ var tslib = require('tslib');
|
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var reactAriaComponents = require('react-aria-components');
|
|
6
6
|
var mergeClassNames = require('../../../utils/mergeClassNames.cjs');
|
|
7
|
-
var MenuItem_module = require('./MenuItem.module.
|
|
7
|
+
var MenuItem_module = require('./MenuItem.module.css.cjs');
|
|
8
8
|
function _interopDefault(e) {
|
|
9
9
|
return e && e.__esModule ? e : {
|
|
10
10
|
default: e
|
|
@@ -19,12 +19,17 @@ var MenuItem = React.forwardRef(function (_a, ref) {
|
|
|
19
19
|
var className = _a.className,
|
|
20
20
|
icon = _a.icon,
|
|
21
21
|
children = _a.children,
|
|
22
|
-
|
|
22
|
+
textValue = _a.textValue,
|
|
23
|
+
props = tslib.__rest(_a, ["className", "icon", "children", "textValue"]);
|
|
24
|
+
var determinedTextValue = textValue || (typeof children === "string" ? children : undefined);
|
|
23
25
|
return React__default.default.createElement(reactAriaComponents.MenuItem, tslib.__assign({
|
|
24
26
|
ref: ref,
|
|
25
|
-
className: mergeClassNames.mergeClassNames(MenuItem_module.item, className)
|
|
26
|
-
|
|
27
|
+
className: mergeClassNames.mergeClassNames(MenuItem_module.item, className),
|
|
28
|
+
textValue: determinedTextValue
|
|
29
|
+
}, props), React__default.default.createElement(React__default.default.Fragment, null, typeof children === "string" && icon ? React__default.default.createElement("div", {
|
|
30
|
+
className: MenuItem_module.flexWrapper
|
|
31
|
+
}, React__default.default.createElement("span", {
|
|
27
32
|
className: MenuItem_module.iconWrapper
|
|
28
|
-
}, icon), children));
|
|
33
|
+
}, icon), children) : React__default.default.createElement(React__default.default.Fragment, null, children)));
|
|
29
34
|
});
|
|
30
35
|
exports.MenuItem = MenuItem;
|