Skip to content

Commit 0b6bc6d

Browse files
committed
server: fix highlight.js build
1 parent 0728f8c commit 0b6bc6d

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

server/build.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,13 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
334334
func(args api.OnResolveArgs) (api.OnResolveResult, error) {
335335
// if it's the entry module
336336
if args.Path == entryPoint || args.Path == entryModuleSpecifier {
337-
if entry.esm != "" {
338-
return api.OnResolveResult{Path: path.Join(ctx.pnpmPkgDir, entry.esm)}, nil
339-
}
340-
if entry.cjs != "" {
341-
return api.OnResolveResult{Path: path.Join(ctx.pnpmPkgDir, entry.cjs)}, nil
337+
if args.Path == entryModuleSpecifier {
338+
if entry.esm != "" {
339+
return api.OnResolveResult{Path: path.Join(ctx.pnpmPkgDir, entry.esm)}, nil
340+
}
341+
if entry.cjs != "" {
342+
return api.OnResolveResult{Path: path.Join(ctx.pnpmPkgDir, entry.cjs)}, nil
343+
}
342344
}
343345
return api.OnResolveResult{}, nil
344346
}
@@ -525,7 +527,7 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
525527
}
526528

527529
// bundle "@babel/runtime/*"
528-
if (args.Kind == api.ResolveJSRequireCall || !noBundle) && ctx.pkgJson.Name != "@babel/runtime" && (strings.HasPrefix(specifier, "@babel/runtime/") || strings.Contains(args.Importer, "/@babel/runtime/")) {
530+
if (args.Kind != api.ResolveJSDynamicImport && !noBundle) && ctx.pkgJson.Name != "@babel/runtime" && (strings.HasPrefix(specifier, "@babel/runtime/") || strings.Contains(args.Importer, "/@babel/runtime/")) {
529531
return api.OnResolveResult{}, nil
530532
}
531533

@@ -610,10 +612,10 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
610612
}
611613
if match {
612614
exportPrefix, _ := utils.SplitByLastByte(exportName, '*')
613-
url := path.Join(ctx.pkgJson.Name, exportPrefix+strings.TrimPrefix(bareName, prefix))
614-
if i := entryModuleSpecifier; url != i && url != i+"/index" {
615+
exportModuleName := path.Join(ctx.pkgJson.Name, exportPrefix+strings.TrimPrefix(bareName, prefix))
616+
if exportModuleName != entryModuleSpecifier && exportModuleName != entryModuleSpecifier+"/index" {
615617
return api.OnResolveResult{
616-
Path: ctx.resolveExternalModule(url, args.Kind),
618+
Path: ctx.resolveExternalModule(exportModuleName, args.Kind),
617619
External: true,
618620
SideEffects: pkgSideEffects,
619621
}, nil
@@ -637,10 +639,10 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
637639
}
638640
}
639641
if match {
640-
url := path.Join(ctx.pkgJson.Name, stripModuleExt(exportName))
641-
if i := entryModuleSpecifier; url != i && url != i+"/index" {
642+
exportModuleName := path.Join(ctx.pkgJson.Name, stripModuleExt(exportName))
643+
if exportModuleName != entryModuleSpecifier && exportModuleName != entryModuleSpecifier+"/index" {
642644
return api.OnResolveResult{
643-
Path: ctx.resolveExternalModule(url, args.Kind),
645+
Path: ctx.resolveExternalModule(exportModuleName, args.Kind),
644646
External: true,
645647
SideEffects: pkgSideEffects,
646648
}, nil
@@ -650,8 +652,14 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
650652
}
651653
}
652654

655+
// module file path
653656
moduleFilepath := path.Join(ctx.pnpmPkgDir, moduleSpecifier)
654657

658+
// if it's the entry module
659+
if moduleSpecifier == entry.cjs || moduleSpecifier == entry.esm {
660+
return api.OnResolveResult{Path: moduleFilepath}, nil
661+
}
662+
655663
// split the module that is an alias of a dependency
656664
// means this file just include a single line(js): `export * from "dep"`
657665
fi, ioErr := os.Lstat(moduleFilepath)
@@ -678,9 +686,7 @@ func (ctx *BuildContext) buildModule() (result BuildResult, err error) {
678686
// bundle the internal module if it's not a dynamic import or `?bundle=false` query present
679687
if args.Kind != api.ResolveJSDynamicImport && !noBundle {
680688
if existsFile(moduleFilepath) {
681-
return api.OnResolveResult{
682-
Path: moduleFilepath,
683-
}, nil
689+
return api.OnResolveResult{Path: moduleFilepath}, nil
684690
}
685691
// let esbuild to handle it
686692
return api.OnResolveResult{}, nil

0 commit comments

Comments
 (0)