AllYourBot / hostedgpt

An open version of ChatGPT you can host anywhere or run locally.
MIT License
304 stars 122 forks source link

Redo import maps for Blocks so it works in web & console #361

Closed krschacht closed 2 months ago

krschacht commented 2 months ago

Recently, I discovered that all the import statements within blocks files were not working on web loading. I changed all the import lines to reference the importmap name. But just now I realized that this change broke all the block files loading within bin/blocks console.

There is a tricky problem in that an import line at the top of a file:

import Service from "../service.js"

Will be interpreted as an importmap line in the browser context but it's expecting a true path in the node context. This PR addresses this inconsistency between the environments.

The solution was to re-do the importmap naming scheme so that all the pretty names are actually the path name. Now even though the import is interpreted differently in the two contexts, it's still is handled properly in both situations.

The only reason this is possible is that the conventions of Blocks are such that any given file is never referred to by two different relative path names. The Service example above, is never imported from a different location such that it's referenced as ../../service.js