seasonjs / espack Goto Github PK
View Code? Open in Web Editor NEWnative web tools writen in go ,aim to replace all current tools
License: MIT License
native web tools writen in go ,aim to replace all current tools
License: MIT License
go 的struct的与c相同所以如果要通过面向对象来实现 继承必然会有问题
而go中的interface 相较而言却十分方便实现
从JS babel-parser的代码到go parse可以看出
babel的代码完全面向对象
而go的代码其实是面向接口,所以我觉得应该吸收他们的优点后进行改造
现在解析的ast的逻辑我是参照babel实现的,因而就会发现,其实很多estree 在go的表达应该是interface{}
所以通过理解我们可以得出
go 的面向对象与js || java 而言是分离的
go 的interface 意味着:
单独声明super abs ... 等等class 到 interface
至于具体实物则为struct 而struct 则尽量不应该继承,而是通过struct 去实现 interface 从而达到泛型的目的
而至于1.18的泛型是否能简化每个struct的使用是可以后续考虑的
下面我写点带go味的代码
type Food interface {
Tasty()
}
type Beef struct {
// Beef attr
}
func (b Beef) Tasty() {}
type Grass struct {
// Grass attr
}
func (g Grass) Tasty() {}
type Animal interface {
Eat(f Food) bool
}
type Dog struct {
// Dog attr
}
func (d Dog) Eat(f Food) bool {
f.Tasty()
switch f.(type) {
case Grass:
return false
case Beef:
return true
default:
return false
}
}
type Rabbit struct {
}
func (d Rabbit) Eat(f Food) bool {
f.Tasty()
switch f.(type) {
case Grass:
return true
case Beef:
return false
default:
return false
}
}
func main() {
var animals []Animal
animals = append(animals, Rabbit{})
animals = append(animals, Dog{})
for _, animal := range animals {
fmt.Println(animal.Eat(Grass{}))
}
}
而在js里我们可以这样写
const Grass = {
kind: "Grass"
}
const Beef = {
kind: "Beef"
}
// inteface like
class Animal {
eat(food) {
return false
}
}
class Dog extends Animal {
eat(food) {
switch (food.kind) {
case "Grass":
return false
case "Beef":
return true
default:
return false
}
}
}
class Rabbit extends Animal {
eat(food) {
switch (food.kind) {
case "Grass":
return true
case "Beef":
return false
default:
return false
}
}
}
const animals = [new Rabbit(), new Dog()]
animals.forEach(animal => {
console.log(animal.eat(Grass))
})
从这个代码来看go 和js 各有冗余,js虽然没有了类型,但是因此得通过对象属性声明类型,go有了类型,但是需要冗余的实现duck type :)
不应该需要在内存条件下还需要新建文件夹
func (f fs) IsDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
return false
}
return s.IsDir()
}
伪代码逻辑:
package xxxPlugin
import (
"fmt"
"github.com/seasonjs/espack/pkg/api/plugin"
)
func init() { plugin.Register("espack_plugin_corejs", NewPlugin) }
func NewPlugin(opt interface{}) *interface{} {
fmt.Println("plugin is regist in espack")
return nil
}
{
"entry": {
"main": "index.jsx"
},
"output": "dist",
"plugins": [
{
"name": "espack_plugin_corejs",
"option": {
"xxx": "xxx",
"others": "this is others option"
}
}
]
}
调研npm代替方案 js.mod -> go mod like?
调研npm元数据api获取
调研unpack方式获取,不大可行,es module 太少(可能会成未来的答案,但是现在我选npm)
调研go解压tgz格式文件
调研go.mod 解析生成原理
获取元数据
解决循环依赖
根据js.mod依赖生成js.sum
根据package.json 生成js.mod
根据解析好的数据下载tarball
处理espack install 命令逻辑
处理单个包下载命令逻辑
增加更多go mod like && npm like && yarn like 命令
完全摆脱对node_model的依赖优先考虑 统一保存,为了兼容性需要增加一个转译的cache,将下载的非esm模块提前转义为esm
调研Import maps vs js.mod的可能性
调研 其他多包其他 vs js.work的可能性
迁移之后,没有了冗余的以下依赖,应用程序大小缩小了5M~~
github.com/gin-contrib/sse v0.1.0
github.com/go-playground/validator/v10 v10.9.0
github.com/goccy/go-json v0.7.8
github.com/json-iterator/go v1.1.12
github.com/mattn/go-isatty v0.0.14
github.com/stretchr/testify v1.7.0
github.com/ugorji/go/codec v1.2.6
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0
https://go.googlesource.com/proposal/+/master/design/45713-workspace.md
1.现在的go的ast结构还是不让人满意
2.现在的项目层级太深了
https://github.com/anacrolix/torrent
I came across your espack
tool in hopes of finding a way to install and bundle Javascript dependencies without relying on NodeJS or NPM.
Does your tool work?
因为js和go完全不同
1.为什么不选择rust?
rust 源码分发难度和编译速度相比go有点差,rust语法概念过于复杂,rust迭代过于频繁很多语法经常变动,不适合我这样没有C基础的
性能这个问题其实是个仁者见仁智者见智的问题。
2.为什么选择go?
因为go有go关键字,go和js python很像,go的性能不是很差,go可以提供二进制分发能力。
3.为什么不选择esbuild和swc另起灶炉?
swc很适合我去偷懒,可惜我们的目标可能有些许偏差,我想要的是具有源码分发和二进制可分发能力的语言,而rust目前看还是有欠缺,swc和esbuild很棒但是有些理念违背了我的想法,我想要完全摆脱node_model与node这个属于2010年这十年间的产物,走向完全可以实现自主分发的程序,就比如deno的**和go mod的**就很棒。
还有esbuild自身定位的问题,就是ast不标准化(不要跟我聊性能问题),这会导致它只能作为一个打包器,而不能作为一个ast服务向其他服务提供能力。
感觉项目的思路不错,跟 deno 的类似,最近我也在研究这方面的东西,不过代码拉不来启动不了,可以给个介绍嘛
buffer 在读取优势没有 string明显,在写入和拼接的时候才能体现出优势
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.