endo
endo copied to clipboard
Support `import.meta.url` and `require.resolve`
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
See: https://github.com/endojs/endo/issues/291
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.