From 9ac9d243b33824dc797a4db042201ea771e81224 Mon Sep 17 00:00:00 2001 From: jimafisk Date: Thu, 2 May 2024 14:35:31 -0400 Subject: [PATCH] Revert "Fingerprint each spa file to break cache (#320)." This reverts commit d84c8e0bd32af3d3c0bf92fb727ce492bb325b12. --- cmd/build.go | 6 +++--- cmd/build/gopack.go | 16 ++++++---------- cmd/build/gopack_dynamic.go | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index 6817b834..74ca2fb3 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -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) } diff --git a/cmd/build/gopack.go b/cmd/build/gopack.go index 32e16017..39d9a95d 100644 --- a/cmd/build/gopack.go +++ b/cmd/build/gopack.go @@ -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") @@ -54,7 +54,7 @@ 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 } @@ -62,12 +62,10 @@ func Gopack(buildPath, spaPath, entrypoint, fingerprint string) error { 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 { @@ -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. @@ -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) } @@ -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. diff --git a/cmd/build/gopack_dynamic.go b/cmd/build/gopack_dynamic.go index 525dfe98..17c3821b 100644 --- a/cmd/build/gopack_dynamic.go +++ b/cmd/build/gopack_dynamic.go @@ -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") @@ -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) }