<h1 dir="auto">Proposal</h1>
<p dir="auto">I propose these implementations:</p>
<h2 dir="auto">Deno.cacheDir()</h2>
<p dir="auto">Implementation of rust's <a href="https://docs.rs/dirs/1.0.5/dirs/fn.cache_dir.html" rel="nofollow">cache_dir</a></p>
<h2 dir="auto">Deno.cache(path: string, options: CacheOptions)</h2>
<p dir="auto">access to <code class="notranslate">deno cache</code> as a method</p>
<h2 dir="auto">resolveCacheModulePath(path: string)</h2>
<p dir="auto">Native way to resolve an url to the local cache file. Either returns the <code class="notranslate">filepath</code> if the file is cached or <code class="notranslate">null</code> if not.<br>
Example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="resolveCachedModulePath(&quot;https://deno.land/std/fmt/colors.ts&quot;) // output on macOS: /User/Name/Library/Caches/deno/deps/https/deno.land/0e481eaf33c7b5f679cc7af0c476a798458854f912fe489bb77131d47e0929db"><pre class="notranslate"><span class="pl-en">resolveCachedModulePath</span><span class="pl-kos">(</span><span class="pl-s">"https://deno.land/std/fmt/colors.ts"</span><span class="pl-kos">)</span> <span class="pl-c">// output on macOS: /User/Name/Library/Caches/deno/deps/https/deno.land/0e481eaf33c7b5f679cc7af0c476a798458854f912fe489bb77131d47e0929db</span></pre></div>
<p dir="auto">Maybe Deno needs a dedicated <code class="notranslate">std/cache</code> module for functions like <code class="notranslate">resolveCachedModulePath</code> and other cache related stuff?</p>
<h1 dir="auto">Use case</h1>
<p dir="auto">The Deno cache system is great. For dev tools written for Deno it is important to have access to the local files for a certain path when bundling or compiling, else it needs to be either re-downloaded or cached with a custom cache system.</p>
<p dir="auto">What are your thoughts on this?</p>
<p dir="auto">References:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="569113567" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/4069" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/4069/hovercard" href="https://github.com/denoland/deno/issues/4069">#4069</a><br>
<a href="https://denolib.gitbook.io/guide/advanced/deno_dir-code-fetch-and-cache" rel="nofollow">https://denolib.gitbook.io/guide/advanced/deno_dir-code-fetch-and-cache</a><br>
<a href="https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts" rel="nofollow">https://doc.deno.land/https/github.com/denoland/deno/releases/latest/download/lib.deno.d.ts</a><br>
<a href="https://deno.land/manual/runtime/compiler_apis" rel="nofollow">https://deno.land/manual/runtime/compiler_apis</a><br>
<a href="https://deno.land/x/cache" rel="nofollow">https://deno.land/x/cache</a></p>
<p dir="auto">We recently changed <code class="notranslate">deno fetch</code> to <code class="notranslate">deno cache</code>.  When we introduced the runtime compiler APIs, one of the challenges is that it didn't align well with the subcommands.  Given that we have a better name now for the subcommands, it feels right to re-align the runtime compiler APIs, also based on some experience with them as well.  I am recommending the following:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="namespace Deno {
  export interface CacheOptions { /* would be close to existing compiler options */ }
  export interface BundleOptions ( /* would vary a little bit from cache options */ }
  export interface TranspileOptions extends CacheOptions { /* a few options differ */ }

  export function cache(root: string, options?: RuntimeCompilerOptions): Promise&lt;Record&lt;string, string&gt;&gt;;
  export function bundle(root: string, options?: RuntimeCompilerOptions): Promise&lt;string&gt;;
  export function transpile(sources: Record&lt;string, string&gt;, options?: TranspileOptions): Promise&lt;Record&lt;string, string&gt;&gt;;
}"><pre class="notranslate"><span class="pl-k">namespace</span> <span class="pl-smi">Deno</span> <span class="pl-kos">{</span>
  <span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">CacheOptions</span> <span class="pl-kos">{</span> <span class="pl-c">/* would be close to existing compiler options */</span> <span class="pl-kos">}</span>
  <span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">BundleOptions</span> <span class="pl-kos">(</span> <span class="pl-c">/* would vary a little bit from cache options */</span> <span class="pl-kos">}</span>
  <span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">TranspileOptions</span> <span class="pl-k">extends</span> <span class="pl-smi">CacheOptions</span> <span class="pl-kos">{</span> <span class="pl-c">/* a few options differ */</span> <span class="pl-kos">}</span>

  <span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-s1">cache</span><span class="pl-kos">(</span><span class="pl-s1">root</span>: <span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-s1">options</span>?: <span class="pl-smi">RuntimeCompilerOptions</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi">Record</span><span class="pl-kos">&lt;</span><span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-smi">string</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>
  <span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-s1">bundle</span><span class="pl-kos">(</span><span class="pl-s1">root</span>: <span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-s1">options</span>?: <span class="pl-smi">RuntimeCompilerOptions</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi">string</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>
  <span class="pl-k">export</span> <span class="pl-k">function</span> <span class="pl-s1">transpile</span><span class="pl-kos">(</span><span class="pl-s1">sources</span>: <span class="pl-smi">Record</span><span class="pl-kos">&lt;</span><span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-smi">string</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span> <span class="pl-s1">options</span>?: <span class="pl-smi">TranspileOptions</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi">Record</span><span class="pl-kos">&lt;</span><span class="pl-smi">string</span><span class="pl-kos">,</span> <span class="pl-smi">string</span><span class="pl-kos">&gt;</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><code class="notranslate">Deno.cache</code> would work like <code class="notranslate">deno cache</code> and the <code class="notranslate">RuntimeCompilerOptions</code> would also support the flags that <code class="notranslate">deno cache</code> supports plus the support of an expanded <code class="notranslate">tsconfig.json</code> set of compiler options aligned to what exists today in <code class="notranslate">CompilerOptions</code>.</p>
<p dir="auto"><code class="notranslate">Deno.bundle</code> would produce a single file emit, like <code class="notranslate">deno bundle</code> does and people would use <code class="notranslate">Deno.transpile()</code> when they have sources that they want the compiler to transpile for them.</p>
<p dir="auto">We could introduce the equivalent <code class="notranslate">--no-check</code> in these APIs as well, as well as adding it to the appropriate subcommands, but that might be an enhancement on top of this refactor.</p>
<p dir="auto">Refs: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="593104393" data-permission-text="Title is private" data-url="https://github.com/denoland/deno/issues/4600" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/4600/hovercard" href="https://github.com/denoland/deno/issues/4600">#4600</a></p>