@tanstack/router-generator
Advanced tools
Comparing version 1.32.10 to 1.33.8
@@ -418,6 +418,7 @@ import path from "path"; | ||
var _a, _b; | ||
const filePathId = removeTrailingUnderscores(routeNode.routePath); | ||
const id = removeGroups(filePathId ?? ""); | ||
const [filePathId, routeId] = getFilePathIdAndRouteIdFromPath( | ||
routeNode.routePath | ||
); | ||
return `'${filePathId}': { | ||
id: '${id}' | ||
id: '${routeId}' | ||
path: '${inferPath(routeNode)}' | ||
@@ -436,10 +437,49 @@ fullPath: '${inferFullPath(routeNode)}' | ||
].filter(Boolean).join("\n\n"); | ||
const routeConfigFileContent = await prettier.format(routeImports, { | ||
semi: config.semicolons, | ||
singleQuote: config.quoteStyle === "single", | ||
parser: "typescript" | ||
}); | ||
const routeTreeContent = await fsp.readFile(path.resolve(config.generatedRouteTree), "utf-8").catch((err) => { | ||
const routeManifest = JSON.stringify( | ||
{ | ||
routes: { | ||
__root__: { | ||
filePath: rootRouteNode == null ? void 0 : rootRouteNode.filePath, | ||
children: routeTree.map( | ||
(d) => getFilePathIdAndRouteIdFromPath(d.routePath)[1] | ||
) | ||
}, | ||
...Object.fromEntries( | ||
routeNodes.map((d) => { | ||
var _a, _b; | ||
const [filePathId, routeId] = getFilePathIdAndRouteIdFromPath( | ||
d.routePath | ||
); | ||
return [ | ||
routeId, | ||
{ | ||
filePath: d.filePath, | ||
parent: ((_a = d.parent) == null ? void 0 : _a.routePath) ? getFilePathIdAndRouteIdFromPath(d.parent.routePath)[1] : void 0, | ||
children: (_b = d.children) == null ? void 0 : _b.map( | ||
(childRoute) => getFilePathIdAndRouteIdFromPath(childRoute.routePath)[1] | ||
) | ||
} | ||
]; | ||
}) | ||
) | ||
} | ||
}, | ||
null, | ||
2 | ||
); | ||
const routeConfigFileContent = [ | ||
await prettier.format(routeImports, { | ||
semi: config.semicolons, | ||
singleQuote: config.quoteStyle === "single", | ||
parser: "typescript" | ||
}), | ||
["/* ROUTE_MANIFEST_START", routeManifest, "ROUTE_MANIFEST_END */"].join( | ||
"\n" | ||
) | ||
].join("\n\n"); | ||
if (!checkLatest()) | ||
return; | ||
const existingRouteTreeContent = await fsp.readFile(path.resolve(config.generatedRouteTree), "utf-8").catch((err) => { | ||
if (err.code === "ENOENT") { | ||
return void 0; | ||
return ""; | ||
} | ||
@@ -450,8 +490,8 @@ throw err; | ||
return; | ||
if (routeTreeContent !== routeConfigFileContent) { | ||
await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), { | ||
recursive: true | ||
}); | ||
if (!checkLatest()) | ||
return; | ||
await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), { | ||
recursive: true | ||
}); | ||
if (!checkLatest()) | ||
return; | ||
if (existingRouteTreeContent !== routeConfigFileContent) { | ||
await fsp.writeFile( | ||
@@ -461,2 +501,4 @@ path.resolve(config.generatedRouteTree), | ||
); | ||
if (!checkLatest()) | ||
return; | ||
} | ||
@@ -557,2 +599,7 @@ logger.log( | ||
}; | ||
function getFilePathIdAndRouteIdFromPath(pathname) { | ||
const filePathId = removeTrailingUnderscores(pathname); | ||
const id = removeGroups(filePathId ?? ""); | ||
return [filePathId, id]; | ||
} | ||
export { | ||
@@ -559,0 +606,0 @@ generator, |
{ | ||
"name": "@tanstack/router-generator", | ||
"version": "1.32.10", | ||
"version": "1.33.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Tanner Linsley", |
@@ -586,7 +586,8 @@ import path from 'path' | ||
.map((routeNode) => { | ||
const filePathId = removeTrailingUnderscores(routeNode.routePath) | ||
const id = removeGroups(filePathId ?? '') | ||
const [filePathId, routeId] = getFilePathIdAndRouteIdFromPath( | ||
routeNode.routePath!, | ||
) | ||
return `'${filePathId}': { | ||
id: '${id}' | ||
id: '${routeId}' | ||
path: '${inferPath(routeNode)}' | ||
@@ -615,14 +616,58 @@ fullPath: '${inferFullPath(routeNode)}' | ||
const routeConfigFileContent = await prettier.format(routeImports, { | ||
semi: config.semicolons, | ||
singleQuote: config.quoteStyle === 'single', | ||
parser: 'typescript', | ||
}) | ||
const routeManifest = JSON.stringify( | ||
{ | ||
routes: { | ||
__root__: { | ||
filePath: rootRouteNode?.filePath, | ||
children: routeTree.map( | ||
(d) => getFilePathIdAndRouteIdFromPath(d.routePath!)[1], | ||
), | ||
}, | ||
...Object.fromEntries( | ||
routeNodes.map((d) => { | ||
const [filePathId, routeId] = getFilePathIdAndRouteIdFromPath( | ||
d.routePath!, | ||
) | ||
const routeTreeContent = await fsp | ||
return [ | ||
routeId, | ||
{ | ||
filePath: d.filePath, | ||
parent: d.parent?.routePath | ||
? getFilePathIdAndRouteIdFromPath(d.parent.routePath)[1] | ||
: undefined, | ||
children: d.children?.map( | ||
(childRoute) => | ||
getFilePathIdAndRouteIdFromPath(childRoute.routePath!)[1], | ||
), | ||
}, | ||
] | ||
}), | ||
), | ||
}, | ||
}, | ||
null, | ||
2, | ||
) | ||
const routeConfigFileContent = [ | ||
await prettier.format(routeImports, { | ||
semi: config.semicolons, | ||
singleQuote: config.quoteStyle === 'single', | ||
parser: 'typescript', | ||
}), | ||
['/* ROUTE_MANIFEST_START', routeManifest, 'ROUTE_MANIFEST_END */'].join( | ||
'\n', | ||
), | ||
].join('\n\n') | ||
if (!checkLatest()) return | ||
const existingRouteTreeContent = await fsp | ||
.readFile(path.resolve(config.generatedRouteTree), 'utf-8') | ||
.catch((err: any) => { | ||
.catch((err) => { | ||
if (err.code === 'ENOENT') { | ||
return undefined | ||
return '' | ||
} | ||
throw err | ||
@@ -633,7 +678,11 @@ }) | ||
if (routeTreeContent !== routeConfigFileContent) { | ||
await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), { | ||
recursive: true, | ||
}) | ||
if (!checkLatest()) return | ||
// Ensure the directory exists | ||
await fsp.mkdir(path.dirname(path.resolve(config.generatedRouteTree)), { | ||
recursive: true, | ||
}) | ||
if (!checkLatest()) return | ||
// Write the route tree file, if it has changed | ||
if (existingRouteTreeContent !== routeConfigFileContent) { | ||
await fsp.writeFile( | ||
@@ -643,2 +692,3 @@ path.resolve(config.generatedRouteTree), | ||
) | ||
if (!checkLatest()) return | ||
} | ||
@@ -819,1 +869,8 @@ | ||
} | ||
function getFilePathIdAndRouteIdFromPath(pathname: string) { | ||
const filePathId = removeTrailingUnderscores(pathname) | ||
const id = removeGroups(filePathId ?? '') | ||
return [filePathId, id] as const | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182375
2368