@sitecore-content-sdk/nextjs 0.3.0-canary.21 → 0.3.0-canary.23

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.
@@ -37,7 +37,7 @@ exports.ComponentPropsContext = exports.ComponentPropsReactContext = void 0;
37
37
  exports.useComponentProps = useComponentProps;
38
38
  const react_1 = __importStar(require("react"));
39
39
  /**
40
- * Component props context which we are using in order to store data fetched on components level (getStaticProps/getServerSideProps)
40
+ * Component props context which we are using in order to store data fetched on components level (getComponentServerProps)
41
41
  */
42
42
  exports.ComponentPropsReactContext = (0, react_1.createContext)({});
43
43
  /**
@@ -37,7 +37,7 @@ exports.default = componentPropsLoader;
37
37
  const recast = __importStar(require("recast"));
38
38
  /**
39
39
  * Webpack loader to strip functions from the source code
40
- * Strips the `getServerSideProps` and `getStaticProps` functions from the source code
40
+ * Strips the `getComponentServerProps` function from the source code
41
41
  * @param {string} source file source code
42
42
  * @returns {string} output file source code with stripped functions
43
43
  */
@@ -46,32 +46,29 @@ function componentPropsLoader(source) {
46
46
  const ast = recast.parse(source, {
47
47
  parser: require('recast/parsers/babel-ts'),
48
48
  });
49
- // List of functions to strip from the AST
50
- const functionsToStrip = ['getServerSideProps', 'getStaticProps'];
51
- // Remove the function from the list of functions to strip
52
- const updateList = (functionName) => {
53
- // Remove the function from the list of functions to strip
54
- functionsToStrip.splice(functionsToStrip.indexOf(functionName), 1);
55
- };
56
- // Traverse the AST and strip the functions
49
+ // The method to strip from the AST
50
+ const method = 'getComponentServerProps';
51
+ // Traverse the AST and find the method to strip
57
52
  recast.visit(ast, {
58
53
  // Visit the named export function expression
59
54
  visitExportNamedDeclaration: function (path) {
60
55
  var _a, _b;
61
56
  // Get the variable declaration from the AST
62
- (_b = (_a = path.node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b.forEach((declaration) => {
63
- // Check if the function is in the list of functions to strip
57
+ const isMethodFound = (_b = (_a = path.node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b.find((declaration) => {
58
+ // Check if the function is the one we want to strip
64
59
  if ('id' in declaration &&
65
60
  'name' in declaration.id &&
66
61
  typeof declaration.id.name === 'string' &&
67
- functionsToStrip.includes(declaration.id.name)) {
68
- updateList(declaration.id.name);
62
+ declaration.id.name === method) {
69
63
  // Strip the function from the AST
70
64
  path.prune();
65
+ // We have pruned the method, so we can stop iterating over the declarations
66
+ return true;
71
67
  }
68
+ return false;
72
69
  });
73
- if (functionsToStrip.length === 0) {
74
- // We have pruned all the functions we need to, so we can stop traversing the AST
70
+ if (isMethodFound) {
71
+ // We have pruned the method, so we can stop traversing the AST
75
72
  return false;
76
73
  }
77
74
  // Continue traversing the AST
@@ -79,17 +76,14 @@ function componentPropsLoader(source) {
79
76
  },
80
77
  // Visit the named export function declaration
81
78
  visitFunctionDeclaration: function (path) {
82
- // Check if the function is in the list of functions to strip
79
+ // Check if the function is the one we want to strip
83
80
  if (path.node.id &&
84
81
  'name' in path.node.id &&
85
82
  typeof path.node.id.name === 'string' &&
86
- functionsToStrip.includes(path.node.id.name)) {
87
- updateList(path.node.id.name);
83
+ path.node.id.name === method) {
88
84
  // Strip the function from the AST
89
85
  path.prune();
90
- }
91
- if (functionsToStrip.length === 0) {
92
- // We have pruned all the functions we need to, so we can stop traversing the AST
86
+ // We have pruned the method, so we can stop traversing the AST
93
87
  return false;
94
88
  }
95
89
  // Continue traversing the AST
@@ -1,6 +1,6 @@
1
1
  import React, { createContext, useContext } from 'react';
2
2
  /**
3
- * Component props context which we are using in order to store data fetched on components level (getStaticProps/getServerSideProps)
3
+ * Component props context which we are using in order to store data fetched on components level (getComponentServerProps)
4
4
  */
5
5
  export const ComponentPropsReactContext = createContext({});
6
6
  /**
@@ -1,7 +1,7 @@
1
1
  import * as recast from 'recast';
2
2
  /**
3
3
  * Webpack loader to strip functions from the source code
4
- * Strips the `getServerSideProps` and `getStaticProps` functions from the source code
4
+ * Strips the `getComponentServerProps` function from the source code
5
5
  * @param {string} source file source code
6
6
  * @returns {string} output file source code with stripped functions
7
7
  */
@@ -10,32 +10,29 @@ export default function componentPropsLoader(source) {
10
10
  const ast = recast.parse(source, {
11
11
  parser: require('recast/parsers/babel-ts'),
12
12
  });
13
- // List of functions to strip from the AST
14
- const functionsToStrip = ['getServerSideProps', 'getStaticProps'];
15
- // Remove the function from the list of functions to strip
16
- const updateList = (functionName) => {
17
- // Remove the function from the list of functions to strip
18
- functionsToStrip.splice(functionsToStrip.indexOf(functionName), 1);
19
- };
20
- // Traverse the AST and strip the functions
13
+ // The method to strip from the AST
14
+ const method = 'getComponentServerProps';
15
+ // Traverse the AST and find the method to strip
21
16
  recast.visit(ast, {
22
17
  // Visit the named export function expression
23
18
  visitExportNamedDeclaration: function (path) {
24
19
  var _a, _b;
25
20
  // Get the variable declaration from the AST
26
- (_b = (_a = path.node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b.forEach((declaration) => {
27
- // Check if the function is in the list of functions to strip
21
+ const isMethodFound = (_b = (_a = path.node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b.find((declaration) => {
22
+ // Check if the function is the one we want to strip
28
23
  if ('id' in declaration &&
29
24
  'name' in declaration.id &&
30
25
  typeof declaration.id.name === 'string' &&
31
- functionsToStrip.includes(declaration.id.name)) {
32
- updateList(declaration.id.name);
26
+ declaration.id.name === method) {
33
27
  // Strip the function from the AST
34
28
  path.prune();
29
+ // We have pruned the method, so we can stop iterating over the declarations
30
+ return true;
35
31
  }
32
+ return false;
36
33
  });
37
- if (functionsToStrip.length === 0) {
38
- // We have pruned all the functions we need to, so we can stop traversing the AST
34
+ if (isMethodFound) {
35
+ // We have pruned the method, so we can stop traversing the AST
39
36
  return false;
40
37
  }
41
38
  // Continue traversing the AST
@@ -43,17 +40,14 @@ export default function componentPropsLoader(source) {
43
40
  },
44
41
  // Visit the named export function declaration
45
42
  visitFunctionDeclaration: function (path) {
46
- // Check if the function is in the list of functions to strip
43
+ // Check if the function is the one we want to strip
47
44
  if (path.node.id &&
48
45
  'name' in path.node.id &&
49
46
  typeof path.node.id.name === 'string' &&
50
- functionsToStrip.includes(path.node.id.name)) {
51
- updateList(path.node.id.name);
47
+ path.node.id.name === method) {
52
48
  // Strip the function from the AST
53
49
  path.prune();
54
- }
55
- if (functionsToStrip.length === 0) {
56
- // We have pruned all the functions we need to, so we can stop traversing the AST
50
+ // We have pruned the method, so we can stop traversing the AST
57
51
  return false;
58
52
  }
59
53
  // Continue traversing the AST
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/nextjs",
3
- "version": "0.3.0-canary.21",
3
+ "version": "0.3.0-canary.23",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -73,15 +73,15 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@babel/parser": "^7.27.2",
76
- "@sitecore-content-sdk/core": "0.3.0-canary.21",
77
- "@sitecore-content-sdk/react": "0.3.0-canary.21",
76
+ "@sitecore-content-sdk/core": "0.3.0-canary.23",
77
+ "@sitecore-content-sdk/react": "0.3.0-canary.23",
78
78
  "recast": "^0.23.11",
79
79
  "regex-parser": "^2.3.1",
80
80
  "sync-disk-cache": "^2.1.0"
81
81
  },
82
82
  "description": "",
83
83
  "types": "types/index.d.ts",
84
- "gitHead": "c793864ef8bbfec2c08aaf4959a169a7519401ce",
84
+ "gitHead": "be43bbd99f1b474488fd0b8fa85b17a97ad29401",
85
85
  "files": [
86
86
  "dist",
87
87
  "types",
@@ -1,7 +1,7 @@
1
1
  import React, { ReactNode, JSX } from 'react';
2
2
  import { ComponentPropsCollection } from '../sharedTypes/component-props';
3
3
  /**
4
- * Component props context which we are using in order to store data fetched on components level (getStaticProps/getServerSideProps)
4
+ * Component props context which we are using in order to store data fetched on components level (getComponentServerProps)
5
5
  */
6
6
  export declare const ComponentPropsReactContext: React.Context<ComponentPropsCollection>;
7
7
  /**
@@ -13,7 +13,7 @@ export type ComponentPropsCollection = {
13
13
  };
14
14
  export type NextContext = GetServerSidePropsContext | GetStaticPropsContext;
15
15
  /**
16
- * Type of side effect function which could be invoked on component level (getStaticProps/getServerSideProps)
16
+ * Type of side effect function which could be invoked on component level (getComponentServerProps)
17
17
  */
18
18
  export type ComponentPropsFetchFunction<FetchedProps = unknown> = {
19
19
  (rendering: ComponentRendering, layoutData: LayoutServiceData, context: NextContext): Promise<FetchedProps>;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Webpack loader to strip functions from the source code
3
- * Strips the `getServerSideProps` and `getStaticProps` functions from the source code
3
+ * Strips the `getComponentServerProps` function from the source code
4
4
  * @param {string} source file source code
5
5
  * @returns {string} output file source code with stripped functions
6
6
  */