Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:webiny/webiny-js into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Dec 5, 2024
2 parents 76ad3ee + bd1354d commit 2c5b72d
Show file tree
Hide file tree
Showing 36 changed files with 601 additions and 282 deletions.
36 changes: 19 additions & 17 deletions .github/workflows/pullRequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# and run "github-actions-wac build" (or "ghawac build") to regenerate this file.
# For more information, run "github-actions-wac --help".
name: Pull Requests
'on': pull_request
"on": pull_request
concurrency:
group: pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
Expand All @@ -19,7 +19,7 @@ jobs:
- uses: webiny/[email protected]
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
validateCommitsDev:
name: Validate commit messages (dev branch, 'feat' commits not allowed)
Expand All @@ -34,7 +34,7 @@ jobs:
allowed-commit-types: fix,docs,style,refactor,test,build,perf,ci,chore,revert,merge,wip
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
constants:
name: Create constants
Expand Down Expand Up @@ -87,12 +87,14 @@ jobs:
$GITHUB_OUTPUT
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
assignMilestone:
name: Assign milestone
needs: constants
if: needs.constants.outputs.is-fork-pr != 'true'
if: >-
needs.constants.outputs.is-fork-pr != 'true' &&
github.event.pull_request.milestone == null
steps:
- uses: actions/setup-node@v4
with:
Expand All @@ -115,7 +117,7 @@ jobs:
milestone: ${{ steps.get-milestone-to-assign.outputs.milestone }}
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
build:
name: Build
Expand Down Expand Up @@ -147,7 +149,7 @@ jobs:
path: ${{ github.base_ref }}/.webiny/cached-packages
key: ${{ needs.constants.outputs.run-cache-key }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
staticCodeAnalysis:
needs:
Expand Down Expand Up @@ -185,7 +187,7 @@ jobs:
working-directory: ${{ github.base_ref }}
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
staticCodeAnalysisTs:
name: Static code analysis (TypeScript)
Expand All @@ -211,7 +213,7 @@ jobs:
run: yarn cy:ts
working-directory: ${{ github.base_ref }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsNoStorageConstants:
needs:
Expand Down Expand Up @@ -239,7 +241,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsNoStorageRun:
needs:
Expand All @@ -260,7 +262,7 @@ jobs:
}}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
if: needs.jestTestsNoStorageConstants.outputs.packages-to-jest-test != '[]'
Expand Down Expand Up @@ -357,7 +359,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsddbRun:
needs:
Expand All @@ -377,7 +379,7 @@ jobs:
fromJson(needs.jestTestsddbConstants.outputs.packages-to-jest-test) }}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
if: needs.jestTestsddbConstants.outputs.packages-to-jest-test != '[]'
Expand Down Expand Up @@ -474,7 +476,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsddb-esRun:
needs:
Expand All @@ -495,7 +497,7 @@ jobs:
}}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
AWS_ELASTIC_SEARCH_DOMAIN_NAME: ${{ secrets.AWS_ELASTIC_SEARCH_DOMAIN_NAME }}
Expand Down Expand Up @@ -604,7 +606,7 @@ jobs:
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
jestTestsddb-osRun:
needs:
Expand All @@ -625,7 +627,7 @@ jobs:
}}
runs-on: ${{ matrix.os }}
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: "--max_old_space_size=4096"
YARN_ENABLE_IMMUTABLE_INSTALLS: false
AWS_REGION: eu-central-1
AWS_ELASTIC_SEARCH_DOMAIN_NAME: ${{ secrets.AWS_OPEN_SEARCH_DOMAIN_NAME }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/wac/pullRequests.wac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ export const pullRequests = createWorkflow({
assignMilestone: createJob({
name: "Assign milestone",
needs: "constants",
if: "needs.constants.outputs.is-fork-pr != 'true'",
if: [
"needs.constants.outputs.is-fork-pr != 'true'",
"github.event.pull_request.milestone == null"
].join(" && "),
steps: [
{
name: "Print latest Webiny version",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import extractPeLoaderDataFromHtml from "../../src/render/extractPeLoaderDataFromHtml";

describe("extractPeLoaderDataFromHtml Tests", () => {
it("must detect pe-loader-data-cache tags in given HTML", async () => {
const results = extractPeLoaderDataFromHtml(TEST_STRING);

expect(results).toEqual([
{
key: "GfT8AoRsYT-1238102521",
value: [
{
description:
"The Falcon 1 was an expendable launch system privately developed and manufactured by SpaceX during 2006-2009. On 28 September 2008, Falcon 1 became the first privately-developed liquid-fuel launch vehicle to go into orbit around the Earth.",
id: "5e9d0d95eda69955f709d1eb",
name: "Falcon 1",
wikipedia: "https://en.wikipedia.org/wiki/Falcon_1"
},
{
description:
"Falcon 9 is a two-stage rocket designed and manufactured by SpaceX for the reliable and safe transport of satellites and the Dragon spacecraft into orbit.",
id: "5e9d0d95eda69973a809d1ec",
name: "Falcon 9",
wikipedia: "https://en.wikipedia.org/wiki/Falcon_9"
},
{
description:
"With the ability to lift into orbit over 54 metric tons (119,000 lb)--a mass equivalent to a 737 jetliner loaded with passengers, crew, luggage and fuel--Falcon Heavy can lift more than twice the payload of the next closest operational vehicle, the Delta IV Heavy, at one-third the cost.",
id: "5e9d0d95eda69974db09d1ed",
name: "Falcon Heavy",
wikipedia: "https://en.wikipedia.org/wiki/Falcon_Heavy"
},
{
description:
"Starship and Super Heavy Rocket represent a fully reusable transportation system designed to service all Earth orbit needs as well as the Moon and Mars. This two-stage vehicle — composed of the Super Heavy rocket (booster) and Starship (ship) — will eventually replace Falcon 9, Falcon Heavy and Dragon.",
id: "5e9d0d96eda699382d09d1ee",
name: "Starship",
wikipedia: "https://en.wikipedia.org/wiki/SpaceX_Starship"
}
]
}
]);
});
});

const TEST_STRING = `...<li><h1>Starship</h1><div>Starship and Super Heavy Rocket represent a fully reusable transportation system designed to service all Earth orbit needs as well as the Moon and Mars. This two-stage vehicle — composed of the Super Heavy rocket (booster) and Starship (ship) — will eventually replace Falcon 9, Falcon Heavy and Dragon.</div><br><div>More info at&nbsp;<a href="https://en.wikipedia.org/wiki/SpaceX_Starship" target="_blank" rel="noreferrer">https://en.wikipedia.org/wiki/SpaceX_Starship</a></div></li></ul></pb-spacex></pb-cell></pb-grid></pb-block></pb-document></main><footer data-testid="pb-footer" class="wby-1lh86qf"><div class="wby-xv6w56"><div class="logo wby-1i3ok2b"><a href="/"></a><div class="copy">DEVR © 2024</div></div></div></footer></div></div><pe-loader-data-cache data-key="GfT8AoRsYT-1238102521" data-value="[{&quot;id&quot;:&quot;5e9d0d95eda69955f709d1eb&quot;,&quot;name&quot;:&quot;Falcon 1&quot;,&quot;description&quot;:&quot;The Falcon 1 was an expendable launch system privately developed and manufactured by SpaceX during 2006-2009. On 28 September 2008, Falcon 1 became the first privately-developed liquid-fuel launch vehicle to go into orbit around the Earth.&quot;,&quot;wikipedia&quot;:&quot;https://en.wikipedia.org/wiki/Falcon_1&quot;},{&quot;id&quot;:&quot;5e9d0d95eda69973a809d1ec&quot;,&quot;name&quot;:&quot;Falcon 9&quot;,&quot;description&quot;:&quot;Falcon 9 is a two-stage rocket designed and manufactured by SpaceX for the reliable and safe transport of satellites and the Dragon spacecraft into orbit.&quot;,&quot;wikipedia&quot;:&quot;https://en.wikipedia.org/wiki/Falcon_9&quot;},{&quot;id&quot;:&quot;5e9d0d95eda69974db09d1ed&quot;,&quot;name&quot;:&quot;Falcon Heavy&quot;,&quot;description&quot;:&quot;With the ability to lift into orbit over 54 metric tons (119,000 lb)--a mass equivalent to a 737 jetliner loaded with passengers, crew, luggage and fuel--Falcon Heavy can lift more than twice the payload of the next closest operational vehicle, the Delta IV Heavy, at one-third the cost.&quot;,&quot;wikipedia&quot;:&quot;https://en.wikipedia.org/wiki/Falcon_Heavy&quot;},{&quot;id&quot;:&quot;5e9d0d96eda699382d09d1ee&quot;,&quot;name&quot;:&quot;Starship&quot;,&quot;description&quot;:&quot;Starship and Super Heavy Rocket represent a fully reusable transportation system designed to service all Earth orbit needs as well as the Moon and Mars. This two-stage vehicle — composed of the Super Heavy rocket (booster) and Starship (ship) — will eventually replace Falcon 9, Falcon Heavy and Dragon.&quot;,&quot;wikipedia&quot;:&quot;https://en.wikipedia.org/wiki/SpaceX_Starship&quot;}]"></pe-loader-data-cache></body></html>`;
2 changes: 2 additions & 0 deletions packages/api-prerendering-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@webiny/handler-client": "0.0.0",
"@webiny/plugins": "0.0.0",
"@webiny/utils": "0.0.0",
"he": "^1.2.0",
"lodash": "^4.17.21",
"object-hash": "^3.0.0",
"pluralize": "^8.0.0",
Expand All @@ -40,6 +41,7 @@
"@babel/plugin-proposal-export-default-from": "^7.23.3",
"@babel/preset-env": "^7.24.0",
"@babel/preset-typescript": "^7.23.3",
"@types/he": "^1.2.3",
"@types/object-hash": "^2.2.1",
"@types/puppeteer-core": "^5.4.0",
"@webiny/cli": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { PeLoaderCacheEntry } from "./types";
import he from "he";

const parsePeLoaderDataCacheTag = (content: string): PeLoaderCacheEntry | null => {
const regex =
/<pe-loader-data-cache data-key="([a-zA-Z0-9-#]+)" data-value="(.*)"><\/pe-loader-data-cache>/gm;
let m;

while ((m = regex.exec(content)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}

const [, key, value] = m;

// JSON in `data-value` is HTML Entities-encoded. So, we need to decode it here first.
const heParsedValue = he.decode(value);
const parsedValue = JSON.parse(heParsedValue);
return { key, value: parsedValue };
}

return null;
};

export default (content: string): PeLoaderCacheEntry[] => {
if (!content) {
return [];
}

const cachedData: PeLoaderCacheEntry[] = [];
const regex = /<pe-loader-data-cache .*><\/pe-loader-data-cache>/gm;
let m;

while ((m = regex.exec(content)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}

const [matchedTag] = m;

if (!matchedTag) {
continue;
}

const parsedTag = parsePeLoaderDataCacheTag(matchedTag);
if (!parsedTag) {
continue;
}

cachedData.push(parsedTag);
}

if (cachedData.length > 0) {
const uniqueMap: Record<string, PeLoaderCacheEntry> = cachedData.reduce(
(collection, peLoaderDataCache) => {
collection[`${peLoaderDataCache.key || ""}${peLoaderDataCache.value || ""}`] =
peLoaderDataCache;

return collection;
},
{} as Record<string, PeLoaderCacheEntry>
);

return Object.values(uniqueMap);
}
return cachedData;
};
31 changes: 19 additions & 12 deletions packages/api-prerendering-service/src/render/renderUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import injectRenderTs from "./injectRenderTs";
import injectTenantLocale from "./injectTenantLocale";
import injectNotFoundPageFlag from "./injectNotFoundPageFlag";
import getPsTags from "./getPsTags";
import extractPeLoaderDataFromHtml from "./extractPeLoaderDataFromHtml";
import shortid from "shortid";
import {
GraphQLCacheEntry,
PeLoaderCacheEntry,
RenderResult,
RenderUrlCallableParams,
RenderUrlParams,
Expand Down Expand Up @@ -108,8 +111,8 @@ export default async (url: string, args: RenderUrlParams): Promise<[File[], Meta
}
},
{
name: "graphql.json",
body: JSON.stringify(render.meta.gqlCache),
name: "cache.json",
body: JSON.stringify(render.meta.cachedData),
type: "application/json",
meta: {}
}
Expand All @@ -118,12 +121,6 @@ export default async (url: string, args: RenderUrlParams): Promise<[File[], Meta
];
};

interface GraphQLCache {
query: any;
variables: Record<string, any>;
data: Record<string, any>;
}

export const defaultRenderUrlFunction = async (
url: string,
params: RenderUrlCallableParams
Expand Down Expand Up @@ -168,7 +165,13 @@ export const defaultRenderUrlFunction = async (
}
});

const gqlCache: GraphQLCache[] = [];
const cachedData: {
apolloGraphQl: GraphQLCacheEntry[];
peLoaders: PeLoaderCacheEntry[];
} = {
apolloGraphQl: [],
peLoaders: []
};

// TODO: should be a plugin.
browserPage.on("response", async response => {
Expand All @@ -189,7 +192,7 @@ export const defaultRenderUrlFunction = async (

if (mustCache) {
const data = Array.isArray(responses) ? responses[i].data : responses.data;
gqlCache.push({
cachedData.apolloGraphQl.push({
query,
variables,
data
Expand All @@ -208,11 +211,15 @@ export const defaultRenderUrlFunction = async (
return window.getApolloState();
});

const content = await browserPage.content();

cachedData.peLoaders = extractPeLoaderDataFromHtml(content);

return {
content: await browserPage.content(),
content,
// TODO: ideally, meta should be assigned here in a more "plugins style" way, not hardcoded.
meta: {
gqlCache,
cachedData,
apolloState
}
};
Expand Down
Loading

0 comments on commit 2c5b72d

Please sign in to comment.