@runtimestudio/tailwind-sort-php 0.2.0 → 0.2.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/README.md +15 -13
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -2
- package/dist/html.d.ts +1 -1
- package/dist/html.js +1 -1
- package/dist/init.js +5 -7
- package/dist/islands.js +1 -1
- package/package.json +1 -1
- package/src/cli.ts +1 -2
- package/src/html.ts +1 -1
- package/src/init.ts +5 -7
- package/src/islands.ts +1 -1
package/README.md
CHANGED
|
@@ -20,17 +20,17 @@ values, using a real PHP-aware lexer, and leaves everything else byte-identical.
|
|
|
20
20
|
|
|
21
21
|
## Requirements
|
|
22
22
|
|
|
23
|
-
- **
|
|
23
|
+
- **Node ≥ 22.18**, or **Bun** — both run the CLI and the programmatic API.
|
|
24
24
|
- `prettier` ≥ 3 and `prettier-plugin-tailwindcss` ≥ 0.8 (peer dependencies).
|
|
25
25
|
|
|
26
26
|
## Install
|
|
27
27
|
|
|
28
28
|
```sh
|
|
29
|
-
# Bun
|
|
30
|
-
bun add -D @runtimestudio/tailwind-sort-php prettier prettier-plugin-tailwindcss
|
|
31
|
-
|
|
32
29
|
# npm
|
|
33
30
|
npm install -D @runtimestudio/tailwind-sort-php prettier prettier-plugin-tailwindcss
|
|
31
|
+
|
|
32
|
+
# Bun
|
|
33
|
+
bun add -D @runtimestudio/tailwind-sort-php prettier prettier-plugin-tailwindcss
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
pnpm and yarn work the same (`pnpm add -D …` / `yarn add -D …`).
|
|
@@ -38,7 +38,9 @@ pnpm and yarn work the same (`pnpm add -D …` / `yarn add -D …`).
|
|
|
38
38
|
## Setup
|
|
39
39
|
|
|
40
40
|
Point Prettier at your Tailwind v4 entry stylesheet so both `prettier-plugin-tailwindcss` and this tool share one
|
|
41
|
-
vocabulary.
|
|
41
|
+
vocabulary. Any config format Prettier supports works (`.prettierrc`, `prettier.config.js`, a `package.json`
|
|
42
|
+
`"prettier"` key, …) — the tool reads the resolved config, exactly like the plugin does. For example, in
|
|
43
|
+
`prettier.config.mjs`:
|
|
42
44
|
|
|
43
45
|
```js
|
|
44
46
|
export default {
|
|
@@ -52,23 +54,23 @@ this in place, the CLI needs no flags.
|
|
|
52
54
|
|
|
53
55
|
## Usage
|
|
54
56
|
|
|
55
|
-
Run with `
|
|
57
|
+
Run with `npx` (Node ≥ 22.18) or `bunx` (Bun):
|
|
56
58
|
|
|
57
59
|
```sh
|
|
58
60
|
# sort every .php file under the cwd (stylesheet read from your Prettier config)
|
|
59
|
-
|
|
61
|
+
npx tailwind-sort-php
|
|
60
62
|
|
|
61
63
|
# specific globs
|
|
62
|
-
|
|
64
|
+
npx tailwind-sort-php "template-parts/**/*.php" "*.php"
|
|
63
65
|
|
|
64
66
|
# CI / pre-commit — write nothing, exit 1 if anything is unsorted
|
|
65
|
-
|
|
67
|
+
npx tailwind-sort-php --check
|
|
66
68
|
|
|
67
69
|
# explicit stylesheet (overrides the Prettier config)
|
|
68
|
-
|
|
70
|
+
npx tailwind-sort-php --stylesheet ./resources/css/main.css
|
|
69
71
|
|
|
70
72
|
# one-time: install the pre-commit hook (see "Pre-commit gate" below)
|
|
71
|
-
|
|
73
|
+
npx tailwind-sort-php init
|
|
72
74
|
```
|
|
73
75
|
|
|
74
76
|
### Options
|
|
@@ -198,8 +200,8 @@ const out = transform(source, sortFn);
|
|
|
198
200
|
## Development
|
|
199
201
|
|
|
200
202
|
```sh
|
|
201
|
-
bun test
|
|
202
|
-
bun run build
|
|
203
|
+
bun test # or: node --test "test/*.test.ts"
|
|
204
|
+
bun run build # compile src → dist (tsc); the published artifact
|
|
203
205
|
```
|
|
204
206
|
|
|
205
207
|
54 tests: 41 core tests that are dependency-free (the sorter is injected, so they run against a mock `SortFn`), 5
|
package/dist/cli.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* --check Don't write; exit 1 if any file needs sorting
|
|
13
13
|
* --no-short-tags Don't treat bare `<?` as a PHP open tag
|
|
14
14
|
*
|
|
15
|
-
* Defaults to all `.php` files under `cwd`
|
|
15
|
+
* Defaults to all `.php` files under `cwd` when no globs are given.
|
|
16
16
|
* Skips `node_modules`, `vendor`, `dist` and `.git`. The `init` subcommand installs the pre-commit hook; see `init.ts`.
|
|
17
17
|
*/
|
|
18
18
|
export {};
|
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* --check Don't write; exit 1 if any file needs sorting
|
|
13
13
|
* --no-short-tags Don't treat bare `<?` as a PHP open tag
|
|
14
14
|
*
|
|
15
|
-
* Defaults to all `.php` files under `cwd`
|
|
15
|
+
* Defaults to all `.php` files under `cwd` when no globs are given.
|
|
16
16
|
* Skips `node_modules`, `vendor`, `dist` and `.git`. The `init` subcommand installs the pre-commit hook; see `init.ts`.
|
|
17
17
|
*/
|
|
18
18
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
@@ -60,7 +60,6 @@ function parseArgs(argv) {
|
|
|
60
60
|
* @param globs Glob patterns relative to `cwd`.
|
|
61
61
|
*/
|
|
62
62
|
async function* scanFiles(globs) {
|
|
63
|
-
// Use `Bun.Glob` when available, fall back to `node:fs` glob (Node 22+).
|
|
64
63
|
if (typeof globalThis.Bun !== 'undefined') {
|
|
65
64
|
const { Glob } = await import('bun');
|
|
66
65
|
for (const pattern of globs) {
|
package/dist/html.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - islands inside a quoted attribute value read as opaque atoms
|
|
9
9
|
*
|
|
10
10
|
* Skips HTML comments, doctype/CDATA, and the raw-text content of `script`/`style`/`textarea`/`title` elements —
|
|
11
|
-
* their
|
|
11
|
+
* their content may contain strings like `class="..."` that must not be touched.
|
|
12
12
|
*
|
|
13
13
|
* @see islands.ts - first pass; produces the islands consumed here.
|
|
14
14
|
*/
|
package/dist/html.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - islands inside a quoted attribute value read as opaque atoms
|
|
9
9
|
*
|
|
10
10
|
* Skips HTML comments, doctype/CDATA, and the raw-text content of `script`/`style`/`textarea`/`title` elements —
|
|
11
|
-
* their
|
|
11
|
+
* their content may contain strings like `class="..."` that must not be touched.
|
|
12
12
|
*
|
|
13
13
|
* @see islands.ts - first pass; produces the islands consumed here.
|
|
14
14
|
*/
|
package/dist/init.js
CHANGED
|
@@ -13,9 +13,8 @@ const HOOK_PATH = `${HOOKS_DIR}/pre-commit`;
|
|
|
13
13
|
* Check-and-fail hook (default): names the unsorted files and blocks the commit; never writes.
|
|
14
14
|
*/
|
|
15
15
|
const HOOK_CHECK = `#!/bin/sh
|
|
16
|
-
# Block commits with unsorted Tailwind classes in staged PHP files.
|
|
17
|
-
#
|
|
18
|
-
# contents, so partial staging (git add -p) can mis-report; see README.
|
|
16
|
+
# Block commits with unsorted Tailwind classes in staged PHP files. Installed by \`tailwind-sort-php init\`.
|
|
17
|
+
# Note: checks working-tree file contents, so partial staging (\`git add -p\`) can mis-report; see README.
|
|
19
18
|
sorter=./node_modules/.bin/tailwind-sort-php
|
|
20
19
|
[ -x "$sorter" ] || exit 0
|
|
21
20
|
git diff --cached --name-only --diff-filter=ACMR -- '*.php' | grep -q . || exit 0
|
|
@@ -31,10 +30,9 @@ exit 1
|
|
|
31
30
|
* Auto-fix hook (--fix): sorts the staged files in place, then blocks the commit for review.
|
|
32
31
|
*/
|
|
33
32
|
const HOOK_FIX = `#!/bin/sh
|
|
34
|
-
# Sort Tailwind classes in staged PHP files, then abort the commit so the
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
# (git add -p), re-staging can pull in unrelated unstaged hunks; see README.
|
|
33
|
+
# Sort Tailwind classes in staged PHP files, then abort the commit so the changes can be reviewed and re-staged.
|
|
34
|
+
# Rewrites working-tree files. Installed by \`tailwind-sort-php init --fix\`.
|
|
35
|
+
# Note: with partial staging (\`git add -p\`), re-staging can pull in unrelated unstaged hunks; see README.
|
|
38
36
|
sorter=./node_modules/.bin/tailwind-sort-php
|
|
39
37
|
[ -x "$sorter" ] || exit 0
|
|
40
38
|
git diff --cached --name-only --diff-filter=ACMR -- '*.php' | grep -q . || exit 0
|
package/dist/islands.js
CHANGED
|
@@ -73,7 +73,7 @@ function scanPhpBody(src, i) {
|
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
75
|
// Double-quoted string.
|
|
76
|
-
// Limitation: nested double quotes in complex `{$a["k"]}` interpolation can desync the lexer
|
|
76
|
+
// Limitation: nested double quotes in complex `{$a["k"]}` interpolation can desync the lexer; see README.
|
|
77
77
|
if (c === '"') {
|
|
78
78
|
i = scanQuoted(src, i + 1, '"');
|
|
79
79
|
continue;
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* --check Don't write; exit 1 if any file needs sorting
|
|
13
13
|
* --no-short-tags Don't treat bare `<?` as a PHP open tag
|
|
14
14
|
*
|
|
15
|
-
* Defaults to all `.php` files under `cwd`
|
|
15
|
+
* Defaults to all `.php` files under `cwd` when no globs are given.
|
|
16
16
|
* Skips `node_modules`, `vendor`, `dist` and `.git`. The `init` subcommand installs the pre-commit hook; see `init.ts`.
|
|
17
17
|
*/
|
|
18
18
|
|
|
@@ -65,7 +65,6 @@ function parseArgs(argv: string[]): Cli {
|
|
|
65
65
|
* @param globs Glob patterns relative to `cwd`.
|
|
66
66
|
*/
|
|
67
67
|
async function* scanFiles(globs: string[]): AsyncGenerator<string> {
|
|
68
|
-
// Use `Bun.Glob` when available, fall back to `node:fs` glob (Node 22+).
|
|
69
68
|
if (typeof (globalThis as any).Bun !== 'undefined') {
|
|
70
69
|
const { Glob } = await import('bun');
|
|
71
70
|
for (const pattern of globs) {
|
package/src/html.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - islands inside a quoted attribute value read as opaque atoms
|
|
9
9
|
*
|
|
10
10
|
* Skips HTML comments, doctype/CDATA, and the raw-text content of `script`/`style`/`textarea`/`title` elements —
|
|
11
|
-
* their
|
|
11
|
+
* their content may contain strings like `class="..."` that must not be touched.
|
|
12
12
|
*
|
|
13
13
|
* @see islands.ts - first pass; produces the islands consumed here.
|
|
14
14
|
*/
|
package/src/init.ts
CHANGED
|
@@ -16,9 +16,8 @@ const HOOK_PATH = `${HOOKS_DIR}/pre-commit`;
|
|
|
16
16
|
* Check-and-fail hook (default): names the unsorted files and blocks the commit; never writes.
|
|
17
17
|
*/
|
|
18
18
|
const HOOK_CHECK = `#!/bin/sh
|
|
19
|
-
# Block commits with unsorted Tailwind classes in staged PHP files.
|
|
20
|
-
#
|
|
21
|
-
# contents, so partial staging (git add -p) can mis-report; see README.
|
|
19
|
+
# Block commits with unsorted Tailwind classes in staged PHP files. Installed by \`tailwind-sort-php init\`.
|
|
20
|
+
# Note: checks working-tree file contents, so partial staging (\`git add -p\`) can mis-report; see README.
|
|
22
21
|
sorter=./node_modules/.bin/tailwind-sort-php
|
|
23
22
|
[ -x "$sorter" ] || exit 0
|
|
24
23
|
git diff --cached --name-only --diff-filter=ACMR -- '*.php' | grep -q . || exit 0
|
|
@@ -35,10 +34,9 @@ exit 1
|
|
|
35
34
|
* Auto-fix hook (--fix): sorts the staged files in place, then blocks the commit for review.
|
|
36
35
|
*/
|
|
37
36
|
const HOOK_FIX = `#!/bin/sh
|
|
38
|
-
# Sort Tailwind classes in staged PHP files, then abort the commit so the
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
# (git add -p), re-staging can pull in unrelated unstaged hunks; see README.
|
|
37
|
+
# Sort Tailwind classes in staged PHP files, then abort the commit so the changes can be reviewed and re-staged.
|
|
38
|
+
# Rewrites working-tree files. Installed by \`tailwind-sort-php init --fix\`.
|
|
39
|
+
# Note: with partial staging (\`git add -p\`), re-staging can pull in unrelated unstaged hunks; see README.
|
|
42
40
|
sorter=./node_modules/.bin/tailwind-sort-php
|
|
43
41
|
[ -x "$sorter" ] || exit 0
|
|
44
42
|
git diff --cached --name-only --diff-filter=ACMR -- '*.php' | grep -q . || exit 0
|
package/src/islands.ts
CHANGED
|
@@ -104,7 +104,7 @@ function scanPhpBody(src: string, i: number): number {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// Double-quoted string.
|
|
107
|
-
// Limitation: nested double quotes in complex `{$a["k"]}` interpolation can desync the lexer
|
|
107
|
+
// Limitation: nested double quotes in complex `{$a["k"]}` interpolation can desync the lexer; see README.
|
|
108
108
|
if (c === '"') {
|
|
109
109
|
i = scanQuoted(src, i + 1, '"');
|
|
110
110
|
continue;
|