@wp-typia/project-tools 0.22.0 → 0.22.1

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.
@@ -24,6 +24,21 @@ export declare const DEFAULT_WORDPRESS_CORE_DATA_VERSION = "^7.44.0";
24
24
  export declare const DEFAULT_WORDPRESS_DATA_VERSION = "^9.28.0";
25
25
  export declare const DEFAULT_WORDPRESS_DATAVIEWS_VERSION = "^14.1.0";
26
26
  export declare const DEFAULT_WP_TYPIA_DATAVIEWS_VERSION = "^0.1.0";
27
+ /**
28
+ * Resolve a managed package version range from linked workspace packages first,
29
+ * then installed package manifests, while preserving the shared normalization
30
+ * and manifest fingerprinting rules used by `getPackageVersions()`.
31
+ *
32
+ * @param packageName npm package whose manifest version should be consulted.
33
+ * @param fallback Canonical range to use when no usable manifest version exists.
34
+ * @param workspacePackageDirName Optional sibling monorepo package directory name.
35
+ * @returns A normalized semver range suitable for generated dependency entries.
36
+ */
37
+ export declare function resolveManagedPackageVersionRange(options: {
38
+ fallback: string;
39
+ packageName: string;
40
+ workspacePackageDirName?: string;
41
+ }): string;
27
42
  /**
28
43
  * Clears the in-memory cache used by `getPackageVersions()`.
29
44
  *
@@ -1,12 +1,12 @@
1
- import fs from "node:fs";
2
- import { createRequire } from "node:module";
3
- import path from "node:path";
4
- import { PROJECT_TOOLS_PACKAGE_ROOT } from "./template-registry.js";
1
+ import fs from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import path from 'node:path';
4
+ import { PROJECT_TOOLS_PACKAGE_ROOT } from './template-registry.js';
5
5
  const require = createRequire(import.meta.url);
6
- const DEFAULT_VERSION_RANGE = "^0.0.0";
7
- const DEFAULT_EXACT_VERSION = "0.0.0";
8
- const DEFAULT_TSX_PACKAGE_VERSION = "^4.20.5";
9
- const DEFAULT_TYPIA_UNPLUGIN_PACKAGE_VERSION = "^12.0.1";
6
+ const DEFAULT_VERSION_RANGE = '^0.0.0';
7
+ const DEFAULT_EXACT_VERSION = '0.0.0';
8
+ const DEFAULT_TSX_PACKAGE_VERSION = '^4.20.5';
9
+ const DEFAULT_TYPIA_UNPLUGIN_PACKAGE_VERSION = '^12.0.1';
10
10
  /**
11
11
  * Explicit fallback ranges for managed WordPress-facing workspace dependencies.
12
12
  *
@@ -14,15 +14,15 @@ const DEFAULT_TYPIA_UNPLUGIN_PACKAGE_VERSION = "^12.0.1";
14
14
  * fresher local or installed manifest version first, so add-command defaults do
15
15
  * not drift across runtime modules.
16
16
  */
17
- export const DEFAULT_WORDPRESS_ABILITIES_VERSION = "^0.10.0";
18
- export const DEFAULT_WORDPRESS_CORE_ABILITIES_VERSION = "^0.9.0";
19
- export const DEFAULT_WORDPRESS_CORE_DATA_VERSION = "^7.44.0";
20
- export const DEFAULT_WORDPRESS_DATA_VERSION = "^9.28.0";
21
- export const DEFAULT_WORDPRESS_DATAVIEWS_VERSION = "^14.1.0";
22
- export const DEFAULT_WP_TYPIA_DATAVIEWS_VERSION = "^0.1.0";
17
+ export const DEFAULT_WORDPRESS_ABILITIES_VERSION = '^0.10.0';
18
+ export const DEFAULT_WORDPRESS_CORE_ABILITIES_VERSION = '^0.9.0';
19
+ export const DEFAULT_WORDPRESS_CORE_DATA_VERSION = '^7.44.0';
20
+ export const DEFAULT_WORDPRESS_DATA_VERSION = '^9.28.0';
21
+ export const DEFAULT_WORDPRESS_DATAVIEWS_VERSION = '^14.1.0';
22
+ export const DEFAULT_WP_TYPIA_DATAVIEWS_VERSION = '^0.1.0';
23
23
  let cachedPackageVersions = null;
24
24
  function getErrorCode(error) {
25
- return typeof error === "object" && error !== null && "code" in error
25
+ return typeof error === 'object' && error !== null && 'code' in error
26
26
  ? String(error.code)
27
27
  : undefined;
28
28
  }
@@ -31,7 +31,7 @@ function normalizeVersionRange(value) {
31
31
  if (!trimmed) {
32
32
  return DEFAULT_VERSION_RANGE;
33
33
  }
34
- if (trimmed.startsWith("workspace:")) {
34
+ if (trimmed.startsWith('workspace:')) {
35
35
  return DEFAULT_VERSION_RANGE;
36
36
  }
37
37
  return /^[~^<>=]/.test(trimmed) ? trimmed : `^${trimmed}`;
@@ -41,10 +41,10 @@ function normalizeExactVersion(value) {
41
41
  if (!trimmed) {
42
42
  return DEFAULT_EXACT_VERSION;
43
43
  }
44
- if (trimmed.startsWith("workspace:")) {
44
+ if (trimmed.startsWith('workspace:')) {
45
45
  return DEFAULT_EXACT_VERSION;
46
46
  }
47
- return trimmed.replace(/^[~^<>=]+/, "");
47
+ return trimmed.replace(/^[~^<>=]+/, '');
48
48
  }
49
49
  function normalizeVersionRangeWithFallback(value, fallback) {
50
50
  const normalized = normalizeVersionRange(value);
@@ -61,7 +61,7 @@ function createContentFingerprint(source) {
61
61
  function resolvePackageManifestLocation(packageJsonPath) {
62
62
  try {
63
63
  const stats = fs.statSync(packageJsonPath);
64
- const source = fs.readFileSync(packageJsonPath, "utf8");
64
+ const source = fs.readFileSync(packageJsonPath, 'utf8');
65
65
  return {
66
66
  cacheKey: `file:${packageJsonPath}:${stats.ino}:${stats.mtimeMs}:${stats.ctimeMs}:${stats.size}:${createContentFingerprint(source)}`,
67
67
  packageJsonPath,
@@ -69,7 +69,7 @@ function resolvePackageManifestLocation(packageJsonPath) {
69
69
  };
70
70
  }
71
71
  catch (error) {
72
- if (getErrorCode(error) === "ENOENT") {
72
+ if (getErrorCode(error) === 'ENOENT') {
73
73
  return {
74
74
  cacheKey: `missing-file:${packageJsonPath}`,
75
75
  packageJsonPath: null,
@@ -85,12 +85,23 @@ function readPackageManifest(location) {
85
85
  }
86
86
  return JSON.parse(location.source);
87
87
  }
88
+ function tryReadPackageManifest(location) {
89
+ if (!location) {
90
+ return null;
91
+ }
92
+ try {
93
+ return readPackageManifest(location);
94
+ }
95
+ catch {
96
+ return null;
97
+ }
98
+ }
88
99
  function resolveInstalledPackageManifestLocation(packageName) {
89
100
  try {
90
101
  return resolvePackageManifestLocation(require.resolve(`${packageName}/package.json`));
91
102
  }
92
103
  catch (error) {
93
- if (getErrorCode(error) === "MODULE_NOT_FOUND") {
104
+ if (getErrorCode(error) === 'MODULE_NOT_FOUND') {
94
105
  return {
95
106
  cacheKey: `missing-module:${packageName}`,
96
107
  packageJsonPath: null,
@@ -101,7 +112,26 @@ function resolveInstalledPackageManifestLocation(packageName) {
101
112
  }
102
113
  }
103
114
  function composePackageVersionsCacheKey(locations) {
104
- return locations.map((location) => location.cacheKey).join("|");
115
+ return locations.map((location) => location.cacheKey).join('|');
116
+ }
117
+ /**
118
+ * Resolve a managed package version range from linked workspace packages first,
119
+ * then installed package manifests, while preserving the shared normalization
120
+ * and manifest fingerprinting rules used by `getPackageVersions()`.
121
+ *
122
+ * @param packageName npm package whose manifest version should be consulted.
123
+ * @param fallback Canonical range to use when no usable manifest version exists.
124
+ * @param workspacePackageDirName Optional sibling monorepo package directory name.
125
+ * @returns A normalized semver range suitable for generated dependency entries.
126
+ */
127
+ export function resolveManagedPackageVersionRange(options) {
128
+ const workspaceManifestLocation = options.workspacePackageDirName
129
+ ? resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, '..', options.workspacePackageDirName, 'package.json'))
130
+ : null;
131
+ const installedManifestLocation = resolveInstalledPackageManifestLocation(options.packageName);
132
+ const workspaceManifest = tryReadPackageManifest(workspaceManifestLocation);
133
+ const installedManifest = tryReadPackageManifest(installedManifestLocation);
134
+ return normalizeVersionRangeWithFallback(workspaceManifest?.version ?? installedManifest?.version, options.fallback);
105
135
  }
106
136
  /**
107
137
  * Clears the in-memory cache used by `getPackageVersions()`.
@@ -128,20 +158,20 @@ export function invalidatePackageVersionsCache() {
128
158
  * disk, the cache key changes and the returned version object is refreshed.
129
159
  */
130
160
  export function getPackageVersions() {
131
- const createManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, "package.json"));
132
- const monorepoManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, "..", "..", "package.json"));
133
- const blockRuntimeManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, "..", "wp-typia-block-runtime", "package.json"));
134
- const wpTypiaManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, "..", "wp-typia", "package.json"));
135
- const installedProjectToolsManifestLocation = resolveInstalledPackageManifestLocation("@wp-typia/project-tools");
136
- const installedApiClientManifestLocation = resolveInstalledPackageManifestLocation("@wp-typia/api-client");
137
- const installedBlockRuntimeManifestLocation = resolveInstalledPackageManifestLocation("@wp-typia/block-runtime");
138
- const installedBlockTypesManifestLocation = resolveInstalledPackageManifestLocation("@wp-typia/block-types");
139
- const installedRestManifestLocation = resolveInstalledPackageManifestLocation("@wp-typia/rest");
140
- const installedTsxManifestLocation = resolveInstalledPackageManifestLocation("tsx");
141
- const installedTypiaManifestLocation = resolveInstalledPackageManifestLocation("typia");
142
- const installedTypiaUnpluginManifestLocation = resolveInstalledPackageManifestLocation("@typia/unplugin");
143
- const installedTypescriptManifestLocation = resolveInstalledPackageManifestLocation("typescript");
144
- const installedWpTypiaManifestLocation = resolveInstalledPackageManifestLocation("wp-typia");
161
+ const createManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, 'package.json'));
162
+ const monorepoManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, '..', '..', 'package.json'));
163
+ const blockRuntimeManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, '..', 'wp-typia-block-runtime', 'package.json'));
164
+ const wpTypiaManifestLocation = resolvePackageManifestLocation(path.join(PROJECT_TOOLS_PACKAGE_ROOT, '..', 'wp-typia', 'package.json'));
165
+ const installedProjectToolsManifestLocation = resolveInstalledPackageManifestLocation('@wp-typia/project-tools');
166
+ const installedApiClientManifestLocation = resolveInstalledPackageManifestLocation('@wp-typia/api-client');
167
+ const installedBlockRuntimeManifestLocation = resolveInstalledPackageManifestLocation('@wp-typia/block-runtime');
168
+ const installedBlockTypesManifestLocation = resolveInstalledPackageManifestLocation('@wp-typia/block-types');
169
+ const installedRestManifestLocation = resolveInstalledPackageManifestLocation('@wp-typia/rest');
170
+ const installedTsxManifestLocation = resolveInstalledPackageManifestLocation('tsx');
171
+ const installedTypiaManifestLocation = resolveInstalledPackageManifestLocation('typia');
172
+ const installedTypiaUnpluginManifestLocation = resolveInstalledPackageManifestLocation('@typia/unplugin');
173
+ const installedTypescriptManifestLocation = resolveInstalledPackageManifestLocation('typescript');
174
+ const installedWpTypiaManifestLocation = resolveInstalledPackageManifestLocation('wp-typia');
145
175
  const cacheKey = composePackageVersionsCacheKey([
146
176
  createManifestLocation,
147
177
  monorepoManifestLocation,
@@ -171,17 +201,17 @@ export function getPackageVersions() {
171
201
  const wpTypiaManifest = readPackageManifest(wpTypiaManifestLocation) ??
172
202
  readPackageManifest(installedWpTypiaManifestLocation) ??
173
203
  {};
174
- const blockRuntimeDependencyVersion = normalizeVersionRange(createManifest.dependencies?.["@wp-typia/block-runtime"]);
204
+ const blockRuntimeDependencyVersion = normalizeVersionRange(createManifest.dependencies?.['@wp-typia/block-runtime']);
175
205
  const versions = {
176
- apiClientPackageVersion: normalizeVersionRange(createManifest.dependencies?.["@wp-typia/api-client"] ??
206
+ apiClientPackageVersion: normalizeVersionRange(createManifest.dependencies?.['@wp-typia/api-client'] ??
177
207
  readPackageManifest(installedApiClientManifestLocation)?.version),
178
208
  blockRuntimePackageVersion: blockRuntimeDependencyVersion !== DEFAULT_VERSION_RANGE
179
209
  ? blockRuntimeDependencyVersion
180
210
  : normalizeVersionRange(blockRuntimeManifest.version),
181
- blockTypesPackageVersion: normalizeVersionRange(createManifest.dependencies?.["@wp-typia/block-types"] ??
211
+ blockTypesPackageVersion: normalizeVersionRange(createManifest.dependencies?.['@wp-typia/block-types'] ??
182
212
  readPackageManifest(installedBlockTypesManifestLocation)?.version),
183
213
  projectToolsPackageVersion: normalizeVersionRange(createManifest.version),
184
- restPackageVersion: normalizeVersionRange(createManifest.dependencies?.["@wp-typia/rest"] ??
214
+ restPackageVersion: normalizeVersionRange(createManifest.dependencies?.['@wp-typia/rest'] ??
185
215
  readPackageManifest(installedRestManifestLocation)?.version),
186
216
  tsxPackageVersion: normalizeVersionRangeWithFallback(monorepoManifest.dependencies?.tsx ??
187
217
  monorepoManifest.devDependencies?.tsx ??
@@ -190,8 +220,8 @@ export function getPackageVersions() {
190
220
  monorepoManifest.devDependencies?.typia ??
191
221
  createManifest.dependencies?.typia ??
192
222
  readPackageManifest(installedTypiaManifestLocation)?.version, DEFAULT_VERSION_RANGE),
193
- typiaUnpluginPackageVersion: normalizeVersionRangeWithFallback(monorepoManifest.dependencies?.["@typia/unplugin"] ??
194
- monorepoManifest.devDependencies?.["@typia/unplugin"] ??
223
+ typiaUnpluginPackageVersion: normalizeVersionRangeWithFallback(monorepoManifest.dependencies?.['@typia/unplugin'] ??
224
+ monorepoManifest.devDependencies?.['@typia/unplugin'] ??
195
225
  readPackageManifest(installedTypiaUnpluginManifestLocation)?.version, DEFAULT_TYPIA_UNPLUGIN_PACKAGE_VERSION),
196
226
  typescriptPackageVersion: normalizeVersionRangeWithFallback(monorepoManifest.dependencies?.typescript ??
197
227
  monorepoManifest.devDependencies?.typescript ??
@@ -19,6 +19,13 @@ export declare function toSnakeCase(input: string): string;
19
19
  * @returns A PascalCase string derived from the normalized kebab-case form.
20
20
  */
21
21
  export declare function toPascalCase(input: string): string;
22
+ /**
23
+ * Normalize arbitrary text into a camelCase identifier.
24
+ *
25
+ * @param input Raw text that may contain spaces, punctuation, or camelCase.
26
+ * @returns A camelCase string derived from the normalized PascalCase form.
27
+ */
28
+ export declare function toCamelCase(input: string): string;
22
29
  /**
23
30
  * Convert delimited text to PascalCase while preserving each segment's
24
31
  * existing internal casing.
@@ -10,10 +10,10 @@ function capitalizeSegment(segment) {
10
10
  export function toKebabCase(input) {
11
11
  return input
12
12
  .trim()
13
- .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
14
- .replace(/[^A-Za-z0-9]+/g, "-")
15
- .replace(/^-+|-+$/g, "")
16
- .replace(/-{2,}/g, "-")
13
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
14
+ .replace(/[^A-Za-z0-9]+/g, '-')
15
+ .replace(/^-+|-+$/g, '')
16
+ .replace(/-{2,}/g, '-')
17
17
  .toLowerCase();
18
18
  }
19
19
  /**
@@ -23,7 +23,7 @@ export function toKebabCase(input) {
23
23
  * @returns A lowercase snake_case string derived from the kebab-case form.
24
24
  */
25
25
  export function toSnakeCase(input) {
26
- return toKebabCase(input).replace(/-/g, "_");
26
+ return toKebabCase(input).replace(/-/g, '_');
27
27
  }
28
28
  /**
29
29
  * Normalize arbitrary text into a PascalCase identifier.
@@ -33,10 +33,20 @@ export function toSnakeCase(input) {
33
33
  */
34
34
  export function toPascalCase(input) {
35
35
  return toKebabCase(input)
36
- .split("-")
36
+ .split('-')
37
37
  .filter(Boolean)
38
38
  .map(capitalizeSegment)
39
- .join("");
39
+ .join('');
40
+ }
41
+ /**
42
+ * Normalize arbitrary text into a camelCase identifier.
43
+ *
44
+ * @param input Raw text that may contain spaces, punctuation, or camelCase.
45
+ * @returns A camelCase string derived from the normalized PascalCase form.
46
+ */
47
+ export function toCamelCase(input) {
48
+ const pascalCase = toPascalCase(input);
49
+ return `${pascalCase.charAt(0).toLowerCase()}${pascalCase.slice(1)}`;
40
50
  }
41
51
  /**
42
52
  * Convert delimited text to PascalCase while preserving each segment's
@@ -47,12 +57,12 @@ export function toPascalCase(input) {
47
57
  */
48
58
  export function toSegmentPascalCase(input) {
49
59
  return input
50
- .replace(/[^A-Za-z0-9]+/g, " ")
60
+ .replace(/[^A-Za-z0-9]+/g, ' ')
51
61
  .trim()
52
62
  .split(/\s+/)
53
63
  .filter(Boolean)
54
64
  .map(capitalizeSegment)
55
- .join("");
65
+ .join('');
56
66
  }
57
67
  /**
58
68
  * Normalize arbitrary text into a human-readable title.
@@ -62,8 +72,8 @@ export function toSegmentPascalCase(input) {
62
72
  */
63
73
  export function toTitleCase(input) {
64
74
  return toKebabCase(input)
65
- .split("-")
75
+ .split('-')
66
76
  .filter(Boolean)
67
77
  .map(capitalizeSegment)
68
- .join(" ");
78
+ .join(' ');
69
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-typia/project-tools",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "description": "Project orchestration and programmatic tooling for wp-typia",
5
5
  "packageManager": "bun@1.3.11",
6
6
  "type": "module",