wp-typia 0.22.4 → 0.22.6

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.
@@ -11,6 +11,7 @@ import {
11
11
  parseAlternateRenderTargets,
12
12
  parseCompoundInnerBlocksPreset,
13
13
  parseTemplateLocator,
14
+ pathExists,
14
15
  renderScaffoldCompatibilityConfig,
15
16
  require_semver,
16
17
  resolveExternalTemplateLayers,
@@ -21,7 +22,7 @@ import {
21
22
  scaffoldProject,
22
23
  syncPersistenceRestArtifacts,
23
24
  updatePluginHeaderCompatibility
24
- } from "./cli-6ymn63t4.js";
25
+ } from "./cli-6a65qfb1.js";
25
26
  import {
26
27
  DEFAULT_WORDPRESS_ABILITIES_VERSION,
27
28
  DEFAULT_WORDPRESS_CORE_ABILITIES_VERSION,
@@ -34,13 +35,13 @@ import {
34
35
  } from "./cli-1sm60g1z.js";
35
36
  import {
36
37
  snapshotProjectVersion
37
- } from "./cli-2mt6bvcj.js";
38
+ } from "./cli-0q0tz4dq.js";
38
39
  import {
39
40
  ensureMigrationDirectories,
40
41
  parseMigrationConfig,
41
42
  writeInitialMigrationScaffold,
42
43
  writeMigrationConfig
43
- } from "./cli-hb9vpsev.js";
44
+ } from "./cli-2rqf6t0b.js";
44
45
  import"./cli-bq2v559b.js";
45
46
  import {
46
47
  findExecutablePatternMatch,
@@ -54,7 +55,6 @@ import {
54
55
  } from "./cli-tke8twkn.js";
55
56
  import {
56
57
  ADD_BLOCK_TEMPLATE_IDS,
57
- ADD_KIND_IDS,
58
58
  EDITOR_PLUGIN_SLOT_IDS,
59
59
  appendWorkspaceInventoryEntries,
60
60
  assertAbilityDoesNotExist,
@@ -79,6 +79,7 @@ import {
79
79
  getMutableBlockHooks,
80
80
  getWorkspaceBlockSelectOptions,
81
81
  getWorkspaceBootstrapPath,
82
+ hasPhpFunctionCall,
82
83
  hasPhpFunctionDefinition,
83
84
  isAddBlockTemplateId,
84
85
  normalizeBlockSlug,
@@ -100,26 +101,25 @@ import {
100
101
  toPascalCase,
101
102
  toSnakeCase,
102
103
  toTitleCase
103
- } from "./cli-qr2ek735.js";
104
+ } from "./cli-5kn2p7ee.js";
104
105
  import {
105
106
  createManagedTempRoot
106
107
  } from "./cli-t73q5aqz.js";
107
108
  import {
108
- CLI_DIAGNOSTIC_CODES,
109
- createCliDiagnosticCodeError
110
- } from "./cli-p95wr1q8.js";
109
+ ADD_KIND_IDS
110
+ } from "./cli-fys8vm2t.js";
111
+ import"./cli-p95wr1q8.js";
111
112
  import {
112
113
  resolveWorkspaceProject
113
- } from "./cli-btbpt84c.js";
114
+ } from "./cli-hhp1d348.js";
114
115
  import {
115
116
  formatInstallCommand
116
- } from "./cli-6bhfzq5e.js";
117
+ } from "./cli-52ke0ptp.js";
117
118
  import {
118
119
  __reExport,
119
120
  __toESM
120
121
  } from "./cli-xnn9xjcy.js";
121
122
  // ../wp-typia-project-tools/src/runtime/cli-add-block.ts
122
- import fs2 from "fs";
123
123
  import { promises as fsp2 } from "fs";
124
124
  import path3 from "path";
125
125
  import {
@@ -485,11 +485,16 @@ async function renderWorkspacePersistenceServerModule(projectDir, variables) {
485
485
  const templateDir = buildServerTemplateRoot(variables.persistencePolicy);
486
486
  await copyInterpolatedDirectory(templateDir, targetDir, variables);
487
487
  }
488
- function hasInstalledWorkspaceDependencies(projectDir) {
489
- return WORKSPACE_INSTALL_MARKERS.some((marker) => fs2.existsSync(path3.join(projectDir, marker)));
488
+ async function hasInstalledWorkspaceDependencies(projectDir) {
489
+ for (const marker of WORKSPACE_INSTALL_MARKERS) {
490
+ if (await pathExists(path3.join(projectDir, marker))) {
491
+ return true;
492
+ }
493
+ }
494
+ return false;
490
495
  }
491
- function assertWorkspaceDependenciesInstalled(workspace) {
492
- if (hasInstalledWorkspaceDependencies(workspace.projectDir)) {
496
+ async function assertWorkspaceDependenciesInstalled(workspace) {
497
+ if (await hasInstalledWorkspaceDependencies(workspace.projectDir)) {
493
498
  return;
494
499
  }
495
500
  throw new Error(`Workspace dependencies have not been installed yet. Run \`${formatInstallCommand(workspace.packageManager)}\` from the workspace root before using \`wp-typia add block ...\`.`);
@@ -561,19 +566,19 @@ function collectWorkspaceBlockPaths(projectDir, templateId, variables) {
561
566
  }
562
567
  return [path3.join(projectDir, "src", "blocks", variables.slugKebabCase)];
563
568
  }
564
- function assertBlockTargetsDoNotExist(projectDir, templateId, variables) {
569
+ async function assertBlockTargetsDoNotExist(projectDir, templateId, variables) {
565
570
  for (const targetPath of collectWorkspaceBlockPaths(projectDir, templateId, variables)) {
566
- if (fs2.existsSync(targetPath)) {
571
+ if (await pathExists(targetPath)) {
567
572
  throw new Error(`A block already exists at ${path3.relative(projectDir, targetPath)}. Choose a different name.`);
568
573
  }
569
574
  }
570
575
  }
571
576
  async function updateWorkspaceMigrationConfigIfPresent(projectDir, newBlocks) {
572
577
  const configPath = path3.join(projectDir, "src", "migrations", "config.ts");
573
- if (!fs2.existsSync(configPath)) {
578
+ const configSource = await readOptionalFile(configPath);
579
+ if (configSource === null) {
574
580
  return;
575
581
  }
576
- const configSource = await fsp2.readFile(configPath, "utf8");
577
582
  const config = parseMigrationConfig(configSource);
578
583
  const existingBlocks = Array.isArray(config.blocks) ? config.blocks : [];
579
584
  const nextBlocks = [
@@ -682,7 +687,7 @@ async function runAddBlockCommand({
682
687
  assertCompoundInnerBlocksPresetAllowed(resolvedTemplateId, innerBlocksPreset);
683
688
  const resolvedInnerBlocksPreset = parseCompoundInnerBlocksPreset(innerBlocksPreset);
684
689
  const workspace = resolveWorkspaceProject(cwd);
685
- assertWorkspaceDependenciesInstalled(workspace);
690
+ await assertWorkspaceDependenciesInstalled(workspace);
686
691
  const normalizedExternalLayerId = normalizeOptionalCliString(externalLayerId);
687
692
  const normalizedExternalLayerSource = resolveLocalCliPathOption({
688
693
  cwd,
@@ -753,7 +758,7 @@ async function runAddBlockCommand({
753
758
  });
754
759
  return scaffoldResult;
755
760
  })();
756
- assertBlockTargetsDoNotExist(workspace.projectDir, resolvedTemplateId, result.variables);
761
+ await assertBlockTargetsDoNotExist(workspace.projectDir, resolvedTemplateId, result.variables);
757
762
  const mutationSnapshot = {
758
763
  fileSources: await snapshotWorkspaceFiles([
759
764
  blockConfigPath,
@@ -789,7 +794,7 @@ async function runAddBlockCommand({
789
794
  }
790
795
  }
791
796
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace.ts
792
- import fs6 from "fs";
797
+ import fs5 from "fs";
793
798
  import { promises as fsp9 } from "fs";
794
799
  import path14 from "path";
795
800
 
@@ -808,8 +813,6 @@ var ADMIN_VIEWS_ASSET = "build/admin-views/index.asset.php";
808
813
  var ADMIN_VIEWS_STYLE = "build/admin-views/style-index.css";
809
814
  var ADMIN_VIEWS_STYLE_RTL = "build/admin-views/style-index-rtl.css";
810
815
  var ADMIN_VIEWS_PHP_GLOB = "/inc/admin-views/*.php";
811
- var ADMIN_VIEW_ALLOW_UNPUBLISHED_DATAVIEWS_ENV = "WP_TYPIA_ALLOW_UNPUBLISHED_DATAVIEWS";
812
- var ADMIN_VIEW_PUBLIC_INSTALLS_ENABLED = false;
813
816
  function isAdminViewCoreDataSource(source) {
814
817
  return source?.kind === ADMIN_VIEW_CORE_DATA_SOURCE_KIND;
815
818
  }
@@ -824,14 +827,8 @@ function formatAdminViewSourceLocator(source) {
824
827
  }
825
828
 
826
829
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-source.ts
827
- function isAdminViewUnpublishedDataViewsOverrideEnabled() {
828
- return process.env[ADMIN_VIEW_ALLOW_UNPUBLISHED_DATAVIEWS_ENV]?.trim() === "1";
829
- }
830
830
  function assertAdminViewPackageAvailability() {
831
- if (isAdminViewUnpublishedDataViewsOverrideEnabled() || ADMIN_VIEW_PUBLIC_INSTALLS_ENABLED) {
832
- return;
833
- }
834
- throw createCliDiagnosticCodeError(CLI_DIAGNOSTIC_CODES.INVALID_ARGUMENT, "`wp-typia add admin-view` is temporarily unavailable because `@wp-typia/dataviews` is not published to npm for public installs yet.");
831
+ return;
835
832
  }
836
833
  function assertValidCoreDataEntitySegment(label, value) {
837
834
  const trimmed = value.trim();
@@ -908,7 +905,7 @@ function resolveAdminViewCoreDataSource(source) {
908
905
  }
909
906
 
910
907
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-scaffold.ts
911
- import fs3 from "fs";
908
+ import fs2 from "fs";
912
909
  import { promises as fsp3 } from "fs";
913
910
  import path5 from "path";
914
911
 
@@ -2094,13 +2091,13 @@ function resolveAdminViewRegistryPath(projectDir) {
2094
2091
  return [
2095
2092
  path5.join(adminViewsDir, "index.ts"),
2096
2093
  path5.join(adminViewsDir, "index.js")
2097
- ].find((candidatePath) => fs3.existsSync(candidatePath)) ?? path5.join(adminViewsDir, "index.ts");
2094
+ ].find((candidatePath) => fs2.existsSync(candidatePath)) ?? path5.join(adminViewsDir, "index.ts");
2098
2095
  }
2099
2096
  function readAdminViewRegistrySlugs(registryPath) {
2100
- if (!fs3.existsSync(registryPath)) {
2097
+ if (!fs2.existsSync(registryPath)) {
2101
2098
  return [];
2102
2099
  }
2103
- const source = fs3.readFileSync(registryPath, "utf8");
2100
+ const source = fs2.readFileSync(registryPath, "utf8");
2104
2101
  return Array.from(source.matchAll(/^\s*import\s+['"]\.\/([^/'"]+)(?:\/index(?:\.[cm]?[jt]sx?)?)?['"];?\s*$/gmu)).map((match) => match[1]);
2105
2102
  }
2106
2103
  async function writeAdminViewRegistry(projectDir, adminViewSlug) {
@@ -2196,7 +2193,7 @@ async function runAddAdminViewCommand({
2196
2193
  }
2197
2194
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-assets.ts
2198
2195
  var import_typescript = __toESM(require_typescript(), 1);
2199
- import fs4 from "fs";
2196
+ import fs3 from "fs";
2200
2197
  import { promises as fsp4 } from "fs";
2201
2198
  import path6 from "path";
2202
2199
  import {
@@ -2794,45 +2791,17 @@ function ${bindingEditorEnqueueFunctionName}() {
2794
2791
  );
2795
2792
  }
2796
2793
  `;
2797
- const insertionAnchors = [
2798
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
2799
- /\?>\s*$/u
2800
- ];
2801
- const insertPhpSnippet = (snippet) => {
2802
- for (const anchor of insertionAnchors) {
2803
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
2804
- ${match}`);
2805
- if (candidate !== nextSource) {
2806
- nextSource = candidate;
2807
- return;
2808
- }
2809
- }
2810
- nextSource = `${nextSource.trimEnd()}
2811
- ${snippet}
2812
- `;
2813
- };
2814
- const appendPhpSnippet = (snippet) => {
2815
- const closingTagPattern = /\?>\s*$/u;
2816
- if (closingTagPattern.test(nextSource)) {
2817
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
2818
- ?>`);
2819
- return;
2820
- }
2821
- nextSource = `${nextSource.trimEnd()}
2822
- ${snippet}
2823
- `;
2824
- };
2825
2794
  if (!hasPhpFunctionDefinition(nextSource, bindingRegistrationFunctionName)) {
2826
- insertPhpSnippet(bindingRegistrationFunction);
2795
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, bindingRegistrationFunction);
2827
2796
  }
2828
2797
  if (!hasPhpFunctionDefinition(nextSource, bindingEditorEnqueueFunctionName)) {
2829
- insertPhpSnippet(bindingEditorEnqueueFunction);
2798
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, bindingEditorEnqueueFunction);
2830
2799
  }
2831
2800
  if (!nextSource.includes(bindingRegistrationHook)) {
2832
- appendPhpSnippet(bindingRegistrationHook);
2801
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, bindingRegistrationHook);
2833
2802
  }
2834
2803
  if (!nextSource.includes(bindingEditorEnqueueHook)) {
2835
- appendPhpSnippet(bindingEditorEnqueueHook);
2804
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, bindingEditorEnqueueHook);
2836
2805
  }
2837
2806
  return nextSource;
2838
2807
  });
@@ -2882,36 +2851,8 @@ function ${enqueueFunctionName}() {
2882
2851
  }
2883
2852
  }
2884
2853
  `;
2885
- const insertionAnchors = [
2886
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
2887
- /\?>\s*$/u
2888
- ];
2889
- const insertPhpSnippet = (snippet) => {
2890
- for (const anchor of insertionAnchors) {
2891
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
2892
- ${match}`);
2893
- if (candidate !== nextSource) {
2894
- nextSource = candidate;
2895
- return;
2896
- }
2897
- }
2898
- nextSource = `${nextSource.trimEnd()}
2899
- ${snippet}
2900
- `;
2901
- };
2902
- const appendPhpSnippet = (snippet) => {
2903
- const closingTagPattern = /\?>\s*$/u;
2904
- if (closingTagPattern.test(nextSource)) {
2905
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
2906
- ?>`);
2907
- return;
2908
- }
2909
- nextSource = `${nextSource.trimEnd()}
2910
- ${snippet}
2911
- `;
2912
- };
2913
2854
  if (!hasPhpFunctionDefinition(nextSource, enqueueFunctionName)) {
2914
- insertPhpSnippet(enqueueFunction);
2855
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, enqueueFunction);
2915
2856
  } else {
2916
2857
  const requiredReferences = [
2917
2858
  EDITOR_PLUGIN_EDITOR_SCRIPT,
@@ -2932,7 +2873,7 @@ ${snippet}
2932
2873
  }
2933
2874
  }
2934
2875
  if (!nextSource.includes(enqueueHook)) {
2935
- appendPhpSnippet(enqueueHook);
2876
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, enqueueHook);
2936
2877
  }
2937
2878
  return nextSource;
2938
2879
  });
@@ -2992,13 +2933,13 @@ async function ensureEditorPluginWebpackAnchors(workspace) {
2992
2933
  }
2993
2934
  function resolveBindingSourceRegistryPath(projectDir) {
2994
2935
  const bindingsDir = path6.join(projectDir, "src", "bindings");
2995
- return [path6.join(bindingsDir, "index.ts"), path6.join(bindingsDir, "index.js")].find((candidatePath) => fs4.existsSync(candidatePath)) ?? path6.join(bindingsDir, "index.ts");
2936
+ return [path6.join(bindingsDir, "index.ts"), path6.join(bindingsDir, "index.js")].find((candidatePath) => fs3.existsSync(candidatePath)) ?? path6.join(bindingsDir, "index.ts");
2996
2937
  }
2997
2938
  async function writeBindingSourceRegistry(projectDir, bindingSourceSlug) {
2998
2939
  const bindingsDir = path6.join(projectDir, "src", "bindings");
2999
2940
  const bindingsIndexPath = resolveBindingSourceRegistryPath(projectDir);
3000
2941
  await fsp4.mkdir(bindingsDir, { recursive: true });
3001
- const existingBindingSourceSlugs = fs4.readdirSync(bindingsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
2942
+ const existingBindingSourceSlugs = fs3.readdirSync(bindingsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
3002
2943
  const nextBindingSourceSlugs = Array.from(new Set([...existingBindingSourceSlugs, bindingSourceSlug])).sort();
3003
2944
  await fsp4.writeFile(bindingsIndexPath, buildBindingSourceIndexSource(nextBindingSourceSlugs), "utf8");
3004
2945
  }
@@ -3007,13 +2948,13 @@ function resolveEditorPluginRegistryPath(projectDir) {
3007
2948
  return [
3008
2949
  path6.join(editorPluginsDir, "index.ts"),
3009
2950
  path6.join(editorPluginsDir, "index.js")
3010
- ].find((candidatePath) => fs4.existsSync(candidatePath)) ?? path6.join(editorPluginsDir, "index.ts");
2951
+ ].find((candidatePath) => fs3.existsSync(candidatePath)) ?? path6.join(editorPluginsDir, "index.ts");
3011
2952
  }
3012
2953
  function readEditorPluginRegistrySlugs(registryPath) {
3013
- if (!fs4.existsSync(registryPath)) {
2954
+ if (!fs3.existsSync(registryPath)) {
3014
2955
  return [];
3015
2956
  }
3016
- const source = fs4.readFileSync(registryPath, "utf8");
2957
+ const source = fs3.readFileSync(registryPath, "utf8");
3017
2958
  return Array.from(source.matchAll(/^\s*import\s+['"]\.\/([^/'"]+)(?:\/index(?:\.[cm]?[jt]sx?)?)?['"];?\s*$/gmu)).map((match) => match[1]);
3018
2959
  }
3019
2960
  async function writeEditorPluginRegistry(projectDir, editorPluginSlug) {
@@ -3198,36 +3139,8 @@ function ${registerFunctionName}() {
3198
3139
  }
3199
3140
  }
3200
3141
  `;
3201
- const insertionAnchors = [
3202
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
3203
- /\?>\s*$/u
3204
- ];
3205
- const insertPhpSnippet = (snippet) => {
3206
- for (const anchor of insertionAnchors) {
3207
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
3208
- ${match}`);
3209
- if (candidate !== nextSource) {
3210
- nextSource = candidate;
3211
- return;
3212
- }
3213
- }
3214
- nextSource = `${nextSource.trimEnd()}
3215
- ${snippet}
3216
- `;
3217
- };
3218
- const appendPhpSnippet = (snippet) => {
3219
- const closingTagPattern = /\?>\s*$/u;
3220
- if (closingTagPattern.test(nextSource)) {
3221
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
3222
- ?>`);
3223
- return;
3224
- }
3225
- nextSource = `${nextSource.trimEnd()}
3226
- ${snippet}
3227
- `;
3228
- };
3229
3142
  if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
3230
- insertPhpSnippet(registerFunction);
3143
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, registerFunction);
3231
3144
  } else if (!nextSource.includes(REST_RESOURCE_SERVER_GLOB)) {
3232
3145
  throw new Error([
3233
3146
  `Unable to patch ${path7.basename(bootstrapPath)} in ensureRestResourceBootstrapAnchors.`,
@@ -3236,7 +3149,7 @@ ${snippet}
3236
3149
  ].join(" "));
3237
3150
  }
3238
3151
  if (!nextSource.includes(registerHook)) {
3239
- appendPhpSnippet(registerHook);
3152
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, registerHook);
3240
3153
  }
3241
3154
  return nextSource;
3242
3155
  });
@@ -4408,7 +4321,7 @@ async function runAddRestResourceCommand({
4408
4321
  }
4409
4322
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-ability-scaffold.ts
4410
4323
  var import_semver = __toESM(require_semver(), 1);
4411
- import fs5 from "fs";
4324
+ import fs4 from "fs";
4412
4325
  import { promises as fsp6 } from "fs";
4413
4326
  import path10 from "path";
4414
4327
  import { syncTypeSchemas as syncTypeSchemas2 } from "@wp-typia/block-runtime/metadata-core";
@@ -4902,13 +4815,13 @@ function resolveManagedDependencyVersion(existingVersion, requiredVersion) {
4902
4815
  }
4903
4816
  function resolveAbilityRegistryPath(projectDir) {
4904
4817
  const abilitiesDir = path10.join(projectDir, "src", "abilities");
4905
- return [path10.join(abilitiesDir, "index.ts"), path10.join(abilitiesDir, "index.js")].find((candidatePath) => fs5.existsSync(candidatePath)) ?? path10.join(abilitiesDir, "index.ts");
4818
+ return [path10.join(abilitiesDir, "index.ts"), path10.join(abilitiesDir, "index.js")].find((candidatePath) => fs4.existsSync(candidatePath)) ?? path10.join(abilitiesDir, "index.ts");
4906
4819
  }
4907
4820
  function readAbilityRegistrySlugs(registryPath) {
4908
- if (!fs5.existsSync(registryPath)) {
4821
+ if (!fs4.existsSync(registryPath)) {
4909
4822
  return [];
4910
4823
  }
4911
- const source = fs5.readFileSync(registryPath, "utf8");
4824
+ const source = fs4.readFileSync(registryPath, "utf8");
4912
4825
  return Array.from(source.matchAll(/^\s*export\s+\*\s+from\s+['"]\.\/([^/'"]+)\/client['"];?\s*$/gmu)).map((match) => match[1]);
4913
4826
  }
4914
4827
  async function writeAbilityRegistry(projectDir, abilitySlug) {
@@ -4919,7 +4832,7 @@ async function writeAbilityRegistry(projectDir, abilitySlug) {
4919
4832
  const existingRegistrySlugs = readAbilityRegistrySlugs(registryPath);
4920
4833
  const nextAbilitySlugs = Array.from(new Set([...existingAbilitySlugs, ...existingRegistrySlugs, abilitySlug])).sort();
4921
4834
  const generatedSection = buildAbilityRegistrySource(nextAbilitySlugs);
4922
- const existingSource = fs5.existsSync(registryPath) ? fs5.readFileSync(registryPath, "utf8") : "";
4835
+ const existingSource = fs4.existsSync(registryPath) ? fs4.readFileSync(registryPath, "utf8") : "";
4923
4836
  const generatedSectionPattern = new RegExp(`${escapeRegex(ABILITY_REGISTRY_START_MARKER)}[\\s\\S]*?${escapeRegex(ABILITY_REGISTRY_END_MARKER)}\\n?`, "u");
4924
4837
  const nextSource = existingSource ? generatedSectionPattern.test(existingSource) ? existingSource.replace(generatedSectionPattern, generatedSection) : `${existingSource.trimEnd()}
4925
4838
 
@@ -5000,8 +4913,16 @@ function ${enqueueFunctionName}() {
5000
4913
  }
5001
4914
  if (!hasPhpFunctionDefinition(nextSource, enqueueFunctionName)) {
5002
4915
  nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, enqueueFunction);
5003
- } else if (!findPhpFunctionRange(nextSource, enqueueFunctionName)?.source.includes("wp_enqueue_script_module")) {
5004
- nextSource = replacePhpFunctionDefinition(nextSource, enqueueFunctionName, enqueueFunction, { trimReplacementStart: true }) ?? nextSource;
4916
+ } else {
4917
+ const functionRange = findPhpFunctionRange(nextSource, enqueueFunctionName);
4918
+ const functionSource = functionRange ? nextSource.slice(functionRange.start, functionRange.end) : "";
4919
+ if (!hasPhpFunctionCall(functionSource, "wp_enqueue_script_module")) {
4920
+ const replacedSource = replacePhpFunctionDefinition(nextSource, enqueueFunctionName, enqueueFunction, { trimReplacementStart: true });
4921
+ if (!replacedSource) {
4922
+ throw new Error(`Unable to repair ${path10.basename(bootstrapPath)} for ${enqueueFunctionName}.`);
4923
+ }
4924
+ nextSource = replacedSource;
4925
+ }
5005
4926
  }
5006
4927
  if (!nextSource.includes(loadHook)) {
5007
4928
  nextSource = appendPhpSnippetBeforeClosingTag(nextSource, loadHook);
@@ -5172,6 +5093,7 @@ async function scaffoldAbilityWorkspace({
5172
5093
  compatibilityPolicy,
5173
5094
  workspace
5174
5095
  }) {
5096
+ const compatibilityWarnings = [];
5175
5097
  const blockConfigPath = path10.join(workspace.projectDir, "scripts", "block-config.ts");
5176
5098
  const bootstrapPath = getWorkspaceBootstrapPath(workspace);
5177
5099
  const buildScriptPath = path10.join(workspace.projectDir, "scripts", "build-workspace.mjs");
@@ -5202,7 +5124,11 @@ async function scaffoldAbilityWorkspace({
5202
5124
  await fsp6.mkdir(abilityDir, { recursive: true });
5203
5125
  await fsp6.mkdir(path10.dirname(phpFilePath), { recursive: true });
5204
5126
  await ensureAbilityBootstrapAnchors(workspace);
5205
- await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
5127
+ await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy, {
5128
+ onWarning: (warning) => {
5129
+ compatibilityWarnings.push(warning);
5130
+ }
5131
+ }));
5206
5132
  await ensureAbilityPackageScripts(workspace);
5207
5133
  await ensureAbilitySyncProjectAnchors(workspace);
5208
5134
  await ensureAbilityBuildScriptAnchors(workspace);
@@ -5234,6 +5160,9 @@ async function scaffoldAbilityWorkspace({
5234
5160
  });
5235
5161
  }
5236
5162
  });
5163
+ return {
5164
+ warnings: compatibilityWarnings
5165
+ };
5237
5166
  }
5238
5167
 
5239
5168
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-ability.ts
@@ -5246,14 +5175,15 @@ async function runAddAbilityCommand({
5246
5175
  const inventory = readWorkspaceInventory(workspace.projectDir);
5247
5176
  assertAbilityDoesNotExist(workspace.projectDir, abilitySlug, inventory);
5248
5177
  const compatibilityPolicy = resolveScaffoldCompatibilityPolicy(REQUIRED_WORKSPACE_ABILITY_COMPATIBILITY);
5249
- await scaffoldAbilityWorkspace({
5178
+ const scaffoldResult = await scaffoldAbilityWorkspace({
5250
5179
  abilitySlug,
5251
5180
  compatibilityPolicy,
5252
5181
  workspace
5253
5182
  });
5254
5183
  return {
5255
5184
  abilitySlug,
5256
- projectDir: workspace.projectDir
5185
+ projectDir: workspace.projectDir,
5186
+ warnings: scaffoldResult.warnings
5257
5187
  };
5258
5188
  }
5259
5189
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-ai-scaffold.ts
@@ -5857,36 +5787,8 @@ function ${registerFunctionName}() {
5857
5787
  }
5858
5788
  }
5859
5789
  `;
5860
- const insertionAnchors = [
5861
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
5862
- /\?>\s*$/u
5863
- ];
5864
- const insertPhpSnippet = (snippet) => {
5865
- for (const anchor of insertionAnchors) {
5866
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
5867
- ${match}`);
5868
- if (candidate !== nextSource) {
5869
- nextSource = candidate;
5870
- return;
5871
- }
5872
- }
5873
- nextSource = `${nextSource.trimEnd()}
5874
- ${snippet}
5875
- `;
5876
- };
5877
- const appendPhpSnippet = (snippet) => {
5878
- const closingTagPattern = /\?>\s*$/u;
5879
- if (closingTagPattern.test(nextSource)) {
5880
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
5881
- ?>`);
5882
- return;
5883
- }
5884
- nextSource = `${nextSource.trimEnd()}
5885
- ${snippet}
5886
- `;
5887
- };
5888
5790
  if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
5889
- insertPhpSnippet(registerFunction);
5791
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, registerFunction);
5890
5792
  } else if (!nextSource.includes(AI_FEATURE_SERVER_GLOB)) {
5891
5793
  throw new Error([
5892
5794
  `Unable to patch ${path12.basename(bootstrapPath)} in ensureAiFeatureBootstrapAnchors.`,
@@ -5895,7 +5797,7 @@ ${snippet}
5895
5797
  ].join(" "));
5896
5798
  }
5897
5799
  if (!nextSource.includes(registerHook)) {
5898
- appendPhpSnippet(registerHook);
5800
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, registerHook);
5899
5801
  }
5900
5802
  return nextSource;
5901
5803
  });
@@ -6724,6 +6626,7 @@ async function scaffoldAiFeatureWorkspace({
6724
6626
  namespace,
6725
6627
  workspace
6726
6628
  }) {
6629
+ const compatibilityWarnings = [];
6727
6630
  const blockConfigPath = path13.join(workspace.projectDir, "scripts", "block-config.ts");
6728
6631
  const bootstrapPath = getWorkspaceBootstrapPath(workspace);
6729
6632
  const packageJsonPath = path13.join(workspace.projectDir, "package.json");
@@ -6750,7 +6653,11 @@ async function scaffoldAiFeatureWorkspace({
6750
6653
  await fsp8.mkdir(aiFeatureDir, { recursive: true });
6751
6654
  await fsp8.mkdir(path13.dirname(phpFilePath), { recursive: true });
6752
6655
  await ensureAiFeatureBootstrapAnchors(workspace);
6753
- await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
6656
+ await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy, {
6657
+ onWarning: (warning) => {
6658
+ compatibilityWarnings.push(warning);
6659
+ }
6660
+ }));
6754
6661
  const packageScriptChanges = await ensureAiFeaturePackageScripts(workspace);
6755
6662
  await ensureAiFeatureSyncProjectAnchors(workspace);
6756
6663
  await ensureAiFeatureSyncRestAnchors(workspace);
@@ -6786,9 +6693,12 @@ async function scaffoldAiFeatureWorkspace({
6786
6693
  transformSource: ensureBlockConfigCanAddRestManifests
6787
6694
  });
6788
6695
  return {
6789
- warnings: packageScriptChanges.addedProjectToolsDependency ? [
6790
- "Added `@wp-typia/project-tools` to devDependencies for `sync-ai`. If this workspace was already installed, rerun your package manager install command before the first `wp-typia sync ai`."
6791
- ] : []
6696
+ warnings: [
6697
+ ...compatibilityWarnings,
6698
+ ...packageScriptChanges.addedProjectToolsDependency ? [
6699
+ "Added `@wp-typia/project-tools` to devDependencies for `sync-ai`. If this workspace was already installed, rerun your package manager install command before the first `wp-typia sync ai`."
6700
+ ] : []
6701
+ ]
6792
6702
  };
6793
6703
  }
6794
6704
  });
@@ -7207,7 +7117,7 @@ async function writeVariationRegistry(projectDir, blockSlug, variationSlug) {
7207
7117
  const variationsDir = path14.join(projectDir, "src", "blocks", blockSlug, "variations");
7208
7118
  const variationsIndexPath = path14.join(variationsDir, "index.ts");
7209
7119
  await fsp9.mkdir(variationsDir, { recursive: true });
7210
- const existingVariationSlugs = fs6.readdirSync(variationsDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
7120
+ const existingVariationSlugs = fs5.readdirSync(variationsDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
7211
7121
  const nextVariationSlugs = Array.from(new Set([...existingVariationSlugs, variationSlug])).sort();
7212
7122
  await fsp9.writeFile(variationsIndexPath, buildVariationIndexSource(nextVariationSlugs), "utf8");
7213
7123
  }
@@ -7215,7 +7125,7 @@ async function writeBlockStyleRegistry(projectDir, blockSlug, styleSlug) {
7215
7125
  const stylesDir = path14.join(projectDir, "src", "blocks", blockSlug, "styles");
7216
7126
  const stylesIndexPath = path14.join(stylesDir, "index.ts");
7217
7127
  await fsp9.mkdir(stylesDir, { recursive: true });
7218
- const existingStyleSlugs = fs6.readdirSync(stylesDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
7128
+ const existingStyleSlugs = fs5.readdirSync(stylesDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
7219
7129
  const nextStyleSlugs = Array.from(new Set([...existingStyleSlugs, styleSlug])).sort();
7220
7130
  await fsp9.writeFile(stylesIndexPath, buildBlockStyleIndexSource(nextStyleSlugs), "utf8");
7221
7131
  }
@@ -7223,7 +7133,7 @@ async function writeBlockTransformRegistry(projectDir, blockSlug, transformSlug)
7223
7133
  const transformsDir = path14.join(projectDir, "src", "blocks", blockSlug, "transforms");
7224
7134
  const transformsIndexPath = path14.join(transformsDir, "index.ts");
7225
7135
  await fsp9.mkdir(transformsDir, { recursive: true });
7226
- const existingTransformSlugs = fs6.readdirSync(transformsDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
7136
+ const existingTransformSlugs = fs5.readdirSync(transformsDir).filter((entry) => entry.endsWith(".ts") && entry !== "index.ts").map((entry) => entry.replace(/\.ts$/u, ""));
7227
7137
  const nextTransformSlugs = Array.from(new Set([...existingTransformSlugs, transformSlug])).sort();
7228
7138
  await fsp9.writeFile(transformsIndexPath, buildBlockTransformIndexSource(nextTransformSlugs), "utf8");
7229
7139
  }
@@ -7272,7 +7182,7 @@ async function runAddVariationCommand({
7272
7182
  const variationsDir = path14.join(workspace.projectDir, "src", "blocks", blockSlug, "variations");
7273
7183
  const variationFilePath = path14.join(variationsDir, `${variationSlug}.ts`);
7274
7184
  const variationsIndexPath = path14.join(variationsDir, "index.ts");
7275
- const shouldRemoveVariationsDirOnRollback = !fs6.existsSync(variationsDir);
7185
+ const shouldRemoveVariationsDirOnRollback = !fs5.existsSync(variationsDir);
7276
7186
  const mutationSnapshot = {
7277
7187
  fileSources: await snapshotWorkspaceFiles([
7278
7188
  blockConfigPath,
@@ -7319,7 +7229,7 @@ async function runAddBlockStyleCommand({
7319
7229
  const stylesDir = path14.join(workspace.projectDir, "src", "blocks", blockSlug, "styles");
7320
7230
  const styleFilePath = path14.join(stylesDir, `${styleSlug}.ts`);
7321
7231
  const stylesIndexPath = path14.join(stylesDir, "index.ts");
7322
- const shouldRemoveStylesDirOnRollback = !fs6.existsSync(stylesDir);
7232
+ const shouldRemoveStylesDirOnRollback = !fs5.existsSync(stylesDir);
7323
7233
  const mutationSnapshot = {
7324
7234
  fileSources: await snapshotWorkspaceFiles([
7325
7235
  blockConfigPath,
@@ -7368,7 +7278,7 @@ async function runAddBlockTransformCommand({
7368
7278
  const transformsDir = path14.join(workspace.projectDir, "src", "blocks", target.blockSlug, "transforms");
7369
7279
  const transformFilePath = path14.join(transformsDir, `${transformSlug}.ts`);
7370
7280
  const transformsIndexPath = path14.join(transformsDir, "index.ts");
7371
- const shouldRemoveTransformsDirOnRollback = !fs6.existsSync(transformsDir);
7281
+ const shouldRemoveTransformsDirOnRollback = !fs5.existsSync(transformsDir);
7372
7282
  const mutationSnapshot = {
7373
7283
  fileSources: await snapshotWorkspaceFiles([
7374
7284
  blockConfigPath,
@@ -7475,4 +7385,4 @@ export {
7475
7385
  ADD_BLOCK_TEMPLATE_IDS
7476
7386
  };
7477
7387
 
7478
- //# debugId=851894DA0B69BA4964756E2164756E21
7388
+ //# debugId=24FCFA027181E91A64756E2164756E21