Skip to content

Commit

Permalink
Merge branch 'master' into teams-white-first
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jul 4, 2024
2 parents 6e75f04 + 025c743 commit 733b2fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 2 additions & 1 deletion ui/.build/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { sass, stopSass } from './sass';
import { esbuild, stopEsbuild } from './esbuild';
import { copies, stopCopies } from './copies';
import { startMonitor, stopMonitor } from './monitor';
import { initManifest } from './manifest';
import { initManifest, writeManifest } from './manifest';
import { clean } from './clean';
import { LichessModule, env, errorMark, colors as c } from './main';

Expand Down Expand Up @@ -50,6 +50,7 @@ export async function stop() {
}

export function postBuild() {
writeManifest();
for (const mod of env.building) {
mod.post.forEach((args: string[]) => {
env.log(`[${c.grey(mod.name)}] exec - ${c.cyanBold(args.join(' '))}`);
Expand Down
5 changes: 2 additions & 3 deletions ui/.build/src/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ export async function esbuild(tsc?: Promise<void>): Promise<void> {
const onEndPlugin = {
name: 'onEnd',
setup(build: es.PluginBuild) {
build.onEnd((result: es.BuildResult) => {
build.onEnd(async (result: es.BuildResult) => {
for (const err of result.errors) esbuildMessage(err, true);
for (const warn of result.warnings) esbuildMessage(warn);
if (result.errors.length === 0) await jsManifest(result.metafile!);
env.done(result.errors.length, 'esbuild');
if (result.errors.length) return;
jsManifest(result.metafile!);
});
},
};
Expand Down
31 changes: 16 additions & 15 deletions ui/.build/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { allSources } from './sass';

type Manifest = { [key: string]: { hash?: string; imports?: string[] } };

const current: { js: Manifest; css: Manifest } = { js: {}, css: {} };
const current: { js: Manifest; css: Manifest; dirty: boolean } = { js: {}, css: {}, dirty: false };
let writeTimer: NodeJS.Timeout;

export async function initManifest() {
if (env.building.length === env.modules.size) return;
// we're building a subset of modules. if possible reuse the previously built full manifest to give us
// we're building a subset of modules. reuse the previousl full manifest for
// a shot at changes viewable in the browser, otherwise punt.
if (!fs.existsSync(env.manifestFile)) return;
if (Object.keys(current.js).length && Object.keys(current.css).length) return;
Expand All @@ -24,15 +24,20 @@ export async function initManifest() {
current.css = manifest.css;
}

export async function writeManifest() {
if (!current.dirty) return;
clearTimeout(writeTimer);
writeTimer = setTimeout(write, 500);
}

export async function css() {
const files = await globArray(path.join(env.cssTempDir, '*.css'), { abs: true });
const css: { name: string; hash: string }[] = await Promise.all(files.map(hashMove));
const newCssManifest: Manifest = {};
for (const { name, hash } of css) newCssManifest[name] = { hash };
if (enumerableEquivalence(newCssManifest, current.css)) return;
if (isEquivalent(newCssManifest, current.css)) return;
current.css = shallowSort({ ...current.css, ...newCssManifest });
clearTimeout(writeTimer);
writeTimer = setTimeout(write, 500);
current.dirty = true;
}

export async function js(meta: es.Metafile) {
Expand All @@ -53,10 +58,9 @@ export async function js(meta: es.Metafile) {
}
newJsManifest[out.name].imports = imports;
}
if (enumerableEquivalence(newJsManifest, current.js) && fs.existsSync(env.manifestFile)) return;
if (isEquivalent(newJsManifest, current.js) && fs.existsSync(env.manifestFile)) return;
current.js = shallowSort({ ...current.js, ...newJsManifest });
clearTimeout(writeTimer);
writeTimer = setTimeout(write, 500);
current.dirty = true;
}

async function write() {
Expand Down Expand Up @@ -98,6 +102,7 @@ async function write() {
JSON.stringify(serverManifest, null, env.prod ? undefined : 2),
),
]);
current.dirty = false;
env.log(`Manifest hash ${c.green(hash)}`);
}

Expand Down Expand Up @@ -142,20 +147,16 @@ function parsePath(path: string) {
return match ? { name: match[1], hash: match[2] } : undefined;
}

function enumerableEquivalence(a: any, b: any): boolean {
function isEquivalent(a: any, b: any): boolean {
if (a === b) return true;
if (typeof a !== typeof b) return false;
if (Array.isArray(a))
return (
Array.isArray(b) &&
a.length === b.length &&
a.every(x => b.find((y: any) => enumerableEquivalence(x, y)))
);
return Array.isArray(b) && a.length === b.length && a.every(x => b.find((y: any) => isEquivalent(x, y)));
if (typeof a !== 'object') return false;
const [aKeys, bKeys] = [Object.keys(a), Object.keys(b)];
if (aKeys.length !== bKeys.length) return false;
for (const key of aKeys) {
if (!bKeys.includes(key) || !enumerableEquivalence(a[key], b[key])) return false;
if (!bKeys.includes(key) || !isEquivalent(a[key], b[key])) return false;
}
return true;
}
3 changes: 3 additions & 0 deletions ui/common/css/component/_lichess-pgn-viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
--c-lpv-bg-pane: #{$m-bg-zebra2--fade-1};
--c-lpv-pgn-text: #{$c-bg-zebra2};
--c-lpv-font: #{$c-font};
// TODO: erase or replace with `--c-lpv-past-moves` when lpv-pgn-viewer > 2.1.0 is out
--c-lpv-font-accent: #{$c-font};

--c-lpv-font-shy: #{$c-font-dim};
--c-lpv-accent-over: #{$c-over};
--c-lpv-fbt-hover: #{$m-primary_bg--mix-75};
Expand Down

0 comments on commit 733b2fa

Please sign in to comment.