Use prettier

This commit is contained in:
Wingy 2024-08-17 06:04:33 -04:00
parent cef6bd975a
commit 48ab85b939
4 changed files with 93 additions and 75 deletions

4
.prettierrc.json Normal file
View file

@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}

BIN
bun.lockb

Binary file not shown.

View file

@ -1,5 +1,6 @@
{ {
"devDependencies": { "devDependencies": {
"@types/bun": "^1.1.6" "@types/bun": "^1.1.6",
"prettier": "^3.3.3"
} }
} }

View file

@ -43,12 +43,17 @@ function getSourcemap(root: string): Promise<RojoSourcemap> {
}) })
} }
function prefixSourcemap(sourcemap: RojoSourcemap, prefix: string): RojoSourcemap { function prefixSourcemap(
sourcemap: RojoSourcemap,
prefix: string,
): RojoSourcemap {
return { return {
name: sourcemap.name, name: sourcemap.name,
className: sourcemap.className, className: sourcemap.className,
filePaths: sourcemap.filePaths?.map(path => `${prefix}/${path}`), filePaths: sourcemap.filePaths?.map((path) => `${prefix}/${path}`),
children: sourcemap.children?.map(child => prefixSourcemap(child, prefix)), children: sourcemap.children?.map((child) =>
prefixSourcemap(child, prefix),
),
} }
} }
@ -63,28 +68,33 @@ function mergeSourcemaps(sourcemaps: RojoSourcemap[]): RojoSourcemap {
name: '', name: '',
className: '', className: '',
filePaths: [], filePaths: [],
children: [] children: [],
}; }
for (const sourcemap of sourcemaps) { for (const sourcemap of sourcemaps) {
merged.name = sourcemap.name; merged.name = sourcemap.name
merged.className = sourcemap.className; merged.className = sourcemap.className
if (sourcemap.filePaths) { if (sourcemap.filePaths) {
merged.filePaths = sourcemap.filePaths; merged.filePaths = sourcemap.filePaths
} }
for (const child of sourcemap.children ?? []) { for (const child of sourcemap.children ?? []) {
const existingChild = merged.children.findIndex(oldChild => oldChild.name === child.name); const existingChild = merged.children.findIndex(
(oldChild) => oldChild.name === child.name,
)
if (existingChild !== -1) { if (existingChild !== -1) {
merged.children[existingChild] = mergeSourcemaps([merged.children[existingChild], child]); merged.children[existingChild] = mergeSourcemaps([
merged.children[existingChild],
child,
])
} else { } else {
merged.children.push(child); merged.children.push(child)
} }
} }
} }
return merged; return merged
} }
async function rebuild() { async function rebuild() {
@ -93,11 +103,14 @@ async function rebuild() {
getPrefixedSourcemap('Core'), getPrefixedSourcemap('Core'),
]) ])
const sourcemap = mergeSourcemaps(sourcemaps) const sourcemap = mergeSourcemaps(sourcemaps)
await fs.promises.writeFile('sourcemap.json', JSON.stringify(sourcemap, null, 2)) await fs.promises.writeFile(
'sourcemap.json',
JSON.stringify(sourcemap, null, 2),
)
} }
for (const root of SOURCE_ROOTS) { for (const root of SOURCE_ROOTS) {
fs.watch(root, {recursive:true}, () => { fs.watch(root, { recursive: true }, () => {
sourcemapCache.delete(root) sourcemapCache.delete(root)
rebuild() rebuild()
}) })