<p dir="auto">I think it would be good to have a standardised way to access <code class="notranslate">deno.json</code> config data, since 3rd party tools (bundlers for example) need to have read <code class="notranslate">compilerOptions</code> and <code class="notranslate">importMap</code> to prevent a separate config file.</p>
<p dir="auto">It is possible to do find and parse the file manually (PR in deno/std <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1273307576" data-permission-text="Title is private" data-url="https://github.com/denoland/deno_std/issues/2356" data-hovercard-type="pull_request" data-hovercard-url="/denoland/deno_std/pull/2356/hovercard" href="https://github.com/denoland/deno_std/pull/2356">denoland/deno_std#2356</a>, but <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ry/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ry">@ry</a> is hesitant, since it could get out of sync with the runtime behavior.<br>
So it would be better to include it in the deno namespace.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="namespace Deno {
  export interface ConfigObject {
    tasks: Record&lt;string, string&gt;;
    importMap: ImportMap
    compilerOptions: CompilerOptions;
    …
  }
  export interface config {
    /**
     * returns the filePath of the deno.json or deno.jsonc file that was parsed by the runtime
     */
    filePath: string | null;
    /**
     * returns the resolved json or jsonc data that was parsed by the runtime
     */
    toObject(): ConfigObject | null;
  }
}"><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">ConfigObject</span> <span class="pl-kos">{</span>
    <span class="pl-c1">tasks</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-c1">importMap</span>: <span class="pl-smi">ImportMap</span>
    <span class="pl-c1">compilerOptions</span>: <span class="pl-smi">CompilerOptions</span><span class="pl-kos">;</span>
    <span class="pl-c1">…</span>
  <span class="pl-kos">}</span>
  <span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">config</span> <span class="pl-kos">{</span>
    <span class="pl-c">/**</span>
<span class="pl-c">     * returns the filePath of the deno.json or deno.jsonc file that was parsed by the runtime</span>
<span class="pl-c">     */</span>
    <span class="pl-c1">filePath</span>: <span class="pl-smi">string</span> <span class="pl-c1">|</span> <span class="pl-c1">null</span><span class="pl-kos">;</span>
    <span class="pl-c">/**</span>
<span class="pl-c">     * returns the resolved json or jsonc data that was parsed by the runtime</span>
<span class="pl-c">     */</span>
    <span class="pl-c1">toObject</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">ConfigObject</span> <span class="pl-c1">|</span> <span class="pl-c1">null</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">What are your thoughts on that?</p>
<p dir="auto">I just started playing with Deno,<br>
i made simpler handler which intercepts req and process that</p>
<p dir="auto">here is my index file</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import { serve } from &quot;https://deno.land/std@v0.42.0/http/server.ts&quot;;
import handler from './handler.ts'
const s = serve({ port: 8000 });
console.log(&quot;http://localhost:8000/&quot;);

if(Deno.args.length !== 1){
  throw new Error('Handler is not defined')
}

// console.log(finalHandler)
for await (const req of s) {
  if(req.url === '/'){
    req.respond({ body: handler(req) });
  }else{
    req.respond({})
  }
}
"><pre class="notranslate"><code class="notranslate">import { serve } from "https://deno.land/std@v0.42.0/http/server.ts";
import handler from './handler.ts'
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");

if(Deno.args.length !== 1){
  throw new Error('Handler is not defined')
}

// console.log(finalHandler)
for await (const req of s) {
  if(req.url === '/'){
    req.respond({ body: handler(req) });
  }else{
    req.respond({})
  }
}

</code></pre></div>
<p dir="auto">and this is my simple handler file</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import { ServerRequest } from &quot;https://deno.land/std@v0.42.0/http/server.ts&quot;;
export default (req: ServerRequest) =&gt; {
    return `test ${req.url} `
}
"><pre class="notranslate"><code class="notranslate">import { ServerRequest } from "https://deno.land/std@v0.42.0/http/server.ts";
export default (req: ServerRequest) =&gt; {
    return `test ${req.url} `
}

</code></pre></div>
<p dir="auto">if i run this command</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno run --allow-net --allow-read index.ts handler.ts"><pre class="notranslate"><code class="notranslate">deno run --allow-net --allow-read index.ts handler.ts
</code></pre></div>
<p dir="auto">it works fine, and when i try loading handler file from Deno args and try importing them then it give me error</p>
<p dir="auto">Updated code in index.ts which fails</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import { serve } from &quot;https://deno.land/std@v0.42.0/http/server.ts&quot;;
// import handler from './handler.ts'
const s = serve({ port: 8000 });
console.log(&quot;http://localhost:8000/&quot;);

if(Deno.args.length !== 1){
  throw new Error('Handler is not defined')
}

let handlerPath = await Deno.realPath(Deno.args[0])
console.log(handlerPath)
let finalHandler = await import(handlerPath)

console.log(finalHandler)
for await (const req of s) {
  if(req.url === '/'){
    req.respond({ body: finalHandler(req) });
  }else{
    req.respond({})
  }
}
"><pre class="notranslate"><code class="notranslate">import { serve } from "https://deno.land/std@v0.42.0/http/server.ts";
// import handler from './handler.ts'
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");

if(Deno.args.length !== 1){
  throw new Error('Handler is not defined')
}

let handlerPath = await Deno.realPath(Deno.args[0])
console.log(handlerPath)
let finalHandler = await import(handlerPath)

console.log(finalHandler)
for await (const req of s) {
  if(req.url === '/'){
    req.respond({ body: finalHandler(req) });
  }else{
    req.respond({})
  }
}

</code></pre></div>
<p dir="auto">it throws error at time of importing file</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let finalHandler = await import(handlerPath)"><pre class="notranslate"><code class="notranslate">let finalHandler = await import(handlerPath)
</code></pre></div>
<p dir="auto">now when i run this command</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deno run --allow-net --allow-read index.ts handler.ts"><pre class="notranslate"><code class="notranslate">deno run --allow-net --allow-read index.ts handler.ts
</code></pre></div>
<p dir="auto">it gives me this error</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="thread 'main' panicked at 'internal error: entered unreachable code', cli\state.rs:492:12
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace"><pre class="notranslate"><code class="notranslate">thread 'main' panicked at 'internal error: entered unreachable code', cli\state.rs:492:12
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
</code></pre></div>