Skip to content

Commit

Permalink
trigger manifest updates on prod in an obviously wrong manner
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed Apr 9, 2024
1 parent bac6f87 commit a5d08e2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/templating/AssetHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait AssetHelper extends HasEnv:

def assetVersion = AssetVersion.current

def updateManifest = if !env.net.isProd then env.manifest.update
def updateManifest = if !env.net.isProd || AssetVersion.checkResetDirty then env.manifest.update

// bump flairs version if a flair is changed only (not added or removed)
val flairVersion = "______2"
Expand Down
2 changes: 1 addition & 1 deletion app/views/base/layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ object layout:
withHrefLangs: Option[LangPath] = None
)(body: Frag)(using ctx: PageContext): Frag =
import ctx.pref
if !netConfig.isProd then updateManifest
updateManifest
frag(
doctype,
htmlTag(
Expand Down
8 changes: 8 additions & 0 deletions modules/core/src/main/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ object ApiVersion extends OpaqueInt[ApiVersion]:
opaque type AssetVersion = String
object AssetVersion extends OpaqueString[AssetVersion]:
private var stored = random
private var dirty = true
def current = stored
def change() =
stored = random
dirty = true
current
def checkResetDirty =
if dirty then
dirty = false
true
else false

private def random = AssetVersion(SecureRandom.nextString(6))
case class Changed(version: AssetVersion)

Expand Down
16 changes: 4 additions & 12 deletions ui/.build/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,10 @@ async function hashMove(src: string) {
const content = await fs.promises.readFile(src, 'utf-8');
const hash = crypto.createHash('sha256').update(content).digest('hex').slice(0, 8);
const basename = path.basename(src, '.css');
const srcMapMove = env.prod
? Promise.resolve()
: /*new Promise<void>(async resolve => {
const mapContent = await fs.promises.readFile(`${src}.map`, 'utf-8');
const cssMap = JSON.parse(mapContent);
cssMap.file = `${basename}.${hash}.css`;
await fs.promises.writeFile(path.join(env.cssDir, `${basename}.css.map`), JSON.stringify(cssMap));
resolve();*/
fs.promises.rename(`${src}.map`, path.join(env.cssDir, `${basename}.css.map`));
//});
await fs.promises.rename(src, path.join(env.cssDir, `${basename}.${hash}.css`));
await srcMapMove;
await Promise.allSettled([
env.prod ? undefined : fs.promises.rename(`${src}.map`, path.join(env.cssDir, `${basename}.css.map`)),
fs.promises.rename(src, path.join(env.cssDir, `${basename}.${hash}.css`)),
]);
return [path.basename(src, '.css'), hash];
}

Expand Down

0 comments on commit a5d08e2

Please sign in to comment.