zero-query 1.1.1 → 1.2.2

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 (156) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -0
  3. package/cli/args.js +33 -33
  4. package/cli/commands/build-api.js +442 -442
  5. package/cli/commands/build.js +253 -247
  6. package/cli/commands/bundle.js +1226 -1224
  7. package/cli/commands/create.js +178 -121
  8. package/cli/commands/dev/devtools/index.js +56 -56
  9. package/cli/commands/dev/devtools/js/components.js +49 -49
  10. package/cli/commands/dev/devtools/js/core.js +423 -423
  11. package/cli/commands/dev/devtools/js/elements.js +421 -421
  12. package/cli/commands/dev/devtools/js/network.js +166 -166
  13. package/cli/commands/dev/devtools/js/performance.js +73 -73
  14. package/cli/commands/dev/devtools/js/router.js +105 -105
  15. package/cli/commands/dev/devtools/js/source.js +132 -132
  16. package/cli/commands/dev/devtools/js/stats.js +35 -35
  17. package/cli/commands/dev/devtools/js/tabs.js +79 -79
  18. package/cli/commands/dev/devtools/panel.html +95 -95
  19. package/cli/commands/dev/devtools/styles.css +244 -244
  20. package/cli/commands/dev/index.js +107 -107
  21. package/cli/commands/dev/logger.js +75 -75
  22. package/cli/commands/dev/overlay.js +858 -858
  23. package/cli/commands/dev/server.js +220 -220
  24. package/cli/commands/dev/validator.js +94 -94
  25. package/cli/commands/dev/watcher.js +172 -172
  26. package/cli/help.js +114 -112
  27. package/cli/index.js +52 -52
  28. package/cli/scaffold/default/LICENSE +21 -21
  29. package/cli/scaffold/default/app/app.js +207 -207
  30. package/cli/scaffold/default/app/components/about.js +201 -201
  31. package/cli/scaffold/default/app/components/api-demo.js +143 -143
  32. package/cli/scaffold/default/app/components/contact-card.js +231 -231
  33. package/cli/scaffold/default/app/components/contacts/contacts.css +706 -706
  34. package/cli/scaffold/default/app/components/contacts/contacts.html +200 -200
  35. package/cli/scaffold/default/app/components/contacts/contacts.js +196 -196
  36. package/cli/scaffold/default/app/components/counter.js +127 -127
  37. package/cli/scaffold/default/app/components/home.js +249 -249
  38. package/cli/scaffold/default/app/components/not-found.js +16 -16
  39. package/cli/scaffold/default/app/components/playground/playground.css +115 -115
  40. package/cli/scaffold/default/app/components/playground/playground.html +161 -161
  41. package/cli/scaffold/default/app/components/playground/playground.js +116 -116
  42. package/cli/scaffold/default/app/components/todos.js +225 -225
  43. package/cli/scaffold/default/app/components/toolkit/toolkit.css +97 -97
  44. package/cli/scaffold/default/app/components/toolkit/toolkit.html +146 -146
  45. package/cli/scaffold/default/app/components/toolkit/toolkit.js +280 -280
  46. package/cli/scaffold/default/app/routes.js +15 -15
  47. package/cli/scaffold/default/app/store.js +101 -101
  48. package/cli/scaffold/default/global.css +552 -552
  49. package/cli/scaffold/default/index.html +99 -99
  50. package/cli/scaffold/minimal/app/app.js +85 -85
  51. package/cli/scaffold/minimal/app/components/about.js +68 -68
  52. package/cli/scaffold/minimal/app/components/counter.js +122 -122
  53. package/cli/scaffold/minimal/app/components/home.js +68 -68
  54. package/cli/scaffold/minimal/app/components/not-found.js +16 -16
  55. package/cli/scaffold/minimal/app/routes.js +9 -9
  56. package/cli/scaffold/minimal/app/store.js +36 -36
  57. package/cli/scaffold/minimal/global.css +300 -300
  58. package/cli/scaffold/minimal/index.html +44 -44
  59. package/cli/scaffold/ssr/app/app.js +41 -41
  60. package/cli/scaffold/ssr/app/components/about.js +55 -55
  61. package/cli/scaffold/ssr/app/components/blog/index.js +65 -65
  62. package/cli/scaffold/ssr/app/components/blog/post.js +86 -86
  63. package/cli/scaffold/ssr/app/components/home.js +37 -37
  64. package/cli/scaffold/ssr/app/components/not-found.js +15 -15
  65. package/cli/scaffold/ssr/app/routes.js +8 -8
  66. package/cli/scaffold/ssr/global.css +228 -228
  67. package/cli/scaffold/ssr/index.html +37 -37
  68. package/cli/scaffold/ssr/package.json +8 -8
  69. package/cli/scaffold/ssr/server/data/posts.js +144 -144
  70. package/cli/scaffold/ssr/server/index.js +213 -213
  71. package/cli/scaffold/webrtc/app/app.js +11 -0
  72. package/cli/scaffold/webrtc/app/components/video-room.js +441 -0
  73. package/cli/scaffold/webrtc/assets/.gitkeep +0 -0
  74. package/cli/scaffold/webrtc/global.css +250 -0
  75. package/cli/scaffold/webrtc/index.html +21 -0
  76. package/cli/scaffold/webrtc/package.json +16 -0
  77. package/cli/scaffold/webrtc/server/index.js +198 -0
  78. package/cli/utils.js +305 -287
  79. package/dist/API.md +661 -0
  80. package/dist/zquery.dist.zip +0 -0
  81. package/dist/zquery.js +10454 -6614
  82. package/dist/zquery.min.js +8 -631
  83. package/index.d.ts +570 -371
  84. package/index.js +311 -240
  85. package/package.json +77 -70
  86. package/src/component.js +1758 -1691
  87. package/src/core.js +929 -921
  88. package/src/diff.js +497 -497
  89. package/src/errors.js +209 -209
  90. package/src/expression.js +929 -922
  91. package/src/http.js +242 -242
  92. package/src/package.json +1 -1
  93. package/src/reactive.js +271 -255
  94. package/src/router.js +878 -843
  95. package/src/ssr.js +421 -418
  96. package/src/store.js +325 -318
  97. package/src/utils.js +534 -515
  98. package/src/webrtc/e2ee.js +351 -0
  99. package/src/webrtc/errors.js +116 -0
  100. package/src/webrtc/ice.js +301 -0
  101. package/src/webrtc/index.js +131 -0
  102. package/src/webrtc/joinToken.js +119 -0
  103. package/src/webrtc/observe.js +172 -0
  104. package/src/webrtc/peer.js +351 -0
  105. package/src/webrtc/reactive.js +268 -0
  106. package/src/webrtc/room.js +625 -0
  107. package/src/webrtc/sdp.js +302 -0
  108. package/src/webrtc/sfu/index.js +43 -0
  109. package/src/webrtc/sfu/livekit.js +131 -0
  110. package/src/webrtc/sfu/mediasoup.js +150 -0
  111. package/src/webrtc/signaling.js +373 -0
  112. package/src/webrtc/turn.js +237 -0
  113. package/tests/_helpers/webrtcFakes.js +289 -0
  114. package/tests/audit.test.js +4158 -4158
  115. package/tests/bench/render.bench.js +77 -0
  116. package/tests/cli.test.js +1136 -1103
  117. package/tests/compare.test.js +497 -486
  118. package/tests/component.test.js +4076 -3938
  119. package/tests/core.test.js +1926 -1910
  120. package/tests/dev-server.test.js +489 -489
  121. package/tests/diff.test.js +1416 -1416
  122. package/tests/docs.test.js +1664 -1650
  123. package/tests/electron-features.test.js +864 -864
  124. package/tests/errors.test.js +619 -619
  125. package/tests/expression.test.js +1087 -1056
  126. package/tests/http.test.js +693 -648
  127. package/tests/reactive.test.js +844 -819
  128. package/tests/router.test.js +2423 -2327
  129. package/tests/ssr.test.js +916 -870
  130. package/tests/store.test.js +840 -830
  131. package/tests/test-minifier.js +153 -153
  132. package/tests/test-ssr.js +27 -27
  133. package/tests/utils.test.js +1411 -1377
  134. package/tests/webrtc/e2ee.test.js +283 -0
  135. package/tests/webrtc/ice.test.js +202 -0
  136. package/tests/webrtc/joinToken.test.js +89 -0
  137. package/tests/webrtc/observe.test.js +111 -0
  138. package/tests/webrtc/peer.test.js +373 -0
  139. package/tests/webrtc/reactive.test.js +235 -0
  140. package/tests/webrtc/room.test.js +406 -0
  141. package/tests/webrtc/sdp.test.js +151 -0
  142. package/tests/webrtc/sfu-livekit.test.js +119 -0
  143. package/tests/webrtc/sfu.test.js +160 -0
  144. package/tests/webrtc/signaling.test.js +251 -0
  145. package/tests/webrtc/turn.test.js +256 -0
  146. package/types/collection.d.ts +383 -383
  147. package/types/component.d.ts +186 -186
  148. package/types/errors.d.ts +135 -135
  149. package/types/http.d.ts +92 -92
  150. package/types/misc.d.ts +201 -201
  151. package/types/reactive.d.ts +98 -98
  152. package/types/router.d.ts +190 -190
  153. package/types/ssr.d.ts +102 -102
  154. package/types/store.d.ts +146 -146
  155. package/types/utils.d.ts +245 -245
  156. package/types/webrtc.d.ts +653 -0
@@ -1,153 +1,153 @@
1
- function minifyCSS(css) {
2
- css = css.replace(/\/\*[\s\S]*?\*\//g, '');
3
- css = css.replace(/\s{2,}/g, ' ');
4
- css = css.replace(/\s*([{};,])\s*/g, '$1');
5
- css = css.replace(/:\s+/g, ':');
6
- css = css.replace(/;}/g, '}');
7
- return css.trim();
8
- }
9
-
10
- const tests = [
11
- // Pseudo-classes with descendant combinator (the bug was that the space before :not() was being removed, which is incorrect)
12
- ['.docs-section :not(pre) > code { color: red }', 'space before :not()'],
13
- ['.foo :has(.bar) { color: red }', 'space before :has()'],
14
- ['.foo :is(.a, .b) { color: red }', 'space before :is()'],
15
- ['.foo :where(.a) { color: red }', 'space before :where()'],
16
-
17
- // Pseudo-elements
18
- ['.foo::before { content: "x" }', '::before'],
19
- ['.foo ::after { content: "x" }', 'space before ::after'],
20
-
21
- // Pseudo-classes directly on element (no space - should stay compact)
22
- ['a:hover { color: red }', ':hover no space'],
23
- ['li:nth-child(2n + 1) { color: red }', ':nth-child()'],
24
- ['input:focus-visible { outline: 1px }', ':focus-visible'],
25
-
26
- // calc() - spaces around operators are significant!
27
- ['.foo { width: calc(100% - 20px) }', 'calc() spaces'],
28
- ['.foo { width: calc(50vw + 2rem) }', 'calc() addition'],
29
- ['.foo { font-size: clamp(1rem, 2vw, 3rem) }', 'clamp()'],
30
-
31
- // @media
32
- ['@media (min-width: 768px) { .foo { color: red } }', '@media query'],
33
- ['@media screen and (max-width: 1024px) { .a { } }', '@media screen and'],
34
-
35
- // Selector combinators
36
- ['.foo > .bar { color: red }', 'child combinator >'],
37
- ['.foo + .bar { color: red }', 'adjacent sibling +'],
38
- ['.foo ~ .bar { color: red }', 'general sibling ~'],
39
- ['.foo .bar { color: red }', 'descendant combinator'],
40
-
41
- // Custom properties
42
- ['body { --main-color: #333; color: var(--main-color) }', 'CSS variables'],
43
-
44
- // Attribute selectors
45
- ['[data-theme="dark"] { color: white }', 'attribute selector'],
46
- ['a[href^="https:"] { color: green }', 'attr with colon'],
47
-
48
- // content with quotes
49
- ['.foo::before { content: "Hello World" }', 'content string'],
50
-
51
- // Multiple selectors with newlines
52
- ['.a,\n.b,\n.c { color: red }', 'selector list'],
53
-
54
- // Keyframes
55
- ['@keyframes fade { 0% { opacity: 0 } 100% { opacity: 1 } }', '@keyframes'],
56
-
57
- // Nested :not with pseudo-class inside
58
- ['.foo :not(:last-child) { margin: 0 }', ':not(:last-child)'],
59
-
60
- // Double :not
61
- ['.bar :not(.a):not(.b) { color: red }', 'chained :not()'],
62
-
63
- // :first-child as descendant
64
- ['.list :first-child { font-weight: bold }', 'space before :first-child'],
65
-
66
- // content with multiple spaces (potential issue)
67
- ['.foo::before { content: "a b" }', 'content double space'],
68
-
69
- // grid-template-areas
70
- ['.grid { grid-template-areas: "a a" "b c" }', 'grid-template-areas'],
71
- ];
72
-
73
- console.log('=== CSS Minifier Edge Case Tests ===\n');
74
- let issues = 0;
75
- for (const [input, label] of tests) {
76
- const result = minifyCSS(input);
77
- console.log(`${label.padEnd(30)}| ${result}`);
78
- }
79
-
80
- // Specific assertions
81
- console.log('\n=== Assertions ===\n');
82
- function assert(input, expected, label) {
83
- const result = minifyCSS(input);
84
- const pass = result === expected;
85
- console.log(`${pass ? 'PASS' : 'FAIL'} ${label}`);
86
- if (!pass) {
87
- console.log(` Expected: ${expected}`);
88
- console.log(` Got: ${result}`);
89
- issues++;
90
- }
91
- }
92
-
93
- assert('.parent :not(pre) > code { color: red }',
94
- '.parent :not(pre) > code{color:red}',
95
- 'space before :not() preserved');
96
-
97
- assert('a:hover { color: red }',
98
- 'a:hover{color:red}',
99
- ':hover stays compact');
100
-
101
- assert('.foo { width: calc(100% - 20px) }',
102
- '.foo{width:calc(100% - 20px)}',
103
- 'calc() spaces preserved');
104
-
105
- assert('@media (min-width: 768px) { .a { color: red } }',
106
- '@media (min-width:768px){.a{color:red}}',
107
- '@media colon stripped');
108
-
109
- assert('.foo > .bar { color: red }',
110
- '.foo > .bar{color:red}',
111
- 'child combinator preserved');
112
-
113
- assert('.foo + .bar { color: red }',
114
- '.foo + .bar{color:red}',
115
- 'adjacent sibling preserved');
116
-
117
- assert('.foo .bar { color: red }',
118
- '.foo .bar{color:red}',
119
- 'descendant space preserved');
120
-
121
- assert('.foo::before { content: "x" }',
122
- '.foo::before{content:"x"}',
123
- '::before works');
124
-
125
- assert('.foo ::after { content: "x" }',
126
- '.foo ::after{content:"x"}',
127
- 'space before ::after preserved');
128
-
129
- assert('li:nth-child(2n + 1) { color: red }',
130
- 'li:nth-child(2n + 1){color:red}',
131
- ':nth-child args preserved');
132
-
133
- assert('.list :first-child { font-weight: bold }',
134
- '.list :first-child{font-weight:bold}',
135
- 'space before :first-child preserved');
136
-
137
- assert('.list :last-child { font-weight: bold }',
138
- '.list :last-child{font-weight:bold}',
139
- 'space before :last-child preserved');
140
-
141
- assert('.bar :not(.a):not(.b) { color: red }',
142
- '.bar :not(.a):not(.b){color:red}',
143
- 'chained :not() with leading space');
144
-
145
- // Edge case: content with double spaces inside quotes
146
- const dblSpace = minifyCSS('.foo::before { content: "a b" }');
147
- if (dblSpace.includes('content:"a b"')) {
148
- console.log('WARN content double space - "a b" collapsed to "a b" (cosmetic, not functional)');
149
- } else {
150
- console.log('PASS content double space preserved');
151
- }
152
-
153
- console.log(`\n${issues === 0 ? 'All assertions passed!' : issues + ' assertion(s) failed!'}`);
1
+ function minifyCSS(css) {
2
+ css = css.replace(/\/\*[\s\S]*?\*\//g, '');
3
+ css = css.replace(/\s{2,}/g, ' ');
4
+ css = css.replace(/\s*([{};,])\s*/g, '$1');
5
+ css = css.replace(/:\s+/g, ':');
6
+ css = css.replace(/;}/g, '}');
7
+ return css.trim();
8
+ }
9
+
10
+ const tests = [
11
+ // Pseudo-classes with descendant combinator (the bug was that the space before :not() was being removed, which is incorrect)
12
+ ['.docs-section :not(pre) > code { color: red }', 'space before :not()'],
13
+ ['.foo :has(.bar) { color: red }', 'space before :has()'],
14
+ ['.foo :is(.a, .b) { color: red }', 'space before :is()'],
15
+ ['.foo :where(.a) { color: red }', 'space before :where()'],
16
+
17
+ // Pseudo-elements
18
+ ['.foo::before { content: "x" }', '::before'],
19
+ ['.foo ::after { content: "x" }', 'space before ::after'],
20
+
21
+ // Pseudo-classes directly on element (no space - should stay compact)
22
+ ['a:hover { color: red }', ':hover no space'],
23
+ ['li:nth-child(2n + 1) { color: red }', ':nth-child()'],
24
+ ['input:focus-visible { outline: 1px }', ':focus-visible'],
25
+
26
+ // calc() - spaces around operators are significant!
27
+ ['.foo { width: calc(100% - 20px) }', 'calc() spaces'],
28
+ ['.foo { width: calc(50vw + 2rem) }', 'calc() addition'],
29
+ ['.foo { font-size: clamp(1rem, 2vw, 3rem) }', 'clamp()'],
30
+
31
+ // @media
32
+ ['@media (min-width: 768px) { .foo { color: red } }', '@media query'],
33
+ ['@media screen and (max-width: 1024px) { .a { } }', '@media screen and'],
34
+
35
+ // Selector combinators
36
+ ['.foo > .bar { color: red }', 'child combinator >'],
37
+ ['.foo + .bar { color: red }', 'adjacent sibling +'],
38
+ ['.foo ~ .bar { color: red }', 'general sibling ~'],
39
+ ['.foo .bar { color: red }', 'descendant combinator'],
40
+
41
+ // Custom properties
42
+ ['body { --main-color: #333; color: var(--main-color) }', 'CSS variables'],
43
+
44
+ // Attribute selectors
45
+ ['[data-theme="dark"] { color: white }', 'attribute selector'],
46
+ ['a[href^="https:"] { color: green }', 'attr with colon'],
47
+
48
+ // content with quotes
49
+ ['.foo::before { content: "Hello World" }', 'content string'],
50
+
51
+ // Multiple selectors with newlines
52
+ ['.a,\n.b,\n.c { color: red }', 'selector list'],
53
+
54
+ // Keyframes
55
+ ['@keyframes fade { 0% { opacity: 0 } 100% { opacity: 1 } }', '@keyframes'],
56
+
57
+ // Nested :not with pseudo-class inside
58
+ ['.foo :not(:last-child) { margin: 0 }', ':not(:last-child)'],
59
+
60
+ // Double :not
61
+ ['.bar :not(.a):not(.b) { color: red }', 'chained :not()'],
62
+
63
+ // :first-child as descendant
64
+ ['.list :first-child { font-weight: bold }', 'space before :first-child'],
65
+
66
+ // content with multiple spaces (potential issue)
67
+ ['.foo::before { content: "a b" }', 'content double space'],
68
+
69
+ // grid-template-areas
70
+ ['.grid { grid-template-areas: "a a" "b c" }', 'grid-template-areas'],
71
+ ];
72
+
73
+ console.log('=== CSS Minifier Edge Case Tests ===\n');
74
+ let issues = 0;
75
+ for (const [input, label] of tests) {
76
+ const result = minifyCSS(input);
77
+ console.log(`${label.padEnd(30)}| ${result}`);
78
+ }
79
+
80
+ // Specific assertions
81
+ console.log('\n=== Assertions ===\n');
82
+ function assert(input, expected, label) {
83
+ const result = minifyCSS(input);
84
+ const pass = result === expected;
85
+ console.log(`${pass ? 'PASS' : 'FAIL'} ${label}`);
86
+ if (!pass) {
87
+ console.log(` Expected: ${expected}`);
88
+ console.log(` Got: ${result}`);
89
+ issues++;
90
+ }
91
+ }
92
+
93
+ assert('.parent :not(pre) > code { color: red }',
94
+ '.parent :not(pre) > code{color:red}',
95
+ 'space before :not() preserved');
96
+
97
+ assert('a:hover { color: red }',
98
+ 'a:hover{color:red}',
99
+ ':hover stays compact');
100
+
101
+ assert('.foo { width: calc(100% - 20px) }',
102
+ '.foo{width:calc(100% - 20px)}',
103
+ 'calc() spaces preserved');
104
+
105
+ assert('@media (min-width: 768px) { .a { color: red } }',
106
+ '@media (min-width:768px){.a{color:red}}',
107
+ '@media colon stripped');
108
+
109
+ assert('.foo > .bar { color: red }',
110
+ '.foo > .bar{color:red}',
111
+ 'child combinator preserved');
112
+
113
+ assert('.foo + .bar { color: red }',
114
+ '.foo + .bar{color:red}',
115
+ 'adjacent sibling preserved');
116
+
117
+ assert('.foo .bar { color: red }',
118
+ '.foo .bar{color:red}',
119
+ 'descendant space preserved');
120
+
121
+ assert('.foo::before { content: "x" }',
122
+ '.foo::before{content:"x"}',
123
+ '::before works');
124
+
125
+ assert('.foo ::after { content: "x" }',
126
+ '.foo ::after{content:"x"}',
127
+ 'space before ::after preserved');
128
+
129
+ assert('li:nth-child(2n + 1) { color: red }',
130
+ 'li:nth-child(2n + 1){color:red}',
131
+ ':nth-child args preserved');
132
+
133
+ assert('.list :first-child { font-weight: bold }',
134
+ '.list :first-child{font-weight:bold}',
135
+ 'space before :first-child preserved');
136
+
137
+ assert('.list :last-child { font-weight: bold }',
138
+ '.list :last-child{font-weight:bold}',
139
+ 'space before :last-child preserved');
140
+
141
+ assert('.bar :not(.a):not(.b) { color: red }',
142
+ '.bar :not(.a):not(.b){color:red}',
143
+ 'chained :not() with leading space');
144
+
145
+ // Edge case: content with double spaces inside quotes
146
+ const dblSpace = minifyCSS('.foo::before { content: "a b" }');
147
+ if (dblSpace.includes('content:"a b"')) {
148
+ console.log('WARN content double space - "a b" collapsed to "a b" (cosmetic, not functional)');
149
+ } else {
150
+ console.log('PASS content double space preserved');
151
+ }
152
+
153
+ console.log(`\n${issues === 0 ? 'All assertions passed!' : issues + ' assertion(s) failed!'}`);
package/tests/test-ssr.js CHANGED
@@ -1,27 +1,27 @@
1
- #!/usr/bin/env node
2
- const { execSync, spawn } = require('child_process');
3
- const { mkdtempSync, rmSync } = require('fs');
4
- const { join } = require('path');
5
- const os = require('os');
6
-
7
- const root = join(__dirname, '..');
8
- const tmp = mkdtempSync(join(os.tmpdir(), 'zq-ssr-'));
9
-
10
- console.log(`Scaffolding SSR app to ${tmp}\n`);
11
- execSync(`node cli/index.js create "${tmp}" --ssr`, { cwd: root, stdio: 'inherit' });
12
- console.log(`\nInstalling local zero-query...\n`);
13
- execSync(`npm install "${root}"`, { cwd: tmp, stdio: 'inherit' });
14
-
15
- console.log(`\nStarting SSR server...\n`);
16
- const child = spawn('node', ['server/index.js'], { cwd: tmp, stdio: 'inherit' });
17
-
18
- setTimeout(() => {
19
- const open = process.platform === 'win32' ? 'start'
20
- : process.platform === 'darwin' ? 'open' : 'xdg-open';
21
- try { execSync(`${open} http://localhost:3000`, { stdio: 'ignore' }); } catch {}
22
- }, 500);
23
-
24
- function cleanup() { try { rmSync(tmp, { recursive: true, force: true }); } catch {} }
25
- process.on('SIGINT', () => { child.kill(); cleanup(); process.exit(); });
26
- process.on('SIGTERM', () => { child.kill(); cleanup(); process.exit(); });
27
- child.on('exit', () => { cleanup(); process.exit(); });
1
+ #!/usr/bin/env node
2
+ const { execSync, spawn } = require('child_process');
3
+ const { mkdtempSync, rmSync } = require('fs');
4
+ const { join } = require('path');
5
+ const os = require('os');
6
+
7
+ const root = join(__dirname, '..');
8
+ const tmp = mkdtempSync(join(os.tmpdir(), 'zq-ssr-'));
9
+
10
+ console.log(`Scaffolding SSR app to ${tmp}\n`);
11
+ execSync(`node cli/index.js create "${tmp}" --ssr`, { cwd: root, stdio: 'inherit' });
12
+ console.log(`\nInstalling local zero-query...\n`);
13
+ execSync(`npm install "${root}"`, { cwd: tmp, stdio: 'inherit' });
14
+
15
+ console.log(`\nStarting SSR server...\n`);
16
+ const child = spawn('node', ['server/index.js'], { cwd: tmp, stdio: 'inherit' });
17
+
18
+ setTimeout(() => {
19
+ const open = process.platform === 'win32' ? 'start'
20
+ : process.platform === 'darwin' ? 'open' : 'xdg-open';
21
+ try { execSync(`${open} http://localhost:3000`, { stdio: 'ignore' }); } catch {}
22
+ }, 500);
23
+
24
+ function cleanup() { try { rmSync(tmp, { recursive: true, force: true }); } catch {} }
25
+ process.on('SIGINT', () => { child.kill(); cleanup(); process.exit(); });
26
+ process.on('SIGTERM', () => { child.kill(); cleanup(); process.exit(); });
27
+ child.on('exit', () => { cleanup(); process.exit(); });