Use prettier
This commit is contained in:
parent
cef6bd975a
commit
be07bb510f
4 changed files with 93 additions and 75 deletions
4
.prettierrc.json
Normal file
4
.prettierrc.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "^1.1.6"
|
"@types/bun": "^1.1.6",
|
||||||
|
"prettier": "^3.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
39
src/index.ts
39
src/index.ts
|
@ -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,7 +103,10 @@ 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) {
|
||||||
|
|
Loading…
Reference in a new issue