@meekojs/meeko 0.0.3 → 0.1.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.
Files changed (188) hide show
  1. package/README.md +35 -16
  2. package/dist/autoimports-ts.d.ts +26 -0
  3. package/dist/autoimports-ts.js +183 -0
  4. package/dist/autoimports-ts.js.map +1 -0
  5. package/dist/autoimports.d.ts +21 -0
  6. package/dist/autoimports.js +301 -0
  7. package/dist/autoimports.js.map +1 -0
  8. package/dist/check.js +74 -33
  9. package/dist/check.js.map +1 -0
  10. package/dist/cli.js +67 -5
  11. package/dist/cli.js.map +1 -0
  12. package/dist/compiler/events.d.ts +2 -0
  13. package/dist/compiler/events.js +6 -0
  14. package/dist/compiler/events.js.map +1 -0
  15. package/dist/compiler/import-graph.d.ts +8 -0
  16. package/dist/compiler/import-graph.js +33 -0
  17. package/dist/compiler/import-graph.js.map +1 -0
  18. package/dist/compiler/mapping.js +1 -0
  19. package/dist/compiler/mapping.js.map +1 -0
  20. package/dist/compiler/project-root.d.ts +2 -0
  21. package/dist/compiler/project-root.js +18 -0
  22. package/dist/compiler/project-root.js.map +1 -0
  23. package/dist/compiler/props.d.ts +12 -0
  24. package/dist/compiler/props.js +32 -0
  25. package/dist/compiler/props.js.map +1 -0
  26. package/dist/compiler/sfc.js +1 -0
  27. package/dist/compiler/sfc.js.map +1 -0
  28. package/dist/compiler/sourcemap.d.ts +3 -0
  29. package/dist/compiler/sourcemap.js +75 -0
  30. package/dist/compiler/sourcemap.js.map +1 -0
  31. package/dist/compiler/template.js +1 -0
  32. package/dist/compiler/template.js.map +1 -0
  33. package/dist/compiler.js +66 -17
  34. package/dist/compiler.js.map +1 -0
  35. package/dist/component-errors.d.ts +18 -0
  36. package/dist/component-errors.js +65 -0
  37. package/dist/component-errors.js.map +1 -0
  38. package/dist/devtools-ui/index.js +1 -0
  39. package/dist/devtools-ui/index.js.map +1 -0
  40. package/dist/devtools.js +3 -4
  41. package/dist/devtools.js.map +1 -0
  42. package/dist/dom.d.ts +18 -5
  43. package/dist/dom.js +295 -90
  44. package/dist/dom.js.map +1 -0
  45. package/dist/error-observer.d.ts +6 -0
  46. package/dist/error-observer.js +41 -0
  47. package/dist/error-observer.js.map +1 -0
  48. package/dist/framework/check-app.d.ts +5 -0
  49. package/dist/framework/check-app.js +214 -0
  50. package/dist/framework/check-app.js.map +1 -0
  51. package/dist/framework/check-project.d.ts +4 -0
  52. package/dist/framework/check-project.js +42 -0
  53. package/dist/framework/check-project.js.map +1 -0
  54. package/dist/framework/client.d.ts +48 -0
  55. package/dist/framework/client.js +249 -0
  56. package/dist/framework/client.js.map +1 -0
  57. package/dist/framework/clients.d.ts +82 -0
  58. package/dist/framework/clients.js +190 -0
  59. package/dist/framework/clients.js.map +1 -0
  60. package/dist/framework/config-type.d.ts +10 -0
  61. package/dist/framework/config-type.js +4 -0
  62. package/dist/framework/config-type.js.map +1 -0
  63. package/dist/framework/config.d.ts +15 -0
  64. package/dist/framework/config.js +138 -0
  65. package/dist/framework/config.js.map +1 -0
  66. package/dist/framework/contracts-generate.d.ts +8 -0
  67. package/dist/framework/contracts-generate.js +290 -0
  68. package/dist/framework/contracts-generate.js.map +1 -0
  69. package/dist/framework/generate.d.ts +7 -0
  70. package/dist/framework/generate.js +67 -0
  71. package/dist/framework/generate.js.map +1 -0
  72. package/dist/framework/init.d.ts +2 -0
  73. package/dist/framework/init.js +183 -0
  74. package/dist/framework/init.js.map +1 -0
  75. package/dist/framework/middleware.d.ts +14 -0
  76. package/dist/framework/middleware.js +16 -0
  77. package/dist/framework/middleware.js.map +1 -0
  78. package/dist/framework/modules.d.ts +22 -0
  79. package/dist/framework/modules.js +29 -0
  80. package/dist/framework/modules.js.map +1 -0
  81. package/dist/framework/page-contracts-check.d.ts +8 -0
  82. package/dist/framework/page-contracts-check.js +110 -0
  83. package/dist/framework/page-contracts-check.js.map +1 -0
  84. package/dist/framework/page-contracts-generate.d.ts +2 -0
  85. package/dist/framework/page-contracts-generate.js +94 -0
  86. package/dist/framework/page-contracts-generate.js.map +1 -0
  87. package/dist/framework/page.d.ts +64 -0
  88. package/dist/framework/page.js +44 -0
  89. package/dist/framework/page.js.map +1 -0
  90. package/dist/framework/prerender.d.ts +14 -0
  91. package/dist/framework/prerender.js +110 -0
  92. package/dist/framework/prerender.js.map +1 -0
  93. package/dist/framework/project-templates.d.ts +3 -0
  94. package/dist/framework/project-templates.js +119 -0
  95. package/dist/framework/project-templates.js.map +1 -0
  96. package/dist/framework/project.d.ts +9 -0
  97. package/dist/framework/project.js +272 -0
  98. package/dist/framework/project.js.map +1 -0
  99. package/dist/framework/router.d.ts +41 -0
  100. package/dist/framework/router.js +259 -0
  101. package/dist/framework/router.js.map +1 -0
  102. package/dist/framework/server.d.ts +65 -0
  103. package/dist/framework/server.js +239 -0
  104. package/dist/framework/server.js.map +1 -0
  105. package/dist/framework/socket-contracts-generate.d.ts +5 -0
  106. package/dist/framework/socket-contracts-generate.js +162 -0
  107. package/dist/framework/socket-contracts-generate.js.map +1 -0
  108. package/dist/framework/socket.d.ts +72 -0
  109. package/dist/framework/socket.js +252 -0
  110. package/dist/framework/socket.js.map +1 -0
  111. package/dist/framework/standard-schema-types.d.ts +7 -0
  112. package/dist/framework/standard-schema-types.js +69 -0
  113. package/dist/framework/standard-schema-types.js.map +1 -0
  114. package/dist/framework/state.d.ts +22 -0
  115. package/dist/framework/state.js +136 -0
  116. package/dist/framework/state.js.map +1 -0
  117. package/dist/framework/styles.d.ts +2 -0
  118. package/dist/framework/styles.js +6 -0
  119. package/dist/framework/styles.js.map +1 -0
  120. package/dist/framework/type-declarations.d.ts +5 -0
  121. package/dist/framework/type-declarations.js +84 -0
  122. package/dist/framework/type-declarations.js.map +1 -0
  123. package/dist/framework-server/auto-clients.d.ts +3 -0
  124. package/dist/framework-server/auto-clients.js +27 -0
  125. package/dist/framework-server/auto-clients.js.map +1 -0
  126. package/dist/framework-server/context.d.ts +21 -0
  127. package/dist/framework-server/context.js +22 -0
  128. package/dist/framework-server/context.js.map +1 -0
  129. package/dist/framework-server/contracts.d.ts +73 -0
  130. package/dist/framework-server/contracts.js +184 -0
  131. package/dist/framework-server/contracts.js.map +1 -0
  132. package/dist/framework-server/discovery.d.ts +43 -0
  133. package/dist/framework-server/discovery.js +257 -0
  134. package/dist/framework-server/discovery.js.map +1 -0
  135. package/dist/framework-server/local.d.ts +21 -0
  136. package/dist/framework-server/local.js +100 -0
  137. package/dist/framework-server/local.js.map +1 -0
  138. package/dist/framework-server/middleware.d.ts +4 -0
  139. package/dist/framework-server/middleware.js +56 -0
  140. package/dist/framework-server/middleware.js.map +1 -0
  141. package/dist/framework-server/node-upgrade.d.ts +23 -0
  142. package/dist/framework-server/node-upgrade.js +96 -0
  143. package/dist/framework-server/node-upgrade.js.map +1 -0
  144. package/dist/framework-server/node-websocket.d.ts +16 -0
  145. package/dist/framework-server/node-websocket.js +127 -0
  146. package/dist/framework-server/node-websocket.js.map +1 -0
  147. package/dist/framework-server/openapi.d.ts +17 -0
  148. package/dist/framework-server/openapi.js +118 -0
  149. package/dist/framework-server/openapi.js.map +1 -0
  150. package/dist/framework-server/session-stores.d.ts +73 -0
  151. package/dist/framework-server/session-stores.js +122 -0
  152. package/dist/framework-server/session-stores.js.map +1 -0
  153. package/dist/framework-server/sessions.d.ts +70 -0
  154. package/dist/framework-server/sessions.js +167 -0
  155. package/dist/framework-server/sessions.js.map +1 -0
  156. package/dist/framework-server/socket.d.ts +83 -0
  157. package/dist/framework-server/socket.js +196 -0
  158. package/dist/framework-server/socket.js.map +1 -0
  159. package/dist/framework-server.d.ts +23 -0
  160. package/dist/framework-server.js +13 -0
  161. package/dist/framework-server.js.map +1 -0
  162. package/dist/framework.d.ts +31 -0
  163. package/dist/framework.js +14 -0
  164. package/dist/framework.js.map +1 -0
  165. package/dist/hmr.js +75 -24
  166. package/dist/hmr.js.map +1 -0
  167. package/dist/index.d.ts +5 -3
  168. package/dist/index.js +3 -1
  169. package/dist/index.js.map +1 -0
  170. package/dist/init.js +31 -3
  171. package/dist/init.js.map +1 -0
  172. package/dist/internal.d.ts +2 -2
  173. package/dist/internal.js +3 -2
  174. package/dist/internal.js.map +1 -0
  175. package/dist/node.d.ts +16 -0
  176. package/dist/node.js +122 -0
  177. package/dist/node.js.map +1 -0
  178. package/dist/reactivity.d.ts +22 -1
  179. package/dist/reactivity.js +132 -18
  180. package/dist/reactivity.js.map +1 -0
  181. package/dist/server.js +1 -0
  182. package/dist/server.js.map +1 -0
  183. package/dist/types.d.ts +2 -0
  184. package/dist/types.js +26 -9
  185. package/dist/types.js.map +1 -0
  186. package/dist/vite.js +112 -7
  187. package/dist/vite.js.map +1 -0
  188. package/package.json +15 -4
@@ -0,0 +1,301 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
3
+ import { extname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import ts from "@typescript/typescript6";
5
+ import { compile } from "./compiler.js";
6
+ import { projectRoot } from "./compiler/project-root.js";
7
+ import { parseSfc } from "./compiler/sfc.js";
8
+ import { loadMeekoConfig, readMeekoConfigSync, resolveConfigSources } from "./framework/config.js";
9
+ const directories = [
10
+ "app/components", "app/composables", "app/utils", "app/stores",
11
+ "shared/types", "shared/schemas", "shared/utils", "shared/constants", "shared/enums",
12
+ "server/utils",
13
+ ];
14
+ function scopeOf(file) {
15
+ if (/\.shared\.[cm]?tsx?$/.test(file))
16
+ return "shared";
17
+ if (/\.server\.[cm]?tsx?$/.test(file))
18
+ return "server";
19
+ if (/\.client\.[cm]?tsx?$/.test(file))
20
+ return "client";
21
+ if (file.includes(`${sep}server${sep}`))
22
+ return "server";
23
+ // App modules render on both sides during SSR, but are not available to shared/ sources.
24
+ if (file.includes(`${sep}app${sep}`))
25
+ return "app";
26
+ return "shared";
27
+ }
28
+ async function filesIn(path) {
29
+ const entries = await readdir(path, { withFileTypes: true }).catch(() => []);
30
+ const files = [];
31
+ for (const entry of entries) {
32
+ const filename = join(path, entry.name);
33
+ if (entry.isDirectory())
34
+ files.push(...await filesIn(filename));
35
+ else if (/\.(?:meeko|[cm]?ts)$/.test(entry.name) && !/\.(?:test|spec|d)\.[cm]?ts$/.test(entry.name))
36
+ files.push(filename);
37
+ }
38
+ return files;
39
+ }
40
+ function filesInSync(path) {
41
+ let entries;
42
+ try {
43
+ entries = readdirSync(path, { withFileTypes: true });
44
+ }
45
+ catch (error) {
46
+ if (error.code === "ENOENT")
47
+ return [];
48
+ throw error;
49
+ }
50
+ const files = [];
51
+ for (const entry of entries) {
52
+ const filename = join(path, entry.name);
53
+ if (entry.isDirectory())
54
+ files.push(...filesInSync(filename));
55
+ else if (/\.(?:meeko|[cm]?ts)$/.test(entry.name) && !/\.(?:test|spec|d)\.[cm]?ts$/.test(entry.name))
56
+ files.push(filename);
57
+ }
58
+ return files;
59
+ }
60
+ function builtins(root) {
61
+ const entries = [
62
+ ...["signal", "computed", "effect", "batch", "onCleanup", "provide", "inject", "createContext", "provideErrorHandler"].map((name) => ({ name, imported: name, file: "@meekojs/meeko", specifier: "@meekojs/meeko", scope: "shared", typeOnly: false, component: false })),
63
+ ...["useState", "href"].map((name) => ({ name, imported: name, file: "@meekojs/meeko/framework", specifier: "@meekojs/meeko/framework", scope: "shared", typeOnly: false, component: false })),
64
+ ];
65
+ for (const scope of ["client", "server"]) {
66
+ const file = join(root, ".meeko", "generated", `clients.${scope}.ts`);
67
+ if (!existsSync(file))
68
+ continue;
69
+ for (const name of ["api", "rpc", "socket", "useSocket"])
70
+ entries.push({ name, imported: name, file, scope, typeOnly: false, component: false });
71
+ }
72
+ if (!entries.some((entry) => entry.name === "useSocket")) {
73
+ entries.push({ name: "useSocket", imported: "useSocket", file: "@meekojs/meeko/framework", specifier: "@meekojs/meeko/framework", scope: "shared", typeOnly: false, component: false });
74
+ }
75
+ return entries;
76
+ }
77
+ function addAutoImport(result, entry) {
78
+ const previous = result.find((candidate) => candidate.name === entry.name
79
+ && candidate.imported === entry.imported
80
+ && candidate.file === entry.file
81
+ && candidate.scope === entry.scope
82
+ && candidate.component === entry.component);
83
+ if (!previous) {
84
+ result.push(entry);
85
+ return;
86
+ }
87
+ // Function overloads and declaration merging describe one exported symbol.
88
+ // Prefer the value-bearing form when a type and value share that symbol.
89
+ if (previous.typeOnly && !entry.typeOnly)
90
+ previous.typeOnly = false;
91
+ }
92
+ function addFileImports(result, root, directory, file, source) {
93
+ const scope = scopeOf(file);
94
+ if (extname(file) === ".meeko") {
95
+ if (directory !== "app/components")
96
+ return;
97
+ const path = relative(join(root, directory), file).replace(/\.meeko$/, "");
98
+ const name = path.split(/[\\/]/).map((part) => part.replace(/(^|[-_])(\w)/g, (_, _dash, letter) => letter.toUpperCase())).join("");
99
+ addAutoImport(result, { name, imported: "*", file, scope, typeOnly: false, component: true });
100
+ return;
101
+ }
102
+ const ast = ts.createSourceFile(file, source ?? "", ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
103
+ for (const statement of ast.statements) {
104
+ const exported = ts.canHaveModifiers(statement) && ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
105
+ if (exported && (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name) {
106
+ addAutoImport(result, { name: statement.name.text, imported: statement.name.text, file, scope, typeOnly: ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement), component: false });
107
+ }
108
+ if (exported && ts.isVariableStatement(statement)) {
109
+ for (const declaration of statement.declarationList.declarations)
110
+ if (ts.isIdentifier(declaration.name)) {
111
+ addAutoImport(result, { name: declaration.name.text, imported: declaration.name.text, file, scope, typeOnly: false, component: false });
112
+ }
113
+ }
114
+ if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
115
+ for (const element of statement.exportClause.elements)
116
+ addAutoImport(result, { name: element.name.text, imported: element.name.text, file, scope, typeOnly: statement.isTypeOnly || element.isTypeOnly, component: false });
117
+ }
118
+ }
119
+ }
120
+ /** Construye el registro a partir de exports sintácticos, sin ejecutar módulos de la aplicación. */
121
+ export async function discoverAutoImports(root) {
122
+ const result = builtins(root);
123
+ const config = await loadMeekoConfig(root);
124
+ const sources = await resolveConfigSources(root, config);
125
+ for (const source of sources) {
126
+ for (const directory of configuredDirectories(config.imports?.serverDirs)) {
127
+ for (const file of await filesIn(join(source.root, directory))) {
128
+ addFileImports(result, source.root, directory, file, extname(file) === ".meeko" ? undefined : await readFile(file, "utf8"));
129
+ }
130
+ }
131
+ }
132
+ return result;
133
+ }
134
+ /** Same static registry used by the synchronous VS Code Language Service. */
135
+ export function discoverAutoImportsSync(root) {
136
+ const result = builtins(root);
137
+ const config = readMeekoConfigSync(root);
138
+ const sourceRoots = [resolve(root)];
139
+ for (const entry of [...(config.extends ?? []), ...(config.modules ?? [])]) {
140
+ const sourceRoot = resolve(root, entry);
141
+ const path = relative(root, sourceRoot);
142
+ if (path === ".." || path.startsWith(`..${sep}`) || isAbsolute(path))
143
+ throw new Error(`Configured autoimport source escapes project root: ${entry}`);
144
+ sourceRoots.push(sourceRoot);
145
+ }
146
+ for (const sourceRoot of sourceRoots) {
147
+ for (const directory of configuredDirectories(config.imports?.serverDirs)) {
148
+ for (const file of filesInSync(join(sourceRoot, directory))) {
149
+ addFileImports(result, sourceRoot, directory, file, extname(file) === ".meeko" ? undefined : readFileSync(file, "utf8"));
150
+ }
151
+ }
152
+ }
153
+ return result;
154
+ }
155
+ function configuredDirectories(serverDirs) {
156
+ const result = new Set(directories);
157
+ for (const raw of serverDirs ?? []) {
158
+ const directory = raw.replaceAll("\\", "/").replace(/\/$/, "");
159
+ const parts = directory.split("/");
160
+ if (parts[0] !== "server" || parts.length < 2 || parts.some((part) => !part || part === "." || part === "..")) {
161
+ throw new Error(`Autoimport serverDir must be a relative path under server/: ${raw}`);
162
+ }
163
+ result.add(directory);
164
+ }
165
+ return [...result];
166
+ }
167
+ function bindingNames(name, names) {
168
+ if (ts.isIdentifier(name))
169
+ names.add(name.text);
170
+ else
171
+ for (const element of name.elements)
172
+ if (ts.isBindingElement(element))
173
+ bindingNames(element.name, names);
174
+ }
175
+ function scopeNames(node) {
176
+ const names = new Set();
177
+ if (ts.isFunctionLike(node)) {
178
+ for (const parameter of node.parameters)
179
+ bindingNames(parameter.name, names);
180
+ for (const parameter of node.typeParameters ?? [])
181
+ names.add(parameter.name.text);
182
+ }
183
+ if (ts.isCatchClause(node) && node.variableDeclaration)
184
+ bindingNames(node.variableDeclaration.name, names);
185
+ if (ts.isForStatement(node) && node.initializer && ts.isVariableDeclarationList(node.initializer)) {
186
+ for (const declaration of node.initializer.declarations)
187
+ bindingNames(declaration.name, names);
188
+ }
189
+ if ((ts.isForOfStatement(node) || ts.isForInStatement(node)) && ts.isVariableDeclarationList(node.initializer)) {
190
+ for (const declaration of node.initializer.declarations)
191
+ bindingNames(declaration.name, names);
192
+ }
193
+ if (ts.isSourceFile(node) || ts.isBlock(node)) {
194
+ for (const statement of node.statements) {
195
+ if (ts.isVariableStatement(statement))
196
+ for (const declaration of statement.declarationList.declarations)
197
+ bindingNames(declaration.name, names);
198
+ if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name)
199
+ names.add(statement.name.text);
200
+ if (ts.isImportDeclaration(statement)) {
201
+ const clause = statement.importClause;
202
+ if (clause?.name)
203
+ names.add(clause.name.text);
204
+ if (clause?.namedBindings) {
205
+ if (ts.isNamespaceImport(clause.namedBindings))
206
+ names.add(clause.namedBindings.name.text);
207
+ else
208
+ for (const element of clause.namedBindings.elements)
209
+ names.add(element.name.text);
210
+ }
211
+ }
212
+ }
213
+ }
214
+ return names;
215
+ }
216
+ function introducesScope(node) {
217
+ return ts.isSourceFile(node) || ts.isBlock(node) || ts.isFunctionLike(node) || ts.isCatchClause(node)
218
+ || ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node);
219
+ }
220
+ function isReference(node) {
221
+ const parent = node.parent;
222
+ if (!parent)
223
+ return false;
224
+ if (ts.isPropertyAccessExpression(parent) && parent.name === node)
225
+ return false;
226
+ if (ts.isQualifiedName(parent) && parent.right === node)
227
+ return false;
228
+ if (ts.isPropertyAssignment(parent) && parent.name === node)
229
+ return false;
230
+ if (ts.isPropertyDeclaration(parent) && parent.name === node)
231
+ return false;
232
+ if (ts.isMethodDeclaration(parent) && parent.name === node)
233
+ return false;
234
+ if (ts.isImportSpecifier(parent) || ts.isExportSpecifier(parent) || ts.isImportClause(parent) || ts.isNamespaceImport(parent))
235
+ return false;
236
+ if (ts.isTypeReferenceNode(parent) && parent.typeName === node)
237
+ return true;
238
+ if (ts.isParameter(parent) && parent.name === node)
239
+ return false;
240
+ if (ts.isTypeParameterDeclaration(parent) && parent.name === node)
241
+ return false;
242
+ if (ts.isVariableDeclaration(parent) && parent.name === node)
243
+ return false;
244
+ if ((ts.isFunctionDeclaration(parent) || ts.isClassDeclaration(parent) || ts.isInterfaceDeclaration(parent) || ts.isTypeAliasDeclaration(parent)) && parent.name === node)
245
+ return false;
246
+ if (ts.isPropertySignature(parent) && parent.name === node)
247
+ return false;
248
+ return true;
249
+ }
250
+ /** Añade imports ESM para referencias libres del módulo generado. */
251
+ export function applyAutoImports(code, filename, registry, target) {
252
+ const ast = ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
253
+ const referenced = new Set();
254
+ const visit = (node, scopes) => {
255
+ const active = introducesScope(node) ? [...scopes, scopeNames(node)] : scopes;
256
+ if (ts.isIdentifier(node) && isReference(node) && !active.some((scope) => scope.has(node.text)))
257
+ referenced.add(node.text);
258
+ ts.forEachChild(node, (child) => visit(child, active));
259
+ };
260
+ visit(ast, []);
261
+ const imports = [];
262
+ for (const name of [...referenced].sort()) {
263
+ const candidates = registry.filter((entry) => entry.name === name);
264
+ if (candidates.length === 0)
265
+ continue;
266
+ const allowed = candidates.filter((entry) => entry.scope === "shared" || entry.scope === target || (target !== "shared" && entry.scope === "app"));
267
+ if (allowed.length === 0)
268
+ throw new Error(`Autoimport ${name} is unavailable in ${target} scope`);
269
+ if (allowed.length > 1)
270
+ throw new Error(`Ambiguous autoimport ${name}: ${allowed.map((entry) => entry.file).join(", ")}`);
271
+ const entry = allowed[0];
272
+ let specifier = entry.specifier ?? relative(resolve(filename, ".."), entry.file).replaceAll("\\", "/");
273
+ if (!entry.specifier && !specifier.startsWith("."))
274
+ specifier = `./${specifier}`;
275
+ if (!entry.component && !entry.specifier)
276
+ specifier = specifier.replace(/\.[cm]?ts$/, ".js");
277
+ if (entry.component)
278
+ imports.push(`import * as ${name} from ${JSON.stringify(specifier)};`);
279
+ else
280
+ imports.push(`import ${entry.typeOnly ? "type " : ""}{ ${entry.imported} as ${name} } from ${JSON.stringify(specifier)};`);
281
+ }
282
+ return imports.length ? `${imports.join("\n")}\n${code}` : code;
283
+ }
284
+ /** Transforma un SFC usando exactamente el mismo compilador que el plugin Vite. */
285
+ export function transformAutoImports(source, filename, code, registry, target) {
286
+ parseSfc(source, filename);
287
+ return applyAutoImports(code, filename, registry, target);
288
+ }
289
+ /** Compile result shared by Vite, CLI checks and declaration generation. */
290
+ export async function compileWithAutoImports(source, filename, options = {}, target = "client") {
291
+ const compiled = compile(source, filename, options);
292
+ const registry = await discoverAutoImports(projectRoot(filename));
293
+ const code = transformAutoImports(source, filename, compiled.code, registry, target);
294
+ const offset = code.length - compiled.code.length;
295
+ return {
296
+ ...compiled,
297
+ code,
298
+ mappings: offset ? compiled.mappings.map((mapping) => ({ ...mapping, generatedStart: mapping.generatedStart + offset, generatedEnd: mapping.generatedEnd + offset })) : compiled.mappings,
299
+ };
300
+ }
301
+ //# sourceMappingURL=autoimports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoimports.js","sourceRoot":"","sources":["../src/autoimports.ts"],"names":[],"mappings":"AA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AC5D,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAAc,EAAE,QAAgB,EAAE,OAAO,GAAmB,EAAE,EAAE,MAAM,GAAwB,QAAQ;IACjJ,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACrF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;IAClD,OAAO;QACL,GAAG,QAAQ;QACX,IAAI;QACJ,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,GAAG,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ;KAC1L,CAAC;AACJ,CAAC","sourcesContent":["import { readdir, readFile } from \"node:fs/promises\";\nimport { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { extname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport ts from \"@typescript/typescript6\";\nimport { compile } from \"./compiler.js\";\nimport type { CompileOptions, CompileResult } from \"./compiler.js\";\nimport { projectRoot } from \"./compiler/project-root.js\";\nimport { parseSfc } from \"./compiler/sfc.js\";\nimport { loadMeekoConfig, readMeekoConfigSync, resolveConfigSources } from \"./framework/config.js\";\n\nexport type ImportScope = \"client\" | \"server\" | \"shared\" | \"app\";\nexport interface AutoImport {\n name: string;\n imported: string;\n file: string;\n scope: ImportScope;\n typeOnly: boolean;\n component: boolean;\n specifier?: string;\n}\n\nconst directories = [\n \"app/components\", \"app/composables\", \"app/utils\", \"app/stores\",\n \"shared/types\", \"shared/schemas\", \"shared/utils\", \"shared/constants\", \"shared/enums\",\n \"server/utils\",\n] as const;\n\nfunction scopeOf(file: string): ImportScope {\n if (/\\.shared\\.[cm]?tsx?$/.test(file)) return \"shared\";\n if (/\\.server\\.[cm]?tsx?$/.test(file)) return \"server\";\n if (/\\.client\\.[cm]?tsx?$/.test(file)) return \"client\";\n if (file.includes(`${sep}server${sep}`)) return \"server\";\n // App modules render on both sides during SSR, but are not available to shared/ sources.\n if (file.includes(`${sep}app${sep}`)) return \"app\";\n return \"shared\";\n}\n\nasync function filesIn(path: string): Promise<string[]> {\n const entries = await readdir(path, { withFileTypes: true }).catch(() => []);\n const files: string[] = [];\n for (const entry of entries) {\n const filename = join(path, entry.name);\n if (entry.isDirectory()) files.push(...await filesIn(filename));\n else if (/\\.(?:meeko|[cm]?ts)$/.test(entry.name) && !/\\.(?:test|spec|d)\\.[cm]?ts$/.test(entry.name)) files.push(filename);\n }\n return files;\n}\n\nfunction filesInSync(path: string): string[] {\n let entries;\n try { entries = readdirSync(path, { withFileTypes: true }); }\n catch (error) { if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return []; throw error; }\n const files: string[] = [];\n for (const entry of entries) {\n const filename = join(path, entry.name);\n if (entry.isDirectory()) files.push(...filesInSync(filename));\n else if (/\\.(?:meeko|[cm]?ts)$/.test(entry.name) && !/\\.(?:test|spec|d)\\.[cm]?ts$/.test(entry.name)) files.push(filename);\n }\n return files;\n}\n\nfunction builtins(root: string): AutoImport[] {\n const entries: AutoImport[] = [\n ...[\"signal\", \"computed\", \"effect\", \"batch\", \"onCleanup\", \"provide\", \"inject\", \"createContext\", \"provideErrorHandler\"].map((name): AutoImport => ({ name, imported: name, file: \"@meekojs/meeko\", specifier: \"@meekojs/meeko\", scope: \"shared\", typeOnly: false, component: false })),\n ...[\"useState\", \"href\"].map((name): AutoImport => ({ name, imported: name, file: \"@meekojs/meeko/framework\", specifier: \"@meekojs/meeko/framework\", scope: \"shared\", typeOnly: false, component: false })),\n ];\n for (const scope of [\"client\", \"server\"] as const) {\n const file = join(root, \".meeko\", \"generated\", `clients.${scope}.ts`);\n if (!existsSync(file)) continue;\n for (const name of [\"api\", \"rpc\", \"socket\", \"useSocket\"]) entries.push({ name, imported: name, file, scope, typeOnly: false, component: false });\n }\n if (!entries.some((entry) => entry.name === \"useSocket\")) {\n entries.push({ name: \"useSocket\", imported: \"useSocket\", file: \"@meekojs/meeko/framework\", specifier: \"@meekojs/meeko/framework\", scope: \"shared\", typeOnly: false, component: false });\n }\n return entries;\n}\n\nfunction addAutoImport(result: AutoImport[], entry: AutoImport): void {\n const previous = result.find((candidate) => candidate.name === entry.name\n && candidate.imported === entry.imported\n && candidate.file === entry.file\n && candidate.scope === entry.scope\n && candidate.component === entry.component);\n if (!previous) {\n result.push(entry);\n return;\n }\n // Function overloads and declaration merging describe one exported symbol.\n // Prefer the value-bearing form when a type and value share that symbol.\n if (previous.typeOnly && !entry.typeOnly) previous.typeOnly = false;\n}\n\nfunction addFileImports(result: AutoImport[], root: string, directory: string, file: string, source?: string): void {\n const scope = scopeOf(file);\n if (extname(file) === \".meeko\") {\n if (directory !== \"app/components\") return;\n const path = relative(join(root, directory), file).replace(/\\.meeko$/, \"\");\n const name = path.split(/[\\\\/]/).map((part) => part.replace(/(^|[-_])(\\w)/g, (_, _dash: string, letter: string) => letter.toUpperCase())).join(\"\");\n addAutoImport(result, { name, imported: \"*\", file, scope, typeOnly: false, component: true });\n return;\n }\n const ast = ts.createSourceFile(file, source ?? \"\", ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n for (const statement of ast.statements) {\n const exported = ts.canHaveModifiers(statement) && ts.getModifiers(statement)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);\n if (exported && (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name) {\n addAutoImport(result, { name: statement.name.text, imported: statement.name.text, file, scope, typeOnly: ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement), component: false });\n }\n if (exported && ts.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) if (ts.isIdentifier(declaration.name)) {\n addAutoImport(result, { name: declaration.name.text, imported: declaration.name.text, file, scope, typeOnly: false, component: false });\n }\n }\n if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n for (const element of statement.exportClause.elements) addAutoImport(result, { name: element.name.text, imported: element.name.text, file, scope, typeOnly: statement.isTypeOnly || element.isTypeOnly, component: false });\n }\n }\n}\n\n/** Construye el registro a partir de exports sintácticos, sin ejecutar módulos de la aplicación. */\nexport async function discoverAutoImports(root: string): Promise<AutoImport[]> {\n const result: AutoImport[] = builtins(root);\n const config = await loadMeekoConfig(root);\n const sources = await resolveConfigSources(root, config);\n for (const source of sources) {\n for (const directory of configuredDirectories(config.imports?.serverDirs)) {\n for (const file of await filesIn(join(source.root, directory))) {\n addFileImports(result, source.root, directory, file, extname(file) === \".meeko\" ? undefined : await readFile(file, \"utf8\"));\n }\n }\n }\n return result;\n}\n\n/** Same static registry used by the synchronous VS Code Language Service. */\nexport function discoverAutoImportsSync(root: string): AutoImport[] {\n const result = builtins(root);\n const config = readMeekoConfigSync(root);\n const sourceRoots = [resolve(root)];\n for (const entry of [...(config.extends ?? []), ...(config.modules ?? [])]) {\n const sourceRoot = resolve(root, entry);\n const path = relative(root, sourceRoot);\n if (path === \"..\" || path.startsWith(`..${sep}`) || isAbsolute(path)) throw new Error(`Configured autoimport source escapes project root: ${entry}`);\n sourceRoots.push(sourceRoot);\n }\n for (const sourceRoot of sourceRoots) {\n for (const directory of configuredDirectories(config.imports?.serverDirs)) {\n for (const file of filesInSync(join(sourceRoot, directory))) {\n addFileImports(result, sourceRoot, directory, file, extname(file) === \".meeko\" ? undefined : readFileSync(file, \"utf8\"));\n }\n }\n }\n return result;\n}\n\nfunction configuredDirectories(serverDirs: readonly string[] | undefined): readonly string[] {\n const result = new Set<string>(directories);\n for (const raw of serverDirs ?? []) {\n const directory = raw.replaceAll(\"\\\\\", \"/\").replace(/\\/$/, \"\");\n const parts = directory.split(\"/\");\n if (parts[0] !== \"server\" || parts.length < 2 || parts.some((part) => !part || part === \".\" || part === \"..\")) {\n throw new Error(`Autoimport serverDir must be a relative path under server/: ${raw}`);\n }\n result.add(directory);\n }\n return [...result];\n}\n\nfunction bindingNames(name: ts.BindingName, names: Set<string>): void {\n if (ts.isIdentifier(name)) names.add(name.text);\n else for (const element of name.elements) if (ts.isBindingElement(element)) bindingNames(element.name, names);\n}\n\nfunction scopeNames(node: ts.Node): Set<string> {\n const names = new Set<string>();\n if (ts.isFunctionLike(node)) {\n for (const parameter of node.parameters) bindingNames(parameter.name, names);\n for (const parameter of node.typeParameters ?? []) names.add(parameter.name.text);\n }\n if (ts.isCatchClause(node) && node.variableDeclaration) bindingNames(node.variableDeclaration.name, names);\n if (ts.isForStatement(node) && node.initializer && ts.isVariableDeclarationList(node.initializer)) {\n for (const declaration of node.initializer.declarations) bindingNames(declaration.name, names);\n }\n if ((ts.isForOfStatement(node) || ts.isForInStatement(node)) && ts.isVariableDeclarationList(node.initializer)) {\n for (const declaration of node.initializer.declarations) bindingNames(declaration.name, names);\n }\n if (ts.isSourceFile(node) || ts.isBlock(node)) {\n for (const statement of node.statements) {\n if (ts.isVariableStatement(statement)) for (const declaration of statement.declarationList.declarations) bindingNames(declaration.name, names);\n if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name) names.add(statement.name.text);\n if (ts.isImportDeclaration(statement)) {\n const clause = statement.importClause;\n if (clause?.name) names.add(clause.name.text);\n if (clause?.namedBindings) {\n if (ts.isNamespaceImport(clause.namedBindings)) names.add(clause.namedBindings.name.text);\n else for (const element of clause.namedBindings.elements) names.add(element.name.text);\n }\n }\n }\n }\n return names;\n}\n\nfunction introducesScope(node: ts.Node): boolean {\n return ts.isSourceFile(node) || ts.isBlock(node) || ts.isFunctionLike(node) || ts.isCatchClause(node)\n || ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node);\n}\n\nfunction isReference(node: ts.Identifier): boolean {\n const parent = node.parent;\n if (!parent) return false;\n if (ts.isPropertyAccessExpression(parent) && parent.name === node) return false;\n if (ts.isQualifiedName(parent) && parent.right === node) return false;\n if (ts.isPropertyAssignment(parent) && parent.name === node) return false;\n if (ts.isPropertyDeclaration(parent) && parent.name === node) return false;\n if (ts.isMethodDeclaration(parent) && parent.name === node) return false;\n if (ts.isImportSpecifier(parent) || ts.isExportSpecifier(parent) || ts.isImportClause(parent) || ts.isNamespaceImport(parent)) return false;\n if (ts.isTypeReferenceNode(parent) && parent.typeName === node) return true;\n if (ts.isParameter(parent) && parent.name === node) return false;\n if (ts.isTypeParameterDeclaration(parent) && parent.name === node) return false;\n if (ts.isVariableDeclaration(parent) && parent.name === node) return false;\n if ((ts.isFunctionDeclaration(parent) || ts.isClassDeclaration(parent) || ts.isInterfaceDeclaration(parent) || ts.isTypeAliasDeclaration(parent)) && parent.name === node) return false;\n if (ts.isPropertySignature(parent) && parent.name === node) return false;\n return true;\n}\n\n/** Añade imports ESM para referencias libres del módulo generado. */\nexport function applyAutoImports(code: string, filename: string, registry: readonly AutoImport[], target: \"client\" | \"server\" | \"shared\"): string {\n const ast = ts.createSourceFile(filename, code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);\n const referenced = new Set<string>();\n const visit = (node: ts.Node, scopes: readonly Set<string>[]): void => {\n const active = introducesScope(node) ? [...scopes, scopeNames(node)] : scopes;\n if (ts.isIdentifier(node) && isReference(node) && !active.some((scope) => scope.has(node.text))) referenced.add(node.text);\n ts.forEachChild(node, (child) => visit(child, active));\n };\n visit(ast, []);\n const imports: string[] = [];\n for (const name of [...referenced].sort()) {\n const candidates = registry.filter((entry) => entry.name === name);\n if (candidates.length === 0) continue;\n const allowed = candidates.filter((entry) => entry.scope === \"shared\" || entry.scope === target || (target !== \"shared\" && entry.scope === \"app\"));\n if (allowed.length === 0) throw new Error(`Autoimport ${name} is unavailable in ${target} scope`);\n if (allowed.length > 1) throw new Error(`Ambiguous autoimport ${name}: ${allowed.map((entry) => entry.file).join(\", \")}`);\n const entry = allowed[0]!;\n let specifier = entry.specifier ?? relative(resolve(filename, \"..\"), entry.file).replaceAll(\"\\\\\", \"/\");\n if (!entry.specifier && !specifier.startsWith(\".\")) specifier = `./${specifier}`;\n if (!entry.component && !entry.specifier) specifier = specifier.replace(/\\.[cm]?ts$/, \".js\");\n if (entry.component) imports.push(`import * as ${name} from ${JSON.stringify(specifier)};`);\n else imports.push(`import ${entry.typeOnly ? \"type \" : \"\"}{ ${entry.imported} as ${name} } from ${JSON.stringify(specifier)};`);\n }\n return imports.length ? `${imports.join(\"\\n\")}\\n${code}` : code;\n}\n\n/** Transforma un SFC usando exactamente el mismo compilador que el plugin Vite. */\nexport function transformAutoImports(source: string, filename: string, code: string, registry: readonly AutoImport[], target: \"client\" | \"server\"): string {\n parseSfc(source, filename);\n return applyAutoImports(code, filename, registry, target);\n}\n\n/** Compile result shared by Vite, CLI checks and declaration generation. */\nexport async function compileWithAutoImports(source: string, filename: string, options: CompileOptions = {}, target: \"client\" | \"server\" = \"client\"): Promise<CompileResult> {\n const compiled = compile(source, filename, options);\n const registry = await discoverAutoImports(projectRoot(filename));\n const code = transformAutoImports(source, filename, compiled.code, registry, target);\n const offset = code.length - compiled.code.length;\n return {\n ...compiled,\n code,\n mappings: offset ? compiled.mappings.map((mapping) => ({ ...mapping, generatedStart: mapping.generatedStart + offset, generatedEnd: mapping.generatedEnd + offset })) : compiled.mappings,\n };\n}\n"]}
package/dist/check.js CHANGED
@@ -1,51 +1,70 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { randomUUID } from "node:crypto";
3
- import { readFile, unlink, writeFile } from "node:fs/promises";
4
- import { basename, dirname, join, relative, resolve } from "node:path";
3
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { createRequire as createModuleRequire } from "node:module";
5
+ import { dirname, join, relative, resolve } from "node:path";
5
6
  import { promisify } from "node:util";
6
7
  import { fileURLToPath } from "node:url";
7
- import { compile } from "./compiler.js";
8
+ import { compileWithAutoImports } from "./autoimports.js";
8
9
  import { originalOffset } from "./compiler/mapping.js";
10
+ import { moduleSpecifiers } from "./compiler/import-graph.js";
11
+ import { projectRoot } from "./compiler/project-root.js";
9
12
  import { compileError, MeekoCompileError, locate } from "./compiler/sfc.js";
10
13
  const execFileAsync = promisify(execFile);
11
- const tscPath = join(dirname(fileURLToPath(import.meta.resolve("typescript/package.json"))), "bin", "tsc");
14
+ const typescriptPackage = fileURLToPath(import.meta.resolve("typescript/package.json"));
15
+ const tscPath = join(dirname(typescriptPackage), "bin", "tsc");
16
+ // The JS launcher spawns tsc.exe without windowsHide, which flashes a terminal in VS Code.
17
+ const nativeTscPath = process.platform === "win32"
18
+ ? join(dirname(createModuleRequire(typescriptPackage).resolve(`@typescript/typescript-win32-${process.arch}/package.json`)), "lib", "tsc.exe")
19
+ : undefined;
20
+ const tscExecutable = nativeTscPath && nativeTscPath.length >= 248 ? `\\\\?\\${nativeTscPath}` : nativeTscPath ?? process.execPath;
12
21
  async function compileGraph(source, filename) {
13
22
  const byOriginal = new Map();
14
23
  const byGenerated = new Map();
15
24
  const nonce = randomUUID();
25
+ const rootDirectory = projectRoot(filename);
26
+ const generatedDirectory = join(rootDirectory, ".meeko", "check", nonce);
16
27
  async function add(original, content) {
17
28
  const previous = byOriginal.get(original);
18
29
  if (previous)
19
30
  return previous;
20
- const compiled = compile(content, original);
31
+ const target = relative(rootDirectory, original).split(/[\\/]/)[0] === "server" ? "server" : "client";
32
+ const compiled = await compileWithAutoImports(content, original, {}, target);
21
33
  const entry = {
22
34
  original, source: content, code: compiled.code,
23
- generated: join(dirname(original), `.${basename(original)}.__meeko_check_${nonce}.ts`),
35
+ generated: join(generatedDirectory, relative(rootDirectory, original) + ".ts"),
24
36
  mappings: compiled.mappings.map((mapping) => ({ ...mapping })),
25
37
  };
26
38
  byOriginal.set(original, entry);
27
39
  byGenerated.set(entry.generated, entry);
28
- const importPattern = /\b(?:from\s*|import\s*)["']([^"']+\.meeko)["']/g;
29
40
  const edits = [];
30
- for (const match of entry.code.matchAll(importPattern)) {
31
- const specifier = match[1];
32
- const start = match.index + match[0].indexOf(specifier);
33
- if (!specifier.startsWith(".")) {
41
+ for (const specifier of moduleSpecifiers(entry.code, entry.generated)) {
42
+ const { value, start, end } = specifier;
43
+ if (!value.endsWith(".meeko") && !value.startsWith("."))
44
+ continue;
45
+ if (value.endsWith(".meeko") && !value.startsWith(".")) {
34
46
  throw compileError(content, original, "MEEK033", "Component imports must use relative .meeko paths", originalOffset(entry.mappings, start) ?? 0);
35
47
  }
36
- const childFilename = resolve(dirname(original), specifier);
37
- let childSource;
38
- try {
39
- childSource = await readFile(childFilename, "utf8");
48
+ let destination;
49
+ if (value.endsWith(".meeko")) {
50
+ const childFilename = resolve(dirname(original), value);
51
+ let childSource;
52
+ try {
53
+ childSource = await readFile(childFilename, "utf8");
54
+ }
55
+ catch {
56
+ throw compileError(content, original, "MEEK034", `Component import not found: ${value}`, originalOffset(entry.mappings, start) ?? 0);
57
+ }
58
+ const child = await add(childFilename, childSource);
59
+ destination = child.generated.replace(/\.ts$/, ".js");
40
60
  }
41
- catch {
42
- throw compileError(content, original, "MEEK034", `Component import not found: ${specifier}`, originalOffset(entry.mappings, start) ?? 0);
61
+ else {
62
+ destination = resolve(dirname(original), value);
43
63
  }
44
- const child = await add(childFilename, childSource);
45
- let target = relative(dirname(entry.generated), child.generated).replaceAll("\\", "/").replace(/\.ts$/, ".js");
64
+ let target = relative(dirname(entry.generated), destination).replaceAll("\\", "/");
46
65
  if (!target.startsWith("./") && !target.startsWith("../"))
47
66
  target = `./${target}`;
48
- edits.push({ start, end: start + specifier.length, text: target });
67
+ edits.push({ start, end, text: target });
49
68
  }
50
69
  for (const edit of edits.reverse()) {
51
70
  const delta = edit.text.length - (edit.end - edit.start);
@@ -60,7 +79,7 @@ async function compileGraph(source, filename) {
60
79
  return entry;
61
80
  }
62
81
  const root = await add(filename, source);
63
- return { root, entries: byGenerated };
82
+ return { root, entries: byGenerated, tempDirectory: generatedDirectory };
64
83
  }
65
84
  function generatedOffset(code, line, column) {
66
85
  const lines = code.split("\n");
@@ -92,20 +111,19 @@ export async function checkSource(source, filename) {
92
111
  return [error.diagnostic];
93
112
  throw error;
94
113
  }
95
- const written = [];
96
114
  let output = "";
97
115
  try {
98
116
  for (const entry of graph.entries.values()) {
117
+ await mkdir(dirname(entry.generated), { recursive: true });
99
118
  await writeFile(entry.generated, entry.code, { encoding: "utf8", flag: "wx" });
100
- written.push(entry.generated);
101
119
  }
102
120
  try {
103
- const result = await execFileAsync(process.execPath, [
104
- tscPath, "--ignoreConfig", "--noEmit", "--pretty", "false", "--strict", "--skipLibCheck",
121
+ const result = await execFileAsync(tscExecutable, [
122
+ ...(nativeTscPath ? [] : [tscPath]), "--ignoreConfig", "--noEmit", "--pretty", "false", "--strict", "--skipLibCheck",
105
123
  "--noUncheckedIndexedAccess", "--exactOptionalPropertyTypes", "--verbatimModuleSyntax",
106
124
  "--module", "nodenext", "--moduleResolution", "nodenext", "--target", "es2022",
107
125
  "--lib", "es2022,dom", graph.root.generated,
108
- ], { cwd: dirname(absolute), maxBuffer: 8 * 1024 * 1024 });
126
+ ], { cwd: dirname(absolute), maxBuffer: 8 * 1024 * 1024, windowsHide: true });
109
127
  output = result.stdout + result.stderr;
110
128
  }
111
129
  catch (error) {
@@ -116,15 +134,38 @@ export async function checkSource(source, filename) {
116
134
  }
117
135
  }
118
136
  finally {
119
- await Promise.all(written.map((path) => unlink(path)));
137
+ await rm(graph.tempDirectory, { recursive: true, force: true });
120
138
  }
121
139
  const typed = parseTypeScriptOutput(output);
122
140
  if (typed.length === 0 && output.trim())
123
141
  throw new Error(`TypeScript 7 check failed: ${output.trim()}`);
124
- return typed.map((diagnostic) => {
125
- const entry = graph.entries.get(resolve(dirname(absolute), diagnostic.file));
126
- const offset = entry ? originalOffset(entry.mappings, generatedOffset(entry.code, diagnostic.line, diagnostic.column)) : undefined;
127
- const message = entry && offset !== undefined ? diagnostic.message : `Generated TypeScript: ${diagnostic.message}`;
128
- return { code: diagnostic.code, message, filename: entry?.original ?? absolute, location: locate(entry?.source ?? source, offset ?? 0) };
129
- });
142
+ return Promise.all(typed.map(async (diagnostic) => {
143
+ const reported = resolve(dirname(absolute), diagnostic.file);
144
+ const entry = graph.entries.get(reported);
145
+ if (entry) {
146
+ const offset = originalOffset(entry.mappings, generatedOffset(entry.code, diagnostic.line, diagnostic.column));
147
+ return {
148
+ code: diagnostic.code,
149
+ message: offset === undefined ? `Generated TypeScript: ${diagnostic.message}` : diagnostic.message,
150
+ filename: entry.original,
151
+ location: locate(entry.source, offset ?? 0),
152
+ };
153
+ }
154
+ // TypeScript also checks .ts dependencies imported by the .meeko graph.
155
+ // Their positions already refer to the original file, not generated code.
156
+ let imported;
157
+ try {
158
+ imported = await readFile(reported, "utf8");
159
+ }
160
+ catch {
161
+ return { code: diagnostic.code, message: `Generated TypeScript: ${diagnostic.message}`, filename: absolute, location: locate(source, 0) };
162
+ }
163
+ return {
164
+ code: diagnostic.code,
165
+ message: diagnostic.message,
166
+ filename: reported,
167
+ location: locate(imported, generatedOffset(imported, diagnostic.line, diagnostic.column)),
168
+ };
169
+ }));
130
170
  }
171
+ //# sourceMappingURL=check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C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,CAAC,CAAC;SAC1F,CAAC;IACJ,CAAC,CAAC,CAAC,CAAC;AACN,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { createRequire as createModuleRequire } from \"node:module\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { fileURLToPath } from \"node:url\";\nimport { compileWithAutoImports } from \"./autoimports.js\";\nimport { originalOffset } from \"./compiler/mapping.js\";\nimport type { SourceMapping } from \"./compiler/mapping.js\";\nimport { moduleSpecifiers } from \"./compiler/import-graph.js\";\nimport { projectRoot } from \"./compiler/project-root.js\";\nimport { compileError, MeekoCompileError, locate } from \"./compiler/sfc.js\";\nimport type { CompileDiagnostic } from \"./compiler/sfc.js\";\n\nconst execFileAsync = promisify(execFile);\nconst typescriptPackage = fileURLToPath(import.meta.resolve(\"typescript/package.json\"));\nconst tscPath = join(dirname(typescriptPackage), \"bin\", \"tsc\");\n// The JS launcher spawns tsc.exe without windowsHide, which flashes a terminal in VS Code.\nconst nativeTscPath = process.platform === \"win32\"\n ? join(dirname(createModuleRequire(typescriptPackage).resolve(`@typescript/typescript-win32-${process.arch}/package.json`)), \"lib\", \"tsc.exe\")\n : undefined;\nconst tscExecutable = nativeTscPath && nativeTscPath.length >= 248 ? `\\\\\\\\?\\\\${nativeTscPath}` : nativeTscPath ?? process.execPath;\n\ninterface GeneratedEntry {\n original: string;\n generated: string;\n source: string;\n code: string;\n mappings: SourceMapping[];\n}\n\nasync function compileGraph(source: string, filename: string): Promise<{ root: GeneratedEntry; entries: Map<string, GeneratedEntry>; tempDirectory: string }> {\n const byOriginal = new Map<string, GeneratedEntry>();\n const byGenerated = new Map<string, GeneratedEntry>();\n const nonce = randomUUID();\n const rootDirectory = projectRoot(filename);\n const generatedDirectory = join(rootDirectory, \".meeko\", \"check\", nonce);\n async function add(original: string, content: string): Promise<GeneratedEntry> {\n const previous = byOriginal.get(original);\n if (previous) return previous;\n const target = relative(rootDirectory, original).split(/[\\\\/]/)[0] === \"server\" ? \"server\" : \"client\";\n const compiled = await compileWithAutoImports(content, original, {}, target);\n const entry: GeneratedEntry = {\n original, source: content, code: compiled.code,\n generated: join(generatedDirectory, relative(rootDirectory, original) + \".ts\"),\n mappings: compiled.mappings.map((mapping) => ({ ...mapping })),\n };\n byOriginal.set(original, entry);\n byGenerated.set(entry.generated, entry);\n const edits: Array<{ start: number; end: number; text: string }> = [];\n for (const specifier of moduleSpecifiers(entry.code, entry.generated)) {\n const { value, start, end } = specifier;\n if (!value.endsWith(\".meeko\") && !value.startsWith(\".\")) continue;\n if (value.endsWith(\".meeko\") && !value.startsWith(\".\")) {\n throw compileError(content, original, \"MEEK033\", \"Component imports must use relative .meeko paths\", originalOffset(entry.mappings, start) ?? 0);\n }\n let destination: string;\n if (value.endsWith(\".meeko\")) {\n const childFilename = resolve(dirname(original), value);\n let childSource: string;\n try {\n childSource = await readFile(childFilename, \"utf8\");\n } catch {\n throw compileError(content, original, \"MEEK034\", `Component import not found: ${value}`, originalOffset(entry.mappings, start) ?? 0);\n }\n const child = await add(childFilename, childSource);\n destination = child.generated.replace(/\\.ts$/, \".js\");\n } else {\n destination = resolve(dirname(original), value);\n }\n let target = relative(dirname(entry.generated), destination).replaceAll(\"\\\\\", \"/\");\n if (!target.startsWith(\"./\") && !target.startsWith(\"../\")) target = `./${target}`;\n edits.push({ start, end, text: target });\n }\n for (const edit of edits.reverse()) {\n const delta = edit.text.length - (edit.end - edit.start);\n entry.code = entry.code.slice(0, edit.start) + edit.text + entry.code.slice(edit.end);\n for (const mapping of entry.mappings) {\n if (mapping.generatedStart >= edit.end) mapping.generatedStart += delta;\n if (mapping.generatedEnd >= edit.end) mapping.generatedEnd += delta;\n }\n }\n return entry;\n }\n const root = await add(filename, source);\n return { root, entries: byGenerated, tempDirectory: generatedDirectory };\n}\n\nfunction generatedOffset(code: string, line: number, column: number): number {\n const lines = code.split(\"\\n\");\n let offset = 0;\n for (let index = 0; index < line - 1; index++) offset += (lines[index]?.length ?? 0) + 1;\n return offset + column - 1;\n}\n\nfunction parseTypeScriptOutput(output: string): Array<{ file: string; line: number; column: number; code: string; message: string }> {\n const diagnostics: Array<{ file: string; line: number; column: number; code: string; message: string }> = [];\n for (const line of output.split(/\\r?\\n/)) {\n const match = /^(.*)\\((\\d+),(\\d+)\\): error TS(\\d+): (.*)$/.exec(line);\n if (match) diagnostics.push({ file: match[1] ?? \"\", line: Number(match[2]), column: Number(match[3]), code: `TS${match[4]}`, message: match[5] ?? \"\" });\n else if (line.trim() && diagnostics.length > 0) diagnostics[diagnostics.length - 1]!.message += `\\n${line}`;\n }\n return diagnostics;\n}\n\n/** Comprueba un componente con TypeScript 7 y devuelve errores ubicados en el .meeko original. */\nexport async function checkSource(source: string, filename: string): Promise<CompileDiagnostic[]> {\n const absolute = resolve(filename);\n let graph: Awaited<ReturnType<typeof compileGraph>>;\n try {\n graph = await compileGraph(source, absolute);\n } catch (error) {\n if (error instanceof MeekoCompileError) return [error.diagnostic];\n throw error;\n }\n\n let output = \"\";\n try {\n for (const entry of graph.entries.values()) {\n await mkdir(dirname(entry.generated), { recursive: true });\n await writeFile(entry.generated, entry.code, { encoding: \"utf8\", flag: \"wx\" });\n }\n try {\n const result = await execFileAsync(tscExecutable, [\n ...(nativeTscPath ? [] : [tscPath]), \"--ignoreConfig\", \"--noEmit\", \"--pretty\", \"false\", \"--strict\", \"--skipLibCheck\",\n \"--noUncheckedIndexedAccess\", \"--exactOptionalPropertyTypes\", \"--verbatimModuleSyntax\",\n \"--module\", \"nodenext\", \"--moduleResolution\", \"nodenext\", \"--target\", \"es2022\",\n \"--lib\", \"es2022,dom\", graph.root.generated,\n ], { cwd: dirname(absolute), maxBuffer: 8 * 1024 * 1024, windowsHide: true });\n output = result.stdout + result.stderr;\n } catch (error) {\n const failure = error as Error & { stdout?: string; stderr?: string };\n output = `${failure.stdout ?? \"\"}${failure.stderr ?? \"\"}`;\n if (!output.trim()) throw error;\n }\n } finally {\n await rm(graph.tempDirectory, { recursive: true, force: true });\n }\n\n const typed = parseTypeScriptOutput(output);\n if (typed.length === 0 && output.trim()) throw new Error(`TypeScript 7 check failed: ${output.trim()}`);\n return Promise.all(typed.map(async (diagnostic) => {\n const reported = resolve(dirname(absolute), diagnostic.file);\n const entry = graph.entries.get(reported);\n if (entry) {\n const offset = originalOffset(entry.mappings, generatedOffset(entry.code, diagnostic.line, diagnostic.column));\n return {\n code: diagnostic.code,\n message: offset === undefined ? `Generated TypeScript: ${diagnostic.message}` : diagnostic.message,\n filename: entry.original,\n location: locate(entry.source, offset ?? 0),\n };\n }\n // TypeScript also checks .ts dependencies imported by the .meeko graph.\n // Their positions already refer to the original file, not generated code.\n let imported: string;\n try { imported = await readFile(reported, \"utf8\"); }\n catch {\n return { code: diagnostic.code, message: `Generated TypeScript: ${diagnostic.message}`, filename: absolute, location: locate(source, 0) };\n }\n return {\n code: diagnostic.code,\n message: diagnostic.message,\n filename: reported,\n location: locate(imported, generatedOffset(imported, diagnostic.line, diagnostic.column)),\n };\n }));\n}\n"]}