vaderjs 1.7.4 → 1.7.5
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/bundler/index.js +20 -14
- package/index.ts +15 -7
- package/main.js +42 -31
- package/package.json +1 -1
package/bundler/index.js
CHANGED
|
@@ -38,10 +38,10 @@ try {
|
|
|
38
38
|
entrypoints: [process.env.ENTRYPOINT],
|
|
39
39
|
minify: false,
|
|
40
40
|
root: process.cwd() + "/dist/",
|
|
41
|
-
outdir: process.cwd() + "/dist/",
|
|
42
|
-
|
|
41
|
+
outdir: process.cwd() + "/dist/",
|
|
43
42
|
format: "esm",
|
|
44
43
|
...(process.env.DEV ? { sourcemap: "inline" } : {}),
|
|
44
|
+
packages: "bundle",
|
|
45
45
|
external: ['*.jsx', '*.js', '*.ts']
|
|
46
46
|
});
|
|
47
47
|
} catch (error) {
|
|
@@ -69,29 +69,33 @@ function handleReplacements(code) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
return newLines.join("\n");
|
|
72
|
-
}
|
|
72
|
+
}
|
|
73
73
|
builtCode = handleReplacements(builtCode)
|
|
74
74
|
fs.writeFileSync(path.join(process.cwd(), 'dist', process.env.filePath), builtCode)
|
|
75
75
|
|
|
76
|
-
let isClass = function (element) {
|
|
77
|
-
return element.toString().startsWith("class");
|
|
76
|
+
let isClass = function (element) {
|
|
77
|
+
return element && element.toString().startsWith("class");
|
|
78
78
|
};
|
|
79
79
|
const generatePage = async (
|
|
80
80
|
data = { path: process.env.INPUT, route: process.env.OUT }
|
|
81
81
|
) => {
|
|
82
82
|
const { path, route } = data;
|
|
83
|
-
if (path.includes("root.js")) return;
|
|
83
|
+
if (path.includes("root.js")) return;
|
|
84
84
|
let html = await import(path).then((m) => m.default);
|
|
85
|
+
|
|
85
86
|
let { head } = await import(path).then((m) => m);
|
|
86
87
|
let isFunction = false;
|
|
87
|
-
globalThis.isServer = true;
|
|
88
|
-
if
|
|
88
|
+
globalThis.isServer = true;
|
|
89
|
+
if(!html){
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
if (isClass(html) ) {
|
|
89
93
|
html = new html();
|
|
90
94
|
html.Mounted = true;
|
|
91
95
|
html = html.render();
|
|
92
96
|
} else {
|
|
93
97
|
isFunction = true;
|
|
94
|
-
let instance = new Component();
|
|
98
|
+
let instance = new Component();
|
|
95
99
|
html = html.bind(instance);
|
|
96
100
|
instance.render = html;
|
|
97
101
|
html = instance.render();
|
|
@@ -108,8 +112,12 @@ const generatePage = async (
|
|
|
108
112
|
headHtml = document(head());
|
|
109
113
|
}
|
|
110
114
|
|
|
115
|
+
|
|
116
|
+
|
|
111
117
|
if (h.includes("<head>")) {
|
|
112
118
|
h = h.replace("<head>", `<head>${process.env.bindes}`)
|
|
119
|
+
}else{
|
|
120
|
+
h += process.env.bindes
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
await Bun.write(
|
|
@@ -132,11 +140,9 @@ const generatePage = async (
|
|
|
132
140
|
)
|
|
133
141
|
);
|
|
134
142
|
process.exit(0);
|
|
135
|
-
};
|
|
136
|
-
try {
|
|
137
|
-
|
|
138
|
-
generatePage({ path: process.env.INPUT, route: process.env.OUT })
|
|
139
|
-
} else if (process.env.isTs == undefined) {
|
|
143
|
+
};
|
|
144
|
+
try {
|
|
145
|
+
if (process.env.isJsx == "true" && process.env.isAppFile == "true" ) {
|
|
140
146
|
generatePage({ path: process.env.INPUT, route: process.env.OUT })
|
|
141
147
|
}
|
|
142
148
|
} catch (error) {
|
package/index.ts
CHANGED
|
@@ -124,7 +124,8 @@ globalThis.Fragment = Fragment;
|
|
|
124
124
|
* @returns
|
|
125
125
|
*/
|
|
126
126
|
export const e = (element, props, ...children) => {
|
|
127
|
-
if(!element)
|
|
127
|
+
if (!element)
|
|
128
|
+
return "";
|
|
128
129
|
let instance;
|
|
129
130
|
switch (true) {
|
|
130
131
|
case isClassComponent(element):
|
|
@@ -136,13 +137,16 @@ export const e = (element, props, ...children) => {
|
|
|
136
137
|
case typeof element === "function":
|
|
137
138
|
instance = new Component;
|
|
138
139
|
instance.render = element;
|
|
140
|
+
if(element.name.toLowerCase() == "default"){
|
|
141
|
+
throw new Error("Function name must be unique")
|
|
142
|
+
}
|
|
143
|
+
instance.key = element.name
|
|
139
144
|
instance.Mounted = true;
|
|
140
145
|
let firstEl = instance.render({ key: instance.key, children, ...props }, children);
|
|
141
|
-
instance.children = children;
|
|
146
|
+
instance.children = children;
|
|
142
147
|
if (!firstEl)
|
|
143
148
|
firstEl = { type: "div", props: { key: instance.key, ...props }, children };
|
|
144
149
|
firstEl.props = { key: instance.key, ...firstEl.props, ...props };
|
|
145
|
-
|
|
146
150
|
return firstEl;
|
|
147
151
|
default:
|
|
148
152
|
return { type: element, props: props || {}, children: children || [] };
|
|
@@ -659,10 +663,14 @@ export function render(element, container) {
|
|
|
659
663
|
} else {
|
|
660
664
|
let memoizedInstance = memoizeClassComponent(Component);
|
|
661
665
|
memoizedInstance.Mounted = true;
|
|
662
|
-
memoizedInstance.render = element.bind(memoizedInstance);
|
|
663
|
-
|
|
664
|
-
|
|
666
|
+
memoizedInstance.render = element.bind(memoizedInstance);
|
|
667
|
+
if(element.name == "default"){
|
|
668
|
+
throw new Error("Function name Must be a unique function name as it is used for a element key")
|
|
669
|
+
}
|
|
670
|
+
memoizedInstance.key = element.name
|
|
671
|
+
let el = memoizedInstance.toElement();
|
|
672
|
+
el.key = element.name
|
|
665
673
|
container.innerHTML = "";
|
|
666
674
|
container.replaceWith(el);
|
|
667
675
|
}
|
|
668
|
-
}
|
|
676
|
+
}
|
package/main.js
CHANGED
|
@@ -204,6 +204,7 @@ async function generateApp() {
|
|
|
204
204
|
code = handleReplacements(code)
|
|
205
205
|
let size = code.length / 1024
|
|
206
206
|
r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
|
|
207
|
+
var beforeR = r
|
|
207
208
|
r = r.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
208
209
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
|
|
209
210
|
fs.writeFileSync(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r), `
|
|
@@ -227,31 +228,40 @@ async function generateApp() {
|
|
|
227
228
|
fs.writeFileSync(process.cwd() + '/dist/src/vader/index.js', await new Bun.Transpiler({
|
|
228
229
|
loader: 'ts',
|
|
229
230
|
}).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
Bun.spawn({
|
|
234
|
+
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
235
|
+
cwd: process.cwd(),
|
|
236
|
+
stdout: 'inherit',
|
|
237
|
+
env: {
|
|
238
|
+
ENTRYPOINT: path.join(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r)),
|
|
239
|
+
ROOT: process.cwd() + '/app/',
|
|
240
|
+
OUT: path.dirname(r),
|
|
241
|
+
file: process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
|
|
242
|
+
DEV: mode === 'development',
|
|
243
|
+
size,
|
|
244
|
+
bindes: bindes.join('\n'),
|
|
245
|
+
isTs: beforeR.endsWith(".tsx"),
|
|
246
|
+
filePath: r,
|
|
247
|
+
|
|
248
|
+
isJsx: beforeR.endsWith('.tsx') || beforeR.endsWith(".jsx") ,
|
|
249
|
+
isAppFile: true,
|
|
250
|
+
INPUT: `../app/${beforeR}`,
|
|
251
|
+
},
|
|
252
|
+
onExit({ exitCode: code }) {
|
|
253
|
+
if (code === 0) {
|
|
254
|
+
bindes = []
|
|
255
|
+
console.log(`Built ${r} in ${Date.now() - start}ms`)
|
|
256
|
+
resolve()
|
|
257
|
+
} else {
|
|
258
|
+
reject()
|
|
259
|
+
}
|
|
252
260
|
}
|
|
253
|
-
}
|
|
254
|
-
})
|
|
261
|
+
})
|
|
262
|
+
} catch (error) {
|
|
263
|
+
|
|
264
|
+
}
|
|
255
265
|
|
|
256
266
|
})
|
|
257
267
|
|
|
@@ -314,13 +324,13 @@ function handleFiles() {
|
|
|
314
324
|
var file = i
|
|
315
325
|
fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(file)), { recursive: true })
|
|
316
326
|
// turn jsx to js
|
|
317
|
-
if (file.
|
|
327
|
+
if (file.endsWith('.jsx') || file.endsWith('.tsx')) {
|
|
318
328
|
let code = await Bun.file(file).text()
|
|
319
329
|
|
|
320
330
|
code = handleReplacements(code)
|
|
321
|
-
|
|
331
|
+
var url = file
|
|
322
332
|
file = file.replace('.jsx', '.js').replace('.tsx', '.js')
|
|
323
|
-
fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.jsx', '.js').replace('.tsx', '.js')), code)
|
|
333
|
+
fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.jsx', '.js').replace('.tsx', '.js')), code)
|
|
324
334
|
await Bun.spawn({
|
|
325
335
|
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
326
336
|
cwd: process.cwd(),
|
|
@@ -334,8 +344,9 @@ function handleFiles() {
|
|
|
334
344
|
DEV: mode === 'development',
|
|
335
345
|
size: code.length / 1024,
|
|
336
346
|
filePath: file.replace('.jsx', '.js'),
|
|
337
|
-
|
|
338
|
-
|
|
347
|
+
isJsx: url.endsWith('.tsx') || url.endsWith(".jsx") ,
|
|
348
|
+
isAppFile: false,
|
|
349
|
+
INPUT: path.join(process.cwd(), url),
|
|
339
350
|
},
|
|
340
351
|
onExit({ exitCode: code }) {
|
|
341
352
|
if (code === 0) {
|
|
@@ -345,7 +356,7 @@ function handleFiles() {
|
|
|
345
356
|
}
|
|
346
357
|
}
|
|
347
358
|
})
|
|
348
|
-
} else if (file.
|
|
359
|
+
} else if (file.endsWith('.ts')) {
|
|
349
360
|
let code = await Bun.file(file).text()
|
|
350
361
|
code = handleReplacements(code)
|
|
351
362
|
file = file.replace('.ts', '.js')
|
|
@@ -527,4 +538,4 @@ if (mode == 'development' || mode == 'serve') {
|
|
|
527
538
|
})
|
|
528
539
|
|
|
529
540
|
console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
|
|
530
|
-
}
|
|
541
|
+
}
|