@griddo/cx 1.75.193 → 1.75.196

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.
@@ -1,17 +1,9 @@
1
- // Types
2
1
  import type { GatsbyBrowser } from "gatsby";
3
2
 
4
- // Core providers
5
3
  import { SessionProvider } from "@griddo/core";
6
-
7
- // External libraries
8
- import * as React from "react";
9
-
10
- // Instance
11
- // @ts-expect-error
4
+ // @ts-expect-error components is unknown
12
5
  import { browser } from "components";
13
-
14
- // Gatsby Browser API
6
+ import * as React from "react";
15
7
 
16
8
  export const disableCorePrefetching = () => {
17
9
  if (browser.disableCorePrefetching) {
package/gatsby-config.ts CHANGED
@@ -1,10 +1,7 @@
1
- // Types
2
1
  import type { GatsbyConfig } from "gatsby";
3
2
 
4
- // External libraries
5
3
  import dotenv from "dotenv";
6
4
 
7
- // Utils
8
5
  import { resolveComponentsPath } from "./src/utils/instance";
9
6
 
10
7
  dotenv.config();
@@ -13,17 +10,19 @@ dotenv.config();
13
10
  const GRIDDO_ASSET_PREFIX = process.env.GRIDDO_ASSET_PREFIX || undefined;
14
11
 
15
12
  // Gatsby configuration file from client
16
- const { plugins, ...gatsbyConfig } = require(resolveComponentsPath("builder.config.js"));
13
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
14
+ const { plugins, ...gatsbyConfig } = require(resolveComponentsPath(
15
+ "builder.config.js"
16
+ ));
17
17
 
18
18
  const config: GatsbyConfig = {
19
- // cliente config
19
+ // Client config
20
20
  ...gatsbyConfig,
21
21
  plugins: [
22
- // client plugins
22
+ // Client plugins
23
23
  ...plugins,
24
24
 
25
- // defaults plugins
26
- "gatsby-plugin-provide-react",
25
+ // Defaults plugins
27
26
  "gatsby-plugin-react-svg",
28
27
  "gatsby-plugin-react-helmet", // TODO: Remove with Gatsby@5.5.0
29
28
  "gatsby-plugin-no-sourcemaps",
@@ -32,7 +31,8 @@ const config: GatsbyConfig = {
32
31
 
33
32
  if (GRIDDO_ASSET_PREFIX) {
34
33
  config.assetPrefix = GRIDDO_ASSET_PREFIX;
35
- config.pathPrefix = undefined;
34
+ // @ts-expect-error what the fuck
35
+ config.pathPrefix = null;
36
36
  }
37
37
 
38
38
  export default config;
package/gatsby-node.ts CHANGED
@@ -1,47 +1,41 @@
1
- // Types
2
- import type { GatsbyNode } from "gatsby";
3
1
  import type { StoreMode } from "./src/types/global";
2
+ import type { GatsbyNode } from "gatsby";
4
3
 
5
- // External libraries
6
- import dotenv from "dotenv";
7
4
  import path from "path";
8
5
 
9
- // Services
6
+ import dotenv from "dotenv";
7
+
10
8
  import { RobotsService } from "./src/services/robots";
11
9
  import { StoreService } from "./src/services/store";
12
-
13
- // Utils
14
10
  import { initCache } from "./src/utils/cache";
15
- import {
16
- prepareServe,
17
- prepareStaticFolder,
18
- updateDist,
19
- } from "./src/utils/folders";
20
- import { isComponentLibraryEnv, projectAliases } from "./src/utils/instance";
21
- import { generateSitemaps, setPagesRenderEnd } from "./src/utils/sites";
11
+ import { prepareStaticFolder, updateDist } from "./src/utils/folders";
22
12
  import { logInfo, logPageSize, msToSec, splash } from "./src/utils/shared";
13
+ import { generateBuildReport, generateSitemaps } from "./src/utils/sites";
23
14
 
24
15
  dotenv.config();
25
16
 
26
17
  // Envs
27
- const IS_SERVE = !!process.env.IS_SERVE && !!JSON.parse(process.env.IS_SERVE);
28
18
  const GRIDDO_STORE_MODE = (process.env.GRIDDO_STORE_MODE ||
29
19
  "file") as StoreMode;
30
20
 
31
21
  // Consts
32
- const storeDirPath = path.resolve(__dirname, "./.store/");
33
- const isMonorepo = !isComponentLibraryEnv;
22
+ const PUBLIC_FOLDER = path.resolve(__dirname, "./public");
23
+ const STORE_DIR_PATH = path.resolve(__dirname, "./.store/");
24
+ const REPORT_FILE = path.resolve(PUBLIC_FOLDER, "__build-report__.json");
25
+ const GRIDDO_SANITIZE_PAGES = true;
34
26
 
35
27
  // -----------------------------------------------------------------------------
36
28
  // onPreInit
37
29
  // -----------------------------------------------------------------------------
38
30
  export const onPreInit = async () => {
39
- if (isMonorepo) splash();
40
-
31
+ splash();
41
32
  initCache();
42
33
  prepareStaticFolder();
43
- StoreService.init(storeDirPath, { mode: GRIDDO_STORE_MODE });
44
- await StoreService.saveBuildData();
34
+ StoreService.init(STORE_DIR_PATH, {
35
+ sanitize: GRIDDO_SANITIZE_PAGES,
36
+ mode: GRIDDO_STORE_MODE,
37
+ });
38
+ await StoreService.createBuildSource();
45
39
 
46
40
  console.log("\n✨ onPreInit\n");
47
41
  };
@@ -49,30 +43,36 @@ export const onPreInit = async () => {
49
43
  // -----------------------------------------------------------------------------
50
44
  // createPages
51
45
  // -----------------------------------------------------------------------------
52
- export const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
46
+ export const createPages: GatsbyNode["createPages"] = async ({
47
+ actions: { createPage },
48
+ }) => {
53
49
  const pages = StoreService.getPages();
54
50
 
55
51
  let totalPagesSize = 0;
56
52
 
53
+ // We need to use a `for..of` to iterate over `pages` since it could be a
54
+ // generator and for example a `forEach` doesn't work on it. Besides a
55
+ // `for..of` is probably the best performance option.
57
56
  for (const page of pages) {
58
57
  const startTime = performance.now();
59
58
 
60
- actions.createPage(page);
59
+ createPage(page);
61
60
 
61
+ const {
62
+ size: pageSize,
63
+ context: { id },
64
+ path: pagePath,
65
+ } = page;
62
66
  const duration = msToSec(performance.now() - startTime);
67
+ const size = logPageSize(Math.round(pageSize));
63
68
 
64
- logInfo(
65
- `Creating page (${GRIDDO_STORE_MODE}) ${page.path} - ${duration}s - ${
66
- page.context.id
67
- } - ${logPageSize(Math.round(page.size))}`
68
- );
69
+ logInfo(`Creating page ${pagePath} - ${duration}s - ${id} - ${size}`);
69
70
 
70
- totalPagesSize += page.size;
71
+ totalPagesSize += pageSize;
71
72
  }
72
73
 
73
- console.info(
74
- `Total page-data.json size: ${(totalPagesSize / 1024).toFixed(3)}MB`
75
- );
74
+ const totalPagesSizeMsg = (totalPagesSize / 1024).toFixed(3);
75
+ console.info(`Total page-data.json size: ${totalPagesSizeMsg}MB`);
76
76
 
77
77
  console.log("\n✨ createPages\n");
78
78
  };
@@ -81,17 +81,12 @@ export const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
81
81
  // onPostBuild
82
82
  // -----------------------------------------------------------------------------
83
83
  export const onPostBuild = async () => {
84
- const {
85
- buildProcessData,
86
- createdPages,
87
- sitesToPublish,
88
- } = StoreService.getMetadata();
89
-
90
- await setPagesRenderEnd(buildProcessData, createdPages);
91
- await RobotsService.writeFiles(`${__dirname}/public`);
84
+ const { buildProcessData, sitesToPublish } = StoreService.getMetadata();
85
+
86
+ await generateBuildReport(REPORT_FILE, buildProcessData);
87
+ await RobotsService.writeFiles(PUBLIC_FOLDER);
92
88
  await generateSitemaps(sitesToPublish);
93
89
  await updateDist();
94
- IS_SERVE && (await prepareServe());
95
90
 
96
91
  console.log("\n✨ onPostBuild\n");
97
92
  };
@@ -99,38 +94,4 @@ export const onPostBuild = async () => {
99
94
  // -----------------------------------------------------------------------------
100
95
  // onCreateWebpackConfig
101
96
  // -----------------------------------------------------------------------------
102
- // TODO: Use webpack types
103
- export const onCreateWebpackConfig: GatsbyNode["onCreateWebpackConfig"] = ({
104
- actions,
105
- plugins,
106
- loaders,
107
- getConfig,
108
- }) => {
109
- if (isComponentLibraryEnv) {
110
- const config = getConfig();
111
- config.module.rules = [
112
- // Omit the default rule where test === '\.jsx?$'
113
- ...config.module.rules.filter(
114
- (rule: any) => String(rule.test) !== String(/\.jsx?$/)
115
- ),
116
- // Recreate it with custom exclude filter
117
- {
118
- ...loaders.js(),
119
- test: /\.jsx?$/,
120
- // Exclude all node_modules from transpilation, except for '@griddo/cx'
121
- exclude: (modulePath: string) =>
122
- /node_modules/.test(modulePath) && !/@griddo\/cx/.test(modulePath),
123
- },
124
- ];
125
- actions.replaceWebpackConfig(config);
126
- }
127
-
128
- // Add component-system aliases to Webpack's Resolve:
129
- actions.setWebpackConfig({
130
- resolve: {
131
- fallback: { path: false },
132
- alias: projectAliases,
133
- },
134
- plugins: [plugins.provide({ process: "process/browser" })],
135
- });
136
- };
97
+ export { onCreateWebpackConfig } from "./src/utils/gatsby";
package/gatsby-ssr.tsx CHANGED
@@ -1,16 +1,9 @@
1
- import React from "react";
2
-
3
- // Types
4
1
  import type { GatsbySSR } from "gatsby";
5
2
 
6
- // Core providers
7
3
  import { SessionProvider } from "@griddo/core";
8
-
9
- // Instance
10
- // @ts-ignore
4
+ // @ts-expect-error components is unknown
11
5
  import { ssr } from "components";
12
-
13
- // Gatsby SSR API
6
+ import * as React from "react";
14
7
 
15
8
  export const wrapPageElement: GatsbySSR["wrapPageElement"] = ({ props }) => {
16
9
  if (ssr.wrapPageElement) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/cx",
3
3
  "description": "Griddo SSG based on Gatsby",
4
- "version": "1.75.193",
4
+ "version": "1.75.196",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -20,14 +20,10 @@
20
20
  "griddo-cx": "./index.js"
21
21
  },
22
22
  "scripts": {
23
- "start": "gatsby develop -H 0.0.0.0",
24
23
  "build": "yarn run build:exporter",
25
24
  "build:exporter": "esbuild ./scripts/griddo-exporter.ts --bundle --platform=node --minify --outfile=./build/index.js",
26
- "build:serve": "IS_SERVE=true gatsby build --prefix-paths && gatsby serve",
27
25
  "export": "gatsby build --prefix-paths",
28
26
  "clean": "gatsby clean; rm -rf .cache public assets dist build .store",
29
- "serve": "gatsby serve",
30
- "format": "prettier --write .",
31
27
  "prepare": "yarn run build:exporter",
32
28
  "watch:tscheck": "tsc --noEmit --watch"
33
29
  },
@@ -37,7 +33,7 @@
37
33
  "@babel/preset-env": "^7.14.5",
38
34
  "@babel/preset-react": "^7.14.5",
39
35
  "@babel/preset-typescript": "^7.16.5",
40
- "@griddo/core": "^1.75.193",
36
+ "@griddo/core": "^1.75.196",
41
37
  "@svgr/webpack": "^5.5.0",
42
38
  "babel-loader": "^8.0.6",
43
39
  "babel-plugin-styled-components": "^1.10.7",
@@ -52,7 +48,6 @@
52
48
  "gatsby": "^4.8.0",
53
49
  "gatsby-plugin-no-sourcemaps": "^4.8.0",
54
50
  "gatsby-plugin-polyfill-io": "^1.1.0",
55
- "gatsby-plugin-provide-react": "^1.0.2",
56
51
  "gatsby-plugin-react-helmet": "^5.8.0",
57
52
  "gatsby-plugin-react-svg": "^3.1.0",
58
53
  "gatsby-plugin-sass": "^5.21.0",
@@ -69,7 +64,7 @@
69
64
  "react-helmet": "^6.0.0"
70
65
  },
71
66
  "devDependencies": {
72
- "@griddo/eslint-config-back": "^1.75.193",
67
+ "@griddo/eslint-config-back": "^1.75.196",
73
68
  "@types/babel__core": "^7.20.0",
74
69
  "@types/babel__preset-env": "^7.9.2",
75
70
  "@types/csvtojson": "^2.0.0",
@@ -117,5 +112,5 @@
117
112
  "publishConfig": {
118
113
  "access": "public"
119
114
  },
120
- "gitHead": "724e3fe43760cf3c8efb56dc4207a3e32e01f9dc"
115
+ "gitHead": "11678ff380b3c5bdb420d5117765637af11c9226"
121
116
  }