Hi larsgw,
If we could get a bit more information as to how you want to use this, it would help us implement it for you, since its actually a UI issue that prevents us from doing this now, not a technical one. Unlike tink, we do not “install as you go”, all the packages really are there. Not just all 400,000, but much larger since every version is there (if you manually inspect the folders, you’ll find them all). The reason we only allow you “access” to ones that are string-literally required is that we can’t figure out which one you want otherwise. Allow me to explain:
When you type require(“x”), it first is unclear what version of x you want. This can be immediately resolved by assuming you want the latest version of the package at the time of typing it. So, if you open a document today and type require(“x”), you’ll get latest as of that time, and then if you return to that document tomorrow, and type require(“y”), you’ll get latest as of the time you typed that. It’s identical to the behavior of typing “npm install x” on your computer, it is resolved as a function of the current state of the package database.
However, if you do require(variable), we don’t know what version you want. You could argue that this could be resolved by only supporting variable of the form “x@semver”, but that actually isn’t sufficient, because that package’s dependencies are semvers themselves, and we have to resolve those semvers as a function of original require time too (if not, every time you ran the document, the internal dependencies could change!).
Now, there are certainly a number of strategies we could use: just use the time the document was last edited, the latest time a literal require happened, etc., but we simply haven’t had enough insight into how people are wanting to use a dynamic import to know the best way to do it.
So, the good news is that this is totally technically feasible, and again, since they’re all already there (really! that statement isn’t misleading at all!), they’ll all “require” instantly, you won’t suffer from an install-time even in this theoretically dynamic world.
The bad news is we simply haven’t figured out a non-confusing way to expose it yet. If you could tell us your use case, you could definitely help us get there!