@@ -25,16 +25,16 @@ import (
2525 "time"
2626
2727 "github.com/fsnotify/fsnotify"
28+ "github.com/neelance/sourcemap"
29+ log "github.com/sirupsen/logrus"
30+ "golang.org/x/tools/go/buildutil"
31+
2832 "github.com/gopherjs/gopherjs/compiler"
2933 "github.com/gopherjs/gopherjs/compiler/astutil"
30- "github.com/gopherjs/gopherjs/compiler/jsFile "
34+ "github.com/gopherjs/gopherjs/compiler/incjs "
3135 "github.com/gopherjs/gopherjs/compiler/sources"
32- "github.com/gopherjs/gopherjs/internal/errorList "
36+ "github.com/gopherjs/gopherjs/internal/errlist "
3337 "github.com/gopherjs/gopherjs/internal/testmain"
34- log "github.com/sirupsen/logrus"
35-
36- "github.com/neelance/sourcemap"
37- "golang.org/x/tools/go/buildutil"
3838)
3939
4040// DefaultGOROOT is the default GOROOT value for builds.
@@ -123,7 +123,7 @@ func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTag
123123// overrideInfo is used by parseAndAugment methods to manage
124124// directives and how the overlay and original are merged.
125125type overrideInfo struct {
126- // KeepOriginal indicates that the original code should be kept
126+ // keepOriginal indicates that the original code should be kept
127127 // but the identifier will be prefixed by `_gopherjs_original_foo`.
128128 // If false the original code is removed.
129129 keepOriginal bool
@@ -166,7 +166,7 @@ type overrideInfo struct {
166166// - Otherwise for identifiers that exist in the original and the overrides,
167167// the original is removed.
168168// - New identifiers that don't exist in original package get added.
169- func parseAndAugment (xctx XContext , pkg * PackageData , isTest bool , fileSet * token.FileSet ) ([]* ast.File , []jsFile. JSFile , error ) {
169+ func parseAndAugment (xctx XContext , pkg * PackageData , isTest bool , fileSet * token.FileSet ) ([]* ast.File , []incjs. File , error ) {
170170 jsFiles , overlayFiles := parseOverlayFiles (xctx , pkg , isTest , fileSet )
171171
172172 originalFiles , err := parserOriginalFiles (pkg , fileSet )
@@ -195,7 +195,7 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke
195195
196196// parseOverlayFiles loads and parses overlay files
197197// to augment the original files with.
198- func parseOverlayFiles (xctx XContext , pkg * PackageData , isTest bool , fileSet * token.FileSet ) ([]jsFile. JSFile , []* ast.File ) {
198+ func parseOverlayFiles (xctx XContext , pkg * PackageData , isTest bool , fileSet * token.FileSet ) ([]incjs. File , []* ast.File ) {
199199 isXTest := strings .HasSuffix (pkg .ImportPath , "_test" )
200200 importPath := pkg .ImportPath
201201 if isXTest {
@@ -241,7 +241,7 @@ func parseOverlayFiles(xctx XContext, pkg *PackageData, isTest bool, fileSet *to
241241// parserOriginalFiles loads and parses the original files to augment.
242242func parserOriginalFiles (pkg * PackageData , fileSet * token.FileSet ) ([]* ast.File , error ) {
243243 var files []* ast.File
244- var errList errorList .ErrorList
244+ var errList errlist .ErrorList
245245 for _ , name := range pkg .GoFiles {
246246 if ! filepath .IsAbs (name ) { // name might be absolute if specified directly. E.g., `gopherjs build /abs/file.go`.
247247 name = filepath .Join (pkg .Dir , name )
@@ -610,15 +610,15 @@ type Options struct {
610610}
611611
612612// PrintError message to the terminal.
613- func (o * Options ) PrintError (format string , a ... interface {} ) {
613+ func (o * Options ) PrintError (format string , a ... any ) {
614614 if o .Color {
615615 format = "\x1B [31m" + format + "\x1B [39m"
616616 }
617617 fmt .Fprintf (os .Stderr , format , a ... )
618618}
619619
620620// PrintSuccess message to the terminal.
621- func (o * Options ) PrintSuccess (format string , a ... interface {} ) {
621+ func (o * Options ) PrintSuccess (format string , a ... any ) {
622622 if o .Color {
623623 format = "\x1B [32m" + format + "\x1B [39m"
624624 }
@@ -629,7 +629,7 @@ func (o *Options) PrintSuccess(format string, a ...interface{}) {
629629// GopherJS requires.
630630type PackageData struct {
631631 * build.Package
632- JSFiles []jsFile. JSFile
632+ JSFiles []incjs. File
633633 // IsTest is true if the package is being built for running tests.
634634 IsTest bool
635635 SrcModTime time.Time
@@ -881,23 +881,14 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, cwd string) erro
881881 }
882882
883883 for _ , file := range filenames {
884- if ! strings .HasSuffix (file , ".inc.js" ) {
885- continue
886- }
887-
888- content , err := os .ReadFile (file )
884+ jsFile , err := incjs .FromFilename (file )
889885 if err != nil {
890- return fmt . Errorf ( "failed to read %s: %w" , file , err )
886+ return err
891887 }
892- info , err := os . Stat ( file )
893- if err != nil {
894- return fmt . Errorf ( "failed to stat %s: %w" , file , err )
888+ if jsFile != nil {
889+ jsFile . Path = filepath . Join ( pkg . Dir , filepath . Base ( file ))
890+ pkg . JSFiles = append ( pkg . JSFiles , * jsFile )
895891 }
896- pkg .JSFiles = append (pkg .JSFiles , jsFile.JSFile {
897- Path : filepath .Join (pkg .Dir , filepath .Base (file )),
898- ModTime : info .ModTime (),
899- Content : content ,
900- })
901892 }
902893
903894 archive , err := s .BuildProject (pkg )
@@ -1311,7 +1302,7 @@ func (s *Session) WaitForChange() {
13111302 if ev .Op & (fsnotify .Create | fsnotify .Write | fsnotify .Remove | fsnotify .Rename ) == 0 || filepath .Base (ev .Name )[0 ] == '.' {
13121303 continue
13131304 }
1314- if ! strings .HasSuffix (ev .Name , ".go" ) && ! strings .HasSuffix (ev .Name , ".inc.js" ) {
1305+ if ! strings .HasSuffix (ev .Name , ".go" ) && ! strings .HasSuffix (ev .Name , incjs . Ext ) {
13151306 continue
13161307 }
13171308 s .options .PrintSuccess ("change detected: %s\n " , ev .Name )
0 commit comments