endo icon indicating copy to clipboard operation
endo copied to clipboard

Support `import.meta.url` and `require.resolve`

Open naugtur opened this issue 2 years ago • 1 comments

Use-cases

The goal of this is to collect requirements for the feature

import.meta.url

  • resolving relative paths to non-code files of the same package (data or reading version from package.json)
  • creating a require function and shimming paths
const require = createRequire(import.meta.url);
__dirname = fileURLToPath(import.meta.url);
  • workers, loaders etc. - situations where code files URLs need to be known
const LOADER = new URL('shared-worker-loader.js', import.meta.url);

require.resolve

  • resetting require cache
delete require.cache[require.resolve('../src/sha3.js')];

Requirements

import.meta

running from live filesystem (loadLocation)

running form bundle/archive

require.resolve require.cache

running from live filesystem (loadLocation)

running form bundle/archive

Work

  • [ ] #1141
  • [ ] #1144

naugtur avatar Apr 12 '22 10:04 naugtur

See: https://github.com/endojs/endo/issues/291

kriskowal avatar Apr 20 '22 22:04 kriskowal

I’ll note that import.meta.resolve is now specified to be synchronous, which we can support because we know where all the dependency packages are before we run JS.

kriskowal avatar Jan 09 '24 01:01 kriskowal