-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:webiny/webiny-js into dev
- Loading branch information
Showing
36 changed files
with
601 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -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) | ||
|
@@ -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: | ||
|
@@ -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: | ||
|
@@ -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 != '[]' | ||
|
@@ -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: | ||
|
@@ -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 != '[]' | ||
|
@@ -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: | ||
|
@@ -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 }} | ||
|
@@ -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: | ||
|
@@ -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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/api-prerendering-service/__tests__/render/extractPeLoaderDataFromHtml.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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="[{"id":"5e9d0d95eda69955f709d1eb","name":"Falcon 1","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.","wikipedia":"https://en.wikipedia.org/wiki/Falcon_1"},{"id":"5e9d0d95eda69973a809d1ec","name":"Falcon 9","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.","wikipedia":"https://en.wikipedia.org/wiki/Falcon_9"},{"id":"5e9d0d95eda69974db09d1ed","name":"Falcon Heavy","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.","wikipedia":"https://en.wikipedia.org/wiki/Falcon_Heavy"},{"id":"5e9d0d96eda699382d09d1ee","name":"Starship","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.","wikipedia":"https://en.wikipedia.org/wiki/SpaceX_Starship"}]"></pe-loader-data-cache></body></html>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/api-prerendering-service/src/render/extractPeLoaderDataFromHtml.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.