wp-typia 0.22.3 → 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.
@@ -45,20 +45,20 @@ import {
45
45
  setValueAtPath,
46
46
  writeInitialMigrationScaffold,
47
47
  writeMigrationConfig
48
- } from "./cli-gcbre1zs.js";
48
+ } from "./cli-hb9vpsev.js";
49
49
  import {
50
50
  createReadlinePrompt
51
51
  } from "./cli-bq2v559b.js";
52
- import {
53
- formatRunScript
54
- } from "./cli-sj5mtyzj.js";
55
52
  import {
56
53
  readWorkspaceInventory
57
- } from "./cli-x0h03qqe.js";
54
+ } from "./cli-qr2ek735.js";
58
55
  import {
59
56
  getInvalidWorkspaceProjectReason,
60
57
  tryResolveWorkspaceProject
61
- } from "./cli-pd5pqgre.js";
58
+ } from "./cli-btbpt84c.js";
59
+ import {
60
+ formatRunScript
61
+ } from "./cli-6bhfzq5e.js";
62
62
 
63
63
  // ../wp-typia-project-tools/src/runtime/migrations.ts
64
64
  import fs8 from "fs";
@@ -2603,4 +2603,4 @@ function seedProjectMigrations(projectDir, currentMigrationVersion, blocks, { re
2603
2603
 
2604
2604
  export { formatMigrationHelpText, parseMigrationArgs, formatDiffReport, verifyProjectMigrations, doctorProjectMigrations, fixturesProjectMigrations, fuzzProjectMigrations, runMigrationCommand, planProjectMigrations, wizardProjectMigrations, initProjectMigrations, snapshotProjectVersion, diffProjectMigrations, scaffoldProjectMigrations, seedProjectMigrations };
2605
2605
 
2606
- //# debugId=BC365CDF987C339064756E2164756E21
2606
+ //# debugId=BE1EB867745EABB564756E2164756E21
@@ -1,5 +1,7 @@
1
1
  // @bun
2
2
  // ../wp-typia-project-tools/src/runtime/package-managers.ts
3
+ import fs from "fs";
4
+ import path from "path";
3
5
  var PACKAGE_MANAGER_DATA = [
4
6
  {
5
7
  id: "bun",
@@ -30,6 +32,15 @@ var PACKAGE_MANAGER_DATA = [
30
32
  frozenInstallCommand: "yarn install --frozen-lockfile"
31
33
  }
32
34
  ];
35
+ var PACKAGE_MANAGER_LOCKFILE_SIGNALS = [
36
+ { id: "bun", filenames: ["bun.lock", "bun.lockb"] },
37
+ { id: "pnpm", filenames: ["pnpm-lock.yaml"] },
38
+ {
39
+ id: "yarn",
40
+ filenames: ["yarn.lock", ".pnp.cjs", ".pnp.loader.mjs", ".yarnrc.yml"]
41
+ },
42
+ { id: "npm", filenames: ["package-lock.json", "npm-shrinkwrap.json"] }
43
+ ];
33
44
  var PACKAGE_MANAGER_IDS = PACKAGE_MANAGER_DATA.map((manager) => manager.id);
34
45
  var PACKAGE_MANAGERS = Object.freeze(Object.fromEntries(PACKAGE_MANAGER_DATA.map((manager) => [manager.id, manager])));
35
46
  var DEV_INSTALL_FLAGS = {
@@ -47,6 +58,34 @@ function getPackageManager(id) {
47
58
  }
48
59
  return manager;
49
60
  }
61
+ function parsePackageManagerField(packageManagerField) {
62
+ const packageManagerId = packageManagerField?.split("@", 1)[0];
63
+ return PACKAGE_MANAGER_IDS.includes(packageManagerId) ? packageManagerId : null;
64
+ }
65
+ function readPackageManagerField(projectDir) {
66
+ try {
67
+ const packageJsonPath = path.join(projectDir, "package.json");
68
+ if (!fs.existsSync(packageJsonPath)) {
69
+ return;
70
+ }
71
+ const manifest = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
72
+ return typeof manifest.packageManager === "string" ? manifest.packageManager : undefined;
73
+ } catch {
74
+ return;
75
+ }
76
+ }
77
+ function inferPackageManagerId(projectDir, packageManagerField) {
78
+ const fieldPackageManager = parsePackageManagerField(packageManagerField) ?? parsePackageManagerField(readPackageManagerField(projectDir));
79
+ if (fieldPackageManager) {
80
+ return fieldPackageManager;
81
+ }
82
+ for (const signal of PACKAGE_MANAGER_LOCKFILE_SIGNALS) {
83
+ if (signal.filenames.some((filename) => fs.existsSync(path.join(projectDir, filename)))) {
84
+ return signal.id;
85
+ }
86
+ }
87
+ return "npm";
88
+ }
50
89
  function formatRunScript(packageManagerId, scriptName, extraArgs = "") {
51
90
  const args = extraArgs.trim();
52
91
  if (packageManagerId === "bun") {
@@ -142,6 +181,6 @@ function transformPackageManagerText(content, packageManagerId) {
142
181
  return replaceDevDependencyInstalls(replaceBunRunCommands(content.replace(/\bbun install --frozen-lockfile\b/g, manager.frozenInstallCommand).replace(/\bbun install\b/g, manager.installCommand), packageManagerId), packageManagerId).replace(/\s*&&\s*/g, " && ").replace(/\s*\|\|\s*/g, " || ");
143
182
  }
144
183
 
145
- export { PACKAGE_MANAGER_IDS, getPackageManager, formatRunScript, formatInstallCommand, formatAddDevDependenciesCommand, formatPackageExecCommand, transformPackageManagerText };
184
+ export { PACKAGE_MANAGER_IDS, getPackageManager, parsePackageManagerField, inferPackageManagerId, formatRunScript, formatInstallCommand, formatAddDevDependenciesCommand, formatPackageExecCommand, transformPackageManagerText };
146
185
 
147
- //# debugId=363EEE7BFAAB3E1264756E2164756E21
186
+ //# debugId=53EC02DB5040505B64756E2164756E21
@@ -4,22 +4,14 @@ import {
4
4
  } from "./cli-1sm60g1z.js";
5
5
  import {
6
6
  seedProjectMigrations
7
- } from "./cli-prc42zqd.js";
7
+ } from "./cli-2mt6bvcj.js";
8
8
  import {
9
9
  ensureMigrationDirectories,
10
10
  isPlainObject,
11
11
  stableJsonStringify,
12
12
  writeInitialMigrationScaffold,
13
13
  writeMigrationConfig
14
- } from "./cli-gcbre1zs.js";
15
- import {
16
- PACKAGE_MANAGER_IDS,
17
- formatInstallCommand,
18
- formatPackageExecCommand,
19
- formatRunScript,
20
- getPackageManager,
21
- transformPackageManagerText
22
- } from "./cli-sj5mtyzj.js";
14
+ } from "./cli-hb9vpsev.js";
23
15
  import {
24
16
  getBuiltInSharedTemplateLayerDir,
25
17
  getBuiltInTemplateLayerDirs,
@@ -59,7 +51,7 @@ import {
59
51
  toTitleCase,
60
52
  validateBlockSlug,
61
53
  validateNamespace
62
- } from "./cli-x0h03qqe.js";
54
+ } from "./cli-qr2ek735.js";
63
55
  import {
64
56
  createManagedTempRoot
65
57
  } from "./cli-t73q5aqz.js";
@@ -67,6 +59,14 @@ import {
67
59
  CLI_DIAGNOSTIC_CODES,
68
60
  createCliDiagnosticCodeError
69
61
  } from "./cli-p95wr1q8.js";
62
+ import {
63
+ PACKAGE_MANAGER_IDS,
64
+ formatInstallCommand,
65
+ formatPackageExecCommand,
66
+ formatRunScript,
67
+ getPackageManager,
68
+ transformPackageManagerText
69
+ } from "./cli-6bhfzq5e.js";
70
70
  import {
71
71
  __commonJS,
72
72
  __require,
@@ -11136,7 +11136,9 @@ import os2 from "os";
11136
11136
  import path16 from "path";
11137
11137
  var EXTERNAL_TEMPLATE_CACHE_ENV = "WP_TYPIA_EXTERNAL_TEMPLATE_CACHE";
11138
11138
  var EXTERNAL_TEMPLATE_CACHE_DIR_ENV = "WP_TYPIA_EXTERNAL_TEMPLATE_CACHE_DIR";
11139
+ var EXTERNAL_TEMPLATE_CACHE_TTL_DAYS_ENV = "WP_TYPIA_EXTERNAL_TEMPLATE_CACHE_TTL_DAYS";
11139
11140
  var CACHE_MARKER_FILE = "wp-typia-template-cache.json";
11141
+ var MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
11140
11142
  var PRIVATE_CACHE_DIRECTORY_MODE = 448;
11141
11143
  var REDACTED_CACHE_METADATA_VALUE = "[redacted]";
11142
11144
  var DISABLED_CACHE_VALUES = new Set(["0", "false", "no", "off"]);
@@ -11150,6 +11152,7 @@ var CACHE_UNAVAILABLE_ERROR_CODES = new Set([
11150
11152
  ]);
11151
11153
  var URL_LIKE_METADATA_KEY = /(url|uri|registry|tarball)/iu;
11152
11154
  var SAFE_CACHE_NAMESPACE_SEGMENT = /^[A-Za-z0-9_.-]+$/u;
11155
+ var SAFE_CACHE_ENTRY_SEGMENT = /^[a-f0-9]{64}$/u;
11153
11156
  function isExternalTemplateCacheEnabled(env = process.env) {
11154
11157
  const rawValue2 = env[EXTERNAL_TEMPLATE_CACHE_ENV];
11155
11158
  if (rawValue2 === undefined) {
@@ -11164,6 +11167,25 @@ function getExternalTemplateCacheRoot(env = process.env) {
11164
11167
  }
11165
11168
  return path16.join(os2.tmpdir(), `wp-typia-template-source-cache-${getCurrentUserCacheSegment()}`);
11166
11169
  }
11170
+ function parseExternalTemplateCacheTtlDays(value) {
11171
+ if (typeof value !== "string" && typeof value !== "number") {
11172
+ return null;
11173
+ }
11174
+ const ttlDays = typeof value === "number" ? value : Number(value.trim());
11175
+ if (!Number.isFinite(ttlDays) || ttlDays <= 0) {
11176
+ return null;
11177
+ }
11178
+ return ttlDays;
11179
+ }
11180
+ function resolveExternalTemplateCacheTtlMs(options = {}) {
11181
+ const env = options.env ?? process.env;
11182
+ const ttlDays = options.ttlDays === undefined ? parseExternalTemplateCacheTtlDays(env[EXTERNAL_TEMPLATE_CACHE_TTL_DAYS_ENV]) : parseExternalTemplateCacheTtlDays(options.ttlDays);
11183
+ if (ttlDays === null) {
11184
+ return null;
11185
+ }
11186
+ const ttlMs = ttlDays * MILLISECONDS_PER_DAY;
11187
+ return Number.isFinite(ttlMs) ? ttlMs : null;
11188
+ }
11167
11189
  function createExternalTemplateCacheKey(keyParts) {
11168
11190
  return createHash("sha256").update(JSON.stringify(keyParts)).digest("hex");
11169
11191
  }
@@ -11330,6 +11352,108 @@ function parseCacheMarkerMetadata(markerText) {
11330
11352
  function cacheMetadataMatches(actual, expected) {
11331
11353
  return Object.entries(expected).every(([key, value]) => actual[key] === value);
11332
11354
  }
11355
+ function getExternalTemplateCacheNowMs(now) {
11356
+ const nowMs = now instanceof Date ? now.getTime() : typeof now === "number" ? now : Date.now();
11357
+ return Number.isFinite(nowMs) ? nowMs : Date.now();
11358
+ }
11359
+ function isPathInsideDirectory(directory, candidatePath) {
11360
+ const relativePath = path16.relative(directory, candidatePath);
11361
+ return relativePath.length > 0 && !relativePath.startsWith("..") && !path16.isAbsolute(relativePath);
11362
+ }
11363
+ async function removeCacheEntryWithinRoot(cacheRoot, entryDir) {
11364
+ if (!isPathInsideDirectory(cacheRoot, entryDir)) {
11365
+ return false;
11366
+ }
11367
+ try {
11368
+ await fsp9.rm(entryDir, { force: true, recursive: true });
11369
+ return true;
11370
+ } catch {
11371
+ return false;
11372
+ }
11373
+ }
11374
+ async function pruneExternalTemplateCache(options = {}) {
11375
+ const env = options.env ?? process.env;
11376
+ const cacheRoot = getExternalTemplateCacheRoot(env);
11377
+ const ttlMs = resolveExternalTemplateCacheTtlMs({
11378
+ env,
11379
+ ttlDays: options.ttlDays
11380
+ });
11381
+ const result = {
11382
+ cacheRoot,
11383
+ prunedEntries: 0,
11384
+ scannedEntries: 0,
11385
+ skippedEntries: 0,
11386
+ ttlMs
11387
+ };
11388
+ if (ttlMs === null || !await isPrivateCacheDirectory(cacheRoot)) {
11389
+ return result;
11390
+ }
11391
+ let namespaceEntries;
11392
+ try {
11393
+ namespaceEntries = await fsp9.readdir(cacheRoot, { withFileTypes: true });
11394
+ } catch {
11395
+ return result;
11396
+ }
11397
+ const expiresBeforeMs = getExternalTemplateCacheNowMs(options.now) - ttlMs;
11398
+ for (const namespaceEntry of namespaceEntries) {
11399
+ if (!namespaceEntry.isDirectory()) {
11400
+ continue;
11401
+ }
11402
+ const namespaceDir = resolveCacheNamespaceDir(cacheRoot, namespaceEntry.name);
11403
+ if (!namespaceDir || !await isPrivateCacheDirectory(namespaceDir)) {
11404
+ result.skippedEntries += 1;
11405
+ continue;
11406
+ }
11407
+ let cacheEntries;
11408
+ try {
11409
+ cacheEntries = await fsp9.readdir(namespaceDir, { withFileTypes: true });
11410
+ } catch {
11411
+ result.skippedEntries += 1;
11412
+ continue;
11413
+ }
11414
+ for (const cacheEntry of cacheEntries) {
11415
+ if (!cacheEntry.isDirectory()) {
11416
+ continue;
11417
+ }
11418
+ if (!SAFE_CACHE_ENTRY_SEGMENT.test(cacheEntry.name)) {
11419
+ result.skippedEntries += 1;
11420
+ continue;
11421
+ }
11422
+ const entryDir = path16.join(namespaceDir, cacheEntry.name);
11423
+ result.scannedEntries += 1;
11424
+ if (!isPathInsideDirectory(cacheRoot, entryDir)) {
11425
+ result.skippedEntries += 1;
11426
+ continue;
11427
+ }
11428
+ const markerPath = path16.join(entryDir, CACHE_MARKER_FILE);
11429
+ const sourceDir = path16.join(entryDir, "source");
11430
+ if (!await isReusableCacheEntry(entryDir, markerPath, sourceDir)) {
11431
+ result.skippedEntries += 1;
11432
+ continue;
11433
+ }
11434
+ let markerText;
11435
+ try {
11436
+ markerText = await fsp9.readFile(markerPath, "utf8");
11437
+ } catch {
11438
+ result.skippedEntries += 1;
11439
+ continue;
11440
+ }
11441
+ const marker = parseCacheMarkerMetadata(markerText);
11442
+ if (!marker) {
11443
+ result.skippedEntries += 1;
11444
+ continue;
11445
+ }
11446
+ if (marker.createdAtMs < expiresBeforeMs) {
11447
+ if (await removeCacheEntryWithinRoot(cacheRoot, entryDir)) {
11448
+ result.prunedEntries += 1;
11449
+ } else {
11450
+ result.skippedEntries += 1;
11451
+ }
11452
+ }
11453
+ }
11454
+ }
11455
+ return result;
11456
+ }
11333
11457
  async function findReusableExternalTemplateSourceCache(descriptor) {
11334
11458
  if (!isExternalTemplateCacheEnabled()) {
11335
11459
  return null;
@@ -11342,6 +11466,7 @@ async function findReusableExternalTemplateSourceCache(descriptor) {
11342
11466
  if (!await isPrivateCacheDirectory(cacheRoot) || !await isPrivateCacheDirectory(namespaceDir)) {
11343
11467
  return null;
11344
11468
  }
11469
+ await pruneExternalTemplateCache();
11345
11470
  let entries;
11346
11471
  try {
11347
11472
  entries = await fsp9.readdir(namespaceDir, { withFileTypes: true });
@@ -11393,6 +11518,7 @@ async function resolveExternalTemplateSourceCache(descriptor, populateSourceDir)
11393
11518
  if (!await ensurePrivateCacheDirectory(cacheRoot) || !await ensurePrivateCacheDirectory(namespaceDir)) {
11394
11519
  return null;
11395
11520
  }
11521
+ await pruneExternalTemplateCache();
11396
11522
  if (await isReusableCacheEntry(entryDir, markerPath, sourceDir)) {
11397
11523
  return {
11398
11524
  cacheHit: true,
@@ -17323,4 +17449,4 @@ async function resolveOptionalInteractiveExternalLayerId({
17323
17449
 
17324
17450
  export { syncPersistenceRestArtifacts, copyInterpolatedDirectory, listInterpolatedDirectoryOutputs, getPrimaryDevelopmentScript, getOptionalOnboardingSteps, getOptionalOnboardingNote, getOptionalOnboardingShortNote, formatNonEmptyTargetDirectoryError, require_semver2 as require_semver, parseTemplateLocator, resolveExternalTemplateLayers, resolveTemplateSeed, normalizeOptionalCliString, resolveLocalCliPathOption, assertExternalLayerCompositionOptions, assertBuiltInTemplateVariantAllowed, parseAlternateRenderTargets, parseCompoundInnerBlocksPreset, OPTIONAL_WORDPRESS_AI_CLIENT_COMPATIBILITY, REQUIRED_WORKSPACE_ABILITY_COMPATIBILITY, resolveScaffoldCompatibilityPolicy, createScaffoldCompatibilityConfig, renderScaffoldCompatibilityConfig, updatePluginHeaderCompatibility, getDefaultAnswers, resolveTemplateId, resolvePackageManagerId, collectScaffoldAnswers, DATA_STORAGE_MODES, PERSISTENCE_POLICIES, isDataStorageMode, isPersistencePolicy, scaffoldProject, resolveOptionalInteractiveExternalLayerId };
17325
17451
 
17326
- //# debugId=FF630622235F6B3064756E2164756E21
17452
+ //# debugId=7E585E3F386D6E1964756E2164756E21