@forgewp/compiler 0.4.2 → 0.4.4
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 +70 -3
- package/bin/add.js +30 -15
- package/bin/analyze.js +66 -1
- package/bin/cli.js +149 -70
- package/bin/doctor.js +21 -12
- package/bin/export.js +69 -20
- package/bin/fresh.js +6 -1
- package/bin/i18n-extract.js +3 -10
- package/bin/i18n-translate.js +15 -24
- package/bin/make-block.js +24 -0
- package/bin/make-editable.js +166 -0
- package/bin/make-form.js +131 -0
- package/bin/make-island.js +11 -0
- package/bin/make-loop.js +147 -0
- package/bin/make-mail.js +27 -0
- package/bin/make-page.js +83 -0
- package/bin/make-post-type.js +68 -29
- package/bin/make-sandbox.js +609 -0
- package/bin/make-section.js +221 -0
- package/bin/make-shell.js +375 -0
- package/bin/repair.js +14 -26
- package/bin/seed.js +119 -0
- package/bin/sync-routes.js +107 -85
- package/lib/adapters/html-adapter.js +13 -3
- package/lib/adapters/stub-adapter.js +10 -2
- package/lib/add-component.js +153 -92
- package/lib/asset-loader.js +333 -1
- package/lib/assets/asset-graph.js +432 -0
- package/lib/assets/asset-pipeline.js +125 -0
- package/lib/assets/diagnostics-report.js +345 -0
- package/lib/assets/external-fetcher.js +173 -0
- package/lib/assets/font-orchestrator.js +348 -0
- package/lib/assets/font-usage-scanner.js +242 -0
- package/lib/assets/image-optimizer.js +229 -0
- package/lib/assets/index.js +51 -0
- package/lib/assets/preload-generator.js +70 -0
- package/lib/assets/public-url.js +153 -0
- package/lib/block-authoring-help.js +11 -0
- package/lib/blocks/ast-parser.js +67 -0
- package/lib/blocks/discover-blocks.js +146 -0
- package/lib/blocks/editor-scope.js +733 -0
- package/lib/blocks/editor-transpiler.js +1229 -0
- package/lib/blocks/index.js +2838 -0
- package/lib/blocks/php-transpiler.js +4928 -0
- package/lib/blocks/scanner.js +1487 -0
- package/lib/blocks/shared-utils.js +290 -0
- package/lib/blocks/source-sanitize.js +1449 -0
- package/lib/blueprints.js +77 -5
- package/lib/build-assets.js +38 -33
- package/lib/collect-page-template-routes.js +102 -0
- package/lib/collect-static-routes.js +175 -0
- package/lib/diagnostics.js +58 -33
- package/lib/export-theme.js +84 -5
- package/lib/extract-template-content.js +90 -0
- package/lib/forms-preview.js +42 -0
- package/lib/functions/cpt-routing.js +69 -0
- package/lib/functions/forms.js +2461 -0
- package/lib/functions/hydration-enqueuer.js +400 -0
- package/lib/functions/index.js +1623 -0
- package/lib/functions/load-menus.js +112 -0
- package/lib/functions/load-translations.js +148 -0
- package/lib/functions/rest-endpoints.js +2923 -0
- package/lib/functions/routing.js +765 -0
- package/lib/functions/seed-mock-data.js +392 -0
- package/lib/functions/seed-products.js +481 -0
- package/lib/functions/settings-page.js +273 -0
- package/lib/functions/theme-setup.js +494 -0
- package/lib/generate-theme.js +2076 -303
- package/lib/hydration/editable-schemas.js +332 -0
- package/lib/hydration/enter-hidden-initial.js +65 -0
- package/lib/hydration/form-schemas.js +227 -0
- package/lib/hydration/index.js +12 -0
- package/lib/hydration/is-interactive.js +951 -0
- package/lib/hydration/island-split.js +1231 -0
- package/lib/hydration/islands-scanner.js +599 -0
- package/lib/hydration/resolve-island-chunk.js +103 -0
- package/lib/hydration/resolve-island-component.js +52 -0
- package/lib/hydration/rollup-inputs.js +81 -0
- package/lib/hydration/root-class-extractor.js +220 -0
- package/lib/hydration/scan-app-providers.js +154 -0
- package/lib/hydration/static-lint.js +382 -0
- package/lib/hydration/transform.js +257 -0
- package/lib/hydration/uses-block-area.js +49 -0
- package/lib/hydration/utils.js +119 -0
- package/lib/i18n/translation-cache.js +141 -0
- package/lib/icon-registry.js +72 -0
- package/lib/index.d.ts +324 -8
- package/lib/index.js +3 -2
- package/lib/load-config.js +338 -144
- package/lib/mail-templates.js +37 -0
- package/lib/markup-processor.js +483 -92
- package/lib/node-runtime.js +7 -0
- package/lib/page-config-plugin.js +84 -0
- package/lib/php-builders.js +383 -42
- package/lib/react-adapter.js +1053 -246
- package/lib/registration-metadata.js +11 -0
- package/lib/render-theme.mts +1410 -543
- package/lib/route-layout.js +76 -0
- package/lib/template-discovery.js +58 -0
- package/lib/theme-compatibility.js +32 -0
- package/lib/validate-export.js +51 -2
- package/lib/validate.js +27 -5
- package/lib/virtual-plugin.js +319 -0
- package/lib/walkthrough.md +26 -0
- package/package.json +17 -5
- package/templates/PresetsStyle.tsx +1 -1
- package/templates/auth/cms/email-logs.json +9 -0
- package/templates/auth/cms/menus.json +11 -0
- package/templates/auth/cms/mock-data.json +123 -0
- package/templates/auth/cms/roles.json +7 -0
- package/templates/auth/cms/sessions.json +1 -0
- package/templates/auth/cms/site-settings.json +28 -0
- package/templates/auth/cms/translations.json +4 -0
- package/templates/auth/cms/users.json +46 -0
- package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
- package/templates/auth/components/forgot-password-form-wrapper.tsx +141 -0
- package/templates/auth/components/login-form-wrapper.tsx +300 -0
- package/templates/auth/components/reset-password-form-wrapper.tsx +190 -0
- package/templates/auth/components/signup-form-wrapper.tsx +257 -0
- package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
- package/templates/auth/pages/DashboardPage.tsx +12 -0
- package/templates/auth/pages/ForgotPasswordPage.tsx +11 -0
- package/templates/auth/pages/LoginPage.tsx +11 -0
- package/templates/auth/pages/ResetPasswordPage.tsx +11 -0
- package/templates/auth/pages/SignUpPage.tsx +11 -0
- package/templates/auth/pages/VerifyEmailPage.tsx +11 -0
- package/templates/auth/ui/button.tsx +57 -0
- package/templates/auth/ui/card.tsx +76 -0
- package/templates/auth/ui/field.tsx +242 -0
- package/templates/auth/ui/input.tsx +22 -0
- package/templates/auth/ui/label.tsx +24 -0
- package/templates/auth/ui/separator.tsx +31 -0
- package/templates/forgewp-config.ts +70 -3
- package/templates/menus.json +12 -10
- package/templates/mock-data.json +122 -433
- package/templates/products.json +5 -0
- package/templates/roles.json +7 -0
- package/templates/sessions.json +1 -0
- package/templates/users.json +38 -0
- package/templates/wordpress.tsx +1835 -1297
- package/bin/make-template.js +0 -145
- package/lib/block-compiler.js +0 -552
- package/lib/functions-builder.js +0 -2044
- package/lib/hydration-scanner.js +0 -821
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the layout a route actually renders with.
|
|
3
|
+
*
|
|
4
|
+
* Local React (`withLayout`) uses, in order: the route's explicit layout
|
|
5
|
+
* argument, then `export const pageConfig` on the page module, then
|
|
6
|
+
* `"default"`. The exporter must follow that same order. It must not infer
|
|
7
|
+
* a shell from a component name — projects name their navigation whatever
|
|
8
|
+
* they want, and a page that opts out of the default layout owns its tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} source
|
|
13
|
+
* @returns {string | false | undefined}
|
|
14
|
+
*/
|
|
15
|
+
export function readPageConfigLayout(source) {
|
|
16
|
+
if (!source) return undefined;
|
|
17
|
+
const match = source.match(
|
|
18
|
+
/export\s+const\s+pageConfig\s*=\s*(?:definePageConfig\s*\(\s*)?\{[\s\S]*?\blayout\s*:\s*(?:(['"])([^'"]+)\1|(false))\s*[,}]/,
|
|
19
|
+
);
|
|
20
|
+
if (!match) return undefined;
|
|
21
|
+
if (match[3] === 'false' || match[2] === 'false') return false;
|
|
22
|
+
return match[2];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Layout declared on a `<Route path="...">`, including `withLayout(Page, { layout })`.
|
|
27
|
+
* `undefined` means the route does not override the page module.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} source
|
|
30
|
+
* @param {string} routePath
|
|
31
|
+
* @returns {string | false | undefined}
|
|
32
|
+
*/
|
|
33
|
+
export function readRouteLayout(source, routePath) {
|
|
34
|
+
if (!source) return undefined;
|
|
35
|
+
const routeRe = /<Route\b([^>]*?)(?:\/>|>([\s\S]*?)<\/Route>)/g;
|
|
36
|
+
let match;
|
|
37
|
+
while ((match = routeRe.exec(source))) {
|
|
38
|
+
const chunk = `${match[1] || ''}\n${match[2] || ''}`;
|
|
39
|
+
const pathMatch = chunk.match(/\bpath\s*=\s*(?:\{)?\s*(['"])([^'"]*)\1/);
|
|
40
|
+
if (!pathMatch || pathMatch[2] !== routePath) continue;
|
|
41
|
+
const layoutMatch = chunk.match(
|
|
42
|
+
/\blayout\s*:\s*(?:(['"])([^'"]+)\1|(false))\s*[,}]/,
|
|
43
|
+
);
|
|
44
|
+
if (!layoutMatch) return undefined;
|
|
45
|
+
if (layoutMatch[3] === 'false' || layoutMatch[2] === 'false') return false;
|
|
46
|
+
return layoutMatch[2];
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {{ pageSource?: string, routesSource?: string }} [sources]
|
|
53
|
+
* @returns {string | false}
|
|
54
|
+
*/
|
|
55
|
+
export function resolveFrontPageLayout({
|
|
56
|
+
pageSource = '',
|
|
57
|
+
routesSource = '',
|
|
58
|
+
} = {}) {
|
|
59
|
+
const routeLayout = readRouteLayout(routesSource, '/');
|
|
60
|
+
if (routeLayout !== undefined) return routeLayout;
|
|
61
|
+
const pageLayout = readPageConfigLayout(pageSource);
|
|
62
|
+
if (pageLayout !== undefined) return pageLayout;
|
|
63
|
+
return 'default';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A blank layout renders the page by itself. The exported template has to
|
|
68
|
+
* keep that whole tree (and its client state) instead of wrapping the
|
|
69
|
+
* default header/footer around an extracted `<main>`.
|
|
70
|
+
*
|
|
71
|
+
* @param {string | false | undefined} layout
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
*/
|
|
74
|
+
export function layoutOwnsDocument(layout) {
|
|
75
|
+
return layout === false || layout === 'blank';
|
|
76
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseSource } from './blocks/ast-parser.js';
|
|
4
|
+
|
|
5
|
+
export function discoverReactTemplates(themeRoot) {
|
|
6
|
+
const app = path.join(themeRoot, 'src/app');
|
|
7
|
+
const pagesDir = path.join(app, 'pages');
|
|
8
|
+
const files = (dir) => fs.existsSync(dir) ? fs.readdirSync(dir).filter((name) => name.endsWith('.tsx') && fs.statSync(path.join(dir, name)).isFile()).sort() : [];
|
|
9
|
+
const roots = files(app).filter((name) => /^(?:single|archive|taxonomy)(?:-.+)?\.tsx$|^404\.tsx$/.test(name));
|
|
10
|
+
const pages = files(pagesDir).filter((name) => !/^placeholder\.tsx$/i.test(name));
|
|
11
|
+
const importers = new Map(pages.map((name) => [name, []]));
|
|
12
|
+
for (const file of [...roots.map((name) => path.join(app, name)), ...pages.map((name) => path.join(pagesDir, name))]) {
|
|
13
|
+
let ast;
|
|
14
|
+
try { ast = parseSource(fs.readFileSync(file, 'utf8')); } catch { continue; }
|
|
15
|
+
for (const node of ast.program.body) {
|
|
16
|
+
if (node.type !== 'ImportDeclaration' || node.importKind === 'type' || !node.source.value.startsWith('.')) continue;
|
|
17
|
+
if (node.specifiers.length && node.specifiers.every((specifier) => specifier.importKind === 'type')) continue;
|
|
18
|
+
const imported = path.resolve(path.dirname(file), node.source.value).replace(/\.(?:js|jsx|ts|tsx)$/, '');
|
|
19
|
+
for (const name of pages) {
|
|
20
|
+
if (imported === path.join(pagesDir, name).replace(/\.tsx$/, '') && path.join(pagesDir, name) !== file) {
|
|
21
|
+
importers.get(name).push(path.relative(themeRoot, file).replaceAll('\\', '/'));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { roots, pages, importers };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function resolvePageTemplateIntent(pageFile, config = {}) {
|
|
30
|
+
if (config.exportTemplate !== undefined && typeof config.exportTemplate !== 'boolean') {
|
|
31
|
+
throw new Error('pageConfig.exportTemplate must be a boolean');
|
|
32
|
+
}
|
|
33
|
+
if (config.exportTemplate === false) return { kind: 'component' };
|
|
34
|
+
const slug = pageFile.replace(/\.tsx$/, '').replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
35
|
+
const single = slug === 'product' || slug.startsWith('single-') || Boolean(config.postType);
|
|
36
|
+
const singleSlug = config.postType || (slug.startsWith('single-') ? slug.slice(7) : slug);
|
|
37
|
+
if (single && (typeof singleSlug !== 'string' || !/^[a-z0-9_-]{1,20}$/.test(singleSlug))) {
|
|
38
|
+
throw new Error('Single template post type must be a WordPress post-type key (1–20 lowercase letters, numbers, underscores or hyphens)');
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
kind: single ? 'single' : 'page', slug, singleSlug,
|
|
42
|
+
cacheStem: single ? `single-${singleSlug}` : `template-${slug}`,
|
|
43
|
+
wordpressFile: single ? `single-${singleSlug}.php` : `page-${slug}.php`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function pageTemplateDiagnostic(source, intent, config, importers = []) {
|
|
48
|
+
if (intent.kind === 'component') return `[ForgeWP Templates] ${source}: standalone export disabled; imports remain usable.`;
|
|
49
|
+
const mapping = `[ForgeWP Templates] ${source} -> ${intent.wordpressFile} (${intent.kind === 'page' ? 'Page template; assign it to a WordPress Page to choose its URL' : 'CPT single template; URL follows WordPress permalinks'}).`;
|
|
50
|
+
if (intent.kind !== 'page' || config.exportTemplate === true || !importers.length) return mapping;
|
|
51
|
+
return `${mapping}\n[ForgeWP Templates Warning] Also imported by ${importers.join(', ')}. If this is a helper, move it to src/app/components/ or set pageConfig.exportTemplate: false. Set it to true to confirm an intentional Page template.`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function writePageTemplateCache(outDir, intent, html, head) {
|
|
55
|
+
if (intent.kind === 'component') return;
|
|
56
|
+
fs.writeFileSync(path.join(outDir, `${intent.cacheStem}.html`), html, 'utf8');
|
|
57
|
+
fs.writeFileSync(path.join(outDir, `${intent.cacheStem}-head.html`), head, 'utf8');
|
|
58
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Baseline metadata for generated themes; project acceptance verifies support.
|
|
2
|
+
export function resolveThemeCompatibility(config) {
|
|
3
|
+
const value = config.compatibility;
|
|
4
|
+
if (value !== undefined && (!value || typeof value !== 'object' || Array.isArray(value))) {
|
|
5
|
+
throw new Error('compatibility must be an object');
|
|
6
|
+
}
|
|
7
|
+
const result = { requiresWordPress: '6.6', requiresPhp: '7.4', ...value };
|
|
8
|
+
for (const key of Object.keys(result)) {
|
|
9
|
+
if (!['requiresWordPress', 'requiresPhp', 'testedUpTo'].includes(key)) {
|
|
10
|
+
throw new Error(`Unknown compatibility option: ${key}`);
|
|
11
|
+
}
|
|
12
|
+
if (typeof result[key] !== 'string' || !/^\d+\.\d+(?:\.\d+)?$/.test(result[key])) {
|
|
13
|
+
throw new Error(`compatibility.${key} must be a numeric version string such as "6.6"`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const compare = (a, b) => {
|
|
17
|
+
const left = a.split('.').map(Number);
|
|
18
|
+
const right = b.split('.').map(Number);
|
|
19
|
+
for (let i = 0; i < 3; i++) {
|
|
20
|
+
const difference = (left[i] || 0) - (right[i] || 0);
|
|
21
|
+
if (difference) return difference;
|
|
22
|
+
}
|
|
23
|
+
return 0;
|
|
24
|
+
};
|
|
25
|
+
if (compare(result.requiresWordPress, '6.6') < 0 || compare(result.requiresPhp, '7.4') < 0) {
|
|
26
|
+
throw new Error('compatibility cannot lower the generated baseline: WordPress 6.6 and PHP 7.4');
|
|
27
|
+
}
|
|
28
|
+
if (result.testedUpTo && compare(result.testedUpTo, result.requiresWordPress) < 0) {
|
|
29
|
+
throw new Error('compatibility.testedUpTo must be at least requiresWordPress');
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
package/lib/validate-export.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { scanForHydrationIslands } from './hydration
|
|
3
|
+
import { scanForHydrationIslands } from './hydration/index.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Validate exported theme package output.
|
|
@@ -151,7 +151,7 @@ export async function validateExport({ themeRoot, outDir, assets, config, strict
|
|
|
151
151
|
// Validate generated page templates from .forgewp/template-*.html
|
|
152
152
|
const templateDir = path.join(themeRoot, '.forgewp');
|
|
153
153
|
if (fs.existsSync(templateDir)) {
|
|
154
|
-
const templateFiles = fs.readdirSync(templateDir).filter((file) => /^template-.*\.html$/.test(file));
|
|
154
|
+
const templateFiles = fs.readdirSync(templateDir).filter((file) => /^template-.*\.html$/.test(file) && !file.endsWith('-head.html'));
|
|
155
155
|
for (const templateFile of templateFiles) {
|
|
156
156
|
const slug = templateFile.replace(/^template-(.*)\.html$/, '$1');
|
|
157
157
|
const templatePhp = path.join(outDir, `page-${slug}.php`);
|
|
@@ -173,6 +173,55 @@ export async function validateExport({ themeRoot, outDir, assets, config, strict
|
|
|
173
173
|
if (!fs.existsSync(screenshotOut)) summary.missing.push(screenshotOut.replace(process.cwd() + path.sep, ''));
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
// WooCommerce Specific Audits
|
|
177
|
+
const packageJsonPath = path.join(themeRoot, 'package.json');
|
|
178
|
+
let isWooCommerce = false;
|
|
179
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
180
|
+
try {
|
|
181
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
182
|
+
isWooCommerce = !!(pkg.dependencies?.['@forgewp/woocommerce'] || pkg.devDependencies?.['@forgewp/woocommerce']);
|
|
183
|
+
} catch (e) {}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (isWooCommerce) {
|
|
187
|
+
if (fs.existsSync(outDir)) {
|
|
188
|
+
const phpFiles = fs.readdirSync(outDir)
|
|
189
|
+
.filter((file) => file.endsWith('.php'))
|
|
190
|
+
.map((file) => path.join(outDir, file));
|
|
191
|
+
|
|
192
|
+
for (const phpFile of phpFiles) {
|
|
193
|
+
const content = fs.readFileSync(phpFile, 'utf8');
|
|
194
|
+
|
|
195
|
+
// 1. XSS / Escaping Audits: Look for unescaped get_price_html()
|
|
196
|
+
if (content.includes('get_price_html()') && !content.includes('wp_kses_post')) {
|
|
197
|
+
summary.warnings.push(`${path.basename(phpFile)}: Found unescaped get_price_html(). Wrap with wp_kses_post() for XSS safety.`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Look for unescaped wc_get_rating_html()
|
|
201
|
+
if (content.includes('wc_get_rating_html') && !content.includes('wp_kses_post')) {
|
|
202
|
+
summary.warnings.push(`${path.basename(phpFile)}: Found unescaped wc_get_rating_html(). Wrap with wp_kses_post() for XSS safety.`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 2. Loop optimization checks
|
|
206
|
+
if (content.includes("post_type' => 'product'") && !content.includes('wc_get_products')) {
|
|
207
|
+
summary.warnings.push(`${path.basename(phpFile)}: Catalog loop should use wc_get_products() pagination wrappers instead of raw post_type => product query.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 3. Hydrator Resource Hygiene check
|
|
213
|
+
const islands = scanForHydrationIslands(themeRoot);
|
|
214
|
+
if (islands.length === 0) {
|
|
215
|
+
const functionsPhpPath = path.join(outDir, 'functions.php');
|
|
216
|
+
if (fs.existsSync(functionsPhpPath)) {
|
|
217
|
+
const functionsPhp = fs.readFileSync(functionsPhpPath, 'utf8');
|
|
218
|
+
if (functionsPhp.includes('forgewp-hydrator.js') || functionsPhp.includes('forgewp-woocommerce')) {
|
|
219
|
+
summary.warnings.push('functions.php: Enqueuing forgewp-hydrator.js or registering woocommerce scripts even though no hydration islands were detected.');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
176
225
|
// If strict, treat warnings as missing
|
|
177
226
|
if (strict && summary.warnings.length > 0) {
|
|
178
227
|
summary.missing.push(...summary.warnings);
|
package/lib/validate.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { existsSync, writeFileSync, mkdirSync } from "node:fs";
|
|
1
|
+
import { existsSync, writeFileSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import pc from "picocolors";
|
|
4
|
-
import { SYSTEM_BLUEPRINTS } from "./blueprints.js";
|
|
4
|
+
import { getSystemBlueprints, SYSTEM_BLUEPRINTS } from "./blueprints.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Preflight Check & Self-Healing Validator
|
|
8
8
|
*
|
|
9
9
|
* Runs before compiling the theme.
|
|
10
10
|
* - Automatically restores any deleted system-critical utility files using pre-compiled blueprints.
|
|
11
|
+
* - Automatically updates system-critical files if their content differs from compiler blueprints.
|
|
11
12
|
* - Throws descriptive, highly actionable errors if a user-editable core file is deleted.
|
|
12
13
|
*
|
|
13
14
|
* @param {string} themeRoot Absolute path to the theme root folder.
|
|
@@ -35,12 +36,33 @@ export function validateCriticalFiles(themeRoot) {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// 2. Validate & Self-Heal System-Critical Files
|
|
38
|
-
|
|
39
|
+
const blueprints = getSystemBlueprints(themeRoot);
|
|
40
|
+
for (const [relativePath, blueprintContent] of Object.entries(blueprints)) {
|
|
39
41
|
const fullPath = path.join(themeRoot, relativePath);
|
|
42
|
+
let shouldWrite = false;
|
|
40
43
|
|
|
41
44
|
if (!existsSync(fullPath)) {
|
|
45
|
+
if (relativePath.startsWith("cms/") && relativePath.endsWith(".json")) {
|
|
46
|
+
const tsVariant = fullPath.replace(/\.json$/, ".ts");
|
|
47
|
+
if (existsSync(tsVariant)) {
|
|
48
|
+
continue; // Typed .ts file exists, do not recreate default .json blueprint
|
|
49
|
+
}
|
|
50
|
+
}
|
|
42
51
|
console.log(pc.yellow(` ⚠️ System file ${pc.bold(relativePath)} was missing! Restoring default system blueprint...`));
|
|
43
|
-
|
|
52
|
+
shouldWrite = true;
|
|
53
|
+
} else if (!relativePath.startsWith("cms/")) {
|
|
54
|
+
try {
|
|
55
|
+
const existingContent = readFileSync(fullPath, "utf8");
|
|
56
|
+
if (existingContent !== blueprintContent) {
|
|
57
|
+
console.log(pc.yellow(` 🔄 System file ${pc.bold(relativePath)} is out of date! Updating to latest system blueprint...`));
|
|
58
|
+
shouldWrite = true;
|
|
59
|
+
}
|
|
60
|
+
} catch (e) {
|
|
61
|
+
shouldWrite = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (shouldWrite) {
|
|
44
66
|
// Ensure target directory exists (e.g. src/lib/)
|
|
45
67
|
const dirPath = path.dirname(fullPath);
|
|
46
68
|
if (!existsSync(dirPath)) {
|
|
@@ -48,7 +70,7 @@ export function validateCriticalFiles(themeRoot) {
|
|
|
48
70
|
}
|
|
49
71
|
|
|
50
72
|
writeFileSync(fullPath, blueprintContent, "utf8");
|
|
51
|
-
console.log(pc.green(` ✅ Successfully restored system file: ${relativePath}`));
|
|
73
|
+
console.log(pc.green(` ✅ Successfully restored/updated system file: ${relativePath}`));
|
|
52
74
|
}
|
|
53
75
|
}
|
|
54
76
|
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { loadConfig } from './load-config.js';
|
|
4
|
+
import { buildFormsPreviewData, formsPreviewScript } from './forms-preview.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ForgeWP Vite Virtual Plugin
|
|
8
|
+
*
|
|
9
|
+
* Provides zero-clutter virtual runtime module resolution and dynamic dev-mode
|
|
10
|
+
* mock data injection directly from local `cms/*.ts` files into the browser runtime.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} options
|
|
13
|
+
* @param {string} [options.projectRoot]
|
|
14
|
+
* @returns {import('vite').Plugin}
|
|
15
|
+
*/
|
|
16
|
+
export function forgewpVirtualPlugin(options = {}) {
|
|
17
|
+
const projectRoot = options.projectRoot || process.cwd();
|
|
18
|
+
|
|
19
|
+
const VIRTUAL_RUNTIME_ID = 'virtual:forgewp-runtime';
|
|
20
|
+
const RESOLVED_RUNTIME_ID = '\0' + VIRTUAL_RUNTIME_ID;
|
|
21
|
+
let development = false;
|
|
22
|
+
let formPreview = buildFormsPreviewData({});
|
|
23
|
+
let authPreview = {};
|
|
24
|
+
async function refreshForms() {
|
|
25
|
+
const configPath = path.join(projectRoot, 'wp.config.ts');
|
|
26
|
+
const config = fs.existsSync(configPath) ? await loadConfig(projectRoot) : {};
|
|
27
|
+
formPreview = buildFormsPreviewData(config);
|
|
28
|
+
const auth = config.auth || {};
|
|
29
|
+
authPreview = { registration: auth.features?.registration, emailVerification: auth.features?.emailVerification, autoLoginAfterSignup: auth.features?.autoLoginAfterSignup, defaultRole: auth.defaultRole, loginField: auth.loginField, registrationMetaFields: auth.registrationMetaFields || [], reservedUsernames: (auth.reservedUsernames || ['admin', 'system', 'root']).map((name) => name.toLowerCase()) };
|
|
30
|
+
}
|
|
31
|
+
const isFormSource = (file) => {
|
|
32
|
+
const relative = path.relative(projectRoot, file).replaceAll('\\', '/');
|
|
33
|
+
return relative === 'wp.config.ts' || (relative.startsWith('cms/mail/') && relative.endsWith('.json')) || (relative.startsWith('cms/forms/') && /\.[jt]sx?$/.test(relative));
|
|
34
|
+
};
|
|
35
|
+
function reloadForms(server) {
|
|
36
|
+
const module = server.moduleGraph.getModuleById(RESOLVED_RUNTIME_ID);
|
|
37
|
+
if (module) server.moduleGraph.invalidateModule(module);
|
|
38
|
+
server.ws.send({ type: 'full-reload' });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function hasPackage(pkgName) {
|
|
42
|
+
const pkgPath = path.join(projectRoot, 'package.json');
|
|
43
|
+
if (fs.existsSync(pkgPath)) {
|
|
44
|
+
try {
|
|
45
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
46
|
+
return Boolean(
|
|
47
|
+
(pkg.dependencies && pkg.dependencies[pkgName]) ||
|
|
48
|
+
(pkg.devDependencies && pkg.devDependencies[pkgName]) ||
|
|
49
|
+
(pkg.peerDependencies && pkg.peerDependencies[pkgName]),
|
|
50
|
+
);
|
|
51
|
+
} catch (e) {}
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
name: 'forgewp-virtual-runtime',
|
|
58
|
+
configResolved(config) { development = config.command === 'serve'; },
|
|
59
|
+
async buildStart() {
|
|
60
|
+
if (!development) return;
|
|
61
|
+
await refreshForms();
|
|
62
|
+
this.addWatchFile?.(path.join(projectRoot, 'wp.config.ts'));
|
|
63
|
+
},
|
|
64
|
+
configureServer(server) {
|
|
65
|
+
const formsDir = path.join(projectRoot, 'cms/forms');
|
|
66
|
+
server.watcher.add(formsDir);
|
|
67
|
+
server.watcher.add(path.join(projectRoot, 'cms/mail'));
|
|
68
|
+
const onStructureChange = async (file) => {
|
|
69
|
+
if (!isFormSource(file)) return;
|
|
70
|
+
try { await refreshForms(); reloadForms(server); }
|
|
71
|
+
catch (error) { server.ws.send({ type: 'error', err: { message: error.message, stack: error.stack } }); }
|
|
72
|
+
};
|
|
73
|
+
server.watcher.on('add', onStructureChange);
|
|
74
|
+
server.watcher.on('unlink', onStructureChange);
|
|
75
|
+
server.httpServer?.once('close', () => {
|
|
76
|
+
server.watcher.off('add', onStructureChange);
|
|
77
|
+
server.watcher.off('unlink', onStructureChange);
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
async handleHotUpdate({ file, server }) {
|
|
81
|
+
if (!isFormSource(file)) return;
|
|
82
|
+
await refreshForms();
|
|
83
|
+
reloadForms(server);
|
|
84
|
+
return [];
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
resolveId(id) {
|
|
88
|
+
if (id === VIRTUAL_RUNTIME_ID) {
|
|
89
|
+
return RESOLVED_RUNTIME_ID;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
transform(code, id) {
|
|
95
|
+
const cleanId = id.split('?')[0].replace(/\\/g, '/');
|
|
96
|
+
if (
|
|
97
|
+
(cleanId.endsWith('/src/main.tsx') ||
|
|
98
|
+
cleanId.endsWith('/src/main.jsx') ||
|
|
99
|
+
cleanId.endsWith('/src/main.ts') ||
|
|
100
|
+
cleanId.endsWith('/src/main.js') ||
|
|
101
|
+
cleanId.endsWith('/src/index.tsx') ||
|
|
102
|
+
cleanId.endsWith('/src/index.jsx')) &&
|
|
103
|
+
!code.includes('virtual:forgewp-runtime')
|
|
104
|
+
) {
|
|
105
|
+
return {
|
|
106
|
+
code: `import 'virtual:forgewp-runtime';\n` + code,
|
|
107
|
+
map: null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
load(id) {
|
|
114
|
+
if (id === RESOLVED_RUNTIME_ID) {
|
|
115
|
+
const cmsDir = path.join(projectRoot, 'cms');
|
|
116
|
+
const hasWooCommerce = hasPackage('@forgewp/woocommerce');
|
|
117
|
+
const hasAuth = hasPackage('@forgewp/auth');
|
|
118
|
+
|
|
119
|
+
const imports = [];
|
|
120
|
+
const unwrapLogic = [
|
|
121
|
+
`const _u = (m, ...ks) => { const o = Object(m); for (const k of ks) if (o[k] !== undefined) return o[k]; return m; };`,
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
// 1. Mock Data / Posts
|
|
125
|
+
const mockDataTs = path.join(cmsDir, 'mock-data.ts');
|
|
126
|
+
const mockDataJson = path.join(cmsDir, 'mock-data.json');
|
|
127
|
+
if (fs.existsSync(mockDataTs) || fs.existsSync(mockDataJson)) {
|
|
128
|
+
const isTs = fs.existsSync(mockDataTs);
|
|
129
|
+
const importPath = isTs ? '/cms/mock-data.ts' : '/cms/mock-data.json';
|
|
130
|
+
imports.push(
|
|
131
|
+
isTs
|
|
132
|
+
? `import * as rawMockData from '${importPath}';`
|
|
133
|
+
: `import rawMockData from '${importPath}';`,
|
|
134
|
+
);
|
|
135
|
+
unwrapLogic.push(
|
|
136
|
+
`const mockData = _u(rawMockData, 'default', 'mockData') || {};`,
|
|
137
|
+
);
|
|
138
|
+
} else {
|
|
139
|
+
unwrapLogic.push(`const mockData = {};`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 2. Menus
|
|
143
|
+
const menusTs = path.join(cmsDir, 'menus.ts');
|
|
144
|
+
const menusJson = path.join(cmsDir, 'menus.json');
|
|
145
|
+
if (fs.existsSync(menusTs) || fs.existsSync(menusJson)) {
|
|
146
|
+
const isTs = fs.existsSync(menusTs);
|
|
147
|
+
const importPath = isTs ? '/cms/menus.ts' : '/cms/menus.json';
|
|
148
|
+
imports.push(
|
|
149
|
+
isTs
|
|
150
|
+
? `import * as rawMenusData from '${importPath}';`
|
|
151
|
+
: `import rawMenusData from '${importPath}';`,
|
|
152
|
+
);
|
|
153
|
+
unwrapLogic.push(
|
|
154
|
+
`const menusData = _u(rawMenusData, 'default', 'menus') || {};`,
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
unwrapLogic.push(`const menusData = {};`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 3. Translations
|
|
161
|
+
const transTs = path.join(cmsDir, 'translations.ts');
|
|
162
|
+
const transJson = path.join(cmsDir, 'translations.json');
|
|
163
|
+
if (fs.existsSync(transTs) || fs.existsSync(transJson)) {
|
|
164
|
+
const isTs = fs.existsSync(transTs);
|
|
165
|
+
const importPath = isTs
|
|
166
|
+
? '/cms/translations.ts'
|
|
167
|
+
: '/cms/translations.json';
|
|
168
|
+
imports.push(
|
|
169
|
+
isTs
|
|
170
|
+
? `import * as rawTranslationsData from '${importPath}';`
|
|
171
|
+
: `import rawTranslationsData from '${importPath}';`,
|
|
172
|
+
);
|
|
173
|
+
unwrapLogic.push(
|
|
174
|
+
`const translationsData = _u(rawTranslationsData, 'default', 'translations') || {};`,
|
|
175
|
+
);
|
|
176
|
+
} else {
|
|
177
|
+
unwrapLogic.push(`const translationsData = {};`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 4. Products (WooCommerce)
|
|
181
|
+
if (hasWooCommerce) {
|
|
182
|
+
const prodTs = path.join(cmsDir, 'products.ts');
|
|
183
|
+
const prodJson = path.join(cmsDir, 'products.json');
|
|
184
|
+
if (fs.existsSync(prodTs) || fs.existsSync(prodJson)) {
|
|
185
|
+
const isTs = fs.existsSync(prodTs);
|
|
186
|
+
const importPath = isTs ? '/cms/products.ts' : '/cms/products.json';
|
|
187
|
+
imports.push(
|
|
188
|
+
isTs
|
|
189
|
+
? `import * as rawProductsData from '${importPath}';`
|
|
190
|
+
: `import rawProductsData from '${importPath}';`,
|
|
191
|
+
);
|
|
192
|
+
unwrapLogic.push(
|
|
193
|
+
`const normalizedProducts = _u(rawProductsData, 'default', 'products', 'product') || [];`,
|
|
194
|
+
);
|
|
195
|
+
unwrapLogic.push(
|
|
196
|
+
`const productsMap = Array.isArray(normalizedProducts) ? { product: normalizedProducts } : normalizedProducts;`,
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
unwrapLogic.push(`const productsMap = {};`);
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
unwrapLogic.push(`const productsMap = {};`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 5. Auth (Users, Roles, Sessions)
|
|
206
|
+
if (hasAuth) {
|
|
207
|
+
const usersTs = path.join(cmsDir, 'users.ts');
|
|
208
|
+
const usersJson = path.join(cmsDir, 'users.json');
|
|
209
|
+
if (fs.existsSync(usersTs) || fs.existsSync(usersJson)) {
|
|
210
|
+
const isTs = fs.existsSync(usersTs);
|
|
211
|
+
const importPath = isTs ? '/cms/users.ts' : '/cms/users.json';
|
|
212
|
+
imports.push(
|
|
213
|
+
isTs
|
|
214
|
+
? `import * as rawUsersData from '${importPath}';`
|
|
215
|
+
: `import rawUsersData from '${importPath}';`,
|
|
216
|
+
);
|
|
217
|
+
unwrapLogic.push(
|
|
218
|
+
`const usersData = _u(rawUsersData, 'default', 'users');`,
|
|
219
|
+
);
|
|
220
|
+
} else {
|
|
221
|
+
unwrapLogic.push(`const usersData = [];`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const rolesTs = path.join(cmsDir, 'roles.ts');
|
|
225
|
+
const rolesJson = path.join(cmsDir, 'roles.json');
|
|
226
|
+
if (fs.existsSync(rolesTs) || fs.existsSync(rolesJson)) {
|
|
227
|
+
const isTs = fs.existsSync(rolesTs);
|
|
228
|
+
const importPath = isTs ? '/cms/roles.ts' : '/cms/roles.json';
|
|
229
|
+
imports.push(
|
|
230
|
+
isTs
|
|
231
|
+
? `import * as rawRolesData from '${importPath}';`
|
|
232
|
+
: `import rawRolesData from '${importPath}';`,
|
|
233
|
+
);
|
|
234
|
+
unwrapLogic.push(
|
|
235
|
+
`const rolesData = _u(rawRolesData, 'default', 'roles');`,
|
|
236
|
+
);
|
|
237
|
+
} else {
|
|
238
|
+
unwrapLogic.push(`const rolesData = {};`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const sessionsJson = path.join(cmsDir, 'sessions.json');
|
|
242
|
+
if (fs.existsSync(sessionsJson)) {
|
|
243
|
+
imports.push(`import rawSessionsData from '/cms/sessions.json';`);
|
|
244
|
+
unwrapLogic.push(`const sessionsData = rawSessionsData || [];`);
|
|
245
|
+
} else {
|
|
246
|
+
unwrapLogic.push(`const sessionsData = [];`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// 6. Site options & Theme mods
|
|
251
|
+
const siteOptionsTs = path.join(cmsDir, 'site-options.ts');
|
|
252
|
+
const siteSettingsJson = path.join(cmsDir, 'site-settings.json');
|
|
253
|
+
if (fs.existsSync(siteOptionsTs)) {
|
|
254
|
+
imports.push(
|
|
255
|
+
`import * as rawOptionsData from '/cms/site-options.ts';`,
|
|
256
|
+
);
|
|
257
|
+
unwrapLogic.push(
|
|
258
|
+
`const optionsData = _u(rawOptionsData, 'default', 'siteOptions', 'options') || {};`,
|
|
259
|
+
);
|
|
260
|
+
} else if (fs.existsSync(siteSettingsJson)) {
|
|
261
|
+
imports.push(
|
|
262
|
+
`import rawSiteSettings from '/cms/site-settings.json';`,
|
|
263
|
+
);
|
|
264
|
+
unwrapLogic.push(
|
|
265
|
+
`const optionsData = (rawSiteSettings && rawSiteSettings.options) || {};`,
|
|
266
|
+
);
|
|
267
|
+
} else {
|
|
268
|
+
unwrapLogic.push(`const optionsData = {};`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const themeModsTs = path.join(cmsDir, 'theme-mods.ts');
|
|
272
|
+
if (fs.existsSync(themeModsTs)) {
|
|
273
|
+
imports.push(`import * as rawModsData from '/cms/theme-mods.ts';`);
|
|
274
|
+
unwrapLogic.push(
|
|
275
|
+
`const modsData = _u(rawModsData, 'default', 'themeMods') || {};`,
|
|
276
|
+
);
|
|
277
|
+
} else if (fs.existsSync(siteSettingsJson)) {
|
|
278
|
+
unwrapLogic.push(
|
|
279
|
+
`const modsData = (typeof rawSiteSettings !== 'undefined' && rawSiteSettings.theme_mods) || {};`,
|
|
280
|
+
);
|
|
281
|
+
} else {
|
|
282
|
+
unwrapLogic.push(`const modsData = {};`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return `
|
|
286
|
+
${imports.join('\n')}
|
|
287
|
+
|
|
288
|
+
${unwrapLogic.join('\n')}
|
|
289
|
+
|
|
290
|
+
if (typeof window !== 'undefined') {
|
|
291
|
+
window._forgeWpMockSiteSettings = {
|
|
292
|
+
options: optionsData,
|
|
293
|
+
theme_mods: modsData,
|
|
294
|
+
};
|
|
295
|
+
window._forgeWpMockPosts = {
|
|
296
|
+
...mockData,
|
|
297
|
+
...productsMap,
|
|
298
|
+
};
|
|
299
|
+
window._forgeWpMockMenus = menusData;
|
|
300
|
+
window._forgeWpMockTranslations = translationsData;
|
|
301
|
+
${development ? formsPreviewScript(formPreview) : ''}
|
|
302
|
+
${development ? `window._forgeWpAuthPreview = ${JSON.stringify(authPreview)};` : ''}
|
|
303
|
+
${hasAuth ? `window._forgeWpMockUsers = usersData;\n window._forgeWpMockRoles = rolesData;\n window._forgeWpMockSessions = sessionsData;` : ''}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export default {
|
|
307
|
+
mockData,
|
|
308
|
+
menusData,
|
|
309
|
+
translationsData,
|
|
310
|
+
};
|
|
311
|
+
`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return null;
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export default forgewpVirtualPlugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Walkthrough — TestControls Block Extraction & Compiler Hydration Order Fix
|
|
2
|
+
|
|
3
|
+
We have successfully extracted the `TestControlsBlock` to a standard JSDoc-annotated component and resolved a crucial compiler chicken-and-egg issue.
|
|
4
|
+
|
|
5
|
+
## Changes Made
|
|
6
|
+
|
|
7
|
+
### 1. Extracted Handcrafted Block into Component
|
|
8
|
+
- Created [TestControls.tsx](file:///c:/Users/hp/Desktop/ForgeWP/hotelchecker24/src/components/TestControls.tsx) under `src/components/` with proper `@forgewp-block` JSDoc annotations.
|
|
9
|
+
- Declared and exported the editable schema using `defineEditable`.
|
|
10
|
+
- Provided fallback values and mapped props appropriately, passing the optional `setAttributes` hook to support inline Gutenberg canvas controls.
|
|
11
|
+
- Deleted the outdated handcrafted file at `src/blocks/TestControlsBlock.tsx` so the scanner can pick up the new component and auto-generate the wrapper.
|
|
12
|
+
|
|
13
|
+
### 2. Fixed Compiler Hook / Chicken-and-Egg Issue
|
|
14
|
+
- Modified [export-theme.js](file:///c:/Users/hp/Desktop/ForgeWP/packages/compiler/lib/export-theme.js#L21-L26) to call `scanAndGenerateBlocks` **before** initiating the Vite build (`buildAssets`).
|
|
15
|
+
- Previously, Vite's asset compilation ran before block wrappers were generated, causing new/modified JSDoc blocks to be omitted from the Rollup input configuration. This resulted in hydration errors (`missing compiled chunk for island(s)...`).
|
|
16
|
+
- By pre-scaffolding block wrappers, Vite now correctly receives the component paths, compiles the required chunks, and outputs the necessary JS files.
|
|
17
|
+
|
|
18
|
+
### 3. Enabled setAttributes on Auto-generated Blocks
|
|
19
|
+
- Updated [block-compiler.js](file:///c:/Users/hp/Desktop/ForgeWP/packages/compiler/lib/block-compiler.js#L1331-L1344) to pass `setAttributes={props.setAttributes}` inside the auto-generated wrapper's `edit` callback.
|
|
20
|
+
- This unlocks interactive in-canvas inline editing (such as `<WpEditable>`) for components built entirely via JSDoc metadata annotations.
|
|
21
|
+
|
|
22
|
+
## Verification & Testing
|
|
23
|
+
- Ran the compilation and sync script: `node scripts/sync-to-wp.mjs hotelchecker24`.
|
|
24
|
+
- The compilation completed successfully with exit code `0`.
|
|
25
|
+
- The smart optimizer detected `TestControls` as an interactive component and successfully generated a code-splitting hydration island of `0.6 kB`.
|
|
26
|
+
- The theme was packaged and synced to the local WordPress themes folder.
|