wp-typia 0.22.3 → 0.22.5

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.
@@ -21,7 +21,7 @@ import {
21
21
  scaffoldProject,
22
22
  syncPersistenceRestArtifacts,
23
23
  updatePluginHeaderCompatibility
24
- } from "./cli-tbd9x8b6.js";
24
+ } from "./cli-ctddkm3n.js";
25
25
  import {
26
26
  DEFAULT_WORDPRESS_ABILITIES_VERSION,
27
27
  DEFAULT_WORDPRESS_CORE_ABILITIES_VERSION,
@@ -34,17 +34,20 @@ import {
34
34
  } from "./cli-1sm60g1z.js";
35
35
  import {
36
36
  snapshotProjectVersion
37
- } from "./cli-prc42zqd.js";
37
+ } from "./cli-xbzfx7qz.js";
38
38
  import {
39
39
  ensureMigrationDirectories,
40
40
  parseMigrationConfig,
41
41
  writeInitialMigrationScaffold,
42
42
  writeMigrationConfig
43
- } from "./cli-gcbre1zs.js";
43
+ } from "./cli-hb9vpsev.js";
44
44
  import"./cli-bq2v559b.js";
45
45
  import {
46
- formatInstallCommand
47
- } from "./cli-sj5mtyzj.js";
46
+ findExecutablePatternMatch,
47
+ hasExecutablePattern,
48
+ hasUncommentedPattern,
49
+ maskTypeScriptCommentsAndLiterals
50
+ } from "./cli-rwjkqjhs.js";
48
51
  import"./cli-10pe4mf8.js";
49
52
  import {
50
53
  SHARED_WORKSPACE_TEMPLATE_ROOT
@@ -97,7 +100,7 @@ import {
97
100
  toPascalCase,
98
101
  toSnakeCase,
99
102
  toTitleCase
100
- } from "./cli-x0h03qqe.js";
103
+ } from "./cli-j30rk466.js";
101
104
  import {
102
105
  createManagedTempRoot
103
106
  } from "./cli-t73q5aqz.js";
@@ -107,7 +110,10 @@ import {
107
110
  } from "./cli-p95wr1q8.js";
108
111
  import {
109
112
  resolveWorkspaceProject
110
- } from "./cli-pd5pqgre.js";
113
+ } from "./cli-btbpt84c.js";
114
+ import {
115
+ formatInstallCommand
116
+ } from "./cli-6bhfzq5e.js";
111
117
  import {
112
118
  __reExport,
113
119
  __toESM
@@ -1865,6 +1871,67 @@ add_action( 'admin_enqueue_scripts', '${enqueueFunctionName}' );
1865
1871
  `;
1866
1872
  }
1867
1873
 
1874
+ // ../wp-typia-project-tools/src/runtime/cli-add-workspace-mutation.ts
1875
+ var DEFAULT_PHP_SNIPPET_INSERTION_ANCHORS = [
1876
+ /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
1877
+ /\?>\s*$/u
1878
+ ];
1879
+
1880
+ class WorkspaceMutationRollbackError extends Error {
1881
+ mutationError;
1882
+ rollbackError;
1883
+ constructor(mutationError, rollbackError) {
1884
+ super("Workspace mutation failed and rollback also failed.");
1885
+ this.name = "WorkspaceMutationRollbackError";
1886
+ this.mutationError = mutationError;
1887
+ this.rollbackError = rollbackError;
1888
+ }
1889
+ }
1890
+ async function executeWorkspaceMutationPlan({
1891
+ filePaths,
1892
+ run,
1893
+ snapshotDirs = [],
1894
+ targetPaths = []
1895
+ }) {
1896
+ const mutationSnapshot = {
1897
+ fileSources: await snapshotWorkspaceFiles(filePaths),
1898
+ snapshotDirs: [...snapshotDirs],
1899
+ targetPaths: [...targetPaths]
1900
+ };
1901
+ try {
1902
+ return await run();
1903
+ } catch (error) {
1904
+ try {
1905
+ await rollbackWorkspaceMutation(mutationSnapshot);
1906
+ } catch (rollbackError) {
1907
+ throw new WorkspaceMutationRollbackError(error, rollbackError);
1908
+ }
1909
+ throw error;
1910
+ }
1911
+ }
1912
+ function insertPhpSnippetBeforeWorkspaceAnchors(source, snippet) {
1913
+ for (const anchor of DEFAULT_PHP_SNIPPET_INSERTION_ANCHORS) {
1914
+ const candidate = source.replace(anchor, (match) => `${snippet}
1915
+ ${match}`);
1916
+ if (candidate !== source) {
1917
+ return candidate;
1918
+ }
1919
+ }
1920
+ return `${source.trimEnd()}
1921
+ ${snippet}
1922
+ `;
1923
+ }
1924
+ function appendPhpSnippetBeforeClosingTag(source, snippet) {
1925
+ const closingTagPattern = /\?>\s*$/u;
1926
+ if (closingTagPattern.test(source)) {
1927
+ return source.replace(closingTagPattern, `${snippet}
1928
+ ?>`);
1929
+ }
1930
+ return `${source.trimEnd()}
1931
+ ${snippet}
1932
+ `;
1933
+ }
1934
+
1868
1935
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view-scaffold.ts
1869
1936
  function detectJsonIndent(source) {
1870
1937
  const indentMatch = /\n([ \t]+)"/u.exec(source);
@@ -1928,36 +1995,8 @@ function ${loadFunctionName}() {
1928
1995
  }
1929
1996
  }
1930
1997
  `;
1931
- const insertionAnchors = [
1932
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
1933
- /\?>\s*$/u
1934
- ];
1935
- const insertPhpSnippet = (snippet) => {
1936
- for (const anchor of insertionAnchors) {
1937
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
1938
- ${match}`);
1939
- if (candidate !== nextSource) {
1940
- nextSource = candidate;
1941
- return;
1942
- }
1943
- }
1944
- nextSource = `${nextSource.trimEnd()}
1945
- ${snippet}
1946
- `;
1947
- };
1948
- const appendPhpSnippet = (snippet) => {
1949
- const closingTagPattern = /\?>\s*$/u;
1950
- if (closingTagPattern.test(nextSource)) {
1951
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
1952
- ?>`);
1953
- return;
1954
- }
1955
- nextSource = `${nextSource.trimEnd()}
1956
- ${snippet}
1957
- `;
1958
- };
1959
1998
  if (!hasPhpFunctionDefinition(nextSource, loadFunctionName)) {
1960
- insertPhpSnippet(loadFunction);
1999
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, loadFunction);
1961
2000
  } else {
1962
2001
  const functionRange = findPhpFunctionRange(nextSource, loadFunctionName);
1963
2002
  const functionSource = functionRange ? nextSource.slice(functionRange.start, functionRange.end) : "";
@@ -1970,7 +2009,7 @@ ${snippet}
1970
2009
  }
1971
2010
  }
1972
2011
  if (!loadHookPattern.test(nextSource)) {
1973
- appendPhpSnippet(loadHook);
2012
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, loadHook);
1974
2013
  }
1975
2014
  return nextSource;
1976
2015
  });
@@ -2093,42 +2132,38 @@ async function scaffoldAdminViewWorkspace(options) {
2093
2132
  const adminViewsIndexPath = resolveAdminViewRegistryPath(workspace.projectDir);
2094
2133
  const adminViewDir = path5.join(workspace.projectDir, "src", "admin-views", adminViewSlug);
2095
2134
  const adminViewPhpPath = path5.join(workspace.projectDir, "inc", "admin-views", `${adminViewSlug}.php`);
2096
- const mutationSnapshot = {
2097
- fileSources: await snapshotWorkspaceFiles([
2135
+ await executeWorkspaceMutationPlan({
2136
+ filePaths: [
2098
2137
  adminViewsIndexPath,
2099
2138
  blockConfigPath,
2100
2139
  bootstrapPath,
2101
2140
  buildScriptPath,
2102
2141
  packageJsonPath,
2103
2142
  webpackConfigPath
2104
- ]),
2105
- snapshotDirs: [],
2106
- targetPaths: [adminViewDir, adminViewPhpPath]
2107
- };
2108
- try {
2109
- await fsp3.mkdir(adminViewDir, { recursive: true });
2110
- await fsp3.mkdir(path5.dirname(adminViewPhpPath), { recursive: true });
2111
- await ensureAdminViewPackageDependencies(workspace, parsedSource);
2112
- await ensureAdminViewBootstrapAnchors(workspace);
2113
- await ensureAdminViewBuildScriptAnchors(workspace);
2114
- await ensureAdminViewWebpackAnchors(workspace);
2115
- await fsp3.writeFile(path5.join(adminViewDir, "types.ts"), buildAdminViewTypesSource(adminViewSlug, restResource, coreDataSource), "utf8");
2116
- await fsp3.writeFile(path5.join(adminViewDir, "config.ts"), buildAdminViewConfigSource(adminViewSlug, workspace.workspace.textDomain, parsedSource, restResource), "utf8");
2117
- await fsp3.writeFile(path5.join(adminViewDir, "data.ts"), coreDataSource ? buildCoreDataAdminViewDataSource(adminViewSlug, coreDataSource) : restResource ? buildRestAdminViewDataSource(adminViewSlug, restResource) : buildDefaultAdminViewDataSource(adminViewSlug), "utf8");
2118
- await fsp3.writeFile(path5.join(adminViewDir, "Screen.tsx"), coreDataSource ? buildCoreDataAdminViewScreenSource(adminViewSlug, workspace.workspace.textDomain) : buildAdminViewScreenSource(adminViewSlug, workspace.workspace.textDomain), "utf8");
2119
- await fsp3.writeFile(path5.join(adminViewDir, "index.tsx"), buildAdminViewEntrySource(adminViewSlug), "utf8");
2120
- await fsp3.writeFile(path5.join(adminViewDir, "style.scss"), buildAdminViewStyleSource(), "utf8");
2121
- await fsp3.writeFile(adminViewPhpPath, buildAdminViewPhpSource(adminViewSlug, workspace), "utf8");
2122
- await writeAdminViewRegistry(workspace.projectDir, adminViewSlug);
2123
- await appendWorkspaceInventoryEntries(workspace.projectDir, {
2124
- adminViewEntries: [
2125
- buildAdminViewConfigEntry(adminViewSlug, parsedSource)
2126
- ]
2127
- });
2128
- } catch (error) {
2129
- await rollbackWorkspaceMutation(mutationSnapshot);
2130
- throw error;
2131
- }
2143
+ ],
2144
+ targetPaths: [adminViewDir, adminViewPhpPath],
2145
+ run: async () => {
2146
+ await fsp3.mkdir(adminViewDir, { recursive: true });
2147
+ await fsp3.mkdir(path5.dirname(adminViewPhpPath), { recursive: true });
2148
+ await ensureAdminViewPackageDependencies(workspace, parsedSource);
2149
+ await ensureAdminViewBootstrapAnchors(workspace);
2150
+ await ensureAdminViewBuildScriptAnchors(workspace);
2151
+ await ensureAdminViewWebpackAnchors(workspace);
2152
+ await fsp3.writeFile(path5.join(adminViewDir, "types.ts"), buildAdminViewTypesSource(adminViewSlug, restResource, coreDataSource), "utf8");
2153
+ await fsp3.writeFile(path5.join(adminViewDir, "config.ts"), buildAdminViewConfigSource(adminViewSlug, workspace.workspace.textDomain, parsedSource, restResource), "utf8");
2154
+ await fsp3.writeFile(path5.join(adminViewDir, "data.ts"), coreDataSource ? buildCoreDataAdminViewDataSource(adminViewSlug, coreDataSource) : restResource ? buildRestAdminViewDataSource(adminViewSlug, restResource) : buildDefaultAdminViewDataSource(adminViewSlug), "utf8");
2155
+ await fsp3.writeFile(path5.join(adminViewDir, "Screen.tsx"), coreDataSource ? buildCoreDataAdminViewScreenSource(adminViewSlug, workspace.workspace.textDomain) : buildAdminViewScreenSource(adminViewSlug, workspace.workspace.textDomain), "utf8");
2156
+ await fsp3.writeFile(path5.join(adminViewDir, "index.tsx"), buildAdminViewEntrySource(adminViewSlug), "utf8");
2157
+ await fsp3.writeFile(path5.join(adminViewDir, "style.scss"), buildAdminViewStyleSource(), "utf8");
2158
+ await fsp3.writeFile(adminViewPhpPath, buildAdminViewPhpSource(adminViewSlug, workspace), "utf8");
2159
+ await writeAdminViewRegistry(workspace.projectDir, adminViewSlug);
2160
+ await appendWorkspaceInventoryEntries(workspace.projectDir, {
2161
+ adminViewEntries: [
2162
+ buildAdminViewConfigEntry(adminViewSlug, parsedSource)
2163
+ ]
2164
+ });
2165
+ }
2166
+ });
2132
2167
  }
2133
2168
 
2134
2169
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-admin-view.ts
@@ -2759,45 +2794,17 @@ function ${bindingEditorEnqueueFunctionName}() {
2759
2794
  );
2760
2795
  }
2761
2796
  `;
2762
- const insertionAnchors = [
2763
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
2764
- /\?>\s*$/u
2765
- ];
2766
- const insertPhpSnippet = (snippet) => {
2767
- for (const anchor of insertionAnchors) {
2768
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
2769
- ${match}`);
2770
- if (candidate !== nextSource) {
2771
- nextSource = candidate;
2772
- return;
2773
- }
2774
- }
2775
- nextSource = `${nextSource.trimEnd()}
2776
- ${snippet}
2777
- `;
2778
- };
2779
- const appendPhpSnippet = (snippet) => {
2780
- const closingTagPattern = /\?>\s*$/u;
2781
- if (closingTagPattern.test(nextSource)) {
2782
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
2783
- ?>`);
2784
- return;
2785
- }
2786
- nextSource = `${nextSource.trimEnd()}
2787
- ${snippet}
2788
- `;
2789
- };
2790
2797
  if (!hasPhpFunctionDefinition(nextSource, bindingRegistrationFunctionName)) {
2791
- insertPhpSnippet(bindingRegistrationFunction);
2798
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, bindingRegistrationFunction);
2792
2799
  }
2793
2800
  if (!hasPhpFunctionDefinition(nextSource, bindingEditorEnqueueFunctionName)) {
2794
- insertPhpSnippet(bindingEditorEnqueueFunction);
2801
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, bindingEditorEnqueueFunction);
2795
2802
  }
2796
2803
  if (!nextSource.includes(bindingRegistrationHook)) {
2797
- appendPhpSnippet(bindingRegistrationHook);
2804
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, bindingRegistrationHook);
2798
2805
  }
2799
2806
  if (!nextSource.includes(bindingEditorEnqueueHook)) {
2800
- appendPhpSnippet(bindingEditorEnqueueHook);
2807
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, bindingEditorEnqueueHook);
2801
2808
  }
2802
2809
  return nextSource;
2803
2810
  });
@@ -2847,36 +2854,8 @@ function ${enqueueFunctionName}() {
2847
2854
  }
2848
2855
  }
2849
2856
  `;
2850
- const insertionAnchors = [
2851
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
2852
- /\?>\s*$/u
2853
- ];
2854
- const insertPhpSnippet = (snippet) => {
2855
- for (const anchor of insertionAnchors) {
2856
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
2857
- ${match}`);
2858
- if (candidate !== nextSource) {
2859
- nextSource = candidate;
2860
- return;
2861
- }
2862
- }
2863
- nextSource = `${nextSource.trimEnd()}
2864
- ${snippet}
2865
- `;
2866
- };
2867
- const appendPhpSnippet = (snippet) => {
2868
- const closingTagPattern = /\?>\s*$/u;
2869
- if (closingTagPattern.test(nextSource)) {
2870
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
2871
- ?>`);
2872
- return;
2873
- }
2874
- nextSource = `${nextSource.trimEnd()}
2875
- ${snippet}
2876
- `;
2877
- };
2878
2857
  if (!hasPhpFunctionDefinition(nextSource, enqueueFunctionName)) {
2879
- insertPhpSnippet(enqueueFunction);
2858
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, enqueueFunction);
2880
2859
  } else {
2881
2860
  const requiredReferences = [
2882
2861
  EDITOR_PLUGIN_EDITOR_SCRIPT,
@@ -2897,7 +2876,7 @@ ${snippet}
2897
2876
  }
2898
2877
  }
2899
2878
  if (!nextSource.includes(enqueueHook)) {
2900
- appendPhpSnippet(enqueueHook);
2879
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, enqueueHook);
2901
2880
  }
2902
2881
  return nextSource;
2903
2882
  });
@@ -3163,36 +3142,8 @@ function ${registerFunctionName}() {
3163
3142
  }
3164
3143
  }
3165
3144
  `;
3166
- const insertionAnchors = [
3167
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
3168
- /\?>\s*$/u
3169
- ];
3170
- const insertPhpSnippet = (snippet) => {
3171
- for (const anchor of insertionAnchors) {
3172
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
3173
- ${match}`);
3174
- if (candidate !== nextSource) {
3175
- nextSource = candidate;
3176
- return;
3177
- }
3178
- }
3179
- nextSource = `${nextSource.trimEnd()}
3180
- ${snippet}
3181
- `;
3182
- };
3183
- const appendPhpSnippet = (snippet) => {
3184
- const closingTagPattern = /\?>\s*$/u;
3185
- if (closingTagPattern.test(nextSource)) {
3186
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
3187
- ?>`);
3188
- return;
3189
- }
3190
- nextSource = `${nextSource.trimEnd()}
3191
- ${snippet}
3192
- `;
3193
- };
3194
3145
  if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
3195
- insertPhpSnippet(registerFunction);
3146
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, registerFunction);
3196
3147
  } else if (!nextSource.includes(REST_RESOURCE_SERVER_GLOB)) {
3197
3148
  throw new Error([
3198
3149
  `Unable to patch ${path7.basename(bootstrapPath)} in ensureRestResourceBootstrapAnchors.`,
@@ -3201,7 +3152,7 @@ ${snippet}
3201
3152
  ].join(" "));
3202
3153
  }
3203
3154
  if (!nextSource.includes(registerHook)) {
3204
- appendPhpSnippet(registerHook);
3155
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, registerHook);
3205
3156
  }
3206
3157
  return nextSource;
3207
3158
  });
@@ -4960,50 +4911,22 @@ function ${enqueueFunctionName}() {
4960
4911
  );
4961
4912
  }
4962
4913
  `;
4963
- const insertionAnchors = [
4964
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
4965
- /\?>\s*$/u
4966
- ];
4967
- const insertPhpSnippet = (snippet) => {
4968
- for (const anchor of insertionAnchors) {
4969
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
4970
- ${match}`);
4971
- if (candidate !== nextSource) {
4972
- nextSource = candidate;
4973
- return;
4974
- }
4975
- }
4976
- nextSource = `${nextSource.trimEnd()}
4977
- ${snippet}
4978
- `;
4979
- };
4980
- const appendPhpSnippet = (snippet) => {
4981
- const closingTagPattern = /\?>\s*$/u;
4982
- if (closingTagPattern.test(nextSource)) {
4983
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
4984
- ?>`);
4985
- return;
4986
- }
4987
- nextSource = `${nextSource.trimEnd()}
4988
- ${snippet}
4989
- `;
4990
- };
4991
4914
  if (!hasPhpFunctionDefinition(nextSource, loadFunctionName)) {
4992
- insertPhpSnippet(loadFunction);
4915
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, loadFunction);
4993
4916
  }
4994
4917
  if (!hasPhpFunctionDefinition(nextSource, enqueueFunctionName)) {
4995
- insertPhpSnippet(enqueueFunction);
4918
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, enqueueFunction);
4996
4919
  } else if (!findPhpFunctionRange(nextSource, enqueueFunctionName)?.source.includes("wp_enqueue_script_module")) {
4997
4920
  nextSource = replacePhpFunctionDefinition(nextSource, enqueueFunctionName, enqueueFunction, { trimReplacementStart: true }) ?? nextSource;
4998
4921
  }
4999
4922
  if (!nextSource.includes(loadHook)) {
5000
- appendPhpSnippet(loadHook);
4923
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, loadHook);
5001
4924
  }
5002
4925
  if (!nextSource.includes(adminEnqueueHook)) {
5003
- appendPhpSnippet(adminEnqueueHook);
4926
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, adminEnqueueHook);
5004
4927
  }
5005
4928
  if (!nextSource.includes(editorEnqueueHook)) {
5006
- appendPhpSnippet(editorEnqueueHook);
4929
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, editorEnqueueHook);
5007
4930
  }
5008
4931
  return nextSource;
5009
4932
  });
@@ -5179,8 +5102,8 @@ async function scaffoldAbilityWorkspace({
5179
5102
  const dataFilePath = path10.join(abilityDir, "data.ts");
5180
5103
  const clientFilePath = path10.join(abilityDir, "client.ts");
5181
5104
  const phpFilePath = path10.join(workspace.projectDir, "inc", "abilities", `${abilitySlug}.php`);
5182
- const mutationSnapshot = {
5183
- fileSources: await snapshotWorkspaceFiles([
5105
+ await executeWorkspaceMutationPlan({
5106
+ filePaths: [
5184
5107
  blockConfigPath,
5185
5108
  bootstrapPath,
5186
5109
  buildScriptPath,
@@ -5189,48 +5112,44 @@ async function scaffoldAbilityWorkspace({
5189
5112
  syncProjectScriptPath,
5190
5113
  webpackConfigPath,
5191
5114
  abilitiesIndexPath
5192
- ]),
5193
- snapshotDirs: [],
5194
- targetPaths: [abilityDir, phpFilePath, syncAbilitiesScriptPath]
5195
- };
5196
- try {
5197
- await fsp6.mkdir(abilityDir, { recursive: true });
5198
- await fsp6.mkdir(path10.dirname(phpFilePath), { recursive: true });
5199
- await ensureAbilityBootstrapAnchors(workspace);
5200
- await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
5201
- await ensureAbilityPackageScripts(workspace);
5202
- await ensureAbilitySyncProjectAnchors(workspace);
5203
- await ensureAbilityBuildScriptAnchors(workspace);
5204
- await ensureAbilityWebpackAnchors(workspace);
5205
- await fsp6.writeFile(syncAbilitiesScriptPath, buildAbilitySyncScriptSource(), "utf8");
5206
- await fsp6.writeFile(configFilePath, buildAbilityConfigSource(abilitySlug, workspace.workspace.namespace), "utf8");
5207
- await fsp6.writeFile(typesFilePath, buildAbilityTypesSource(abilitySlug), "utf8");
5208
- await fsp6.writeFile(dataFilePath, buildAbilityDataSource(abilitySlug), "utf8");
5209
- await fsp6.writeFile(clientFilePath, buildAbilityClientSource(abilitySlug), "utf8");
5210
- await fsp6.writeFile(phpFilePath, buildAbilityPhpSource(abilitySlug, workspace), "utf8");
5211
- const pascalCase = toPascalCase(abilitySlug);
5212
- await syncTypeSchemas2({
5213
- jsonSchemaFile: `src/abilities/${abilitySlug}/input.schema.json`,
5214
- projectRoot: workspace.projectDir,
5215
- sourceTypeName: `${pascalCase}AbilityInput`,
5216
- typesFile: `src/abilities/${abilitySlug}/types.ts`
5217
- });
5218
- await syncTypeSchemas2({
5219
- jsonSchemaFile: `src/abilities/${abilitySlug}/output.schema.json`,
5220
- projectRoot: workspace.projectDir,
5221
- sourceTypeName: `${pascalCase}AbilityOutput`,
5222
- typesFile: `src/abilities/${abilitySlug}/types.ts`
5223
- });
5224
- await writeAbilityRegistry(workspace.projectDir, abilitySlug);
5225
- await appendWorkspaceInventoryEntries(workspace.projectDir, {
5226
- abilityEntries: [
5227
- buildAbilityConfigEntry(abilitySlug, compatibilityPolicy)
5228
- ]
5229
- });
5230
- } catch (error) {
5231
- await rollbackWorkspaceMutation(mutationSnapshot);
5232
- throw error;
5233
- }
5115
+ ],
5116
+ targetPaths: [abilityDir, phpFilePath, syncAbilitiesScriptPath],
5117
+ run: async () => {
5118
+ await fsp6.mkdir(abilityDir, { recursive: true });
5119
+ await fsp6.mkdir(path10.dirname(phpFilePath), { recursive: true });
5120
+ await ensureAbilityBootstrapAnchors(workspace);
5121
+ await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
5122
+ await ensureAbilityPackageScripts(workspace);
5123
+ await ensureAbilitySyncProjectAnchors(workspace);
5124
+ await ensureAbilityBuildScriptAnchors(workspace);
5125
+ await ensureAbilityWebpackAnchors(workspace);
5126
+ await fsp6.writeFile(syncAbilitiesScriptPath, buildAbilitySyncScriptSource(), "utf8");
5127
+ await fsp6.writeFile(configFilePath, buildAbilityConfigSource(abilitySlug, workspace.workspace.namespace), "utf8");
5128
+ await fsp6.writeFile(typesFilePath, buildAbilityTypesSource(abilitySlug), "utf8");
5129
+ await fsp6.writeFile(dataFilePath, buildAbilityDataSource(abilitySlug), "utf8");
5130
+ await fsp6.writeFile(clientFilePath, buildAbilityClientSource(abilitySlug), "utf8");
5131
+ await fsp6.writeFile(phpFilePath, buildAbilityPhpSource(abilitySlug, workspace), "utf8");
5132
+ const pascalCase = toPascalCase(abilitySlug);
5133
+ await syncTypeSchemas2({
5134
+ jsonSchemaFile: `src/abilities/${abilitySlug}/input.schema.json`,
5135
+ projectRoot: workspace.projectDir,
5136
+ sourceTypeName: `${pascalCase}AbilityInput`,
5137
+ typesFile: `src/abilities/${abilitySlug}/types.ts`
5138
+ });
5139
+ await syncTypeSchemas2({
5140
+ jsonSchemaFile: `src/abilities/${abilitySlug}/output.schema.json`,
5141
+ projectRoot: workspace.projectDir,
5142
+ sourceTypeName: `${pascalCase}AbilityOutput`,
5143
+ typesFile: `src/abilities/${abilitySlug}/types.ts`
5144
+ });
5145
+ await writeAbilityRegistry(workspace.projectDir, abilitySlug);
5146
+ await appendWorkspaceInventoryEntries(workspace.projectDir, {
5147
+ abilityEntries: [
5148
+ buildAbilityConfigEntry(abilitySlug, compatibilityPolicy)
5149
+ ]
5150
+ });
5151
+ }
5152
+ });
5234
5153
  }
5235
5154
 
5236
5155
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-ability.ts
@@ -5854,36 +5773,8 @@ function ${registerFunctionName}() {
5854
5773
  }
5855
5774
  }
5856
5775
  `;
5857
- const insertionAnchors = [
5858
- /add_action\(\s*["']init["']\s*,\s*["'][^"']+_load_textdomain["']\s*\);\s*\n/u,
5859
- /\?>\s*$/u
5860
- ];
5861
- const insertPhpSnippet = (snippet) => {
5862
- for (const anchor of insertionAnchors) {
5863
- const candidate = nextSource.replace(anchor, (match) => `${snippet}
5864
- ${match}`);
5865
- if (candidate !== nextSource) {
5866
- nextSource = candidate;
5867
- return;
5868
- }
5869
- }
5870
- nextSource = `${nextSource.trimEnd()}
5871
- ${snippet}
5872
- `;
5873
- };
5874
- const appendPhpSnippet = (snippet) => {
5875
- const closingTagPattern = /\?>\s*$/u;
5876
- if (closingTagPattern.test(nextSource)) {
5877
- nextSource = nextSource.replace(closingTagPattern, `${snippet}
5878
- ?>`);
5879
- return;
5880
- }
5881
- nextSource = `${nextSource.trimEnd()}
5882
- ${snippet}
5883
- `;
5884
- };
5885
5776
  if (!hasPhpFunctionDefinition(nextSource, registerFunctionName)) {
5886
- insertPhpSnippet(registerFunction);
5777
+ nextSource = insertPhpSnippetBeforeWorkspaceAnchors(nextSource, registerFunction);
5887
5778
  } else if (!nextSource.includes(AI_FEATURE_SERVER_GLOB)) {
5888
5779
  throw new Error([
5889
5780
  `Unable to patch ${path12.basename(bootstrapPath)} in ensureAiFeatureBootstrapAnchors.`,
@@ -5892,7 +5783,7 @@ ${snippet}
5892
5783
  ].join(" "));
5893
5784
  }
5894
5785
  if (!nextSource.includes(registerHook)) {
5895
- appendPhpSnippet(registerHook);
5786
+ nextSource = appendPhpSnippetBeforeClosingTag(nextSource, registerHook);
5896
5787
  }
5897
5788
  return nextSource;
5898
5789
  });
@@ -6151,6 +6042,8 @@ if ( ! defined( 'ABSPATH' ) ) {
6151
6042
  * - ${quotePhpString(adminNoticeMessageFilterHook)} filters the wp-admin notice shown when AI support is unavailable.
6152
6043
  * - ${quotePhpString(unavailableMessageFilterHook)} filters REST-facing unavailable messages by reason code.
6153
6044
  * - ${quotePhpString(telemetryFilterHook)} filters the response telemetry array before schema validation. Return a schema-compatible array.
6045
+ *
6046
+ * Compatibility note: this server-only endpoint avoids WordPress script-module enqueue APIs so older sites can load the generated feature file safely.
6154
6047
  */
6155
6048
 
6156
6049
  if ( ! function_exists( '${loadSchemaFunctionName}' ) ) {
@@ -6731,66 +6624,62 @@ async function scaffoldAiFeatureWorkspace({
6731
6624
  const apiFilePath = path13.join(aiFeatureDir, "api.ts");
6732
6625
  const dataFilePath = path13.join(aiFeatureDir, "data.ts");
6733
6626
  const phpFilePath = path13.join(workspace.projectDir, "inc", "ai-features", `${aiFeatureSlug}.php`);
6734
- const mutationSnapshot = {
6735
- fileSources: await snapshotWorkspaceFiles([
6627
+ return executeWorkspaceMutationPlan({
6628
+ filePaths: [
6736
6629
  blockConfigPath,
6737
6630
  bootstrapPath,
6738
6631
  packageJsonPath,
6739
6632
  syncAiScriptPath,
6740
6633
  syncProjectScriptPath,
6741
6634
  syncRestScriptPath
6742
- ]),
6743
- snapshotDirs: [],
6744
- targetPaths: [aiFeatureDir, phpFilePath, syncAiScriptPath]
6745
- };
6746
- try {
6747
- await fsp8.mkdir(aiFeatureDir, { recursive: true });
6748
- await fsp8.mkdir(path13.dirname(phpFilePath), { recursive: true });
6749
- await ensureAiFeatureBootstrapAnchors(workspace);
6750
- await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
6751
- const packageScriptChanges = await ensureAiFeaturePackageScripts(workspace);
6752
- await ensureAiFeatureSyncProjectAnchors(workspace);
6753
- await ensureAiFeatureSyncRestAnchors(workspace);
6754
- await fsp8.writeFile(syncAiScriptPath, buildAiFeatureSyncScriptSource(), "utf8");
6755
- await fsp8.writeFile(typesFilePath, buildAiFeatureTypesSource(aiFeatureSlug), "utf8");
6756
- await fsp8.writeFile(validatorsFilePath, buildAiFeatureValidatorsSource(aiFeatureSlug), "utf8");
6757
- await fsp8.writeFile(apiFilePath, buildAiFeatureApiSource(aiFeatureSlug), "utf8");
6758
- await fsp8.writeFile(dataFilePath, buildAiFeatureDataSource(aiFeatureSlug), "utf8");
6759
- await fsp8.writeFile(phpFilePath, buildAiFeaturePhpSource(aiFeatureSlug, namespace, workspace.workspace.phpPrefix, workspace.workspace.textDomain), "utf8");
6760
- const pascalCase = toPascalCase(aiFeatureSlug);
6761
- await syncAiFeatureRestArtifacts({
6762
- clientFile: `src/ai-features/${aiFeatureSlug}/api-client.ts`,
6763
- outputDir: path13.join("src", "ai-features", aiFeatureSlug),
6764
- projectDir: workspace.projectDir,
6765
- typesFile: `src/ai-features/${aiFeatureSlug}/api-types.ts`,
6766
- validatorsFile: `src/ai-features/${aiFeatureSlug}/api-validators.ts`,
6767
- variables: {
6768
- namespace,
6769
- pascalCase,
6770
- slugKebabCase: aiFeatureSlug,
6771
- title: toTitleCase(aiFeatureSlug)
6772
- }
6773
- });
6774
- await syncAiFeatureSchemaArtifact({
6775
- aiSchemaFile: `src/ai-features/${aiFeatureSlug}/ai-schemas/feature-result.ai.schema.json`,
6776
- outputDir: path13.join("src", "ai-features", aiFeatureSlug),
6777
- projectDir: workspace.projectDir
6778
- });
6779
- await appendWorkspaceInventoryEntries(workspace.projectDir, {
6780
- aiFeatureEntries: [
6781
- buildAiFeatureConfigEntry(aiFeatureSlug, namespace)
6782
- ],
6783
- transformSource: ensureBlockConfigCanAddRestManifests
6784
- });
6785
- return {
6786
- warnings: packageScriptChanges.addedProjectToolsDependency ? [
6787
- "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`."
6788
- ] : []
6789
- };
6790
- } catch (error) {
6791
- await rollbackWorkspaceMutation(mutationSnapshot);
6792
- throw error;
6793
- }
6635
+ ],
6636
+ targetPaths: [aiFeatureDir, phpFilePath, syncAiScriptPath],
6637
+ run: async () => {
6638
+ await fsp8.mkdir(aiFeatureDir, { recursive: true });
6639
+ await fsp8.mkdir(path13.dirname(phpFilePath), { recursive: true });
6640
+ await ensureAiFeatureBootstrapAnchors(workspace);
6641
+ await patchFile(bootstrapPath, (source) => updatePluginHeaderCompatibility(source, compatibilityPolicy));
6642
+ const packageScriptChanges = await ensureAiFeaturePackageScripts(workspace);
6643
+ await ensureAiFeatureSyncProjectAnchors(workspace);
6644
+ await ensureAiFeatureSyncRestAnchors(workspace);
6645
+ await fsp8.writeFile(syncAiScriptPath, buildAiFeatureSyncScriptSource(), "utf8");
6646
+ await fsp8.writeFile(typesFilePath, buildAiFeatureTypesSource(aiFeatureSlug), "utf8");
6647
+ await fsp8.writeFile(validatorsFilePath, buildAiFeatureValidatorsSource(aiFeatureSlug), "utf8");
6648
+ await fsp8.writeFile(apiFilePath, buildAiFeatureApiSource(aiFeatureSlug), "utf8");
6649
+ await fsp8.writeFile(dataFilePath, buildAiFeatureDataSource(aiFeatureSlug), "utf8");
6650
+ await fsp8.writeFile(phpFilePath, buildAiFeaturePhpSource(aiFeatureSlug, namespace, workspace.workspace.phpPrefix, workspace.workspace.textDomain), "utf8");
6651
+ const pascalCase = toPascalCase(aiFeatureSlug);
6652
+ await syncAiFeatureRestArtifacts({
6653
+ clientFile: `src/ai-features/${aiFeatureSlug}/api-client.ts`,
6654
+ outputDir: path13.join("src", "ai-features", aiFeatureSlug),
6655
+ projectDir: workspace.projectDir,
6656
+ typesFile: `src/ai-features/${aiFeatureSlug}/api-types.ts`,
6657
+ validatorsFile: `src/ai-features/${aiFeatureSlug}/api-validators.ts`,
6658
+ variables: {
6659
+ namespace,
6660
+ pascalCase,
6661
+ slugKebabCase: aiFeatureSlug,
6662
+ title: toTitleCase(aiFeatureSlug)
6663
+ }
6664
+ });
6665
+ await syncAiFeatureSchemaArtifact({
6666
+ aiSchemaFile: `src/ai-features/${aiFeatureSlug}/ai-schemas/feature-result.ai.schema.json`,
6667
+ outputDir: path13.join("src", "ai-features", aiFeatureSlug),
6668
+ projectDir: workspace.projectDir
6669
+ });
6670
+ await appendWorkspaceInventoryEntries(workspace.projectDir, {
6671
+ aiFeatureEntries: [
6672
+ buildAiFeatureConfigEntry(aiFeatureSlug, namespace)
6673
+ ],
6674
+ transformSource: ensureBlockConfigCanAddRestManifests
6675
+ });
6676
+ return {
6677
+ warnings: packageScriptChanges.addedProjectToolsDependency ? [
6678
+ "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`."
6679
+ ] : []
6680
+ };
6681
+ }
6682
+ });
6794
6683
  }
6795
6684
 
6796
6685
  // ../wp-typia-project-tools/src/runtime/cli-add-workspace-ai.ts
@@ -6834,80 +6723,6 @@ var BLOCK_TRANSFORMS_CALL_LINE = "applyWorkspaceBlockTransforms(registration.set
6834
6723
  var BLOCK_TRANSFORMS_CALL_PATTERN = /applyWorkspaceBlockTransforms\s*\(\s*registration\s*\.\s*settings\s*\)\s*;?/u;
6835
6724
  var SCAFFOLD_REGISTRATION_SETTINGS_CALL_PATTERN = /registerScaffoldBlockType\s*\(\s*registration\s*\.\s*name\s*,\s*registration\s*\.\s*settings\s*\)\s*;?/u;
6836
6725
  var FULL_BLOCK_NAME_PATTERN = /^[a-z0-9-]+\/[a-z0-9-]+$/u;
6837
- function maskSourceSegment(segment) {
6838
- return segment.replace(/[^\n\r]/gu, " ");
6839
- }
6840
- function maskTypeScriptComments(source) {
6841
- return source.replace(/\/\*[\s\S]*?\*\//gu, maskSourceSegment).replace(/\/\/[^\n\r]*/gu, maskSourceSegment);
6842
- }
6843
- function maskTypeScriptCommentsAndLiterals(source) {
6844
- let maskedSource = "";
6845
- let index = 0;
6846
- while (index < source.length) {
6847
- const current = source[index];
6848
- const next = source[index + 1];
6849
- if (current === "/" && next === "/") {
6850
- const start = index;
6851
- index += 2;
6852
- while (index < source.length && source[index] !== `
6853
- ` && source[index] !== "\r") {
6854
- index += 1;
6855
- }
6856
- maskedSource += maskSourceSegment(source.slice(start, index));
6857
- continue;
6858
- }
6859
- if (current === "/" && next === "*") {
6860
- const start = index;
6861
- index += 2;
6862
- while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) {
6863
- index += 1;
6864
- }
6865
- index = Math.min(index + 2, source.length);
6866
- maskedSource += maskSourceSegment(source.slice(start, index));
6867
- continue;
6868
- }
6869
- if (current === "'" || current === '"' || current === "`") {
6870
- const start = index;
6871
- const quote = current;
6872
- index += 1;
6873
- while (index < source.length) {
6874
- const char = source[index];
6875
- if (char === "\\") {
6876
- index += 2;
6877
- continue;
6878
- }
6879
- index += 1;
6880
- if (char === quote) {
6881
- break;
6882
- }
6883
- }
6884
- maskedSource += maskSourceSegment(source.slice(start, index));
6885
- continue;
6886
- }
6887
- maskedSource += current;
6888
- index += 1;
6889
- }
6890
- return maskedSource;
6891
- }
6892
- function hasExecutablePattern(source, pattern) {
6893
- return pattern.test(maskTypeScriptCommentsAndLiterals(source));
6894
- }
6895
- function hasUncommentedPattern(source, pattern) {
6896
- return pattern.test(maskTypeScriptComments(source));
6897
- }
6898
- function findExecutablePatternMatch(source, patterns) {
6899
- const maskedSource = maskTypeScriptCommentsAndLiterals(source);
6900
- for (const pattern of patterns) {
6901
- const match = pattern.exec(maskedSource);
6902
- if (match && match.index !== undefined) {
6903
- return {
6904
- end: match.index + match[0].length,
6905
- start: match.index
6906
- };
6907
- }
6908
- }
6909
- return;
6910
- }
6911
6726
  function isIdentifierBoundary(source, index) {
6912
6727
  if (index < 0 || index >= source.length) {
6913
6728
  return true;
@@ -7540,6 +7355,7 @@ export {
7540
7355
  runAddAiFeatureCommand,
7541
7356
  runAddAdminViewCommand,
7542
7357
  runAddAbilityCommand,
7358
+ isAddBlockTemplateId,
7543
7359
  getWorkspaceBlockSelectOptions,
7544
7360
  formatAddHelpText,
7545
7361
  EDITOR_PLUGIN_SLOT_IDS,
@@ -7547,4 +7363,4 @@ export {
7547
7363
  ADD_BLOCK_TEMPLATE_IDS
7548
7364
  };
7549
7365
 
7550
- //# debugId=272EBA8B7C96349F64756E2164756E21
7366
+ //# debugId=BE460360B35E3C8864756E2164756E21