@eightshift/frontend-libs-tailwind 3.4.0 → 4.0.0-beta.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.
- package/.github/CODEOWNERS +1 -1
- package/CHANGELOG.md +19 -1
- package/README.md +187 -0
- package/bin/tw-sweep.mjs +281 -0
- package/bun/build.mjs +341 -0
- package/bun/cli.mjs +77 -0
- package/bun/css.mjs +145 -0
- package/bun/discovery.mjs +121 -0
- package/bun/editor.mjs +105 -0
- package/bun/eightshift-css.mjs +66 -0
- package/bun/eightshift-discovery.mjs +135 -0
- package/bun/flat-publication.mjs +343 -0
- package/bun/index.mjs +118 -0
- package/bun/media.mjs +49 -0
- package/bun/preset.mjs +118 -0
- package/bun/publish.mjs +236 -0
- package/bun/release.mjs +182 -0
- package/{webpack/responsive-compiler.mjs → bun/responsive.mjs} +18 -39
- package/bun/ssr.mjs +89 -0
- package/bun/theme-build.mjs +464 -0
- package/bun/theme-discovery.mjs +171 -0
- package/bun/watch.mjs +211 -0
- package/bun/wordpress.mjs +173 -0
- package/linters/oxlint.config.mjs +65 -0
- package/linters/tw-ignore.mjs +45 -0
- package/linters/tw-sweep-extract.mjs +545 -0
- package/package.json +16 -16
- package/test/fixtures/theme/src/Blocks/custom/card/card.php +23 -0
- package/test/fixtures/theme/src/Blocks/custom/card/manifest.json +13 -0
- package/test/fixtures/theme/src/Plugins/Forms.php +15 -0
- package/test/fixtures/theme/src/card.js +2 -0
- package/test/fixtures/theme/tailwind.css +6 -0
- package/test/fixtures/theme/tw-ignore.json +1 -0
- package/test/tw-sweep.test.mjs +119 -0
- package/bun.lock +0 -1433
- package/webpack/base.mjs +0 -126
- package/webpack/helpers.mjs +0 -55
- package/webpack/index.mjs +0 -46
- package/webpack/production.mjs +0 -60
- package/webpack/project.mjs +0 -50
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
|
|
8
|
+
const bin = resolve(import.meta.dirname, '../bin/tw-sweep.mjs');
|
|
9
|
+
const fixture = resolve(import.meta.dirname, 'fixtures/theme');
|
|
10
|
+
|
|
11
|
+
const run = (cwd, ...args) => {
|
|
12
|
+
const result = spawnSync(process.execPath, [bin, ...args], { cwd, encoding: 'utf8' });
|
|
13
|
+
|
|
14
|
+
return { code: result.status, out: result.stdout, err: result.stderr };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const reported = (out) =>
|
|
18
|
+
out
|
|
19
|
+
.trim()
|
|
20
|
+
.split('\n')
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.map((line) => line.replace(/:\d+:\d+/, '').replace(/\s+/g, ' '));
|
|
23
|
+
|
|
24
|
+
test('reports unknown and non-canonical classes from manifests, PHP calls, class attributes and regions, once each and outside comments', () => {
|
|
25
|
+
const { code, out } = run(fixture);
|
|
26
|
+
|
|
27
|
+
assert.equal(code, 1);
|
|
28
|
+
assert.deepEqual(reported(out).sort(), [
|
|
29
|
+
'src/Blocks/custom/card/card.php aspect-[5/3] → aspect-5/3',
|
|
30
|
+
'src/Blocks/custom/card/card.php unknown text-lg',
|
|
31
|
+
'src/Blocks/custom/card/card.php unknown text-xs',
|
|
32
|
+
'src/Blocks/custom/card/card.php w-[16px] → w-4',
|
|
33
|
+
'src/Blocks/custom/card/card.php w-[16px] → w-4',
|
|
34
|
+
'src/Blocks/custom/card/card.php w-[16px] → w-4',
|
|
35
|
+
'src/Blocks/custom/card/card.php w-[16px] → w-4',
|
|
36
|
+
'src/Blocks/custom/card/manifest.json [&_.card\\_icon]:w-[16px] → [&_.card\\_icon]:w-4',
|
|
37
|
+
'src/Blocks/custom/card/manifest.json aspect-[5/3] → aspect-5/3',
|
|
38
|
+
'src/Blocks/custom/card/manifest.json h-[16px] → h-4',
|
|
39
|
+
'src/Blocks/custom/card/manifest.json unknown text-sm',
|
|
40
|
+
'src/Blocks/custom/card/manifest.json w-[16px] → w-4',
|
|
41
|
+
'src/Plugins/Forms.php [&_.card\\_icon]:w-[16px] → [&_.card\\_icon]:w-4',
|
|
42
|
+
'src/Plugins/Forms.php aspect-[5/3] → aspect-5/3',
|
|
43
|
+
'src/Plugins/Forms.php h-[16px] → h-4',
|
|
44
|
+
'src/Plugins/Forms.php unknown text-xl',
|
|
45
|
+
'src/Plugins/Forms.php w-[16px] → w-4',
|
|
46
|
+
'src/Plugins/Forms.php w-[16px] → w-4',
|
|
47
|
+
]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('--write rewrites non-canonical classes, keeps unknown ones and still fails on them', () => {
|
|
51
|
+
const dir = mkdtempSync(join(tmpdir(), 'tw-sweep-'));
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
cpSync(fixture, dir, { recursive: true });
|
|
55
|
+
|
|
56
|
+
const { code } = run(dir, '--write', '--entry', resolve(fixture, 'tailwind.css'));
|
|
57
|
+
const php = readFileSync(join(dir, 'src/Blocks/custom/card/card.php'), 'utf8');
|
|
58
|
+
const forms = readFileSync(join(dir, 'src/Plugins/Forms.php'), 'utf8');
|
|
59
|
+
|
|
60
|
+
assert.equal(code, 1);
|
|
61
|
+
assert.match(php, /'text-lg w-4'/);
|
|
62
|
+
assert.match(php, /class="card__wrap aspect-5\/3"/);
|
|
63
|
+
assert.match(forms, /\$single = \['aspect-5\/3'\];\n/);
|
|
64
|
+
assert.match(forms, /\$wrapped = Helpers::getTwClasses\(\$attributes, \$manifest, 'h-4'\);\n/);
|
|
65
|
+
assert.match(forms, /\$escaped = \["w-4\\nh-full", '\[&_\.card\\_icon\]:w-4 content-\[\\'x\\'\]'\];\n\/\/ tw-sweep-classes-end/);
|
|
66
|
+
assert.equal(JSON.parse(readFileSync(join(dir, 'src/Blocks/custom/card/manifest.json'), 'utf8')).tailwind.parts.icon.twClassesEditor, 'h-4\nh-full\t[.card\\_\\_icon_&]:w-[16px] [&_.card\\_icon]:w-4 h-0');
|
|
67
|
+
assert.deepEqual(reported(run(dir, '--no-unknown', '--entry', resolve(fixture, 'tailwind.css')).out), []);
|
|
68
|
+
} finally {
|
|
69
|
+
rmSync(dir, { recursive: true, force: true });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('JS string escapes are decoded for checking and re-escaped by --write', () => {
|
|
74
|
+
const dir = mkdtempSync(join(tmpdir(), 'tw-sweep-'));
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
cpSync(fixture, dir, { recursive: true });
|
|
78
|
+
|
|
79
|
+
const { code, out } = run(dir, 'src/card.js', '--write', '--entry', resolve(fixture, 'tailwind.css'));
|
|
80
|
+
|
|
81
|
+
assert.equal(code, 0);
|
|
82
|
+
assert.deepEqual(reported(out), ['src/card.js w-[16px] → w-4', 'src/card.js [&_.a\\_b]:w-[16px] → [&_.a\\_b]:w-4']);
|
|
83
|
+
assert.ok(readFileSync(join(dir, 'src/card.js'), 'utf8').includes("\nexport const card = { className: 'w-4\\nh-full [&_.a\\\\_b]:w-4 content-[\\'x\\']' };\n"));
|
|
84
|
+
} finally {
|
|
85
|
+
rmSync(dir, { recursive: true, force: true });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('an invalid ignore pattern is a usage error naming the pattern', () => {
|
|
90
|
+
const dir = mkdtempSync(join(tmpdir(), 'tw-sweep-'));
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
cpSync(fixture, dir, { recursive: true });
|
|
94
|
+
writeFileSync(join(dir, 'tw-ignore.json'), '["^js-", "card__("]');
|
|
95
|
+
|
|
96
|
+
const { code, err } = run(dir);
|
|
97
|
+
|
|
98
|
+
assert.equal(code, 2);
|
|
99
|
+
assert.match(err, /card__\(/);
|
|
100
|
+
} finally {
|
|
101
|
+
rmSync(dir, { recursive: true, force: true });
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('a tailwind.css that does not import tailwindcss is not used as the entry', () => {
|
|
106
|
+
const dir = mkdtempSync(join(tmpdir(), 'tw-sweep-'));
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
cpSync(fixture, dir, { recursive: true });
|
|
110
|
+
writeFileSync(join(dir, 'tailwind.css'), '@theme {\n\t--text-body-sm: 0.875rem;\n}\n');
|
|
111
|
+
|
|
112
|
+
const { code, err } = run(dir);
|
|
113
|
+
|
|
114
|
+
assert.equal(code, 2);
|
|
115
|
+
assert.match(err, /imports 'tailwindcss'/);
|
|
116
|
+
} finally {
|
|
117
|
+
rmSync(dir, { recursive: true, force: true });
|
|
118
|
+
}
|
|
119
|
+
});
|