#Simpler way to read a file relative to current module?

10 messages · Page 1 of 1 (latest)

vital plinth
#

So I wrote a little helper function for reading the text content of a file relative to the current module. I came up with the following, but is there any simpler way that I'm missing? It seems a bit wordy 😄

import * as path from "std//path/mod.ts";

const gql = (filename: string) =>
  Deno.readTextFileSync(
    path.resolve(
      path.dirname(path.fromFileUrl(import.meta.url)),
      filename,
    ),
  );
granite geode
#

new URL(filepath, import.meta.utl)?

#

This is usually what I do for relative wasm URL's

vital plinth
#

Ah, thanks a lot 🙂

granite geode
#

Np

wanton orbit
#

even simpler: import.meta.resolve(filename)

granite geode
#

since when is that a thing!?!?!?

vital plinth
granite geode
#

Apparently it resolves to a URL that is potentially a module

wanton orbit
#

It resolves any URL and take into account the import_map.