xpine 0.0.43 → 0.0.44

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/dist/index.js CHANGED
@@ -269,7 +269,7 @@ function getXpineOnLoadFunction(pathName, source, onLoadFileResult) {
269
269
  value.imports = importText + "\n" + value.imports;
270
270
  }
271
271
  if ([ts.SyntaxKind.FirstStatement, ts.SyntaxKind.FunctionDeclaration].includes(child.kind)) {
272
- let text = child.getText(source);
272
+ const text = child.getText(source);
273
273
  if (text.includes("xpineOnLoad")) {
274
274
  const body = child?.body?.getText(source) || "";
275
275
  value.fn = value.fn + "\n" + body ? `(function() ${body})();` : "";
@@ -386,7 +386,7 @@ function transformTSXFiles(componentData, pageConfigFiles) {
386
386
  import fs3 from "fs-extra";
387
387
  import path4 from "path";
388
388
  import builtinModules from "builtin-modules";
389
- function addDotJS(allPackages2, extensions2, isDev) {
389
+ function addDotJS(allPackages2, extensions2, isDev2) {
390
390
  const allPackagesIncludingNode = allPackages2.concat(builtinModules);
391
391
  return {
392
392
  name: "add-dot-js",
@@ -404,7 +404,7 @@ function addDotJS(allPackages2, extensions2, isDev) {
404
404
  }
405
405
  let outputPath = args.path + (existsAsFile ? "" : "/index") + ".js";
406
406
  outputPath = args.path.endsWith(".js") || args.path.endsWith(".mjs") ? args.path : outputPath;
407
- return { path: outputPath + (isDev ? `?cache=${Date.now()}` : ""), external: true };
407
+ return { path: outputPath + (isDev2 ? `?cache=${Date.now()}` : ""), external: true };
408
408
  }
409
409
  });
410
410
  }
@@ -485,6 +485,8 @@ import requestIP from "request-ip";
485
485
  import fs5 from "fs-extra";
486
486
  import path5 from "path";
487
487
  import EventEmitter from "events";
488
+ var methods = ["get", "post", "put", "patch", "delete"];
489
+ var isDev = process.env.NODE_ENV === "development";
488
490
  var OnInitEmitter = class extends EventEmitter {
489
491
  };
490
492
  var onInitEmitter = new OnInitEmitter();
@@ -507,94 +509,107 @@ function getAllBuiltRoutes() {
507
509
  };
508
510
  }).filter(Boolean);
509
511
  }
510
- async function createRouter() {
511
- const isDev = process.env.NODE_ENV === "development";
512
- const methods = ["get", "post", "put", "patch", "delete"];
513
- const router = express.Router();
514
- const routeMap = getAllBuiltRoutes();
515
- const routeResults = [];
516
- const configFiles = globSync(config.pagesDir + "/**/+config.{tsx,ts}");
517
- await triggerXPineOnLoad();
518
- for (const route of routeMap) {
519
- const isJSX = route.originalRoute.endsWith(".tsx") || route.originalRoute.endsWith(".jsx");
520
- const slugRoute = route.route.replace(/[ ]/g, "");
521
- const foundMethod = methods.find((method) => slugRoute.endsWith(`.${method}`));
522
- const isDynamicRoute = slugRoute.match(regex_default.isDynamicRoute);
523
- let formattedRouteItem = slugRoute;
524
- if (foundMethod) formattedRouteItem = formattedRouteItem.split(".").shift();
525
- if (isDynamicRoute) {
526
- const result = [...formattedRouteItem.matchAll(regex_default.dynamicRoutes)];
527
- for (const match of result) {
528
- formattedRouteItem = formattedRouteItem.replace(match[0], ":" + match[2]);
529
- }
512
+ async function createRouteFunction(route, configFiles) {
513
+ const isJSX = route.originalRoute.endsWith(".tsx") || route.originalRoute.endsWith(".jsx");
514
+ const slugRoute = route.route.replace(/[ ]/g, "");
515
+ const foundMethod = methods.find((method) => slugRoute.endsWith(`.${method}`));
516
+ const isDynamicRoute = slugRoute.match(regex_default.isDynamicRoute);
517
+ let formattedRouteItem = slugRoute;
518
+ if (foundMethod) formattedRouteItem = formattedRouteItem.split(".").shift();
519
+ if (isDynamicRoute) {
520
+ const result = [...formattedRouteItem.matchAll(regex_default.dynamicRoutes)];
521
+ for (const match of result) {
522
+ formattedRouteItem = formattedRouteItem.replace(match[0], ":" + match[2]);
530
523
  }
531
- const hasCatchAll = formattedRouteItem.match(regex_default.catchAllRoute);
532
- if (hasCatchAll) formattedRouteItem = formattedRouteItem.replace(regex_default.catchAllRoute, "/*");
533
- const componentImport = await import(route.path);
534
- const componentFn = isDev ? null : componentImport?.default;
535
- if (componentImport?.config?.onInit) {
536
- await componentImport.config?.onInit();
524
+ }
525
+ const hasCatchAll = formattedRouteItem.match(regex_default.catchAllRoute);
526
+ if (hasCatchAll) formattedRouteItem = formattedRouteItem.replace(regex_default.catchAllRoute, "/*");
527
+ const componentImport = await import(route.path);
528
+ const componentFn = isDev ? null : componentImport?.default;
529
+ if (componentImport?.config?.onInit) {
530
+ await componentImport.config?.onInit();
531
+ }
532
+ let config2 = {};
533
+ const configFilePaths = getConfigFiles(route.originalRoute, configFiles);
534
+ if (!isDev) {
535
+ config2 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
536
+ if (componentImport?.config) {
537
+ config2 = {
538
+ ...config2,
539
+ ...componentImport.config
540
+ };
537
541
  }
538
- let config2 = {};
539
- const configFilePaths = getConfigFiles(route.originalRoute, configFiles);
540
- if (!isDev) {
541
- config2 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
542
- if (componentImport?.config) {
543
- config2 = {
544
- ...config2,
545
- ...componentImport.config
546
- };
542
+ }
543
+ async function routeFn(req, res) {
544
+ const urlPath = req?.route?.path || "/";
545
+ try {
546
+ const staticPath = routeHasStaticPath(formattedRouteItem, req.params);
547
+ if (staticPath && !isDev) {
548
+ res.sendFile(staticPath);
549
+ return;
547
550
  }
548
- }
549
- routeResults.push({
550
- formattedRouteItem,
551
- foundMethod,
552
- route
553
- });
554
- router[foundMethod || "get"](formattedRouteItem, async (req, res) => {
555
- const urlPath = req?.route?.path || "/";
556
- try {
557
- const staticPath = routeHasStaticPath(formattedRouteItem, req.params);
558
- if (staticPath && !isDev) {
559
- res.sendFile(staticPath);
560
- return;
561
- }
562
- if (componentFn && !isDev) {
563
- if (isJSX) {
564
- const data = config2?.data ? await config2.data(req) : null;
565
- const originalResult = await componentFn({ req, res, data, routePath: urlPath });
566
- const output = config2?.wrapper ? await config2.wrapper({ req, children: originalResult, config: config2, data, routePath: urlPath }) : originalResult;
567
- res.send(doctypeHTML + output);
568
- } else {
569
- await componentFn(req, res);
570
- }
571
- return;
572
- }
573
- await triggerXPineOnLoad(true);
574
- const componentImportDev = await import(route.path + `?cache=${Date.now()}`);
575
- const componentFnDev = componentImportDev.default;
576
- onInitEmitter.emit("triggerOnInit", getAllBuiltRoutes());
551
+ if (componentFn && !isDev) {
577
552
  if (isJSX) {
578
- let config3 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
579
- if (componentImportDev?.config) {
580
- config3 = {
581
- ...config3,
582
- ...componentImportDev.config
583
- };
584
- }
585
- const data = config3?.data ? await config3.data(req) : null;
586
- const originalResult = await componentFnDev({ req, res, data, config: config3, routePath: urlPath });
587
- const output = config3?.wrapper ? await config3.wrapper({ req, children: originalResult, config: config3, data, routePath: urlPath }) : originalResult;
588
- context.clear();
553
+ const data = config2?.data ? await config2.data(req) : null;
554
+ const originalResult = await componentFn({ req, res, data, routePath: urlPath });
555
+ const output = config2?.wrapper ? await config2.wrapper({ req, children: originalResult, config: config2, data, routePath: urlPath }) : originalResult;
589
556
  res.send(doctypeHTML + output);
590
557
  } else {
591
- await componentFnDev(req, res);
558
+ await componentFn(req, res);
592
559
  }
593
- } catch (err) {
594
- console.error(err);
595
- res.status(err?.status || 500).send(err?.message || "Error");
560
+ return;
596
561
  }
597
- });
562
+ await triggerXPineOnLoad(true);
563
+ const componentImportDev = await import(route.path + `?cache=${Date.now()}`);
564
+ const componentFnDev = componentImportDev.default;
565
+ onInitEmitter.emit("triggerOnInit", getAllBuiltRoutes());
566
+ if (isJSX) {
567
+ let config3 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
568
+ if (componentImportDev?.config) {
569
+ config3 = {
570
+ ...config3,
571
+ ...componentImportDev.config
572
+ };
573
+ }
574
+ const data = config3?.data ? await config3.data(req) : null;
575
+ const originalResult = await componentFnDev({ req, res, data, config: config3, routePath: urlPath });
576
+ const output = config3?.wrapper ? await config3.wrapper({ req, children: originalResult, config: config3, data, routePath: urlPath }) : originalResult;
577
+ context.clear();
578
+ res.send(doctypeHTML + output);
579
+ } else {
580
+ await componentFnDev(req, res);
581
+ }
582
+ } catch (err) {
583
+ console.error(err);
584
+ res.status(err?.status || 500).send(err?.message || "Error");
585
+ }
586
+ }
587
+ return {
588
+ formattedRouteItem,
589
+ foundMethod,
590
+ route,
591
+ routeFn
592
+ };
593
+ }
594
+ async function createRouter() {
595
+ const router = express.Router();
596
+ const routeMap = getAllBuiltRoutes();
597
+ const routeResults = [];
598
+ const configFiles = globSync(config.pagesDir + "/**/+config.{tsx,ts}");
599
+ await triggerXPineOnLoad();
600
+ for (const route of routeMap) {
601
+ try {
602
+ const { formattedRouteItem, foundMethod, routeFn } = await createRouteFunction(route, configFiles);
603
+ router[foundMethod || "get"](formattedRouteItem, routeFn);
604
+ routeResults.push({
605
+ formattedRouteItem,
606
+ foundMethod,
607
+ route,
608
+ routeFn
609
+ });
610
+ } catch (err) {
611
+ console.error(err);
612
+ }
598
613
  }
599
614
  return {
600
615
  router,
@@ -623,15 +638,11 @@ async function createXPineRouter(app, beforeErrorRoute) {
623
638
  router(req, res, next);
624
639
  });
625
640
  const found404 = routeResults?.find((item) => item?.formattedRouteItem === "/404");
626
- const import404 = process.env.NODE_ENV === "development" || !found404 ? null : (await import(found404.route.path)).default;
627
641
  if (beforeErrorRoute) beforeErrorRoute(app);
628
642
  app.use(async function(req, res) {
629
643
  res.status(404);
630
- if (import404) {
631
- res.send(doctypeHTML + await import404(req, res));
632
- } else if (found404 && process.env.NODE_ENV === "development") {
633
- const import404Item = (await import(found404.route.path + `?cache=${Date.now()}`)).default;
634
- res.send(doctypeHTML + await import404Item(req, res));
644
+ if (found404?.routeFn) {
645
+ found404?.routeFn(req, res);
635
646
  } else {
636
647
  res.send("Error");
637
648
  }
@@ -700,19 +711,19 @@ var plugin2 = (opts = {}) => {
700
711
  },
701
712
  OnceExit(root) {
702
713
  root.append([
703
- `:root {`,
704
- `--active-breakpoint: "default";`,
705
- `}`
714
+ ":root {",
715
+ '--active-breakpoint: "default";',
716
+ "}"
706
717
  ].join(""));
707
718
  const nodeValuesMapped = nodeValues.sort((a, b) => {
708
719
  return Number(a.value.replace(/[^0-9]/g, "")) - Number(b.value.replace(/[^0-9]/g, ""));
709
720
  }).map(({ breakpoint, value }) => {
710
721
  return [
711
722
  `@media (min-width: ${value}) {`,
712
- `:root {`,
723
+ ":root {",
713
724
  `--active-breakpoint: "${breakpoint}";`,
714
- `}`,
715
- `}`
725
+ "}",
726
+ "}"
716
727
  ].join("");
717
728
  });
718
729
  for (const value of nodeValuesMapped) {
@@ -748,28 +759,28 @@ var packageJson = JSON.parse(fs7.readFileSync(config.packageJsonPath, "utf-8"));
748
759
  var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
749
760
  var xpineDistDir = getXPineDistDir();
750
761
  async function buildApp(args) {
751
- const isDev = args?.isDev || false;
762
+ const isDev2 = args?.isDev || false;
752
763
  const removePreviousBuild = args?.removePreviousBuild || false;
753
764
  const disableTailwind = args?.disableTailwind || false;
754
765
  try {
755
766
  if (removePreviousBuild) fs7.removeSync(config.distDir);
756
767
  const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
757
- const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev);
768
+ const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev2);
758
769
  const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
759
- await buildClientSideFiles([alpineDataFile], isDev);
770
+ await buildClientSideFiles([alpineDataFile], isDev2);
760
771
  fs7.removeSync(config.distTempFolder);
761
772
  await buildCSS(disableTailwind);
762
773
  await buildPublicFolderSymlinks();
763
- await buildOnLoadFile(componentData, isDev);
764
- if (!isDev) await triggerXPineOnLoad();
765
- if (!isDev) await buildFilesWithConfigs(componentData);
766
- if (!isDev) context.clear();
774
+ await buildOnLoadFile(componentData, isDev2);
775
+ if (!isDev2) await triggerXPineOnLoad();
776
+ if (!isDev2) await buildFilesWithConfigs(componentData);
777
+ if (!isDev2) context.clear();
767
778
  } catch (err) {
768
779
  console.error("Build failed");
769
780
  console.error(err);
770
781
  }
771
782
  }
772
- async function buildAppFiles(files, isDev) {
783
+ async function buildAppFiles(files, isDev2) {
773
784
  const componentData = [];
774
785
  const dataFiles = [];
775
786
  const pageConfigFiles = files.filter((file) => {
@@ -784,12 +795,12 @@ async function buildAppFiles(files, isDev) {
784
795
  platform: "node",
785
796
  outdir: config.distDir,
786
797
  bundle: true,
787
- sourcemap: isDev ? "inline" : false,
798
+ sourcemap: isDev2 ? "inline" : false,
788
799
  external: allPackages,
789
800
  jsx: "transform",
790
- minify: !isDev,
801
+ minify: !isDev2,
791
802
  plugins: [
792
- addDotJS(allPackages, extensions, isDev),
803
+ addDotJS(allPackages, extensions, isDev2),
793
804
  transformTSXFiles(componentData, pageConfigFiles),
794
805
  getDataFiles(dataFiles)
795
806
  ]
@@ -800,7 +811,7 @@ async function buildAppFiles(files, isDev) {
800
811
  dataFiles
801
812
  };
802
813
  }
803
- async function buildClientSideFiles(alpineDataFiles = [], isDev) {
814
+ async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
804
815
  const tempFilePath = path6.join(config.distTempFolder, "./app.ts");
805
816
  fs7.ensureFileSync(tempFilePath);
806
817
  const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
@@ -811,22 +822,22 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
811
822
  }
812
823
  );
813
824
  convertEntryPointsToSingleFile(alpineDataFiles.concat(clientFiles), tempFilePath);
814
- if (isDev) writeDevServerClientSideCode(tempFilePath);
825
+ if (isDev2) writeDevServerClientSideCode(tempFilePath);
815
826
  writeSpaClientSideCode(tempFilePath);
816
827
  await build({
817
828
  entryPoints: [tempFilePath],
818
829
  bundle: true,
819
830
  outdir: config.distPublicScriptsDir,
820
- minify: !isDev,
821
- sourcemap: isDev ? "inline" : false
831
+ minify: !isDev2,
832
+ sourcemap: isDev2 ? "inline" : false
822
833
  });
823
834
  const pagesFiles = globSync3(pagesScriptsGlob);
824
835
  await build({
825
836
  entryPoints: pagesFiles || [],
826
837
  bundle: true,
827
838
  outdir: config.distPublicScriptsDir + "/pages",
828
- minify: !isDev,
829
- sourcemap: isDev ? "inline" : false
839
+ minify: !isDev2,
840
+ sourcemap: isDev2 ? "inline" : false
830
841
  });
831
842
  await logSize(config.distPublicDir, "client");
832
843
  }
@@ -1001,7 +1012,7 @@ function getComponentDynamicPaths(componentPath) {
1001
1012
  }
1002
1013
  return output;
1003
1014
  }
1004
- async function buildOnLoadFile(componentData, isDev) {
1015
+ async function buildOnLoadFile(componentData, isDev2) {
1005
1016
  const onLoadFiles = [];
1006
1017
  const onLoadFileResult = {
1007
1018
  imports: "",
@@ -1039,12 +1050,12 @@ async function buildOnLoadFile(componentData, isDev) {
1039
1050
  platform: "node",
1040
1051
  outdir: config.distDir,
1041
1052
  bundle: true,
1042
- sourcemap: isDev ? "inline" : false,
1053
+ sourcemap: isDev2 ? "inline" : false,
1043
1054
  external: allPackages,
1044
1055
  jsx: "transform",
1045
- minify: !isDev,
1056
+ minify: !isDev2,
1046
1057
  plugins: [
1047
- addDotJS(allPackages, extensions, isDev)
1058
+ addDotJS(allPackages, extensions, isDev2)
1048
1059
  ]
1049
1060
  });
1050
1061
  }
@@ -1 +1 @@
1
- {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAgB,OAAO,EAAqB,MAAM,SAAS,CAAC;AAyC5E,wBAAsB,YAAY;;;GAmHjC;AAiBD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,iBA6B1F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,KAAK,CAanG;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,OAAc,UAQzE"}
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAgB,OAAO,EAAqB,MAAM,SAAS,CAAC;AAuJ5E,wBAAsB,YAAY;;;GA8BjC;AAiBD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,iBAyB1F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,KAAK,CAanG;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,OAAc,UAQzE"}
@@ -264,7 +264,7 @@ function getXpineOnLoadFunction(pathName, source, onLoadFileResult) {
264
264
  value.imports = importText + "\n" + value.imports;
265
265
  }
266
266
  if ([ts.SyntaxKind.FirstStatement, ts.SyntaxKind.FunctionDeclaration].includes(child.kind)) {
267
- let text = child.getText(source);
267
+ const text = child.getText(source);
268
268
  if (text.includes("xpineOnLoad")) {
269
269
  const body = child?.body?.getText(source) || "";
270
270
  value.fn = value.fn + "\n" + body ? `(function() ${body})();` : "";
@@ -381,7 +381,7 @@ function transformTSXFiles(componentData, pageConfigFiles) {
381
381
  import fs3 from "fs-extra";
382
382
  import path4 from "path";
383
383
  import builtinModules from "builtin-modules";
384
- function addDotJS(allPackages2, extensions2, isDev2) {
384
+ function addDotJS(allPackages2, extensions2, isDev3) {
385
385
  const allPackagesIncludingNode = allPackages2.concat(builtinModules);
386
386
  return {
387
387
  name: "add-dot-js",
@@ -399,7 +399,7 @@ function addDotJS(allPackages2, extensions2, isDev2) {
399
399
  }
400
400
  let outputPath = args.path + (existsAsFile ? "" : "/index") + ".js";
401
401
  outputPath = args.path.endsWith(".js") || args.path.endsWith(".mjs") ? args.path : outputPath;
402
- return { path: outputPath + (isDev2 ? `?cache=${Date.now()}` : ""), external: true };
402
+ return { path: outputPath + (isDev3 ? `?cache=${Date.now()}` : ""), external: true };
403
403
  }
404
404
  });
405
405
  }
@@ -446,6 +446,7 @@ var { verify, sign } = jsonwebtoken;
446
446
  import requestIP from "request-ip";
447
447
  import fs5 from "fs-extra";
448
448
  import EventEmitter from "events";
449
+ var isDev = process.env.NODE_ENV === "development";
449
450
  var OnInitEmitter = class extends EventEmitter {
450
451
  };
451
452
  var onInitEmitter = new OnInitEmitter();
@@ -506,19 +507,19 @@ var plugin2 = (opts = {}) => {
506
507
  },
507
508
  OnceExit(root) {
508
509
  root.append([
509
- `:root {`,
510
- `--active-breakpoint: "default";`,
511
- `}`
510
+ ":root {",
511
+ '--active-breakpoint: "default";',
512
+ "}"
512
513
  ].join(""));
513
514
  const nodeValuesMapped = nodeValues.sort((a, b) => {
514
515
  return Number(a.value.replace(/[^0-9]/g, "")) - Number(b.value.replace(/[^0-9]/g, ""));
515
516
  }).map(({ breakpoint, value }) => {
516
517
  return [
517
518
  `@media (min-width: ${value}) {`,
518
- `:root {`,
519
+ ":root {",
519
520
  `--active-breakpoint: "${breakpoint}";`,
520
- `}`,
521
- `}`
521
+ "}",
522
+ "}"
522
523
  ].join("");
523
524
  });
524
525
  for (const value of nodeValuesMapped) {
@@ -554,28 +555,28 @@ var packageJson = JSON.parse(fs7.readFileSync(config.packageJsonPath, "utf-8"));
554
555
  var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
555
556
  var xpineDistDir = getXPineDistDir();
556
557
  async function buildApp(args) {
557
- const isDev2 = args?.isDev || false;
558
+ const isDev3 = args?.isDev || false;
558
559
  const removePreviousBuild2 = args?.removePreviousBuild || false;
559
560
  const disableTailwind2 = args?.disableTailwind || false;
560
561
  try {
561
562
  if (removePreviousBuild2) fs7.removeSync(config.distDir);
562
563
  const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
563
- const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev2);
564
+ const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev3);
564
565
  const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
565
- await buildClientSideFiles([alpineDataFile], isDev2);
566
+ await buildClientSideFiles([alpineDataFile], isDev3);
566
567
  fs7.removeSync(config.distTempFolder);
567
568
  await buildCSS(disableTailwind2);
568
569
  await buildPublicFolderSymlinks();
569
- await buildOnLoadFile(componentData, isDev2);
570
- if (!isDev2) await triggerXPineOnLoad();
571
- if (!isDev2) await buildFilesWithConfigs(componentData);
572
- if (!isDev2) context.clear();
570
+ await buildOnLoadFile(componentData, isDev3);
571
+ if (!isDev3) await triggerXPineOnLoad();
572
+ if (!isDev3) await buildFilesWithConfigs(componentData);
573
+ if (!isDev3) context.clear();
573
574
  } catch (err) {
574
575
  console.error("Build failed");
575
576
  console.error(err);
576
577
  }
577
578
  }
578
- async function buildAppFiles(files, isDev2) {
579
+ async function buildAppFiles(files, isDev3) {
579
580
  const componentData = [];
580
581
  const dataFiles = [];
581
582
  const pageConfigFiles = files.filter((file) => {
@@ -590,12 +591,12 @@ async function buildAppFiles(files, isDev2) {
590
591
  platform: "node",
591
592
  outdir: config.distDir,
592
593
  bundle: true,
593
- sourcemap: isDev2 ? "inline" : false,
594
+ sourcemap: isDev3 ? "inline" : false,
594
595
  external: allPackages,
595
596
  jsx: "transform",
596
- minify: !isDev2,
597
+ minify: !isDev3,
597
598
  plugins: [
598
- addDotJS(allPackages, extensions, isDev2),
599
+ addDotJS(allPackages, extensions, isDev3),
599
600
  transformTSXFiles(componentData, pageConfigFiles),
600
601
  getDataFiles(dataFiles)
601
602
  ]
@@ -606,7 +607,7 @@ async function buildAppFiles(files, isDev2) {
606
607
  dataFiles
607
608
  };
608
609
  }
609
- async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
610
+ async function buildClientSideFiles(alpineDataFiles = [], isDev3) {
610
611
  const tempFilePath = path5.join(config.distTempFolder, "./app.ts");
611
612
  fs7.ensureFileSync(tempFilePath);
612
613
  const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
@@ -617,22 +618,22 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
617
618
  }
618
619
  );
619
620
  convertEntryPointsToSingleFile(alpineDataFiles.concat(clientFiles), tempFilePath);
620
- if (isDev2) writeDevServerClientSideCode(tempFilePath);
621
+ if (isDev3) writeDevServerClientSideCode(tempFilePath);
621
622
  writeSpaClientSideCode(tempFilePath);
622
623
  await build({
623
624
  entryPoints: [tempFilePath],
624
625
  bundle: true,
625
626
  outdir: config.distPublicScriptsDir,
626
- minify: !isDev2,
627
- sourcemap: isDev2 ? "inline" : false
627
+ minify: !isDev3,
628
+ sourcemap: isDev3 ? "inline" : false
628
629
  });
629
630
  const pagesFiles = globSync3(pagesScriptsGlob);
630
631
  await build({
631
632
  entryPoints: pagesFiles || [],
632
633
  bundle: true,
633
634
  outdir: config.distPublicScriptsDir + "/pages",
634
- minify: !isDev2,
635
- sourcemap: isDev2 ? "inline" : false
635
+ minify: !isDev3,
636
+ sourcemap: isDev3 ? "inline" : false
636
637
  });
637
638
  await logSize(config.distPublicDir, "client");
638
639
  }
@@ -807,7 +808,7 @@ function getComponentDynamicPaths(componentPath) {
807
808
  }
808
809
  return output;
809
810
  }
810
- async function buildOnLoadFile(componentData, isDev2) {
811
+ async function buildOnLoadFile(componentData, isDev3) {
811
812
  const onLoadFiles = [];
812
813
  const onLoadFileResult = {
813
814
  imports: "",
@@ -845,12 +846,12 @@ async function buildOnLoadFile(componentData, isDev2) {
845
846
  platform: "node",
846
847
  outdir: config.distDir,
847
848
  bundle: true,
848
- sourcemap: isDev2 ? "inline" : false,
849
+ sourcemap: isDev3 ? "inline" : false,
849
850
  external: allPackages,
850
851
  jsx: "transform",
851
- minify: !isDev2,
852
+ minify: !isDev3,
852
853
  plugins: [
853
- addDotJS(allPackages, extensions, isDev2)
854
+ addDotJS(allPackages, extensions, isDev3)
854
855
  ]
855
856
  });
856
857
  }
@@ -859,5 +860,5 @@ async function buildOnLoadFile(componentData, isDev2) {
859
860
  import yargs from "yargs";
860
861
  import { hideBin } from "yargs/helpers";
861
862
  var argv = yargs(hideBin(process.argv)).argv;
862
- var { isDev, removePreviousBuild, disableTailwind } = argv;
863
- buildApp({ isDev, removePreviousBuild, disableTailwind });
863
+ var { isDev: isDev2, removePreviousBuild, disableTailwind } = argv;
864
+ buildApp({ isDev: isDev2, removePreviousBuild, disableTailwind });
@@ -271,7 +271,7 @@ function getXpineOnLoadFunction(pathName, source, onLoadFileResult) {
271
271
  value.imports = importText + "\n" + value.imports;
272
272
  }
273
273
  if ([ts.SyntaxKind.FirstStatement, ts.SyntaxKind.FunctionDeclaration].includes(child.kind)) {
274
- let text = child.getText(source);
274
+ const text = child.getText(source);
275
275
  if (text.includes("xpineOnLoad")) {
276
276
  const body = child?.body?.getText(source) || "";
277
277
  value.fn = value.fn + "\n" + body ? `(function() ${body})();` : "";
@@ -388,7 +388,7 @@ function transformTSXFiles(componentData, pageConfigFiles) {
388
388
  import fs3 from "fs-extra";
389
389
  import path4 from "path";
390
390
  import builtinModules from "builtin-modules";
391
- function addDotJS(allPackages2, extensions2, isDev) {
391
+ function addDotJS(allPackages2, extensions2, isDev2) {
392
392
  const allPackagesIncludingNode = allPackages2.concat(builtinModules);
393
393
  return {
394
394
  name: "add-dot-js",
@@ -406,7 +406,7 @@ function addDotJS(allPackages2, extensions2, isDev) {
406
406
  }
407
407
  let outputPath = args.path + (existsAsFile ? "" : "/index") + ".js";
408
408
  outputPath = args.path.endsWith(".js") || args.path.endsWith(".mjs") ? args.path : outputPath;
409
- return { path: outputPath + (isDev ? `?cache=${Date.now()}` : ""), external: true };
409
+ return { path: outputPath + (isDev2 ? `?cache=${Date.now()}` : ""), external: true };
410
410
  }
411
411
  });
412
412
  }
@@ -453,6 +453,7 @@ var { verify, sign } = jsonwebtoken;
453
453
  import requestIP from "request-ip";
454
454
  import fs5 from "fs-extra";
455
455
  import EventEmitter from "events";
456
+ var isDev = process.env.NODE_ENV === "development";
456
457
  var OnInitEmitter = class extends EventEmitter {
457
458
  };
458
459
  var onInitEmitter = new OnInitEmitter();
@@ -513,19 +514,19 @@ var plugin2 = (opts = {}) => {
513
514
  },
514
515
  OnceExit(root) {
515
516
  root.append([
516
- `:root {`,
517
- `--active-breakpoint: "default";`,
518
- `}`
517
+ ":root {",
518
+ '--active-breakpoint: "default";',
519
+ "}"
519
520
  ].join(""));
520
521
  const nodeValuesMapped = nodeValues.sort((a, b) => {
521
522
  return Number(a.value.replace(/[^0-9]/g, "")) - Number(b.value.replace(/[^0-9]/g, ""));
522
523
  }).map(({ breakpoint, value }) => {
523
524
  return [
524
525
  `@media (min-width: ${value}) {`,
525
- `:root {`,
526
+ ":root {",
526
527
  `--active-breakpoint: "${breakpoint}";`,
527
- `}`,
528
- `}`
528
+ "}",
529
+ "}"
529
530
  ].join("");
530
531
  });
531
532
  for (const value of nodeValuesMapped) {
@@ -561,28 +562,28 @@ var packageJson = JSON.parse(fs7.readFileSync(config.packageJsonPath, "utf-8"));
561
562
  var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
562
563
  var xpineDistDir = getXPineDistDir();
563
564
  async function buildApp(args) {
564
- const isDev = args?.isDev || false;
565
+ const isDev2 = args?.isDev || false;
565
566
  const removePreviousBuild = args?.removePreviousBuild || false;
566
567
  const disableTailwind = args?.disableTailwind || false;
567
568
  try {
568
569
  if (removePreviousBuild) fs7.removeSync(config.distDir);
569
570
  const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
570
- const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev);
571
+ const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev2);
571
572
  const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
572
- await buildClientSideFiles([alpineDataFile], isDev);
573
+ await buildClientSideFiles([alpineDataFile], isDev2);
573
574
  fs7.removeSync(config.distTempFolder);
574
575
  await buildCSS(disableTailwind);
575
576
  await buildPublicFolderSymlinks();
576
- await buildOnLoadFile(componentData, isDev);
577
- if (!isDev) await triggerXPineOnLoad();
578
- if (!isDev) await buildFilesWithConfigs(componentData);
579
- if (!isDev) context.clear();
577
+ await buildOnLoadFile(componentData, isDev2);
578
+ if (!isDev2) await triggerXPineOnLoad();
579
+ if (!isDev2) await buildFilesWithConfigs(componentData);
580
+ if (!isDev2) context.clear();
580
581
  } catch (err) {
581
582
  console.error("Build failed");
582
583
  console.error(err);
583
584
  }
584
585
  }
585
- async function buildAppFiles(files, isDev) {
586
+ async function buildAppFiles(files, isDev2) {
586
587
  const componentData = [];
587
588
  const dataFiles = [];
588
589
  const pageConfigFiles = files.filter((file) => {
@@ -597,12 +598,12 @@ async function buildAppFiles(files, isDev) {
597
598
  platform: "node",
598
599
  outdir: config.distDir,
599
600
  bundle: true,
600
- sourcemap: isDev ? "inline" : false,
601
+ sourcemap: isDev2 ? "inline" : false,
601
602
  external: allPackages,
602
603
  jsx: "transform",
603
- minify: !isDev,
604
+ minify: !isDev2,
604
605
  plugins: [
605
- addDotJS(allPackages, extensions, isDev),
606
+ addDotJS(allPackages, extensions, isDev2),
606
607
  transformTSXFiles(componentData, pageConfigFiles),
607
608
  getDataFiles(dataFiles)
608
609
  ]
@@ -613,7 +614,7 @@ async function buildAppFiles(files, isDev) {
613
614
  dataFiles
614
615
  };
615
616
  }
616
- async function buildClientSideFiles(alpineDataFiles = [], isDev) {
617
+ async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
617
618
  const tempFilePath = path5.join(config.distTempFolder, "./app.ts");
618
619
  fs7.ensureFileSync(tempFilePath);
619
620
  const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
@@ -624,22 +625,22 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
624
625
  }
625
626
  );
626
627
  convertEntryPointsToSingleFile(alpineDataFiles.concat(clientFiles), tempFilePath);
627
- if (isDev) writeDevServerClientSideCode(tempFilePath);
628
+ if (isDev2) writeDevServerClientSideCode(tempFilePath);
628
629
  writeSpaClientSideCode(tempFilePath);
629
630
  await build({
630
631
  entryPoints: [tempFilePath],
631
632
  bundle: true,
632
633
  outdir: config.distPublicScriptsDir,
633
- minify: !isDev,
634
- sourcemap: isDev ? "inline" : false
634
+ minify: !isDev2,
635
+ sourcemap: isDev2 ? "inline" : false
635
636
  });
636
637
  const pagesFiles = globSync3(pagesScriptsGlob);
637
638
  await build({
638
639
  entryPoints: pagesFiles || [],
639
640
  bundle: true,
640
641
  outdir: config.distPublicScriptsDir + "/pages",
641
- minify: !isDev,
642
- sourcemap: isDev ? "inline" : false
642
+ minify: !isDev2,
643
+ sourcemap: isDev2 ? "inline" : false
643
644
  });
644
645
  await logSize(config.distPublicDir, "client");
645
646
  }
@@ -814,7 +815,7 @@ function getComponentDynamicPaths(componentPath) {
814
815
  }
815
816
  return output;
816
817
  }
817
- async function buildOnLoadFile(componentData, isDev) {
818
+ async function buildOnLoadFile(componentData, isDev2) {
818
819
  const onLoadFiles = [];
819
820
  const onLoadFileResult = {
820
821
  imports: "",
@@ -852,12 +853,12 @@ async function buildOnLoadFile(componentData, isDev) {
852
853
  platform: "node",
853
854
  outdir: config.distDir,
854
855
  bundle: true,
855
- sourcemap: isDev ? "inline" : false,
856
+ sourcemap: isDev2 ? "inline" : false,
856
857
  external: allPackages,
857
858
  jsx: "transform",
858
- minify: !isDev,
859
+ minify: !isDev2,
859
860
  plugins: [
860
- addDotJS(allPackages, extensions, isDev)
861
+ addDotJS(allPackages, extensions, isDev2)
861
862
  ]
862
863
  });
863
864
  }
@@ -214,11 +214,14 @@ function safeParseURL(url) {
214
214
  return {};
215
215
  }
216
216
  }
217
+ function getCurrentBreakpoint() {
218
+ return window.getComputedStyle(document.documentElement).getPropertyValue("--active-breakpoint")?.replace(/[\'\"]/g, "")?.trim() || "";
219
+ }
217
220
  function handleBreakpointEvents() {
218
221
  let lastSentBreakpoint = "";
219
222
  let initial = true;
220
223
  return function() {
221
- const breakpoint = window.getComputedStyle(document.documentElement).getPropertyValue("--active-breakpoint")?.replace(/[\'\"]/g, "")?.trim() || "";
224
+ const breakpoint = getCurrentBreakpoint();
222
225
  if (breakpoint !== lastSentBreakpoint) {
223
226
  const event = new CustomEvent("breakpoint-change", {
224
227
  detail: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpine",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "main": "dist/index.js",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-secrets-manager": "^3.758.0",