From d1afd66362bd384b02396c7c95e1958f752da220 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 20 Jun 2018 14:29:21 -0700 Subject: [PATCH] Remove all generated hashes from SPA templates (#11) --- .../Templates/AngularTemplate.cs | 22 ++++++++---------- .../Templates/ReactReduxTemplate.cs | 9 +------- AspNetCoreSdkTests/Templates/ReactTemplate.cs | 23 +++++++++++-------- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/AspNetCoreSdkTests/Templates/AngularTemplate.cs b/AspNetCoreSdkTests/Templates/AngularTemplate.cs index bd858349d8..9dc493d0e2 100644 --- a/AspNetCoreSdkTests/Templates/AngularTemplate.cs +++ b/AspNetCoreSdkTests/Templates/AngularTemplate.cs @@ -11,11 +11,9 @@ namespace AspNetCoreSdkTests.Templates public override string Name => "angular"; - // For some reason, the generated hash in main.[HASH].bundle.js is different on Windows and Linux, despite - // the file contents being identical. Replacing the generated hash with "[HASH]" allows the tests to pass - // on both platforms. + // Remove generated hashes since they may vary by platform public override IEnumerable FilesAfterPublish => - base.FilesAfterPublish.Select(f => Regex.Replace(f, @"main\.[0-9a-f]+\.bundle\.js$", "main.[HASH].bundle.js")); + base.FilesAfterPublish.Select(f => Regex.Replace(f, @"\.[0-9a-f]{20}\.", ".[HASH].")); public override IEnumerable ExpectedFilesAfterPublish => base.ExpectedFilesAfterPublish @@ -23,16 +21,16 @@ namespace AspNetCoreSdkTests.Templates { Path.Combine("wwwroot", "favicon.ico"), Path.Combine("ClientApp", "dist", "3rdpartylicenses.txt"), - Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.448c34a56d699c29117a.woff2"), - Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.89889688147bd7575d63.svg"), - Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.e18bbf611f2a2e43afc0.ttf"), - Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.f4769f9bdb7466be6508.eot"), - Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.fa2772327f55d8198301.woff"), + Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.[HASH].woff2"), + Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.[HASH].svg"), + Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.[HASH].ttf"), + Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.[HASH].eot"), + Path.Combine("ClientApp", "dist", "glyphicons-halflings-regular.[HASH].woff"), Path.Combine("ClientApp", "dist", "index.html"), - Path.Combine("ClientApp", "dist", "inline.318b50c57b4eba3d437b.bundle.js"), + Path.Combine("ClientApp", "dist", "inline.[HASH].bundle.js"), Path.Combine("ClientApp", "dist", "main.[HASH].bundle.js"), - Path.Combine("ClientApp", "dist", "polyfills.bf95165a1d5098766b92.bundle.js"), - Path.Combine("ClientApp", "dist", "styles.2727681ffee5a66f9fe6.bundle.css"), + Path.Combine("ClientApp", "dist", "polyfills.[HASH].bundle.js"), + Path.Combine("ClientApp", "dist", "styles.[HASH].bundle.css"), }); } } diff --git a/AspNetCoreSdkTests/Templates/ReactReduxTemplate.cs b/AspNetCoreSdkTests/Templates/ReactReduxTemplate.cs index 8e89ba0817..bcbc5fc8c1 100644 --- a/AspNetCoreSdkTests/Templates/ReactReduxTemplate.cs +++ b/AspNetCoreSdkTests/Templates/ReactReduxTemplate.cs @@ -1,16 +1,9 @@ -using System.Collections.Generic; -using System.Linq; - -namespace AspNetCoreSdkTests.Templates +namespace AspNetCoreSdkTests.Templates { public class ReactReduxTemplate : ReactTemplate { public ReactReduxTemplate() { } public override string Name => "reactredux"; - - public override IEnumerable ExpectedFilesAfterPublish => - from f in base.ExpectedFilesAfterPublish - select f.Replace("main.31eb739b.js", "main.485d93fa.js"); } } diff --git a/AspNetCoreSdkTests/Templates/ReactTemplate.cs b/AspNetCoreSdkTests/Templates/ReactTemplate.cs index 20b5203279..a0fc738623 100644 --- a/AspNetCoreSdkTests/Templates/ReactTemplate.cs +++ b/AspNetCoreSdkTests/Templates/ReactTemplate.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; namespace AspNetCoreSdkTests.Templates { @@ -10,6 +11,10 @@ namespace AspNetCoreSdkTests.Templates public override string Name => "react"; + // Remove generated hashes since they may var by platform + public override IEnumerable FilesAfterPublish => + base.FilesAfterPublish.Select(f => Regex.Replace(f, @"\.[0-9a-f]{8}\.", ".[HASH].")); + public override IEnumerable ExpectedFilesAfterPublish => base.ExpectedFilesAfterPublish .Concat(new[] @@ -19,15 +24,15 @@ namespace AspNetCoreSdkTests.Templates Path.Combine("ClientApp", "build", "index.html"), Path.Combine("ClientApp", "build", "manifest.json"), Path.Combine("ClientApp", "build", "service-worker.js"), - Path.Combine("ClientApp", "build", "static", "css", "main.8302bbea.css"), - Path.Combine("ClientApp", "build", "static", "css", "main.8302bbea.css.map"), - Path.Combine("ClientApp", "build", "static", "js", "main.31eb739b.js"), - Path.Combine("ClientApp", "build", "static", "js", "main.31eb739b.js.map"), - Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.448c34a5.woff2"), - Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.89889688.svg"), - Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.e18bbf61.ttf"), - Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.f4769f9b.eot"), - Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.fa277232.woff"), + Path.Combine("ClientApp", "build", "static", "css", "main.[HASH].css"), + Path.Combine("ClientApp", "build", "static", "css", "main.[HASH].css.map"), + Path.Combine("ClientApp", "build", "static", "js", "main.[HASH].js"), + Path.Combine("ClientApp", "build", "static", "js", "main.[HASH].js.map"), + Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.[HASH].woff2"), + Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.[HASH].svg"), + Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.[HASH].ttf"), + Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.[HASH].eot"), + Path.Combine("ClientApp", "build", "static", "media", "glyphicons-halflings-regular.[HASH].woff"), }); } }