xpine 0.0.41 → 0.0.43

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 CHANGED
@@ -43,6 +43,22 @@ setupEnv also supports AWS secrets manager. Simply add SECRETS_NAME=your_aws_sec
43
43
 
44
44
  `import { createXPineRouter } from 'xpine';`
45
45
 
46
+ - Catch all routes
47
+ - You can create catch all routes by naming the file _all_.(jsx|tsx|js|ts)
48
+ - You can make static catch all route pages by using the param `0` in the staticPaths config function:
49
+ ```
50
+ export const config = {
51
+ staticPaths() {
52
+ return [
53
+ {
54
+ 0: 'hello/world',
55
+ }
56
+ ]
57
+ },
58
+ }
59
+ ```
60
+ - You can get the route param in your function with req.params[0], such as how express handles catch all routes
61
+
46
62
 
47
63
  ### SPA interactivity
48
64
 
package/dist/index.js CHANGED
@@ -312,7 +312,10 @@ var regex_default = {
312
312
  endsWithTSX: /\.tsx$/,
313
313
  endsWithJSX: /\.jsx$/,
314
314
  endsWithFileName: /\.(html|tsx|jsx|js|ts)$/,
315
- indexFile: /index\.(html|tsx|jsx|js|ts)$/g
315
+ indexFile: /index\.(html|tsx|jsx|js|ts)$/g,
316
+ catchAllRoute: /\/_all_$/g,
317
+ catchAllRouteFilePath: /_all_\.(html|tsx|jsx|js|ts)$/g,
318
+ catchAllRouteFileName: /_all_/g
316
319
  };
317
320
 
318
321
  // src/util/config-file.ts
@@ -525,6 +528,8 @@ async function createRouter() {
525
528
  formattedRouteItem = formattedRouteItem.replace(match[0], ":" + match[2]);
526
529
  }
527
530
  }
531
+ const hasCatchAll = formattedRouteItem.match(regex_default.catchAllRoute);
532
+ if (hasCatchAll) formattedRouteItem = formattedRouteItem.replace(regex_default.catchAllRoute, "/*");
528
533
  const componentImport = await import(route.path);
529
534
  const componentFn = isDev ? null : componentImport?.default;
530
535
  if (componentImport?.config?.onInit) {
@@ -637,6 +642,7 @@ function routeHasStaticPath(route, params) {
637
642
  let routeToStaticPath = route;
638
643
  for (const [key, value] of paramEntries) {
639
644
  routeToStaticPath = routeToStaticPath.replace(`:${key}`, value);
645
+ if (key === "0") routeToStaticPath = routeToStaticPath.replace(/\/\*/g, `/${value}`);
640
646
  }
641
647
  routeToStaticPath += "/index.html";
642
648
  const outputPath = path5.join(config.distPagesDir, routeToStaticPath);
@@ -933,7 +939,13 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
933
939
  let componentFileName = component.path.split("/").pop().replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
934
940
  const isDynamicRoute = component.path.match(regex_default.isDynamicRoute);
935
941
  if (isDynamicRoute) {
936
- componentFileName = component.path.split("/").filter((dir) => dir.match(regex_default.isDynamicRoute)).join("/").replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
942
+ componentFileName = component.path.split("/").filter((dir) => {
943
+ return dir.match(regex_default.isDynamicRoute) || dir.match(regex_default.catchAllRouteFilePath);
944
+ }).map((dir) => {
945
+ const matchesCatchAll = dir.match(regex_default.catchAllRouteFilePath);
946
+ if (matchesCatchAll) return dir.replace(regex_default.catchAllRouteFileName, "[0]");
947
+ return dir;
948
+ }).join("/").replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
937
949
  }
938
950
  const componentDynamicPaths = getComponentDynamicPaths(componentFileName);
939
951
  const componentFn = componentImport.default;
@@ -953,7 +965,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
953
965
  );
954
966
  } catch (err) {
955
967
  console.error(err);
956
- console.log("Could not build static component", component.path);
968
+ console.error("Could not build static component", component.path);
957
969
  }
958
970
  } else if (typeof config2?.staticPaths === "function") {
959
971
  const dynamicPaths = await config2.staticPaths();
@@ -974,14 +986,14 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
974
986
  doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
975
987
  );
976
988
  } catch (err) {
977
- console.log("Could not build static component", component.path);
978
989
  console.error(err);
990
+ console.error("Could not build static component", component.path);
979
991
  }
980
992
  }
981
993
  }
982
994
  }
983
995
  function getComponentDynamicPaths(componentPath) {
984
- const matches = [...componentPath.matchAll(regex_default.dynamicRoutes)];
996
+ const matches = [...componentPath.matchAll(regex_default.dynamicRoutes)].concat([...componentPath.matchAll(regex_default.catchAllRoute)]);
985
997
  if (!matches?.length) return null;
986
998
  const output = [];
987
999
  for (const match of matches) {
@@ -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;;;GA+GjC;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,CAWnG;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;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 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;AAajF,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAA;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,iBAsBhD;AAiJD,wBAAsB,yBAAyB,kBAgB9C;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,EAAE,eAAe,WAAkB,iBAahH;AAED,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,aAAa,EAAE,iBAezE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,iBAmEpI;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxE;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAA;AAGD,wBAAsB,eAAe,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,iBAoDpF"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;AAajF,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAA;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,iBAsBhD;AAiJD,wBAAsB,yBAAyB,kBAgB9C;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,EAAE,eAAe,WAAkB,iBAahH;AAED,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,aAAa,EAAE,iBAezE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,iBAyEpI;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxE;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAA;AAGD,wBAAsB,eAAe,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,iBAoDpF"}
@@ -307,7 +307,10 @@ var regex_default = {
307
307
  endsWithTSX: /\.tsx$/,
308
308
  endsWithJSX: /\.jsx$/,
309
309
  endsWithFileName: /\.(html|tsx|jsx|js|ts)$/,
310
- indexFile: /index\.(html|tsx|jsx|js|ts)$/g
310
+ indexFile: /index\.(html|tsx|jsx|js|ts)$/g,
311
+ catchAllRoute: /\/_all_$/g,
312
+ catchAllRouteFilePath: /_all_\.(html|tsx|jsx|js|ts)$/g,
313
+ catchAllRouteFileName: /_all_/g
311
314
  };
312
315
 
313
316
  // src/util/config-file.ts
@@ -742,7 +745,13 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
742
745
  let componentFileName = component.path.split("/").pop().replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
743
746
  const isDynamicRoute = component.path.match(regex_default.isDynamicRoute);
744
747
  if (isDynamicRoute) {
745
- componentFileName = component.path.split("/").filter((dir) => dir.match(regex_default.isDynamicRoute)).join("/").replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
748
+ componentFileName = component.path.split("/").filter((dir) => {
749
+ return dir.match(regex_default.isDynamicRoute) || dir.match(regex_default.catchAllRouteFilePath);
750
+ }).map((dir) => {
751
+ const matchesCatchAll = dir.match(regex_default.catchAllRouteFilePath);
752
+ if (matchesCatchAll) return dir.replace(regex_default.catchAllRouteFileName, "[0]");
753
+ return dir;
754
+ }).join("/").replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
746
755
  }
747
756
  const componentDynamicPaths = getComponentDynamicPaths(componentFileName);
748
757
  const componentFn = componentImport.default;
@@ -762,7 +771,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
762
771
  );
763
772
  } catch (err) {
764
773
  console.error(err);
765
- console.log("Could not build static component", component.path);
774
+ console.error("Could not build static component", component.path);
766
775
  }
767
776
  } else if (typeof config2?.staticPaths === "function") {
768
777
  const dynamicPaths = await config2.staticPaths();
@@ -783,14 +792,14 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
783
792
  doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
784
793
  );
785
794
  } catch (err) {
786
- console.log("Could not build static component", component.path);
787
795
  console.error(err);
796
+ console.error("Could not build static component", component.path);
788
797
  }
789
798
  }
790
799
  }
791
800
  }
792
801
  function getComponentDynamicPaths(componentPath) {
793
- const matches = [...componentPath.matchAll(regex_default.dynamicRoutes)];
802
+ const matches = [...componentPath.matchAll(regex_default.dynamicRoutes)].concat([...componentPath.matchAll(regex_default.catchAllRoute)]);
794
803
  if (!matches?.length) return null;
795
804
  const output = [];
796
805
  for (const match of matches) {
@@ -314,7 +314,10 @@ var regex_default = {
314
314
  endsWithTSX: /\.tsx$/,
315
315
  endsWithJSX: /\.jsx$/,
316
316
  endsWithFileName: /\.(html|tsx|jsx|js|ts)$/,
317
- indexFile: /index\.(html|tsx|jsx|js|ts)$/g
317
+ indexFile: /index\.(html|tsx|jsx|js|ts)$/g,
318
+ catchAllRoute: /\/_all_$/g,
319
+ catchAllRouteFilePath: /_all_\.(html|tsx|jsx|js|ts)$/g,
320
+ catchAllRouteFileName: /_all_/g
318
321
  };
319
322
 
320
323
  // src/util/config-file.ts
@@ -749,7 +752,13 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
749
752
  let componentFileName = component.path.split("/").pop().replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
750
753
  const isDynamicRoute = component.path.match(regex_default.isDynamicRoute);
751
754
  if (isDynamicRoute) {
752
- componentFileName = component.path.split("/").filter((dir) => dir.match(regex_default.isDynamicRoute)).join("/").replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
755
+ componentFileName = component.path.split("/").filter((dir) => {
756
+ return dir.match(regex_default.isDynamicRoute) || dir.match(regex_default.catchAllRouteFilePath);
757
+ }).map((dir) => {
758
+ const matchesCatchAll = dir.match(regex_default.catchAllRouteFilePath);
759
+ if (matchesCatchAll) return dir.replace(regex_default.catchAllRouteFileName, "[0]");
760
+ return dir;
761
+ }).join("/").replace(regex_default.endsWithJSX, "").replace(regex_default.endsWithTSX, "");
753
762
  }
754
763
  const componentDynamicPaths = getComponentDynamicPaths(componentFileName);
755
764
  const componentFn = componentImport.default;
@@ -769,7 +778,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
769
778
  );
770
779
  } catch (err) {
771
780
  console.error(err);
772
- console.log("Could not build static component", component.path);
781
+ console.error("Could not build static component", component.path);
773
782
  }
774
783
  } else if (typeof config2?.staticPaths === "function") {
775
784
  const dynamicPaths = await config2.staticPaths();
@@ -790,14 +799,14 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
790
799
  doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
791
800
  );
792
801
  } catch (err) {
793
- console.log("Could not build static component", component.path);
794
802
  console.error(err);
803
+ console.error("Could not build static component", component.path);
795
804
  }
796
805
  }
797
806
  }
798
807
  }
799
808
  function getComponentDynamicPaths(componentPath) {
800
- const matches = [...componentPath.matchAll(regex_default.dynamicRoutes)];
809
+ const matches = [...componentPath.matchAll(regex_default.dynamicRoutes)].concat([...componentPath.matchAll(regex_default.catchAllRoute)]);
801
810
  if (!matches?.length) return null;
802
811
  const output = [];
803
812
  for (const match of matches) {
@@ -27,8 +27,8 @@ async function updatePageOnLinkClick(e) {
27
27
  window.history.pushState(
28
28
  {
29
29
  type: "link-click",
30
- href: targetHref,
31
- url: newURL
30
+ hrefTarget: targetHref,
31
+ href: newURL?.href
32
32
  },
33
33
  "",
34
34
  targetHref
@@ -8,6 +8,9 @@ declare const _default: {
8
8
  endsWithJSX: RegExp;
9
9
  endsWithFileName: RegExp;
10
10
  indexFile: RegExp;
11
+ catchAllRoute: RegExp;
12
+ catchAllRouteFilePath: RegExp;
13
+ catchAllRouteFileName: RegExp;
11
14
  };
12
15
  export default _default;
13
16
  //# sourceMappingURL=regex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../../src/util/regex.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,wBAUE"}
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../../src/util/regex.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wBAaE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpine",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "main": "dist/index.js",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-secrets-manager": "^3.758.0",