slicejs-web-framework 3.4.4 → 3.5.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 (101) hide show
  1. package/Slice/Components/Structural/Controller/Controller.js +135 -0
  2. package/Slice/Components/Structural/EventManager/EventManager.js +289 -4
  3. package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +368 -30
  4. package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -0
  5. package/Slice/Slice.js +14 -1
  6. package/Slice/tests/event-emitters.test.js +79 -0
  7. package/Slice/tests/event-registry.test.js +141 -0
  8. package/Slice/tests/leak-orphans.test.js +131 -0
  9. package/api/index.js +35 -8
  10. package/package.json +1 -1
  11. package/sliceConfig.schema.json +10 -1
  12. package/src/sliceConfig.json +5 -1
  13. package/types/index.d.ts +12 -0
  14. package/slicejs-cli/.github/workflows/ci.yml +0 -43
  15. package/slicejs-cli/LICENSE +0 -21
  16. package/slicejs-cli/assets/Slice.js-logo.png +0 -0
  17. package/slicejs-cli/client.js +0 -740
  18. package/slicejs-cli/commands/Print.js +0 -164
  19. package/slicejs-cli/commands/Validations.js +0 -92
  20. package/slicejs-cli/commands/build/build.js +0 -40
  21. package/slicejs-cli/commands/buildProduction/buildProduction.js +0 -577
  22. package/slicejs-cli/commands/bundle/bundle.js +0 -236
  23. package/slicejs-cli/commands/createComponent/VisualComponentTemplate.js +0 -55
  24. package/slicejs-cli/commands/createComponent/createComponent.js +0 -128
  25. package/slicejs-cli/commands/deleteComponent/deleteComponent.js +0 -81
  26. package/slicejs-cli/commands/doctor/doctor.js +0 -516
  27. package/slicejs-cli/commands/getComponent/getComponent.js +0 -695
  28. package/slicejs-cli/commands/init/init.js +0 -473
  29. package/slicejs-cli/commands/listComponents/listComponents.js +0 -172
  30. package/slicejs-cli/commands/startServer/startServer.js +0 -240
  31. package/slicejs-cli/commands/startServer/watchServer.js +0 -66
  32. package/slicejs-cli/commands/types/types.js +0 -583
  33. package/slicejs-cli/commands/utils/LocalCliDelegation.js +0 -53
  34. package/slicejs-cli/commands/utils/PackageManager.js +0 -148
  35. package/slicejs-cli/commands/utils/PathHelper.js +0 -75
  36. package/slicejs-cli/commands/utils/VersionChecker.js +0 -169
  37. package/slicejs-cli/commands/utils/bundling/BundleGenerator.js +0 -2525
  38. package/slicejs-cli/commands/utils/bundling/DependencyAnalyzer.js +0 -933
  39. package/slicejs-cli/commands/utils/loadConfig.js +0 -31
  40. package/slicejs-cli/commands/utils/sliceScripts.js +0 -48
  41. package/slicejs-cli/commands/utils/updateManager.js +0 -471
  42. package/slicejs-cli/package.json +0 -71
  43. package/slicejs-cli/playwright.config.js +0 -51
  44. package/slicejs-cli/pnpm-lock.yaml +0 -1629
  45. package/slicejs-cli/tests/build-command-integration.test.js +0 -87
  46. package/slicejs-cli/tests/build-mangling-e2e.test.js +0 -290
  47. package/slicejs-cli/tests/build-production-e2e.test.js +0 -140
  48. package/slicejs-cli/tests/builder-edge-cases.test.js +0 -322
  49. package/slicejs-cli/tests/bundle-generate-e2e.test.js +0 -115
  50. package/slicejs-cli/tests/bundle-generator.test.js +0 -691
  51. package/slicejs-cli/tests/bundle-v2-register-output.test.js +0 -470
  52. package/slicejs-cli/tests/bundling-dependency-edges.test.js +0 -127
  53. package/slicejs-cli/tests/bundling-imports-unit.test.js +0 -267
  54. package/slicejs-cli/tests/client-launcher-contract.test.js +0 -211
  55. package/slicejs-cli/tests/commands-component-crud.test.js +0 -128
  56. package/slicejs-cli/tests/commands-doctor.test.js +0 -152
  57. package/slicejs-cli/tests/commands-version-checker.test.js +0 -37
  58. package/slicejs-cli/tests/component-registry-parse.test.js +0 -34
  59. package/slicejs-cli/tests/dependency-analyzer.test.js +0 -24
  60. package/slicejs-cli/tests/e2e/bundles.spec.js +0 -91
  61. package/slicejs-cli/tests/e2e/dependency-scenarios.spec.js +0 -56
  62. package/slicejs-cli/tests/e2e/fixtures/components/Service/FetchManager/FetchManager.js +0 -136
  63. package/slicejs-cli/tests/e2e/fixtures/components/Service/IndexedDbManager/IndexedDbManager.js +0 -149
  64. package/slicejs-cli/tests/e2e/fixtures/components/Service/LocalStorageManager/LocalStorageManager.js +0 -45
  65. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Button/Button.css +0 -106
  66. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Button/Button.html +0 -5
  67. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Button/Button.js +0 -158
  68. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Link/Link.js +0 -33
  69. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Loading/Loading.css +0 -56
  70. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Loading/Loading.html +0 -83
  71. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Loading/Loading.js +0 -164
  72. package/slicejs-cli/tests/e2e/fixtures/components/Visual/MultiRoute/MultiRoute.js +0 -167
  73. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Navbar/Navbar.css +0 -116
  74. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Navbar/Navbar.html +0 -44
  75. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Navbar/Navbar.js +0 -180
  76. package/slicejs-cli/tests/e2e/fixtures/components/Visual/NotFound/NotFound.js +0 -20
  77. package/slicejs-cli/tests/e2e/fixtures/components/Visual/Route/Route.js +0 -181
  78. package/slicejs-cli/tests/e2e/fixtures/components/registry.json +0 -12
  79. package/slicejs-cli/tests/e2e/fixtures/vendor-components.mjs +0 -65
  80. package/slicejs-cli/tests/e2e/navigation.spec.js +0 -44
  81. package/slicejs-cli/tests/e2e/render.spec.js +0 -34
  82. package/slicejs-cli/tests/e2e/serve.mjs +0 -264
  83. package/slicejs-cli/tests/e2e/shared-deps.spec.js +0 -61
  84. package/slicejs-cli/tests/e2e/unminified.spec.js +0 -33
  85. package/slicejs-cli/tests/e2e-serve.test.js +0 -148
  86. package/slicejs-cli/tests/fixtures/components.js +0 -8
  87. package/slicejs-cli/tests/fixtures/sliceConfig.json +0 -74
  88. package/slicejs-cli/tests/getcomponent.test.js +0 -435
  89. package/slicejs-cli/tests/helpers/setup.js +0 -102
  90. package/slicejs-cli/tests/init-command-contract.test.js +0 -101
  91. package/slicejs-cli/tests/init-e2e.test.js +0 -82
  92. package/slicejs-cli/tests/init-project-isolation.test.js +0 -98
  93. package/slicejs-cli/tests/local-cli-delegation.test.js +0 -81
  94. package/slicejs-cli/tests/package-manager.test.js +0 -127
  95. package/slicejs-cli/tests/path-helper.test.js +0 -206
  96. package/slicejs-cli/tests/perf-budget.test.js +0 -84
  97. package/slicejs-cli/tests/postinstall-command.test.js +0 -103
  98. package/slicejs-cli/tests/property-mangling-regression.test.js +0 -182
  99. package/slicejs-cli/tests/types-breakage.test.js +0 -491
  100. package/slicejs-cli/tests/types-generator-errors.test.js +0 -361
  101. package/slicejs-cli/tests/types-generator.test.js +0 -348
@@ -1,240 +0,0 @@
1
- // commands/startServer/startServer.js - IMPROVED WITH VALIDATION AND FEEDBACK
2
-
3
- import fs from 'fs-extra';
4
- import path from 'path';
5
- import { spawn } from 'child_process';
6
- import { createServer } from 'net';
7
- import setupWatcher, { stopWatcher } from './watchServer.js';
8
- import Print from '../Print.js';
9
- import { getApiPath, getSrcPath, getDistPath, getPath } from '../utils/PathHelper.js';
10
- import { loadConfigSync } from '../utils/loadConfig.js';
11
- import build from '../build/build.js';
12
-
13
- /**
14
- * Checks if a port is available
15
- */
16
- async function isPortAvailable(port) {
17
- return new Promise((resolve) => {
18
- const server = createServer();
19
-
20
- server.once('error', (err) => {
21
- if (err.code === 'EADDRINUSE') {
22
- resolve(false);
23
- } else {
24
- resolve(false);
25
- }
26
- });
27
-
28
- server.once('listening', () => {
29
- server.close();
30
- resolve(true);
31
- });
32
-
33
- server.listen(port);
34
- });
35
- }
36
-
37
- /**
38
- * Checks if a production build exists
39
- */
40
- async function checkProductionBuild() {
41
- const distDir = getDistPath(import.meta.url);
42
- const bundleConfigPath = getPath(import.meta.url, 'dist', 'bundles', 'bundle.config.json');
43
- return (await fs.pathExists(distDir)) && (await fs.pathExists(bundleConfigPath));
44
- }
45
-
46
- /**
47
- * Checks if the development structure exists
48
- */
49
- async function checkDevelopmentStructure() {
50
- const srcDir = getSrcPath(import.meta.url);
51
- const apiDir = getApiPath(import.meta.url);
52
-
53
- return (await fs.pathExists(srcDir)) && (await fs.pathExists(apiDir));
54
- }
55
-
56
- /**
57
- * Starts the Node.js server with arguments and improved feedback
58
- */
59
- function startNodeServer(port, mode) {
60
- return new Promise((resolve, reject) => {
61
- const apiIndexPath = getApiPath(import.meta.url, 'index.js');
62
-
63
- // Verify the file exists
64
- if (!fs.existsSync(apiIndexPath)) {
65
- reject(new Error(`Server file not found: ${apiIndexPath}`));
66
- return;
67
- }
68
-
69
- Print.serverStatus('starting', 'Starting server...');
70
-
71
- // Build arguments based on mode
72
- const args = [apiIndexPath];
73
- if (mode === 'production') {
74
- args.push('--production');
75
- } else {
76
- args.push('--development');
77
- }
78
-
79
- // Ensure the spawned server process receives NODE_ENV consistent with the
80
- // requested mode. This guarantees code that only checks process.env.NODE_ENV
81
- // (instead of CLI flags) will behave as expected.
82
- const serverEnv = {
83
- ...process.env,
84
- PORT: port,
85
- NODE_ENV: mode === 'production' ? 'production' : (process.env.NODE_ENV || 'development')
86
- };
87
-
88
- const serverProcess = spawn('node', args, {
89
- stdio: ['inherit', 'pipe', 'pipe'],
90
- env: serverEnv
91
- });
92
-
93
- let serverStarted = false;
94
- let outputBuffer = '';
95
-
96
- // Capture output to detect when the server is ready
97
- serverProcess.stdout.on('data', (data) => {
98
- const output = data.toString();
99
- outputBuffer += output;
100
-
101
- // Detect common messages indicating the server has started
102
- if (!serverStarted && (
103
- output.includes('Server running') ||
104
- output.includes('listening on') ||
105
- output.includes('Started on') ||
106
- output.includes(`port ${port}`)
107
- )) {
108
- serverStarted = true;
109
- Print.serverReady(port);
110
- }
111
-
112
- // Display server output
113
- process.stdout.write(output);
114
- });
115
-
116
- serverProcess.stderr.on('data', (data) => {
117
- const output = data.toString();
118
- process.stderr.write(output);
119
- });
120
-
121
- serverProcess.on('error', (error) => {
122
- if (!serverStarted) {
123
- Print.serverStatus('error', `Failed to start server: ${error.message}`);
124
- reject(error);
125
- }
126
- });
127
-
128
- serverProcess.on('exit', (code, signal) => {
129
- if (code !== null && code !== 0 && !serverStarted) {
130
- reject(new Error(`Server exited with code ${code}`));
131
- }
132
- });
133
-
134
- // If after 3 seconds we haven't detected startup, assume it's ready
135
- setTimeout(() => {
136
- if (!serverStarted) {
137
- serverStarted = true;
138
- Print.serverReady(port);
139
- }
140
- resolve(serverProcess);
141
- }, 3000);
142
- });
143
- }
144
-
145
- let currentServerProcess = null;
146
- let currentWatcher = null;
147
-
148
- process.on('SIGINT', () => shutdown());
149
- process.on('SIGTERM', () => shutdown());
150
-
151
- function shutdown() {
152
- Print.newLine();
153
- Print.info('Shutting down server...');
154
- if (currentWatcher) stopWatcher(currentWatcher);
155
- if (currentServerProcess) currentServerProcess.kill('SIGINT');
156
- setTimeout(() => process.exit(0), 100);
157
- }
158
-
159
- /**
160
- * Main function to start the server
161
- */
162
- export default async function startServer(options = {}) {
163
- const config = loadConfigSync(import.meta.url);
164
- const defaultPort = config?.server?.port || 3000;
165
-
166
- const { mode = 'development', port = defaultPort, watch = false } = options;
167
-
168
- try {
169
- Print.title(`🚀 Starting Slice.js ${mode} server...`);
170
- Print.newLine();
171
-
172
- // Verify project structure
173
- if (!await checkDevelopmentStructure()) {
174
- throw new Error('Project structure not found. Run "slice init" first.');
175
- }
176
-
177
- let actualPort = await isPortAvailable(port) ? port : port + 1; // Try one more port
178
- if(actualPort !== port) {
179
- // Check if the fallback is available
180
- const fallbackAvailable = await isPortAvailable(actualPort);
181
- if(!fallbackAvailable) {
182
- throw new Error(`Ports ${port} and ${actualPort} are in use.`);
183
- }
184
- Print.info(`â„šī¸ Port ${port} in use, using ${actualPort} instead.`);
185
- }
186
-
187
- Print.serverStatus('checking', `Port ${actualPort} available ✓`);
188
- Print.newLine();
189
-
190
- if (mode === 'production') {
191
- // Verify production build exists
192
- if (!await checkProductionBuild()) {
193
- Print.info('No production build found. Running "slice build"...');
194
- const success = await build({});
195
- if (!success) {
196
- throw new Error('Build failed. Cannot start production server.');
197
- }
198
- }
199
- Print.info('Production mode: serving optimized files from /dist');
200
- } else {
201
- Print.info('Development mode: serving files from /src (HMR enabled)');
202
- }
203
-
204
- Print.newLine();
205
-
206
- // Start the server with arguments
207
- currentServerProcess = await startNodeServer(actualPort, mode);
208
-
209
- // Configure watch mode if enabled
210
- if (watch) {
211
- Print.newLine();
212
- currentWatcher = setupWatcher(currentServerProcess, async (changedPath) => {
213
- if (currentServerProcess) {
214
- currentServerProcess.kill();
215
- }
216
-
217
- // Short delay to ensure port is freed
218
- await new Promise(r => setTimeout(r, 500));
219
-
220
- try {
221
- Print.info('🔄 File changed. Restarting server...');
222
-
223
- currentServerProcess = await startNodeServer(actualPort, mode);
224
- } catch (e) {
225
- Print.error(`Failed to restart server: ${e.message}`);
226
- }
227
- });
228
- }
229
-
230
- } catch (error) {
231
- Print.newLine();
232
- Print.error(`Failed to start development server: ${error.message}`);
233
- throw error;
234
- }
235
- }
236
-
237
- /**
238
- * Exported utility functions
239
- */
240
- export { checkProductionBuild, checkDevelopmentStructure, isPortAvailable };
@@ -1,66 +0,0 @@
1
- import chokidar from 'chokidar';
2
- import chalk from 'chalk';
3
- import Print from '../Print.js';
4
-
5
- /**
6
- * Configures the watcher for project files
7
- * @param {ChildProcess} serverProcess - Server process
8
- * @returns {FSWatcher} - Chokidar watcher
9
- */
10
- export default function setupWatcher(serverProcess, onRestart) {
11
- Print.info('Watch mode enabled - monitoring file changes...');
12
- Print.newLine();
13
-
14
- const watcher = chokidar.watch(['api/**/*'], {
15
- ignored: [
16
- /(^|[\/\\])\../, // hidden files
17
- '**/node_modules/**',
18
- '**/dist/**',
19
- '**/bundles/**',
20
- '**/*.log'
21
- ],
22
- persistent: true,
23
- ignoreInitial: true,
24
- awaitWriteFinish: {
25
- stabilityThreshold: 100,
26
- pollInterval: 50
27
- }
28
- });
29
-
30
- let reloadTimeout;
31
-
32
- const handleChange = (changedPath) => {
33
- clearTimeout(reloadTimeout);
34
- reloadTimeout = setTimeout(() => {
35
- if (onRestart) {
36
- console.log(chalk.yellow('🔄 API change detected, restarting server...'));
37
- onRestart(changedPath);
38
- }
39
- }, 500);
40
- };
41
-
42
- watcher
43
- .on('change', handleChange)
44
- .on('add', handleChange)
45
- .on('unlink', handleChange)
46
- .on('error', (error) => {
47
- Print.error(`Watcher error: ${error.message}`);
48
- })
49
- .on('ready', () => {
50
- console.log(chalk.gray('👀 Watching for file changes...'));
51
- Print.newLine();
52
- });
53
-
54
- return watcher;
55
- }
56
-
57
- /**
58
- * Stops the watcher safely
59
- * @param {FSWatcher} watcher - Watcher to stop
60
- */
61
- export function stopWatcher(watcher) {
62
- if (watcher) {
63
- watcher.close();
64
- console.log(chalk.gray('Watch mode stopped'));
65
- }
66
- }