@imwz/wp-pattern-sentinel 1.0.2 → 1.0.3

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 (2) hide show
  1. package/package.json +5 -1
  2. package/src/editor.js +14 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imwz/wp-pattern-sentinel",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Browser-based WordPress block pattern validator using Playwright",
5
5
  "type": "module",
6
6
  "engines": {
@@ -25,6 +25,10 @@
25
25
  "validation"
26
26
  ],
27
27
  "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/imagewize/wp-pattern-sentinel"
31
+ },
28
32
  "dependencies": {
29
33
  "js-yaml": "^4.1.0",
30
34
  "p-queue": "^8.0.1",
package/src/editor.js CHANGED
@@ -29,10 +29,11 @@ function stripPhpForValidation(content) {
29
29
  }
30
30
 
31
31
  /**
32
- * Strip the PHP file header (opening tag + docblock) and return the raw block markup.
33
- * Inline PHP expressions within the block markup are replaced with static values
34
- * so the editor receives valid content for round-trip validation.
35
- * Returns null if no block comment is found.
32
+ * Strip the PHP file header (opening tag, docblock, and any header-only PHP
33
+ * such as a direct-access guard) and return the raw block markup. Inline PHP
34
+ * expressions within the block markup are replaced with static values so the
35
+ * editor receives valid content for round-trip validation. Returns null if no
36
+ * block comment is found.
36
37
  *
37
38
  * WordPress pattern files look like:
38
39
  * <?php
@@ -40,14 +41,20 @@ function stripPhpForValidation(content) {
40
41
  * * Title: My Pattern
41
42
  * * ...
42
43
  * *\/
44
+ *
45
+ * if ( ! defined( 'ABSPATH' ) ) {
46
+ * exit; // Optional direct-access guard (e.g. Aludra patterns).
47
+ * }
43
48
  * ?>
44
49
  * <!-- wp:group -->...
50
+ *
51
+ * The header is everything up to and including the *first* closing PHP tag,
52
+ * regardless of what it contains (docblock only, or docblock + guard) — so a
53
+ * single non-greedy strip handles both shapes in one pass.
45
54
  */
46
55
  export function extractBlockContent(fileContent) {
47
56
  const stripped = fileContent
48
- .replace(/^<\?php\s*/m, '')
49
- .replace(/\/\*\*[\s\S]*?\*\//m, '')
50
- .replace(/^\s*\?>\s*/m, '')
57
+ .replace(/^[\s\S]*?\?>\s*/, '')
51
58
  .trim();
52
59
 
53
60
  if (!stripped.startsWith('<!--')) return null;