Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from esm-dev:main #57

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion HOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You will need [Go](https://golang.org/dl) 1.22+ to compile and run the server.
go run main.go --config=config.json
```

Then you can import `React` from <http://localhost:808080/react>.
Then you can import `React` from <http://localhost:8080/react>.

## Deploy the Server to a Single Machine

Expand Down
8 changes: 4 additions & 4 deletions server/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, include
pkgName, _, subPath, _ := splitEsmPath(specifier)
if pkgName == ctx.esm.PkgName {
version = ctx.esm.PkgVersion
} else if v, ok := ctx.pkgJson.Dependencies[pkgName]; ok && regexpVersionStrict.MatchString(v) {
} else if v, ok := ctx.pkgJson.Dependencies[pkgName]; ok && isExactVersion(v) {
version = v
} else if v, ok := ctx.pkgJson.PeerDependencies[pkgName]; ok && regexpVersionStrict.MatchString(v) {
} else if v, ok := ctx.pkgJson.PeerDependencies[pkgName]; ok && isExactVersion(v) {
version = v
}
p := pkgName
Expand Down Expand Up @@ -866,7 +866,7 @@ func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, include
} else if version, ok := ctx.pkgJson.PeerDependencies["svelte"]; ok {
svelteVersion = version
}
if !regexpVersionStrict.MatchString(svelteVersion) {
if !isExactVersion(svelteVersion) {
info, err := ctx.npmrc.getPackageInfo("svelte", svelteVersion)
if err != nil {
return esbuild.OnLoadResult{}, errors.New("failed to get svelte package info")
Expand Down Expand Up @@ -900,7 +900,7 @@ func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, include
} else if version, ok := ctx.pkgJson.PeerDependencies["vue"]; ok {
vueVersion = version
}
if !regexpVersionStrict.MatchString(vueVersion) {
if !isExactVersion(vueVersion) {
info, err := ctx.npmrc.getPackageInfo("vue", vueVersion)
if err != nil {
return esbuild.OnLoadResult{}, errors.New("failed to get vue package info")
Expand Down
6 changes: 3 additions & 3 deletions server/build_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,11 +923,11 @@ func (ctx *BuildContext) resolveExternalModule(specifier string, kind api.Resolv

var isFixedVersion bool
if dep.GhPrefix {
isFixedVersion = isCommitish(dep.PkgVersion) || regexpVersionStrict.MatchString(strings.TrimPrefix(dep.PkgVersion, "v"))
isFixedVersion = isCommitish(dep.PkgVersion) || isExactVersion(strings.TrimPrefix(dep.PkgVersion, "v"))
} else if dep.PrPrefix {
isFixedVersion = true
} else {
isFixedVersion = regexpVersionStrict.MatchString(dep.PkgVersion)
isFixedVersion = isExactVersion(dep.PkgVersion)
}
if isFixedVersion {
buildArgsPrefix := ""
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func (ctx *BuildContext) resloveDTS(entry BuildEntry) (string, error) {
}

// lookup types in @types scope
if pkgJson := ctx.pkgJson; pkgJson.Types == "" && !strings.HasPrefix(pkgJson.Name, "@types/") && regexpVersionStrict.MatchString(pkgJson.Version) {
if pkgJson := ctx.pkgJson; pkgJson.Types == "" && !strings.HasPrefix(pkgJson.Name, "@types/") && isExactVersion(pkgJson.Version) {
versionParts := strings.Split(pkgJson.Version, ".")
versions := []string{
versionParts[0] + "." + versionParts[1], // major.minor
Expand Down
2 changes: 1 addition & 1 deletion server/cjs_module_lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ RETRY:
if strings.HasPrefix(line, "@") {
ret.Reexport = line[1:]
break
} else if regexpJSIdent.MatchString(line) && !isJsReservedWord(line) {
} else if isJsIdentifier(line) && !isJsReservedWord(line) {
ret.Exports = append(ret.Exports, line)
}
}
Expand Down
5 changes: 2 additions & 3 deletions server/legacy_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ func legacyESM(ctx *rex.Context, pathname string) any {
if ctx.R.URL.RawQuery != "" {
query = "?" + ctx.R.URL.RawQuery
}
isFixedVersion := regexpVersionStrict.MatchString(pkgVersion)
if !isFixedVersion {
if !isExactVersion(pkgVersion) {
npmrc := DefaultNpmRC()
pkgInfo, err := npmrc.fetchPackageInfo(pkgName, pkgVersion)
pkgInfo, err := npmrc.getPackageInfo(pkgName, pkgVersion)
if err != nil {
if strings.Contains(err.Error(), " not found") {
return rex.Status(404, err.Error())
Expand Down
4 changes: 2 additions & 2 deletions server/loader_implements.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func resolveSvelteVersion(npmrc *NpmRC, importMap common.ImportMap) (svelteVersi
}
}
}
if !regexpVersionStrict.MatchString(svelteVersion) {
if !isExactVersion(svelteVersion) {
var info *PackageJSON
info, err = npmrc.getPackageInfo("svelte", svelteVersion)
if err != nil {
Expand Down Expand Up @@ -282,7 +282,7 @@ func resolveVueVersion(npmrc *NpmRC, importMap common.ImportMap) (vueVersion str
}
}
}
if !regexpVersionStrict.MatchString(vueVersion) {
if !isExactVersion(vueVersion) {
var info *PackageJSON
info, err = npmrc.getPackageInfo("vue", vueVersion)
if err != nil {
Expand Down
Loading
Loading