esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

Make esm.sh into a library

Open jimisaacs opened this issue 2 years ago • 19 comments

Hello @ije, been a little while. I'm getting back into this project a little more, and realizing that it would be a lot easier to make it work for use cases that I'm trying to, if the core functionality was a library that you can pass objects to rather than a server with configuration options.

That would keep the implementations and drivers light in the library, and open free server version of the project.

What do you think?

How would it help me and where is this coming from? The more I get into the AWS linkage, the more I think a library would feel better in this separation of concerns.

jimisaacs avatar Apr 18 '22 21:04 jimisaacs

Maybe the library is esmd

jimisaacs avatar Apr 18 '22 21:04 jimisaacs

If you are interested, I can take a crack at it if you'd create the repo.

jimisaacs avatar Apr 18 '22 21:04 jimisaacs

interesting! but i am not very sure how the library idea work, can you please post an example?

ije avatar Apr 19 '22 06:04 ije

The library would almost be everything except main.go, and the Serve function would take much more options and configuration than what it does now, something like this:

func main() {
    server.Serve(&server.Config { db: myDB, fs: myFS, emdedFS: myEmbedFS, cache: myCache, /* etc...*/  })
}

What could be scrutinized after the split, are the driver implementations.

jimisaacs avatar Apr 19 '22 21:04 jimisaacs

So esmd (or whatever it is called), would include almost everything that another project would import into their main.go.

This project (esm.sh repo) would be almost the same, except a lot of code is gone, and maybe it only includes some of the drivers that are in use. Though not sure which drivers would be included in the lib or in userland, which would be defined as a consumer of the lib.

jimisaacs avatar Apr 20 '22 04:04 jimisaacs

yeah, i like this idea, but i think we can do it even more radically, remove the rex pkg, provider a http handler instead:

esmd := esm.New(esm.Config{ ... })

// build instantly
output, err := esmd.Build(esm.BuildOption{
  Name: "react-dom",
  Version: "18",
  Target: "es2020",
  Deps: esm.Deps {
    "react": "18",
  },
})
fmt.Println(esm.Get(output.id).Content)

// serve as http
http.HandleFunc("/esm", func(w http.ResponseWriter, r *http.Request){
  esmd.Serve(w, r)
})

ije avatar Apr 22 '22 10:04 ije

Hi, guys. How can you install esm.sh binary?

Related: go install failure

https://github.com/esm-dev/esm.sh/issues/307

loynoir avatar Apr 22 '22 20:04 loynoir

still an appetite for this @ije?

jimisaacs avatar May 11 '22 15:05 jimisaacs

@jimisaacs yeah, i like the idea! but i don't have any time on this... i want to finish https://github.com/esm-dev/esm.sh/pull/302 first

ije avatar May 13 '22 05:05 ije

Can I make a proposal? Would it be possible to do one of the following? 1. Give me permission in the org to do the following, or... 2. Fork the esm.sh repo name it esm or esmd, make the go.mod a fully qualified name in that repo, and have this repo pull that package in on main.

Basically do this before improving on the api, can we just make a split to then iterate on it?

2.5. Fork the repo, and submodule it into this one until it can be used as a library.

All in all, I'd love to help but I don't really know where I can get started. I have my own fork and was thinking about trying stuff there, but it would be nice to have things reference the real repos and package names.

jimisaacs avatar May 13 '22 12:05 jimisaacs

Can I make a proposal? Would it be possible to do one of the following? 1. Give me permission in the org to do the following, or... 2. Fork the esm.sh repo name it esm or esmd, make the go.mod a fully qualified name in that repo, and have this repo pull that package in on main.

Basically do this before improving on the api, can we just make a split to then iterate on it?

2.5. Fork the repo, and submodule it into this one until it can be used as a library.

All in all, I'd love to help but I don't really know where I can get started. I have my own fork and was thinking about trying stuff there, but it would be nice to have things reference the real repos and package names.

sure please, i just invited you into the org, please check your email box. and i just created a repo: https://github.com/esm-dev/esmd, maybe we should start from here, keep the package as simple as possible, only provide interfaces for storage, no rex/postdb pkgs needed

ije avatar May 13 '22 14:05 ije

Awesome thanks @ije 👍 ⚡

One more question, can I assume #302 won't affect go source?

jimisaacs avatar May 13 '22 14:05 jimisaacs

sure, go forward!

ije avatar May 13 '22 15:05 ije

Sorry @ije you invited me as a maintainer to esm.sh repo, but not esmd repo. I wanted to pull in the history of esm.sh there and start changing things on top of it. Would it be ok to do that, and rewrite the history of esmd/main?

jimisaacs avatar May 15 '22 19:05 jimisaacs

Just in case my last message was a little unclear, I meant that I don't seem to have the same permissions on the esmd repo as I do on the esm.sh repo

jimisaacs avatar May 16 '22 02:05 jimisaacs

I don't understand, you already in the org, should have the write permission for all repos.

ije avatar May 16 '22 04:05 ije

oh sorry, i didn't notice the default org permissions settings, just updated it to write!

ije avatar May 16 '22 04:05 ije

Hey, what is the current roadmap? Is it done or in progress? I am curious about the module outputted, but I am a new bird of the go. Could you give me a simple way to understand what the esm has done and the goals of esm to reach via the library way?

vanpipy avatar Sep 01 '22 01:09 vanpipy

This would be extremely useful for setups like Bazel. Where you might want to create cached ESM artifacts (processed in separate sandboxes) from your CJS in node_modules to be able to boot up for development with browser-ready ESM

tryggvigy avatar Jan 24 '23 02:01 tryggvigy