vaderjs 2.0.5 → 2.0.6

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 (3) hide show
  1. package/main.js +20 -17
  2. package/package.json +1 -1
  3. package/bun.lockb +0 -0
package/main.js CHANGED
@@ -201,9 +201,9 @@ async function generateApp() {
201
201
 
202
202
  let r = routes.routes[route]
203
203
  let code = await Bun.file(r).text()
204
- code = handleReplacements(code)
205
204
  let size = code.length / 1024
206
205
  r = r.replace(process.cwd().replace(/\\/g, '/') + '/app', '')
206
+ var beforeR = r
207
207
  r = r.replace('.jsx', '.js').replace('.tsx', '.js')
208
208
  fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
209
209
  fs.writeFileSync(process.cwd() + '/dist/' + path.dirname(r) + '/' + path.basename(r), `
@@ -227,6 +227,7 @@ async function generateApp() {
227
227
  fs.writeFileSync(process.cwd() + '/dist/src/vader/index.js', await new Bun.Transpiler({
228
228
  loader: 'ts',
229
229
  }).transformSync(await Bun.file(require.resolve('vaderjs')).text()))
230
+
230
231
  Bun.spawn({
231
232
  cmd: ['bun', 'run', './dev/bundler.js'],
232
233
  cwd: process.cwd(),
@@ -239,10 +240,12 @@ async function generateApp() {
239
240
  DEV: mode === 'development',
240
241
  size,
241
242
  bindes: bindes.join('\n'),
243
+ isTs: beforeR.endsWith(".tsx"),
242
244
  filePath: r,
245
+
246
+ isJsx: beforeR.endsWith('.tsx') || beforeR.endsWith(".jsx"),
243
247
  isAppFile: true,
244
- isJsx: true,
245
- INPUT: `../app/${r.replace('.js', '.jsx').replace('.tsx', '.js')}`,
248
+ INPUT: `../app/${beforeR}`,
246
249
  },
247
250
  onExit({ exitCode: code }) {
248
251
  if (code === 0) {
@@ -302,7 +305,6 @@ async function generateApp() {
302
305
  function handleFiles() {
303
306
  return new Promise(async (resolve, reject) => {
304
307
  try {
305
- console.log(Glob)
306
308
  let glob = new Glob('public/**/*')
307
309
  for await (var i of glob.scan()) {
308
310
  let file = i
@@ -317,11 +319,11 @@ function handleFiles() {
317
319
  var file = i
318
320
  fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(file)), { recursive: true })
319
321
  // turn jsx to js
320
- if (file.includes('.jsx') || file.includes('.tsx')) {
322
+ if (file.endsWith('.jsx') || file.endsWith('.tsx')) {
321
323
  let code = await Bun.file(file).text()
322
324
 
323
325
  code = handleReplacements(code)
324
-
326
+ var url = file
325
327
  file = file.replace('.jsx', '.js').replace('.tsx', '.js')
326
328
  fs.writeFileSync(path.join(process.cwd() + '/dist', file.replace('.jsx', '.js').replace('.tsx', '.js')), code)
327
329
  await Bun.spawn({
@@ -337,8 +339,9 @@ function handleFiles() {
337
339
  DEV: mode === 'development',
338
340
  size: code.length / 1024,
339
341
  filePath: file.replace('.jsx', '.js'),
340
- isTs: file.includes('.tsx'),
341
- INPUT: path.join(process.cwd(), file.replace('.js', '.jsx').replace('.tsx', '.js')),
342
+ isJsx: url.endsWith('.tsx') || url.endsWith(".jsx"),
343
+ isAppFile: false,
344
+ INPUT: path.join(process.cwd(), url),
342
345
  },
343
346
  onExit({ exitCode: code }) {
344
347
  if (code === 0) {
@@ -348,7 +351,7 @@ function handleFiles() {
348
351
  }
349
352
  }
350
353
  })
351
- } else if (file.includes('.ts')) {
354
+ } else if (file.endsWith('.ts')) {
352
355
  let code = await Bun.file(file).text()
353
356
  code = handleReplacements(code)
354
357
  file = file.replace('.ts', '.js')
@@ -389,8 +392,8 @@ function handleFiles() {
389
392
  globalThis.clients = []
390
393
 
391
394
  if (mode === 'development') {
392
- await generateApp()
393
395
  await handleFiles()
396
+ await generateApp()
394
397
  const watcher = fs.watch(path.join(process.cwd() + '/'), { recursive: true })
395
398
  let isBuilding = false; // Flag to track build status
396
399
 
@@ -400,10 +403,10 @@ if (mode === 'development') {
400
403
  // Function to handle file changes with debounce
401
404
  const handleFileChangeDebounced = async (change, file) => {
402
405
  if (file.endsWith('.tsx') || file.endsWith('.jsx') || file.endsWith('.css') || file.endsWith('.ts')
403
- && !file.includes('node_module')
406
+ && !file.includes('node_module')
404
407
  ) {
405
408
  // delete files cache
406
- if (file.endsWith('vader.config.ts')){
409
+ if (file.endsWith('vader.config.ts')) {
407
410
  delete require.cache[require.resolve(process.cwd() + '/vader.config.ts')]
408
411
 
409
412
  config = require(process.cwd() + '/vader.config.ts').default
@@ -491,16 +494,16 @@ if (mode == 'development' || mode == 'serve') {
491
494
  style: 'nextjs'
492
495
  })
493
496
  router.reload()
494
- let route = router.match(url.pathname)
497
+ let route = router.match(url.pathname)
495
498
  if (!route) {
496
499
  return new Response('Not found', { status: 404 })
497
500
  }
498
501
  let p = route.pathname;
499
502
  let base = path.dirname(route.filePath)
500
503
  base = base.replace(/\\/g, '/')
501
- base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '')
502
- base = base.replace(/\\/g, '/').replace('/app', '/dist')
503
- base = process.cwd() + "/dist/" + base
504
+ base = base.replace(path.join(process.cwd() + '/app').replace(/\\/g, '/'), '');
505
+ base = base.replace(/\\/g, '/').replace(/\/app(\/|$)/, '/dist$1');
506
+ base = process.cwd() + '/dist/' + base;
504
507
  let data = await Bun.file(path.join(base, 'index.html')).text()
505
508
  if (mode == "development") {
506
509
  return new Response(data + `
@@ -530,4 +533,4 @@ if (mode == 'development' || mode == 'serve') {
530
533
  })
531
534
 
532
535
  console.log(ansiColors.green('Server started at http://localhost:' + port || 8080))
533
- }
536
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"
package/bun.lockb DELETED
Binary file