Skip to content

Commit

Permalink
Support semver versioning URL (#875)
Browse files Browse the repository at this point in the history
* Update go mod

* Redirect semver urls for deno

* Update testings
  • Loading branch information
ije authored Sep 8, 2024
1 parent de74745 commit a1c25c6
Show file tree
Hide file tree
Showing 15 changed files with 545 additions and 381 deletions.
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
module github.com/esm-dev/esm.sh

go 1.21
go 1.22

toolchain go1.22.3

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/Masterminds/semver/v3 v3.3.0
github.com/evanw/esbuild v0.23.1
github.com/ije/esbuild-internal v0.23.1
github.com/ije/gox v0.6.2
github.com/ije/rex v1.11.0
github.com/ije/gox v0.6.3
github.com/ije/rex v1.11.2
github.com/mileusna/useragent v1.3.4
go.etcd.io/bbolt v1.3.10
go.etcd.io/bbolt v1.3.11
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/rs/cors v1.11.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
)
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -8,10 +8,10 @@ github.com/evanw/esbuild v0.23.1 h1:ociewhY6arjTarKLdrXfDTgy25oxhTZmzP8pfuBTfTA=
github.com/evanw/esbuild v0.23.1/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48=
github.com/ije/esbuild-internal v0.23.1 h1:OUZwdyIT7tPq9xXjmJ6EYPbGxfYjuYSQcWR3sy+b/z0=
github.com/ije/esbuild-internal v0.23.1/go.mod h1:s7HvKZ4ZGifyzvgWpSwnJOQTr6b+bsgfNBZ8HAEwwSM=
github.com/ije/gox v0.6.2 h1:6jviCiE8EPr9JD9unSOuqex6WSriZzeCdrIfg7RLGgQ=
github.com/ije/gox v0.6.2/go.mod h1:HeDdgw2DUqWKHUyRjy9pdS4ESVxxv+0N5iOufd1JGRs=
github.com/ije/rex v1.11.0 h1:J1n/HeIDRdQf9igenHvLLKmUToxyQFTk/z4DyFFrXUo=
github.com/ije/rex v1.11.0/go.mod h1:ZpJJyaVbRqxeSHK1Ct3ay4rT0v/bq+o2mPAagckv1sM=
github.com/ije/gox v0.6.3 h1:deQW+euX6ZRmSYz3eFRkQvAKYDdWgSJECOBEETmk2oc=
github.com/ije/gox v0.6.3/go.mod h1:HeDdgw2DUqWKHUyRjy9pdS4ESVxxv+0N5iOufd1JGRs=
github.com/ije/rex v1.11.2 h1:tQ9ZXKYeyTIbk3x1hLB2azdb+nhEHTtmSnbFvIvvJIU=
github.com/ije/rex v1.11.2/go.mod h1:thZ8rRfvE17vjcsfc/n7y3zkXn9C4Y8jwi25njmOOBY=
github.com/mileusna/useragent v1.3.4 h1:MiuRRuvGjEie1+yZHO88UBYg8YBC/ddF6T7F56i3PCk=
github.com/mileusna/useragent v1.3.4/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -20,18 +20,18 @@ github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po=
github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
28 changes: 19 additions & 9 deletions server/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type BuildContext struct {
packageJson PackageJSON
isDeprecated string
args BuildArgs
target string
bundleMode BundleMode
dev bool
target string
sourceMap bool
wd string
pkgDir string
Expand Down Expand Up @@ -1024,16 +1024,18 @@ rebuild:
if strings.HasSuffix(file.Path, ".js") {
jsContent := file.Contents
extraBanner := ""
if nodeEnv == "" {
extraBanner = " development"
if ctx.dev {
extraBanner += " development"
}
if ctx.bundleMode == BundleAll {
extraBanner = " bundle-all"
extraBanner += " bundle-all"
} else if ctx.bundleMode == BundleFalse {
extraBanner += " bundle-false"
}
header := bytes.NewBufferString(fmt.Sprintf(
"/* esm.sh(v%d) - %s %s%s */\n",
VERSION,
"/* esm.sh - %s (v%d %s%s) */\n",
ctx.module.String(),
VERSION,
strings.ToLower(ctx.target),
extraBanner,
))
Expand All @@ -1054,11 +1056,19 @@ rebuild:
if ctx.args.external.Has("node:process") || ctx.args.externalAll {
fmt.Fprintf(header, `import __Process$ from "node:process";%s`, EOL)
} else if ctx.isBrowserTarget() {
if len(ctx.packageJson.Browser) == 0 {
if len(ctx.packageJson.Browser) > 0 {
var browserExclude bool
if name, ok := ctx.packageJson.Browser["process"]; ok {
browserExclude = name == ""
} else if name, ok := ctx.packageJson.Browser["node:process"]; ok {
browserExclude = name == ""
}
if !browserExclude {
fmt.Fprintf(header, `const __Process$ = {env:{}};%s`, EOL)
}
} else {
fmt.Fprintf(header, `import __Process$ from "/node/process.js";%s`, EOL)
imports.Add("/node/process.js")
} else {
fmt.Fprintf(header, `const __Process$ = {};%s`, EOL)
}
} else if ctx.target == "denonext" {
fmt.Fprintf(header, `import __Process$ from "node:process";%s`, EOL)
Expand Down
2 changes: 1 addition & 1 deletion server/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const npmRegistry = "https://registry.npmjs.org/"
const jsrRegistry = "https://npm.jsr.io/"

var npmNaming = valid.Validator{valid.FromTo{'a', 'z'}, valid.FromTo{'A', 'Z'}, valid.FromTo{'0', '9'}, valid.Eq('_'), valid.Eq('$'), valid.Eq('.'), valid.Eq('-'), valid.Eq('+'), valid.Eq('!'), valid.Eq('~'), valid.Eq('*'), valid.Eq('('), valid.Eq(')')}
var npmNaming = valid.Validator{valid.Range{'a', 'z'}, valid.Range{'A', 'Z'}, valid.Range{'0', '9'}, valid.Eq('_'), valid.Eq('$'), valid.Eq('.'), valid.Eq('-'), valid.Eq('+'), valid.Eq('!'), valid.Eq('~'), valid.Eq('*'), valid.Eq('('), valid.Eq(')')}

// NpmPackageVerions defines versions of a NPM package
type NpmPackageVerions struct {
Expand Down
Loading

0 comments on commit a1c25c6

Please sign in to comment.