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 +6 -1
- package/compiler/compiler.js +20 -9
- package/package.json +2 -2
- package/src/index.js +20 -21
package/README.md
CHANGED
|
@@ -61,4 +61,9 @@ createApp(App).mount('body');
|
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
## Result:
|
|
64
|
-

|
|
64
|
+

|
|
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)
|
package/compiler/compiler.js
CHANGED
|
@@ -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(
|
|
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
|
-
]
|
|
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(
|
|
105
|
+
log(`🔁 File changed: ${filePath}`);
|
|
106
|
+
log('🔨 Rebuilding project...');
|
|
107
|
+
|
|
100
108
|
try {
|
|
101
109
|
compileProject(projectDir);
|
|
102
|
-
|
|
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.
|
|
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.
|
|
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
|
|
13
|
+
const index = stateIndex;
|
|
14
14
|
|
|
15
|
-
if (globalState[
|
|
16
|
-
globalState[
|
|
15
|
+
if (globalState[index] === undefined) {
|
|
16
|
+
globalState[index] = initialValue;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function setState(newValue) {
|
|
20
|
-
globalState[
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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[
|
|
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;
|
|
68
|
+
return null;
|
|
73
69
|
}
|
|
74
|
-
|
|
70
|
+
|
|
75
71
|
window.__NEUTRONIUM_ROOT__ = root;
|
|
76
|
-
window.__NEUTRONIUM_RENDER_FN__ = component;
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
83
|
+
return root;
|
|
85
84
|
}
|
|
86
85
|
};
|
|
87
86
|
}
|