"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "resources/resource_transformers/js/options.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).

options.go  (hugo-0.80.0):options.go  (hugo-0.81.0)
skipping to change at line 23 skipping to change at line 23
package js package js
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/spf13/afero"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/evanw/esbuild/pkg/api" "github.com/evanw/esbuild/pkg/api"
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/media" "github.com/gohugoio/hugo/media"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/spf13/cast" "github.com/spf13/cast"
) )
skipping to change at line 65 skipping to change at line 67
// One of: es2015, es2016, es2017, es2018, es2019, es2020 or esnext. // One of: es2015, es2016, es2017, es2018, es2019, es2020 or esnext.
// Default is esnext. // Default is esnext.
Target string Target string
// The output format. // The output format.
// One of: iife, cjs, esm // One of: iife, cjs, esm
// Default is to esm. // Default is to esm.
Format string Format string
// External dependencies, e.g. "react". // External dependencies, e.g. "react".
Externals []string `hash:"set"` Externals []string
// This option allows you to automatically replace a global variable with
an import from another file.
// The filenames must be relative to /assets.
// See https://esbuild.github.io/api/#inject
Inject []string
// User defined symbols. // User defined symbols.
Defines map[string]interface{} Defines map[string]interface{}
// Maps a component import to another.
Shims map[string]string
// User defined params. Will be marshaled to JSON and available as "@para ms", e.g. // User defined params. Will be marshaled to JSON and available as "@para ms", e.g.
// import * as params from '@params'; // import * as params from '@params';
Params interface{} Params interface{}
// What to use instead of React.createElement. // What to use instead of React.createElement.
JSXFactory string JSXFactory string
// What to use instead of React.Fragment. // What to use instead of React.Fragment.
JSXFragment string JSXFragment string
skipping to change at line 95 skipping to change at line 105
// is in widespread use. // is in widespread use.
// //
// See https://bugs.webkit.org/show_bug.cgi?id=199866 // See https://bugs.webkit.org/show_bug.cgi?id=199866
// Deprecated: This no longer have any effect and will be removed. // Deprecated: This no longer have any effect and will be removed.
// TODO(bep) remove. See https://github.com/evanw/esbuild/commit/869e8117 b499ca1dbfc5b3021938a53ffe934dba // TODO(bep) remove. See https://github.com/evanw/esbuild/commit/869e8117 b499ca1dbfc5b3021938a53ffe934dba
AvoidTDZ bool AvoidTDZ bool
mediaType media.Type mediaType media.Type
outDir string outDir string
contents string contents string
sourcefile string sourceDir string
resolveDir string resolveDir string
tsConfig string tsConfig string
} }
func decodeOptions(m map[string]interface{}) (Options, error) { func decodeOptions(m map[string]interface{}) (Options, error) {
var opts Options var opts Options
if err := mapstructure.WeakDecode(m, &opts); err != nil { if err := mapstructure.WeakDecode(m, &opts); err != nil {
return opts, err return opts, err
} }
skipping to change at line 137 skipping to change at line 147
} }
func loaderFromFilename(filename string) api.Loader { func loaderFromFilename(filename string) api.Loader {
l, found := extensionToLoaderMap[filepath.Ext(filename)] l, found := extensionToLoaderMap[filepath.Ext(filename)]
if found { if found {
return l return l
} }
return api.LoaderJS return api.LoaderJS
} }
func resolveComponentInAssets(fs afero.Fs, impPath string) hugofs.FileMeta {
findFirst := func(base string) hugofs.FileMeta {
// This is the most common sub-set of ESBuild's default extension
s.
// We assume that imports of JSON, CSS etc. will be using their f
ull
// name with extension.
for _, ext := range []string{".js", ".ts", ".tsx", ".jsx"} {
if fi, err := fs.Stat(base + ext); err == nil {
return fi.(hugofs.FileMetaInfo).Meta()
}
}
// Not found.
return nil
}
var m hugofs.FileMeta
// First the path as is.
fi, err := fs.Stat(impPath)
if err == nil {
if fi.IsDir() {
m = findFirst(filepath.Join(impPath, "index"))
} else {
m = fi.(hugofs.FileMetaInfo).Meta()
}
} else {
// It may be a regular file imported without an extension.
m = findFirst(impPath)
}
return m
}
func createBuildPlugins(c *Client, opts Options) ([]api.Plugin, error) { func createBuildPlugins(c *Client, opts Options) ([]api.Plugin, error) {
fs := c.rs.Assets fs := c.rs.Assets
resolveImport := func(args api.OnResolveArgs) (api.OnResolveResult, error ) { resolveImport := func(args api.OnResolveArgs) (api.OnResolveResult, error ) {
impPath := args.Path
if opts.Shims != nil {
override, found := opts.Shims[impPath]
if found {
impPath = override
}
}
isStdin := args.Importer == stdinImporter isStdin := args.Importer == stdinImporter
var relDir string var relDir string
if !isStdin { if !isStdin {
rel, found := fs.MakePathRelative(args.Importer) rel, found := fs.MakePathRelative(args.Importer)
if !found { if !found {
// Not in any of the /assets folders. // Not in any of the /assets folders.
// This is an import from a node_modules, let // This is an import from a node_modules, let
// ESBuild resolve this. // ESBuild resolve this.
return api.OnResolveResult{}, nil return api.OnResolveResult{}, nil
} }
relDir = filepath.Dir(rel) relDir = filepath.Dir(rel)
} else { } else {
relDir = filepath.Dir(opts.sourcefile) relDir = opts.sourceDir
} }
impPath := args.Path
// Imports not starting with a "." is assumed to live relative to /assets. // Imports not starting with a "." is assumed to live relative to /assets.
// Hugo makes no assumptions about the directory structure below /assets. // Hugo makes no assumptions about the directory structure below /assets.
if relDir != "" && strings.HasPrefix(impPath, ".") { if relDir != "" && strings.HasPrefix(impPath, ".") {
impPath = filepath.Join(relDir, impPath) impPath = filepath.Join(relDir, impPath)
} }
findFirst := func(base string) hugofs.FileMeta { m := resolveComponentInAssets(fs.Fs, impPath)
// This is the most common sub-set of ESBuild's default e
xtensions.
// We assume that imports of JSON, CSS etc. will be using
their full
// name with extension.
for _, ext := range []string{".js", ".ts", ".tsx", ".jsx"
} {
if fi, err := fs.Fs.Stat(base + ext); err == nil
{
return fi.(hugofs.FileMetaInfo).Meta()
}
}
// Not found.
return nil
}
var m hugofs.FileMeta
// First the path as is.
fi, err := fs.Fs.Stat(impPath)
if err == nil {
if fi.IsDir() {
m = findFirst(filepath.Join(impPath, "index"))
} else {
m = fi.(hugofs.FileMetaInfo).Meta()
}
} else {
// It may be a regular file imported without an extension
.
m = findFirst(impPath)
}
//
if m != nil { if m != nil {
// Store the source root so we can create a jsconfig.json // Store the source root so we can create a jsconfig.json
// to help intellisense when the build is done. // to help intellisense when the build is done.
// This should be a small number of elements, and when // This should be a small number of elements, and when
// in server mode, we may get stale entries on renames et c., // in server mode, we may get stale entries on renames et c.,
// but that shouldn't matter too much. // but that shouldn't matter too much.
c.rs.JSConfigBuilder.AddSourceRoot(m.SourceRoot()) c.rs.JSConfigBuilder.AddSourceRoot(m.SourceRoot())
return api.OnResolveResult{Path: m.Filename(), Namespace: nsImportHugo}, nil return api.OnResolveResult{Path: m.Filename(), Namespace: nsImportHugo}, nil
} }
skipping to change at line 341 skipping to change at line 361
defines = cast.ToStringMapString(opts.Defines) defines = cast.ToStringMapString(opts.Defines)
} }
// By default we only need to specify outDir and no outFile // By default we only need to specify outDir and no outFile
outDir := opts.outDir outDir := opts.outDir
outFile := "" outFile := ""
var sourceMap api.SourceMap var sourceMap api.SourceMap
switch opts.SourceMap { switch opts.SourceMap {
case "inline": case "inline":
sourceMap = api.SourceMapInline sourceMap = api.SourceMapInline
case "external":
sourceMap = api.SourceMapExternal
case "": case "":
sourceMap = api.SourceMapNone sourceMap = api.SourceMapNone
default: default:
err = fmt.Errorf("unsupported sourcemap type: %q", opts.SourceMap ) err = fmt.Errorf("unsupported sourcemap type: %q", opts.SourceMap )
return return
} }
buildOptions = api.BuildOptions{ buildOptions = api.BuildOptions{
Outfile: outFile, Outfile: outFile,
Bundle: true, Bundle: true,
skipping to change at line 372 skipping to change at line 394
External: opts.Externals, External: opts.Externals,
JSXFactory: opts.JSXFactory, JSXFactory: opts.JSXFactory,
JSXFragment: opts.JSXFragment, JSXFragment: opts.JSXFragment,
AvoidTDZ: opts.AvoidTDZ, AvoidTDZ: opts.AvoidTDZ,
Tsconfig: opts.tsConfig, Tsconfig: opts.tsConfig,
// Note: We're not passing Sourcefile to ESBuild.
// This makes ESBuild pass `stdin` as the Importer to the import
// resolver, which is what we need/expect.
Stdin: &api.StdinOptions{ Stdin: &api.StdinOptions{
Contents: opts.contents, Contents: opts.contents,
Sourcefile: opts.sourcefile,
ResolveDir: opts.resolveDir, ResolveDir: opts.resolveDir,
Loader: loader, Loader: loader,
}, },
} }
return return
} }
 End of changes. 12 change blocks. 
41 lines changed or deleted 63 lines changed or added

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