|
| 1 | +import os from 'node:os' |
1 | 2 | import path from 'node:path'
|
| 3 | +import { describe } from 'vitest' |
2 | 4 | import { candidate, css, html, js, json, test, yaml } from '../utils'
|
3 | 5 |
|
4 |
| -test( |
5 |
| - 'production build', |
6 |
| - { |
7 |
| - fs: { |
8 |
| - 'package.json': json`{}`, |
9 |
| - 'pnpm-workspace.yaml': yaml` |
10 |
| - # |
11 |
| - packages: |
12 |
| - - project-a |
13 |
| - `, |
14 |
| - 'project-a/package.json': json` |
15 |
| - { |
16 |
| - "dependencies": { |
17 |
| - "tailwindcss": "workspace:^", |
18 |
| - "@tailwindcss/cli": "workspace:^" |
| 6 | +const STANDALONE_BINARY = (() => { |
| 7 | + switch (os.platform()) { |
| 8 | + case 'win32': |
| 9 | + return 'tailwindcss-windows-x64.exe' |
| 10 | + case 'darwin': |
| 11 | + return os.arch() === 'x64' ? 'tailwindcss-macos-x64' : 'tailwindcss-macos-arm64' |
| 12 | + case 'linux': |
| 13 | + return os.arch() === 'x64' ? 'tailwindcss-linux-x64' : 'tailwindcss-linux-arm64' |
| 14 | + default: |
| 15 | + throw new Error(`Unsupported platform: ${os.platform()} ${os.arch()}`) |
| 16 | + } |
| 17 | +})() |
| 18 | + |
| 19 | +describe.each([ |
| 20 | + ['CLI', 'pnpm tailwindcss'], |
| 21 | + [ |
| 22 | + 'Standalone CLI', |
| 23 | + path.resolve(__dirname, `../../packages/@tailwindcss-standalone/dist/${STANDALONE_BINARY}`), |
| 24 | + ], |
| 25 | +])('%s', (_, command) => { |
| 26 | + test( |
| 27 | + 'production build', |
| 28 | + { |
| 29 | + fs: { |
| 30 | + 'package.json': json`{}`, |
| 31 | + 'pnpm-workspace.yaml': yaml` |
| 32 | + # |
| 33 | + packages: |
| 34 | + - project-a |
| 35 | + `, |
| 36 | + 'project-a/package.json': json` |
| 37 | + { |
| 38 | + "dependencies": { |
| 39 | + "tailwindcss": "workspace:^", |
| 40 | + "@tailwindcss/cli": "workspace:^" |
| 41 | + } |
| 42 | + } |
| 43 | + `, |
| 44 | + 'project-a/index.html': html` |
| 45 | + <div |
| 46 | + class="underline 2xl:font-bold hocus:underline inverted:flex" |
| 47 | + ></div> |
| 48 | + `, |
| 49 | + 'project-a/plugin.js': js` |
| 50 | + module.exports = function ({ addVariant }) { |
| 51 | + addVariant('inverted', '@media (inverted-colors: inverted)') |
| 52 | + addVariant('hocus', ['&:focus', '&:hover']) |
19 | 53 | }
|
20 |
| - } |
21 |
| - `, |
22 |
| - 'project-a/index.html': html` |
23 |
| - <div |
24 |
| - class="underline 2xl:font-bold hocus:underline inverted:flex" |
25 |
| - ></div> |
26 |
| - `, |
27 |
| - 'project-a/plugin.js': js` |
28 |
| - module.exports = function ({ addVariant }) { |
29 |
| - addVariant('inverted', '@media (inverted-colors: inverted)') |
30 |
| - addVariant('hocus', ['&:focus', '&:hover']) |
31 |
| - } |
32 |
| - `, |
33 |
| - 'project-a/src/index.css': css` |
34 |
| - @import 'tailwindcss/utilities'; |
35 |
| - @source '../../project-b/src/**/*.js'; |
36 |
| - @plugin '../plugin.js'; |
37 |
| - `, |
38 |
| - 'project-a/src/index.js': js` |
39 |
| - const className = "content-['project-a/src/index.js']" |
40 |
| - module.exports = { className } |
41 |
| - `, |
42 |
| - 'project-b/src/index.js': js` |
43 |
| - const className = "content-['project-b/src/index.js']" |
44 |
| - module.exports = { className } |
45 |
| - `, |
| 54 | + `, |
| 55 | + 'project-a/src/index.css': css` |
| 56 | + @import 'tailwindcss/utilities'; |
| 57 | + @source '../../project-b/src/**/*.js'; |
| 58 | + @plugin '../plugin.js'; |
| 59 | + `, |
| 60 | + 'project-a/src/index.js': js` |
| 61 | + const className = "content-['project-a/src/index.js']" |
| 62 | + module.exports = { className } |
| 63 | + `, |
| 64 | + 'project-b/src/index.js': js` |
| 65 | + const className = "content-['project-b/src/index.js']" |
| 66 | + module.exports = { className } |
| 67 | + `, |
| 68 | + }, |
46 | 69 | },
|
47 |
| - }, |
48 |
| - async ({ root, fs, exec }) => { |
49 |
| - await exec('pnpm tailwindcss --input src/index.css --output dist/out.css', { |
50 |
| - cwd: path.join(root, 'project-a'), |
51 |
| - }) |
| 70 | + async ({ root, fs, exec }) => { |
| 71 | + await exec(`${command} --input src/index.css --output dist/out.css`, { |
| 72 | + cwd: path.join(root, 'project-a'), |
| 73 | + }) |
52 | 74 |
|
53 |
| - await fs.expectFileToContain('project-a/dist/out.css', [ |
54 |
| - candidate`underline`, |
55 |
| - candidate`content-['project-a/src/index.js']`, |
56 |
| - candidate`content-['project-b/src/index.js']`, |
57 |
| - candidate`inverted:flex`, |
58 |
| - candidate`hocus:underline`, |
59 |
| - ]) |
60 |
| - }, |
61 |
| -) |
| 75 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 76 | + candidate`underline`, |
| 77 | + candidate`content-['project-a/src/index.js']`, |
| 78 | + candidate`content-['project-b/src/index.js']`, |
| 79 | + candidate`inverted:flex`, |
| 80 | + candidate`hocus:underline`, |
| 81 | + ]) |
| 82 | + }, |
| 83 | + ) |
62 | 84 |
|
63 |
| -test( |
64 |
| - 'watch mode', |
65 |
| - { |
66 |
| - fs: { |
67 |
| - 'package.json': json`{}`, |
68 |
| - 'pnpm-workspace.yaml': yaml` |
69 |
| - # |
70 |
| - packages: |
71 |
| - - project-a |
72 |
| - `, |
73 |
| - 'project-a/package.json': json` |
74 |
| - { |
75 |
| - "dependencies": { |
76 |
| - "tailwindcss": "workspace:^", |
77 |
| - "@tailwindcss/cli": "workspace:^" |
| 85 | + test( |
| 86 | + 'watch mode', |
| 87 | + { |
| 88 | + fs: { |
| 89 | + 'package.json': json`{}`, |
| 90 | + 'pnpm-workspace.yaml': yaml` |
| 91 | + # |
| 92 | + packages: |
| 93 | + - project-a |
| 94 | + `, |
| 95 | + 'project-a/package.json': json` |
| 96 | + { |
| 97 | + "dependencies": { |
| 98 | + "tailwindcss": "workspace:^", |
| 99 | + "@tailwindcss/cli": "workspace:^" |
| 100 | + } |
78 | 101 | }
|
79 |
| - } |
80 |
| - `, |
81 |
| - 'project-a/index.html': html` |
82 |
| - <div |
83 |
| - class="underline 2xl:font-bold hocus:underline inverted:flex" |
84 |
| - ></div> |
85 |
| - `, |
86 |
| - 'project-a/plugin.js': js` |
87 |
| - module.exports = function ({ addVariant }) { |
88 |
| - addVariant('inverted', '@media (inverted-colors: inverted)') |
89 |
| - addVariant('hocus', ['&:focus', '&:hover']) |
90 |
| - } |
91 |
| - `, |
92 |
| - 'project-a/src/index.css': css` |
93 |
| - @import 'tailwindcss/utilities'; |
94 |
| - @source '../../project-b/src/**/*.js'; |
95 |
| - @plugin '../plugin.js'; |
96 |
| - `, |
97 |
| - 'project-a/src/index.js': js` |
98 |
| - const className = "content-['project-a/src/index.js']" |
99 |
| - module.exports = { className } |
100 |
| - `, |
101 |
| - 'project-b/src/index.js': js` |
102 |
| - const className = "content-['project-b/src/index.js']" |
103 |
| - module.exports = { className } |
104 |
| - `, |
| 102 | + `, |
| 103 | + 'project-a/index.html': html` |
| 104 | + <div |
| 105 | + class="underline 2xl:font-bold hocus:underline inverted:flex" |
| 106 | + ></div> |
| 107 | + `, |
| 108 | + 'project-a/plugin.js': js` |
| 109 | + module.exports = function ({ addVariant }) { |
| 110 | + addVariant('inverted', '@media (inverted-colors: inverted)') |
| 111 | + addVariant('hocus', ['&:focus', '&:hover']) |
| 112 | + } |
| 113 | + `, |
| 114 | + 'project-a/src/index.css': css` |
| 115 | + @import 'tailwindcss/utilities'; |
| 116 | + @source '../../project-b/src/**/*.js'; |
| 117 | + @plugin '../plugin.js'; |
| 118 | + `, |
| 119 | + 'project-a/src/index.js': js` |
| 120 | + const className = "content-['project-a/src/index.js']" |
| 121 | + module.exports = { className } |
| 122 | + `, |
| 123 | + 'project-b/src/index.js': js` |
| 124 | + const className = "content-['project-b/src/index.js']" |
| 125 | + module.exports = { className } |
| 126 | + `, |
| 127 | + }, |
105 | 128 | },
|
106 |
| - }, |
107 |
| - async ({ root, fs, spawn }) => { |
108 |
| - await spawn('pnpm tailwindcss --input src/index.css --output dist/out.css --watch', { |
109 |
| - cwd: path.join(root, 'project-a'), |
110 |
| - }) |
| 129 | + async ({ root, fs, spawn }) => { |
| 130 | + await spawn(`${command} --input src/index.css --output dist/out.css --watch`, { |
| 131 | + cwd: path.join(root, 'project-a'), |
| 132 | + }) |
111 | 133 |
|
112 |
| - await fs.expectFileToContain('project-a/dist/out.css', [ |
113 |
| - candidate`underline`, |
114 |
| - candidate`content-['project-a/src/index.js']`, |
115 |
| - candidate`content-['project-b/src/index.js']`, |
116 |
| - candidate`inverted:flex`, |
117 |
| - candidate`hocus:underline`, |
118 |
| - ]) |
| 134 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 135 | + candidate`underline`, |
| 136 | + candidate`content-['project-a/src/index.js']`, |
| 137 | + candidate`content-['project-b/src/index.js']`, |
| 138 | + candidate`inverted:flex`, |
| 139 | + candidate`hocus:underline`, |
| 140 | + ]) |
119 | 141 |
|
120 |
| - await fs.write( |
121 |
| - 'project-a/src/index.js', |
122 |
| - js` |
123 |
| - const className = "[.changed_&]:content-['project-a/src/index.js']" |
124 |
| - module.exports = { className } |
125 |
| - `, |
126 |
| - ) |
127 |
| - await fs.expectFileToContain('project-a/dist/out.css', [ |
128 |
| - candidate`[.changed_&]:content-['project-a/src/index.js']`, |
129 |
| - ]) |
| 142 | + await fs.write( |
| 143 | + 'project-a/src/index.js', |
| 144 | + js` |
| 145 | + const className = "[.changed_&]:content-['project-a/src/index.js']" |
| 146 | + module.exports = { className } |
| 147 | + `, |
| 148 | + ) |
| 149 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 150 | + candidate`[.changed_&]:content-['project-a/src/index.js']`, |
| 151 | + ]) |
130 | 152 |
|
131 |
| - await fs.write( |
132 |
| - 'project-b/src/index.js', |
133 |
| - js` |
134 |
| - const className = "[.changed_&]:content-['project-b/src/index.js']" |
135 |
| - module.exports = { className } |
136 |
| - `, |
137 |
| - ) |
138 |
| - await fs.expectFileToContain('project-a/dist/out.css', [ |
139 |
| - candidate`[.changed_&]:content-['project-b/src/index.js']`, |
140 |
| - ]) |
141 |
| - }, |
142 |
| -) |
| 153 | + await fs.write( |
| 154 | + 'project-b/src/index.js', |
| 155 | + js` |
| 156 | + const className = "[.changed_&]:content-['project-b/src/index.js']" |
| 157 | + module.exports = { className } |
| 158 | + `, |
| 159 | + ) |
| 160 | + await fs.expectFileToContain('project-a/dist/out.css', [ |
| 161 | + candidate`[.changed_&]:content-['project-b/src/index.js']`, |
| 162 | + ]) |
| 163 | + }, |
| 164 | + ) |
| 165 | +}) |
0 commit comments