@rohal12/twee-ts 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -24,6 +24,7 @@ __export(src_exports, {
24
24
  TweeLexer: () => TweeLexer,
25
25
  TweeTsError: () => TweeTsError,
26
26
  applyTagAliases: () => applyTagAliases,
27
+ clearCachedFormats: () => clearCachedFormats,
27
28
  compile: () => compile,
28
29
  compileToFile: () => compileToFile,
29
30
  discoverCachedFormats: () => discoverCachedFormats,
@@ -33,8 +34,10 @@ __export(src_exports, {
33
34
  formatLintReport: () => formatLintReport,
34
35
  generateIFID: () => generateIFID,
35
36
  getCacheDir: () => getCacheDir,
37
+ getCacheSize: () => getCacheSize,
36
38
  getFormatSearchDirs: () => getFormatSearchDirs,
37
39
  lint: () => lint,
40
+ listCachedFormats: () => listCachedFormats,
38
41
  loadConfig: () => loadConfig,
39
42
  loadConfigFile: () => loadConfigFile,
40
43
  parseFormatJSON: () => parseFormatJSON,
@@ -2137,6 +2140,75 @@ function discoverCachedFormats() {
2137
2140
  }
2138
2141
  return formats;
2139
2142
  }
2143
+ function listCachedFormats() {
2144
+ const cacheDir = getCacheDir();
2145
+ const entries = [];
2146
+ try {
2147
+ if (!(0, import_node_fs6.existsSync)(cacheDir)) return entries;
2148
+ } catch {
2149
+ return entries;
2150
+ }
2151
+ let names;
2152
+ try {
2153
+ names = (0, import_node_fs6.readdirSync)(cacheDir);
2154
+ } catch {
2155
+ return entries;
2156
+ }
2157
+ for (const name of names) {
2158
+ const nameDir = (0, import_node_path7.join)(cacheDir, name);
2159
+ try {
2160
+ if (!(0, import_node_fs6.statSync)(nameDir).isDirectory()) continue;
2161
+ } catch {
2162
+ continue;
2163
+ }
2164
+ let versions;
2165
+ try {
2166
+ versions = (0, import_node_fs6.readdirSync)(nameDir);
2167
+ } catch {
2168
+ continue;
2169
+ }
2170
+ for (const version of versions) {
2171
+ const formatPath = (0, import_node_path7.join)(nameDir, version, "format.js");
2172
+ try {
2173
+ const stat = (0, import_node_fs6.statSync)(formatPath);
2174
+ entries.push({
2175
+ name,
2176
+ version,
2177
+ sizeBytes: stat.size,
2178
+ modifiedAt: stat.mtime
2179
+ });
2180
+ } catch {
2181
+ }
2182
+ }
2183
+ }
2184
+ return entries;
2185
+ }
2186
+ function clearCachedFormats(name) {
2187
+ const cacheDir = getCacheDir();
2188
+ if (!(0, import_node_fs6.existsSync)(cacheDir)) return 0;
2189
+ if (!name) {
2190
+ const entries = listCachedFormats();
2191
+ const count2 = entries.length;
2192
+ (0, import_node_fs6.rmSync)(cacheDir, { recursive: true, force: true });
2193
+ return count2;
2194
+ }
2195
+ const nameDir = (0, import_node_path7.join)(cacheDir, name);
2196
+ if (!(0, import_node_fs6.existsSync)(nameDir)) return 0;
2197
+ let versions;
2198
+ try {
2199
+ versions = (0, import_node_fs6.readdirSync)(nameDir);
2200
+ } catch {
2201
+ return 0;
2202
+ }
2203
+ const count = versions.length;
2204
+ (0, import_node_fs6.rmSync)(nameDir, { recursive: true, force: true });
2205
+ return count;
2206
+ }
2207
+ function getCacheSize() {
2208
+ const entries = listCachedFormats();
2209
+ const totalBytes = entries.reduce((sum, e) => sum + e.sizeBytes, 0);
2210
+ return { totalBytes, count: entries.length };
2211
+ }
2140
2212
 
2141
2213
  // src/compiler.ts
2142
2214
  var CREATOR_NAME3 = "Twee-ts";
@@ -2608,6 +2680,7 @@ function scaffoldConfig() {
2608
2680
  TweeLexer,
2609
2681
  TweeTsError,
2610
2682
  applyTagAliases,
2683
+ clearCachedFormats,
2611
2684
  compile,
2612
2685
  compileToFile,
2613
2686
  discoverCachedFormats,
@@ -2617,8 +2690,10 @@ function scaffoldConfig() {
2617
2690
  formatLintReport,
2618
2691
  generateIFID,
2619
2692
  getCacheDir,
2693
+ getCacheSize,
2620
2694
  getFormatSearchDirs,
2621
2695
  lint,
2696
+ listCachedFormats,
2622
2697
  loadConfig,
2623
2698
  loadConfigFile,
2624
2699
  parseFormatJSON,