almostnode 0.2.6 → 0.2.8

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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/__sw__.js +80 -84
  3. package/dist/assets/{runtime-worker-B8_LZkBX.js → runtime-worker-D8VYeuKv.js} +1448 -1121
  4. package/dist/assets/runtime-worker-D8VYeuKv.js.map +1 -0
  5. package/dist/frameworks/code-transforms.d.ts +53 -0
  6. package/dist/frameworks/code-transforms.d.ts.map +1 -0
  7. package/dist/frameworks/next-config-parser.d.ts +16 -0
  8. package/dist/frameworks/next-config-parser.d.ts.map +1 -0
  9. package/dist/frameworks/next-dev-server.d.ts +29 -18
  10. package/dist/frameworks/next-dev-server.d.ts.map +1 -1
  11. package/dist/frameworks/next-html-generator.d.ts +35 -0
  12. package/dist/frameworks/next-html-generator.d.ts.map +1 -0
  13. package/dist/frameworks/next-shims.d.ts +79 -0
  14. package/dist/frameworks/next-shims.d.ts.map +1 -0
  15. package/dist/frameworks/vite-dev-server.d.ts +0 -4
  16. package/dist/frameworks/vite-dev-server.d.ts.map +1 -1
  17. package/dist/index.cjs +30392 -9523
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +3 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.mjs +27296 -8797
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/runtime.d.ts +20 -0
  24. package/dist/runtime.d.ts.map +1 -1
  25. package/dist/server-bridge.d.ts +2 -0
  26. package/dist/server-bridge.d.ts.map +1 -1
  27. package/dist/shims/crypto.d.ts +2 -0
  28. package/dist/shims/crypto.d.ts.map +1 -1
  29. package/dist/shims/esbuild.d.ts.map +1 -1
  30. package/dist/shims/fs.d.ts.map +1 -1
  31. package/dist/shims/http.d.ts +29 -0
  32. package/dist/shims/http.d.ts.map +1 -1
  33. package/dist/shims/path.d.ts.map +1 -1
  34. package/dist/shims/stream.d.ts.map +1 -1
  35. package/dist/shims/vfs-adapter.d.ts.map +1 -1
  36. package/dist/shims/ws.d.ts +2 -0
  37. package/dist/shims/ws.d.ts.map +1 -1
  38. package/dist/utils/binary-encoding.d.ts +13 -0
  39. package/dist/utils/binary-encoding.d.ts.map +1 -0
  40. package/dist/virtual-fs.d.ts.map +1 -1
  41. package/package.json +8 -4
  42. package/src/convex-app-demo-entry.ts +231 -35
  43. package/src/frameworks/code-transforms.ts +581 -0
  44. package/src/frameworks/next-config-parser.ts +140 -0
  45. package/src/frameworks/next-dev-server.ts +561 -1641
  46. package/src/frameworks/next-html-generator.ts +597 -0
  47. package/src/frameworks/next-shims.ts +1050 -0
  48. package/src/frameworks/tailwind-config-loader.ts +1 -1
  49. package/src/frameworks/vite-dev-server.ts +2 -61
  50. package/src/index.ts +2 -0
  51. package/src/runtime.ts +94 -15
  52. package/src/server-bridge.ts +61 -28
  53. package/src/shims/crypto.ts +13 -0
  54. package/src/shims/esbuild.ts +4 -1
  55. package/src/shims/fs.ts +9 -11
  56. package/src/shims/http.ts +309 -3
  57. package/src/shims/path.ts +6 -13
  58. package/src/shims/stream.ts +12 -26
  59. package/src/shims/vfs-adapter.ts +5 -2
  60. package/src/shims/ws.ts +92 -2
  61. package/src/utils/binary-encoding.ts +43 -0
  62. package/src/virtual-fs.ts +7 -15
  63. package/dist/assets/runtime-worker-B8_LZkBX.js.map +0 -1
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Next.js Config Parser
3
+ *
4
+ * Extracts configuration values from next.config.{ts,js,mjs} files
5
+ * using acorn AST parsing with regex fallback.
6
+ */
7
+
8
+ import * as acorn from 'acorn';
9
+ import { stripTypescriptSyntax } from './tailwind-config-loader';
10
+
11
+ /**
12
+ * Parse a string value from a Next.js config file.
13
+ *
14
+ * @param content - Raw file content of next.config.{ts,js,mjs}
15
+ * @param key - Config key to extract (e.g., 'assetPrefix', 'basePath')
16
+ * @param isTypeScript - Whether the content needs TypeScript syntax stripping
17
+ * @returns The string value, or null if not found
18
+ */
19
+ export function parseNextConfigValue(
20
+ content: string,
21
+ key: string,
22
+ isTypeScript: boolean = false
23
+ ): string | null {
24
+ const processed = isTypeScript ? stripTypescriptSyntax(content) : content;
25
+ try {
26
+ return parseNextConfigValueAst(processed, key);
27
+ } catch {
28
+ return parseNextConfigValueRegex(processed, key);
29
+ }
30
+ }
31
+
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ type ASTNode = any;
34
+
35
+ function parseNextConfigValueAst(content: string, key: string): string | null {
36
+ const ast = acorn.parse(content, {
37
+ ecmaVersion: 'latest',
38
+ sourceType: 'module',
39
+ });
40
+
41
+ // Collect top-level variable declarations: name -> init node
42
+ const variables = new Map<string, ASTNode>();
43
+ for (const node of (ast as ASTNode).body) {
44
+ if (node.type === 'VariableDeclaration') {
45
+ for (const decl of node.declarations) {
46
+ if (decl.id?.name && decl.init) {
47
+ variables.set(decl.id.name, decl.init);
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ // Find the exported config object
54
+ let configObject: ASTNode = null;
55
+
56
+ for (const node of (ast as ASTNode).body) {
57
+ // export default { ... } or export default configVar
58
+ if (node.type === 'ExportDefaultDeclaration') {
59
+ configObject = resolveToObject(node.declaration, variables);
60
+ if (configObject) break;
61
+ }
62
+
63
+ // module.exports = { ... } or module.exports = configVar
64
+ if (
65
+ node.type === 'ExpressionStatement' &&
66
+ node.expression.type === 'AssignmentExpression' &&
67
+ node.expression.left.type === 'MemberExpression' &&
68
+ node.expression.left.object?.name === 'module' &&
69
+ node.expression.left.property?.name === 'exports'
70
+ ) {
71
+ configObject = resolveToObject(node.expression.right, variables);
72
+ if (configObject) break;
73
+ }
74
+ }
75
+
76
+ if (!configObject || configObject.type !== 'ObjectExpression') {
77
+ return null;
78
+ }
79
+
80
+ // Find the property matching key
81
+ for (const prop of configObject.properties) {
82
+ if (prop.type !== 'Property') continue;
83
+
84
+ const propName =
85
+ prop.key.type === 'Identifier'
86
+ ? prop.key.name
87
+ : prop.key.type === 'Literal'
88
+ ? String(prop.key.value)
89
+ : null;
90
+
91
+ if (propName !== key) continue;
92
+
93
+ return resolveToString(prop.value, variables);
94
+ }
95
+
96
+ return null;
97
+ }
98
+
99
+ /** Resolve a node to an ObjectExpression, following Identifiers and CallExpressions */
100
+ function resolveToObject(
101
+ node: ASTNode,
102
+ variables: Map<string, ASTNode>
103
+ ): ASTNode | null {
104
+ if (!node) return null;
105
+ if (node.type === 'ObjectExpression') return node;
106
+ if (node.type === 'Identifier') {
107
+ const init = variables.get(node.name);
108
+ return init ? resolveToObject(init, variables) : null;
109
+ }
110
+ // Handle wrapper functions like defineConfig({ ... })
111
+ if (node.type === 'CallExpression' && node.arguments.length > 0) {
112
+ return resolveToObject(node.arguments[0], variables);
113
+ }
114
+ return null;
115
+ }
116
+
117
+ /** Resolve a node to a string value, following Identifiers */
118
+ function resolveToString(
119
+ node: ASTNode,
120
+ variables: Map<string, ASTNode>
121
+ ): string | null {
122
+ if (!node) return null;
123
+ if (node.type === 'Literal' && typeof node.value === 'string') {
124
+ return node.value;
125
+ }
126
+ if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {
127
+ return node.quasis[0]?.value?.cooked ?? null;
128
+ }
129
+ if (node.type === 'Identifier') {
130
+ const init = variables.get(node.name);
131
+ return init ? resolveToString(init, variables) : null;
132
+ }
133
+ return null;
134
+ }
135
+
136
+ function parseNextConfigValueRegex(content: string, key: string): string | null {
137
+ const regex = new RegExp(`${key}\\s*:\\s*["'\`]([^"'\`]+)["'\`]`);
138
+ const match = content.match(regex);
139
+ return match ? match[1] : null;
140
+ }