"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "resources/resource_transformers/js/build.go" between
hugo-0.80.0.tar.gz and hugo-0.81.0.tar.gz

About: Hugo is a static site generator that takes a source directory of Markdown files and templates and uses these as input to create a complete website (written in Go).

build.go  (hugo-0.80.0):build.go  (hugo-0.81.0)
skipping to change at line 17 skipping to change at line 17
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package js package js
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"path/filepath"
"regexp"
"strings" "strings"
"github.com/pkg/errors"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/hugolib/filesystems" "github.com/gohugoio/hugo/hugolib/filesystems"
"github.com/gohugoio/hugo/media" "github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resources/internal" "github.com/gohugoio/hugo/resources/internal"
skipping to change at line 80 skipping to change at line 84
ctx.OutPath = opts.TargetPath ctx.OutPath = opts.TargetPath
} else { } else {
ctx.ReplaceOutPathExtension(".js") ctx.ReplaceOutPathExtension(".js")
} }
src, err := ioutil.ReadAll(ctx.From) src, err := ioutil.ReadAll(ctx.From)
if err != nil { if err != nil {
return err return err
} }
opts.sourcefile = ctx.SourcePath opts.sourceDir = filepath.FromSlash(path.Dir(ctx.SourcePath))
opts.resolveDir = t.c.rs.WorkingDir opts.resolveDir = t.c.rs.WorkingDir // where node_modules gets resolved
opts.contents = string(src) opts.contents = string(src)
opts.mediaType = ctx.InMediaType opts.mediaType = ctx.InMediaType
buildOptions, err := toBuildOptions(opts) buildOptions, err := toBuildOptions(opts)
if err != nil { if err != nil {
return err return err
} }
buildOptions.Plugins, err = createBuildPlugins(t.c, opts) buildOptions.Plugins, err = createBuildPlugins(t.c, opts)
if err != nil { if err != nil {
return err return err
} }
if buildOptions.Sourcemap == api.SourceMapExternal && buildOptions.Outdir
== "" {
buildOptions.Outdir, err = ioutil.TempDir(os.TempDir(), "compileO
utput")
if err != nil {
return err
}
defer os.Remove(buildOptions.Outdir)
}
if opts.Inject != nil {
// Resolve the absolute filenames.
for i, ext := range opts.Inject {
impPath := filepath.FromSlash(ext)
if filepath.IsAbs(impPath) {
return errors.Errorf("inject: absolute paths not
supported, must be relative to /assets")
}
m := resolveComponentInAssets(t.c.rs.Assets.Fs, impPath)
if m == nil {
return errors.Errorf("inject: file %q not found",
ext)
}
opts.Inject[i] = m.Filename()
}
buildOptions.Inject = opts.Inject
}
result := api.Build(buildOptions) result := api.Build(buildOptions)
if len(result.Errors) > 0 { if len(result.Errors) > 0 {
createErr := func(msg api.Message) error { createErr := func(msg api.Message) error {
loc := msg.Location loc := msg.Location
if loc == nil {
return errors.New(msg.Text)
}
path := loc.File path := loc.File
var ( var (
f afero.File f afero.File
err error err error
) )
if strings.HasPrefix(path, nsImportHugo) { if strings.HasPrefix(path, nsImportHugo) {
path = strings.TrimPrefix(path, nsImportHugo+":") path = strings.TrimPrefix(path, nsImportHugo+":")
f, err = hugofs.Os.Open(path) f, err = hugofs.Os.Open(path)
skipping to change at line 148 skipping to change at line 185
// Return 1, log the rest. // Return 1, log the rest.
for i, err := range errors { for i, err := range errors {
if i > 0 { if i > 0 {
t.c.rs.Logger.Errorf("js.Build failed: %s", err) t.c.rs.Logger.Errorf("js.Build failed: %s", err)
} }
} }
return errors[0] return errors[0]
} }
ctx.To.Write(result.OutputFiles[0].Contents) if buildOptions.Sourcemap == api.SourceMapExternal {
content := string(result.OutputFiles[1].Contents)
symPath := path.Base(ctx.OutPath) + ".map"
re := regexp.MustCompile(`//# sourceMappingURL=.*\n?`)
content = re.ReplaceAllString(content, "//# sourceMappingURL="+sy
mPath+"\n")
if err = ctx.PublishSourceMap(string(result.OutputFiles[0].Conten
ts)); err != nil {
return err
}
_, err := ctx.To.Write([]byte(content))
if err != nil {
return err
}
} else {
_, err := ctx.To.Write(result.OutputFiles[0].Contents)
if err != nil {
return err
}
}
return nil return nil
} }
// Process process esbuild transform // Process process esbuild transform
func (c *Client) Process(res resources.ResourceTransformer, opts map[string]inte rface{}) (resource.Resource, error) { func (c *Client) Process(res resources.ResourceTransformer, opts map[string]inte rface{}) (resource.Resource, error) {
return res.Transform( return res.Transform(
&buildTransformation{c: c, optsm: opts}, &buildTransformation{c: c, optsm: opts},
) )
} }
 End of changes. 7 change blocks. 
4 lines changed or deleted 65 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)