Skip to content

Commit

Permalink
Revert "Fingerprint each spa file to break cache (#320)."
Browse files Browse the repository at this point in the history
This reverts commit d84c8e0.
  • Loading branch information
jimafisk committed May 2, 2024
1 parent fbb86a2 commit 9ac9d24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,19 @@ func Build() error {
}

// Run Gopack (custom Snowpack alternative) on app for ESM support.
err = build.Gopack(buildPath, spaPath, spaPath+"core/main.js", siteConfig.Fingerprint)
err = build.Gopack(buildPath, spaPath, spaPath+"core/main.js")
if err != nil {
log.Fatal("\nError in Gopack main.js build step", err)
}

// Run Gopack (custom Snowpack alternative) on dynamically imported adminMenu.
err = build.Gopack(buildPath, spaPath, spaPath+"core/cms/admin_menu.js", siteConfig.Fingerprint)
err = build.Gopack(buildPath, spaPath, spaPath+"core/cms/admin_menu.js")
if err != nil {
log.Fatal("\nError in Gopack admin_menu.svelte build step", err)
}

// Run Gopack manually on dynamic imports
err = build.GopackDynamic(buildPath, spaPath, siteConfig.Fingerprint)
err = build.GopackDynamic(buildPath, spaPath)
if err != nil {
log.Fatal("\nError in GopackDynamic build step", err)
}
Expand Down
16 changes: 6 additions & 10 deletions cmd/build/gopack.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
var alreadyConvertedFiles []string

// Gopack ensures ESM support for NPM dependencies.
func Gopack(buildPath, spaPath, entrypoint, fingerprint string) error {
func Gopack(buildPath, spaPath, entrypoint string) error {

defer Benchmark(time.Now(), "Running Gopack")

Expand All @@ -54,20 +54,18 @@ func Gopack(buildPath, spaPath, entrypoint, fingerprint string) error {
alreadyConvertedFiles = []string{}

// Start at the entry point for the app
err := runPack(buildPath, spaPath, entrypoint, fingerprint)
err := runPack(buildPath, spaPath, entrypoint)
if err != nil {
return err
}

return nil
}

func runPack(buildPath, spaPath, convertPath, fingerprint string) error {
func runPack(buildPath, spaPath, convertPath string) error {
// Destination path for dependencies
gopackDir := spaPath + "web_modules"

// Remove query string to read file
convertPath = strings.Split(convertPath, "?")[0]
// Get the actual contents of the file we want to convert
contentBytes, err := ioutil.ReadFile(convertPath)
if err != nil {
Expand Down Expand Up @@ -99,8 +97,6 @@ func runPack(buildPath, spaPath, convertPath, fingerprint string) error {
pathStr := string(pathBytes)
// Remove single or double quotes around path.
pathStr = strings.Trim(pathStr, `'"`)
// Remove query string so path can be found
pathStr = strings.Split(pathStr, "?")[0]
// Intitialize the string that determines if we found the import path.
var foundPath string
// Initialize the full path of the import.
Expand Down Expand Up @@ -193,7 +189,7 @@ func runPack(buildPath, spaPath, convertPath, fingerprint string) error {
// Add the current file to list of already converted files.
alreadyConvertedFiles = append(alreadyConvertedFiles, fullPathStr)
// Use fullPathStr recursively to find its imports.
err = runPack(buildPath, spaPath, fullPathStr, fingerprint)
err = runPack(buildPath, spaPath, fullPathStr)
if err != nil {
return fmt.Errorf("\nCan't runPack on %s %w", fullPathStr, err)
}
Expand All @@ -202,8 +198,8 @@ func runPack(buildPath, spaPath, convertPath, fingerprint string) error {
if foundPath != "" {
// Remove "public" build dir from path.
replacePath := strings.Replace(foundPath, buildPath, "", 1)
// Wrap path in quotes and add query params to break cache.
replacePath = "'" + replacePath + "?" + fingerprint + "'"
// Wrap path in quotes.
replacePath = "'" + replacePath + "'"
// Convert string path to bytes.
replacePathBytes := []byte(replacePath)
// Actually replace the path to the dependency in the source content.
Expand Down
4 changes: 2 additions & 2 deletions cmd/build/gopack_dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Create ESM support for files that don't have static imports in the app
func GopackDynamic(buildPath, spaPath, fingerprint string) error {
func GopackDynamic(buildPath string, spaPath string) error {

defer Benchmark(time.Now(), "Running GopackDynamic")

Expand All @@ -27,7 +27,7 @@ func GopackDynamic(buildPath, spaPath, fingerprint string) error {
if info.IsDir() {
return nil
}
err = Gopack(buildPath, spaPath, spaPath+fieldWidgetPath+"/"+path, fingerprint)
err = Gopack(buildPath, spaPath, spaPath+fieldWidgetPath+"/"+path)
if err != nil {
return fmt.Errorf("\nError running Gopack for custom FieldWidget: %w", err)
}
Expand Down

0 comments on commit 9ac9d24

Please sign in to comment.