@wp-typia/project-tools 0.22.2 → 0.22.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/dist/runtime/built-in-block-code-templates/interactivity.d.ts +1 -1
- package/dist/runtime/built-in-block-code-templates/interactivity.js +4 -2
- package/dist/runtime/cli-add-block-json.d.ts +31 -0
- package/dist/runtime/cli-add-block-json.js +65 -0
- package/dist/runtime/cli-add-collision.d.ts +129 -0
- package/dist/runtime/cli-add-collision.js +293 -0
- package/dist/runtime/cli-add-filesystem.d.ts +29 -0
- package/dist/runtime/cli-add-filesystem.js +77 -0
- package/dist/runtime/cli-add-help.d.ts +4 -0
- package/dist/runtime/cli-add-help.js +41 -0
- package/dist/runtime/cli-add-shared.d.ts +6 -255
- package/dist/runtime/cli-add-shared.js +6 -391
- package/dist/runtime/cli-add-types.d.ts +247 -0
- package/dist/runtime/cli-add-types.js +64 -0
- package/dist/runtime/cli-add-validation.d.ts +87 -0
- package/dist/runtime/cli-add-validation.js +147 -0
- package/dist/runtime/cli-add-workspace-ability-scaffold.d.ts +5 -0
- package/dist/runtime/cli-add-workspace-ability-scaffold.js +366 -0
- package/dist/runtime/cli-add-workspace-ability-templates.d.ts +34 -0
- package/dist/runtime/cli-add-workspace-ability-templates.js +500 -0
- package/dist/runtime/cli-add-workspace-ability-types.d.ts +27 -0
- package/dist/runtime/cli-add-workspace-ability-types.js +14 -0
- package/dist/runtime/cli-add-workspace-ability.js +12 -852
- package/dist/runtime/cli-add-workspace-admin-view-scaffold.js +35 -61
- package/dist/runtime/cli-add-workspace-ai-scaffold.d.ts +21 -0
- package/dist/runtime/cli-add-workspace-ai-scaffold.js +87 -0
- package/dist/runtime/cli-add-workspace-ai-templates.d.ts +4 -0
- package/dist/runtime/cli-add-workspace-ai-templates.js +607 -0
- package/dist/runtime/cli-add-workspace-ai.js +15 -688
- package/dist/runtime/cli-add-workspace-assets.js +7 -4
- package/dist/runtime/cli-add-workspace-mutation.d.ts +30 -0
- package/dist/runtime/cli-add-workspace-mutation.js +60 -0
- package/dist/runtime/cli-add-workspace.js +2 -98
- package/dist/runtime/cli-add.d.ts +2 -2
- package/dist/runtime/cli-add.js +2 -2
- package/dist/runtime/cli-doctor-workspace-bindings.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-bindings.js +134 -0
- package/dist/runtime/cli-doctor-workspace-blocks.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-blocks.js +439 -0
- package/dist/runtime/cli-doctor-workspace-features.d.ts +11 -0
- package/dist/runtime/cli-doctor-workspace-features.js +383 -0
- package/dist/runtime/cli-doctor-workspace-package.d.ts +18 -0
- package/dist/runtime/cli-doctor-workspace-package.js +59 -0
- package/dist/runtime/cli-doctor-workspace-shared.d.ts +69 -0
- package/dist/runtime/cli-doctor-workspace-shared.js +87 -0
- package/dist/runtime/cli-doctor-workspace.js +25 -1062
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/migration-utils.d.ts +2 -1
- package/dist/runtime/migration-utils.js +3 -11
- package/dist/runtime/package-managers.d.ts +19 -0
- package/dist/runtime/package-managers.js +62 -0
- package/dist/runtime/template-source-cache.d.ts +59 -0
- package/dist/runtime/template-source-cache.js +160 -0
- package/dist/runtime/ts-source-masking.d.ts +28 -0
- package/dist/runtime/ts-source-masking.js +104 -0
- package/dist/runtime/typia-llm.d.ts +9 -1
- package/dist/runtime/typia-llm.js +20 -5
- package/dist/runtime/workspace-inventory.js +116 -59
- package/dist/runtime/workspace-project.d.ts +1 -1
- package/dist/runtime/workspace-project.js +2 -10
- package/package.json +4 -4
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseScaffoldBlockMetadata } from "@wp-typia/block-runtime/blocks";
|
|
4
|
+
import { checkExistingFiles, createDoctorCheck, WORKSPACE_FULL_BLOCK_NAME_PATTERN, WORKSPACE_GENERATED_BLOCK_ARTIFACTS, } from "./cli-doctor-workspace-shared.js";
|
|
5
|
+
import { HOOKED_BLOCK_ANCHOR_PATTERN, HOOKED_BLOCK_POSITION_SET, } from "./hooked-blocks.js";
|
|
6
|
+
import { hasExecutablePattern, hasUncommentedPattern, maskTypeScriptCommentsAndLiterals, } from "./ts-source-masking.js";
|
|
7
|
+
const WORKSPACE_COLLECTION_IMPORT_LINE = "import '../../collection';";
|
|
8
|
+
const WORKSPACE_COLLECTION_IMPORT_PATTERN = /^\s*import\s+["']\.\.\/\.\.\/collection["']\s*;?\s*$/m;
|
|
9
|
+
const WORKSPACE_VARIATIONS_IMPORT_PATTERN = /^\s*import\s*\{\s*registerWorkspaceVariations\s*\}\s*from\s*["']\.\/variations["']\s*;?\s*$/mu;
|
|
10
|
+
const WORKSPACE_VARIATIONS_CALL_PATTERN = /registerWorkspaceVariations\s*\(\s*\)\s*;?/u;
|
|
11
|
+
const WORKSPACE_BLOCK_STYLES_IMPORT_PATTERN = /^\s*import\s*\{\s*registerWorkspaceBlockStyles\s*\}\s*from\s*["']\.\/styles["']\s*;?\s*$/mu;
|
|
12
|
+
const WORKSPACE_BLOCK_STYLES_CALL_PATTERN = /registerWorkspaceBlockStyles\s*\(\s*\)\s*;?/u;
|
|
13
|
+
const WORKSPACE_BLOCK_TRANSFORMS_IMPORT_PATTERN = /^\s*import\s*\{\s*applyWorkspaceBlockTransforms\s*\}\s*from\s*["']\.\/transforms["']\s*;?\s*$/mu;
|
|
14
|
+
const WORKSPACE_BLOCK_TRANSFORMS_CALL_PATTERN = /applyWorkspaceBlockTransforms\s*\(\s*registration\s*\.\s*settings\s*\)\s*;?/u;
|
|
15
|
+
const WORKSPACE_BLOCK_IFRAME_COMPATIBILITY_DOC_URL = "https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/block-migration-for-iframe-editor-compatibility/";
|
|
16
|
+
const WORKSPACE_BLOCK_IFRAME_DIAGNOSTIC_CODES = {
|
|
17
|
+
API_VERSION: "wp-typia.workspace.block.iframe.api-version",
|
|
18
|
+
BLOCK_PROPS: "wp-typia.workspace.block.iframe.block-props",
|
|
19
|
+
EDITOR_GLOBALS: "wp-typia.workspace.block.iframe.editor-globals",
|
|
20
|
+
EDITOR_STYLES: "wp-typia.workspace.block.iframe.editor-styles",
|
|
21
|
+
};
|
|
22
|
+
const WORKSPACE_BLOCK_EDITOR_SOURCE_FILE_PATTERN = /\.[cm]?[jt]sx?$/u;
|
|
23
|
+
const WORKSPACE_BLOCK_EDITOR_SOURCE_BASENAMES = new Set([
|
|
24
|
+
"edit",
|
|
25
|
+
"editor",
|
|
26
|
+
"index",
|
|
27
|
+
"save",
|
|
28
|
+
]);
|
|
29
|
+
const WORKSPACE_BLOCK_EDITOR_SOURCE_DIRECTORIES = new Set([
|
|
30
|
+
"components",
|
|
31
|
+
"controls",
|
|
32
|
+
"editor",
|
|
33
|
+
"inspector",
|
|
34
|
+
]);
|
|
35
|
+
const WORKSPACE_BLOCK_LOCAL_STYLE_FILES = [
|
|
36
|
+
"editor.css",
|
|
37
|
+
"editor.scss",
|
|
38
|
+
"index.css",
|
|
39
|
+
"style.css",
|
|
40
|
+
"style.scss",
|
|
41
|
+
];
|
|
42
|
+
const WORKSPACE_BLOCK_IFRAME_GLOBAL_DOM_PATTERN = /\b(?:document|window)\b|\b(?:parent|top)\b(?!\s*:)/gu;
|
|
43
|
+
const WORKSPACE_BLOCK_PROPS_PATTERN = /\buse(?:Block|InnerBlocks)Props(?:\.save)?\s*\(/u;
|
|
44
|
+
function normalizePathSeparators(relativePath) {
|
|
45
|
+
return relativePath.split(path.sep).join("/");
|
|
46
|
+
}
|
|
47
|
+
function hasRegisteredBlockAsset(value) {
|
|
48
|
+
if (typeof value === "string") {
|
|
49
|
+
return value.trim().length > 0;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
return value.some((entry) => hasRegisteredBlockAsset(entry));
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
function readWorkspaceBlockIframeMetadata(projectDir, blockSlug) {
|
|
57
|
+
const blockJsonRelativePath = path.join("src", "blocks", blockSlug, "block.json");
|
|
58
|
+
const blockJsonPath = path.join(projectDir, blockJsonRelativePath);
|
|
59
|
+
if (!fs.existsSync(blockJsonPath)) {
|
|
60
|
+
return {
|
|
61
|
+
blockJsonRelativePath,
|
|
62
|
+
error: `Missing ${blockJsonRelativePath}`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const document = parseScaffoldBlockMetadata(JSON.parse(fs.readFileSync(blockJsonPath, "utf8")));
|
|
67
|
+
return {
|
|
68
|
+
blockJsonRelativePath,
|
|
69
|
+
document,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return {
|
|
74
|
+
blockJsonRelativePath,
|
|
75
|
+
error: error instanceof Error ? error.message : String(error),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function isWorkspaceBlockEditorSource(relativePath) {
|
|
80
|
+
if (!WORKSPACE_BLOCK_EDITOR_SOURCE_FILE_PATTERN.test(relativePath)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const normalizedRelativePath = normalizePathSeparators(relativePath);
|
|
84
|
+
const normalizedDirName = path.posix.dirname(normalizedRelativePath);
|
|
85
|
+
const normalizedBaseName = path.posix.basename(normalizedRelativePath, path.posix.extname(normalizedRelativePath));
|
|
86
|
+
if (WORKSPACE_BLOCK_EDITOR_SOURCE_BASENAMES.has(normalizedBaseName)) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
const pathSegments = normalizedDirName.split("/");
|
|
90
|
+
return pathSegments.some((segment) => WORKSPACE_BLOCK_EDITOR_SOURCE_DIRECTORIES.has(segment));
|
|
91
|
+
}
|
|
92
|
+
function isWorkspaceBlockSaveSource(relativePath) {
|
|
93
|
+
const normalizedBaseName = path.basename(relativePath, path.extname(relativePath));
|
|
94
|
+
return normalizedBaseName === "save";
|
|
95
|
+
}
|
|
96
|
+
function collectWorkspaceBlockEditorSources(projectDir, blockSlug) {
|
|
97
|
+
const blockDir = path.join(projectDir, "src", "blocks", blockSlug);
|
|
98
|
+
if (!fs.existsSync(blockDir)) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const collected = [];
|
|
102
|
+
const queue = [blockDir];
|
|
103
|
+
while (queue.length > 0) {
|
|
104
|
+
const currentDir = queue.pop();
|
|
105
|
+
if (!currentDir) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
|
|
109
|
+
const absolutePath = path.join(currentDir, entry.name);
|
|
110
|
+
if (entry.isDirectory()) {
|
|
111
|
+
queue.push(absolutePath);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!entry.isFile()) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const relativePath = path.relative(projectDir, absolutePath);
|
|
118
|
+
if (!isWorkspaceBlockEditorSource(relativePath)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
collected.push({
|
|
122
|
+
relativePath: normalizePathSeparators(relativePath),
|
|
123
|
+
source: fs.readFileSync(absolutePath, "utf8"),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return collected.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
128
|
+
}
|
|
129
|
+
function getSourceLineNumber(source, index) {
|
|
130
|
+
let line = 1;
|
|
131
|
+
for (let cursor = 0; cursor < index; cursor += 1) {
|
|
132
|
+
if (source[cursor] === "\n") {
|
|
133
|
+
line += 1;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return line;
|
|
137
|
+
}
|
|
138
|
+
function isGlobalDomAccessCandidate(source, index, identifier) {
|
|
139
|
+
const lineStart = source.lastIndexOf("\n", index - 1) + 1;
|
|
140
|
+
const lineEndCandidate = source.indexOf("\n", index);
|
|
141
|
+
const lineEnd = lineEndCandidate === -1 ? source.length : lineEndCandidate;
|
|
142
|
+
const lineSource = source.slice(lineStart, lineEnd);
|
|
143
|
+
const trimmedLine = lineSource.trimStart();
|
|
144
|
+
if (trimmedLine.startsWith("import ")) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (trimmedLine.startsWith("const ") || trimmedLine.startsWith("let ") || trimmedLine.startsWith("var ")) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (trimmedLine.startsWith("function ") || trimmedLine.startsWith("class ")) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
const precedingCharacter = index > 0 ? source[index - 1] : "";
|
|
154
|
+
if (precedingCharacter === "." || precedingCharacter === "'" || precedingCharacter === '"') {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return (identifier === "document" ||
|
|
158
|
+
identifier === "window" ||
|
|
159
|
+
identifier === "parent" ||
|
|
160
|
+
identifier === "top");
|
|
161
|
+
}
|
|
162
|
+
function findWorkspaceBlockGlobalDomAccesses(editorSources) {
|
|
163
|
+
return editorSources.flatMap(({ relativePath, source }) => {
|
|
164
|
+
const maskedSource = maskTypeScriptCommentsAndLiterals(source);
|
|
165
|
+
const matches = maskedSource.matchAll(WORKSPACE_BLOCK_IFRAME_GLOBAL_DOM_PATTERN);
|
|
166
|
+
const findings = [];
|
|
167
|
+
for (const match of matches) {
|
|
168
|
+
const identifier = match[0];
|
|
169
|
+
const matchIndex = match.index ?? -1;
|
|
170
|
+
if (matchIndex < 0) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (!isGlobalDomAccessCandidate(source, matchIndex, identifier)) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
findings.push(`${relativePath}:${getSourceLineNumber(source, matchIndex)}`);
|
|
177
|
+
}
|
|
178
|
+
return findings;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function getWorkspaceBlockRequiredFiles(block) {
|
|
182
|
+
const blockDir = path.join("src", "blocks", block.slug);
|
|
183
|
+
return Array.from(new Set([
|
|
184
|
+
block.typesFile,
|
|
185
|
+
block.apiTypesFile,
|
|
186
|
+
block.openApiFile,
|
|
187
|
+
path.join(blockDir, "index.tsx"),
|
|
188
|
+
...WORKSPACE_GENERATED_BLOCK_ARTIFACTS.map((fileName) => path.join(blockDir, fileName)),
|
|
189
|
+
].filter((filePath) => typeof filePath === "string")));
|
|
190
|
+
}
|
|
191
|
+
function checkWorkspaceBlockMetadata(projectDir, workspace, block) {
|
|
192
|
+
const blockJsonRelativePath = path.join("src", "blocks", block.slug, "block.json");
|
|
193
|
+
const blockJsonPath = path.join(projectDir, blockJsonRelativePath);
|
|
194
|
+
if (!fs.existsSync(blockJsonPath)) {
|
|
195
|
+
return createDoctorCheck(`Block metadata ${block.slug}`, "fail", `Missing ${blockJsonRelativePath}`);
|
|
196
|
+
}
|
|
197
|
+
let blockJson;
|
|
198
|
+
try {
|
|
199
|
+
blockJson = parseScaffoldBlockMetadata(JSON.parse(fs.readFileSync(blockJsonPath, "utf8")));
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return createDoctorCheck(`Block metadata ${block.slug}`, "fail", error instanceof Error ? error.message : String(error));
|
|
203
|
+
}
|
|
204
|
+
const expectedName = `${workspace.workspace.namespace}/${block.slug}`;
|
|
205
|
+
const issues = [];
|
|
206
|
+
if (blockJson.name !== expectedName) {
|
|
207
|
+
issues.push(`block.json name must equal "${expectedName}"`);
|
|
208
|
+
}
|
|
209
|
+
if (blockJson.textdomain !== workspace.workspace.textDomain) {
|
|
210
|
+
issues.push(`block.json textdomain must equal "${workspace.workspace.textDomain}"`);
|
|
211
|
+
}
|
|
212
|
+
return createDoctorCheck(`Block metadata ${block.slug}`, issues.length === 0 ? "pass" : "fail", issues.length === 0
|
|
213
|
+
? `block.json matches ${expectedName} and ${workspace.workspace.textDomain}`
|
|
214
|
+
: issues.join("; "));
|
|
215
|
+
}
|
|
216
|
+
function checkWorkspaceBlockHooks(projectDir, blockSlug) {
|
|
217
|
+
const blockJsonRelativePath = path.join("src", "blocks", blockSlug, "block.json");
|
|
218
|
+
const blockJsonPath = path.join(projectDir, blockJsonRelativePath);
|
|
219
|
+
if (!fs.existsSync(blockJsonPath)) {
|
|
220
|
+
return createDoctorCheck(`Block hooks ${blockSlug}`, "fail", `Missing ${blockJsonRelativePath}`);
|
|
221
|
+
}
|
|
222
|
+
let blockJson;
|
|
223
|
+
try {
|
|
224
|
+
blockJson = parseScaffoldBlockMetadata(JSON.parse(fs.readFileSync(blockJsonPath, "utf8")));
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
return createDoctorCheck(`Block hooks ${blockSlug}`, "fail", error instanceof Error ? error.message : String(error));
|
|
228
|
+
}
|
|
229
|
+
const blockHooks = blockJson.blockHooks;
|
|
230
|
+
if (blockHooks === undefined) {
|
|
231
|
+
return createDoctorCheck(`Block hooks ${blockSlug}`, "pass", "No blockHooks metadata configured");
|
|
232
|
+
}
|
|
233
|
+
if (!blockHooks || typeof blockHooks !== "object" || Array.isArray(blockHooks)) {
|
|
234
|
+
return createDoctorCheck(`Block hooks ${blockSlug}`, "fail", `${blockJsonRelativePath} must define blockHooks as an object when present.`);
|
|
235
|
+
}
|
|
236
|
+
const blockName = typeof blockJson.name === "string" && blockJson.name.trim().length > 0
|
|
237
|
+
? blockJson.name.trim()
|
|
238
|
+
: null;
|
|
239
|
+
const invalidEntries = Object.entries(blockHooks).filter(([anchor, position]) => (blockName !== null && anchor.trim() === blockName) ||
|
|
240
|
+
anchor.trim().length === 0 ||
|
|
241
|
+
anchor !== anchor.trim() ||
|
|
242
|
+
!HOOKED_BLOCK_ANCHOR_PATTERN.test(anchor) ||
|
|
243
|
+
typeof position !== "string" ||
|
|
244
|
+
!HOOKED_BLOCK_POSITION_SET.has(position));
|
|
245
|
+
return createDoctorCheck(`Block hooks ${blockSlug}`, invalidEntries.length === 0 ? "pass" : "fail", invalidEntries.length === 0
|
|
246
|
+
? `blockHooks metadata is valid${Object.keys(blockHooks).length > 0 ? ` (${Object.keys(blockHooks).join(", ")})` : ""}`
|
|
247
|
+
: `Invalid blockHooks entries: ${invalidEntries
|
|
248
|
+
.map(([anchor, position]) => `${anchor || "<empty>"} => ${String(position)}`)
|
|
249
|
+
.join(", ")}`);
|
|
250
|
+
}
|
|
251
|
+
function checkWorkspaceBlockCollectionImport(projectDir, blockSlug) {
|
|
252
|
+
const entryRelativePath = path.join("src", "blocks", blockSlug, "index.tsx");
|
|
253
|
+
const entryPath = path.join(projectDir, entryRelativePath);
|
|
254
|
+
if (!fs.existsSync(entryPath)) {
|
|
255
|
+
return createDoctorCheck(`Block collection ${blockSlug}`, "fail", `Missing ${entryRelativePath}`);
|
|
256
|
+
}
|
|
257
|
+
const source = fs.readFileSync(entryPath, "utf8");
|
|
258
|
+
const hasCollectionImport = WORKSPACE_COLLECTION_IMPORT_PATTERN.test(source);
|
|
259
|
+
return createDoctorCheck(`Block collection ${blockSlug}`, hasCollectionImport ? "pass" : "fail", hasCollectionImport
|
|
260
|
+
? "Shared block collection import is present"
|
|
261
|
+
: `Missing a shared collection import like ${WORKSPACE_COLLECTION_IMPORT_LINE}`);
|
|
262
|
+
}
|
|
263
|
+
function checkWorkspaceBlockIframeCompatibility(projectDir, blockSlug) {
|
|
264
|
+
const metadataResult = readWorkspaceBlockIframeMetadata(projectDir, blockSlug);
|
|
265
|
+
if (!metadataResult.document) {
|
|
266
|
+
return [
|
|
267
|
+
createDoctorCheck(`Block iframe/API v3 ${blockSlug}`, "warn", metadataResult.error ?? `Unable to inspect ${metadataResult.blockJsonRelativePath}`, WORKSPACE_BLOCK_IFRAME_DIAGNOSTIC_CODES.API_VERSION),
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
const blockJson = metadataResult.document;
|
|
271
|
+
const apiVersion = typeof blockJson.apiVersion === "number" && Number.isFinite(blockJson.apiVersion)
|
|
272
|
+
? blockJson.apiVersion
|
|
273
|
+
: null;
|
|
274
|
+
const blockDir = path.join(projectDir, "src", "blocks", blockSlug);
|
|
275
|
+
const localStyleFiles = WORKSPACE_BLOCK_LOCAL_STYLE_FILES.filter((fileName) => fs.existsSync(path.join(blockDir, fileName))).map((fileName) => normalizePathSeparators(path.join("src", "blocks", blockSlug, fileName)));
|
|
276
|
+
const hasRegisteredEditorStyles = hasRegisteredBlockAsset(blockJson.style) ||
|
|
277
|
+
hasRegisteredBlockAsset(blockJson.editorStyle);
|
|
278
|
+
const editorSources = collectWorkspaceBlockEditorSources(projectDir, blockSlug);
|
|
279
|
+
const editorWrapperSources = editorSources.filter((source) => !isWorkspaceBlockSaveSource(source.relativePath));
|
|
280
|
+
const globalDomAccesses = findWorkspaceBlockGlobalDomAccesses(editorSources);
|
|
281
|
+
const hasBlockPropsUsage = editorSources.some(({ source }) => hasExecutablePattern(source, WORKSPACE_BLOCK_PROPS_PATTERN));
|
|
282
|
+
const hasEditorBlockPropsUsage = editorWrapperSources.some(({ source }) => hasExecutablePattern(source, WORKSPACE_BLOCK_PROPS_PATTERN));
|
|
283
|
+
const blockWrapperStatus = editorWrapperSources.length === 0 || hasEditorBlockPropsUsage ? "pass" : "warn";
|
|
284
|
+
const blockWrapperDetail = editorSources.length === 0
|
|
285
|
+
? "No editor-facing block source files found; general file checks will report missing entrypoints"
|
|
286
|
+
: editorWrapperSources.length === 0
|
|
287
|
+
? "No editor wrapper source files found; general file checks will report missing entrypoints"
|
|
288
|
+
: hasEditorBlockPropsUsage
|
|
289
|
+
? "Editor-facing sources use block wrapper props"
|
|
290
|
+
: hasBlockPropsUsage
|
|
291
|
+
? "Only save-facing useBlockProps.save() usage was detected. Confirm the editor wrapper also receives useBlockProps() or useInnerBlocksProps() before relying on iframe editor rendering."
|
|
292
|
+
: "No useBlockProps(), useBlockProps.save(), or useInnerBlocksProps() usage was detected in editor-facing sources. Confirm the block wrapper receives WordPress block editor props before relying on iframe editor rendering.";
|
|
293
|
+
return [
|
|
294
|
+
createDoctorCheck(`Block iframe API version ${blockSlug}`, apiVersion !== null && apiVersion >= 3 ? "pass" : "warn", apiVersion !== null && apiVersion >= 3
|
|
295
|
+
? "block.json declares apiVersion 3 for iframe editor readiness"
|
|
296
|
+
: `Set ${metadataResult.blockJsonRelativePath} apiVersion to 3 after testing the block in iframe-enabled Post Editor and Site Editor contexts. WordPress recommends API v3 for iframe editor compatibility. See ${WORKSPACE_BLOCK_IFRAME_COMPATIBILITY_DOC_URL}`, WORKSPACE_BLOCK_IFRAME_DIAGNOSTIC_CODES.API_VERSION),
|
|
297
|
+
createDoctorCheck(`Block iframe styles ${blockSlug}`, localStyleFiles.length === 0 || hasRegisteredEditorStyles ? "pass" : "warn", localStyleFiles.length === 0
|
|
298
|
+
? "No local block stylesheet source files found to register"
|
|
299
|
+
: hasRegisteredEditorStyles
|
|
300
|
+
? "block.json registers block styles for iframe editor loading"
|
|
301
|
+
: `Found stylesheet source files (${localStyleFiles.join(", ")}) but block.json does not declare style or editorStyle. Register block content styles so iframe editors do not depend on parent admin styles.`, WORKSPACE_BLOCK_IFRAME_DIAGNOSTIC_CODES.EDITOR_STYLES),
|
|
302
|
+
createDoctorCheck(`Block iframe globals ${blockSlug}`, globalDomAccesses.length === 0 ? "pass" : "warn", globalDomAccesses.length === 0
|
|
303
|
+
? "No direct window/document/parent DOM access detected in editor-facing block sources"
|
|
304
|
+
: `Direct global DOM access detected at ${globalDomAccesses.join(", ")}. Prefer element.ownerDocument/defaultView via refs or useRefEffect for iframe editor content.`, WORKSPACE_BLOCK_IFRAME_DIAGNOSTIC_CODES.EDITOR_GLOBALS),
|
|
305
|
+
createDoctorCheck(`Block iframe wrapper ${blockSlug}`, blockWrapperStatus, blockWrapperDetail, WORKSPACE_BLOCK_IFRAME_DIAGNOSTIC_CODES.BLOCK_PROPS),
|
|
306
|
+
];
|
|
307
|
+
}
|
|
308
|
+
function checkWorkspacePatternBootstrap(projectDir, packageName) {
|
|
309
|
+
const packageBaseName = packageName.split("/").pop() ?? packageName;
|
|
310
|
+
const bootstrapPath = path.join(projectDir, `${packageBaseName}.php`);
|
|
311
|
+
if (!fs.existsSync(bootstrapPath)) {
|
|
312
|
+
return createDoctorCheck("Pattern bootstrap", "fail", `Missing ${path.basename(bootstrapPath)}`);
|
|
313
|
+
}
|
|
314
|
+
const source = fs.readFileSync(bootstrapPath, "utf8");
|
|
315
|
+
const hasCategoryAnchor = source.includes("register_block_pattern_category");
|
|
316
|
+
const hasPatternGlob = source.includes("/src/patterns/*.php");
|
|
317
|
+
return createDoctorCheck("Pattern bootstrap", hasCategoryAnchor && hasPatternGlob ? "pass" : "fail", hasCategoryAnchor && hasPatternGlob
|
|
318
|
+
? "Pattern category and loader hooks are present"
|
|
319
|
+
: "Missing pattern category registration or src/patterns loader hook");
|
|
320
|
+
}
|
|
321
|
+
function checkVariationEntrypoint(projectDir, blockSlug) {
|
|
322
|
+
const entryPath = path.join(projectDir, "src", "blocks", blockSlug, "index.tsx");
|
|
323
|
+
if (!fs.existsSync(entryPath)) {
|
|
324
|
+
return createDoctorCheck(`Variation entrypoint ${blockSlug}`, "fail", `Missing ${path.relative(projectDir, entryPath)}`);
|
|
325
|
+
}
|
|
326
|
+
const source = fs.readFileSync(entryPath, "utf8");
|
|
327
|
+
const hasImport = hasUncommentedPattern(source, WORKSPACE_VARIATIONS_IMPORT_PATTERN);
|
|
328
|
+
const hasCall = hasExecutablePattern(source, WORKSPACE_VARIATIONS_CALL_PATTERN);
|
|
329
|
+
return createDoctorCheck(`Variation entrypoint ${blockSlug}`, hasImport && hasCall ? "pass" : "fail", hasImport && hasCall
|
|
330
|
+
? "Variations registration hook is present"
|
|
331
|
+
: "Missing ./variations import or registerWorkspaceVariations() call");
|
|
332
|
+
}
|
|
333
|
+
function checkBlockStyleEntrypoint(projectDir, blockSlug) {
|
|
334
|
+
const entryPath = path.join(projectDir, "src", "blocks", blockSlug, "index.tsx");
|
|
335
|
+
if (!fs.existsSync(entryPath)) {
|
|
336
|
+
return createDoctorCheck(`Block style entrypoint ${blockSlug}`, "fail", `Missing ${path.relative(projectDir, entryPath)}`);
|
|
337
|
+
}
|
|
338
|
+
const source = fs.readFileSync(entryPath, "utf8");
|
|
339
|
+
const hasImport = hasUncommentedPattern(source, WORKSPACE_BLOCK_STYLES_IMPORT_PATTERN);
|
|
340
|
+
const hasCall = hasExecutablePattern(source, WORKSPACE_BLOCK_STYLES_CALL_PATTERN);
|
|
341
|
+
return createDoctorCheck(`Block style entrypoint ${blockSlug}`, hasImport && hasCall ? "pass" : "fail", hasImport && hasCall
|
|
342
|
+
? "Block style registration hook is present"
|
|
343
|
+
: "Missing ./styles import or registerWorkspaceBlockStyles() call");
|
|
344
|
+
}
|
|
345
|
+
function checkBlockTransformEntrypoint(projectDir, blockSlug) {
|
|
346
|
+
const entryPath = path.join(projectDir, "src", "blocks", blockSlug, "index.tsx");
|
|
347
|
+
if (!fs.existsSync(entryPath)) {
|
|
348
|
+
return createDoctorCheck(`Block transform entrypoint ${blockSlug}`, "fail", `Missing ${path.relative(projectDir, entryPath)}`);
|
|
349
|
+
}
|
|
350
|
+
const source = fs.readFileSync(entryPath, "utf8");
|
|
351
|
+
const hasImport = hasUncommentedPattern(source, WORKSPACE_BLOCK_TRANSFORMS_IMPORT_PATTERN);
|
|
352
|
+
const hasCall = hasExecutablePattern(source, WORKSPACE_BLOCK_TRANSFORMS_CALL_PATTERN);
|
|
353
|
+
return createDoctorCheck(`Block transform entrypoint ${blockSlug}`, hasImport && hasCall ? "pass" : "fail", hasImport && hasCall
|
|
354
|
+
? "Block transform registration hook is present"
|
|
355
|
+
: "Missing ./transforms import or applyWorkspaceBlockTransforms(registration.settings) call");
|
|
356
|
+
}
|
|
357
|
+
function checkBlockTransformConfig(workspace, transform) {
|
|
358
|
+
const expectedTo = `${workspace.workspace.namespace}/${transform.block}`;
|
|
359
|
+
const issues = [];
|
|
360
|
+
if (!WORKSPACE_FULL_BLOCK_NAME_PATTERN.test(transform.from)) {
|
|
361
|
+
issues.push("from must use full namespace/block format");
|
|
362
|
+
}
|
|
363
|
+
if (transform.to !== expectedTo) {
|
|
364
|
+
issues.push(`to must equal "${expectedTo}" for workspace block "${transform.block}"`);
|
|
365
|
+
}
|
|
366
|
+
return createDoctorCheck(`Block transform config ${transform.block}/${transform.slug}`, issues.length === 0 ? "pass" : "fail", issues.length === 0
|
|
367
|
+
? `${transform.from} transforms into ${transform.to}`
|
|
368
|
+
: issues.join("; "));
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Collect block-, variation-, transform-, and pattern-related workspace doctor checks.
|
|
372
|
+
*
|
|
373
|
+
* @param workspace Resolved workspace metadata and filesystem paths.
|
|
374
|
+
* @param inventory Parsed workspace inventory from `scripts/block-config.ts`.
|
|
375
|
+
* @returns Ordered `DoctorCheck[]` rows for extracted block diagnostics.
|
|
376
|
+
*/
|
|
377
|
+
export function getWorkspaceBlockDoctorChecks(workspace, inventory) {
|
|
378
|
+
const checks = [];
|
|
379
|
+
for (const block of inventory.blocks) {
|
|
380
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Block ${block.slug}`, getWorkspaceBlockRequiredFiles(block)));
|
|
381
|
+
checks.push(checkWorkspaceBlockMetadata(workspace.projectDir, workspace, block));
|
|
382
|
+
checks.push(checkWorkspaceBlockHooks(workspace.projectDir, block.slug));
|
|
383
|
+
checks.push(checkWorkspaceBlockCollectionImport(workspace.projectDir, block.slug));
|
|
384
|
+
checks.push(...checkWorkspaceBlockIframeCompatibility(workspace.projectDir, block.slug));
|
|
385
|
+
}
|
|
386
|
+
const registeredBlockSlugs = new Set(inventory.blocks.map((block) => block.slug));
|
|
387
|
+
const variationTargetBlocks = new Set();
|
|
388
|
+
for (const variation of inventory.variations) {
|
|
389
|
+
if (!registeredBlockSlugs.has(variation.block)) {
|
|
390
|
+
checks.push(createDoctorCheck(`Variation ${variation.block}/${variation.slug}`, "fail", `Variation references unknown block "${variation.block}"`));
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
variationTargetBlocks.add(variation.block);
|
|
394
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Variation ${variation.block}/${variation.slug}`, [variation.file]));
|
|
395
|
+
}
|
|
396
|
+
for (const blockSlug of variationTargetBlocks) {
|
|
397
|
+
checks.push(checkVariationEntrypoint(workspace.projectDir, blockSlug));
|
|
398
|
+
}
|
|
399
|
+
const blockStyleTargetBlocks = new Set();
|
|
400
|
+
for (const blockStyle of inventory.blockStyles) {
|
|
401
|
+
if (!registeredBlockSlugs.has(blockStyle.block)) {
|
|
402
|
+
checks.push(createDoctorCheck(`Block style ${blockStyle.block}/${blockStyle.slug}`, "fail", `Block style references unknown block "${blockStyle.block}"`));
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
blockStyleTargetBlocks.add(blockStyle.block);
|
|
406
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Block style ${blockStyle.block}/${blockStyle.slug}`, [blockStyle.file]));
|
|
407
|
+
}
|
|
408
|
+
for (const blockSlug of blockStyleTargetBlocks) {
|
|
409
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Block style registry ${blockSlug}`, [
|
|
410
|
+
path.join("src", "blocks", blockSlug, "styles", "index.ts"),
|
|
411
|
+
]));
|
|
412
|
+
checks.push(checkBlockStyleEntrypoint(workspace.projectDir, blockSlug));
|
|
413
|
+
}
|
|
414
|
+
const blockTransformTargetBlocks = new Set();
|
|
415
|
+
for (const blockTransform of inventory.blockTransforms) {
|
|
416
|
+
if (!registeredBlockSlugs.has(blockTransform.block)) {
|
|
417
|
+
checks.push(createDoctorCheck(`Block transform ${blockTransform.block}/${blockTransform.slug}`, "fail", `Block transform references unknown block "${blockTransform.block}"`));
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
blockTransformTargetBlocks.add(blockTransform.block);
|
|
421
|
+
checks.push(checkBlockTransformConfig(workspace, blockTransform));
|
|
422
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Block transform ${blockTransform.block}/${blockTransform.slug}`, [blockTransform.file]));
|
|
423
|
+
}
|
|
424
|
+
for (const blockSlug of blockTransformTargetBlocks) {
|
|
425
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Block transform registry ${blockSlug}`, [
|
|
426
|
+
path.join("src", "blocks", blockSlug, "transforms", "index.ts"),
|
|
427
|
+
]));
|
|
428
|
+
checks.push(checkBlockTransformEntrypoint(workspace.projectDir, blockSlug));
|
|
429
|
+
}
|
|
430
|
+
const shouldCheckPatternBootstrap = inventory.patterns.length > 0 ||
|
|
431
|
+
fs.existsSync(path.join(workspace.projectDir, "src", "patterns"));
|
|
432
|
+
if (shouldCheckPatternBootstrap) {
|
|
433
|
+
checks.push(checkWorkspacePatternBootstrap(workspace.projectDir, workspace.packageName));
|
|
434
|
+
}
|
|
435
|
+
for (const pattern of inventory.patterns) {
|
|
436
|
+
checks.push(checkExistingFiles(workspace.projectDir, `Pattern ${pattern.slug}`, [pattern.file]));
|
|
437
|
+
}
|
|
438
|
+
return checks;
|
|
439
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DoctorCheck } from "./cli-doctor.js";
|
|
2
|
+
import type { WorkspaceInventory } from "./workspace-inventory.js";
|
|
3
|
+
import type { WorkspaceProject } from "./workspace-project.js";
|
|
4
|
+
/**
|
|
5
|
+
* Collect workspace doctor checks for REST resources, abilities, AI features, editor plugins, and admin views.
|
|
6
|
+
*
|
|
7
|
+
* @param workspace Resolved workspace metadata and filesystem paths.
|
|
8
|
+
* @param inventory Parsed workspace inventory from `scripts/block-config.ts`.
|
|
9
|
+
* @returns Ordered `DoctorCheck[]` rows for extracted workspace feature diagnostics.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getWorkspaceFeatureDoctorChecks(workspace: WorkspaceProject, inventory: WorkspaceInventory): DoctorCheck[];
|