@screenbook/cli 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Screenbook Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.mjs CHANGED
@@ -3042,25 +3042,26 @@ function parseVueRouterConfig(filePath, preloadedContent) {
3042
3042
  throw new Error(`Failed to parse routes file "${absolutePath}": ${message}`);
3043
3043
  }
3044
3044
  const routes = [];
3045
+ const importMap = buildImportMap(ast.program.body, routesFileDir);
3045
3046
  for (const node of ast.program.body) {
3046
3047
  if (node.type === "ExportNamedDeclaration" && node.declaration?.type === "VariableDeclaration") {
3047
3048
  for (const decl of node.declaration.declarations) if (decl.id.type === "Identifier" && decl.id.name === "routes" && decl.init?.type === "ArrayExpression") {
3048
- const parsed = parseRoutesArray(decl.init, routesFileDir, warnings);
3049
+ const parsed = parseRoutesArray(decl.init, routesFileDir, warnings, importMap);
3049
3050
  routes.push(...parsed);
3050
3051
  }
3051
3052
  }
3052
3053
  if (node.type === "VariableDeclaration") {
3053
3054
  for (const decl of node.declarations) if (decl.id.type === "Identifier" && decl.id.name === "routes" && decl.init?.type === "ArrayExpression") {
3054
- const parsed = parseRoutesArray(decl.init, routesFileDir, warnings);
3055
+ const parsed = parseRoutesArray(decl.init, routesFileDir, warnings, importMap);
3055
3056
  routes.push(...parsed);
3056
3057
  }
3057
3058
  }
3058
3059
  if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "ArrayExpression") {
3059
- const parsed = parseRoutesArray(node.declaration, routesFileDir, warnings);
3060
+ const parsed = parseRoutesArray(node.declaration, routesFileDir, warnings, importMap);
3060
3061
  routes.push(...parsed);
3061
3062
  }
3062
3063
  if (node.type === "ExportDefaultDeclaration" && node.declaration.type === "TSSatisfiesExpression" && node.declaration.expression.type === "ArrayExpression") {
3063
- const parsed = parseRoutesArray(node.declaration.expression, routesFileDir, warnings);
3064
+ const parsed = parseRoutesArray(node.declaration.expression, routesFileDir, warnings, importMap);
3064
3065
  routes.push(...parsed);
3065
3066
  }
3066
3067
  }
@@ -3071,9 +3072,25 @@ function parseVueRouterConfig(filePath, preloadedContent) {
3071
3072
  };
3072
3073
  }
3073
3074
  /**
3075
+ * Build a map of imported identifiers to their file paths
3076
+ */
3077
+ function buildImportMap(body, baseDir) {
3078
+ const importMap = /* @__PURE__ */ new Map();
3079
+ for (const node of body) {
3080
+ if (node.type !== "ImportDeclaration") continue;
3081
+ const source = node.source.value;
3082
+ if (typeof source !== "string") continue;
3083
+ const resolvedPath = resolveImportPath(source, baseDir);
3084
+ if (!resolvedPath) continue;
3085
+ for (const specifier of node.specifiers) if (specifier.type === "ImportDefaultSpecifier") importMap.set(specifier.local.name, resolvedPath);
3086
+ else if (specifier.type === "ImportSpecifier") importMap.set(specifier.local.name, resolvedPath);
3087
+ }
3088
+ return importMap;
3089
+ }
3090
+ /**
3074
3091
  * Parse an array expression containing route objects
3075
3092
  */
3076
- function parseRoutesArray(arrayNode, baseDir, warnings) {
3093
+ function parseRoutesArray(arrayNode, baseDir, warnings, importMap) {
3077
3094
  const routes = [];
3078
3095
  for (const element of arrayNode.elements) {
3079
3096
  if (!element) continue;
@@ -3083,7 +3100,7 @@ function parseRoutesArray(arrayNode, baseDir, warnings) {
3083
3100
  continue;
3084
3101
  }
3085
3102
  if (element.type === "ObjectExpression") {
3086
- const route = parseRouteObject(element, baseDir, warnings);
3103
+ const route = parseRouteObject(element, baseDir, warnings, importMap);
3087
3104
  if (route) routes.push(route);
3088
3105
  }
3089
3106
  }
@@ -3092,14 +3109,18 @@ function parseRoutesArray(arrayNode, baseDir, warnings) {
3092
3109
  /**
3093
3110
  * Parse a single route object expression
3094
3111
  */
3095
- function parseRouteObject(objectNode, baseDir, warnings) {
3096
- const route = { path: "" };
3112
+ function parseRouteObject(objectNode, baseDir, warnings, importMap) {
3113
+ const route = {};
3114
+ let hasPath = false;
3097
3115
  for (const prop of objectNode.properties) {
3098
3116
  if (prop.type !== "ObjectProperty") continue;
3099
3117
  if (prop.key.type !== "Identifier") continue;
3100
3118
  switch (prop.key.name) {
3101
3119
  case "path":
3102
- if (prop.value.type === "StringLiteral") route.path = prop.value.value;
3120
+ if (prop.value.type === "StringLiteral") {
3121
+ route.path = prop.value.value;
3122
+ hasPath = true;
3123
+ }
3103
3124
  break;
3104
3125
  case "name":
3105
3126
  if (prop.value.type === "StringLiteral") route.name = prop.value.value;
@@ -3108,21 +3129,21 @@ function parseRouteObject(objectNode, baseDir, warnings) {
3108
3129
  if (prop.value.type === "StringLiteral") route.redirect = prop.value.value;
3109
3130
  break;
3110
3131
  case "component":
3111
- route.component = extractComponentPath(prop.value, baseDir);
3132
+ route.component = extractComponentPath(prop.value, baseDir, importMap);
3112
3133
  break;
3113
3134
  case "children":
3114
- if (prop.value.type === "ArrayExpression") route.children = parseRoutesArray(prop.value, baseDir, warnings);
3135
+ if (prop.value.type === "ArrayExpression") route.children = parseRoutesArray(prop.value, baseDir, warnings, importMap);
3115
3136
  break;
3116
3137
  }
3117
3138
  }
3118
- if (!route.path) return null;
3139
+ if (!hasPath) return null;
3119
3140
  return route;
3120
3141
  }
3121
3142
  /**
3122
3143
  * Extract component path from various component definitions
3123
3144
  */
3124
- function extractComponentPath(node, baseDir) {
3125
- if (node.type === "Identifier") return;
3145
+ function extractComponentPath(node, baseDir, importMap) {
3146
+ if (node.type === "Identifier") return importMap.get(node.name);
3126
3147
  if (node.type === "ArrowFunctionExpression") {
3127
3148
  const body = node.body;
3128
3149
  if (body.type === "CallExpression" && body.callee.type === "Import") {