merge: 최신 main의 수치 상태 정책을 통합한다
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
import { readdir, readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
|
||||
const root = process.cwd();
|
||||
const sourceRoots = ['app', 'packages'];
|
||||
const inventoryPath = path.join(root, 'docs', 'ref-compatibility-shims.md');
|
||||
const beginPattern = /REF-COMPAT:BEGIN ([a-z0-9]+(?:-[a-z0-9]+)*)/g;
|
||||
const endPattern = /REF-COMPAT:END ([a-z0-9]+(?:-[a-z0-9]+)*)/g;
|
||||
const inventoryPattern = /<!-- REF-COMPAT-ID: ([a-z0-9]+(?:-[a-z0-9]+)*) -->/g;
|
||||
const sourceExtensions = new Set(['.ts', '.tsx', '.vue', '.js', '.mjs', '.cjs']);
|
||||
const ignoredDirectories = new Set(['node_modules', 'dist', 'coverage', '.turbo']);
|
||||
|
||||
const collectFiles = async (directory) => {
|
||||
const entries = await readdir(directory, { withFileTypes: true });
|
||||
const files = [];
|
||||
for (const entry of entries) {
|
||||
const absolute = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (ignoredDirectories.has(entry.name)) {
|
||||
continue;
|
||||
}
|
||||
files.push(...(await collectFiles(absolute)));
|
||||
} else if (sourceExtensions.has(path.extname(entry.name))) {
|
||||
files.push(absolute);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
};
|
||||
|
||||
const fail = (message) => {
|
||||
process.stderr.write(`ref compatibility marker check failed: ${message}\n`);
|
||||
process.exitCode = 1;
|
||||
};
|
||||
|
||||
const regionsById = new Map();
|
||||
for (const sourceRoot of sourceRoots) {
|
||||
for (const file of await collectFiles(path.join(root, sourceRoot))) {
|
||||
const relative = path.relative(root, file);
|
||||
const lines = (await readFile(file, 'utf8')).split(/\r?\n/);
|
||||
let openRegion = null;
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const lineNumber = index + 1;
|
||||
const begins = [...lines[index].matchAll(beginPattern)].map((match) => match[1]);
|
||||
const ends = [...lines[index].matchAll(endPattern)].map((match) => match[1]);
|
||||
if (begins.length + ends.length > 1) {
|
||||
fail(`${relative}:${lineNumber} contains more than one marker`);
|
||||
continue;
|
||||
}
|
||||
if (begins.length === 1) {
|
||||
if (openRegion) {
|
||||
fail(`${relative}:${lineNumber} nests ${begins[0]} inside ${openRegion.id}`);
|
||||
} else {
|
||||
openRegion = { id: begins[0], line: lineNumber };
|
||||
}
|
||||
}
|
||||
if (ends.length === 1) {
|
||||
if (!openRegion) {
|
||||
fail(`${relative}:${lineNumber} closes ${ends[0]} without a BEGIN marker`);
|
||||
} else if (openRegion.id !== ends[0]) {
|
||||
fail(`${relative}:${lineNumber} closes ${ends[0]} but ${openRegion.id} is open`);
|
||||
} else {
|
||||
const regions = regionsById.get(openRegion.id) ?? [];
|
||||
regions.push(`${relative}:${openRegion.line}-${lineNumber}`);
|
||||
regionsById.set(openRegion.id, regions);
|
||||
openRegion = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (openRegion) {
|
||||
fail(`${relative}:${openRegion.line} leaves ${openRegion.id} open`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const inventory = await readFile(inventoryPath, 'utf8');
|
||||
const inventoryIds = [...inventory.matchAll(inventoryPattern)].map((match) => match[1]);
|
||||
const uniqueInventoryIds = new Set(inventoryIds);
|
||||
if (uniqueInventoryIds.size !== inventoryIds.length) {
|
||||
fail('the inventory contains a duplicate REF-COMPAT-ID');
|
||||
}
|
||||
|
||||
for (const id of regionsById.keys()) {
|
||||
if (!uniqueInventoryIds.has(id)) {
|
||||
fail(`${id} is marked in source but missing from docs/ref-compatibility-shims.md`);
|
||||
}
|
||||
}
|
||||
for (const id of uniqueInventoryIds) {
|
||||
if (!regionsById.has(id)) {
|
||||
fail(`${id} is documented but has no source region`);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.exitCode) {
|
||||
process.exit(process.exitCode);
|
||||
}
|
||||
|
||||
const regionCount = [...regionsById.values()].reduce((sum, regions) => sum + regions.length, 0);
|
||||
process.stdout.write(
|
||||
`ref compatibility markers: ${regionsById.size} ids, ${regionCount} source regions, inventory synchronized\n`
|
||||
);
|
||||
@@ -1,12 +1,10 @@
|
||||
import { GameClock, LiteHashDRBG, RandUtil, type RNG } from '@sammo-ts/common';
|
||||
import { readLegacyStoredFloat } from '@sammo-ts/logic/compat/legacyFloat.js';
|
||||
import {
|
||||
GENERAL_TURN_COMMAND_KEYS,
|
||||
isSelectableGeneralTurnCommandKey,
|
||||
LogFormat,
|
||||
NATION_TURN_COMMAND_KEYS,
|
||||
normalizeScenarioEffect,
|
||||
readLegacyCityTrust,
|
||||
sendMessage,
|
||||
type MapDefinition,
|
||||
type MessageDraft,
|
||||
@@ -934,10 +932,7 @@ const projectWorld = (
|
||||
conflict: city.conflict ?? {},
|
||||
state: city.state,
|
||||
term: readNumber(city.meta, 'term'),
|
||||
// The reference snapshot observes MariaDB FLOAT through its text
|
||||
// protocol. Project the in-memory binary32 value at that same
|
||||
// read boundary before comparing state deltas.
|
||||
trust: readLegacyCityTrust(readNumber(city.meta, 'trust')),
|
||||
trust: readNumber(city.meta, 'trust'),
|
||||
trade: readNumber(city.meta, 'trade'),
|
||||
officerSet: readNumber(city.meta, 'officer_set'),
|
||||
})),
|
||||
@@ -950,7 +945,7 @@ const projectWorld = (
|
||||
capitalCityId: nation.capitalCityId,
|
||||
gold: toDatabaseInt(nation.gold),
|
||||
rice: toDatabaseInt(nation.rice),
|
||||
tech: readLegacyStoredFloat(readNumber(nation.meta, 'tech')),
|
||||
tech: readNumber(nation.meta, 'tech'),
|
||||
level: nation.level,
|
||||
typeCode: nation.typeCode,
|
||||
generalCount: readNumber(
|
||||
|
||||
Reference in New Issue
Block a user