neutronium 2.9.5 → 2.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -61,4 +61,9 @@ createApp(App).mount('body');
61
61
  ```
62
62
 
63
63
  ## Result:
64
- ![Results](https://raw.githubusercontent.com/PFMCODES/neutronium/main/results.png)
64
+ ![Results](https://raw.githubusercontent.com/PFMCODES/neutronium/main/results.png)
65
+
66
+ ## Other helpful packages you might need
67
+ ### [@neuhq/alert](https://www.npmjs.com/package/@neuhq/alert)
68
+ ## ⚒️ In dev
69
+ ### [@neuhq/router](https://www.npmjs.com/package/@neuhq/router)
@@ -61,18 +61,22 @@ async function compileProject(projectDir = process.cwd()) {
61
61
  ]]
62
62
  });
63
63
 
64
+ // Ensure _neutronium is imported
64
65
  if (!source.includes('_neutronium')) {
65
66
  code = `import * as _neutronium from '${neutroniumPath}';\n\n${code}`;
66
67
  }
67
68
 
69
+ // Replace imports to local neutronium
68
70
  code = code.replace(/from\s+['"]neutronium['"]/g, `from '${neutroniumPath}'`);
69
- code = code.replace("_neutronium.createApp(App).mount('#app');")
70
71
 
71
72
  writeFile(outputPath, code);
72
73
  }
73
74
 
74
75
  log('🛠️ Generating index.html...');
75
- const htmlContent = baseHtml(``, entry);
76
+ const htmlContent = baseHtml(`
77
+ <script defer type="module" src="./${entry}"></script>
78
+ `, entry);
79
+
76
80
  writeFile(path.join(distDir, 'index.html'), htmlContent);
77
81
 
78
82
  log('✅ Compilation complete!');
@@ -91,24 +95,31 @@ function compileProjectWatch(projectDir = process.cwd(), port = 3000) {
91
95
  chokidar.watch([
92
96
  path.join(projectDir, '**/*.js'),
93
97
  path.join(projectDir, '**/*.ts'),
94
- path.join(projectDir, '**/*.tsx'),
95
- ]).on('change', () => {
98
+ path.join(projectDir, '**/*.tsx')
99
+ ], {
100
+ ignoreInitial: true,
101
+ }).on('change', filePath => {
96
102
  clearTimeout(timeout);
97
103
  timeout = setTimeout(() => {
98
104
  console.clear();
99
- log('🔁 File changed, rebuilding...');
105
+ log(`🔁 File changed: ${filePath}`);
106
+ log('🔨 Rebuilding project...');
107
+
100
108
  try {
101
109
  compileProject(projectDir);
102
- if (server.broadcastReload) server.broadcastReload();
110
+
111
+ if (server?.broadcastReload) {
112
+ server.broadcastReload();
113
+ log('🔃 Reload broadcasted');
114
+ }
103
115
  } catch (err) {
104
- console.error('❌ Rebuild failed:', err.message);
116
+ console.error('❌ Rebuild failed:', err.stack || err.message);
105
117
  }
106
- }, 100);
118
+ }, 100); // Debounce multiple rapid file changes
107
119
  });
108
120
  }
109
121
 
110
122
  function serveProject(projectDir = process.cwd(), port = 3000) {
111
-
112
123
  const server = http.createServer((req, res) => {
113
124
  let reqPath = req.url;
114
125
  if (reqPath === '/' || reqPath === '/index.html') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neutronium",
3
- "version": "2.9.5",
3
+ "version": "2.9.7",
4
4
  "description": "A dense, efficient JavaScript framework for building modern web applications",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
@@ -35,7 +35,7 @@
35
35
  "inquirer": "^12.7.0",
36
36
  "jsdom": "^26.1.0",
37
37
  "mime": "^4.0.7",
38
- "open": "^10.1.2",
38
+ "open": "^10.2.0",
39
39
  "ws": "^8.18.3"
40
40
  },
41
41
  "devDependencies": {
package/src/index.js CHANGED
@@ -10,26 +10,22 @@ export function resetStateIndex() {
10
10
 
11
11
  // Custom useState implementation
12
12
  function useState(initialValue) {
13
- const current = stateIndex;
13
+ const index = stateIndex;
14
14
 
15
- if (globalState[current] === undefined) {
16
- globalState[current] = initialValue;
15
+ if (globalState[index] === undefined) {
16
+ globalState[index] = initialValue;
17
17
  }
18
18
 
19
19
  function setState(newValue) {
20
- globalState[current] = newValue;
21
-
22
- // Re-render the entire app
23
- if (window.__NEUTRONIUM_ROOT__ && typeof window.__NEUTRONIUM_RENDER_FN__ === 'function') {
24
- window.__NEUTRONIUM_ROOT__.innerHTML = '';
25
- resetStateIndex();
26
- const newVNode = window.__NEUTRONIUM_RENDER_FN__();
27
- window.__NEUTRONIUM_ROOT__.appendChild(newVNode);
20
+ globalState[index] = newValue;
21
+
22
+ if (typeof window.__NEUTRONIUM_RENDER_FN__ === 'function') {
23
+ window.__NEUTRONIUM_RENDER_FN__(); // triggers re-render
28
24
  }
29
25
  }
30
26
 
31
27
  stateIndex++;
32
- return [globalState[current], setState];
28
+ return [globalState[index], setState];
33
29
  }
34
30
 
35
31
  function h(type, props = {}, ...children) {
@@ -69,19 +65,22 @@ function createApp(component) {
69
65
  const root = typeof selector === 'string' ? document.querySelector(selector) : selector;
70
66
  if (!root) {
71
67
  console.error(`❌ Root element '${selector}' not found`);
72
- return null; // return something explicit
68
+ return null;
73
69
  }
74
- // Save render function + root globally so useState can use them
70
+
75
71
  window.__NEUTRONIUM_ROOT__ = root;
76
- window.__NEUTRONIUM_RENDER_FN__ = component;
77
72
 
78
- // Reset before first render
79
- resetStateIndex();
80
- const vnode = component();
81
- root.innerHTML = '';
82
- root.appendChild(vnode);
73
+ function render() {
74
+ resetStateIndex(); // ✅ this is enough
75
+ const vnode = component();
76
+ root.innerHTML = '';
77
+ root.appendChild(vnode);
78
+ }
79
+
80
+ window.__NEUTRONIUM_RENDER_FN__ = render; // save render function
81
+ render(); // initial render
83
82
 
84
- return vnode; // ✅ REQUIRED
83
+ return root;
85
84
  }
86
85
  };
87
86
  }