vaderjs 1.7.5 → 1.7.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/bundler/index.js +65 -16
- package/index.ts +40 -11
- package/main.js +31 -36
- package/package.json +1 -1
package/bundler/index.js
CHANGED
|
@@ -41,36 +41,84 @@ try {
|
|
|
41
41
|
outdir: process.cwd() + "/dist/",
|
|
42
42
|
format: "esm",
|
|
43
43
|
...(process.env.DEV ? { sourcemap: "inline" } : {}),
|
|
44
|
-
packages: "bundle",
|
|
45
|
-
external:
|
|
44
|
+
packages: "bundle",
|
|
45
|
+
external:["vaderjs"]
|
|
46
46
|
});
|
|
47
47
|
} catch (error) {
|
|
48
48
|
console.error(error)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
let builtCode = fs.readFileSync(path.join(process.cwd(), 'dist', process.env.filePath), 'utf-8')
|
|
53
|
+
console.log({builtCode, path:path.join(process.cwd(), 'dist', process.env.filePath) })
|
|
54
|
+
const handleReplacements = (code) => {
|
|
55
|
+
let lines = code.split('\n')
|
|
56
|
+
let newLines = []
|
|
56
57
|
for (let line of lines) {
|
|
57
58
|
let hasImport = line.includes('import')
|
|
58
|
-
if
|
|
59
|
+
if(hasImport && line.includes('vaderjs')){
|
|
60
|
+
line = line.replace('vaderjs', '/src/vader/index.js')
|
|
61
|
+
}
|
|
62
|
+
if (hasImport && line.includes('.css')) {
|
|
59
63
|
try {
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
let isSmallColon = line.includes("'")
|
|
65
|
+
let url = isSmallColon ? line.split("'")[1] : line.split('"')[1]
|
|
66
|
+
// start from "/" not "/app"
|
|
67
|
+
// remvoe all ./ and ../
|
|
68
|
+
url = url.replaceAll('./', '/').replaceAll('../', '/')
|
|
69
|
+
|
|
70
|
+
let p = path.join(process.cwd(), '/', url)
|
|
71
|
+
line = '';
|
|
72
|
+
url = url.replace(process.cwd() + '/app', '')
|
|
73
|
+
url = url.replace(/\\/g, '/')
|
|
74
|
+
if (!bindes.includes(`<link rel="stylesheet" href="${url}">`)) {
|
|
75
|
+
bindes.push(`
|
|
76
|
+
<style>
|
|
77
|
+
${fs.readFileSync(p, 'utf-8')}
|
|
78
|
+
</style>
|
|
79
|
+
`)
|
|
80
|
+
}
|
|
64
81
|
} catch (error) {
|
|
65
|
-
|
|
82
|
+
console.error(error)
|
|
66
83
|
}
|
|
67
|
-
} else {
|
|
68
|
-
newLines.push(line)
|
|
69
84
|
}
|
|
85
|
+
if (line.toLowerCase().includes('genkey()')) {
|
|
86
|
+
line = line.toLowerCase().replace('genkey()', `this.key = "${crypto.randomUUID()}"`)
|
|
87
|
+
}
|
|
88
|
+
if (!hasImport && line.includes('useFetch')) {
|
|
89
|
+
line = line.replace('useFetch', 'this.useFetch')
|
|
90
|
+
}
|
|
91
|
+
if (!hasImport && line.includes('useState') && line.includes('[')) {
|
|
92
|
+
let key = line.split(',')[0].split('[')[1].replace(' ', '')
|
|
93
|
+
let b4 = line
|
|
94
|
+
b4 = line.replace('useState(', `this.useState('${key}',`)
|
|
95
|
+
line = b4
|
|
96
|
+
}
|
|
97
|
+
if (!hasImport && line.includes('useAsyncState')) {
|
|
98
|
+
let key = line.split(',')[0].split('[')[1].replace(' ', '')
|
|
99
|
+
let b4 = line
|
|
100
|
+
b4 = line.replace('useAsyncState(', `this.useAsyncState('${key}',`)
|
|
101
|
+
line = b4
|
|
102
|
+
}
|
|
103
|
+
if (!hasImport && line.includes('useEffect')) {
|
|
104
|
+
let b4 = line
|
|
105
|
+
b4 = line.replace('useEffect(', `this.useEffect(`)
|
|
106
|
+
line = b4
|
|
107
|
+
}
|
|
108
|
+
if (!hasImport && line.includes('useRef')) {
|
|
109
|
+
let b4 = line
|
|
110
|
+
let key = line.split(' ')[1].split('=')[0]
|
|
111
|
+
b4 = line.replace('useRef(', `this.useRef('${key}',`)
|
|
112
|
+
line = b4
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
newLines.push(line)
|
|
70
116
|
}
|
|
71
|
-
|
|
117
|
+
let c = newLines.join('\n')
|
|
118
|
+
return c
|
|
72
119
|
}
|
|
73
120
|
builtCode = handleReplacements(builtCode)
|
|
121
|
+
|
|
74
122
|
fs.writeFileSync(path.join(process.cwd(), 'dist', process.env.filePath), builtCode)
|
|
75
123
|
|
|
76
124
|
let isClass = function (element) {
|
|
@@ -140,7 +188,8 @@ const generatePage = async (
|
|
|
140
188
|
)
|
|
141
189
|
);
|
|
142
190
|
process.exit(0);
|
|
143
|
-
};
|
|
191
|
+
};
|
|
192
|
+
console.log(process.env.isJsx, process.env.isAppFile == "true" )
|
|
144
193
|
try {
|
|
145
194
|
if (process.env.isJsx == "true" && process.env.isAppFile == "true" ) {
|
|
146
195
|
generatePage({ path: process.env.INPUT, route: process.env.OUT })
|
package/index.ts
CHANGED
|
@@ -322,33 +322,62 @@ export class Component {
|
|
|
322
322
|
executeCallback();
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
}
|
|
325
|
+
}
|
|
326
|
+
useState(key, defaultValue, persist = false) {
|
|
326
327
|
if (typeof window === "undefined")
|
|
327
|
-
return [defaultValue, () => {
|
|
328
|
-
|
|
329
|
-
|
|
328
|
+
return [defaultValue, () => {}];
|
|
329
|
+
|
|
330
|
+
// Retrieve initial value from sessionStorage or defaultValue
|
|
331
|
+
let value = sessionStorage.getItem("state_" + key)
|
|
332
|
+
? JSON.parse(sessionStorage.getItem("state_" + key)).value
|
|
333
|
+
: defaultValue;
|
|
334
|
+
|
|
335
|
+
// Parse stringified values safely
|
|
330
336
|
if (typeof value === "string") {
|
|
331
337
|
try {
|
|
332
338
|
value = JSON.parse(value);
|
|
333
|
-
} catch
|
|
339
|
+
} catch {
|
|
340
|
+
// Value remains a string if parsing fails
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
|
-
|
|
337
|
-
|
|
343
|
+
|
|
344
|
+
// Ensure event listener is added only once
|
|
345
|
+
if (!window[`listener_${key}`]) {
|
|
346
|
+
window[`listener_${key}`] = true;
|
|
338
347
|
window.addEventListener("beforeunload", () => {
|
|
339
|
-
!persist
|
|
348
|
+
if (!persist) sessionStorage.removeItem("state_" + key);
|
|
340
349
|
});
|
|
341
350
|
}
|
|
351
|
+
|
|
342
352
|
const setValue = (newValue) => {
|
|
343
353
|
if (typeof newValue === "function") {
|
|
344
354
|
newValue = newValue(value);
|
|
345
355
|
}
|
|
346
|
-
|
|
347
|
-
|
|
356
|
+
|
|
357
|
+
const currentValue = sessionStorage.getItem("state_" + key)
|
|
358
|
+
? JSON.parse(sessionStorage.getItem("state_" + key)).value
|
|
359
|
+
: defaultValue;
|
|
360
|
+
|
|
361
|
+
if (JSON.stringify(currentValue) === JSON.stringify(newValue)) {
|
|
362
|
+
return; // Skip if the value hasn't changed
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
sessionStorage.setItem(
|
|
366
|
+
"state_" + key,
|
|
367
|
+
JSON.stringify({ value: newValue })
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
if (this.forceUpdate) {
|
|
371
|
+
this.forceUpdate(this.key);
|
|
372
|
+
}
|
|
348
373
|
};
|
|
374
|
+
|
|
349
375
|
const getVal = () => {
|
|
350
|
-
return sessionStorage.getItem("state_" + key)
|
|
376
|
+
return sessionStorage.getItem("state_" + key)
|
|
377
|
+
? JSON.parse(sessionStorage.getItem("state_" + key)).value
|
|
378
|
+
: defaultValue;
|
|
351
379
|
};
|
|
380
|
+
|
|
352
381
|
return [getVal, setValue];
|
|
353
382
|
}
|
|
354
383
|
useFetch(url, options) {
|
package/main.js
CHANGED
|
@@ -200,8 +200,7 @@ async function generateApp() {
|
|
|
200
200
|
Object.keys(routes.routes).forEach(async (route) => {
|
|
201
201
|
|
|
202
202
|
let r = routes.routes[route]
|
|
203
|
-
let code = await Bun.file(r).text()
|
|
204
|
-
code = handleReplacements(code)
|
|
203
|
+
let code = await Bun.file(r).text()
|
|
205
204
|
let size = code.length / 1024
|
|
206
205
|
r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
|
|
207
206
|
var beforeR = r
|
|
@@ -229,39 +228,35 @@ async function generateApp() {
|
|
|
229
228
|
loader: 'ts',
|
|
230
229
|
}).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
|
|
231
230
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
reject()
|
|
259
|
-
}
|
|
231
|
+
Bun.spawn({
|
|
232
|
+
cmd: ['bun', 'run', './dev/bundler.js'],
|
|
233
|
+
cwd: process.cwd(),
|
|
234
|
+
stdout: 'inherit',
|
|
235
|
+
env: {
|
|
236
|
+
ENTRYPOINT: path.join(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r)),
|
|
237
|
+
ROOT: process.cwd() + '/app/',
|
|
238
|
+
OUT: path.dirname(r),
|
|
239
|
+
file: process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r),
|
|
240
|
+
DEV: mode === 'development',
|
|
241
|
+
size,
|
|
242
|
+
bindes: bindes.join('\n'),
|
|
243
|
+
isTs: beforeR.endsWith(".tsx"),
|
|
244
|
+
filePath: r,
|
|
245
|
+
|
|
246
|
+
isJsx: beforeR.endsWith('.tsx') || beforeR.endsWith(".jsx") ,
|
|
247
|
+
isAppFile: true,
|
|
248
|
+
INPUT: `../app/${beforeR}`,
|
|
249
|
+
},
|
|
250
|
+
onExit({ exitCode: code }) {
|
|
251
|
+
if (code === 0) {
|
|
252
|
+
bindes = []
|
|
253
|
+
console.log(`Built ${r} in ${Date.now() - start}ms`)
|
|
254
|
+
resolve()
|
|
255
|
+
} else {
|
|
256
|
+
reject()
|
|
260
257
|
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
}
|
|
258
|
+
}
|
|
259
|
+
})
|
|
265
260
|
|
|
266
261
|
})
|
|
267
262
|
|
|
@@ -396,9 +391,9 @@ function handleFiles() {
|
|
|
396
391
|
}
|
|
397
392
|
globalThis.clients = []
|
|
398
393
|
|
|
399
|
-
if (mode === 'development') {
|
|
400
|
-
await generateApp()
|
|
394
|
+
if (mode === 'development') {
|
|
401
395
|
await handleFiles()
|
|
396
|
+
await generateApp()
|
|
402
397
|
const watcher = fs.watch(path.join(process.cwd() + '/'), { recursive: true })
|
|
403
398
|
let isBuilding = false; // Flag to track build status
|
|
404
399
|
|