@yahoo/uds 2.0.0-beta.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/cli/README.md +50 -0
  2. package/cli/bin/uds-darwin-arm64-baseline +0 -0
  3. package/cli/bin/uds-linux-arm64 +0 -0
  4. package/cli/bin/uds-linux-x64-baseline +0 -0
  5. package/cli/cli.ts +21 -4
  6. package/cli/commands/codemod/codemod.ts +12 -9
  7. package/cli/commands/codemod/sizingProps.ts +1 -1
  8. package/cli/commands/login.ts +30 -0
  9. package/cli/commands/logout.ts +27 -0
  10. package/cli/commands/purge.ts +3 -1
  11. package/cli/commands/sync.ts +2 -0
  12. package/cli/commands/uds.ts +6 -1
  13. package/cli/commands/version.ts +2 -0
  14. package/cli/compile.ts +8 -9
  15. package/cli/consts.ts +5 -2
  16. package/cli/env.d.ts +5 -0
  17. package/cli/exec.ts +1 -1
  18. package/cli/preload.ts +17 -0
  19. package/cli/tsconfig.json +4 -4
  20. package/cli/uds-cli +6 -2
  21. package/cli/utils/analytics.ts +26 -0
  22. package/cli/utils/auth.ts +338 -0
  23. package/cli/utils/client_secrets.json +23 -0
  24. package/cli/utils/client_secrets.json.enc +0 -0
  25. package/cli/utils/configWorker.ts +3 -2
  26. package/cli/utils/secrets.ts +40 -0
  27. package/dist/analytics/server.cjs +1 -0
  28. package/dist/analytics/server.d.cts +1 -0
  29. package/dist/analytics/server.d.ts +1 -0
  30. package/dist/analytics/server.js +1 -0
  31. package/dist/chunk-3PK6DOFO.js +3 -0
  32. package/dist/chunk-5WBROFT5.cjs +1 -0
  33. package/dist/chunk-DCXVARRB.cjs +1 -0
  34. package/dist/chunk-DMMTEAJW.cjs +2 -0
  35. package/dist/chunk-EYFQOFYW.cjs +1 -0
  36. package/dist/chunk-FWF2C6TL.cjs +1 -0
  37. package/dist/chunk-GIJ2FHY5.cjs +1 -0
  38. package/dist/chunk-IUL5ZI4O.js +2 -0
  39. package/dist/chunk-JGIKFUBH.cjs +2 -0
  40. package/dist/chunk-P5B5IOMM.js +2 -0
  41. package/dist/chunk-PE2P7J44.js +2 -0
  42. package/dist/chunk-PFT3UA6K.cjs +2 -0
  43. package/dist/chunk-SUASN3GG.js +2 -0
  44. package/dist/chunk-VPR62GYQ.js +2 -0
  45. package/dist/chunk-X6F5UEQ5.js +2 -0
  46. package/dist/chunk-YM5TKITI.js +2 -0
  47. package/dist/chunk-YUHY3FXT.cjs +1 -0
  48. package/dist/chunk-ZV62SW5G.js +1 -0
  49. package/dist/client/index.cjs +3 -0
  50. package/dist/client/index.d.cts +97 -0
  51. package/dist/client/index.d.ts +97 -0
  52. package/dist/client/index.js +4 -0
  53. package/dist/experimental/index.cjs +2 -0
  54. package/dist/experimental/index.d.cts +469 -0
  55. package/dist/experimental/index.d.ts +469 -0
  56. package/dist/experimental/index.js +2 -0
  57. package/dist/fixtures.cjs +1506 -0
  58. package/dist/fixtures.d.cts +94 -0
  59. package/dist/fixtures.d.ts +94 -0
  60. package/dist/fixtures.js +1449 -0
  61. package/dist/flags.cjs +1 -0
  62. package/dist/flags.d.cts +17 -0
  63. package/dist/flags.d.ts +17 -0
  64. package/dist/flags.js +2 -0
  65. package/dist/index.cjs +1 -0
  66. package/dist/index.d.cts +385 -0
  67. package/dist/index.d.ts +385 -0
  68. package/dist/index.js +1 -0
  69. package/dist/metafile-cjs.json +1 -0
  70. package/dist/metafile-esm.json +1 -0
  71. package/dist/motionFeatures-I76FFCTS.js +1 -0
  72. package/dist/motionFeatures-P3FQL2KP.cjs +1 -0
  73. package/dist/styles/toast.css +3 -0
  74. package/dist/styles/toast.d.cts +2 -0
  75. package/dist/styles/toast.d.ts +2 -0
  76. package/dist/tailwind/plugin.cjs +2 -0
  77. package/dist/tailwind/plugin.d.cts +60 -0
  78. package/dist/tailwind/plugin.d.ts +60 -0
  79. package/dist/tailwind/plugin.js +2 -0
  80. package/dist/tailwind/purger.cjs +5 -0
  81. package/dist/tailwind/purger.d.cts +17 -0
  82. package/dist/tailwind/purger.d.ts +17 -0
  83. package/dist/tailwind/purger.js +6 -0
  84. package/dist/tailwind/tsMorph.cjs +1 -0
  85. package/dist/tailwind/tsMorph.d.cts +31 -0
  86. package/dist/tailwind/tsMorph.d.ts +31 -0
  87. package/dist/tailwind/tsMorph.js +1 -0
  88. package/dist/tailwind/utils.cjs +1 -0
  89. package/dist/tailwind/utils.d.cts +99 -0
  90. package/dist/tailwind/utils.d.ts +99 -0
  91. package/dist/tailwind/utils.js +1 -0
  92. package/dist/tokens/index.cjs +1 -0
  93. package/dist/tokens/index.d.cts +1127 -0
  94. package/dist/tokens/index.d.ts +1127 -0
  95. package/dist/tokens/index.js +1 -0
  96. package/dist/tokens/parseTokens.cjs +1 -0
  97. package/dist/tokens/parseTokens.d.cts +59 -0
  98. package/dist/tokens/parseTokens.d.ts +59 -0
  99. package/dist/tokens/parseTokens.js +1 -0
  100. package/dist/types-Pyccco5Q.d.cts +949 -0
  101. package/dist/types-Pyccco5Q.d.ts +949 -0
  102. package/fonts/mobile.cjs +1 -1
  103. package/package.json +183 -156
  104. package/cli/codemods/propsToClass.test.tsx +0 -97
  105. package/cli/utils/purgeCSS.test.ts +0 -210
package/fonts/mobile.cjs CHANGED
@@ -25,5 +25,5 @@ var fonts = [
25
25
  require.resolve('@yahoo/uds/fonts/yahoo-serif-display-bold.otf'),
26
26
  ];
27
27
 
28
- // eslint-disable-next-line no-undef
28
+
29
29
  module.exports.fonts = fonts;
package/package.json CHANGED
@@ -1,156 +1,183 @@
1
- {
2
- "name": "@yahoo/uds",
3
- "description": "Yahoo Universal System",
4
- "version": "2.0.0-beta.1",
5
- "type": "module",
6
- "bin": {
7
- "uds": "./cli/uds-cli"
8
- },
9
- "files": [
10
- "cli/**",
11
- "dist/**",
12
- "fonts/**",
13
- "package.json"
14
- ],
15
- "sideEffects": false,
16
- "exports": {
17
- ".": {
18
- "import": {
19
- "types": "./dist/index.d.ts",
20
- "default": "./dist/index.js"
21
- },
22
- "require": {
23
- "types": "./dist/index.d.cts",
24
- "default": "./dist/index.cjs"
25
- }
26
- },
27
- "./client": {
28
- "import": {
29
- "types": "./dist/client/index.d.ts",
30
- "default": "./dist/client/index.js"
31
- },
32
- "require": {
33
- "types": "./dist/client/index.d.cts",
34
- "default": "./dist/client/index.cjs"
35
- }
36
- },
37
- "./experimental": {
38
- "import": {
39
- "types": "./dist/experimental/index.d.ts",
40
- "default": "./dist/experimental/index.js"
41
- },
42
- "require": {
43
- "types": "./dist/experimental/index.d.cts",
44
- "default": "./dist/experimental/index.cjs"
45
- }
46
- },
47
- "./fixtures": {
48
- "import": {
49
- "types": "./dist/fixtures.d.ts",
50
- "default": "./dist/fixtures.js"
51
- },
52
- "require": {
53
- "types": "./dist/fixtures.d.cts",
54
- "default": "./dist/fixtures.cjs"
55
- }
56
- },
57
- "./fonts/*.otf": "./fonts/*.otf",
58
- "./fonts/*.ttf": "./fonts/*.ttf",
59
- "./fonts/*.woff2": "./fonts/*.woff2",
60
- "./fonts/*": {
61
- "types": "./fonts/*.d.ts",
62
- "require": "./fonts/*.cjs"
63
- },
64
- "./package.json": "./package.json",
65
- "./styles/*": "./dist/styles/*",
66
- "./tailwind/*": {
67
- "import": {
68
- "types": "./dist/tailwind/*.d.ts",
69
- "default": "./dist/tailwind/*.js"
70
- },
71
- "require": {
72
- "types": "./dist/tailwind/*.d.cts",
73
- "default": "./dist/tailwind/*.cjs"
74
- }
75
- },
76
- "./tokens": {
77
- "import": {
78
- "types": "./dist/tokens/index.d.ts",
79
- "default": "./dist/tokens/index.js"
80
- },
81
- "require": {
82
- "types": "./dist/tokens/index.d.cts",
83
- "default": "./dist/tokens/index.cjs"
84
- }
85
- },
86
- "./tokens/parseTokens": {
87
- "import": {
88
- "types": "./dist/tokens/parseTokens.d.ts",
89
- "default": "./dist/tokens/parseTokens.js"
90
- },
91
- "require": {
92
- "types": "./dist/tokens/parseTokens.d.cts",
93
- "default": "./dist/tokens/parseTokens.cjs"
94
- }
95
- }
96
- },
97
- "scripts": {
98
- "build": "bun run ./scripts/prebuild.ts && tsup && bun run ./scripts/postbuild.ts",
99
- "build:cli": "bun ./cli/compile.ts",
100
- "build:fixtures": "bun run ./scripts/buildFixtures.ts",
101
- "build:purgeCSSData": "bun run ./scripts/generatePurgeCSSData.ts",
102
- "ci:publish": "npx semantic-release -e semantic-release-monorepo --debug",
103
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .coverage",
104
- "dev": "concurrently bun:dev:*",
105
- "dev:fixtures": "bun run ./scripts/buildFixtures.ts --watch",
106
- "dev:purgeCSSData": "bun run ./scripts/generatePurgeCSSData.ts --watch",
107
- "dev:ts": "tsup --watch",
108
- "lint": "ESLINT_USE_FLAT_CONFIG=true eslint -c eslint.config.mjs .",
109
- "lint:pkg": "bun publint",
110
- "test": "vitest run",
111
- "test:bun": "bun run test:bun:scripts && bun run test:bun:cli",
112
- "test:bun:cli": "cd ./cli && bun test",
113
- "test:bun:scripts": "cd ./scripts && bun test",
114
- "test:coverage": "vitest run --coverage",
115
- "test:ui": "vitest --ui --coverage",
116
- "test:watch": "vitest",
117
- "typecheck": "concurrently bun:typecheck:*",
118
- "typecheck:cli": "tsc -p ./cli --noEmit",
119
- "typecheck:scripts": "tsc -p ./scripts --noEmit",
120
- "typecheck:uds": "tsc -p . --noEmit"
121
- },
122
- "dependencies": {
123
- "@ariakit/react": "^0.4.11",
124
- "bluebun": "^0.0.34",
125
- "clsx": "^2.1.1",
126
- "framer-motion": "^11.5.4",
127
- "imurmurhash": "^0.1.4",
128
- "lodash-es": "^4.17.21",
129
- "prompts": "^2.4.2",
130
- "react-toastify": "^10.0.5",
131
- "semver": "^7.6.3",
132
- "tailwind-merge": "^2.5.2",
133
- "ts-morph": "^23.0.0"
134
- },
135
- "devDependencies": {
136
- "@fullhuman/postcss-purgecss": "^6.0.0",
137
- "@types/imurmurhash": "^0.1.4",
138
- "@types/prompts": "^2.4.9",
139
- "@types/react": "^18.3.5",
140
- "@types/react-dom": "^18.3.0",
141
- "@yahoo/uds-icons": "1.0.4",
142
- "autoprefixer": "^10.4.20",
143
- "chalk": "^5.3.0",
144
- "concurrently": "^8.2.2",
145
- "postcss": "^8.4.45",
146
- "tailwindcss": "^3.4.10",
147
- "terser": "^5.31.6",
148
- "tsconfig": "0.0.1",
149
- "tsup": "^8.2.4"
150
- },
151
- "peerDependencies": {
152
- "react": "^18.3.1",
153
- "react-dom": "^18.3.1",
154
- "tailwindcss": "^3.4.10"
155
- }
156
- }
1
+ {
2
+ "name": "@yahoo/uds",
3
+ "description": "Yahoo Universal System",
4
+ "version": "2.1.0",
5
+ "type": "module",
6
+ "bin": {
7
+ "uds": "./cli/uds-cli"
8
+ },
9
+ "files": [
10
+ "cli/**",
11
+ "!cli/**/*.test.*",
12
+ "dist/**",
13
+ "fonts/**"
14
+ ],
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "import": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "require": {
23
+ "types": "./dist/index.d.cts",
24
+ "default": "./dist/index.cjs"
25
+ }
26
+ },
27
+ "./analytics/server": {
28
+ "import": {
29
+ "types": "./dist/analytics/server.d.ts",
30
+ "default": "./dist/analytics/server.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/analytics/server.d.cts",
34
+ "default": "./dist/analytics/server.cjs"
35
+ }
36
+ },
37
+ "./flags": {
38
+ "import": {
39
+ "types": "./dist/flags.d.ts",
40
+ "default": "./dist/flags.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/flags.d.cts",
44
+ "default": "./dist/flags.cjs"
45
+ }
46
+ },
47
+ "./client": {
48
+ "import": {
49
+ "types": "./dist/client/index.d.ts",
50
+ "default": "./dist/client/index.js"
51
+ },
52
+ "require": {
53
+ "types": "./dist/client/index.d.cts",
54
+ "default": "./dist/client/index.cjs"
55
+ }
56
+ },
57
+ "./experimental": {
58
+ "import": {
59
+ "types": "./dist/experimental/index.d.ts",
60
+ "default": "./dist/experimental/index.js"
61
+ },
62
+ "require": {
63
+ "types": "./dist/experimental/index.d.cts",
64
+ "default": "./dist/experimental/index.cjs"
65
+ }
66
+ },
67
+ "./fixtures": {
68
+ "import": {
69
+ "types": "./dist/fixtures.d.ts",
70
+ "default": "./dist/fixtures.js"
71
+ },
72
+ "require": {
73
+ "types": "./dist/fixtures.d.cts",
74
+ "default": "./dist/fixtures.cjs"
75
+ }
76
+ },
77
+ "./fonts/*.otf": "./fonts/*.otf",
78
+ "./fonts/*.ttf": "./fonts/*.ttf",
79
+ "./fonts/*.woff2": "./fonts/*.woff2",
80
+ "./fonts/*": {
81
+ "types": "./fonts/*.d.ts",
82
+ "require": "./fonts/*.cjs"
83
+ },
84
+ "./package.json": "./package.json",
85
+ "./styles/*": "./dist/styles/*",
86
+ "./tailwind/*": {
87
+ "import": {
88
+ "types": "./dist/tailwind/*.d.ts",
89
+ "default": "./dist/tailwind/*.js"
90
+ },
91
+ "require": {
92
+ "types": "./dist/tailwind/*.d.cts",
93
+ "default": "./dist/tailwind/*.cjs"
94
+ }
95
+ },
96
+ "./tokens": {
97
+ "import": {
98
+ "types": "./dist/tokens/index.d.ts",
99
+ "default": "./dist/tokens/index.js"
100
+ },
101
+ "require": {
102
+ "types": "./dist/tokens/index.d.cts",
103
+ "default": "./dist/tokens/index.cjs"
104
+ }
105
+ },
106
+ "./tokens/parseTokens": {
107
+ "import": {
108
+ "types": "./dist/tokens/parseTokens.d.ts",
109
+ "default": "./dist/tokens/parseTokens.js"
110
+ },
111
+ "require": {
112
+ "types": "./dist/tokens/parseTokens.d.cts",
113
+ "default": "./dist/tokens/parseTokens.cjs"
114
+ }
115
+ }
116
+ },
117
+ "scripts": {
118
+ "build": "bun run ./scripts/build.ts",
119
+ "build:cli": "bun run ./cli/utils/secrets.ts decrypt && bun ./cli/compile.ts",
120
+ "ci:publish": "bun semantic-release -e semantic-release-monorepo",
121
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .coverage && rm -rf cli/bin",
122
+ "dev": "concurrently bun:dev:*",
123
+ "dev:fixtures": "bun run ./scripts/buildFixtures.ts --watch",
124
+ "dev:purgeCSSData": "bun run ./scripts/generatePurgeCSSData.ts --watch",
125
+ "dev:ts": "tsup --watch",
126
+ "lint": "eslint -c eslint.config.mjs .",
127
+ "lint:fix": "bun run lint --fix",
128
+ "lint:pkg": "bun publint",
129
+ "test": "vitest run",
130
+ "test:bun": "bun run test:bun:scripts && bun run test:bun:cli",
131
+ "test:bun:cli": "cd ./cli && bun test",
132
+ "test:bun:scripts": "cd ./scripts && bun test",
133
+ "test:coverage": "vitest run --coverage",
134
+ "test:e2e": "bun run e2e/verifyCLI.ts",
135
+ "test:ui": "vitest --ui --coverage",
136
+ "test:watch": "vitest",
137
+ "typecheck": "concurrently bun:typecheck:*",
138
+ "typecheck:cli": "tsc -p ./cli --noEmit",
139
+ "typecheck:scripts": "tsc -p ./scripts --noEmit",
140
+ "typecheck:uds": "tsc -p . --noEmit"
141
+ },
142
+ "dependencies": {
143
+ "@ariakit/react": "^0.4.12",
144
+ "bluebun": "^0.0.34",
145
+ "clsx": "^2.1.1",
146
+ "firebase": "^11.0.0",
147
+ "framer-motion": "^11.11.4",
148
+ "googleapis": "^144.0.0",
149
+ "imurmurhash": "^0.1.4",
150
+ "lodash-es": "^4.17.21",
151
+ "open": "^10.1.0",
152
+ "prompts": "^2.4.2",
153
+ "react-toastify": "^10.0.5",
154
+ "semver": "^7.6.3",
155
+ "tailwind-merge": "^2.5.3",
156
+ "ts-morph": "^24.0.0",
157
+ "uuid": "^11.0.3"
158
+ },
159
+ "devDependencies": {
160
+ "@fullhuman/postcss-purgecss": "^7.0.0",
161
+ "@next/env": "^14.2.15",
162
+ "@types/bun": "1.1.14",
163
+ "@types/imurmurhash": "^0.1.4",
164
+ "@types/prompts": "^2.4.9",
165
+ "@types/react": "^18.3.11",
166
+ "@types/react-dom": "^18.3.0",
167
+ "@yahoo/uds-icons": "workspace:*",
168
+ "autoprefixer": "^10.4.20",
169
+ "chalk": "^5.3.0",
170
+ "concurrently": "^9.0.1",
171
+ "node-mocks-http": "^1.16.1",
172
+ "postcss": "^8.4.47",
173
+ "tailwindcss": "^3.4.13",
174
+ "terser": "^5.34.1",
175
+ "tsconfig": "workspace:*",
176
+ "tsup": "^8.3.0"
177
+ },
178
+ "peerDependencies": {
179
+ "react": "^18.3.1",
180
+ "react-dom": "^18.3.1",
181
+ "tailwindcss": "^3.4.13"
182
+ }
183
+ }
@@ -1,97 +0,0 @@
1
- import { unlink } from 'node:fs';
2
- import path from 'node:path';
3
-
4
- import * as bluebun from 'bluebun';
5
- import { afterEach, beforeAll, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test';
6
- import { IndentationText, Project } from 'ts-morph';
7
-
8
- import { propsToClass } from './propsToClass';
9
- import { sizingPropToClassMap } from './utils/sizingPropToClassMap';
10
-
11
- const FILE_NAME = 'PropsToClass.mock.tsx';
12
- const FILE_BEFORE = `
13
- import { Button, cx, HStack, Text } from '@yahoo/uds';
14
- const textClassName = cx('text-primary');
15
- const otherProps = { height: 'fit' };
16
-
17
- export const PageA = () => {
18
- return (
19
- <HStack width="full" maxHeight="screen">
20
- <Button minWidth="full">Click me</Button>
21
- <Text width="10/12" className={textClassName}>Some text</Text>
22
- <Text {...otherProps}>Some text</Text>
23
- </HStack>
24
- );
25
- }
26
- `.trim();
27
- const FILE_AFTER = `
28
- import { Button, cx, HStack, Text } from '@yahoo/uds';
29
- const textClassName = cx('text-primary');
30
- const otherProps = { height: 'fit' };
31
-
32
- export const PageA = () => {
33
- return (
34
- <HStack className="w-full max-h-screen">
35
- <Button className="min-w-full">Click me</Button>
36
- {/* 🙏 TODO: Add w-10/12 to your className attribute */}
37
- <Text className={textClassName}>Some text</Text>
38
- <Text {...otherProps}>Some text</Text>
39
- </HStack>
40
- );
41
- }
42
- `.trim();
43
-
44
- describe('propsToClass', () => {
45
- const workspaceDir = Bun.env.PWD;
46
- const srcDir = path.join(workspaceDir, 'tsconfig.json');
47
- const project = new Project({
48
- tsConfigFilePath: srcDir,
49
- manipulationSettings: { indentationText: IndentationText.TwoSpaces },
50
- });
51
-
52
- beforeAll(async () => {
53
- // setup mocks
54
- mock.module('bluebun', () => ({ print: () => 'mocked' }));
55
- });
56
-
57
- beforeEach(async () => {
58
- // Setup files
59
- project.createSourceFile(FILE_NAME, FILE_BEFORE, {
60
- overwrite: true,
61
- });
62
- });
63
- afterEach(async () => {
64
- // teardown files
65
- unlink(FILE_NAME, (err) => {
66
- if (err) {
67
- throw err;
68
- }
69
- });
70
- });
71
-
72
- it('converts props to classNames', async () => {
73
- // Sanity check
74
- const fileBefore = project.getSourceFile(FILE_NAME)?.getText();
75
- expect(fileBefore).toEqual(FILE_BEFORE);
76
-
77
- // Apply the codemod
78
- await propsToClass({ propToClassMap: sizingPropToClassMap, project });
79
-
80
- // Confirm it's been transformed
81
- const fileAfter = project.getSourceFile(FILE_NAME)?.getText();
82
- expect(fileAfter).toEqual(FILE_AFTER);
83
- });
84
- it('logs a warning when a complex expression is found', async () => {
85
- // Spy on the bun logger
86
- const spy = spyOn(bluebun, 'print');
87
-
88
- // Apply the codemod
89
- await propsToClass({
90
- propToClassMap: sizingPropToClassMap,
91
- project,
92
- });
93
-
94
- // We print 3 times for each complex expression, and 2 times for each spread expression
95
- expect(spy).toHaveBeenCalledTimes(5);
96
- });
97
- });
@@ -1,210 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import { Project } from 'ts-morph';
3
-
4
- import {
5
- getClassesForEnabledThemesAndScales,
6
- getComponentsToConvertToTW,
7
- getFiles,
8
- getTailwindSafelist,
9
- getUsedProps,
10
- isUDSComponent,
11
- parseFiles,
12
- scanGetStylesReferences,
13
- } from './purgeCSS';
14
-
15
- const PAGE_A_CODE = `
16
- import { HStack, Button, getStyles } from '@yahoo/uds';
17
-
18
- const functionWithProp = () => {
19
- const vars = {
20
- isActive: false
21
- };
22
-
23
- return {
24
- ...vars,
25
- color: 'blue'
26
- }
27
- }
28
-
29
- const AnotherComponent = () => {
30
- const propsList = functionWithProp();
31
-
32
- const classNames = getStyles({
33
- borderStartColor: 'primary'
34
- });
35
-
36
- return <HStack testProp="testValue" classNames={classNames} {...propsList}>meow</HStack>
37
- }
38
-
39
- const PageA = () => {
40
- const justifyContent = 'justify-start';
41
- const classNames = getStyles({
42
- justifyContent
43
- });
44
-
45
- return (
46
- <div>
47
- <HStack />
48
- <Button> Click me </Button>
49
- </div>
50
- )
51
- }
52
- `;
53
-
54
- const PAGE_B_CODE = `
55
- import { HStack, Spinner } from '@yahoo/uds';
56
- import { noop } from 'lodash';
57
-
58
- const PageB = () => {
59
- return (
60
- <div>
61
- <HStack flexGrow="1" alignItems="center" justifyContent="center">
62
- <Spinner />
63
- </HStack>
64
- </div>
65
- )
66
- }
67
- `;
68
-
69
- const FILES = ['/pages/PageA.tsx', '/pages/PageB.tsx'];
70
- const IMPORTED_UDS_COMPONENTS = ['HStack', 'Button', 'getStyles', 'Spinner'];
71
-
72
- describe('purgeCSS', () => {
73
- const project = new Project();
74
-
75
- describe('getFiles', () => {
76
- it('returns the list of files', async () => {
77
- const files = await getFiles('./src/');
78
-
79
- expect(files).toEqual(FILES);
80
- });
81
- });
82
-
83
- describe('parseFiles', () => {
84
- it('returns the list of imports from @yahoo/uds', () => {
85
- project.createSourceFile(FILES[0], PAGE_A_CODE, {
86
- overwrite: true,
87
- });
88
- project.createSourceFile(FILES[1], PAGE_B_CODE, {
89
- overwrite: true,
90
- });
91
-
92
- const res = parseFiles(project, FILES);
93
-
94
- expect(res).toEqual(IMPORTED_UDS_COMPONENTS);
95
- });
96
- });
97
-
98
- describe('getTailwindSafelist', () => {
99
- it('returns the tailwind classes required for all the components', () => {
100
- project.createSourceFile(FILES[0], PAGE_A_CODE, {
101
- overwrite: true,
102
- });
103
- project.createSourceFile(FILES[1], PAGE_B_CODE, {
104
- overwrite: true,
105
- });
106
-
107
- const res = getTailwindSafelist(project, IMPORTED_UDS_COMPONENTS);
108
-
109
- expect(res).toEqual([
110
- 'container',
111
- 'fill',
112
- 'items-start',
113
- 'items-center',
114
- 'justify-start',
115
- 'justify-center',
116
- 'text-accent',
117
- 'text-alert',
118
- 'text-black',
119
- 'text-brand',
120
- 'text-positive',
121
- 'text-warning',
122
- 'text-white',
123
- 'text-transparent',
124
- 'text-muted',
125
- 'text-on-color',
126
- 'text-primary',
127
- 'text-secondary',
128
- 'text-tertiary',
129
- 'text-current',
130
- 'border-s-primary',
131
- ]);
132
- });
133
- });
134
-
135
- describe('getComponentsToConvertToTW', () => {
136
- it('should get just exports which are components from UDS', () => {
137
- const res = getComponentsToConvertToTW(['Button', 'HStack', 'randomThingy']);
138
-
139
- expect(res).toEqual(['Button', 'Icon', 'Pressable', 'Text', 'HStack', 'Box']);
140
- });
141
- });
142
-
143
- describe('isUDSComponent', () => {
144
- it('returns true if the component is exported from UDS', () => {
145
- const res = isUDSComponent('HStack');
146
-
147
- expect(res).toBeTrue();
148
- });
149
-
150
- it('returns false if the component is not exported from UDS', () => {
151
- const res = isUDSComponent('NotUdsComponent');
152
-
153
- expect(res).toBeFalse();
154
- });
155
- });
156
-
157
- describe('getUsedProps', () => {
158
- it('return the list of all used props in the project for a given component', () => {
159
- project.createSourceFile(FILES[0], PAGE_A_CODE, {
160
- overwrite: true,
161
- });
162
- project.createSourceFile(FILES[1], PAGE_B_CODE, {
163
- overwrite: true,
164
- });
165
-
166
- const usedProps = getUsedProps(project, 'HStack');
167
-
168
- expect(usedProps).toEqual([
169
- ['testProp', ['testValue']],
170
- ['classNames', []],
171
- ['color', []],
172
- ['isActive', []],
173
- ['flexGrow', ['1']],
174
- ['alignItems', ['center']],
175
- ['justifyContent', ['center']],
176
- ]);
177
- });
178
- });
179
-
180
- describe('getClassesForEnabledThemesAndScales', () => {
181
- it('returns the list of classes related to the mode/themes we have in the config', () => {
182
- const classes = getClassesForEnabledThemesAndScales();
183
-
184
- expect(classes).toEqual([
185
- 'uds-color-mode-dark',
186
- 'uds-color-mode-light',
187
- 'uds-scale-mode-large',
188
- ]);
189
- });
190
- });
191
-
192
- describe('scanGetStylesReferences', () => {
193
- it('should scan the project for getStyles references and return the used variants', () => {
194
- project.createSourceFile(FILES[0], PAGE_A_CODE, {
195
- overwrite: true,
196
- });
197
- project.createSourceFile(FILES[1], PAGE_B_CODE, {
198
- overwrite: true,
199
- });
200
-
201
- const res = scanGetStylesReferences(project);
202
-
203
- const expectedResult = new Map();
204
- expectedResult.set('borderStartColor', new Set(['primary']));
205
- expectedResult.set('justifyContent', new Set([]));
206
-
207
- expect(res).toEqual(expectedResult);
208
- });
209
- });
210
- });