@tanstack/router-cli
Advanced tools
Comparing version 0.0.1-beta.47 to 0.0.1-beta.56
@@ -122,8 +122,4 @@ /** | ||
const reparented = await reparent(config.routesDirectory); | ||
async function buildRouteConfig(nodes, depth) { | ||
if (depth === void 0) { | ||
depth = 1; | ||
} | ||
async function buildRouteConfig(nodes, depth = 1) { | ||
const children = nodes.map(async n => { | ||
var _node$children; | ||
let node = nodeCache.find(d => d.fullPath === n.fullPath); | ||
@@ -178,13 +174,9 @@ if (node) { | ||
})); | ||
imports = transforms.filter(_ref => { | ||
let { | ||
exported | ||
} = _ref; | ||
return exported; | ||
}); | ||
node.importedFiles = await Promise.all(imports.map(_ref2 => { | ||
let { | ||
key, | ||
code | ||
} = _ref2; | ||
imports = transforms.filter(({ | ||
exported | ||
}) => exported); | ||
node.importedFiles = await Promise.all(imports.map(({ | ||
key, | ||
code | ||
}) => { | ||
const importFilename = `${node.genPathNoExt}-${key}.tsx`; | ||
@@ -209,3 +201,3 @@ queueWriteFile(importFilename, code); | ||
const route = `${node.variable}Route`; | ||
if ((_node$children = node.children) != null && _node$children.length) { | ||
if (node.children?.length) { | ||
const childConfigs = await buildRouteConfig(node.children, depth + 1); | ||
@@ -235,4 +227,3 @@ return `${route}.addChildren([\n${spaces(depth * 4)}${childConfigs}\n${spaces(depth * 2)}])`; | ||
if (!checkLatest()) return; | ||
await Promise.all(fileQueue.map(async _ref3 => { | ||
let [filename, content] = _ref3; | ||
await Promise.all(fileQueue.map(async ([filename, content]) => { | ||
await fs__default["default"].ensureDir(path__default["default"].dirname(filename)); | ||
@@ -265,6 +256,3 @@ const exists = await fs__default["default"].pathExists(filename); | ||
} | ||
let node = nodeCache.find(n => { | ||
var _n$importedFiles; | ||
return n.genPath === d || path__default["default"].resolve(n.genDir, n.clientFilename) === d || ((_n$importedFiles = n.importedFiles) == null ? void 0 : _n$importedFiles.includes(d)); | ||
}); | ||
let node = nodeCache.find(n => n.genPath === d || path__default["default"].resolve(n.genDir, n.clientFilename) === d || n.importedFiles?.includes(d)); | ||
return !node; | ||
@@ -311,9 +299,4 @@ }); | ||
} | ||
function multiSortBy(arr, accessors) { | ||
if (accessors === void 0) { | ||
accessors = [d => d]; | ||
} | ||
return arr.map((d, i) => [d, i]).sort((_ref4, _ref5) => { | ||
let [a, ai] = _ref4; | ||
let [b, bi] = _ref5; | ||
function multiSortBy(arr, accessors = [d => d]) { | ||
return arr.map((d, i) => [d, i]).sort(([a, ai], [b, bi]) => { | ||
for (const accessor of accessors) { | ||
@@ -334,6 +317,3 @@ const ao = accessor(a); | ||
return ai - bi; | ||
}).map(_ref6 => { | ||
let [d] = _ref6; | ||
return d; | ||
}); | ||
}).map(([d]) => d); | ||
} | ||
@@ -340,0 +320,0 @@ function capitalize(s) { |
@@ -51,3 +51,2 @@ /** | ||
async function ensureBoilerplate(node, code) { | ||
var _originalFile$code, _originalFile$code2, _file$code, _file$code2; | ||
const relativeImportPath = path__default["default"].relative(node.fullDir, node.genPathNoExt); | ||
@@ -104,10 +103,9 @@ const originalFile = await babel__namespace.transformAsync(code, { | ||
const separator = node.isRoot ? 'createRouteConfig(' : 'routeConfig.generate('; | ||
if (!(originalFile != null && originalFile.code)) { | ||
return `${file == null ? void 0 : file.code}\n\n${separator}{\n\n})`; | ||
if (!originalFile?.code) { | ||
return `${file?.code}\n\n${separator}{\n\n})`; | ||
} | ||
const originalHead = originalFile == null ? void 0 : (_originalFile$code = originalFile.code) == null ? void 0 : _originalFile$code.substring(0, originalFile == null ? void 0 : (_originalFile$code2 = originalFile.code) == null ? void 0 : _originalFile$code2.indexOf(separator)); | ||
const generatedHead = file == null ? void 0 : (_file$code = file.code) == null ? void 0 : _file$code.substring(0, file == null ? void 0 : (_file$code2 = file.code) == null ? void 0 : _file$code2.indexOf(separator)); | ||
const originalHead = originalFile?.code?.substring(0, originalFile?.code?.indexOf(separator)); | ||
const generatedHead = file?.code?.substring(0, file?.code?.indexOf(separator)); | ||
if (originalHead !== generatedHead) { | ||
var _originalFile$code3, _originalFile$code4; | ||
return `${generatedHead}\n\n${originalFile == null ? void 0 : (_originalFile$code3 = originalFile.code) == null ? void 0 : _originalFile$code3.substring(originalFile == null ? void 0 : (_originalFile$code4 = originalFile.code) == null ? void 0 : _originalFile$code4.indexOf(separator))}`; | ||
return `${generatedHead}\n\n${originalFile?.code?.substring(originalFile?.code?.indexOf(separator))}`; | ||
} | ||
@@ -117,4 +115,3 @@ return; | ||
async function isolateOptionToExport(node, code, opts) { | ||
var _await$babel$transfor; | ||
return (_await$babel$transfor = await babel__namespace.transformAsync(code, { | ||
return (await babel__namespace.transformAsync(code, { | ||
configFile: false, | ||
@@ -124,3 +121,3 @@ babelrc: false, | ||
ast: true | ||
})) == null ? void 0 : _await$babel$transfor.code; | ||
}))?.code; | ||
function plugin() { | ||
@@ -138,3 +135,2 @@ return { | ||
if (options) { | ||
var _path$findParent; | ||
const property = options.properties.find(property => { | ||
@@ -145,3 +141,3 @@ return t__namespace.isObjectProperty(property) && t__namespace.isIdentifier(property.key) && property.key.name === opts.isolate; | ||
const program = path.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram()) { | ||
if (program?.isProgram()) { | ||
program.node.body.push(babel__namespace.template.statement(`export const ${opts.isolate} = $LOADER`)({ | ||
@@ -152,3 +148,3 @@ $LOADER: property.value | ||
} | ||
(_path$findParent = path.findParent(d => d.isExpressionStatement())) == null ? void 0 : _path$findParent.remove(); | ||
path.findParent(d => d.isExpressionStatement())?.remove(); | ||
} | ||
@@ -168,3 +164,2 @@ } | ||
if (options) { | ||
var _path$findParent2; | ||
const property = options.properties.find(property => { | ||
@@ -176,3 +171,3 @@ return t__namespace.isObjectProperty(property) && t__namespace.isIdentifier(property.key) && property.key.name === opts.isolate; | ||
const program = path.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram()) { | ||
if (program?.isProgram()) { | ||
program.node.body.push(babel__namespace.template.statement(`export const ${opts.isolate} = $LOADER`)({ | ||
@@ -184,3 +179,3 @@ $LOADER: property.value | ||
} | ||
(_path$findParent2 = path.findParent(d => d.isExpressionStatement())) == null ? void 0 : _path$findParent2.remove(); | ||
path.findParent(d => d.isExpressionStatement())?.remove(); | ||
} | ||
@@ -209,4 +204,3 @@ } | ||
if (t__namespace.isVariableDeclaration(path.node.declaration)) { | ||
var _path$node$declaratio; | ||
if (t__namespace.isVariableDeclarator((_path$node$declaratio = path.node.declaration.declarations) == null ? void 0 : _path$node$declaratio[0])) { | ||
if (t__namespace.isVariableDeclarator(path.node.declaration.declarations?.[0])) { | ||
if (t__namespace.isIdentifier(path.node.declaration.declarations[0].id)) { | ||
@@ -225,4 +219,3 @@ exported.push(path.node.declaration.declarations[0].id.name); | ||
async function generateRouteConfig(node, routeCode, imports, clientOnly) { | ||
var _node$parent, _node$parent2, _node$parent3, _node$parent4, _await$babel$transfor2; | ||
const relativeParentRoutePath = clientOnly ? node.parent ? generator.removeExt(path__default["default"].relative(node.genDir, path__default["default"].resolve((_node$parent = node.parent) == null ? void 0 : _node$parent.genDir, (_node$parent2 = node.parent) == null ? void 0 : _node$parent2.clientFilename))) : `./${generator.rootRouteClientName}` : node.parent ? generator.removeExt(path__default["default"].relative(node.genDir, path__default["default"].resolve((_node$parent3 = node.parent) == null ? void 0 : _node$parent3.genDir, (_node$parent4 = node.parent) == null ? void 0 : _node$parent4.filename))) : `./${generator.rootRouteName}`; | ||
const relativeParentRoutePath = clientOnly ? node.parent ? generator.removeExt(path__default["default"].relative(node.genDir, path__default["default"].resolve(node.parent?.genDir, node.parent?.clientFilename))) : `./${generator.rootRouteClientName}` : node.parent ? generator.removeExt(path__default["default"].relative(node.genDir, path__default["default"].resolve(node.parent?.genDir, node.parent?.filename))) : `./${generator.rootRouteName}`; | ||
const pathName = node.isRoot ? undefined : node.fileNameNoExt.startsWith('__') ? undefined : node.fileNameNoExt === 'index' ? '/' : node.fileNameNoExt; | ||
@@ -243,3 +236,3 @@ const routeId = node.isRoot ? undefined : node.fileNameNoExt; | ||
const program = path.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram()) { | ||
if (program?.isProgram()) { | ||
program.node.body.unshift(babel__namespace.template.statement(`import { routeConfig as parentRouteConfig } from '$IMPORT'`)({ | ||
@@ -258,6 +251,4 @@ $IMPORT: relativeParentRoutePath | ||
if (t__namespace.isCallExpression(iPath.parentPath.node)) { | ||
var _iPath$parentPath$par; | ||
if (t__namespace.isExpressionStatement((_iPath$parentPath$par = iPath.parentPath.parentPath) == null ? void 0 : _iPath$parentPath$par.node)) { | ||
var _iPath$parentPath$par2; | ||
(_iPath$parentPath$par2 = iPath.parentPath.parentPath) == null ? void 0 : _iPath$parentPath$par2.replaceWith(t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(t__namespace.identifier('routeConfig'), iPath.parentPath.node)])); | ||
if (t__namespace.isExpressionStatement(iPath.parentPath.parentPath?.node)) { | ||
iPath.parentPath.parentPath?.replaceWith(t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(t__namespace.identifier('routeConfig'), iPath.parentPath.node)])); | ||
} | ||
@@ -306,7 +297,4 @@ } | ||
const program = iPath.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram() && options) { | ||
const index = program.node.body.findIndex(d => { | ||
var _iPath$parentPath$par3; | ||
return d.start === ((_iPath$parentPath$par3 = iPath.parentPath.parentPath) == null ? void 0 : _iPath$parentPath$par3.node.start); | ||
}); | ||
if (program?.isProgram() && options) { | ||
const index = program.node.body.findIndex(d => d.start === iPath.parentPath.parentPath?.node.start); | ||
if (node.isRoot) { | ||
@@ -339,3 +327,3 @@ program.node.body[index] = babel__namespace.template.statement(`const routeConfig = createRouteConfig( | ||
} | ||
const code = (_await$babel$transfor2 = await babel__namespace.transformAsync(routeCode, { | ||
const code = (await babel__namespace.transformAsync(routeCode, { | ||
configFile: false, | ||
@@ -345,3 +333,3 @@ babelrc: false, | ||
ast: true | ||
})) == null ? void 0 : _await$babel$transfor2.code; | ||
}))?.code; | ||
if (!code) { | ||
@@ -392,7 +380,5 @@ throw new Error('Error while generating a route file!'); | ||
function getRouteConfigGenerateOptions(path) { | ||
var _path$parentPath$pare; | ||
const tryOptions = node => { | ||
if (t__namespace.isIdentifier(node)) { | ||
var _path$scope$getBindin; | ||
const initNode = (_path$scope$getBindin = path.scope.getBinding(node.name)) == null ? void 0 : _path$scope$getBindin.path.node; | ||
const initNode = path.scope.getBinding(node.name)?.path.node; | ||
if (t__namespace.isVariableDeclarator(initNode)) { | ||
@@ -406,5 +392,4 @@ return tryOptions(initNode.init); | ||
}; | ||
if (t__namespace.isMemberExpression(path.parentPath.node) && t__namespace.isCallExpression((_path$parentPath$pare = path.parentPath.parentPath) == null ? void 0 : _path$parentPath$pare.node)) { | ||
var _path$parentPath$pare2; | ||
const options = (_path$parentPath$pare2 = path.parentPath.parentPath) == null ? void 0 : _path$parentPath$pare2.node.arguments[0]; | ||
if (t__namespace.isMemberExpression(path.parentPath.node) && t__namespace.isCallExpression(path.parentPath.parentPath?.node)) { | ||
const options = path.parentPath.parentPath?.node.arguments[0]; | ||
return tryOptions(options); | ||
@@ -414,7 +399,5 @@ } | ||
function getCreateRouteConfigOptions(path) { | ||
var _path$parentPath; | ||
const tryOptions = node => { | ||
if (t__namespace.isIdentifier(node)) { | ||
var _path$scope$getBindin2; | ||
const initNode = (_path$scope$getBindin2 = path.scope.getBinding(node.name)) == null ? void 0 : _path$scope$getBindin2.path.node; | ||
const initNode = path.scope.getBinding(node.name)?.path.node; | ||
if (t__namespace.isVariableDeclarator(initNode)) { | ||
@@ -428,5 +411,4 @@ return tryOptions(initNode.init); | ||
}; | ||
if (t__namespace.isCallExpression((_path$parentPath = path.parentPath) == null ? void 0 : _path$parentPath.node)) { | ||
var _path$parentPath2; | ||
const options = (_path$parentPath2 = path.parentPath) == null ? void 0 : _path$parentPath2.node.arguments[0]; | ||
if (t__namespace.isCallExpression(path.parentPath?.node)) { | ||
const options = path.parentPath?.node.arguments[0]; | ||
return tryOptions(options); | ||
@@ -441,3 +423,3 @@ } | ||
function cleanUnusedCode(programPath, state, keepExports) { | ||
function cleanUnusedCode(programPath, state, keepExports = []) { | ||
state.refs = new Set(); | ||
@@ -444,0 +426,0 @@ state.done = false; |
@@ -32,3 +32,2 @@ /** | ||
async function ensureBoilerplate(node, code) { | ||
var _originalFile$code, _originalFile$code2, _file$code, _file$code2; | ||
const relativeImportPath = path.relative(node.fullDir, node.genPathNoExt); | ||
@@ -85,10 +84,9 @@ const originalFile = await babel.transformAsync(code, { | ||
const separator = node.isRoot ? 'createRouteConfig(' : 'routeConfig.generate('; | ||
if (!(originalFile != null && originalFile.code)) { | ||
return `${file == null ? void 0 : file.code}\n\n${separator}{\n\n})`; | ||
if (!originalFile?.code) { | ||
return `${file?.code}\n\n${separator}{\n\n})`; | ||
} | ||
const originalHead = originalFile == null ? void 0 : (_originalFile$code = originalFile.code) == null ? void 0 : _originalFile$code.substring(0, originalFile == null ? void 0 : (_originalFile$code2 = originalFile.code) == null ? void 0 : _originalFile$code2.indexOf(separator)); | ||
const generatedHead = file == null ? void 0 : (_file$code = file.code) == null ? void 0 : _file$code.substring(0, file == null ? void 0 : (_file$code2 = file.code) == null ? void 0 : _file$code2.indexOf(separator)); | ||
const originalHead = originalFile?.code?.substring(0, originalFile?.code?.indexOf(separator)); | ||
const generatedHead = file?.code?.substring(0, file?.code?.indexOf(separator)); | ||
if (originalHead !== generatedHead) { | ||
var _originalFile$code3, _originalFile$code4; | ||
return `${generatedHead}\n\n${originalFile == null ? void 0 : (_originalFile$code3 = originalFile.code) == null ? void 0 : _originalFile$code3.substring(originalFile == null ? void 0 : (_originalFile$code4 = originalFile.code) == null ? void 0 : _originalFile$code4.indexOf(separator))}`; | ||
return `${generatedHead}\n\n${originalFile?.code?.substring(originalFile?.code?.indexOf(separator))}`; | ||
} | ||
@@ -98,4 +96,3 @@ return; | ||
async function isolateOptionToExport(node, code, opts) { | ||
var _await$babel$transfor; | ||
return (_await$babel$transfor = await babel.transformAsync(code, { | ||
return (await babel.transformAsync(code, { | ||
configFile: false, | ||
@@ -105,3 +102,3 @@ babelrc: false, | ||
ast: true | ||
})) == null ? void 0 : _await$babel$transfor.code; | ||
}))?.code; | ||
function plugin() { | ||
@@ -119,3 +116,2 @@ return { | ||
if (options) { | ||
var _path$findParent; | ||
const property = options.properties.find(property => { | ||
@@ -126,3 +122,3 @@ return t.isObjectProperty(property) && t.isIdentifier(property.key) && property.key.name === opts.isolate; | ||
const program = path.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram()) { | ||
if (program?.isProgram()) { | ||
program.node.body.push(babel.template.statement(`export const ${opts.isolate} = $LOADER`)({ | ||
@@ -133,3 +129,3 @@ $LOADER: property.value | ||
} | ||
(_path$findParent = path.findParent(d => d.isExpressionStatement())) == null ? void 0 : _path$findParent.remove(); | ||
path.findParent(d => d.isExpressionStatement())?.remove(); | ||
} | ||
@@ -149,3 +145,2 @@ } | ||
if (options) { | ||
var _path$findParent2; | ||
const property = options.properties.find(property => { | ||
@@ -157,3 +152,3 @@ return t.isObjectProperty(property) && t.isIdentifier(property.key) && property.key.name === opts.isolate; | ||
const program = path.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram()) { | ||
if (program?.isProgram()) { | ||
program.node.body.push(babel.template.statement(`export const ${opts.isolate} = $LOADER`)({ | ||
@@ -165,3 +160,3 @@ $LOADER: property.value | ||
} | ||
(_path$findParent2 = path.findParent(d => d.isExpressionStatement())) == null ? void 0 : _path$findParent2.remove(); | ||
path.findParent(d => d.isExpressionStatement())?.remove(); | ||
} | ||
@@ -190,4 +185,3 @@ } | ||
if (t.isVariableDeclaration(path.node.declaration)) { | ||
var _path$node$declaratio; | ||
if (t.isVariableDeclarator((_path$node$declaratio = path.node.declaration.declarations) == null ? void 0 : _path$node$declaratio[0])) { | ||
if (t.isVariableDeclarator(path.node.declaration.declarations?.[0])) { | ||
if (t.isIdentifier(path.node.declaration.declarations[0].id)) { | ||
@@ -206,4 +200,3 @@ exported.push(path.node.declaration.declarations[0].id.name); | ||
async function generateRouteConfig(node, routeCode, imports, clientOnly) { | ||
var _node$parent, _node$parent2, _node$parent3, _node$parent4, _await$babel$transfor2; | ||
const relativeParentRoutePath = clientOnly ? node.parent ? removeExt(path.relative(node.genDir, path.resolve((_node$parent = node.parent) == null ? void 0 : _node$parent.genDir, (_node$parent2 = node.parent) == null ? void 0 : _node$parent2.clientFilename))) : `./${rootRouteClientName}` : node.parent ? removeExt(path.relative(node.genDir, path.resolve((_node$parent3 = node.parent) == null ? void 0 : _node$parent3.genDir, (_node$parent4 = node.parent) == null ? void 0 : _node$parent4.filename))) : `./${rootRouteName}`; | ||
const relativeParentRoutePath = clientOnly ? node.parent ? removeExt(path.relative(node.genDir, path.resolve(node.parent?.genDir, node.parent?.clientFilename))) : `./${rootRouteClientName}` : node.parent ? removeExt(path.relative(node.genDir, path.resolve(node.parent?.genDir, node.parent?.filename))) : `./${rootRouteName}`; | ||
const pathName = node.isRoot ? undefined : node.fileNameNoExt.startsWith('__') ? undefined : node.fileNameNoExt === 'index' ? '/' : node.fileNameNoExt; | ||
@@ -224,3 +217,3 @@ const routeId = node.isRoot ? undefined : node.fileNameNoExt; | ||
const program = path.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram()) { | ||
if (program?.isProgram()) { | ||
program.node.body.unshift(babel.template.statement(`import { routeConfig as parentRouteConfig } from '$IMPORT'`)({ | ||
@@ -239,6 +232,4 @@ $IMPORT: relativeParentRoutePath | ||
if (t.isCallExpression(iPath.parentPath.node)) { | ||
var _iPath$parentPath$par; | ||
if (t.isExpressionStatement((_iPath$parentPath$par = iPath.parentPath.parentPath) == null ? void 0 : _iPath$parentPath$par.node)) { | ||
var _iPath$parentPath$par2; | ||
(_iPath$parentPath$par2 = iPath.parentPath.parentPath) == null ? void 0 : _iPath$parentPath$par2.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('routeConfig'), iPath.parentPath.node)])); | ||
if (t.isExpressionStatement(iPath.parentPath.parentPath?.node)) { | ||
iPath.parentPath.parentPath?.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('routeConfig'), iPath.parentPath.node)])); | ||
} | ||
@@ -287,7 +278,4 @@ } | ||
const program = iPath.findParent(d => d.isProgram()); | ||
if (program != null && program.isProgram() && options) { | ||
const index = program.node.body.findIndex(d => { | ||
var _iPath$parentPath$par3; | ||
return d.start === ((_iPath$parentPath$par3 = iPath.parentPath.parentPath) == null ? void 0 : _iPath$parentPath$par3.node.start); | ||
}); | ||
if (program?.isProgram() && options) { | ||
const index = program.node.body.findIndex(d => d.start === iPath.parentPath.parentPath?.node.start); | ||
if (node.isRoot) { | ||
@@ -320,3 +308,3 @@ program.node.body[index] = babel.template.statement(`const routeConfig = createRouteConfig( | ||
} | ||
const code = (_await$babel$transfor2 = await babel.transformAsync(routeCode, { | ||
const code = (await babel.transformAsync(routeCode, { | ||
configFile: false, | ||
@@ -326,3 +314,3 @@ babelrc: false, | ||
ast: true | ||
})) == null ? void 0 : _await$babel$transfor2.code; | ||
}))?.code; | ||
if (!code) { | ||
@@ -373,7 +361,5 @@ throw new Error('Error while generating a route file!'); | ||
function getRouteConfigGenerateOptions(path) { | ||
var _path$parentPath$pare; | ||
const tryOptions = node => { | ||
if (t.isIdentifier(node)) { | ||
var _path$scope$getBindin; | ||
const initNode = (_path$scope$getBindin = path.scope.getBinding(node.name)) == null ? void 0 : _path$scope$getBindin.path.node; | ||
const initNode = path.scope.getBinding(node.name)?.path.node; | ||
if (t.isVariableDeclarator(initNode)) { | ||
@@ -387,5 +373,4 @@ return tryOptions(initNode.init); | ||
}; | ||
if (t.isMemberExpression(path.parentPath.node) && t.isCallExpression((_path$parentPath$pare = path.parentPath.parentPath) == null ? void 0 : _path$parentPath$pare.node)) { | ||
var _path$parentPath$pare2; | ||
const options = (_path$parentPath$pare2 = path.parentPath.parentPath) == null ? void 0 : _path$parentPath$pare2.node.arguments[0]; | ||
if (t.isMemberExpression(path.parentPath.node) && t.isCallExpression(path.parentPath.parentPath?.node)) { | ||
const options = path.parentPath.parentPath?.node.arguments[0]; | ||
return tryOptions(options); | ||
@@ -395,7 +380,5 @@ } | ||
function getCreateRouteConfigOptions(path) { | ||
var _path$parentPath; | ||
const tryOptions = node => { | ||
if (t.isIdentifier(node)) { | ||
var _path$scope$getBindin2; | ||
const initNode = (_path$scope$getBindin2 = path.scope.getBinding(node.name)) == null ? void 0 : _path$scope$getBindin2.path.node; | ||
const initNode = path.scope.getBinding(node.name)?.path.node; | ||
if (t.isVariableDeclarator(initNode)) { | ||
@@ -409,5 +392,4 @@ return tryOptions(initNode.init); | ||
}; | ||
if (t.isCallExpression((_path$parentPath = path.parentPath) == null ? void 0 : _path$parentPath.node)) { | ||
var _path$parentPath2; | ||
const options = (_path$parentPath2 = path.parentPath) == null ? void 0 : _path$parentPath2.node.arguments[0]; | ||
if (t.isCallExpression(path.parentPath?.node)) { | ||
const options = path.parentPath?.node.arguments[0]; | ||
return tryOptions(options); | ||
@@ -422,3 +404,3 @@ } | ||
function cleanUnusedCode(programPath, state, keepExports) { | ||
function cleanUnusedCode(programPath, state, keepExports = []) { | ||
state.refs = new Set(); | ||
@@ -693,8 +675,4 @@ state.done = false; | ||
const reparented = await reparent(config.routesDirectory); | ||
async function buildRouteConfig(nodes, depth) { | ||
if (depth === void 0) { | ||
depth = 1; | ||
} | ||
async function buildRouteConfig(nodes, depth = 1) { | ||
const children = nodes.map(async n => { | ||
var _node$children; | ||
let node = nodeCache.find(d => d.fullPath === n.fullPath); | ||
@@ -749,13 +727,9 @@ if (node) { | ||
})); | ||
imports = transforms.filter(_ref => { | ||
let { | ||
exported | ||
} = _ref; | ||
return exported; | ||
}); | ||
node.importedFiles = await Promise.all(imports.map(_ref2 => { | ||
let { | ||
key, | ||
code | ||
} = _ref2; | ||
imports = transforms.filter(({ | ||
exported | ||
}) => exported); | ||
node.importedFiles = await Promise.all(imports.map(({ | ||
key, | ||
code | ||
}) => { | ||
const importFilename = `${node.genPathNoExt}-${key}.tsx`; | ||
@@ -780,3 +754,3 @@ queueWriteFile(importFilename, code); | ||
const route = `${node.variable}Route`; | ||
if ((_node$children = node.children) != null && _node$children.length) { | ||
if (node.children?.length) { | ||
const childConfigs = await buildRouteConfig(node.children, depth + 1); | ||
@@ -806,4 +780,3 @@ return `${route}.addChildren([\n${spaces(depth * 4)}${childConfigs}\n${spaces(depth * 2)}])`; | ||
if (!checkLatest()) return; | ||
await Promise.all(fileQueue.map(async _ref3 => { | ||
let [filename, content] = _ref3; | ||
await Promise.all(fileQueue.map(async ([filename, content]) => { | ||
await fs.ensureDir(path.dirname(filename)); | ||
@@ -836,6 +809,3 @@ const exists = await fs.pathExists(filename); | ||
} | ||
let node = nodeCache.find(n => { | ||
var _n$importedFiles; | ||
return n.genPath === d || path.resolve(n.genDir, n.clientFilename) === d || ((_n$importedFiles = n.importedFiles) == null ? void 0 : _n$importedFiles.includes(d)); | ||
}); | ||
let node = nodeCache.find(n => n.genPath === d || path.resolve(n.genDir, n.clientFilename) === d || n.importedFiles?.includes(d)); | ||
return !node; | ||
@@ -882,9 +852,4 @@ }); | ||
} | ||
function multiSortBy(arr, accessors) { | ||
if (accessors === void 0) { | ||
accessors = [d => d]; | ||
} | ||
return arr.map((d, i) => [d, i]).sort((_ref4, _ref5) => { | ||
let [a, ai] = _ref4; | ||
let [b, bi] = _ref5; | ||
function multiSortBy(arr, accessors = [d => d]) { | ||
return arr.map((d, i) => [d, i]).sort(([a, ai], [b, bi]) => { | ||
for (const accessor of accessors) { | ||
@@ -905,6 +870,3 @@ const ao = accessor(a); | ||
return ai - bi; | ||
}).map(_ref6 => { | ||
let [d] = _ref6; | ||
return d; | ||
}); | ||
}).map(([d]) => d); | ||
} | ||
@@ -911,0 +873,0 @@ function capitalize(s) { |
{ | ||
"name": "@tanstack/router-cli", | ||
"author": "Tanner Linsley", | ||
"version": "0.0.1-beta.47", | ||
"version": "0.0.1-beta.56", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "tanstack/router", |
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
297611
3229